@roackb2/heddle 0.0.28 → 0.0.29

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.
Files changed (138) hide show
  1. package/README.md +51 -17
  2. package/dist/examples/programmatic-loop.js +12 -0
  3. package/dist/examples/programmatic-loop.js.map +1 -1
  4. package/dist/src/cli/ask.d.ts.map +1 -1
  5. package/dist/src/cli/ask.js +27 -5
  6. package/dist/src/cli/ask.js.map +1 -1
  7. package/dist/src/cli/chat/App.js +5 -3
  8. package/dist/src/cli/chat/App.js.map +1 -1
  9. package/dist/src/cli/chat/hooks/useAgentRun.d.ts +1 -0
  10. package/dist/src/cli/chat/hooks/useAgentRun.d.ts.map +1 -1
  11. package/dist/src/cli/chat/hooks/useAgentRun.js +73 -0
  12. package/dist/src/cli/chat/hooks/useAgentRun.js.map +1 -1
  13. package/dist/src/cli/chat/hooks/useApprovalFlow.d.ts +1 -0
  14. package/dist/src/cli/chat/hooks/useApprovalFlow.d.ts.map +1 -1
  15. package/dist/src/cli/chat/hooks/useApprovalFlow.js +3 -0
  16. package/dist/src/cli/chat/hooks/useApprovalFlow.js.map +1 -1
  17. package/dist/src/cli/chat/utils/format.d.ts.map +1 -1
  18. package/dist/src/cli/chat/utils/format.js +8 -0
  19. package/dist/src/cli/chat/utils/format.js.map +1 -1
  20. package/dist/src/cli/chat/utils/runtime.d.ts.map +1 -1
  21. package/dist/src/cli/chat/utils/runtime.js +7 -3
  22. package/dist/src/cli/chat/utils/runtime.js.map +1 -1
  23. package/dist/src/cli/main.js +223 -1
  24. package/dist/src/cli/main.js.map +1 -1
  25. package/dist/src/cli/remote/control-plane-client.d.ts +43 -0
  26. package/dist/src/cli/remote/control-plane-client.d.ts.map +1 -1
  27. package/dist/src/core/agent/mutation-tracking.d.ts.map +1 -1
  28. package/dist/src/core/agent/mutation-tracking.js +3 -0
  29. package/dist/src/core/agent/mutation-tracking.js.map +1 -1
  30. package/dist/src/core/agent/post-mutation.js +2 -2
  31. package/dist/src/core/agent/post-mutation.js.map +1 -1
  32. package/dist/src/core/agent/run-agent.d.ts.map +1 -1
  33. package/dist/src/core/agent/run-agent.js +132 -28
  34. package/dist/src/core/agent/run-agent.js.map +1 -1
  35. package/dist/src/core/chat/conversation-lines.d.ts.map +1 -1
  36. package/dist/src/core/chat/conversation-lines.js +1 -26
  37. package/dist/src/core/chat/conversation-lines.js.map +1 -1
  38. package/dist/src/core/chat/session-lease.d.ts +4 -0
  39. package/dist/src/core/chat/session-lease.d.ts.map +1 -1
  40. package/dist/src/core/chat/session-lease.js +29 -1
  41. package/dist/src/core/chat/session-lease.js.map +1 -1
  42. package/dist/src/core/chat/session-submit.d.ts +2 -0
  43. package/dist/src/core/chat/session-submit.d.ts.map +1 -1
  44. package/dist/src/core/chat/session-submit.js +120 -15
  45. package/dist/src/core/chat/session-submit.js.map +1 -1
  46. package/dist/src/core/chat/trace-summary.d.ts.map +1 -1
  47. package/dist/src/core/chat/trace-summary.js +10 -0
  48. package/dist/src/core/chat/trace-summary.js.map +1 -1
  49. package/dist/src/core/memory/catalog.d.ts +46 -0
  50. package/dist/src/core/memory/catalog.d.ts.map +1 -0
  51. package/dist/src/core/memory/catalog.js +230 -0
  52. package/dist/src/core/memory/catalog.js.map +1 -0
  53. package/dist/src/core/memory/domain-prompt.d.ts +2 -0
  54. package/dist/src/core/memory/domain-prompt.d.ts.map +1 -0
  55. package/dist/src/core/memory/domain-prompt.js +35 -0
  56. package/dist/src/core/memory/domain-prompt.js.map +1 -0
  57. package/dist/src/core/memory/maintainer-tools.d.ts +5 -0
  58. package/dist/src/core/memory/maintainer-tools.d.ts.map +1 -0
  59. package/dist/src/core/memory/maintainer-tools.js +10 -0
  60. package/dist/src/core/memory/maintainer-tools.js.map +1 -0
  61. package/dist/src/core/memory/maintainer.d.ts +45 -0
  62. package/dist/src/core/memory/maintainer.d.ts.map +1 -0
  63. package/dist/src/core/memory/maintainer.js +204 -0
  64. package/dist/src/core/memory/maintainer.js.map +1 -0
  65. package/dist/src/core/memory/maintenance-integration.d.ts +20 -0
  66. package/dist/src/core/memory/maintenance-integration.d.ts.map +1 -0
  67. package/dist/src/core/memory/maintenance-integration.js +189 -0
  68. package/dist/src/core/memory/maintenance-integration.js.map +1 -0
  69. package/dist/src/core/memory/templates.d.ts +9 -0
  70. package/dist/src/core/memory/templates.d.ts.map +1 -0
  71. package/dist/src/core/memory/templates.js +32 -0
  72. package/dist/src/core/memory/templates.js.map +1 -0
  73. package/dist/src/core/memory/validation.d.ts +39 -0
  74. package/dist/src/core/memory/validation.d.ts.map +1 -0
  75. package/dist/src/core/memory/validation.js +94 -0
  76. package/dist/src/core/memory/validation.js.map +1 -0
  77. package/dist/src/core/memory/visibility.d.ts +42 -0
  78. package/dist/src/core/memory/visibility.d.ts.map +1 -0
  79. package/dist/src/core/memory/visibility.js +156 -0
  80. package/dist/src/core/memory/visibility.js.map +1 -0
  81. package/dist/src/core/prompts/system-prompt.d.ts.map +1 -1
  82. package/dist/src/core/prompts/system-prompt.js +0 -10
  83. package/dist/src/core/prompts/system-prompt.js.map +1 -1
  84. package/dist/src/core/runtime/default-tools.d.ts +1 -0
  85. package/dist/src/core/runtime/default-tools.d.ts.map +1 -1
  86. package/dist/src/core/runtime/default-tools.js +22 -4
  87. package/dist/src/core/runtime/default-tools.js.map +1 -1
  88. package/dist/src/core/runtime/heartbeat.d.ts.map +1 -1
  89. package/dist/src/core/runtime/heartbeat.js +9 -2
  90. package/dist/src/core/runtime/heartbeat.js.map +1 -1
  91. package/dist/src/core/tools/file-edit-core.d.ts +1 -0
  92. package/dist/src/core/tools/file-edit-core.d.ts.map +1 -1
  93. package/dist/src/core/tools/file-edit-core.js +10 -0
  94. package/dist/src/core/tools/file-edit-core.js.map +1 -1
  95. package/dist/src/core/tools/memory-checkpoint.d.ts +8 -0
  96. package/dist/src/core/tools/memory-checkpoint.d.ts.map +1 -0
  97. package/dist/src/core/tools/memory-checkpoint.js +131 -0
  98. package/dist/src/core/tools/memory-checkpoint.js.map +1 -0
  99. package/dist/src/core/tools/memory-notes.d.ts.map +1 -1
  100. package/dist/src/core/tools/memory-notes.js +4 -3
  101. package/dist/src/core/tools/memory-notes.js.map +1 -1
  102. package/dist/src/core/tools/record-knowledge.d.ts +9 -0
  103. package/dist/src/core/tools/record-knowledge.d.ts.map +1 -0
  104. package/dist/src/core/tools/record-knowledge.js +177 -0
  105. package/dist/src/core/tools/record-knowledge.js.map +1 -0
  106. package/dist/src/core/types.d.ts +33 -0
  107. package/dist/src/core/types.d.ts.map +1 -1
  108. package/dist/src/index.d.ts +13 -0
  109. package/dist/src/index.d.ts.map +1 -1
  110. package/dist/src/index.js +8 -0
  111. package/dist/src/index.js.map +1 -1
  112. package/dist/src/server/features/control-plane/router.d.ts +43 -0
  113. package/dist/src/server/features/control-plane/router.d.ts.map +1 -1
  114. package/dist/src/server/features/control-plane/router.js +36 -0
  115. package/dist/src/server/features/control-plane/router.js.map +1 -1
  116. package/dist/src/server/features/control-plane/services/ask.d.ts.map +1 -1
  117. package/dist/src/server/features/control-plane/services/ask.js +23 -5
  118. package/dist/src/server/features/control-plane/services/ask.js.map +1 -1
  119. package/dist/src/server/features/control-plane/services/chat-sessions.d.ts +2 -0
  120. package/dist/src/server/features/control-plane/services/chat-sessions.d.ts.map +1 -1
  121. package/dist/src/server/features/control-plane/services/chat-sessions.js +1 -0
  122. package/dist/src/server/features/control-plane/services/chat-sessions.js.map +1 -1
  123. package/dist/src/server/features/control-plane/services/control-plane-state.d.ts.map +1 -1
  124. package/dist/src/server/features/control-plane/services/control-plane-state.js +4 -1
  125. package/dist/src/server/features/control-plane/services/control-plane-state.js.map +1 -1
  126. package/dist/src/server/features/control-plane/services/memory.d.ts +22 -0
  127. package/dist/src/server/features/control-plane/services/memory.d.ts.map +1 -0
  128. package/dist/src/server/features/control-plane/services/memory.js +36 -0
  129. package/dist/src/server/features/control-plane/services/memory.js.map +1 -0
  130. package/dist/src/server/features/control-plane/types.d.ts +2 -0
  131. package/dist/src/server/features/control-plane/types.d.ts.map +1 -1
  132. package/dist/src/server/router.d.ts +43 -0
  133. package/dist/src/server/router.d.ts.map +1 -1
  134. package/dist/src/web/assets/index-BCCIDJRN.js +52 -0
  135. package/dist/src/web/assets/{index-COAJyPuH.css → index-DarVaee6.css} +1 -1
  136. package/dist/src/web/index.html +2 -2
  137. package/package.json +13 -2
  138. package/dist/src/web/assets/index-DxGlp0Wk.js +0 -52
