@roackb2/heddle 0.0.36 → 0.0.37

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 (110) hide show
  1. package/dist/src/cli/chat/App.d.ts.map +1 -1
  2. package/dist/src/cli/chat/App.js +94 -80
  3. package/dist/src/cli/chat/App.js.map +1 -1
  4. package/dist/src/cli/chat/components/PromptInput.d.ts +5 -0
  5. package/dist/src/cli/chat/components/PromptInput.d.ts.map +1 -1
  6. package/dist/src/cli/chat/components/PromptInput.js +131 -85
  7. package/dist/src/cli/chat/components/PromptInput.js.map +1 -1
  8. package/dist/src/cli/chat/hooks/tui-agent-turn-lifecycle.d.ts +6 -0
  9. package/dist/src/cli/chat/hooks/tui-agent-turn-lifecycle.d.ts.map +1 -0
  10. package/dist/src/cli/chat/hooks/tui-agent-turn-lifecycle.js +38 -0
  11. package/dist/src/cli/chat/hooks/tui-agent-turn-lifecycle.js.map +1 -0
  12. package/dist/src/cli/chat/hooks/tui-agent-turn-result.d.ts +48 -0
  13. package/dist/src/cli/chat/hooks/tui-agent-turn-result.d.ts.map +1 -0
  14. package/dist/src/cli/chat/hooks/tui-agent-turn-result.js +171 -0
  15. package/dist/src/cli/chat/hooks/tui-agent-turn-result.js.map +1 -0
  16. package/dist/src/cli/chat/hooks/tui-compaction-status.d.ts +24 -0
  17. package/dist/src/cli/chat/hooks/tui-compaction-status.d.ts.map +1 -0
  18. package/dist/src/cli/chat/hooks/tui-compaction-status.js +65 -0
  19. package/dist/src/cli/chat/hooks/tui-compaction-status.js.map +1 -0
  20. package/dist/src/cli/chat/hooks/tui-direct-shell-result.d.ts +28 -0
  21. package/dist/src/cli/chat/hooks/tui-direct-shell-result.d.ts.map +1 -0
  22. package/dist/src/cli/chat/hooks/tui-direct-shell-result.js +41 -0
  23. package/dist/src/cli/chat/hooks/tui-direct-shell-result.js.map +1 -0
  24. package/dist/src/cli/chat/hooks/tui-direct-shell.d.ts +22 -0
  25. package/dist/src/cli/chat/hooks/tui-direct-shell.d.ts.map +1 -0
  26. package/dist/src/cli/chat/hooks/tui-direct-shell.js +127 -0
  27. package/dist/src/cli/chat/hooks/tui-direct-shell.js.map +1 -0
  28. package/dist/src/cli/chat/hooks/tui-drift-observer.d.ts +13 -0
  29. package/dist/src/cli/chat/hooks/tui-drift-observer.d.ts.map +1 -0
  30. package/dist/src/cli/chat/hooks/tui-drift-observer.js +36 -0
  31. package/dist/src/cli/chat/hooks/tui-drift-observer.js.map +1 -0
  32. package/dist/src/cli/chat/hooks/tui-ordinary-turn.d.ts +31 -0
  33. package/dist/src/cli/chat/hooks/tui-ordinary-turn.d.ts.map +1 -0
  34. package/dist/src/cli/chat/hooks/tui-ordinary-turn.js +83 -0
  35. package/dist/src/cli/chat/hooks/tui-ordinary-turn.js.map +1 -0
  36. package/dist/src/cli/chat/hooks/tui-run-loop-events.d.ts +23 -0
  37. package/dist/src/cli/chat/hooks/tui-run-loop-events.d.ts.map +1 -0
  38. package/dist/src/cli/chat/hooks/tui-run-loop-events.js +74 -0
  39. package/dist/src/cli/chat/hooks/tui-run-loop-events.js.map +1 -0
  40. package/dist/src/cli/chat/hooks/tui-tool-approval.d.ts +8 -0
  41. package/dist/src/cli/chat/hooks/tui-tool-approval.d.ts.map +1 -0
  42. package/dist/src/cli/chat/hooks/tui-tool-approval.js +37 -0
  43. package/dist/src/cli/chat/hooks/tui-tool-approval.js.map +1 -0
  44. package/dist/src/cli/chat/hooks/useAgentRun.d.ts +1 -1
  45. package/dist/src/cli/chat/hooks/useAgentRun.d.ts.map +1 -1
  46. package/dist/src/cli/chat/hooks/useAgentRun.js +59 -551
  47. package/dist/src/cli/chat/hooks/useAgentRun.js.map +1 -1
  48. package/dist/src/cli/chat/hooks/useChatStatusSummary.d.ts +58 -0
  49. package/dist/src/cli/chat/hooks/useChatStatusSummary.d.ts.map +1 -0
  50. package/dist/src/cli/chat/hooks/useChatStatusSummary.js +85 -0
  51. package/dist/src/cli/chat/hooks/useChatStatusSummary.js.map +1 -0
  52. package/dist/src/cli/chat/hooks/usePromptSubmission.d.ts.map +1 -1
  53. package/dist/src/cli/chat/hooks/usePromptSubmission.js +1 -0
  54. package/dist/src/cli/chat/hooks/usePromptSubmission.js.map +1 -1
  55. package/dist/src/cli/chat/utils/format.d.ts.map +1 -1
  56. package/dist/src/cli/chat/utils/format.js +21 -0
  57. package/dist/src/cli/chat/utils/format.js.map +1 -1
  58. package/dist/src/cli/chat/utils/runtime.d.ts.map +1 -1
  59. package/dist/src/cli/chat/utils/runtime.js +5 -3
  60. package/dist/src/cli/chat/utils/runtime.js.map +1 -1
  61. package/dist/src/core/agent/tool-dispatch.js +3 -2
  62. package/dist/src/core/agent/tool-dispatch.js.map +1 -1
  63. package/dist/src/core/chat/ordinary-turn.d.ts +34 -0
  64. package/dist/src/core/chat/ordinary-turn.d.ts.map +1 -0
  65. package/dist/src/core/chat/ordinary-turn.js +274 -0
  66. package/dist/src/core/chat/ordinary-turn.js.map +1 -0
  67. package/dist/src/core/chat/session-submit.d.ts +4 -4
  68. package/dist/src/core/chat/session-submit.d.ts.map +1 -1
  69. package/dist/src/core/chat/session-submit.js +23 -282
  70. package/dist/src/core/chat/session-submit.js.map +1 -1
  71. package/dist/src/core/chat/session-title.d.ts +15 -0
  72. package/dist/src/core/chat/session-title.d.ts.map +1 -0
  73. package/dist/src/core/chat/session-title.js +17 -0
  74. package/dist/src/core/chat/session-title.js.map +1 -0
  75. package/dist/src/core/chat/session-turn-preflight.d.ts +37 -0
  76. package/dist/src/core/chat/session-turn-preflight.d.ts.map +1 -0
  77. package/dist/src/core/chat/session-turn-preflight.js +43 -0
  78. package/dist/src/core/chat/session-turn-preflight.js.map +1 -0
  79. package/dist/src/core/chat/session-turn-result.d.ts +36 -0
  80. package/dist/src/core/chat/session-turn-result.d.ts.map +1 -0
  81. package/dist/src/core/chat/session-turn-result.js +60 -0
  82. package/dist/src/core/chat/session-turn-result.js.map +1 -0
  83. package/dist/src/core/chat/tool-approval-host.d.ts +22 -0
  84. package/dist/src/core/chat/tool-approval-host.d.ts.map +1 -0
  85. package/dist/src/core/chat/tool-approval-host.js +14 -0
  86. package/dist/src/core/chat/tool-approval-host.js.map +1 -0
  87. package/dist/src/core/chat/turn-host.d.ts +25 -0
  88. package/dist/src/core/chat/turn-host.d.ts.map +1 -0
  89. package/dist/src/core/chat/turn-host.js +2 -0
  90. package/dist/src/core/chat/turn-host.js.map +1 -0
  91. package/dist/src/core/memory/domain-prompt.d.ts.map +1 -1
  92. package/dist/src/core/memory/domain-prompt.js +48 -40
  93. package/dist/src/core/memory/domain-prompt.js.map +1 -1
  94. package/dist/src/core/runtime/agent-loop.d.ts.map +1 -1
  95. package/dist/src/core/runtime/agent-loop.js +9 -3
  96. package/dist/src/core/runtime/agent-loop.js.map +1 -1
  97. package/dist/src/core/runtime/default-tools.d.ts.map +1 -1
  98. package/dist/src/core/runtime/default-tools.js +1 -0
  99. package/dist/src/core/runtime/default-tools.js.map +1 -1
  100. package/dist/src/core/tools/file-edit-core.d.ts.map +1 -1
  101. package/dist/src/core/tools/file-edit-core.js +21 -2
  102. package/dist/src/core/tools/file-edit-core.js.map +1 -1
  103. package/dist/src/server/features/control-plane/services/chat-session-events.d.ts +26 -0
  104. package/dist/src/server/features/control-plane/services/chat-session-events.d.ts.map +1 -0
  105. package/dist/src/server/features/control-plane/services/chat-session-events.js +61 -0
  106. package/dist/src/server/features/control-plane/services/chat-session-events.js.map +1 -0
  107. package/dist/src/server/features/control-plane/services/chat-sessions.d.ts.map +1 -1
  108. package/dist/src/server/features/control-plane/services/chat-sessions.js +21 -39
  109. package/dist/src/server/features/control-plane/services/chat-sessions.js.map +1 -1
  110. package/package.json +1 -1
