@downcity/agent 1.1.430 → 1.1.438
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 +13 -11
- package/bin/agent/Agent.d.ts +3 -3
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +38 -8
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentInstructions.js +2 -2
- package/bin/agent/AgentInstructions.js.map +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
- package/bin/agent/AgentMemoryStorage.js +1 -0
- package/bin/agent/AgentMemoryStorage.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +5 -1
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +17 -9
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/executor/Executor.d.ts +9 -27
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +32 -127
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts +0 -4
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js +0 -5
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +3 -9
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js +4 -130
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +3 -30
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +38 -194
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +6 -6
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +2 -2
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionModelMessages.d.ts +0 -3
- package/bin/executor/messages/SessionModelMessages.d.ts.map +1 -1
- package/bin/executor/messages/SessionModelMessages.js +80 -97
- package/bin/executor/messages/SessionModelMessages.js.map +1 -1
- package/bin/executor/model/ModelStepRunner.d.ts +2 -6
- package/bin/executor/model/ModelStepRunner.d.ts.map +1 -1
- package/bin/executor/model/ModelStepRunner.js +0 -28
- package/bin/executor/model/ModelStepRunner.js.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +7 -64
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js +29 -45
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +1 -3
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/index.d.ts +9 -13
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -4
- package/bin/index.js.map +1 -1
- package/bin/session/DefaultSessionComposer.d.ts +13 -7
- package/bin/session/DefaultSessionComposer.d.ts.map +1 -1
- package/bin/session/DefaultSessionComposer.js +26 -21
- package/bin/session/DefaultSessionComposer.js.map +1 -1
- package/bin/session/Session.d.ts +12 -19
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +70 -202
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionComposition.d.ts +0 -2
- package/bin/session/SessionComposition.d.ts.map +1 -1
- package/bin/session/SessionComposition.js +30 -54
- package/bin/session/SessionComposition.js.map +1 -1
- package/bin/session/SessionLoop.d.ts +17 -16
- package/bin/session/SessionLoop.d.ts.map +1 -1
- package/bin/session/SessionLoop.js +217 -320
- package/bin/session/SessionLoop.js.map +1 -1
- package/bin/session/SessionMessages.d.ts +52 -44
- package/bin/session/SessionMessages.d.ts.map +1 -1
- package/bin/session/SessionMessages.js +285 -187
- package/bin/session/SessionMessages.js.map +1 -1
- package/bin/session/SessionQueue.d.ts +1 -1
- package/bin/session/SessionQueue.d.ts.map +1 -1
- package/bin/session/SessionQueue.js +2 -1
- package/bin/session/SessionQueue.js.map +1 -1
- package/bin/session/SessionState.d.ts +3 -7
- package/bin/session/SessionState.d.ts.map +1 -1
- package/bin/session/SessionState.js +50 -89
- package/bin/session/SessionState.js.map +1 -1
- package/bin/session/SessionSystem.d.ts +5 -1
- package/bin/session/SessionSystem.d.ts.map +1 -1
- package/bin/session/SessionSystem.js +40 -0
- package/bin/session/SessionSystem.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +3 -3
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +2 -2
- package/bin/session/browse/Browse.d.ts +32 -46
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +104 -360
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/browse/SessionMessageTimeline.d.ts.map +1 -1
- package/bin/session/browse/SessionMessageTimeline.js +61 -37
- package/bin/session/browse/SessionMessageTimeline.js.map +1 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +35 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +1 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js +256 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +1 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +24 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +1 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.js +31 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +1 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts +16 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +1 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.js +32 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.js.map +1 -0
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts +15 -4
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js +7 -3
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +1 -1
- package/bin/session/messages/{SessionActionMessageWriter.d.ts → SessionAgentActionPartWriter.d.ts} +7 -7
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +1 -0
- package/bin/session/messages/{SessionActionMessageWriter.js → SessionAgentActionPartWriter.js} +7 -7
- package/bin/session/messages/SessionAgentActionPartWriter.js.map +1 -0
- package/bin/session/messages/SessionAgentContent.d.ts +10 -0
- package/bin/session/messages/SessionAgentContent.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentContent.js +44 -0
- package/bin/session/messages/SessionAgentContent.js.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts +50 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.js +283 -0
- package/bin/session/messages/SessionAgentMessageState.js.map +1 -0
- package/bin/session/messages/{SessionAssistantMessageWriter.d.ts → SessionAgentMessageWriter.d.ts} +22 -8
- package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -0
- package/bin/session/messages/{SessionAssistantMessageWriter.js → SessionAgentMessageWriter.js} +54 -42
- package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -0
- package/bin/session/messages/SessionForkMessageFiles.d.ts +11 -0
- package/bin/session/messages/SessionForkMessageFiles.d.ts.map +1 -1
- package/bin/session/messages/SessionForkMessageFiles.js +8 -2
- package/bin/session/messages/SessionForkMessageFiles.js.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts +6 -6
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +4 -4
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +1 -1
- package/bin/session/messages/SessionMessageText.d.ts +3 -3
- package/bin/session/messages/SessionMessageText.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageText.js +0 -2
- package/bin/session/messages/SessionMessageText.js.map +1 -1
- package/bin/session/messages/SessionTurnFileDiffData.d.ts +3 -3
- package/bin/session/messages/SessionTurnFileDiffData.d.ts.map +1 -1
- package/bin/session/messages/SessionTurnFileDiffData.js.map +1 -1
- package/bin/session/messages/SessionUserMessage.d.ts +3 -3
- package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
- package/bin/session/messages/SessionUserMessage.js +6 -3
- package/bin/session/messages/SessionUserMessage.js.map +1 -1
- package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/preview/SessionMessagePreview.js +25 -9
- package/bin/session/preview/SessionMessagePreview.js.map +1 -1
- package/bin/session/runtime/SessionTurnCompletion.d.ts +15 -0
- package/bin/session/runtime/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/session/runtime/SessionTurnCompletion.js +126 -0
- package/bin/session/runtime/SessionTurnCompletion.js.map +1 -0
- package/bin/session/runtime/SessionTurnContext.d.ts.map +1 -1
- package/bin/session/runtime/SessionTurnContext.js +14 -19
- package/bin/session/runtime/SessionTurnContext.js.map +1 -1
- package/bin/session/runtime/SessionTurnFileDiff.d.ts +12 -0
- package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/session/runtime/SessionTurnFileDiff.js +71 -0
- package/bin/session/runtime/SessionTurnFileDiff.js.map +1 -0
- package/bin/session/storage/LocalSessionDataStore.d.ts +6 -41
- package/bin/session/storage/LocalSessionDataStore.d.ts.map +1 -1
- package/bin/session/storage/LocalSessionDataStore.js +19 -101
- package/bin/session/storage/LocalSessionDataStore.js.map +1 -1
- package/bin/session/storage/LocalSessionStore.d.ts +13 -5
- package/bin/session/storage/LocalSessionStore.d.ts.map +1 -1
- package/bin/session/storage/LocalSessionStore.js +153 -30
- package/bin/session/storage/LocalSessionStore.js.map +1 -1
- package/bin/session/storage/LocalStorePaths.d.ts +4 -16
- package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
- package/bin/session/storage/LocalStorePaths.js +7 -31
- package/bin/session/storage/LocalStorePaths.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +4 -4
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +3 -11
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +4 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +3 -3
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/session/storage/SessionStorageCodec.d.ts +59 -0
- package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -0
- package/bin/session/storage/SessionStorageCodec.js +331 -0
- package/bin/session/storage/SessionStorageCodec.js.map +1 -0
- package/bin/session/storage/SessionStorageSchema.d.ts +11 -0
- package/bin/session/storage/SessionStorageSchema.d.ts.map +1 -0
- package/bin/session/storage/SessionStorageSchema.js +131 -0
- package/bin/session/storage/SessionStorageSchema.js.map +1 -0
- package/bin/session/storage/SqliteSessionStorage.d.ts +120 -0
- package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -0
- package/bin/session/storage/SqliteSessionStorage.js +581 -0
- package/bin/session/storage/SqliteSessionStorage.js.map +1 -0
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +3 -1
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/action/ActionResult.d.ts +9 -9
- package/bin/types/action/ActionResult.d.ts.map +1 -1
- package/bin/types/action/ActionResult.js +1 -1
- package/bin/types/agent/AgentOptions.d.ts +10 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentStorage.d.ts +3 -1
- package/bin/types/agent/AgentStorage.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +0 -9
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +5 -5
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionAssistantOutput.d.ts +15 -4
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +1 -1
- package/bin/types/executor/SessionTurnContext.d.ts +17 -19
- package/bin/types/executor/SessionTurnContext.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +1 -1
- package/bin/types/sdk/AgentSessionAction.js +1 -1
- package/bin/types/sdk/AgentSessionPrompt.d.ts +14 -5
- package/bin/types/sdk/AgentSessionPrompt.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js.map +1 -1
- package/bin/types/session/AdaptivePartContextPolicy.d.ts +31 -0
- package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +1 -0
- package/bin/types/session/AdaptivePartContextPolicy.js +7 -0
- package/bin/types/session/AdaptivePartContextPolicy.js.map +1 -0
- package/bin/types/session/{SessionAssistantMessageState.d.ts → SessionAgentMessageState.d.ts} +7 -7
- package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -0
- package/bin/types/session/{SessionAssistantMessageState.js → SessionAgentMessageState.js} +1 -1
- package/bin/types/session/SessionAgentMessageState.js.map +1 -0
- package/bin/types/session/SessionCommand.d.ts +19 -7
- package/bin/types/session/SessionCommand.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.d.ts +43 -43
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.js +2 -2
- package/bin/types/session/SessionComposition.d.ts +2 -5
- package/bin/types/session/SessionComposition.d.ts.map +1 -1
- package/bin/types/session/SessionContextPolicy.d.ts +70 -0
- package/bin/types/session/SessionContextPolicy.d.ts.map +1 -0
- package/bin/types/session/SessionContextPolicy.js +8 -0
- package/bin/types/session/SessionContextPolicy.js.map +1 -0
- package/bin/types/session/SessionExecution.d.ts +5 -32
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionLoop.d.ts +3 -5
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +18 -28
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +5 -5
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +8 -9
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionState.d.ts +2 -5
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +14 -0
- 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 +23 -0
- package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/types/session/SessionTurnCompletion.js +8 -0
- package/bin/types/session/SessionTurnCompletion.js.map +1 -0
- package/bin/types/session/SessionTurnFileDiff.d.ts +42 -0
- package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/types/session/SessionTurnFileDiff.js +8 -0
- package/bin/types/session/SessionTurnFileDiff.js.map +1 -0
- package/bin/types/store/LocalStore.d.ts +6 -13
- package/bin/types/store/LocalStore.d.ts.map +1 -1
- package/bin/types/store/LocalStore.js +1 -1
- package/bin/types/store/SessionStorage.d.ts +103 -0
- package/bin/types/store/SessionStorage.d.ts.map +1 -0
- package/bin/types/store/SessionStorage.js +8 -0
- package/bin/types/store/SessionStorage.js.map +1 -0
- package/bin/types/store/SessionStore.d.ts +5 -3
- package/bin/types/store/SessionStore.d.ts.map +1 -1
- package/package.json +2 -2
- package/scripts/core-engine-context-compaction.test.mjs +96 -219
- package/scripts/core-engine-model-stream.test.mjs +2 -4
- package/scripts/executor-failure-result.test.mjs +14 -17
- package/scripts/session-agent-message-part-order.test.mjs +63 -0
- package/scripts/session-initialization.test.mjs +141 -0
- package/scripts/session-message-timeline.test.mjs +5 -6
- package/scripts/session-messages-error-part.test.mjs +175 -0
- package/scripts/session-messages-error.test.mjs +47 -6
- package/scripts/session-prompt-idempotency.test.mjs +91 -0
- package/scripts/session-queue.test.mjs +13 -12
- package/scripts/session-storage-sqlite.test.mjs +209 -0
- package/scripts/session-turn-context.test.mjs +21 -33
- package/src/agent/Agent.ts +48 -12
- package/src/agent/AgentInstructions.ts +2 -2
- package/src/agent/AgentMemoryStorage.ts +1 -0
- package/src/agent/AgentSessions.ts +31 -12
- package/src/executor/Executor.ts +47 -184
- package/src/executor/README.md +12 -13
- package/src/executor/composer/system/default/SystemPromptAssets.ts +0 -6
- package/src/executor/core-engine/CoreEngineContextCompaction.ts +3 -135
- package/src/executor/core-engine/CoreEngineRunner.ts +51 -273
- package/src/executor/core-engine/CoreEngineSignals.ts +9 -9
- package/src/executor/messages/SessionAttachmentMapper.ts +4 -4
- package/src/executor/messages/SessionMessageLog.ts +3 -3
- package/src/executor/messages/SessionModelMessages.ts +85 -103
- package/src/executor/model/ModelStepRunner.ts +9 -41
- package/src/executor/services/ExecutorRecoveryPolicy.ts +34 -127
- package/src/executor/types/SessionHistoryMeta.ts +1 -3
- package/src/index.ts +39 -47
- package/src/session/DefaultSessionComposer.ts +33 -30
- package/src/session/Session.ts +96 -227
- package/src/session/SessionComposition.ts +28 -65
- package/src/session/SessionLoop.ts +267 -370
- package/src/session/SessionMessages.ts +363 -242
- package/src/session/SessionQueue.ts +3 -2
- package/src/session/SessionState.ts +55 -101
- package/src/session/SessionSystem.ts +51 -1
- package/src/session/SessionTitle.ts +4 -4
- package/src/session/browse/Browse.ts +182 -468
- package/src/session/browse/SessionMessageTimeline.ts +63 -38
- package/src/session/composer/policies/AdaptivePartContextPolicy.ts +307 -0
- package/src/session/composer/policies/FullHistoryContextPolicy.ts +36 -0
- package/src/session/composer/policies/SessionSummaryPrompts.ts +42 -0
- package/src/session/execution/SessionAssistantOutputAdapter.ts +25 -11
- package/src/session/messages/{SessionActionMessageWriter.ts → SessionAgentActionPartWriter.ts} +8 -8
- package/src/session/messages/SessionAgentContent.ts +56 -0
- package/src/session/messages/SessionAgentMessageState.ts +378 -0
- package/src/session/messages/{SessionAssistantMessageWriter.ts → SessionAgentMessageWriter.ts} +89 -60
- package/src/session/messages/SessionForkMessageFiles.ts +25 -1
- package/src/session/messages/SessionMessageInteractionWriter.ts +19 -19
- package/src/session/messages/SessionMessageText.ts +3 -4
- package/src/session/messages/SessionTurnFileDiffData.ts +3 -3
- package/src/session/messages/SessionUserMessage.ts +10 -7
- package/src/session/preview/SessionMessagePreview.ts +26 -9
- package/src/session/runtime/SessionTurnCompletion.ts +159 -0
- package/src/session/runtime/SessionTurnContext.ts +20 -21
- package/src/session/runtime/SessionTurnFileDiff.ts +105 -0
- package/src/session/storage/LocalSessionDataStore.ts +27 -176
- package/src/session/storage/LocalSessionStore.ts +170 -38
- package/src/session/storage/LocalStorePaths.ts +14 -86
- package/src/session/storage/Metadata.ts +4 -13
- package/src/session/storage/RuntimeSessionPort.ts +7 -7
- package/src/session/storage/SessionStorageCodec.ts +465 -0
- package/src/session/storage/SessionStorageSchema.ts +132 -0
- package/src/session/storage/SqliteSessionStorage.ts +776 -0
- package/src/tools/ask/AskQuestionsTool.ts +3 -1
- package/src/types/action/ActionResult.ts +10 -10
- package/src/types/agent/AgentOptions.ts +11 -0
- package/src/types/agent/AgentStorage.ts +3 -1
- package/src/types/agent/SessionActor.ts +0 -10
- package/src/types/agent/SessionTypes.ts +5 -5
- package/src/types/executor/SessionAssistantOutput.ts +15 -4
- package/src/types/executor/SessionTurnContext.ts +25 -22
- package/src/types/sdk/AgentSessionAction.ts +1 -1
- package/src/types/sdk/AgentSessionPrompt.ts +15 -5
- package/src/types/session/AdaptivePartContextPolicy.ts +37 -0
- package/src/types/session/{SessionAssistantMessageState.ts → SessionAgentMessageState.ts} +6 -6
- package/src/types/session/SessionCommand.ts +21 -7
- package/src/types/session/SessionComposer.ts +48 -48
- package/src/types/session/SessionComposition.ts +2 -5
- package/src/types/session/SessionContextPolicy.ts +77 -0
- package/src/types/session/SessionExecution.ts +11 -36
- package/src/types/session/SessionLoop.ts +3 -8
- package/src/types/session/SessionMessages.ts +19 -29
- package/src/types/session/SessionOptions.ts +5 -5
- package/src/types/session/SessionPort.ts +10 -10
- package/src/types/session/SessionState.ts +2 -5
- package/src/types/session/SessionSystem.ts +19 -0
- package/src/types/session/SessionTool.ts +2 -2
- package/src/types/session/SessionTurnCompletion.ts +24 -0
- package/src/types/session/SessionTurnFileDiff.ts +44 -0
- package/src/types/store/LocalStore.ts +6 -14
- package/src/types/store/SessionStorage.ts +121 -0
- package/src/types/store/SessionStore.ts +6 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +0 -45
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +0 -144
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +0 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts +0 -23
- package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +0 -1
- package/bin/executor/composer/system/SessionSystemComposer.js +0 -9
- package/bin/executor/composer/system/SessionSystemComposer.js.map +0 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +0 -43
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +0 -42
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js.map +0 -1
- package/bin/executor/composer/system/default/PromptRenderer.d.ts +0 -35
- package/bin/executor/composer/system/default/PromptRenderer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/PromptRenderer.js +0 -23
- package/bin/executor/composer/system/default/PromptRenderer.js.map +0 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts +0 -151
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +0 -1
- package/bin/executor/composer/system/default/SystemDomain.js +0 -162
- package/bin/executor/composer/system/default/SystemDomain.js.map +0 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/task.prompt.js.map +0 -1
- package/bin/executor/composer/system/default/variables/GeoContext.d.ts +0 -14
- package/bin/executor/composer/system/default/variables/GeoContext.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/GeoContext.js +0 -150
- package/bin/executor/composer/system/default/variables/GeoContext.js.map +0 -1
- package/bin/executor/composer/system/default/variables/PromptTypes.d.ts +0 -36
- package/bin/executor/composer/system/default/variables/PromptTypes.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/PromptTypes.js +0 -9
- package/bin/executor/composer/system/default/variables/PromptTypes.js.map +0 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts +0 -61
- package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.js +0 -93
- package/bin/executor/composer/system/default/variables/VariableReplacer.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +0 -63
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js +0 -81
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +0 -1
- package/bin/session/SessionCommand.d.ts +0 -24
- package/bin/session/SessionCommand.d.ts.map +0 -1
- package/bin/session/SessionCommand.js +0 -35
- package/bin/session/SessionCommand.js.map +0 -1
- package/bin/session/messages/SessionActionMessageWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionActionMessageWriter.js.map +0 -1
- package/bin/session/messages/SessionAssistantMessageState.d.ts +0 -49
- package/bin/session/messages/SessionAssistantMessageState.d.ts.map +0 -1
- package/bin/session/messages/SessionAssistantMessageState.js +0 -296
- package/bin/session/messages/SessionAssistantMessageState.js.map +0 -1
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionAssistantMessageWriter.js.map +0 -1
- package/bin/session/messages/SessionMessageCompaction.d.ts +0 -29
- package/bin/session/messages/SessionMessageCompaction.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageCompaction.js +0 -128
- package/bin/session/messages/SessionMessageCompaction.js.map +0 -1
- package/bin/session/runtime/SessionCompactOperation.d.ts +0 -29
- package/bin/session/runtime/SessionCompactOperation.d.ts.map +0 -1
- package/bin/session/runtime/SessionCompactOperation.js +0 -66
- package/bin/session/runtime/SessionCompactOperation.js.map +0 -1
- package/bin/session/runtime/SessionHistoryCompaction.d.ts +0 -22
- package/bin/session/runtime/SessionHistoryCompaction.d.ts.map +0 -1
- package/bin/session/runtime/SessionHistoryCompaction.js +0 -31
- package/bin/session/runtime/SessionHistoryCompaction.js.map +0 -1
- package/bin/session/storage/JsonlSessionMessageStore.d.ts +0 -77
- package/bin/session/storage/JsonlSessionMessageStore.d.ts.map +0 -1
- package/bin/session/storage/JsonlSessionMessageStore.js +0 -419
- package/bin/session/storage/JsonlSessionMessageStore.js.map +0 -1
- package/bin/session/storage/SessionMessageStoreFactory.d.ts +0 -12
- package/bin/session/storage/SessionMessageStoreFactory.d.ts.map +0 -1
- package/bin/session/storage/SessionMessageStoreFactory.js +0 -13
- package/bin/session/storage/SessionMessageStoreFactory.js.map +0 -1
- package/bin/types/common/Template.d.ts +0 -9
- package/bin/types/common/Template.d.ts.map +0 -1
- package/bin/types/common/Template.js +0 -9
- package/bin/types/common/Template.js.map +0 -1
- package/bin/types/sdk/AgentSessionCompact.d.ts +0 -30
- package/bin/types/sdk/AgentSessionCompact.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionCompact.js +0 -8
- package/bin/types/sdk/AgentSessionCompact.js.map +0 -1
- package/bin/types/session/SessionAssistantMessageState.d.ts.map +0 -1
- package/bin/types/session/SessionAssistantMessageState.js.map +0 -1
- package/bin/types/session/SessionSegment.d.ts +0 -57
- package/bin/types/session/SessionSegment.d.ts.map +0 -1
- package/bin/types/session/SessionSegment.js +0 -8
- package/bin/types/session/SessionSegment.js.map +0 -1
- package/bin/types/store/SessionDataStore.d.ts +0 -88
- package/bin/types/store/SessionDataStore.d.ts.map +0 -1
- package/bin/types/store/SessionDataStore.js +0 -9
- package/bin/types/store/SessionDataStore.js.map +0 -1
- package/bin/utils/Template.d.ts +0 -17
- package/bin/utils/Template.d.ts.map +0 -1
- package/bin/utils/Template.js +0 -24
- package/bin/utils/Template.js.map +0 -1
- package/scripts/session-compaction-prompts.test.mjs +0 -49
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +0 -162
- package/src/executor/composer/system/SessionSystemComposer.ts +0 -25
- package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +0 -76
- package/src/executor/composer/system/default/PromptRenderer.ts +0 -52
- package/src/executor/composer/system/default/SystemDomain.ts +0 -301
- package/src/executor/composer/system/default/assets/task.prompt.ts +0 -9
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +0 -33
- package/src/executor/composer/system/default/variables/GeoContext.ts +0 -180
- package/src/executor/composer/system/default/variables/PromptTypes.ts +0 -37
- package/src/executor/composer/system/default/variables/VariableReplacer.ts +0 -154
- package/src/executor/core-engine/CoreEngineMessageState.ts +0 -117
- package/src/session/SessionCommand.ts +0 -42
- package/src/session/messages/SessionAssistantMessageState.ts +0 -392
- package/src/session/messages/SessionMessageCompaction.ts +0 -160
- package/src/session/runtime/SessionCompactOperation.ts +0 -93
- package/src/session/runtime/SessionHistoryCompaction.ts +0 -45
- package/src/session/storage/JsonlSessionMessageStore.ts +0 -513
- package/src/session/storage/SessionMessageStoreFactory.ts +0 -18
- package/src/types/common/Template.ts +0 -9
- package/src/types/sdk/AgentSessionCompact.ts +0 -32
- package/src/types/session/SessionSegment.ts +0 -62
- package/src/types/store/SessionDataStore.ts +0 -113
- package/src/utils/Template.ts +0 -28
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SystemDomain:system 领域统一实现。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 收敛 system 的资产加载、上下文档位判定、Plugin prompt 收集、messages 组装。
|
|
6
|
-
* - `DefaultSessionSystemComposer` 只做组件适配;核心逻辑统一在本文件。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
|
|
10
|
-
import { transform_prompts_into_system_messages } from "@executor/composer/system/default/PromptRenderer.js";
|
|
11
|
-
import type { SessionHookRuntime } from "@downcity/type";
|
|
12
|
-
import { build_runtime_clock_system_prompt } from "@executor/composer/system/default/variables/VariableReplacer.js";
|
|
13
|
-
import {
|
|
14
|
-
CORE_SYSTEM_PROMPT,
|
|
15
|
-
TASK_SYSTEM_PROMPT,
|
|
16
|
-
} from "@executor/composer/system/default/SystemPromptAssets.js";
|
|
17
|
-
|
|
18
|
-
const DEFAULT_DISABLED_EXTENSION_NAMES: string[] = [];
|
|
19
|
-
|
|
20
|
-
function normalize_system_text(input: string | null | undefined): string {
|
|
21
|
-
return String(input || "").trim();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Ship 默认系统提示模板。
|
|
26
|
-
*/
|
|
27
|
-
export const DEFAULT_SHIP_PROMPTS = CORE_SYSTEM_PROMPT;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 构建一次运行的运行时 system prompt。
|
|
31
|
-
*
|
|
32
|
-
* 关键点(中文)
|
|
33
|
-
* - 仅承载“稳定规则”块,避免把每轮变化字段放在前缀 system。
|
|
34
|
-
* - task 模式下追加任务输出规则;chat 模式为空。
|
|
35
|
-
*/
|
|
36
|
-
export function build_context_system_prompt(input: {
|
|
37
|
-
/**
|
|
38
|
-
* 项目根目录。
|
|
39
|
-
*/
|
|
40
|
-
project_root: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 当前会话 ID。
|
|
44
|
-
*/
|
|
45
|
-
session_id: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 当前 system 模式(默认 chat)。
|
|
49
|
-
*/
|
|
50
|
-
mode?: "chat" | "task";
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 额外上下文行(可选)。
|
|
54
|
-
*/
|
|
55
|
-
extra_context_lines?: string[];
|
|
56
|
-
}): string {
|
|
57
|
-
const { project_root, extra_context_lines } = input;
|
|
58
|
-
const mode = input.mode === "task" ? "task" : "chat";
|
|
59
|
-
if (mode === "chat") return "";
|
|
60
|
-
|
|
61
|
-
const runtimeContextLines: string[] = [
|
|
62
|
-
"Task runtime context:",
|
|
63
|
-
`- Project root: ${project_root}`,
|
|
64
|
-
];
|
|
65
|
-
|
|
66
|
-
if (Array.isArray(extra_context_lines) && extra_context_lines.length > 0) {
|
|
67
|
-
runtimeContextLines.push(...extra_context_lines);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const outputRules = [
|
|
71
|
-
"Task-run output rules:",
|
|
72
|
-
"- This is a task execution context, not an interactive chat turn.",
|
|
73
|
-
"- Do NOT send external channel messages via `downcity chat send` unless explicitly required by the task itself.",
|
|
74
|
-
"- Reply with result-oriented content; do NOT paste raw tool outputs or JSON logs.",
|
|
75
|
-
"- Keep output compact and avoid unnecessary conversational fillers.",
|
|
76
|
-
].join("\n");
|
|
77
|
-
|
|
78
|
-
return [runtimeContextLines.join("\n"), "", outputRules].join("\n");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 解析静态 system prompts。
|
|
83
|
-
*
|
|
84
|
-
* 关键点(中文)
|
|
85
|
-
* - task 执行上下文可替换默认 core prompt(`DEFAULT_SHIP_PROMPTS`)为任务专用提示词。
|
|
86
|
-
* - PROFILE/SOUL 等其他静态提示保持不变。
|
|
87
|
-
*/
|
|
88
|
-
export function resolve_static_system_prompts(input: {
|
|
89
|
-
/**
|
|
90
|
-
* 当前静态 system 文本集合。
|
|
91
|
-
*/
|
|
92
|
-
systems: string[];
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 可选默认 core prompt 替换文本(task 场景常用)。
|
|
96
|
-
*/
|
|
97
|
-
replace_default_core_prompt?: string;
|
|
98
|
-
}): string[] {
|
|
99
|
-
const base = Array.isArray(input.systems) ? [...input.systems] : [];
|
|
100
|
-
const replacement = String(input.replace_default_core_prompt || "").trim();
|
|
101
|
-
if (!replacement) return base;
|
|
102
|
-
return [...base.filter((item) => item !== DEFAULT_SHIP_PROMPTS), replacement];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
type ResolvedSystemContextProfile = {
|
|
106
|
-
mode: "chat" | "task";
|
|
107
|
-
replace_default_core_prompt?: string;
|
|
108
|
-
disabled_plugin_names: string[];
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* System 档位。
|
|
113
|
-
*
|
|
114
|
-
* 关键点(中文)
|
|
115
|
-
* - 由外部创建 system 时显式指定,避免在 system 域猜测业务上下文。
|
|
116
|
-
*/
|
|
117
|
-
export type SystemProfile = "chat" | "task";
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 按显式 profile 解析 system 上下文档位。
|
|
121
|
-
*
|
|
122
|
-
* 关键点(中文)
|
|
123
|
-
* - chat 模式:使用默认 core prompt 与全部 Plugin system。
|
|
124
|
-
* - task 模式:自动替换 task core prompt,并禁用 chat Plugin system。
|
|
125
|
-
*/
|
|
126
|
-
export function resolve_system_context_profile(
|
|
127
|
-
profile?: SystemProfile,
|
|
128
|
-
): ResolvedSystemContextProfile {
|
|
129
|
-
if (profile !== "task") {
|
|
130
|
-
return {
|
|
131
|
-
mode: "chat",
|
|
132
|
-
disabled_plugin_names: [...DEFAULT_DISABLED_EXTENSION_NAMES],
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
mode: "task",
|
|
137
|
-
replace_default_core_prompt: TASK_SYSTEM_PROMPT,
|
|
138
|
-
disabled_plugin_names: ["chat"],
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 收集宿主 Plugin 提供的 system 文本。
|
|
144
|
-
*
|
|
145
|
-
* 关键点(中文)
|
|
146
|
-
* - core prompt 已包含扩展系统总规则;这里只收集各 Plugin 自己的 system prompt。
|
|
147
|
-
* - 单个 Plugin 是否可用由宿主投影的运行时负责。
|
|
148
|
-
*/
|
|
149
|
-
export async function load_plugin_system_prompts(input: {
|
|
150
|
-
/**
|
|
151
|
-
* 当前执行上下文。
|
|
152
|
-
*/
|
|
153
|
-
hooks: SessionHookRuntime;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 当前轮禁用的 Plugin 名称集合。
|
|
157
|
-
*/
|
|
158
|
-
disabled_plugin_names: string[];
|
|
159
|
-
}): Promise<string[]> {
|
|
160
|
-
const out: string[] = [];
|
|
161
|
-
const disabled_plugin_names = new Set(
|
|
162
|
-
input.disabled_plugin_names
|
|
163
|
-
.map((item) => String(item || "").trim())
|
|
164
|
-
.filter(Boolean),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
const blocks = await input.hooks.system_blocks();
|
|
168
|
-
for (const block of blocks) {
|
|
169
|
-
if (disabled_plugin_names.has(block.name)) continue;
|
|
170
|
-
const text = normalize_system_text(block.content);
|
|
171
|
-
if (text) out.push(text);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return out;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 统一构建一次 Session 运行所需的 system messages。
|
|
179
|
-
*
|
|
180
|
-
* 关键点(中文)
|
|
181
|
-
* - context/static/extension 的组装逻辑统一收敛在 system 域。
|
|
182
|
-
*/
|
|
183
|
-
export async function build_session_system_messages(input: {
|
|
184
|
-
/**
|
|
185
|
-
* 项目根目录(用于模板变量和运行态上下文)。
|
|
186
|
-
*/
|
|
187
|
-
project_root: string;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* 当前会话 ID。
|
|
191
|
-
*/
|
|
192
|
-
session_id: string;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 本轮模式(chat/task)。
|
|
196
|
-
*/
|
|
197
|
-
mode?: "chat" | "task";
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 可选默认 core prompt 替换文本(task 场景常用)。
|
|
201
|
-
*/
|
|
202
|
-
replace_default_core_prompt?: string;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* 静态 system 文本集合(profile/soul/user/default)。
|
|
206
|
-
*/
|
|
207
|
-
static_system_prompts: string[];
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* 宿主 Plugin 提供的 system 文本集合。
|
|
211
|
-
*/
|
|
212
|
-
plugin_system_prompts: string[];
|
|
213
|
-
}): Promise<SessionSystemMessage[]> {
|
|
214
|
-
const runtimeClockText = build_runtime_clock_system_prompt({
|
|
215
|
-
projectPath: input.project_root,
|
|
216
|
-
session_id: input.session_id,
|
|
217
|
-
});
|
|
218
|
-
const runtimeClockMessages: SessionSystemMessage[] = runtimeClockText
|
|
219
|
-
? [{ role: "system", content: runtimeClockText }]
|
|
220
|
-
: [];
|
|
221
|
-
const runtimeSystemText = build_context_system_prompt({
|
|
222
|
-
project_root: input.project_root,
|
|
223
|
-
session_id: input.session_id,
|
|
224
|
-
mode: input.mode,
|
|
225
|
-
});
|
|
226
|
-
const runtimeRuleMessages: SessionSystemMessage[] = runtimeSystemText
|
|
227
|
-
? [{ role: "system", content: runtimeSystemText }]
|
|
228
|
-
: [];
|
|
229
|
-
|
|
230
|
-
const staticSystemMessages = await transform_prompts_into_system_messages(
|
|
231
|
-
resolve_static_system_prompts({
|
|
232
|
-
systems: input.static_system_prompts,
|
|
233
|
-
replace_default_core_prompt: input.replace_default_core_prompt,
|
|
234
|
-
}),
|
|
235
|
-
{
|
|
236
|
-
projectPath: input.project_root,
|
|
237
|
-
variableMode: "stable",
|
|
238
|
-
},
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
const plugin_system_messages = await transform_prompts_into_system_messages(
|
|
242
|
-
Array.isArray(input.plugin_system_prompts)
|
|
243
|
-
? input.plugin_system_prompts
|
|
244
|
-
: [],
|
|
245
|
-
{
|
|
246
|
-
projectPath: input.project_root,
|
|
247
|
-
variableMode: "stable",
|
|
248
|
-
},
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
return [
|
|
252
|
-
...staticSystemMessages,
|
|
253
|
-
...plugin_system_messages,
|
|
254
|
-
...runtimeRuleMessages,
|
|
255
|
-
...runtimeClockMessages,
|
|
256
|
-
];
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* 统一解析一次 Session 运行所需的 system messages(含上下文档位判定与 Plugin 收集)。
|
|
261
|
-
*/
|
|
262
|
-
export async function resolve_session_system_messages(input: {
|
|
263
|
-
/**
|
|
264
|
-
* 项目根目录。
|
|
265
|
-
*/
|
|
266
|
-
project_root: string;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* 当前会话 ID。
|
|
270
|
-
*/
|
|
271
|
-
session_id: string;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 当前 system 档位(默认 chat)。
|
|
275
|
-
*/
|
|
276
|
-
profile?: SystemProfile;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* 当前静态 system 文本集合。
|
|
280
|
-
*/
|
|
281
|
-
static_system_prompts: string[];
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* 当前执行上下文。
|
|
285
|
-
*/
|
|
286
|
-
hooks: SessionHookRuntime;
|
|
287
|
-
|
|
288
|
-
}): Promise<SessionSystemMessage[]> {
|
|
289
|
-
const profile = resolve_system_context_profile(input.profile);
|
|
290
|
-
return await build_session_system_messages({
|
|
291
|
-
project_root: input.project_root,
|
|
292
|
-
session_id: input.session_id,
|
|
293
|
-
mode: profile.mode,
|
|
294
|
-
replace_default_core_prompt: profile.replace_default_core_prompt,
|
|
295
|
-
static_system_prompts: input.static_system_prompts,
|
|
296
|
-
plugin_system_prompts: await load_plugin_system_prompts({
|
|
297
|
-
hooks: input.hooks,
|
|
298
|
-
disabled_plugin_names: profile.disabled_plugin_names,
|
|
299
|
-
}),
|
|
300
|
-
});
|
|
301
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 自动生成文件,请勿手改。
|
|
3
|
-
* 源文件:由同路径 `*.ts.txt` 生成。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Source: src/executor/composer/system/default/assets/task.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "You are executing an internal Task-system job, not a chat conversation.\n\nRuntime constraints:\n- This context is for task execution and auditing, not a user chat turn.\n- Unless the task body explicitly asks for it, do not call the chat plugin send action or any external-channel sending action.\n- Do not act like a real-time support agent. Prioritize completing the task objective and producing an auditable result.\n- You may produce necessary intermediate notes during execution, but your final assistant message will be treated directly as `output.md` and as the final content to send.\n\nOutput principles:\n- Your final assistant message must be the task deliverable itself.\n- The final assistant message must not include process reports, status summaries, task-management notes, or sending notes.\n- Prefer reusable, structured, concise result content.\n- Do not echo long raw logs. Summarize them and include only the key conclusions when needed.\n- If the task input requires a fixed format such as JSON, follow that format strictly.\n- If the task asks to \"send to the current conversation\" or \"send to the user\", assume the system will send your final assistant message back directly. Therefore, output exactly the text that should be sent to the user.\n- Unless the task body explicitly requests an execution summary, the final assistant message must not say \"task completed\", \"sent\", \"I will take a look\", \"I will handle this for you\", or similar meta language.\n\nCommon content that is forbidden in the final assistant message:\n- \"I will help you...\"\n- \"First, let me...\"\n- \"I see there is already a task with the same name...\"\n- \"Task sent / completed / updated...\"\n- \"Task status summary...\"\n- Any explanatory text centered on task-management workflow.\n\nFinal self-check:\n- Before finishing, check whether your final assistant message is the final deliverable itself.\n- If the final assistant message mainly describes the process, task status, or sending state rather than the final content, the output direction is wrong and must be rewritten.\n- If removing phrases such as \"I will\", \"first\", \"sent\", or \"task status\" leaves almost no useful content, it is not a valid task output.\n\nContext principles:\n- This task context is an independent execution context. It does not inherit the chat conversation goal.\n- If these rules conflict with other system prompts, the task execution context rules take precedence.\n";
|
|
8
|
-
|
|
9
|
-
export default TEXT_MODULE_CONTENT;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
You are executing an internal Task-system job, not a chat conversation.
|
|
2
|
-
|
|
3
|
-
Runtime constraints:
|
|
4
|
-
- This context is for task execution and auditing, not a user chat turn.
|
|
5
|
-
- Unless the task body explicitly asks for it, do not call the chat plugin send action or any external-channel sending action.
|
|
6
|
-
- Do not act like a real-time support agent. Prioritize completing the task objective and producing an auditable result.
|
|
7
|
-
- You may produce necessary intermediate notes during execution, but your final assistant message will be treated directly as `output.md` and as the final content to send.
|
|
8
|
-
|
|
9
|
-
Output principles:
|
|
10
|
-
- Your final assistant message must be the task deliverable itself.
|
|
11
|
-
- The final assistant message must not include process reports, status summaries, task-management notes, or sending notes.
|
|
12
|
-
- Prefer reusable, structured, concise result content.
|
|
13
|
-
- Do not echo long raw logs. Summarize them and include only the key conclusions when needed.
|
|
14
|
-
- If the task input requires a fixed format such as JSON, follow that format strictly.
|
|
15
|
-
- If the task asks to "send to the current conversation" or "send to the user", assume the system will send your final assistant message back directly. Therefore, output exactly the text that should be sent to the user.
|
|
16
|
-
- Unless the task body explicitly requests an execution summary, the final assistant message must not say "task completed", "sent", "I will take a look", "I will handle this for you", or similar meta language.
|
|
17
|
-
|
|
18
|
-
Common content that is forbidden in the final assistant message:
|
|
19
|
-
- "I will help you..."
|
|
20
|
-
- "First, let me..."
|
|
21
|
-
- "I see there is already a task with the same name..."
|
|
22
|
-
- "Task sent / completed / updated..."
|
|
23
|
-
- "Task status summary..."
|
|
24
|
-
- Any explanatory text centered on task-management workflow.
|
|
25
|
-
|
|
26
|
-
Final self-check:
|
|
27
|
-
- Before finishing, check whether your final assistant message is the final deliverable itself.
|
|
28
|
-
- If the final assistant message mainly describes the process, task status, or sending state rather than the final content, the output direction is wrong and must be rewritten.
|
|
29
|
-
- If removing phrases such as "I will", "first", "sent", or "task status" leaves almost no useful content, it is not a valid task output.
|
|
30
|
-
|
|
31
|
-
Context principles:
|
|
32
|
-
- This task context is an independent execution context. It does not inherit the chat conversation goal.
|
|
33
|
-
- If these rules conflict with other system prompts, the task execution context rules take precedence.
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prompt 地理上下文解析器。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 基于公网 IP 服务推断 location + timezone。
|
|
6
|
-
* - 失败时回退到本机时区,保证 prompt 渲染稳定可用。
|
|
7
|
-
* - 使用进程内缓存,避免每次请求都访问外部服务。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { PromptGeoContext } from "@executor/composer/system/default/variables/PromptTypes.js";
|
|
11
|
-
|
|
12
|
-
type IpApiCoResponse = {
|
|
13
|
-
ip?: unknown;
|
|
14
|
-
city?: unknown;
|
|
15
|
-
region?: unknown;
|
|
16
|
-
country_name?: unknown;
|
|
17
|
-
timezone?: unknown;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type IpWhoIsResponse = {
|
|
21
|
-
success?: unknown;
|
|
22
|
-
ip?: unknown;
|
|
23
|
-
city?: unknown;
|
|
24
|
-
region?: unknown;
|
|
25
|
-
country?: unknown;
|
|
26
|
-
timezone?: unknown;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const GEO_CACHE_TTL_MS = 30 * 60 * 1000;
|
|
30
|
-
const GEO_REQUEST_TIMEOUT_MS = 3000;
|
|
31
|
-
|
|
32
|
-
let cachedGeoContext:
|
|
33
|
-
| {
|
|
34
|
-
value: PromptGeoContext;
|
|
35
|
-
expires_at: number;
|
|
36
|
-
}
|
|
37
|
-
| null = null;
|
|
38
|
-
let inFlightGeoContext: Promise<PromptGeoContext> | null = null;
|
|
39
|
-
|
|
40
|
-
function readString(input: unknown): string | null {
|
|
41
|
-
if (typeof input !== "string") return null;
|
|
42
|
-
const value = input.trim();
|
|
43
|
-
return value ? value : null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function isValidIanaTimezone(input: string | null): input is string {
|
|
47
|
-
if (!input) return false;
|
|
48
|
-
try {
|
|
49
|
-
new Intl.DateTimeFormat("en-US", { timeZone: input });
|
|
50
|
-
return true;
|
|
51
|
-
} catch {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function buildLocation(parts: Array<unknown>): string {
|
|
57
|
-
const values = parts.map(readString).filter((item): item is string => Boolean(item));
|
|
58
|
-
return values.length > 0 ? values.join(", ") : "Unknown";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function buildFallbackGeoContext(): PromptGeoContext {
|
|
62
|
-
const timezone = readString(Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
63
|
-
const safeTimezone = isValidIanaTimezone(timezone) ? timezone : "UTC";
|
|
64
|
-
return {
|
|
65
|
-
ip: "unknown",
|
|
66
|
-
location: "Unknown",
|
|
67
|
-
timezone: safeTimezone,
|
|
68
|
-
source: "local",
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function writeCache(value: PromptGeoContext): PromptGeoContext {
|
|
73
|
-
cachedGeoContext = {
|
|
74
|
-
value,
|
|
75
|
-
expires_at: Date.now() + GEO_CACHE_TTL_MS,
|
|
76
|
-
};
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function fetchIpApiGeoContext(): Promise<PromptGeoContext | null> {
|
|
81
|
-
let response: Response;
|
|
82
|
-
try {
|
|
83
|
-
response = await fetch("https://ipapi.co/json/", {
|
|
84
|
-
headers: {
|
|
85
|
-
Accept: "application/json",
|
|
86
|
-
},
|
|
87
|
-
signal: AbortSignal.timeout(GEO_REQUEST_TIMEOUT_MS),
|
|
88
|
-
});
|
|
89
|
-
} catch {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
if (!response.ok) return null;
|
|
93
|
-
|
|
94
|
-
let data: IpApiCoResponse;
|
|
95
|
-
try {
|
|
96
|
-
data = (await response.json()) as IpApiCoResponse;
|
|
97
|
-
} catch {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const timezone = readString(data.timezone);
|
|
102
|
-
if (!isValidIanaTimezone(timezone)) return null;
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
ip: readString(data.ip) || "unknown",
|
|
106
|
-
location: buildLocation([data.city, data.region, data.country_name]),
|
|
107
|
-
timezone,
|
|
108
|
-
source: "ipapi",
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function readIpWhoIsTimezone(input: unknown): string | null {
|
|
113
|
-
if (typeof input === "string") return readString(input);
|
|
114
|
-
if (!input || typeof input !== "object") return null;
|
|
115
|
-
return readString((input as { id?: unknown }).id);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function fetchIpWhoIsGeoContext(): Promise<PromptGeoContext | null> {
|
|
119
|
-
let response: Response;
|
|
120
|
-
try {
|
|
121
|
-
response = await fetch("https://ipwho.is/", {
|
|
122
|
-
headers: {
|
|
123
|
-
Accept: "application/json",
|
|
124
|
-
},
|
|
125
|
-
signal: AbortSignal.timeout(GEO_REQUEST_TIMEOUT_MS),
|
|
126
|
-
});
|
|
127
|
-
} catch {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
if (!response.ok) return null;
|
|
131
|
-
|
|
132
|
-
let data: IpWhoIsResponse;
|
|
133
|
-
try {
|
|
134
|
-
data = (await response.json()) as IpWhoIsResponse;
|
|
135
|
-
} catch {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (data.success === false) return null;
|
|
140
|
-
|
|
141
|
-
const timezone = readIpWhoIsTimezone(data.timezone);
|
|
142
|
-
if (!isValidIanaTimezone(timezone)) return null;
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
ip: readString(data.ip) || "unknown",
|
|
146
|
-
location: buildLocation([data.city, data.region, data.country]),
|
|
147
|
-
timezone,
|
|
148
|
-
source: "ipwhois",
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async function loadGeoContext(): Promise<PromptGeoContext> {
|
|
153
|
-
const now = Date.now();
|
|
154
|
-
if (cachedGeoContext && now < cachedGeoContext.expires_at) {
|
|
155
|
-
return cachedGeoContext.value;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (inFlightGeoContext) return inFlightGeoContext;
|
|
159
|
-
|
|
160
|
-
inFlightGeoContext = (async () => {
|
|
161
|
-
const ipApiResult = await fetchIpApiGeoContext();
|
|
162
|
-
if (ipApiResult) return writeCache(ipApiResult);
|
|
163
|
-
|
|
164
|
-
const ipWhoIsResult = await fetchIpWhoIsGeoContext();
|
|
165
|
-
if (ipWhoIsResult) return writeCache(ipWhoIsResult);
|
|
166
|
-
|
|
167
|
-
return writeCache(buildFallbackGeoContext());
|
|
168
|
-
})().finally(() => {
|
|
169
|
-
inFlightGeoContext = null;
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return inFlightGeoContext;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* 解析 prompt 所需地理上下文。
|
|
177
|
-
*/
|
|
178
|
-
export async function resolve_prompt_geo_context(): Promise<PromptGeoContext> {
|
|
179
|
-
return loadGeoContext();
|
|
180
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prompt 模板变量类型。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 统一描述 prompt template 支持的运行时变量结构。
|
|
6
|
-
* - 供模板渲染与地理位置解析模块复用,避免隐式约定。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export interface PromptGeoContext {
|
|
10
|
-
/** 公网 IP;当外部服务不可用时回退为 `unknown`。 */
|
|
11
|
-
ip: string;
|
|
12
|
-
/** 地理解析后的地点描述,用于提示模型当前大致位置。 */
|
|
13
|
-
location: string;
|
|
14
|
-
/** IANA 时区标识,例如 `Asia/Shanghai`。 */
|
|
15
|
-
timezone: string;
|
|
16
|
-
/** 地理上下文来源。 */
|
|
17
|
-
source: "ipapi" | "ipwhois" | "local";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface PromptVariables {
|
|
21
|
-
/** 当前日期字符串,按当前时区格式化为 `YYYY-MM-DD`。 */
|
|
22
|
-
currentDate: string;
|
|
23
|
-
/** 当前时间字符串,包含日期、时分秒与时区信息。 */
|
|
24
|
-
currentTime: string;
|
|
25
|
-
/** 当前年份字符串,用于显式提示“现在是几几年”。 */
|
|
26
|
-
currentYear: string;
|
|
27
|
-
/** 当前运行时使用的 IANA 时区标识,例如 `Asia/Shanghai`。 */
|
|
28
|
-
timezone: string;
|
|
29
|
-
/** 当前地理位置描述。 */
|
|
30
|
-
location: string;
|
|
31
|
-
/** 当前项目路径。 */
|
|
32
|
-
projectPath: string;
|
|
33
|
-
/** 当前项目根路径。 */
|
|
34
|
-
project_root: string;
|
|
35
|
-
/** 当前会话标识。 */
|
|
36
|
-
session_id: string;
|
|
37
|
-
}
|