@denizokcu/haze 1.0.0 → 1.1.1
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 +33 -0
- package/README.md +17 -8
- package/SECURITY.md +3 -1
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/TaskBar.js +1 -1
- package/dist/cli/chat/busyIndicator.d.ts +11 -0
- package/dist/cli/chat/busyIndicator.js +34 -0
- package/dist/cli/chat/chatMetrics.d.ts +0 -1
- package/dist/cli/chat/chatMetrics.js +1 -7
- package/dist/cli/chat/followUpQueue.d.ts +11 -0
- package/dist/cli/chat/followUpQueue.js +38 -0
- package/dist/cli/chat/inputSuggestions.js +1 -0
- package/dist/cli/chat/messages.d.ts +0 -22
- package/dist/cli/chat/messages.js +42 -87
- package/dist/cli/chat/sessionLifecycle.d.ts +3 -1
- package/dist/cli/chat/sessionLifecycle.js +6 -1
- package/dist/cli/chat/sessionRecorder.d.ts +2 -0
- package/dist/cli/chat/sessionRecorder.js +6 -0
- package/dist/cli/chat/startupSequence.d.ts +29 -0
- package/dist/cli/chat/startupSequence.js +59 -0
- package/dist/cli/chat/transcriptPartition.d.ts +23 -0
- package/dist/cli/chat/transcriptPartition.js +78 -0
- package/dist/cli/chat/wizard/fieldTransitions.d.ts +38 -0
- package/dist/cli/chat/wizard/fieldTransitions.js +43 -0
- package/dist/cli/chat/wizard/lspHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/lspHandlers.js +85 -0
- package/dist/cli/chat/wizard/mcpHandlers.d.ts +8 -0
- package/dist/cli/chat/wizard/mcpHandlers.js +82 -0
- package/dist/cli/chat/wizard/providerHandlers.d.ts +12 -0
- package/dist/cli/chat/wizard/providerHandlers.js +420 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +48 -0
- package/dist/cli/chat/wizard/skillsHandlers.d.ts +4 -0
- package/dist/cli/chat/wizard/skillsHandlers.js +125 -0
- package/dist/cli/chat/wizard/types.d.ts +63 -0
- package/dist/cli/chat/wizard/types.js +24 -0
- package/dist/cli/chat/wizard/uiState.d.ts +56 -0
- package/dist/cli/chat/wizard/uiState.js +15 -0
- package/dist/cli/chat/wizardDispatch.d.ts +11 -113
- package/dist/cli/chat/wizardDispatch.js +41 -805
- package/dist/cli/commands/chat.js +89 -110
- package/dist/cli/commands/commandHelp.js +2 -0
- package/dist/cli/commands/commands.js +2 -0
- package/dist/cli/commands/formatters.d.ts +0 -3
- package/dist/cli/commands/formatters.js +6 -29
- package/dist/cli/commands/runCommand.d.ts +2 -0
- package/dist/cli/commands/runCommand.js +67 -4
- package/dist/cli/commands/settingsSummary.js +2 -0
- package/dist/cli/commands/streaming/assistantSegments.d.ts +19 -0
- package/dist/cli/commands/streaming/assistantSegments.js +48 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +2 -2
- package/dist/cli/commands/streaming/attemptOutcome.js +17 -7
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +69 -8
- package/dist/cli/commands/streaming/goalCheckpoint.js +36 -1
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +17 -2
- package/dist/cli/commands/streaming/goalSupervisor.js +62 -12
- package/dist/cli/commands/streaming/prepareStep.d.ts +35 -0
- package/dist/cli/commands/streaming/prepareStep.js +100 -0
- package/dist/cli/commands/streaming/recoverySlices.d.ts +15 -0
- package/dist/cli/commands/streaming/recoverySlices.js +29 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +0 -1
- package/dist/cli/commands/streaming/stallRecovery.js +0 -4
- package/dist/cli/commands/streaming/streamLoop.js +9 -230
- package/dist/cli/commands/streaming/toolGroupRenderer.js +2 -1
- package/dist/cli/commands/streaming/toolPartHandlers.d.ts +19 -0
- package/dist/cli/commands/streaming/toolPartHandlers.js +95 -0
- package/dist/cli/commands/streaming.d.ts +4 -1
- package/dist/cli/commands/streaming.js +6 -21
- package/dist/cli/commands/themesCommand.d.ts +17 -0
- package/dist/cli/commands/themesCommand.js +24 -0
- package/dist/cli/commands/wizardFlow.d.ts +7 -0
- package/dist/cli/commands/wizardFlow.js +20 -0
- package/dist/cli/index.js +3 -1
- package/dist/config/providerPresets.d.ts +7 -0
- package/dist/config/providerPresets.js +195 -391
- package/dist/config/settings.d.ts +2 -0
- package/dist/config/settings.js +1 -0
- package/dist/core/agent/completionController.d.ts +14 -7
- package/dist/core/agent/completionController.js +12 -6
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/goalPolicy.d.ts +4 -3
- package/dist/core/agent/goalPolicy.js +9 -4
- package/dist/core/agent/workState.d.ts +25 -15
- package/dist/core/agent/workState.js +71 -43
- package/dist/core/safety/secretPaths.d.ts +18 -0
- package/dist/core/safety/secretPaths.js +115 -0
- package/dist/core/session/sessionSlimming.js +8 -0
- package/dist/core/session/sessionStore.d.ts +61 -1
- package/dist/core/session/sessionStore.js +115 -6
- package/dist/llm/hazeTools.d.ts +64 -208
- package/dist/llm/hazeTools.js +6 -0
- package/dist/llm/systemPrompt.js +3 -1
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/failures.d.ts +6 -0
- package/dist/llm/tools/failures.js +8 -2
- package/dist/llm/tools/readRecovery.js +2 -0
- package/dist/llm/tools/shellTool.js +3 -0
- package/dist/llm/tools/taskTool.d.ts +64 -208
- package/dist/llm/tools/taskTool.js +22 -10
- package/dist/llm/tools/workspaceFile.d.ts +4 -3
- package/dist/llm/tools/workspaceFile.js +30 -13
- package/dist/ui/components/Header.js +1 -1
- package/dist/ui/components/MarkdownText.js +10 -10
- package/dist/ui/components/TextInput.d.ts +1 -1
- package/dist/ui/components/TextInput.js +8 -69
- package/dist/ui/components/useInputSuggestions.d.ts +27 -0
- package/dist/ui/components/useInputSuggestions.js +98 -0
- package/dist/ui/terminalColors.d.ts +29 -0
- package/dist/ui/terminalColors.js +47 -0
- package/dist/ui/theme.d.ts +105 -10
- package/dist/ui/theme.js +125 -15
- package/dist/ui/themes/registry.d.ts +5 -0
- package/dist/ui/themes/registry.js +436 -0
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/format.js +45 -0
- package/package.json +1 -1
|
@@ -29,7 +29,51 @@ export type SessionEntry = {
|
|
|
29
29
|
at: string;
|
|
30
30
|
name: string;
|
|
31
31
|
text?: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'goal';
|
|
34
|
+
at: string;
|
|
35
|
+
goalId: string;
|
|
36
|
+
phase: 'goal_start' | 'goal_continue' | 'goal_end';
|
|
37
|
+
request: string;
|
|
38
|
+
requestHash: string;
|
|
39
|
+
intent: string;
|
|
40
|
+
cycle: number;
|
|
41
|
+
mutationCount: number;
|
|
42
|
+
validationOutcome: string;
|
|
43
|
+
progressSignature: string;
|
|
44
|
+
taskCounts?: {
|
|
45
|
+
total: number;
|
|
46
|
+
pending: number;
|
|
47
|
+
inProgress: number;
|
|
48
|
+
completed: number;
|
|
49
|
+
};
|
|
50
|
+
redEvidence?: {
|
|
51
|
+
command: string;
|
|
52
|
+
commandKey: string;
|
|
53
|
+
summary: string;
|
|
54
|
+
};
|
|
55
|
+
stopReason?: string;
|
|
56
|
+
status?: string;
|
|
32
57
|
};
|
|
58
|
+
/** Durable goal-ledger entry (P1): one append per supervisor boundary. */
|
|
59
|
+
export type GoalLedgerEntry = Extract<SessionEntry, {
|
|
60
|
+
type: 'goal';
|
|
61
|
+
}>;
|
|
62
|
+
/** An unterminated goal frontier detected in a session (P1 resume path). */
|
|
63
|
+
export interface GoalLedgerFrontier {
|
|
64
|
+
goalId: string;
|
|
65
|
+
request: string;
|
|
66
|
+
requestHash: string;
|
|
67
|
+
intent: string;
|
|
68
|
+
cycle: number;
|
|
69
|
+
mutationCount: number;
|
|
70
|
+
validationOutcome: string;
|
|
71
|
+
progressSignature: string;
|
|
72
|
+
taskCounts?: GoalLedgerEntry['taskCounts'];
|
|
73
|
+
/** Unresolved red evidence carried so crash resume preserves the pending same-check green requirement. */
|
|
74
|
+
redEvidence?: GoalLedgerEntry['redEvidence'];
|
|
75
|
+
at: string;
|
|
76
|
+
}
|
|
33
77
|
type SessionHeader = Extract<SessionEntry, {
|
|
34
78
|
type: 'header';
|
|
35
79
|
}>;
|
|
@@ -70,6 +114,10 @@ export declare function appendSessionEntry(session: HazeSession, entry: SessionE
|
|
|
70
114
|
export declare const SESSION_VACUUM_THRESHOLD_BYTES: number;
|
|
71
115
|
/** Test-only override for the vacuum trigger; tests restore the original. */
|
|
72
116
|
export declare function setSessionVacuumThresholdForTests(bytes: number): void;
|
|
117
|
+
/** Trailing goal-ledger entries preserved per goal id when the vacuum rewrites (frontier + end + one audit entry). */
|
|
118
|
+
export declare const GOAL_LEDGER_KEEP_PER_GOAL = 3;
|
|
119
|
+
/** Ledger trim must amortize its rewrite: rewrite for goal entries alone only past this many dropped bytes. */
|
|
120
|
+
export declare const GOAL_LEDGER_TRIM_BYTES = 2048;
|
|
73
121
|
export declare function vacuumSessionFileIfLarge(session: HazeSession, thresholdBytes?: number): Promise<boolean>;
|
|
74
122
|
export interface ReadSessionEntriesResult {
|
|
75
123
|
entries: SessionEntry[];
|
|
@@ -84,6 +132,16 @@ export interface ReadSessionEntriesResult {
|
|
|
84
132
|
* loss in debug mode instead of silently dropping messages.
|
|
85
133
|
*/
|
|
86
134
|
export declare function readSessionEntries(session: HazeSession): Promise<ReadSessionEntriesResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Pure frontier detection over parsed session entries (P1): the append-only
|
|
137
|
+
* goal ledger's frontier is the last entry of the most recent goal id that has
|
|
138
|
+
* no `goal_end` entry. A truncated or malformed tail line parses as absent, so
|
|
139
|
+
* a crash mid-write can never resurrect a half-written boundary
|
|
140
|
+
* (autoprompt's "treat half-written artifacts as absent").
|
|
141
|
+
*/
|
|
142
|
+
export declare function findGoalLedgerFrontier(entries: readonly SessionEntry[]): GoalLedgerFrontier | undefined;
|
|
143
|
+
/** Read the goal-ledger frontier of a stored session (one file scan). */
|
|
144
|
+
export declare function readGoalLedgerFrontier(session: HazeSession): Promise<GoalLedgerFrontier | undefined>;
|
|
87
145
|
export interface RestoreConversationResult {
|
|
88
146
|
messages: ModelMessage[];
|
|
89
147
|
parseErrors: string[];
|
|
@@ -92,11 +150,13 @@ export interface RestoreSessionStateResult {
|
|
|
92
150
|
messages: ModelMessage[];
|
|
93
151
|
workState: WorkState | undefined;
|
|
94
152
|
parseErrors: string[];
|
|
153
|
+
/** Unterminated goal frontier from the durable ledger, if any (P1 resume path). */
|
|
154
|
+
goalFrontier: GoalLedgerFrontier | undefined;
|
|
95
155
|
}
|
|
96
156
|
/**
|
|
97
157
|
* Restore conversation and work state in one file scan (CR-013). Session
|
|
98
158
|
* files grow to megabytes in long workspaces; resuming should not parse the
|
|
99
|
-
* JSONL twice.
|
|
159
|
+
* JSONL twice. The goal-ledger frontier rides the same scan (P1).
|
|
100
160
|
*/
|
|
101
161
|
export declare function restoreSessionState(session: HazeSession): Promise<RestoreSessionStateResult>;
|
|
102
162
|
export declare function restoreConversation(session: HazeSession): Promise<RestoreConversationResult>;
|
|
@@ -6,6 +6,15 @@ import { prepareSessionEntryForWrite } from './sessionSlimming.js';
|
|
|
6
6
|
import { appendPrivateFile, ensurePrivateDir, tightenPrivateFile, writePrivateFileAtomic } from '../../config/privateStorage.js';
|
|
7
7
|
import { JSONL_LINE_BYTES } from '../limits.js';
|
|
8
8
|
import { iterateBoundedUtf8Lines } from '../io/boundedRead.js';
|
|
9
|
+
function parseLedgerRedEvidence(value) {
|
|
10
|
+
if (typeof value !== 'object' || value == null)
|
|
11
|
+
return undefined;
|
|
12
|
+
const record = value;
|
|
13
|
+
if (typeof record.command !== 'string' || typeof record.commandKey !== 'string')
|
|
14
|
+
return undefined;
|
|
15
|
+
const summary = typeof record.summary === 'string' ? record.summary : '';
|
|
16
|
+
return { command: record.command.slice(0, 400), commandKey: record.commandKey.slice(0, 400), summary: summary.slice(0, 200) };
|
|
17
|
+
}
|
|
9
18
|
const DEFAULT_SESSIONS_DIR = path.join(HAZE_DIR, 'sessions');
|
|
10
19
|
function cwdHash(cwd = process.cwd()) {
|
|
11
20
|
return crypto.createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 16);
|
|
@@ -110,6 +119,10 @@ let effectiveVacuumThresholdBytes = SESSION_VACUUM_THRESHOLD_BYTES;
|
|
|
110
119
|
export function setSessionVacuumThresholdForTests(bytes) {
|
|
111
120
|
effectiveVacuumThresholdBytes = bytes;
|
|
112
121
|
}
|
|
122
|
+
/** Trailing goal-ledger entries preserved per goal id when the vacuum rewrites (frontier + end + one audit entry). */
|
|
123
|
+
export const GOAL_LEDGER_KEEP_PER_GOAL = 3;
|
|
124
|
+
/** Ledger trim must amortize its rewrite: rewrite for goal entries alone only past this many dropped bytes. */
|
|
125
|
+
export const GOAL_LEDGER_TRIM_BYTES = 2_048;
|
|
113
126
|
export async function vacuumSessionFileIfLarge(session, thresholdBytes = effectiveVacuumThresholdBytes) {
|
|
114
127
|
const file = validatedSessionFile(session);
|
|
115
128
|
if (session.deferredWrite)
|
|
@@ -126,16 +139,36 @@ export async function vacuumSessionFileIfLarge(session, thresholdBytes = effecti
|
|
|
126
139
|
if (entry.type === 'work_state_snapshot')
|
|
127
140
|
lastWorkState = index;
|
|
128
141
|
});
|
|
142
|
+
// Goal-ledger bound (P1): long autonomous goals append one entry per physical
|
|
143
|
+
// turn; intermediate `goal_continue` entries of superseded cycles are audit
|
|
144
|
+
// trail only. Keep the trailing few per goal id — the frontier and the
|
|
145
|
+
// terminal entry are always among them — so a very long-lived session file
|
|
146
|
+
// stays bounded without ever losing a live frontier.
|
|
147
|
+
const keepGoal = new Set();
|
|
148
|
+
const goalIndexesByGoal = new Map();
|
|
149
|
+
entries.forEach((entry, index) => {
|
|
150
|
+
if (entry.type === 'goal')
|
|
151
|
+
goalIndexesByGoal.set(entry.goalId, [...(goalIndexesByGoal.get(entry.goalId) ?? []), index]);
|
|
152
|
+
});
|
|
153
|
+
for (const indexes of goalIndexesByGoal.values()) {
|
|
154
|
+
for (const index of indexes.slice(-GOAL_LEDGER_KEEP_PER_GOAL))
|
|
155
|
+
keepGoal.add(index);
|
|
156
|
+
}
|
|
129
157
|
// Malformed lines are dropped by the rewrite: they were already unusable
|
|
130
158
|
// (and reported as parse errors on read) and keeping them would defeat the
|
|
131
159
|
// size bound the vacuum exists to enforce.
|
|
132
|
-
const
|
|
160
|
+
const candidate = entries.filter((entry, index) => (entry.type !== 'conversation_snapshot' && entry.type !== 'work_state_snapshot')
|
|
133
161
|
|| index === lastConversation
|
|
134
162
|
|| index === lastWorkState);
|
|
163
|
+
const kept = candidate.filter((entry, index) => entry.type !== 'goal' || keepGoal.has(index));
|
|
164
|
+
const droppedGoalBytes = candidate
|
|
165
|
+
.filter((entry, index) => entry.type === 'goal' && !keepGoal.has(index))
|
|
166
|
+
.reduce((sum, entry) => sum + Buffer.byteLength(JSON.stringify(entry), 'utf8'), 0);
|
|
135
167
|
const serialized = kept.map(entry => JSON.stringify(entry)).join('\n') + '\n';
|
|
136
|
-
// Only rewrite when it meaningfully shrinks the file
|
|
137
|
-
// dominant snapshot would trigger a full rewrite on every append
|
|
138
|
-
|
|
168
|
+
// Only rewrite when it meaningfully shrinks the file (otherwise a single
|
|
169
|
+
// dominant snapshot would trigger a full rewrite on every append), or when
|
|
170
|
+
// the goal-ledger trim alone has accumulated enough to amortize the rewrite.
|
|
171
|
+
if (serialized.length > stat.size / 2 && droppedGoalBytes < GOAL_LEDGER_TRIM_BYTES)
|
|
139
172
|
return false;
|
|
140
173
|
await writePrivateFileAtomic(file, serialized);
|
|
141
174
|
return true;
|
|
@@ -155,6 +188,31 @@ function optionalBuildProvenance(value) {
|
|
|
155
188
|
return false;
|
|
156
189
|
return optionalString(value.commit) && optionalString(value.builtAt);
|
|
157
190
|
}
|
|
191
|
+
function optionalTaskCounts(value) {
|
|
192
|
+
if (value === undefined)
|
|
193
|
+
return true;
|
|
194
|
+
if (!isRecord(value))
|
|
195
|
+
return false;
|
|
196
|
+
return ['total', 'pending', 'inProgress', 'completed'].every(key => typeof value[key] === 'number');
|
|
197
|
+
}
|
|
198
|
+
function optionalLedgerRedEvidence(value) {
|
|
199
|
+
return value === undefined || parseLedgerRedEvidence(value) !== undefined;
|
|
200
|
+
}
|
|
201
|
+
function frontierFromGoalEntry(entry) {
|
|
202
|
+
return {
|
|
203
|
+
goalId: entry.goalId,
|
|
204
|
+
request: entry.request,
|
|
205
|
+
requestHash: entry.requestHash,
|
|
206
|
+
intent: entry.intent,
|
|
207
|
+
cycle: entry.cycle,
|
|
208
|
+
mutationCount: entry.mutationCount,
|
|
209
|
+
validationOutcome: entry.validationOutcome,
|
|
210
|
+
progressSignature: entry.progressSignature,
|
|
211
|
+
...(entry.taskCounts ? { taskCounts: entry.taskCounts } : {}),
|
|
212
|
+
...(entry.redEvidence ? { redEvidence: entry.redEvidence } : {}),
|
|
213
|
+
at: entry.at,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
158
216
|
function parseSessionEntry(value) {
|
|
159
217
|
const invalid = (detail) => {
|
|
160
218
|
throw new Error(`unexpected entry shape: ${detail}`);
|
|
@@ -192,6 +250,17 @@ function parseSessionEntry(value) {
|
|
|
192
250
|
if (typeof value.at !== 'string' || typeof value.name !== 'string' || !optionalString(value.text))
|
|
193
251
|
return invalid('invalid event');
|
|
194
252
|
return value;
|
|
253
|
+
case 'goal':
|
|
254
|
+
if (typeof value.at !== 'string' || typeof value.goalId !== 'string'
|
|
255
|
+
|| (value.phase !== 'goal_start' && value.phase !== 'goal_continue' && value.phase !== 'goal_end')
|
|
256
|
+
|| typeof value.request !== 'string' || typeof value.requestHash !== 'string' || typeof value.intent !== 'string'
|
|
257
|
+
|| typeof value.cycle !== 'number' || typeof value.mutationCount !== 'number'
|
|
258
|
+
|| typeof value.validationOutcome !== 'string' || typeof value.progressSignature !== 'string'
|
|
259
|
+
|| !optionalTaskCounts(value.taskCounts)
|
|
260
|
+
|| !optionalString(value.stopReason) || !optionalString(value.status)
|
|
261
|
+
|| !optionalLedgerRedEvidence(value.redEvidence))
|
|
262
|
+
return invalid('invalid goal');
|
|
263
|
+
return value;
|
|
195
264
|
default:
|
|
196
265
|
return invalid(`unknown entry type '${type}'`);
|
|
197
266
|
}
|
|
@@ -239,21 +308,61 @@ export async function readSessionEntries(session) {
|
|
|
239
308
|
const parseErrors = await scanSessionEntries(session, entry => entries.push(entry));
|
|
240
309
|
return { entries, parseErrors };
|
|
241
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Pure frontier detection over parsed session entries (P1): the append-only
|
|
313
|
+
* goal ledger's frontier is the last entry of the most recent goal id that has
|
|
314
|
+
* no `goal_end` entry. A truncated or malformed tail line parses as absent, so
|
|
315
|
+
* a crash mid-write can never resurrect a half-written boundary
|
|
316
|
+
* (autoprompt's "treat half-written artifacts as absent").
|
|
317
|
+
*/
|
|
318
|
+
export function findGoalLedgerFrontier(entries) {
|
|
319
|
+
let frontier;
|
|
320
|
+
for (const entry of entries) {
|
|
321
|
+
if (entry.type !== 'goal')
|
|
322
|
+
continue;
|
|
323
|
+
if (entry.phase === 'goal_end') {
|
|
324
|
+
if (frontier?.goalId === entry.goalId)
|
|
325
|
+
frontier = undefined;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
frontier = frontierFromGoalEntry(entry);
|
|
329
|
+
}
|
|
330
|
+
return frontier;
|
|
331
|
+
}
|
|
332
|
+
/** Read the goal-ledger frontier of a stored session (one file scan). */
|
|
333
|
+
export async function readGoalLedgerFrontier(session) {
|
|
334
|
+
const { entries } = await readSessionEntries(session);
|
|
335
|
+
return findGoalLedgerFrontier(entries);
|
|
336
|
+
}
|
|
242
337
|
/**
|
|
243
338
|
* Restore conversation and work state in one file scan (CR-013). Session
|
|
244
339
|
* files grow to megabytes in long workspaces; resuming should not parse the
|
|
245
|
-
* JSONL twice.
|
|
340
|
+
* JSONL twice. The goal-ledger frontier rides the same scan (P1).
|
|
246
341
|
*/
|
|
247
342
|
export async function restoreSessionState(session) {
|
|
248
343
|
let messages = [];
|
|
249
344
|
let workState;
|
|
345
|
+
let goalFrontier;
|
|
346
|
+
const terminatedGoals = new Set();
|
|
250
347
|
const parseErrors = await scanSessionEntries(session, entry => {
|
|
251
348
|
if (entry.type === 'conversation_snapshot')
|
|
252
349
|
messages = entry.messages;
|
|
253
350
|
if (entry.type === 'work_state_snapshot')
|
|
254
351
|
workState = entry.state;
|
|
352
|
+
if (entry.type === 'goal') {
|
|
353
|
+
if (entry.phase === 'goal_end') {
|
|
354
|
+
terminatedGoals.add(entry.goalId);
|
|
355
|
+
if (goalFrontier?.goalId === entry.goalId)
|
|
356
|
+
goalFrontier = undefined;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
goalFrontier = frontierFromGoalEntry(entry);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
255
362
|
});
|
|
256
|
-
|
|
363
|
+
if (goalFrontier && terminatedGoals.has(goalFrontier.goalId))
|
|
364
|
+
goalFrontier = undefined;
|
|
365
|
+
return { messages, workState, parseErrors, goalFrontier };
|
|
257
366
|
}
|
|
258
367
|
export async function restoreConversation(session) {
|
|
259
368
|
const { messages, parseErrors } = await restoreSessionState(session);
|