@@ -0,0 +1,274 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { appendMemoryCatalogSystemContext, createDefaultAgentTools, createLlmAdapter, DEFAULT_OPENAI_MODEL, inferProviderFromModel, runAgentLoop, } from '../../index.js';
4
+ import { runMaintenanceForRecordedCandidates } from '../memory/maintenance-integration.js';
5
+ import { buildCompactionRunningContext } from './compaction.js';
6
+ import { buildConversationMessages } from './conversation-lines.js';
7
+ import { releaseSessionLease } from './session-lease.js';
8
+ import { prepareChatSessionTurn } from './session-turn-preflight.js';
9
+ import { persistChatTurnResult } from './session-turn-result.js';
10
+ import { loadChatSessions, saveChatSessions, touchSession } from './storage.js';
11
+ import { summarizeTrace } from './trace-summary.js';
12
+ import { formatMissingProviderCredentialMessage, hasProviderCredentialForModel, resolveApiKeyForModel, resolveProviderCredentialSourceForModel, } from '../../core/runtime/api-keys.js';
13
+ export async function executeOrdinaryChatTurn(args) {
14
+ const sessions = loadChatSessions(args.sessionStoragePath, true);
15
+ const session = sessions.find((candidate) => candidate.id === args.sessionId);
16
+ if (!session) {
17
+ throw new Error(`Chat session not found: ${args.sessionId}`);
18
+ }
19
+ const model = session.model ?? process.env.OPENAI_MODEL ?? process.env.ANTHROPIC_MODEL ?? DEFAULT_OPENAI_MODEL;
20
+ const provider = inferProviderFromModel(model);
21
+ const apiKey = args.apiKey ?? resolveApiKeyForModel(model, { preferApiKey: args.preferApiKey });
22
+ const providerCredentialSource = resolveProviderCredentialSourceForModel(model, {
23
+ apiKey,
24
+ apiKeyProvider: args.apiKey ? 'explicit' : apiKey ? provider : undefined,
25
+ credentialStorePath: args.credentialStorePath,
26
+ preferApiKey: args.preferApiKey,
27
+ });
28
+ if (!hasProviderCredentialForModel(model, {
29
+ apiKey: args.apiKey,
30
+ apiKeyProvider: args.apiKey ? 'explicit' : undefined,
31
+ credentialStorePath: args.credentialStorePath,
32
+ preferApiKey: args.preferApiKey,
33
+ })) {
34
+ throw new Error(formatMissingProviderCredentialMessage(model));
35
+ }
36
+ const leaseOwner = args.leaseOwner ?? {
37
+ ownerKind: 'ask',
38
+ ownerId: `submit-${process.pid}`,
39
+ clientLabel: 'another Heddle client',
40
+ };
41
+ const llm = createLlmAdapter({ model, apiKey, credentialStorePath: args.credentialStorePath });
42
+ const memoryDir = join(args.stateRoot, 'memory');
43
+ const systemContext = appendMemoryCatalogSystemContext({
44
+ systemContext: args.systemContext,
45
+ memoryRoot: memoryDir,
46
+ });
47
+ const tools = createDefaultAgentTools({
48
+ model,
49
+ apiKey,
50
+ providerCredentialSource,
51
+ credentialStorePath: args.credentialStorePath,
52
+ workspaceRoot: args.workspaceRoot,
53
+ memoryDir,
54
+ searchIgnoreDirs: [],
55
+ includePlanTool: true,
56
+ });
57
+ try {
58
+ const preflight = await prepareChatSessionTurn({
59
+ sessionStoragePath: args.sessionStoragePath,
60
+ sessionId: session.id,
61
+ fallbackHistory: session.history,
62
+ prompt: args.prompt,
63
+ model,
64
+ stateRoot: args.stateRoot,
65
+ systemContext,
66
+ toolNames: tools.map((tool) => tool.name),
67
+ summarizer: { credentialSource: providerCredentialSource },
68
+ leaseOwner,
69
+ onCompactionStatus: (event, _sourceHistory, leasedSession) => {
70
+ args.onCompactionStatus?.(event);
71
+ args.host?.compaction?.onPreflightCompactionStatus?.(event);
72
+ if (event.status === 'running' && leasedSession) {
73
+ const compactionSeed = touchSession({
74
+ ...leasedSession,
75
+ context: buildCompactionRunningContext({
76
+ history: leasedSession.history,
77
+ previous: leasedSession.context,
78
+ archiveCount: leasedSession.archives?.length,
79
+ currentSummaryPath: leasedSession.context?.currentSummaryPath,
80
+ lastArchivePath: event.archivePath,
81
+ }),
82
+ });
83
+ saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? compactionSeed : candidate));
84
+ }
85
+ },
86
+ });
87
+ if (!preflight.ok) {
88
+ throw new Error(preflight.message);
89
+ }
90
+ const preflightSession = preflight.session ?? touchSession({
91
+ ...session,
92
+ history: preflight.preflightHistory,
93
+ context: preflight.context,
94
+ archives: preflight.archives,
95
+ messages: buildConversationMessages(preflight.preflightHistory),
96
+ });
97
+ saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? preflightSession : candidate));
98
+ const result = await runAgentLoop({
99
+ goal: args.prompt,
100
+ model,
101
+ apiKey,
102
+ workspaceRoot: args.workspaceRoot,
103
+ stateDir: args.stateRoot,
104
+ memoryDir,
105
+ llm,
106
+ tools,
107
+ includeDefaultTools: false,
108
+ history: preflightSession.history,
109
+ systemContext,
110
+ onAssistantStream: args.onAssistantStream,
111
+ onTraceEvent: args.onTraceEvent,
112
+ onEvent: args.host?.events?.onAgentLoopEvent,
113
+ approveToolCall: args.host?.approvals?.requestToolApproval ?
114
+ ((call, tool) => args.host?.approvals?.requestToolApproval?.({ call, tool }) ?? Promise.resolve({ approved: false, reason: 'Missing approval port.' }))
115
+ : undefined,
116
+ shouldStop: args.shouldStop,
117
+ abortSignal: args.abortSignal,
118
+ });
119
+ const maintenanceMode = args.memoryMaintenanceMode ?? 'background';
120
+ const inlineMaintenance = maintenanceMode === 'inline' ?
121
+ await runMaintenanceForRecordedCandidates({
122
+ memoryRoot: memoryDir,
123
+ llm,
124
+ source: `chat session ${session.id}`,
125
+ trace: result.trace,
126
+ maxSteps: 20,
127
+ onTraceEvent: (event) => args.host?.events?.onAgentLoopEvent?.({
128
+ type: 'trace',
129
+ runId: result.state.runId,
130
+ event,
131
+ timestamp: new Date().toISOString(),
132
+ }),
133
+ })
134
+ : undefined;
135
+ const resultTrace = inlineMaintenance && inlineMaintenance.events.length > 0 ?
136
+ [...result.trace, ...inlineMaintenance.events]
137
+ : result.trace;
138
+ const resultForPersistence = {
139
+ ...result,
140
+ trace: resultTrace,
141
+ state: {
142
+ ...result.state,
143
+ trace: resultTrace,
144
+ },
145
+ };
146
+ const persisted = await persistChatTurnResult({
147
+ result: resultForPersistence,
148
+ prompt: args.prompt,
149
+ session: preflightSession,
150
+ model,
151
+ stateRoot: args.stateRoot,
152
+ traceDir: join(args.stateRoot, 'traces'),
153
+ systemContext,
154
+ toolNames: tools.map((tool) => tool.name),
155
+ historyForTokenEstimate: session.history,
156
+ summarizer: { credentialSource: providerCredentialSource },
157
+ createTurnId: () => `server-turn-${Date.now()}`,
158
+ onCompactionStatus: (event) => {
159
+ args.onCompactionStatus?.(event);
160
+ args.host?.compaction?.onFinalCompactionStatus?.(event);
161
+ if (event.status === 'running') {
162
+ const compactionSeed = touchSession({
163
+ ...preflightSession,
164
+ history: result.transcript,
165
+ context: buildCompactionRunningContext({
166
+ history: resultForPersistence.transcript,
167
+ previous: preflightSession.context,
168
+ archiveCount: preflightSession.archives?.length,
169
+ currentSummaryPath: preflightSession.context?.currentSummaryPath,
170
+ lastArchivePath: event.archivePath,
171
+ }),
172
+ });
173
+ saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? compactionSeed : candidate));
174
+ }
175
+ },
176
+ });
177
+ const nextSessions = sessions.map((candidate) => candidate.id === session.id ? persisted.session : candidate);
178
+ saveChatSessions(args.sessionStoragePath, nextSessions);
179
+ if (maintenanceMode === 'background') {
180
+ scheduleBackgroundMemoryMaintenance({
181
+ memoryRoot: memoryDir,
182
+ llm,
183
+ source: `chat session ${session.id}`,
184
+ trace: result.trace,
185
+ traceFile: persisted.traceFile,
186
+ sessionStoragePath: args.sessionStoragePath,
187
+ sessionId: session.id,
188
+ runId: result.state?.runId ?? `session-${session.id}`,
189
+ onEvent: args.host?.events?.onAgentLoopEvent,
190
+ });
191
+ }
192
+ return {
193
+ outcome: resultForPersistence.outcome,
194
+ summary: persisted.summary,
195
+ session: persisted.session,
196
+ };
197
+ }
198
+ finally {
199
+ clearOrdinaryChatTurnLease(args.sessionStoragePath, session.id, leaseOwner);
200
+ }
201
+ }
202
+ function scheduleBackgroundMemoryMaintenance(args) {
203
+ void (async () => {
204
+ const maintenance = await runMaintenanceForRecordedCandidates({
205
+ memoryRoot: args.memoryRoot,
206
+ llm: args.llm,
207
+ source: args.source,
208
+ trace: args.trace,
209
+ maxSteps: 20,
210
+ onTraceEvent: (event) => args.onEvent?.({ type: 'trace', runId: args.runId, event, timestamp: new Date().toISOString() }),
211
+ });
212
+ if (maintenance.events.length === 0) {
213
+ return;
214
+ }
215
+ const currentTrace = readTraceEvents(args.traceFile);
216
+ const nextTrace = [...currentTrace, ...maintenance.events];
217
+ writeFileSync(args.traceFile, `${JSON.stringify(nextTrace, null, 2)}\n`, 'utf8');
218
+ const sessions = loadChatSessions(args.sessionStoragePath, true);
219
+ const nextSessions = sessions.map((session) => {
220
+ if (session.id !== args.sessionId) {
221
+ return session;
222
+ }
223
+ return touchSession({
224
+ ...session,
225
+ turns: session.turns.map((turn, index) => (index === session.turns.length - 1 ?
226
+ {
227
+ ...turn,
228
+ events: summarizeTrace(nextTrace),
229
+ }
230
+ : turn)),
231
+ });
232
+ });
233
+ saveChatSessions(args.sessionStoragePath, nextSessions);
234
+ })().catch((error) => {
235
+ args.onEvent?.({
236
+ type: 'trace',
237
+ runId: args.runId,
238
+ event: {
239
+ type: 'memory.maintenance_failed',
240
+ runId: `memory-run-${Date.now()}`,
241
+ error: error instanceof Error ? error.message : String(error),
242
+ candidateIds: [],
243
+ step: nextTraceStep(args.trace),
244
+ timestamp: new Date().toISOString(),
245
+ },
246
+ timestamp: new Date().toISOString(),
247
+ });
248
+ });
249
+ }
250
+ function readTraceEvents(path) {
251
+ try {
252
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
253
+ return Array.isArray(parsed) ? parsed : [];
254
+ }
255
+ catch {
256
+ return [];
257
+ }
258
+ }
259
+ function nextTraceStep(trace) {
260
+ return trace.reduce((max, event) => 'step' in event ? Math.max(max, event.step) : max, 0) + 1;
261
+ }
262
+ export function clearOrdinaryChatTurnLease(sessionStoragePath, sessionId, owner) {
263
+ const sessions = loadChatSessions(sessionStoragePath, true);
264
+ const session = sessions.find((candidate) => candidate.id === sessionId);
265
+ if (!session?.lease) {
266
+ return;
267
+ }
268
+ const released = releaseSessionLease(session, owner);
269
+ if (released === session) {
270
+ return;
271
+ }
272
+ saveChatSessions(sessionStoragePath, sessions.map((candidate) => candidate.id === sessionId ? touchSession(released) : candidate));
273
+ }
274
+ //# sourceMappingURL=ordinary-turn.js.map
@@ -0,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QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,gBAAgB,CACd,kBAAkB,EAClB,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAC7F,CAAC;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { ToolCall, ToolDefinition } from '../../index.js';
2
- import { type ChatSessionLeaseOwner } from './session-lease.js';
3
- import type { ChatSession } from './types.js';
2
+ import { clearOrdinaryChatTurnLease } from './ordinary-turn.js';
3
+ import type { ChatSessionLeaseOwner } from './session-lease.js';
4
4
  import type { AgentLoopEvent } from '../../index.js';