@@ -0,0 +1,230 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { buildMemoryDomainSystemContext } from './domain-prompt.js';
4
+ export const DEFAULT_MEMORY_ROOT_CATALOG_MAX_BYTES = 12 * 1024;
5
+ export const DEFAULT_MEMORY_ROOT_CATALOG_TARGET_BYTES = 8 * 1024;
6
+ export const DEFAULT_MEMORY_FOLDER_CATALOG_MAX_BYTES = 8 * 1024;
7
+ export const DEFAULT_MEMORY_FOLDER_CATALOG_TARGET_BYTES = 5 * 1024;
8
+ export const DEFAULT_MEMORY_CATEGORIES = [
9
+ {
10
+ path: 'current-state',
11
+ title: 'Current State',
12
+ purpose: 'Fresh-session summary, active workstreams, blockers, and recent verified changes.',
13
+ readWhen: 'Start here for non-trivial work or when the user asks what is happening now.',
14
+ },
15
+ {
16
+ path: 'workflows',
17
+ title: 'Workflows',
18
+ purpose: 'Procedures for planning, implementation, review, release, incident, and support work.',
19
+ readWhen: 'Use when the task is process-heavy or the user asks you to follow an established workflow.',
20
+ },
21
+ {
22
+ path: 'preferences',
23
+ title: 'Preferences',
24
+ purpose: 'User or team preferences that should shape communication, code style, risk tolerance, and review behavior.',
25
+ readWhen: 'Use before making broad implementation, design, communication, or review choices.',
26
+ },
27
+ {
28
+ path: 'domain',
29
+ title: 'Domain',
30
+ purpose: 'Durable project, product, architecture, service, data, or business-domain knowledge.',
31
+ readWhen: 'Use before answering architecture questions or changing unfamiliar project behavior.',
32
+ },
33
+ {
34
+ path: 'operations',
35
+ title: 'Operations',
36
+ purpose: 'Commands, environments, deployment/release surfaces, operational status, credentials caveats, and safety notes.',
37
+ readWhen: 'Use before running verification, deployment, migration, incident, or environment-sensitive work.',
38
+ },
39
+ {
40
+ path: 'relationships',
41
+ title: 'Relationships',
42
+ purpose: 'People, teams, systems, projects, ownership, dependencies, escalation paths, and schedules.',
43
+ readWhen: 'Use when work depends on ownership, coordination, external systems, stakeholders, or timing.',
44
+ },
45
+ {
46
+ path: 'history',
47
+ title: 'History',
48
+ purpose: 'Completed decisions, incidents, investigations, migrations, and older context that explains current constraints.',
49
+ readWhen: 'Use when current behavior has historical causes or the task resembles a past incident or decision.',
50
+ },
51
+ ];
52
+ export function bootstrapMemoryWorkspace(options) {
53
+ const memoryRoot = resolve(options.memoryRoot);
54
+ const createdPaths = [];
55
+ mkdirSync(memoryRoot, { recursive: true });
56
+ writeIfMissing(join(memoryRoot, 'README.md'), createRootCatalogTemplate(), createdPaths, memoryRoot);
57
+ for (const category of DEFAULT_MEMORY_CATEGORIES) {
58
+ const categoryRoot = join(memoryRoot, category.path);
59
+ mkdirSync(categoryRoot, { recursive: true });
60
+ writeIfMissing(join(categoryRoot, 'README.md'), createFolderCatalogTemplate(category), createdPaths, memoryRoot);
61
+ }
62
+ mkdirSync(join(memoryRoot, '_maintenance'), { recursive: true });
63
+ writeIfMissing(join(memoryRoot, '_maintenance', 'runs.jsonl'), '', createdPaths, memoryRoot);
64
+ return { memoryRoot, createdPaths };
65
+ }
66
+ export function loadMemoryRootCatalog(options) {
67
+ const memoryRoot = resolve(options.memoryRoot);
68
+ const maxBytes = options.maxBytes ?? DEFAULT_MEMORY_ROOT_CATALOG_MAX_BYTES;
69
+ const catalogPath = join(memoryRoot, 'README.md');
70
+ if (!existsSync(catalogPath)) {
71
+ const content = [
72
+ 'No workspace memory catalog exists yet.',
73
+ '',
74
+ `Expected root catalog: ${catalogPath}`,
75
+ '',
76
+ 'Memory remains available through list/read/search tools when notes exist, but startup recall is not initialized.',
77
+ 'Initialize a cataloged memory workspace before relying on durable recall.',
78
+ ].join('\n');
79
+ return {
80
+ memoryRoot,
81
+ catalogPath,
82
+ exists: false,
83
+ content,
84
+ truncated: false,
85
+ originalBytes: Buffer.byteLength(content, 'utf8'),
86
+ maxBytes,
87
+ };
88
+ }
89
+ const original = readFileSync(catalogPath, 'utf8').trim();
90
+ const originalBytes = Buffer.byteLength(original, 'utf8');
91
+ const truncatedContent = truncateUtf8(original, maxBytes);
92
+ const truncated = originalBytes > Buffer.byteLength(truncatedContent, 'utf8');
93
+ const content = truncated ?
94
+ [
95
+ truncatedContent,
96
+ '',
97
+ `[Memory catalog truncated to ${maxBytes} bytes from ${originalBytes} bytes. Use read_memory_note on README.md for the full catalog.]`,
98
+ ].join('\n')
99
+ : original;
100
+ return {
101
+ memoryRoot,
102
+ catalogPath,
103
+ exists: true,
104
+ content,
105
+ truncated,
106
+ originalBytes,
107
+ maxBytes,
108
+ };
109
+ }
110
+ export function formatMemoryCatalogSystemContext(catalog) {
111
+ const header = catalog.exists ? '## Workspace Memory Catalog' : '## Workspace Memory Catalog Missing';
112
+ return [
113
+ header,
114
+ '',
115
+ `Source: ${catalog.catalogPath}`,
116
+ '',
117
+ catalog.content,
118
+ '',
119
+ 'Startup memory policy: this is the only memory document loaded automatically. Use memory tools to read relevant folder catalogs or notes before relying on deeper memory.',
120
+ ].join('\n');
121
+ }
122
+ export function appendMemoryCatalogSystemContext(options) {
123
+ const catalog = loadMemoryRootCatalog({ memoryRoot: options.memoryRoot, maxBytes: options.maxBytes });
124
+ const memoryContext = formatMemoryCatalogSystemContext(catalog);
125
+ const domainContext = buildMemoryDomainSystemContext();
126
+ const context = `${domainContext}\n\n${memoryContext}`;
127
+ return options.systemContext ? `${options.systemContext}\n\n${context}` : context;
128
+ }
129
+ export function validateMemoryCatalogShape(options) {
130
+ const memoryRoot = resolve(options.memoryRoot);
131
+ const requiredPaths = [
132
+ 'README.md',
133
+ ...DEFAULT_MEMORY_CATEGORIES.map((category) => join(category.path, 'README.md')),
134
+ ];
135
+ const missing = requiredPaths.filter((relativePath) => !existsSync(join(memoryRoot, relativePath)));
136
+ return {
137
+ ok: missing.length === 0,
138
+ memoryRoot,
139
+ missing,
140
+ };
141
+ }
142
+ function writeIfMissing(path, content, createdPaths, memoryRoot) {
143
+ if (existsSync(path)) {
144
+ return;
145
+ }
146
+ mkdirSync(dirname(path), { recursive: true });
147
+ writeFileSync(path, content, 'utf8');
148
+ createdPaths.push(toMemoryRelativePath(memoryRoot, path));
149
+ }
150
+ function createRootCatalogTemplate() {
151
+ return [
152
+ '# Workspace Memory',
153
+ '',
154
+ 'Purpose: durable workspace knowledge that helps future agents become operational quickly.',
155
+ '',
156
+ '## Authority And Freshness',
157
+ '',
158
+ '- Live workspace evidence wins over memory when they disagree.',
159
+ '- Current-state notes with recent verification are stronger than older focused notes.',
160
+ '- Historical notes explain decisions and incidents but may be stale.',
161
+ '- Important stale, disputed, or superseded facts should be marked rather than silently removed.',
162
+ '',
163
+ '## Fast Reading Path',
164
+ '',
165
+ '- New non-trivial task: read `current-state/README.md`, then the category that matches the task.',
166
+ '- Coding or architecture task: read `domain/README.md`, `operations/README.md`, and relevant preferences.',
167
+ '- Workflow, release, PR, or incident task: read `workflows/README.md`, `operations/README.md`, and relevant history.',
168
+ '- Coordination-heavy task: read `relationships/README.md`.',
169
+ '',
170
+ '## Category Index',
171
+ '',
172
+ ...DEFAULT_MEMORY_CATEGORIES.map((category) => `- [${category.title}](${category.path}/README.md): ${category.purpose}`),
173
+ '',
174
+ '## High-Value Notes',
175
+ '',
176
+ '- Add links here when notes become important enough for every fresh agent to notice.',
177
+ '',
178
+ '## Stale Or Disputed Notes',
179
+ '',
180
+ '- Add links here when a note should be treated with caution.',
181
+ '',
182
+ '## Maintenance Instructions',
183
+ '',
184
+ '- Keep this catalog short and navigable.',
185
+ '- Every folder that contains memory notes needs its own `README.md` catalog.',
186
+ '- Every durable note should be discoverable through this catalog or a folder catalog.',
187
+ '- Prefer updating existing notes over scattering small one-off notes.',
188
+ '- Do not store secrets.',
189
+ '',
190
+ ].join('\n');
191
+ }
192
+ function createFolderCatalogTemplate(category) {
193
+ return [
194
+ `# ${category.title}`,
195
+ '',
196
+ `Purpose: ${category.purpose}`,
197
+ '',
198
+ `When to read: ${category.readWhen}`,
199
+ '',
200
+ '## Notes Index',
201
+ '',
202
+ '- Add note links here as this folder grows.',
203
+ '',
204
+ '## Related Folders',
205
+ '',
206
+ '- `../README.md`: root memory catalog.',
207
+ '',
208
+ '## Maintenance Rules',
209
+ '',
210
+ '- Keep this catalog short enough to scan quickly.',
211
+ '- Add notes only when they preserve durable context for future work.',
212
+ '- Update this catalog whenever adding, renaming, or retiring notes in this folder.',
213
+ '- Mark stale, disputed, or superseded knowledge explicitly.',
214
+ '',
215
+ ].join('\n');
216
+ }
217
+ function truncateUtf8(value, maxBytes) {
218
+ if (maxBytes <= 0) {
219
+ return '';
220
+ }
221
+ const bytes = Buffer.from(value, 'utf8');
222
+ if (bytes.length <= maxBytes) {
223
+ return value;
224
+ }
225
+ return bytes.subarray(0, maxBytes).toString('utf8').replace(/\uFFFD+$/u, '').trimEnd();
226
+ }
227
+ function toMemoryRelativePath(memoryRoot, path) {
228
+ return path.slice(memoryRoot.length).replace(/^\/+/, '') || '.';
229
+ }
230
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../../src/core/memory/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAEpE,MAAM,CAAC,MAAM,qCAAqC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/D,MAAM,CAAC,MAAM,wCAAw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QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AACzF,CAAC;AAED,SAAS,oBAAoB,CAAC,UAAkB,EAAE,IAAY;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAClE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function buildMemoryDomainSystemContext(): string;
2
+ //# sourceMappingURL=domain-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-prompt.d.ts","sourceRoot":"","sources":["../../../../src/core/memory/domain-prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,8BAA8B,IAAI,MAAM,CAiCvD"}
@@ -0,0 +1,35 @@
1
+ export function buildMemoryDomainSystemContext() {
2
+ return [
3
+ '## Heddle-Managed Memory Domain',
4
+ '',
5
+ 'Heddle-managed memory is the durable recall substrate for the agent. It is different from ordinary repository documentation.',
6
+ '',
7
+ '### Knowledge Surfaces',
8
+ '',
9
+ '- Repository docs such as README files, AGENTS.md, or docs/ are project-authored evidence. Use them for current product, code, and user-facing documentation facts.',
10
+ '- Heddle-managed memory under .heddle/memory is agent-maintained durable context. Use it for preferences, workflows, current-state handoff, operational conventions, relationships, history, and not-obvious knowledge that helps future sessions avoid rediscovery.',
11
+ '- Live workspace evidence wins when implementation facts conflict with memory. Memory is strongest for user/team preferences, recurring workflows, historical context, and operational knowledge that may not be obvious from code.',
12
+ '',
13
+ '### Retrieval Model',
14
+ '',
15
+ '- For preference-shaped, workflow-shaped, planning-style, ticket/format, review-style, coordination, or recurring operational questions, consult Heddle-managed memory before broad repository search.',
16
+ '- Follow the catalog path: read the root memory catalog, then the relevant folder README catalog, then focused notes listed there.',
17
+ '- Use search_memory_notes when the likely folder is unclear. Use list_memory_notes and read_memory_note when the catalog already points to a likely folder or note.',
18
+ '- Do not grep ordinary repo files first for durable preferences or workflow conventions unless memory has no relevant path or live repository evidence is needed.',
19
+ '',
20
+ '### Maintenance Model',
21
+ '',
22
+ '- Preserve the discovery path. Every durable memory note must be discoverable from the root README.md or a folder README.md.',
23
+ '- Prefer updating an existing cataloged note over scattering many small notes.',
24
+ '- Keep folder README.md files as indexes, not long-form dumps.',
25
+ '- Do not store secrets, speculative guesses, one-turn plans, or temporary command output.',
26
+ '',
27
+ '### Checkpoint Model',
28
+ '',
29
+ '- Before the final answer, run a quick memory checkpoint when memory_checkpoint is available.',
30
+ '- Record durable candidates when the user states a future preference/workflow/format or the turn uncovers stable reusable workspace knowledge.',
31
+ '- Skip one-off task details, duplicate facts, temporary plans, speculative guesses, and information that should remain only in the current transcript.',
32
+ '',
33
+ ].join('\n');
34
+ }
35
+ //# sourceMappingURL=domain-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-prompt.js","sourceRoot":"","sources":["../../../../src/core/memory/domain-prompt.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,8BAA8B;IAC5C,OAAO;QACL,iCAAiC;QACjC,EAAE;QACF,8HAA8H;QAC9H,EAAE;QACF,wBAAwB;QACxB,EAAE;QACF,qKAAqK;QACrK,sQAAsQ;QACtQ,qOAAqO;QACrO,EAAE;QACF,qBAAqB;QACrB,EAAE;QACF,wMAAwM;QACxM,oIAAoI;QACpI,qKAAqK;QACrK,mKAAmK;QACnK,EAAE;QACF,uBAAuB;QACvB,EAAE;QACF,8HAA8H;QAC9H,gFAAgF;QAChF,gEAAgE;QAChE,2FAA2F;QAC3F,EAAE;QACF,sBAAsB;QACtB,EAAE;QACF,+FAA+F;QAC/F,gJAAgJ;QAChJ,wJAAwJ;QACxJ,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ToolDefinition } from '../types.js';
2
+ export declare function createMemoryMaintainerTools(options: {
3
+ memoryRoot: string;
4
+ }): ToolDefinition[];
5
+ //# sourceMappingURL=maintainer-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintainer-tools.d.ts","sourceRoot":"","sources":["../../../../src/core/memory/maintainer-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAQlD,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,EAAE,CAO7F"}
@@ -0,0 +1,10 @@
1
+ import { createEditMemoryNoteTool, createListMemoryNotesTool, createReadMemoryNoteTool, createSearchMemoryNotesTool, } from '../tools/memory-notes.js';
2
+ export function createMemoryMaintainerTools(options) {
3
+ return [
4
+ createListMemoryNotesTool({ memoryRoot: options.memoryRoot }),
5
+ createReadMemoryNoteTool({ memoryRoot: options.memoryRoot }),
6
+ createSearchMemoryNotesTool({ memoryRoot: options.memoryRoot }),
7
+ createEditMemoryNoteTool({ memoryRoot: options.memoryRoot }),
8
+ ];
9
+ }
10
+ //# sourceMappingURL=maintainer-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintainer-tools.js","sourceRoot":"","sources":["../../../../src/core/memory/maintainer-tools.ts"],"names":[],"mappings":"AACA,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,2BAA2B,CAAC,OAA+B;IACzE,OAAO;QACL,yBAAyB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7D,wBAAwB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;QAC5D,2BAA2B,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;QAC/D,wBAAwB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;KAC7D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { LlmAdapter } from '../llm/types.js';
2
+ import type { RunResult } from '../types.js';
3
+ export type KnowledgeCandidate = {
4
+ id: string;
5
+ recordedAt: string;
6
+ status: 'pending';
7
+ summary: string;
8
+ evidence?: string[];
9
+ categoryHint?: string;
10
+ importance?: 'low' | 'medium' | 'high';
11
+ confidence?: 'user-stated' | 'tool-verified' | 'inferred' | 'historical';
12
+ sourceRefs?: string[];
13
+ };
14
+ export type KnowledgeMaintenanceRunRecord = {
15
+ id: string;
16
+ startedAt: string;
17
+ finishedAt: string;
18
+ source: string;
19
+ outcome: RunResult['outcome'] | 'skipped';
20
+ summary: string;
21
+ candidateIds: string[];
22
+ processedCandidateIds: string[];
23
+ failedCandidateIds: string[];
24
+ catalogValid: boolean;
25
+ catalogMissing: string[];
26
+ };
27
+ export type RunKnowledgeMaintenanceOptions = {
28
+ memoryRoot: string;
29
+ observations: KnowledgeCandidate[];
30
+ llm: LlmAdapter;
31
+ source: string;
32
+ maxSteps?: number;
33
+ now?: () => Date;
34
+ nextRunId?: () => string;
35
+ };
36
+ export type RunKnowledgeMaintenanceResult = {
37
+ run: KnowledgeMaintenanceRunRecord;
38
+ result?: RunResult;
39
+ };
40
+ export declare function readPendingKnowledgeCandidates(options: {
41
+ memoryRoot: string;
42
+ }): Promise<KnowledgeCandidate[]>;
43
+ export declare function runKnowledgeMaintenance(options: RunKnowledgeMaintenanceOptions): Promise<RunKnowledgeMaintenanceResult>;
44
+ export declare function runKnowledgeMaintenanceForBacklog(options: Omit<RunKnowledgeMaintenanceOptions, 'observations'>): Promise<RunKnowledgeMaintenanceResult>;
45
+ //# sourceMappingURL=maintainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintainer.d.ts","sourceRoot":"","sources":["../../../../src/core/memory/maintainer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACvC,UAAU,CAAC,EAAE,aAAa,GAAG,eAAe,GAAG,UAAU,GAAG,YAAY,CAAC;IACzE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,kBAAkB,EAAE,CAAC;IACnC,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,GAAG,EAAE,6BAA6B,CAAC;IACnC,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAEF,wBAAsB,8BAA8B,CAAC,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwBnH;AAED,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,8BAA8B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAoE7H;AAWD,wBAAsB,iCAAiC,CAAC,OAAO,EAAE,IAAI,CAAC,8BAA8B,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAG7J"}
@@ -0,0 +1,204 @@
1
+ import { appendFile, mkdir, readFile } from 'node:fs/promises';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { runAgent } from '../agent/run-agent.js';
4
+ import { createLogger } from '../utils/logger.js';
5
+ import { bootstrapMemoryWorkspace, loadMemoryRootCatalog, validateMemoryCatalogShape } from './catalog.js';
6
+ import { createMemoryMaintainerTools } from './maintainer-tools.js';
7
+ export async function readPendingKnowledgeCandidates(options) {
8
+ const memoryRoot = resolve(options.memoryRoot);
9
+ const candidatesPath = join(memoryRoot, '_maintenance', 'candidates.jsonl');
10
+ const lines = await readJsonlLines(candidatesPath);
11
+ const processed = new Set();
12
+ const pending = [];
13
+ for (const line of lines) {
14
+ const parsed = parseJsonObject(line);
15
+ if (!parsed) {
16
+ continue;
17
+ }
18
+ if (parsed.kind === 'candidate_status' && typeof parsed.candidateId === 'string' && parsed.status === 'processed') {
19
+ processed.add(parsed.candidateId);
20
+ continue;
21
+ }
22
+ if (isKnowledgeCandidate(parsed)) {
23
+ pending.push(parsed);
24
+ }
25
+ }
26
+ return pending.filter((candidate) => !processed.has(candidate.id));
27
+ }
28
+ export async function runKnowledgeMaintenance(options) {
29
+ const memoryRoot = resolve(options.memoryRoot);
30
+ bootstrapMemoryWorkspace({ memoryRoot });
31
+ const now = options.now ?? (() => new Date());
32
+ const startedAt = now();
33
+ const runId = options.nextRunId?.() ?? `memory-run-${startedAt.getTime()}`;
34
+ const candidateIds = options.observations.map((candidate) => candidate.id);
35
+ const skippedCandidateIds = options.observations
36
+ .filter((candidate) => !isMaintainerCandidateAllowed(candidate))
37
+ .map((candidate) => candidate.id);
38
+ const observations = options.observations.filter(isMaintainerCandidateAllowed);
39
+ if (observations.length === 0) {
40
+ const validation = validateMemoryCatalogShape({ memoryRoot });
41
+ const summary = candidateIds.length === 0 ? 'No pending knowledge candidates.'
42
+ : `Skipped ${candidateIds.length} low-value, duplicate, or secret-like memory candidate(s).`;
43
+ const run = {
44
+ id: runId,
45
+ startedAt: startedAt.toISOString(),
46
+ finishedAt: now().toISOString(),
47
+ source: options.source,
48
+ outcome: 'skipped',
49
+ summary,
50
+ candidateIds,
51
+ processedCandidateIds: [],
52
+ failedCandidateIds: skippedCandidateIds,
53
+ catalogValid: validation.ok,
54
+ catalogMissing: validation.missing,
55
+ };
56
+ await appendMaintenanceRun(memoryRoot, run);
57
+ return { run };
58
+ }
59
+ const rootCatalog = loadMemoryRootCatalog({ memoryRoot }).content;
60
+ const goal = buildMaintenanceGoal(observations);
61
+ const systemContext = buildMaintainerSystemContext(rootCatalog);
62
+ const result = await runAgent({
63
+ goal,
64
+ llm: options.llm,
65
+ tools: createMemoryMaintainerTools({ memoryRoot }),
66
+ maxSteps: options.maxSteps ?? 40,
67
+ logger: createLogger({ console: false, level: 'silent' }),
68
+ systemContext,
69
+ });
70
+ const validation = validateMemoryCatalogShape({ memoryRoot });
71
+ const processedCandidateIds = result.outcome === 'done' ? observations.map((candidate) => candidate.id) : [];
72
+ const failedCandidateIds = result.outcome === 'done' ? skippedCandidateIds : candidateIds;
73
+ const run = {
74
+ id: runId,
75
+ startedAt: startedAt.toISOString(),
76
+ finishedAt: now().toISOString(),
77
+ source: options.source,
78
+ outcome: result.outcome,
79
+ summary: result.summary,
80
+ candidateIds,
81
+ processedCandidateIds,
82
+ failedCandidateIds,
83
+ catalogValid: validation.ok,
84
+ catalogMissing: validation.missing,
85
+ };
86
+ await appendMaintenanceRun(memoryRoot, run);
87
+ if (processedCandidateIds.length > 0) {
88
+ await appendCandidateStatusEvents(memoryRoot, processedCandidateIds, run.id, now);
89
+ }
90
+ return { run, result };
91
+ }
92
+ function isMaintainerCandidateAllowed(candidate) {
93
+ const text = [
94
+ candidate.summary,
95
+ ...(candidate.evidence ?? []),
96
+ ...(candidate.sourceRefs ?? []),
97
+ ].join('\n');
98
+ return !containsSecretLikeText(text);
99
+ }
100
+ export async function runKnowledgeMaintenanceForBacklog(options) {
101
+ const observations = await readPendingKnowledgeCandidates({ memoryRoot: options.memoryRoot });
102
+ return await runKnowledgeMaintenance({ ...options, observations });
103
+ }
104
+ function buildMaintainerSystemContext(rootCatalog) {
105
+ return [
106
+ '## Memory Maintainer Mode',
107
+ '',
108
+ 'You maintain Heddle workspace memory. You are not doing general coding work.',
109
+ 'Use only memory tools. Do not ask for shell, code edit, web, or external tools.',
110
+ '',
111
+ 'Hard invariants:',
112
+ '- Every durable note must be discoverable through the root catalog or a folder catalog.',
113
+ '- Read the root catalog first, then read the relevant folder catalog before writing.',
114
+ '- Search existing notes before creating a new note.',
115
+ '- Prefer updating existing notes over creating duplicates.',
116
+ '- Update folder catalogs whenever you create, rename, or retire a note.',
117
+ '- Update the root catalog only when a new high-value note or discovery path matters globally.',
118
+ '- Do not store secrets, credentials, private keys, tokens, or passwords.',
119
+ '- Skip low-value, duplicate, speculative, or one-turn scratch observations.',
120
+ '',
121
+ 'Loaded root catalog:',
122
+ '',
123
+ rootCatalog,
124
+ ].join('\n');
125
+ }
126
+ function buildMaintenanceGoal(observations) {
127
+ return [
128
+ 'Process these pending memory candidates into maintained cataloged memory.',
129
+ '',
130
+ ...observations.map((candidate, index) => [
131
+ `Candidate ${index + 1}: ${candidate.id}`,
132
+ `Summary: ${candidate.summary}`,
133
+ candidate.categoryHint ? `Category hint: ${candidate.categoryHint}` : undefined,
134
+ candidate.importance ? `Importance: ${candidate.importance}` : undefined,
135
+ candidate.confidence ? `Confidence: ${candidate.confidence}` : undefined,
136
+ candidate.evidence?.length ? `Evidence:\n${candidate.evidence.map((item) => `- ${item}`).join('\n')}` : undefined,
137
+ candidate.sourceRefs?.length ? `Source refs: ${candidate.sourceRefs.join(', ')}` : undefined,
138
+ ].filter((line) => Boolean(line)).join('\n')),
139
+ '',
140
+ 'End with a concise summary of what memory notes or catalogs changed, or why candidates were skipped.',
141
+ ].join('\n\n');
142
+ }
143
+ async function appendMaintenanceRun(memoryRoot, run) {
144
+ const path = join(memoryRoot, '_maintenance', 'runs.jsonl');
145
+ await mkdir(dirname(path), { recursive: true });
146
+ await appendFile(path, `${JSON.stringify(run)}\n`, 'utf8');
147
+ }
148
+ async function appendCandidateStatusEvents(memoryRoot, candidateIds, runId, now) {
149
+ const path = join(memoryRoot, '_maintenance', 'candidates.jsonl');
150
+ await mkdir(dirname(path), { recursive: true });
151
+ const recordedAt = now().toISOString();
152
+ await appendFile(path, candidateIds.map((candidateId) => JSON.stringify({
153
+ kind: 'candidate_status',
154
+ candidateId,
155
+ status: 'processed',
156
+ runId,
157
+ recordedAt,
158
+ })).join('\n') + '\n', 'utf8');
159
+ }
160
+ async function readJsonlLines(path) {
161
+ try {
162
+ const raw = await readFile(path, 'utf8');
163
+ return raw.split(/\r?\n/u).filter((line) => line.trim());
164
+ }
165
+ catch (error) {
166
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
167
+ return [];
168
+ }
169
+ throw error;
170
+ }
171
+ }
172
+ function parseJsonObject(line) {
173
+ try {
174
+ const parsed = JSON.parse(line);
175
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : undefined;
176
+ }
177
+ catch {
178
+ return undefined;
179
+ }
180
+ }
181
+ function isKnowledgeCandidate(value) {
182
+ return typeof value.id === 'string'
183
+ && typeof value.recordedAt === 'string'
184
+ && value.status === 'pending'
185
+ && typeof value.summary === 'string'
186
+ && (value.evidence === undefined || isStringArray(value.evidence))
187
+ && (value.categoryHint === undefined || typeof value.categoryHint === 'string')
188
+ && (value.importance === undefined || value.importance === 'low' || value.importance === 'medium' || value.importance === 'high')
189
+ && (value.confidence === undefined || value.confidence === 'user-stated' || value.confidence === 'tool-verified' || value.confidence === 'inferred' || value.confidence === 'historical')
190
+ && (value.sourceRefs === undefined || isStringArray(value.sourceRefs));
191
+ }
192
+ function isStringArray(value) {
193
+ return Array.isArray(value) && value.every((item) => typeof item === 'string');
194
+ }
195
+ function containsSecretLikeText(value) {
196
+ const normalized = value.toLowerCase();
197
+ return /\b(api[_ -]?key|password|passwd|private[_ -]?key|access[_ -]?token|refresh[_ -]?token|bearer\s+[a-z0-9._~+/=-]{12,})\b/i.test(value)
198
+ || /\bsecret\s*[:=]\s*\S{8,}/i.test(value)
199
+ || /\bsk-[a-z0-9_-]{12,}\b/i.test(value)
200
+ || normalized.includes('-----begin private key-----')
201
+ || normalized.includes('-----begin rsa private key-----')
202
+ || normalized.includes('-----begin openssh private key-----');
203
+ }
204
+ //# sourceMappingURL=maintainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintainer.js","sourceRoot":"","sources":["../../../../src/core/memory/maintainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,QAAQ,EAAE,MAAM,u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AAU,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,KAAK,aAAa,IAAI,KAAK,CAAC,UAAU,KAAK,eAAe,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU,IAAI,KAAK,CAAC,UAAU,KAAK,YAAY,CAAC;WACtL,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;AACjF,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACvC,OAAO,yHAAyH,CAAC,IAAI,CAAC,KAAK,CAAC;WACvI,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC;WACvC,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC;WACrC,UAAU,CAAC,QAAQ,CAAC,6BAA6B,CAAC;WAClD,UAAU,CAAC,QAAQ,CAAC,iCAAiC,CAAC;WACtD,UAAU,CAAC,QAAQ,CAAC,qCAAqC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { LlmAdapter } from '../llm/types.js';
2
+ import type { TraceEvent } from '../types.js';
3
+ import { type RunKnowledgeMaintenanceResult } from './maintainer.js';
4
+ export type RunMaintenanceForRecordedCandidatesOptions = {
5
+ memoryRoot: string;
6
+ llm: LlmAdapter;
7
+ source: string;
8
+ trace: TraceEvent[];
9
+ maxSteps?: number;
10
+ lockTimeoutMs?: number;
11
+ lockStaleAfterMs?: number;
12
+ onTraceEvent?: (event: TraceEvent) => void;
13
+ };
14
+ export type RunMaintenanceForRecordedCandidatesResult = {
15
+ candidateIds: string[];
16
+ maintenance?: RunKnowledgeMaintenanceResult;
17
+ events: TraceEvent[];
18
+ };
19
+ export declare function runMaintenanceForRecordedCandidates(options: RunMaintenanceForRecordedCandidatesOptions): Promise<RunMaintenanceForRecordedCandidatesResult>;
20
+ //# sourceMappingURL=maintenance-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintenance-integration.d.ts","sourceRoot":"","sources":["../../../../src/core/memory/maintenance-integration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAGL,KAAK,6BAA6B,EACnC,MAAM,iBAAiB,CAAC;AAOzB,MAAM,MAAM,0CAA0C,GAAG;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,yCAAyC,GAAG;IACtD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,6BAA6B,CAAC;IAC5C,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,wBAAsB,mCAAmC,CACvD,OAAO,EAAE,0CAA0C,GAClD,OAAO,CAAC,yCAAyC,CAAC,CAEpD"}