actoviq-agent-sdk 0.4.11 → 0.4.13
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/CHANGELOG.md +42 -0
- package/dist/src/computer/hadamardComputerUse.d.ts +15 -0
- package/dist/src/computer/hadamardComputerUse.d.ts.map +1 -1
- package/dist/src/computer/hadamardComputerUse.js +120 -4
- package/dist/src/computer/hadamardComputerUse.js.map +1 -1
- package/dist/src/config/agentDefinitionMigration.d.ts +125 -0
- package/dist/src/config/agentDefinitionMigration.d.ts.map +1 -0
- package/dist/src/config/agentDefinitionMigration.js +540 -0
- package/dist/src/config/agentDefinitionMigration.js.map +1 -0
- package/dist/src/config/agentProfiles.d.ts +23 -0
- package/dist/src/config/agentProfiles.d.ts.map +1 -1
- package/dist/src/config/agentProfiles.js +69 -13
- package/dist/src/config/agentProfiles.js.map +1 -1
- package/dist/src/config/hadamardHome.js +0 -1
- package/dist/src/config/hadamardHome.js.map +1 -1
- package/dist/src/config/modelConfigurationCatalog.d.ts +25 -0
- package/dist/src/config/modelConfigurationCatalog.d.ts.map +1 -0
- package/dist/src/config/modelConfigurationCatalog.js +50 -0
- package/dist/src/config/modelConfigurationCatalog.js.map +1 -0
- package/dist/src/config/projectSettings.d.ts +62 -0
- package/dist/src/config/projectSettings.d.ts.map +1 -0
- package/dist/src/config/projectSettings.js +242 -0
- package/dist/src/config/projectSettings.js.map +1 -0
- package/dist/src/config/resolveRuntimeConfig.d.ts.map +1 -1
- package/dist/src/config/resolveRuntimeConfig.js +97 -4
- package/dist/src/config/resolveRuntimeConfig.js.map +1 -1
- package/dist/src/goal/goalCommandService.d.ts +11 -0
- package/dist/src/goal/goalCommandService.d.ts.map +1 -0
- package/dist/src/goal/goalCommandService.js +138 -0
- package/dist/src/goal/goalCommandService.js.map +1 -0
- package/dist/src/goal/goalContinuation.d.ts +50 -0
- package/dist/src/goal/goalContinuation.d.ts.map +1 -0
- package/dist/src/goal/goalContinuation.js +131 -0
- package/dist/src/goal/goalContinuation.js.map +1 -0
- package/dist/src/goal/goalController.d.ts +42 -0
- package/dist/src/goal/goalController.d.ts.map +1 -0
- package/dist/src/goal/goalController.js +281 -0
- package/dist/src/goal/goalController.js.map +1 -0
- package/dist/src/goal/goalPrompt.d.ts +3 -0
- package/dist/src/goal/goalPrompt.d.ts.map +1 -1
- package/dist/src/goal/goalPrompt.js +28 -2
- package/dist/src/goal/goalPrompt.js.map +1 -1
- package/dist/src/goal/goalService.d.ts +68 -2
- package/dist/src/goal/goalService.d.ts.map +1 -1
- package/dist/src/goal/goalService.js +500 -8
- package/dist/src/goal/goalService.js.map +1 -1
- package/dist/src/goal/goalStore.d.ts.map +1 -1
- package/dist/src/goal/goalStore.js +172 -5
- package/dist/src/goal/goalStore.js.map +1 -1
- package/dist/src/goal/goalTools.d.ts +2 -1
- package/dist/src/goal/goalTools.d.ts.map +1 -1
- package/dist/src/goal/goalTools.js +70 -5
- package/dist/src/goal/goalTools.js.map +1 -1
- package/dist/src/goal/goalWorkCoordinator.d.ts +43 -0
- package/dist/src/goal/goalWorkCoordinator.d.ts.map +1 -0
- package/dist/src/goal/goalWorkCoordinator.js +72 -0
- package/dist/src/goal/goalWorkCoordinator.js.map +1 -0
- package/dist/src/goal/index.d.ts +10 -4
- package/dist/src/goal/index.d.ts.map +1 -1
- package/dist/src/goal/index.js +7 -1
- package/dist/src/goal/index.js.map +1 -1
- package/dist/src/goal/projectGoalApi.d.ts +82 -0
- package/dist/src/goal/projectGoalApi.d.ts.map +1 -0
- package/dist/src/goal/projectGoalApi.js +287 -0
- package/dist/src/goal/projectGoalApi.js.map +1 -0
- package/dist/src/goal/projectGoalStore.d.ts +131 -0
- package/dist/src/goal/projectGoalStore.d.ts.map +1 -0
- package/dist/src/goal/projectGoalStore.js +808 -0
- package/dist/src/goal/projectGoalStore.js.map +1 -0
- package/dist/src/goal/types.d.ts +127 -3
- package/dist/src/goal/types.d.ts.map +1 -1
- package/dist/src/goal/types.js +2 -2
- package/dist/src/goal/types.js.map +1 -1
- package/dist/src/gui/agentTargetPicker.d.ts +32 -0
- package/dist/src/gui/agentTargetPicker.d.ts.map +1 -0
- package/dist/src/gui/agentTargetPicker.js +99 -0
- package/dist/src/gui/agentTargetPicker.js.map +1 -0
- package/dist/src/gui/electronMain.js +10 -3
- package/dist/src/gui/electronMain.js.map +1 -1
- package/dist/src/gui/hadamardGui.d.ts +24 -0
- package/dist/src/gui/hadamardGui.d.ts.map +1 -1
- package/dist/src/gui/hadamardGui.js +6321 -1327
- package/dist/src/gui/hadamardGui.js.map +1 -1
- package/dist/src/gui/projectWorkbench.d.ts +13 -2
- package/dist/src/gui/projectWorkbench.d.ts.map +1 -1
- package/dist/src/gui/projectWorkbench.js +109 -67
- package/dist/src/gui/projectWorkbench.js.map +1 -1
- package/dist/src/gui/promptTemplates.d.ts +18 -0
- package/dist/src/gui/promptTemplates.d.ts.map +1 -0
- package/dist/src/gui/promptTemplates.js +178 -0
- package/dist/src/gui/promptTemplates.js.map +1 -0
- package/dist/src/gui/terminalManager.d.ts +14 -0
- package/dist/src/gui/terminalManager.d.ts.map +1 -1
- package/dist/src/gui/terminalManager.js +25 -5
- package/dist/src/gui/terminalManager.js.map +1 -1
- package/dist/src/gui/transcript/clientBundle.d.ts +6 -1
- package/dist/src/gui/transcript/clientBundle.d.ts.map +1 -1
- package/dist/src/gui/transcript/clientBundle.js +6 -1
- package/dist/src/gui/transcript/clientBundle.js.map +1 -1
- package/dist/src/help/productCapabilities.d.ts +17 -0
- package/dist/src/help/productCapabilities.d.ts.map +1 -0
- package/dist/src/help/productCapabilities.js +146 -0
- package/dist/src/help/productCapabilities.js.map +1 -0
- package/dist/src/index.d.ts +21 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +15 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/issues/issueExecution.d.ts.map +1 -1
- package/dist/src/issues/issueExecution.js +29 -9
- package/dist/src/issues/issueExecution.js.map +1 -1
- package/dist/src/manager/assistantGlobalTools.d.ts +44 -0
- package/dist/src/manager/assistantGlobalTools.d.ts.map +1 -1
- package/dist/src/manager/assistantGlobalTools.js +565 -34
- package/dist/src/manager/assistantGlobalTools.js.map +1 -1
- package/dist/src/manager/assistantProposals.d.ts +87 -0
- package/dist/src/manager/assistantProposals.d.ts.map +1 -0
- package/dist/src/manager/assistantProposals.js +207 -0
- package/dist/src/manager/assistantProposals.js.map +1 -0
- package/dist/src/manager/referenceIndex.d.ts +82 -0
- package/dist/src/manager/referenceIndex.d.ts.map +1 -0
- package/dist/src/manager/referenceIndex.js +167 -0
- package/dist/src/manager/referenceIndex.js.map +1 -0
- package/dist/src/manager/referenceOperations.d.ts +108 -0
- package/dist/src/manager/referenceOperations.d.ts.map +1 -0
- package/dist/src/manager/referenceOperations.js +821 -0
- package/dist/src/manager/referenceOperations.js.map +1 -0
- package/dist/src/manager/resolveTargetRef.d.ts +67 -0
- package/dist/src/manager/resolveTargetRef.d.ts.map +1 -0
- package/dist/src/manager/resolveTargetRef.js +81 -0
- package/dist/src/manager/resolveTargetRef.js.map +1 -0
- package/dist/src/memory/durableMemoryPipeline.d.ts +51 -0
- package/dist/src/memory/durableMemoryPipeline.d.ts.map +1 -0
- package/dist/src/memory/durableMemoryPipeline.js +266 -0
- package/dist/src/memory/durableMemoryPipeline.js.map +1 -0
- package/dist/src/memory/durableMemoryStore.d.ts +59 -0
- package/dist/src/memory/durableMemoryStore.d.ts.map +1 -0
- package/dist/src/memory/durableMemoryStore.js +194 -0
- package/dist/src/memory/durableMemoryStore.js.map +1 -0
- package/dist/src/memory/hadamardDream.d.ts +18 -0
- package/dist/src/memory/hadamardDream.d.ts.map +1 -1
- package/dist/src/memory/hadamardDream.js +119 -39
- package/dist/src/memory/hadamardDream.js.map +1 -1
- package/dist/src/memory/hadamardMemory.d.ts +20 -39
- package/dist/src/memory/hadamardMemory.d.ts.map +1 -1
- package/dist/src/memory/hadamardMemory.js +112 -450
- package/dist/src/memory/hadamardMemory.js.map +1 -1
- package/dist/src/memory/hadamardSessionMemoryState.d.ts +2 -5
- package/dist/src/memory/hadamardSessionMemoryState.d.ts.map +1 -1
- package/dist/src/memory/hadamardSessionMemoryState.js +5 -61
- package/dist/src/memory/hadamardSessionMemoryState.js.map +1 -1
- package/dist/src/memory/memoryCommandService.d.ts +25 -0
- package/dist/src/memory/memoryCommandService.d.ts.map +1 -0
- package/dist/src/memory/memoryCommandService.js +93 -0
- package/dist/src/memory/memoryCommandService.js.map +1 -0
- package/dist/src/memory/memoryProposalCommandService.d.ts.map +1 -1
- package/dist/src/memory/memoryProposalCommandService.js +2 -1
- package/dist/src/memory/memoryProposalCommandService.js.map +1 -1
- package/dist/src/memory/memoryProposalTools.d.ts +1 -0
- package/dist/src/memory/memoryProposalTools.d.ts.map +1 -1
- package/dist/src/memory/memoryProposalTools.js +16 -11
- package/dist/src/memory/memoryProposalTools.js.map +1 -1
- package/dist/src/parity/bridgeConfigs.d.ts +4 -0
- package/dist/src/parity/bridgeConfigs.d.ts.map +1 -1
- package/dist/src/parity/bridgeConfigs.js +30 -1
- package/dist/src/parity/bridgeConfigs.js.map +1 -1
- package/dist/src/router/modelRouter.d.ts +22 -2
- package/dist/src/router/modelRouter.d.ts.map +1 -1
- package/dist/src/router/modelRouter.js +76 -9
- package/dist/src/router/modelRouter.js.map +1 -1
- package/dist/src/runtime/agentClient.d.ts +24 -4
- package/dist/src/runtime/agentClient.d.ts.map +1 -1
- package/dist/src/runtime/agentClient.js +581 -262
- package/dist/src/runtime/agentClient.js.map +1 -1
- package/dist/src/runtime/agentSession.d.ts +8 -3
- package/dist/src/runtime/agentSession.d.ts.map +1 -1
- package/dist/src/runtime/agentSession.js +10 -3
- package/dist/src/runtime/agentSession.js.map +1 -1
- package/dist/src/runtime/agentTemplates.d.ts +28 -0
- package/dist/src/runtime/agentTemplates.d.ts.map +1 -0
- package/dist/src/runtime/agentTemplates.js +73 -0
- package/dist/src/runtime/agentTemplates.js.map +1 -0
- package/dist/src/runtime/conversationEngine.d.ts +4 -0
- package/dist/src/runtime/conversationEngine.d.ts.map +1 -1
- package/dist/src/runtime/conversationEngine.js +52 -3
- package/dist/src/runtime/conversationEngine.js.map +1 -1
- package/dist/src/runtime/defaultHadamardAgents.d.ts.map +1 -1
- package/dist/src/runtime/defaultHadamardAgents.js +9 -47
- package/dist/src/runtime/defaultHadamardAgents.js.map +1 -1
- package/dist/src/runtime/effectiveAgentRunOptions.d.ts +49 -0
- package/dist/src/runtime/effectiveAgentRunOptions.d.ts.map +1 -0
- package/dist/src/runtime/effectiveAgentRunOptions.js +50 -0
- package/dist/src/runtime/effectiveAgentRunOptions.js.map +1 -0
- package/dist/src/runtime/externalAgentRunner.d.ts +25 -0
- package/dist/src/runtime/externalAgentRunner.d.ts.map +1 -0
- package/dist/src/runtime/externalAgentRunner.js +57 -0
- package/dist/src/runtime/externalAgentRunner.js.map +1 -0
- package/dist/src/runtime/hadamardAgentDefinitions.d.ts +15 -0
- package/dist/src/runtime/hadamardAgentDefinitions.d.ts.map +1 -1
- package/dist/src/runtime/hadamardAgentDefinitions.js +42 -2
- package/dist/src/runtime/hadamardAgentDefinitions.js.map +1 -1
- package/dist/src/runtime/hadamardAgents.d.ts +6 -0
- package/dist/src/runtime/hadamardAgents.d.ts.map +1 -1
- package/dist/src/runtime/hadamardAgents.js +52 -1
- package/dist/src/runtime/hadamardAgents.js.map +1 -1
- package/dist/src/runtime/hadamardCompact.d.ts +12 -1
- package/dist/src/runtime/hadamardCompact.d.ts.map +1 -1
- package/dist/src/runtime/hadamardCompact.js +91 -35
- package/dist/src/runtime/hadamardCompact.js.map +1 -1
- package/dist/src/runtime/hadamardPermissions.d.ts +1 -0
- package/dist/src/runtime/hadamardPermissions.d.ts.map +1 -1
- package/dist/src/runtime/hadamardPermissions.js +6 -0
- package/dist/src/runtime/hadamardPermissions.js.map +1 -1
- package/dist/src/runtime/hadamardSlashCommands.d.ts +7 -1
- package/dist/src/runtime/hadamardSlashCommands.d.ts.map +1 -1
- package/dist/src/runtime/hadamardSlashCommands.js +47 -5
- package/dist/src/runtime/hadamardSlashCommands.js.map +1 -1
- package/dist/src/runtime/tools.d.ts.map +1 -1
- package/dist/src/runtime/tools.js +2 -0
- package/dist/src/runtime/tools.js.map +1 -1
- package/dist/src/team/executorTarget.d.ts +26 -0
- package/dist/src/team/executorTarget.d.ts.map +1 -0
- package/dist/src/team/executorTarget.js +15 -0
- package/dist/src/team/executorTarget.js.map +1 -0
- package/dist/src/team/modelTeam.d.ts +5 -1
- package/dist/src/team/modelTeam.d.ts.map +1 -1
- package/dist/src/team/modelTeam.js +157 -41
- package/dist/src/team/modelTeam.js.map +1 -1
- package/dist/src/team/teamComposition.d.ts +20 -0
- package/dist/src/team/teamComposition.d.ts.map +1 -0
- package/dist/src/team/teamComposition.js +78 -0
- package/dist/src/team/teamComposition.js.map +1 -0
- package/dist/src/team/teamDefinitions.d.ts +10 -1
- package/dist/src/team/teamDefinitions.d.ts.map +1 -1
- package/dist/src/team/teamDefinitions.js +123 -16
- package/dist/src/team/teamDefinitions.js.map +1 -1
- package/dist/src/team/teamGraph.d.ts +1 -1
- package/dist/src/team/teamGraph.d.ts.map +1 -1
- package/dist/src/team/teamGraph.js +1 -1
- package/dist/src/team/teamGraph.js.map +1 -1
- package/dist/src/team/teamPrompts.d.ts.map +1 -1
- package/dist/src/team/teamPrompts.js +0 -4
- package/dist/src/team/teamPrompts.js.map +1 -1
- package/dist/src/team/teamProposalService.d.ts +9 -1
- package/dist/src/team/teamProposalService.d.ts.map +1 -1
- package/dist/src/team/teamProposalService.js +66 -6
- package/dist/src/team/teamProposalService.js.map +1 -1
- package/dist/src/team/teamPropose.d.ts +3 -1
- package/dist/src/team/teamPropose.d.ts.map +1 -1
- package/dist/src/team/teamPropose.js +16 -10
- package/dist/src/team/teamPropose.js.map +1 -1
- package/dist/src/team/teamRuntime.d.ts +5 -0
- package/dist/src/team/teamRuntime.d.ts.map +1 -1
- package/dist/src/team/teamRuntime.js +23 -5
- package/dist/src/team/teamRuntime.js.map +1 -1
- package/dist/src/team/workflowSquad.d.ts +10 -2
- package/dist/src/team/workflowSquad.d.ts.map +1 -1
- package/dist/src/team/workflowSquad.js +250 -12
- package/dist/src/team/workflowSquad.js.map +1 -1
- package/dist/src/tools/enterWorktree.d.ts.map +1 -1
- package/dist/src/tools/enterWorktree.js +3 -0
- package/dist/src/tools/enterWorktree.js.map +1 -1
- package/dist/src/tools/exaSearch.d.ts +2 -2
- package/dist/src/tools/exitWorktree.d.ts.map +1 -1
- package/dist/src/tools/exitWorktree.js +3 -1
- package/dist/src/tools/exitWorktree.js.map +1 -1
- package/dist/src/tools/hadamardCoreTools.d.ts +5 -14
- package/dist/src/tools/hadamardCoreTools.d.ts.map +1 -1
- package/dist/src/tools/hadamardCoreTools.js +31 -0
- package/dist/src/tools/hadamardCoreTools.js.map +1 -1
- package/dist/src/tools/hadamardFileTools.d.ts.map +1 -1
- package/dist/src/tools/hadamardFileTools.js +116 -38
- package/dist/src/tools/hadamardFileTools.js.map +1 -1
- package/dist/src/tools/planMode/PlanModeTools.d.ts +22 -0
- package/dist/src/tools/planMode/PlanModeTools.d.ts.map +1 -1
- package/dist/src/tools/planMode/PlanModeTools.js +102 -5
- package/dist/src/tools/planMode/PlanModeTools.js.map +1 -1
- package/dist/src/tools/todo/TodoWriteTool.d.ts +1 -1
- package/dist/src/tui/hadamardTui.d.ts.map +1 -1
- package/dist/src/tui/hadamardTui.js +387 -168
- package/dist/src/tui/hadamardTui.js.map +1 -1
- package/dist/src/tui/pendingInput.d.ts +17 -0
- package/dist/src/tui/pendingInput.d.ts.map +1 -0
- package/dist/src/tui/pendingInput.js +23 -0
- package/dist/src/tui/pendingInput.js.map +1 -0
- package/dist/src/tui/reasoningDisplay.d.ts +13 -0
- package/dist/src/tui/reasoningDisplay.d.ts.map +1 -0
- package/dist/src/tui/reasoningDisplay.js +45 -0
- package/dist/src/tui/reasoningDisplay.js.map +1 -0
- package/dist/src/tui/screen.d.ts +11 -1
- package/dist/src/tui/screen.d.ts.map +1 -1
- package/dist/src/tui/screen.js +64 -34
- package/dist/src/tui/screen.js.map +1 -1
- package/dist/src/types.d.ts +210 -77
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/ui/commandSurface.d.ts +8 -0
- package/dist/src/ui/commandSurface.d.ts.map +1 -1
- package/dist/src/ui/commandSurface.js +78 -13
- package/dist/src/ui/commandSurface.js.map +1 -1
- package/dist/src/update/appUpdateService.d.ts +34 -1
- package/dist/src/update/appUpdateService.d.ts.map +1 -1
- package/dist/src/update/appUpdateService.js +114 -9
- package/dist/src/update/appUpdateService.js.map +1 -1
- package/package.json +3 -2
- package/dist/src/prompts/outputStyles.d.ts +0 -20
- package/dist/src/prompts/outputStyles.d.ts.map +0 -1
- package/dist/src/prompts/outputStyles.js +0 -35
- package/dist/src/prompts/outputStyles.js.map +0 -1
|
@@ -1,59 +1,13 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
4
4
|
import { getDefaultHadamardSettingsPath, persistHadamardSettingsStore, resolveHadamardSettingsStore, } from '../config/hadamardSettingsStore.js';
|
|
5
5
|
import { resolveHadamardHome } from '../config/hadamardHome.js';
|
|
6
6
|
import { assertSafeStorageSegment, joinUnderStorageRoot, safeStorageFileName, } from '../storage/pathSafety.js';
|
|
7
7
|
import { formatMemoryManifest, memoryAge, memoryAgeDays, memoryFreshnessNote, memoryFreshnessText, memoryHeader, readMemoriesForSurfacing, scanMemoryFiles, selectRelevantMemories, } from './hadamardRelevantMemories.js';
|
|
8
|
-
const DEFAULT_SESSION_MEMORY_TEMPLATE = `
|
|
9
|
-
# Session Title
|
|
10
|
-
_A short and distinctive 5-10 word descriptive title for the session. Super info dense, no filler_
|
|
11
|
-
|
|
12
|
-
# Current State
|
|
13
|
-
_What is actively being worked on right now? Pending tasks not yet completed. Immediate next steps._
|
|
14
|
-
|
|
15
|
-
# Task specification
|
|
16
|
-
_What did the user ask to build? Any design decisions or other explanatory context_
|
|
17
|
-
|
|
18
|
-
# Files and Functions
|
|
19
|
-
_What are the important files? In short, what do they contain and why are they relevant?_
|
|
20
|
-
|
|
21
|
-
# Workflow
|
|
22
|
-
_What bash commands are usually run and in what order? How to interpret their output if not obvious?_
|
|
23
|
-
|
|
24
|
-
# Errors & Corrections
|
|
25
|
-
_Errors encountered and how they were fixed. What did the user correct? What approaches failed and should not be tried again?_
|
|
26
|
-
|
|
27
|
-
# Codebase and System Documentation
|
|
28
|
-
_What are the important system components? How do they work/fit together?_
|
|
29
|
-
|
|
30
|
-
# Learnings
|
|
31
|
-
_What has worked well? What has not? What to avoid? Do not duplicate items from other sections_
|
|
32
|
-
|
|
33
|
-
# Key results
|
|
34
|
-
_If the user asked a specific output such as an answer to a question, a table, or other document, repeat the exact result here_
|
|
35
|
-
|
|
36
|
-
# Worklog
|
|
37
|
-
_Step by step, what was attempted, done? Very terse summary for each step_
|
|
38
|
-
`.trim();
|
|
39
|
-
const MAX_SECTION_LENGTH = 2_000;
|
|
40
|
-
const MAX_TOTAL_SESSION_MEMORY_TOKENS = 12_000;
|
|
41
8
|
const ENTRYPOINT_NAME = 'MEMORY.md';
|
|
42
9
|
const MAX_ENTRYPOINT_LINES = 200;
|
|
43
10
|
const MAX_ENTRYPOINT_BYTES = 25_000;
|
|
44
|
-
const DEFAULT_SESSION_MEMORY_CONFIG = {
|
|
45
|
-
minimumMessageTokensToInit: 10_000,
|
|
46
|
-
minimumTokensBetweenUpdate: 5_000,
|
|
47
|
-
toolCallsBetweenUpdates: 3,
|
|
48
|
-
};
|
|
49
|
-
const DEFAULT_SESSION_MEMORY_COMPACT_CONFIG = {
|
|
50
|
-
minTokens: 10_000,
|
|
51
|
-
minTextBlockMessages: 5,
|
|
52
|
-
maxTokens: 40_000,
|
|
53
|
-
};
|
|
54
|
-
function roughTokenCountEstimation(content) {
|
|
55
|
-
return Math.ceil(content.length / 4);
|
|
56
|
-
}
|
|
57
11
|
function sanitizeSegment(value) {
|
|
58
12
|
return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'project';
|
|
59
13
|
}
|
|
@@ -136,52 +90,28 @@ function buildPaths(raw, configPath, homeDir, projectPath, sessionId) {
|
|
|
136
90
|
teamMemoryDir: path.join(autoMemoryDir, 'team'),
|
|
137
91
|
teamMemoryEntrypoint: path.join(autoMemoryDir, 'team', ENTRYPOINT_NAME),
|
|
138
92
|
sessionId: safeSessionId,
|
|
139
|
-
sessionMemoryDir: safeSessionId
|
|
140
|
-
? joinUnderStorageRoot(projectStateDir, safeSessionId, 'session-memory')
|
|
141
|
-
: undefined,
|
|
142
|
-
sessionMemoryPath: safeSessionId
|
|
143
|
-
? joinUnderStorageRoot(projectStateDir, safeSessionId, 'session-memory', 'summary.md')
|
|
144
|
-
: undefined,
|
|
145
93
|
};
|
|
146
94
|
}
|
|
147
95
|
function buildCombinedMemoryPrompt(paths, extraGuidelines, skipIndex = false) {
|
|
148
|
-
const howToSave =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
]
|
|
159
|
-
|
|
160
|
-
'## How to save memories',
|
|
161
|
-
'',
|
|
162
|
-
'Saving a memory is a two-step process:',
|
|
163
|
-
'',
|
|
164
|
-
`1. Write the memory to its own file in either \`${paths.autoMemoryDir}\` or \`${paths.teamMemoryDir}\`.`,
|
|
165
|
-
`2. Add a pointer to that file in the directory entrypoint \`${ENTRYPOINT_NAME}\`. Each entry should be one short line: \`- [Title](file.md) — one-line hook\`. Never write the memory body directly into \`${ENTRYPOINT_NAME}\`.`,
|
|
166
|
-
'',
|
|
167
|
-
`Both \`${ENTRYPOINT_NAME}\` indexes are loaded into future context, so keep them concise and actively maintained.`,
|
|
168
|
-
'- Keep the name, description, and type fields in memory files up-to-date with the content',
|
|
169
|
-
'- Organize memory semantically by topic, not chronologically',
|
|
170
|
-
'- Update or remove memories that turn out to be wrong or outdated',
|
|
171
|
-
'- Do not write duplicate memories. Update an existing memory before creating a new one when possible.',
|
|
172
|
-
];
|
|
96
|
+
const howToSave = [
|
|
97
|
+
'## How memory is updated',
|
|
98
|
+
'',
|
|
99
|
+
'- Treat durable memory as read-only during the main chat.',
|
|
100
|
+
'- Never use ordinary Write or Edit calls to silently modify durable memory.',
|
|
101
|
+
'- To suggest a durable fact, use ProposeMemory. The runtime writes it only after the user applies the proposal.',
|
|
102
|
+
'- Automatic Dream consolidation rewrites MEMORY.md and memory_summary.md.',
|
|
103
|
+
...(skipIndex ? [] : [
|
|
104
|
+
`- Detailed durable memory lives in \`${paths.autoMemoryEntrypoint}\`.`,
|
|
105
|
+
`- Only \`memory_summary.md\` is auto-injected into this prompt; Read MEMORY.md when you need detail.`,
|
|
106
|
+
]),
|
|
107
|
+
];
|
|
173
108
|
return [
|
|
174
109
|
'# Memory',
|
|
175
110
|
'',
|
|
176
|
-
`You have a persistent
|
|
111
|
+
`You have a persistent file-based durable memory under \`${paths.autoMemoryDir}\`.`,
|
|
177
112
|
'',
|
|
178
113
|
'Use memory for information that will be useful in future conversations, not for transient task state that only matters within the current turn.',
|
|
179
114
|
'',
|
|
180
|
-
'## Memory scope',
|
|
181
|
-
'',
|
|
182
|
-
`- private: memories that are private to the current user and stored under \`${paths.autoMemoryDir}\``,
|
|
183
|
-
`- team: memories that are shared with collaborators in the current project and stored under \`${paths.teamMemoryDir}\``,
|
|
184
|
-
'',
|
|
185
115
|
'## What to save',
|
|
186
116
|
'',
|
|
187
117
|
'- collaboration preferences that remain useful over time',
|
|
@@ -201,6 +131,7 @@ function buildCombinedMemoryPrompt(paths, extraGuidelines, skipIndex = false) {
|
|
|
201
131
|
'',
|
|
202
132
|
'- when the user explicitly asks you to remember, recall, or check memory',
|
|
203
133
|
'- when prior collaboration context seems directly relevant',
|
|
134
|
+
`- Read \`${paths.autoMemoryEntrypoint}\` for full detail; the summary below is only a map`,
|
|
204
135
|
'- if the user asks you to ignore memory, behave as if MEMORY.md were empty',
|
|
205
136
|
'',
|
|
206
137
|
'## Memory and other forms of persistence',
|
|
@@ -248,82 +179,6 @@ function truncateEntrypointContent(raw) {
|
|
|
248
179
|
wasByteTruncated,
|
|
249
180
|
};
|
|
250
181
|
}
|
|
251
|
-
function substituteVariables(template, variables) {
|
|
252
|
-
return template.replace(/\{\{(\w+)\}\}/g, (match, key) => Object.prototype.hasOwnProperty.call(variables, key) ? variables[key] : match);
|
|
253
|
-
}
|
|
254
|
-
function analyzeSectionSizes(content) {
|
|
255
|
-
const sections = {};
|
|
256
|
-
const lines = content.split('\n');
|
|
257
|
-
let currentSection = '';
|
|
258
|
-
let currentContent = [];
|
|
259
|
-
for (const line of lines) {
|
|
260
|
-
if (line.startsWith('# ')) {
|
|
261
|
-
if (currentSection && currentContent.length > 0) {
|
|
262
|
-
sections[currentSection] = roughTokenCountEstimation(currentContent.join('\n').trim());
|
|
263
|
-
}
|
|
264
|
-
currentSection = line;
|
|
265
|
-
currentContent = [];
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
currentContent.push(line);
|
|
269
|
-
}
|
|
270
|
-
if (currentSection && currentContent.length > 0) {
|
|
271
|
-
sections[currentSection] = roughTokenCountEstimation(currentContent.join('\n').trim());
|
|
272
|
-
}
|
|
273
|
-
return sections;
|
|
274
|
-
}
|
|
275
|
-
function generateSectionReminders(sectionSizes, totalTokens) {
|
|
276
|
-
const overBudget = totalTokens > MAX_TOTAL_SESSION_MEMORY_TOKENS;
|
|
277
|
-
const oversizedSections = Object.entries(sectionSizes)
|
|
278
|
-
.filter(([, tokens]) => tokens > MAX_SECTION_LENGTH)
|
|
279
|
-
.sort(([, left], [, right]) => right - left)
|
|
280
|
-
.map(([section, tokens]) => `- "${section}" is ~${tokens} tokens (limit: ${MAX_SECTION_LENGTH})`);
|
|
281
|
-
if (oversizedSections.length === 0 && !overBudget) {
|
|
282
|
-
return '';
|
|
283
|
-
}
|
|
284
|
-
const parts = [];
|
|
285
|
-
if (overBudget) {
|
|
286
|
-
parts.push(`\n\nCRITICAL: The session memory file is currently ~${totalTokens} tokens, which exceeds the maximum of ${MAX_TOTAL_SESSION_MEMORY_TOKENS} tokens. Condense the file while keeping Current State and Errors & Corrections accurate.`);
|
|
287
|
-
}
|
|
288
|
-
if (oversizedSections.length > 0) {
|
|
289
|
-
parts.push(`\n\nOversized sections to condense:\n${oversizedSections.join('\n')}`);
|
|
290
|
-
}
|
|
291
|
-
return parts.join('');
|
|
292
|
-
}
|
|
293
|
-
function buildCompactContinuationSummary(summary, transcriptPath, recentMessagesPreserved = true) {
|
|
294
|
-
let baseSummary = `This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation.
|
|
295
|
-
|
|
296
|
-
${summary}`;
|
|
297
|
-
if (transcriptPath) {
|
|
298
|
-
baseSummary += `\n\nIf you need specific details from before compaction, read the full transcript at: ${transcriptPath}`;
|
|
299
|
-
}
|
|
300
|
-
if (recentMessagesPreserved) {
|
|
301
|
-
baseSummary += '\n\nRecent messages are preserved verbatim.';
|
|
302
|
-
}
|
|
303
|
-
return `${baseSummary}
|
|
304
|
-
|
|
305
|
-
Continue the conversation from where it left off without asking the user to repeat prior context. Resume directly and keep moving on the most recent task.`;
|
|
306
|
-
}
|
|
307
|
-
function flushSessionSection(sectionHeader, sectionLines, maxCharsPerSection) {
|
|
308
|
-
if (!sectionHeader) {
|
|
309
|
-
return { lines: sectionLines, wasTruncated: false };
|
|
310
|
-
}
|
|
311
|
-
const sectionContent = sectionLines.join('\n');
|
|
312
|
-
if (sectionContent.length <= maxCharsPerSection) {
|
|
313
|
-
return { lines: [sectionHeader, ...sectionLines], wasTruncated: false };
|
|
314
|
-
}
|
|
315
|
-
let charCount = 0;
|
|
316
|
-
const keptLines = [sectionHeader];
|
|
317
|
-
for (const line of sectionLines) {
|
|
318
|
-
if (charCount + line.length + 1 > maxCharsPerSection) {
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
keptLines.push(line);
|
|
322
|
-
charCount += line.length + 1;
|
|
323
|
-
}
|
|
324
|
-
keptLines.push('\n[... section truncated for length ...]');
|
|
325
|
-
return { lines: keptLines, wasTruncated: true };
|
|
326
|
-
}
|
|
327
182
|
async function readTextIfExists(filePath) {
|
|
328
183
|
try {
|
|
329
184
|
return await readFile(filePath, 'utf8');
|
|
@@ -336,6 +191,35 @@ async function readTextIfExists(filePath) {
|
|
|
336
191
|
throw error;
|
|
337
192
|
}
|
|
338
193
|
}
|
|
194
|
+
async function listMarkdownFiles(root) {
|
|
195
|
+
const files = [];
|
|
196
|
+
const visit = async (directory) => {
|
|
197
|
+
let entries;
|
|
198
|
+
try {
|
|
199
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (error.code === 'ENOENT')
|
|
203
|
+
return;
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
for (const entry of entries) {
|
|
207
|
+
if (entry.isSymbolicLink())
|
|
208
|
+
continue;
|
|
209
|
+
const target = path.join(directory, entry.name);
|
|
210
|
+
if (entry.isDirectory()) {
|
|
211
|
+
if (entry.name === 'team')
|
|
212
|
+
continue;
|
|
213
|
+
await visit(target);
|
|
214
|
+
}
|
|
215
|
+
else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
216
|
+
files.push(target);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
await visit(root);
|
|
221
|
+
return files;
|
|
222
|
+
}
|
|
339
223
|
export class HadamardMemoryApi {
|
|
340
224
|
defaults;
|
|
341
225
|
constructor(defaults = {}) {
|
|
@@ -385,24 +269,14 @@ export class HadamardMemoryApi {
|
|
|
385
269
|
const lines = [
|
|
386
270
|
buildCombinedMemoryPrompt(paths, options.extraGuidelines, options.skipIndex),
|
|
387
271
|
];
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
},
|
|
397
|
-
];
|
|
398
|
-
for (const entrypoint of entrypoints) {
|
|
399
|
-
lines.push('', `## ${entrypoint.title}`);
|
|
400
|
-
if (entrypoint.content?.trim()) {
|
|
401
|
-
lines.push('', truncateEntrypointContent(entrypoint.content).content);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
lines.push('', `Your ${ENTRYPOINT_NAME} is currently empty. When you save new memories, they will appear here.`);
|
|
405
|
-
}
|
|
272
|
+
const summaryPath = path.join(paths.autoMemoryDir, 'memory_summary.md');
|
|
273
|
+
const summaryContent = (await readTextIfExists(summaryPath))?.slice(0, 20_000);
|
|
274
|
+
lines.push('', `## ${summaryPath}`);
|
|
275
|
+
if (summaryContent?.trim()) {
|
|
276
|
+
lines.push('', truncateEntrypointContent(summaryContent).content);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
lines.push('', `memory_summary.md is currently empty. After Dream runs, it will map sections of \`${paths.autoMemoryEntrypoint}\`.`);
|
|
406
280
|
}
|
|
407
281
|
return lines.join('\n');
|
|
408
282
|
}
|
|
@@ -429,269 +303,73 @@ export class HadamardMemoryApi {
|
|
|
429
303
|
limit: options.limit,
|
|
430
304
|
});
|
|
431
305
|
}
|
|
432
|
-
async surfaceRelevantMemories(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
async loadSessionTemplate(options = {}) {
|
|
437
|
-
const homeDir = resolveHadamardHome(options.homeDir ?? this.defaults.homeDir);
|
|
438
|
-
const templatePath = path.join(homeDir, 'session-memory', 'config', 'template.md');
|
|
439
|
-
return (await readTextIfExists(templatePath)) ?? DEFAULT_SESSION_MEMORY_TEMPLATE;
|
|
440
|
-
}
|
|
441
|
-
async loadSessionPrompt(options = {}) {
|
|
442
|
-
const homeDir = resolveHadamardHome(options.homeDir ?? this.defaults.homeDir);
|
|
443
|
-
const promptPath = path.join(homeDir, 'session-memory', 'config', 'prompt.md');
|
|
444
|
-
return ((await readTextIfExists(promptPath)) ??
|
|
445
|
-
`IMPORTANT: This message and these instructions are NOT part of the actual user conversation. Do NOT include any references to "note-taking", "session notes extraction", or these update instructions in the notes content.
|
|
446
|
-
|
|
447
|
-
Based on the user conversation above (EXCLUDING this note-taking instruction message as well as system prompt, HADAMARD.md entries, or any past session summaries), update the session notes file.
|
|
448
|
-
|
|
449
|
-
The file {{notesPath}} has already been read for you. Here are its current contents:
|
|
450
|
-
<current_notes_content>
|
|
451
|
-
{{currentNotes}}
|
|
452
|
-
</current_notes_content>
|
|
453
|
-
|
|
454
|
-
Your ONLY task is to use the Edit tool to update the notes file, then stop. You can make multiple edits - make all Edit tool calls in parallel in a single message. Do not call any other tools.
|
|
455
|
-
|
|
456
|
-
CRITICAL RULES FOR EDITING:
|
|
457
|
-
- The file must maintain its exact structure with all sections, headers, and italic descriptions intact
|
|
458
|
-
-- NEVER modify, delete, or add section headers (the lines starting with # like # Task specification)
|
|
459
|
-
-- NEVER modify or delete the italic _section description_ lines
|
|
460
|
-
-- ONLY update the actual content that appears BELOW the italic _section descriptions_ within each existing section
|
|
461
|
-
- Do NOT reference this note-taking process or instructions anywhere in the notes
|
|
462
|
-
- It's OK to skip updating a section if there are no substantial new insights to add
|
|
463
|
-
- Write detailed, information-dense content for each section
|
|
464
|
-
- Keep each section under ~${MAX_SECTION_LENGTH} tokens/words
|
|
465
|
-
- IMPORTANT: Always update "Current State" to reflect the most recent work
|
|
466
|
-
|
|
467
|
-
Use the Edit tool with file_path: {{notesPath}}.
|
|
468
|
-
|
|
469
|
-
REMEMBER: Use the Edit tool in parallel and stop. Do not continue after the edits.`);
|
|
470
|
-
}
|
|
471
|
-
async buildSessionUpdatePrompt(currentNotes, notesPath, options = {}) {
|
|
472
|
-
const promptTemplate = await this.loadSessionPrompt(options);
|
|
473
|
-
const sectionSizes = analyzeSectionSizes(currentNotes);
|
|
474
|
-
const totalTokens = roughTokenCountEstimation(currentNotes);
|
|
475
|
-
const reminders = generateSectionReminders(sectionSizes, totalTokens);
|
|
476
|
-
return (substituteVariables(promptTemplate, {
|
|
477
|
-
currentNotes,
|
|
478
|
-
notesPath,
|
|
479
|
-
}) + reminders);
|
|
306
|
+
async surfaceRelevantMemories(_query, _options = {}) {
|
|
307
|
+
// Topic/file auto-surfacing removed: only memory_summary.md is injected via
|
|
308
|
+
// the system prompt; agents Read MEMORY.md on demand.
|
|
309
|
+
return [];
|
|
480
310
|
}
|
|
481
|
-
async
|
|
482
|
-
return `${await this.buildSessionUpdatePrompt(currentNotes, notesPath, options)}
|
|
483
|
-
|
|
484
|
-
You are running in direct-output mode, not tool-edit mode.
|
|
485
|
-
|
|
486
|
-
Return the FULL updated notes file as markdown only.
|
|
487
|
-
- Do not wrap the response in code fences
|
|
488
|
-
- Do not explain what you changed
|
|
489
|
-
- Preserve every existing section header and italic guide line exactly
|
|
490
|
-
- Only update the section bodies beneath those guides
|
|
491
|
-
- If a section has no meaningful updates, keep its existing content unchanged`;
|
|
492
|
-
}
|
|
493
|
-
async ensureSessionMemory(options = {}) {
|
|
311
|
+
async listMemoryContent(options = {}) {
|
|
494
312
|
const paths = await this.paths(options);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (existing != null) {
|
|
501
|
-
return {
|
|
502
|
-
path: paths.sessionMemoryPath,
|
|
503
|
-
content: existing,
|
|
504
|
-
created: false,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
const template = await this.loadSessionTemplate(options);
|
|
508
|
-
await writeFile(paths.sessionMemoryPath, `${template.trim()}\n`, 'utf8');
|
|
509
|
-
return {
|
|
510
|
-
path: paths.sessionMemoryPath,
|
|
511
|
-
content: template,
|
|
512
|
-
created: true,
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
async writeSessionMemory(content, options = {}) {
|
|
516
|
-
const ensured = await this.ensureSessionMemory(options);
|
|
517
|
-
await writeFile(ensured.path, `${content.trim()}\n`, 'utf8');
|
|
518
|
-
return {
|
|
519
|
-
path: ensured.path,
|
|
520
|
-
content: content.trim(),
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
async isSessionMemoryEmpty(content, options = {}) {
|
|
524
|
-
const template = await this.loadSessionTemplate(options);
|
|
525
|
-
return content.trim() === template.trim();
|
|
526
|
-
}
|
|
527
|
-
truncateSessionMemoryForCompact(content) {
|
|
528
|
-
const lines = content.split('\n');
|
|
529
|
-
const maxCharsPerSection = MAX_SECTION_LENGTH * 4;
|
|
530
|
-
const outputLines = [];
|
|
531
|
-
let currentSectionHeader = '';
|
|
532
|
-
let currentSectionLines = [];
|
|
533
|
-
let wasTruncated = false;
|
|
534
|
-
for (const line of lines) {
|
|
535
|
-
if (line.startsWith('# ')) {
|
|
536
|
-
const result = flushSessionSection(currentSectionHeader, currentSectionLines, maxCharsPerSection);
|
|
537
|
-
outputLines.push(...result.lines);
|
|
538
|
-
wasTruncated = wasTruncated || result.wasTruncated;
|
|
539
|
-
currentSectionHeader = line;
|
|
540
|
-
currentSectionLines = [];
|
|
313
|
+
const entries = [];
|
|
314
|
+
const durableFiles = await listMarkdownFiles(paths.autoMemoryDir);
|
|
315
|
+
for (const filePath of durableFiles) {
|
|
316
|
+
const relative = path.relative(paths.autoMemoryDir, filePath).replaceAll(path.sep, '/');
|
|
317
|
+
if (relative === 'team' || relative.startsWith('team/'))
|
|
541
318
|
continue;
|
|
542
|
-
|
|
543
|
-
|
|
319
|
+
const raw = relative === 'raw_memories.md' || relative.startsWith('rollout_summaries/');
|
|
320
|
+
const stats = await stat(filePath);
|
|
321
|
+
entries.push({
|
|
322
|
+
id: `${raw ? 'raw' : 'durable'}:${relative}`,
|
|
323
|
+
kind: raw ? 'raw' : 'durable',
|
|
324
|
+
path: filePath,
|
|
325
|
+
size: stats.size,
|
|
326
|
+
modifiedAt: stats.mtime.toISOString(),
|
|
327
|
+
});
|
|
544
328
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
329
|
+
return entries
|
|
330
|
+
.filter(entry => options.kind == null || entry.kind === options.kind)
|
|
331
|
+
.sort((left, right) => right.modifiedAt.localeCompare(left.modifiedAt));
|
|
332
|
+
}
|
|
333
|
+
async readMemoryContent(idOrPath, options = {}) {
|
|
334
|
+
const entries = await this.listMemoryContent(options);
|
|
335
|
+
const resolved = path.resolve(idOrPath);
|
|
336
|
+
const entry = entries.find(candidate => candidate.id === idOrPath || path.resolve(candidate.path) === resolved);
|
|
337
|
+
if (!entry)
|
|
338
|
+
throw new Error(`Memory content not found in the current project: ${idOrPath}`);
|
|
339
|
+
return { entry, content: await readFile(entry.path, 'utf8') };
|
|
340
|
+
}
|
|
341
|
+
async searchMemoryContent(query, options = {}) {
|
|
342
|
+
const normalized = query.trim().toLowerCase();
|
|
343
|
+
if (!normalized)
|
|
344
|
+
return [];
|
|
345
|
+
const results = [];
|
|
346
|
+
for (const entry of await this.listMemoryContent(options)) {
|
|
347
|
+
const lines = (await readFile(entry.path, 'utf8')).split(/\r?\n/u);
|
|
348
|
+
const matches = lines.filter(line => line.toLowerCase().includes(normalized)).slice(0, 20);
|
|
349
|
+
if (matches.length > 0)
|
|
350
|
+
results.push({ entry, matches });
|
|
565
351
|
}
|
|
566
|
-
|
|
567
|
-
return {
|
|
568
|
-
exists: true,
|
|
569
|
-
path: summaryPath,
|
|
570
|
-
content,
|
|
571
|
-
isEmpty: await this.isSessionMemoryEmpty(content, options),
|
|
572
|
-
tokenEstimate: roughTokenCountEstimation(content),
|
|
573
|
-
truncatedContent: truncated.truncatedContent,
|
|
574
|
-
wasTruncated: truncated.wasTruncated,
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
getSessionMemoryConfig() {
|
|
578
|
-
return {
|
|
579
|
-
...DEFAULT_SESSION_MEMORY_CONFIG,
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
getSessionMemoryCompactConfig() {
|
|
583
|
-
return {
|
|
584
|
-
...DEFAULT_SESSION_MEMORY_COMPACT_CONFIG,
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
evaluateSessionMemoryProgress(options) {
|
|
588
|
-
const config = this.getSessionMemoryConfig();
|
|
589
|
-
const currentTokenCount = options.currentTokenCount;
|
|
590
|
-
const tokensAtLastExtraction = options.tokensAtLastExtraction ?? 0;
|
|
591
|
-
const tokensSinceLastExtraction = typeof currentTokenCount === 'number'
|
|
592
|
-
? Math.max(currentTokenCount - tokensAtLastExtraction, 0)
|
|
593
|
-
: undefined;
|
|
594
|
-
const meetsInitializationThreshold = typeof currentTokenCount === 'number'
|
|
595
|
-
? currentTokenCount >= config.minimumMessageTokensToInit
|
|
596
|
-
: undefined;
|
|
597
|
-
const meetsUpdateThreshold = typeof tokensSinceLastExtraction === 'number'
|
|
598
|
-
? tokensSinceLastExtraction >= config.minimumTokensBetweenUpdate
|
|
599
|
-
: undefined;
|
|
600
|
-
const meetsToolCallThreshold = typeof options.toolCallsSinceLastUpdate === 'number'
|
|
601
|
-
? options.toolCallsSinceLastUpdate >= config.toolCallsBetweenUpdates
|
|
602
|
-
: undefined;
|
|
603
|
-
const hasToolCallsInLastTurn = options.hasToolCallsInLastTurn;
|
|
604
|
-
const initialized = options.initialized === true || meetsInitializationThreshold === true;
|
|
605
|
-
const shouldExtract = initialized &&
|
|
606
|
-
meetsUpdateThreshold === true &&
|
|
607
|
-
(meetsToolCallThreshold === true || hasToolCallsInLastTurn === false);
|
|
608
|
-
return {
|
|
609
|
-
currentTokenCount,
|
|
610
|
-
tokensAtLastExtraction,
|
|
611
|
-
tokensSinceLastExtraction,
|
|
612
|
-
messageCountSinceLastExtraction: options.messageCountSinceLastExtraction,
|
|
613
|
-
toolCallsSinceLastUpdate: options.toolCallsSinceLastUpdate,
|
|
614
|
-
initialized,
|
|
615
|
-
meetsInitializationThreshold,
|
|
616
|
-
meetsUpdateThreshold,
|
|
617
|
-
meetsToolCallThreshold,
|
|
618
|
-
hasToolCallsInLastTurn,
|
|
619
|
-
shouldExtract,
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
async buildSessionMemoryCompactSummary(options = {}) {
|
|
623
|
-
const state = await this.readSessionMemory({
|
|
624
|
-
sessionId: options.sessionId ?? this.defaults.sessionId,
|
|
625
|
-
projectPath: options.projectPath ?? this.defaults.projectPath,
|
|
626
|
-
});
|
|
627
|
-
if (!state.exists || !state.content || state.isEmpty) {
|
|
628
|
-
return undefined;
|
|
629
|
-
}
|
|
630
|
-
const paths = await this.paths({
|
|
631
|
-
sessionId: options.sessionId ?? this.defaults.sessionId,
|
|
632
|
-
projectPath: options.projectPath ?? this.defaults.projectPath,
|
|
633
|
-
});
|
|
634
|
-
let summaryContent = state.truncatedContent ?? state.content;
|
|
635
|
-
if (state.wasTruncated && options.includeFullMemoryPathHint !== false && paths.sessionMemoryPath) {
|
|
636
|
-
summaryContent += `\n\nSome session memory sections were truncated for length. The full session memory can be viewed at: ${paths.sessionMemoryPath}`;
|
|
637
|
-
}
|
|
638
|
-
return buildCompactContinuationSummary(summaryContent, options.transcriptPath, options.recentMessagesPreserved ?? true);
|
|
352
|
+
return results;
|
|
639
353
|
}
|
|
640
354
|
async compactState(options = {}) {
|
|
641
|
-
const baseState = await this.state(
|
|
642
|
-
...options,
|
|
643
|
-
includeSessionMemory: options.includeSessionMemory ?? true,
|
|
644
|
-
});
|
|
645
|
-
const sessionMemoryConfig = this.getSessionMemoryConfig();
|
|
646
|
-
const sessionMemoryCompactConfig = this.getSessionMemoryCompactConfig();
|
|
355
|
+
const baseState = await this.state(options);
|
|
647
356
|
const sessionId = options.sessionId ?? this.defaults.sessionId;
|
|
648
357
|
const transcriptPath = sessionId != null
|
|
649
358
|
? joinUnderStorageRoot(baseState.paths.projectStateDir, safeStorageFileName('sessionId', sessionId, 'jsonl'))
|
|
650
359
|
: undefined;
|
|
651
|
-
const progress = options.currentTokenCount != null ||
|
|
652
|
-
options.tokensAtLastExtraction != null ||
|
|
653
|
-
options.initialized != null ||
|
|
654
|
-
options.toolCallsSinceLastUpdate != null
|
|
655
|
-
? this.evaluateSessionMemoryProgress({
|
|
656
|
-
currentTokenCount: options.currentTokenCount,
|
|
657
|
-
tokensAtLastExtraction: options.tokensAtLastExtraction,
|
|
658
|
-
initialized: options.initialized,
|
|
659
|
-
toolCallsSinceLastUpdate: options.toolCallsSinceLastUpdate,
|
|
660
|
-
})
|
|
661
|
-
: undefined;
|
|
662
|
-
const boundaries = undefined;
|
|
663
|
-
const latestBoundary = undefined;
|
|
664
|
-
const compactCount = 0;
|
|
665
|
-
const microcompactCount = 0;
|
|
666
|
-
const lastSummarizedMessageUuid = undefined;
|
|
667
|
-
const latestPreservedSegment = undefined;
|
|
668
|
-
const latestBoundarySummary = undefined;
|
|
669
360
|
return {
|
|
670
361
|
...baseState,
|
|
671
|
-
sessionMemoryConfig,
|
|
672
|
-
sessionMemoryCompactConfig,
|
|
673
|
-
progress,
|
|
674
362
|
runtimeState: options.runtimeState,
|
|
675
363
|
transcriptPath,
|
|
676
|
-
boundaries,
|
|
677
|
-
latestBoundary,
|
|
678
|
-
compactCount,
|
|
679
|
-
microcompactCount,
|
|
680
|
-
hasCompacted:
|
|
364
|
+
boundaries: undefined,
|
|
365
|
+
latestBoundary: undefined,
|
|
366
|
+
compactCount: 0,
|
|
367
|
+
microcompactCount: 0,
|
|
368
|
+
hasCompacted: false,
|
|
681
369
|
pendingPostCompaction: options.runtimeState?.pendingPostCompaction,
|
|
682
|
-
lastSummarizedMessageUuid,
|
|
683
|
-
latestPreservedSegment,
|
|
684
|
-
latestBoundarySummary,
|
|
685
|
-
canUseSessionMemoryCompaction: baseState.enabled.autoCompact &&
|
|
686
|
-
baseState.sessionMemory?.exists === true &&
|
|
687
|
-
baseState.sessionMemory?.isEmpty === false,
|
|
688
|
-
summaryMessage: options.includeSummaryMessage
|
|
689
|
-
? await this.buildSessionMemoryCompactSummary({
|
|
690
|
-
sessionId,
|
|
691
|
-
projectPath: baseState.paths.projectPath,
|
|
692
|
-
transcriptPath,
|
|
693
|
-
})
|
|
694
|
-
: undefined,
|
|
370
|
+
lastSummarizedMessageUuid: undefined,
|
|
371
|
+
latestPreservedSegment: undefined,
|
|
372
|
+
latestBoundarySummary: undefined,
|
|
695
373
|
};
|
|
696
374
|
}
|
|
697
375
|
async state(options = {}) {
|
|
@@ -702,9 +380,15 @@ Return the FULL updated notes file as markdown only.
|
|
|
702
380
|
const settings = parseSettings(store.raw);
|
|
703
381
|
const paths = buildPaths(store.raw, store.configPath, store.homeDir, options.projectPath ?? this.defaults.projectPath ?? process.cwd(), options.sessionId ?? this.defaults.sessionId);
|
|
704
382
|
const enabled = {
|
|
705
|
-
autoCompact:
|
|
706
|
-
|
|
707
|
-
|
|
383
|
+
autoCompact: options.enabledOverrides?.autoCompact
|
|
384
|
+
?? this.defaults.enabledOverrides?.autoCompact
|
|
385
|
+
?? settings.autoCompactEnabled !== false,
|
|
386
|
+
autoMemory: options.enabledOverrides?.autoMemory
|
|
387
|
+
?? this.defaults.enabledOverrides?.autoMemory
|
|
388
|
+
?? settings.autoMemoryEnabled !== false,
|
|
389
|
+
autoDream: options.enabledOverrides?.autoDream
|
|
390
|
+
?? this.defaults.enabledOverrides?.autoDream
|
|
391
|
+
?? settings.autoDreamEnabled === true,
|
|
708
392
|
};
|
|
709
393
|
return {
|
|
710
394
|
settings,
|
|
@@ -713,24 +397,12 @@ Return the FULL updated notes file as markdown only.
|
|
|
713
397
|
combinedPrompt: options.includeCombinedPrompt
|
|
714
398
|
? buildCombinedMemoryPrompt(paths, options.extraGuidelines, options.skipIndex)
|
|
715
399
|
: undefined,
|
|
716
|
-
sessionMemory: options.includeSessionMemory
|
|
717
|
-
? await this.readSessionMemory(options)
|
|
718
|
-
: undefined,
|
|
719
|
-
sessionTemplate: options.includeSessionTemplate
|
|
720
|
-
? await this.loadSessionTemplate(options)
|
|
721
|
-
: undefined,
|
|
722
|
-
sessionPrompt: options.includeSessionPrompt
|
|
723
|
-
? await this.loadSessionPrompt(options)
|
|
724
|
-
: undefined,
|
|
725
400
|
};
|
|
726
401
|
}
|
|
727
402
|
}
|
|
728
403
|
export function createHadamardMemoryApi(options = {}) {
|
|
729
404
|
return new HadamardMemoryApi(options);
|
|
730
405
|
}
|
|
731
|
-
export function getHadamardDefaultSessionMemoryTemplate() {
|
|
732
|
-
return DEFAULT_SESSION_MEMORY_TEMPLATE;
|
|
733
|
-
}
|
|
734
406
|
export function getHadamardCompactBoundarySummary(metadata) {
|
|
735
407
|
if (!metadata) {
|
|
736
408
|
return undefined;
|
|
@@ -760,16 +432,6 @@ export function getHadamardCompactBoundarySummary(metadata) {
|
|
|
760
432
|
].filter(Boolean);
|
|
761
433
|
return parts.length > 0 ? parts.join(', ') : undefined;
|
|
762
434
|
}
|
|
763
|
-
export function getHadamardDefaultSessionMemoryConfig() {
|
|
764
|
-
return {
|
|
765
|
-
...DEFAULT_SESSION_MEMORY_CONFIG,
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
export function getHadamardDefaultSessionMemoryCompactConfig() {
|
|
769
|
-
return {
|
|
770
|
-
...DEFAULT_SESSION_MEMORY_COMPACT_CONFIG,
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
435
|
export { formatMemoryManifest as formatHadamardMemoryManifest, memoryAge as getHadamardMemoryAge, memoryAgeDays as getHadamardMemoryAgeDays, memoryFreshnessNote as getHadamardMemoryFreshnessNote, memoryFreshnessText as getHadamardMemoryFreshnessText, memoryHeader as getHadamardMemoryHeader, readMemoriesForSurfacing as readHadamardMemoriesForSurfacing, scanMemoryFiles as scanHadamardMemoryFiles, selectRelevantMemories as selectHadamardRelevantMemories, };
|
|
774
436
|
export function getHadamardDefaultSettingsPath(options = {}) {
|
|
775
437
|
return getDefaultHadamardSettingsPath(options.homeDir);
|