5
5
  export type SubmitChatSessionPromptArgs = {
6
6
  workspaceRoot: string;
@@ -29,7 +29,7 @@ export type SubmitChatSessionPromptArgs = {
29
29
  export declare function submitChatSessionPrompt(args: SubmitChatSessionPromptArgs): Promise<{
30
30
  outcome: import("../types.js").StopReason;
31
31
  summary: string;
32
- session: ChatSession;
32
+ session: import("./types.js").ChatSession;
33
33
  }>;
34
- export declare function clearChatSessionLease(sessionStoragePath: string, sessionId: string, owner: ChatSessionLeaseOwner): void;
34
+ export declare const clearChatSessionLease: typeof clearOrdinaryChatTurnLease;
35
35
  //# sourceMappingURL=session-submit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-submit.d.ts","sourceRoot":"","sources":["../../../../src/core/chat/session-submit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmB,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKhF,OAAO,EAAqE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEnI,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAA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} from 'node:path';
2
- import { readFileSync, writeFileSync } from 'node:fs';
3
- import { appendMemoryCatalogSystemContext, createDefaultAgentTools, createLlmAdapter, DEFAULT_OPENAI_MODEL, inferProviderFromModel, runAgentLoop, } from '../../index.js';
4
- import { runMaintenanceForRecordedCandidates } from '../memory/maintenance-integration.js';
5
- import { buildCompactionRunningContext, compactChatHistoryWithArchive, estimateChatHistoryTokens } from './compaction.js';
6
- import { buildConversationMessages } from './conversation-lines.js';
7
- import { formatChatFailureMessage } from './failure-messages.js';
8
- import { acquireSessionLease, getSessionLeaseConflict, releaseSessionLease } from './session-lease.js';
9
- import { loadChatSessions, saveChatSessions, touchSession } from './storage.js';
10
- import { saveTrace } from './trace.js';
11
- import { countAssistantSteps, summarizeTrace } from './trace-summary.js';
12
- import { formatMissingProviderCredentialMessage, hasProviderCredentialForModel, resolveApiKeyForModel, resolveProviderCredentialSourceForModel, } from '../../core/runtime/api-keys.js';
1
+ import { executeOrdinaryChatTurn, clearOrdinaryChatTurnLease } from './ordinary-turn.js';
13
2
  export async function submitChatSessionPrompt(args) {
14
- const sessions = loadChatSessions(args.sessionStoragePath, true);
15
- const session = sessions.find((candidate) => candidate.id === args.sessionId);
16
- if (!session) {
17
- throw new Error(`Chat session not found: ${args.sessionId}`);
18
- }
19
- const model = session.model ?? process.env.OPENAI_MODEL ?? process.env.ANTHROPIC_MODEL ?? DEFAULT_OPENAI_MODEL;
20
- const provider = inferProviderFromModel(model);
21
- const apiKey = args.apiKey ?? resolveApiKeyForModel(model, { preferApiKey: args.preferApiKey });
22
- const providerCredentialSource = resolveProviderCredentialSourceForModel(model, {
23
- apiKey,
24
- apiKeyProvider: args.apiKey ? 'explicit' : apiKey ? provider : undefined,
25
- preferApiKey: args.preferApiKey,
26
- });
27
- if (!hasProviderCredentialForModel(model, {
3
+ const result = await executeOrdinaryChatTurn({
4
+ workspaceRoot: args.workspaceRoot,
5
+ stateRoot: args.stateRoot,
6
+ sessionStoragePath: args.sessionStoragePath,
7
+ sessionId: args.sessionId,
8
+ prompt: args.prompt,
28
9
  apiKey: args.apiKey,
29
- apiKeyProvider: args.apiKey ? 'explicit' : undefined,
30
10
  preferApiKey: args.preferApiKey,
31
- })) {
32
- throw new Error(formatMissingProviderCredentialMessage(model));
33
- }
34
- const leaseOwner = args.leaseOwner ?? {
35
- ownerKind: 'ask',
36
- ownerId: `submit-${process.pid}`,
37
- clientLabel: 'another Heddle client',
38
- };
39
- const leaseConflict = getSessionLeaseConflict(session, leaseOwner);
40
- if (leaseConflict) {
41
- throw new Error(leaseConflict);
42
- }
43
- const leasedSession = touchSession(acquireSessionLease(session, leaseOwner));
44
- saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? leasedSession : candidate));
45
- const llm = createLlmAdapter({ model, apiKey, credentialStorePath: args.stateRoot });
46
- const memoryDir = join(args.stateRoot, 'memory');
47
- const systemContext = appendMemoryCatalogSystemContext({
48
11
  systemContext: args.systemContext,
49
- memoryRoot: memoryDir,
50
- });
51
- const tools = createDefaultAgentTools({
52
- model,
53
- apiKey,
54
- providerCredentialSource,
55
- credentialStorePath: args.stateRoot,
56
- workspaceRoot: args.workspaceRoot,
57
- memoryDir,
58
- searchIgnoreDirs: [],
59
- includePlanTool: true,
12
+ memoryMaintenanceMode: args.memoryMaintenanceMode,
13
+ host: {
14
+ events: args.onEvent ? { onAgentLoopEvent: args.onEvent } : undefined,
15
+ compaction: args.onCompactionStatus ? {
16
+ onPreflightCompactionStatus: args.onCompactionStatus,
17
+ onFinalCompactionStatus: args.onCompactionStatus,
18
+ } : undefined,
19
+ approvals: args.approveToolCall ? {
20
+ requestToolApproval: ({ call, tool }) => args.approveToolCall?.(call, tool) ?? Promise.resolve({ approved: false, reason: 'Missing approval handler.' }),
21
+ } : undefined,
22
+ },
23
+ onCompactionStatus: args.onCompactionStatus,
24
+ abortSignal: args.abortSignal,
25
+ leaseOwner: args.leaseOwner,
60
26
  });
61
- try {
62
- const preflightCompacted = await compactChatHistoryWithArchive({
63
- history: session.history,
64
- model,
65
- sessionId: session.id,
66
- stateRoot: args.stateRoot,
67
- toolNames: tools.map((tool) => tool.name),
68
- goal: args.prompt,
69
- systemContext,
70
- summarizer: { credentialSource: providerCredentialSource },
71
- onStatusChange: (event) => {
72
- args.onCompactionStatus?.(event);
73
- if (event.status === 'running') {
74
- const compactionSeed = touchSession({
75
- ...leasedSession,
76
- context: buildCompactionRunningContext({
77
- history: leasedSession.history,
78
- previous: leasedSession.context,
79
- archiveCount: leasedSession.archives?.length,
80
- currentSummaryPath: leasedSession.context?.currentSummaryPath,
81
- lastArchivePath: event.archivePath,
82
- }),
83
- });
84
- saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? compactionSeed : candidate));
85
- }
86
- },
87
- });
88
- const preflightSession = preflightCompacted.history !== leasedSession.history || preflightCompacted.archives.length !== (leasedSession.archives?.length ?? 0) ?
89
- touchSession({
90
- ...leasedSession,
91
- history: preflightCompacted.history,
92
- context: preflightCompacted.context,
93
- archives: preflightCompacted.archives,
94
- messages: buildConversationMessages(preflightCompacted.history),
95
- })
96
- : leasedSession;
97
- if (preflightSession !== leasedSession) {
98
- saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? preflightSession : candidate));
99
- }
100
- const result = await runAgentLoop({
101
- goal: args.prompt,
102
- model,
103
- apiKey,
104
- workspaceRoot: args.workspaceRoot,
105
- stateDir: args.stateRoot,
106
- memoryDir,
107
- llm,
108
- tools,
109
- includeDefaultTools: false,
110
- history: preflightSession.history,
111
- systemContext,
112
- onEvent: args.onEvent,
113
- approveToolCall: args.approveToolCall,
114
- abortSignal: args.abortSignal,
115
- });
116
- const maintenanceMode = args.memoryMaintenanceMode ?? 'background';
117
- const inlineMaintenance = maintenanceMode === 'inline' ?
118
- await runMaintenanceForRecordedCandidates({
119
- memoryRoot: memoryDir,
120
- llm,
121
- source: `chat session ${session.id}`,
122
- trace: result.trace,
123
- maxSteps: 20,
124
- onTraceEvent: (event) => args.onEvent?.({ type: 'trace', runId: result.state.runId, event, timestamp: new Date().toISOString() }),
125
- })
126
- : undefined;
127
- const resultTrace = inlineMaintenance && inlineMaintenance.events.length > 0 ?
128
- [...result.trace, ...inlineMaintenance.events]
129
- : result.trace;
130
- const resultForPersistence = {
131
- ...result,
132
- trace: resultTrace,
133
- state: {
134
- ...result.state,
135
- trace: resultTrace,
136
- },
137
- };
138
- const compacted = await compactChatHistoryWithArchive({
139
- history: resultForPersistence.transcript,
140
- model,
141
- sessionId: session.id,
142
- stateRoot: args.stateRoot,
143
- usage: resultForPersistence.usage,
144
- toolNames: tools.map((tool) => tool.name),
145
- goal: args.prompt,
146
- systemContext,
147
- summarizer: { credentialSource: providerCredentialSource },
148
- onStatusChange: (event) => {
149
- args.onCompactionStatus?.(event);
150
- if (event.status === 'running') {
151
- const compactionSeed = touchSession({
152
- ...preflightSession,
153
- history: result.transcript,
154
- context: buildCompactionRunningContext({
155
- history: resultForPersistence.transcript,
156
- previous: preflightSession.context,
157
- archiveCount: preflightSession.archives?.length,
158
- currentSummaryPath: preflightSession.context?.currentSummaryPath,
159
- lastArchivePath: event.archivePath,
160
- }),
161
- });
162
- saveChatSessions(args.sessionStoragePath, sessions.map((candidate) => candidate.id === session.id ? compactionSeed : candidate));
163
- }
164
- },
165
- });
166
- const traceFile = saveTrace(join(args.stateRoot, 'traces'), resultForPersistence.trace);
167
- const nextTurn = {
168
- id: `server-turn-${Date.now()}`,
169
- prompt: args.prompt,
170
- outcome: resultForPersistence.outcome,
171
- summary: resultForPersistence.summary,
172
- steps: countAssistantSteps(resultForPersistence.trace),
173
- traceFile,
174
- events: summarizeTrace(resultForPersistence.trace),
175
- };
176
- const formattedSummary = resultForPersistence.outcome === 'error' ?
177
- formatChatFailureMessage(resultForPersistence.summary, {
178
- model,
179
- estimatedHistoryTokens: estimateChatHistoryTokens(session.history),
180
- })
181
- : resultForPersistence.summary;
182
- const updatedSession = touchSession({
183
- ...preflightSession,
184
- lastContinuePrompt: args.prompt,
185
- history: compacted.history,
186
- context: compacted.context,
187
- archives: compacted.archives,
188
- lease: undefined,
189
- messages: buildConversationMessages(compacted.history),
190
- turns: [...preflightSession.turns, nextTurn].slice(-8),
191
- });
192
- const nextSessions = sessions.map((candidate) => candidate.id === session.id ? updatedSession : candidate);
193
- saveChatSessions(args.sessionStoragePath, nextSessions);
194
- if (maintenanceMode === 'background') {
195
- scheduleBackgroundMemoryMaintenance({
196
- memoryRoot: memoryDir,
197
- llm,
198
- source: `chat session ${session.id}`,
199
- trace: result.trace,
200
- traceFile,
201
- sessionStoragePath: args.sessionStoragePath,
202
- sessionId: session.id,
203
- runId: result.state?.runId ?? `session-${session.id}`,
204
- onEvent: args.onEvent,
205
- });
206
- }
207
- return {
208
- outcome: resultForPersistence.outcome,
209
- summary: formattedSummary,
210
- session: updatedSession,
211
- };
212
- }
213
- finally {
214
- clearChatSessionLease(args.sessionStoragePath, session.id, leaseOwner);
215
- }
216
- }
217
- function scheduleBackgroundMemoryMaintenance(args) {
218
- void (async () => {
219
- const maintenance = await runMaintenanceForRecordedCandidates({
220
- memoryRoot: args.memoryRoot,
221
- llm: args.llm,
222
- source: args.source,
223
- trace: args.trace,
224
- maxSteps: 20,
225
- onTraceEvent: (event) => args.onEvent?.({ type: 'trace', runId: args.runId, event, timestamp: new Date().toISOString() }),
226
- });
227
- if (maintenance.events.length === 0) {
228
- return;
229
- }
230
- const currentTrace = readTraceEvents(args.traceFile);
231
- const nextTrace = [...currentTrace, ...maintenance.events];
232
- writeFileSync(args.traceFile, `${JSON.stringify(nextTrace, null, 2)}\n`, 'utf8');
233
- const sessions = loadChatSessions(args.sessionStoragePath, true);
234
- const nextSessions = sessions.map((session) => {
235
- if (session.id !== args.sessionId) {
236
- return session;
237
- }
238
- return touchSession({
239
- ...session,
240
- turns: session.turns.map((turn, index) => (index === session.turns.length - 1 ?
241
- {
242
- ...turn,
243
- events: summarizeTrace(nextTrace),
244
- }
245
- : turn)),
246
- });
247
- });
248
- saveChatSessions(args.sessionStoragePath, nextSessions);
249
- })().catch((error) => {
250
- args.onEvent?.({
251
- type: 'trace',
252
- runId: args.runId,
253
- event: {
254
- type: 'memory.maintenance_failed',
255
- runId: `memory-run-${Date.now()}`,
256
- error: error instanceof Error ? error.message : String(error),
257
- candidateIds: [],
258
- step: nextTraceStep(args.trace),
259
- timestamp: new Date().toISOString(),
260
- },
261
- timestamp: new Date().toISOString(),
262
- });
263
- });
264
- }
265
- function readTraceEvents(path) {
266
- try {
267
- const parsed = JSON.parse(readFileSync(path, 'utf8'));
268
- return Array.isArray(parsed) ? parsed : [];
269
- }
270
- catch {
271
- return [];
272
- }
273
- }
274
- function nextTraceStep(trace) {
275
- return trace.reduce((max, event) => 'step' in event ? Math.max(max, event.step) : max, 0) + 1;
276
- }
277
- export function clearChatSessionLease(sessionStoragePath, sessionId, owner) {
278
- const sessions = loadChatSessions(sessionStoragePath, true);
279
- const session = sessions.find((candidate) => candidate.id === sessionId);
280
- if (!session?.lease) {
281
- return;
282
- }
283
- const released = releaseSessionLease(session, owner);
284
- if (released === session) {
285
- return;
286
- }
287
- saveChatSessions(sessionStoragePath, sessions.map((candidate) => candidate.id === sessionId ? touchSession(released) : candidate));
27
+ return result;
288
28
  }
29
+ export const clearChatSessionLease = clearOrdinaryChatTurnLease;
289
30
  //# sourceMappingURL=session-submit.js.map