fixate-on 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +396 -2
- package/completion-verdict.schema.json +52 -0
- package/docs/tui-integration.md +75 -0
- package/index.d.ts +608 -0
- package/package.json +121 -4
- package/plugin/fixate-on/plugin.js +15171 -0
- package/plugin/fixate-on/tui.js +4499 -0
- package/tui.d.ts +75 -0
|
@@ -0,0 +1,4499 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/tui-components.ts
|
|
15
|
+
function formatNumber(n) {
|
|
16
|
+
return n.toLocaleString("en-US");
|
|
17
|
+
}
|
|
18
|
+
function formatRelativeTime(timestamp, now = Date.now()) {
|
|
19
|
+
const diff = now - timestamp;
|
|
20
|
+
if (diff < 60000)
|
|
21
|
+
return "just now";
|
|
22
|
+
const minutes = Math.floor(diff / 60000);
|
|
23
|
+
if (minutes < 60)
|
|
24
|
+
return `${minutes}m ago`;
|
|
25
|
+
const hours = Math.floor(minutes / 60);
|
|
26
|
+
if (hours < 24)
|
|
27
|
+
return `${hours}h ago`;
|
|
28
|
+
const days = Math.floor(hours / 24);
|
|
29
|
+
return `${days}d ago`;
|
|
30
|
+
}
|
|
31
|
+
var PRODUCT_DISPLAY_NAME = "Fixate";
|
|
32
|
+
|
|
33
|
+
// src/status-label.ts
|
|
34
|
+
function isSelfResolvingStop(status, stopReason) {
|
|
35
|
+
if (status !== "paused")
|
|
36
|
+
return false;
|
|
37
|
+
return SELF_RESOLVING_STOP_REASONS.has(stopReason ?? "");
|
|
38
|
+
}
|
|
39
|
+
function statusTag(status, _stopReason) {
|
|
40
|
+
return status;
|
|
41
|
+
}
|
|
42
|
+
function stopReasonLabel(stopReason) {
|
|
43
|
+
if (stopReason === USER_INTERVENTION_STOP_REASON) {
|
|
44
|
+
return "paused by an earlier message; run /goal resume";
|
|
45
|
+
}
|
|
46
|
+
return stopReason;
|
|
47
|
+
}
|
|
48
|
+
var USER_INTERVENTION_STOP_REASON = "user intervention", SELF_RESOLVING_STOP_REASONS;
|
|
49
|
+
var init_status_label = __esm(() => {
|
|
50
|
+
SELF_RESOLVING_STOP_REASONS = new Set([
|
|
51
|
+
"recovery",
|
|
52
|
+
"queued"
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// src/accounting.ts
|
|
57
|
+
function chargedTokens(usage) {
|
|
58
|
+
if (!usage)
|
|
59
|
+
return 0;
|
|
60
|
+
return toNonNegativeInteger(usage.input) + toNonNegativeInteger(usage.cacheWrite) + toNonNegativeInteger(usage.output) + toNonNegativeInteger(usage.reasoning);
|
|
61
|
+
}
|
|
62
|
+
function emptyUsage() {
|
|
63
|
+
return {
|
|
64
|
+
input: 0,
|
|
65
|
+
output: 0,
|
|
66
|
+
reasoning: 0,
|
|
67
|
+
cacheRead: 0,
|
|
68
|
+
cacheWrite: 0,
|
|
69
|
+
cost: 0,
|
|
70
|
+
costKnown: false
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function normalizeUsage(value) {
|
|
74
|
+
const source = typeof value === "object" && value !== null ? value : {};
|
|
75
|
+
const usage = emptyUsage();
|
|
76
|
+
for (const field of USAGE_TOKEN_FIELDS) {
|
|
77
|
+
usage[field] = toNonNegativeInteger(source[field]);
|
|
78
|
+
}
|
|
79
|
+
const rawCost = source.cost;
|
|
80
|
+
usage.cost = Number.isFinite(Number(rawCost)) && Number(rawCost) >= 0 ? Number(rawCost) : 0;
|
|
81
|
+
usage.costKnown = source.costKnown === true || usage.cost > 0;
|
|
82
|
+
return usage;
|
|
83
|
+
}
|
|
84
|
+
function normalizeMessageUsage(message) {
|
|
85
|
+
const msg = message;
|
|
86
|
+
const info = msg?.info;
|
|
87
|
+
const tokens = info?.tokens ?? msg?.tokens ?? msg?.usage ?? {};
|
|
88
|
+
const cache = typeof tokens.cache === "object" && tokens.cache !== null ? tokens.cache : {};
|
|
89
|
+
const rawCost = info?.cost ?? msg?.cost ?? tokens.cost;
|
|
90
|
+
return {
|
|
91
|
+
input: toNonNegativeInteger(tokens.input ?? tokens.input_tokens ?? tokens.prompt_tokens),
|
|
92
|
+
output: toNonNegativeInteger(tokens.output ?? tokens.output_tokens ?? tokens.completion_tokens),
|
|
93
|
+
reasoning: toNonNegativeInteger(tokens.reasoning ?? tokens.reasoning_tokens),
|
|
94
|
+
cacheRead: toNonNegativeInteger(cache.read ?? tokens.cacheRead ?? tokens.cache_read),
|
|
95
|
+
cacheWrite: toNonNegativeInteger(cache.write ?? tokens.cacheWrite ?? tokens.cache_write),
|
|
96
|
+
cost: Number.isFinite(Number(rawCost)) && Number(rawCost) >= 0 ? Number(rawCost) : 0,
|
|
97
|
+
costKnown: rawCost != null && Number.isFinite(Number(rawCost)) && Number(rawCost) >= 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function addUsageDelta(total, current, previous, isNewStep = false) {
|
|
101
|
+
const next = normalizeUsage(total);
|
|
102
|
+
const cur = normalizeUsage(current);
|
|
103
|
+
const prev = normalizeUsage(previous);
|
|
104
|
+
const costIncreased = prev.cost > 0 && cur.cost > prev.cost;
|
|
105
|
+
const anyTokenFieldDecreased = STEP_DETECTION_FIELDS.some((field) => cur[field] < prev[field]);
|
|
106
|
+
const completedAnotherStep = isNewStep || costIncreased || anyTokenFieldDecreased;
|
|
107
|
+
for (const field of USAGE_TOKEN_FIELDS) {
|
|
108
|
+
next[field] += completedAnotherStep ? cur[field] : Math.max(0, cur[field] - prev[field]);
|
|
109
|
+
}
|
|
110
|
+
next.cost += Math.max(0, cur.cost - prev.cost);
|
|
111
|
+
next.costKnown ||= cur.costKnown;
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
function totalTokensForMessage(message) {
|
|
115
|
+
const msg = message;
|
|
116
|
+
const info = msg?.info;
|
|
117
|
+
const tokens = info?.tokens ?? msg?.tokens ?? msg?.usage ?? {};
|
|
118
|
+
const reportedTotal = toNonNegativeInteger(tokens.total);
|
|
119
|
+
if (reportedTotal > 0)
|
|
120
|
+
return reportedTotal;
|
|
121
|
+
return toNonNegativeInteger(tokens.input ?? tokens.input_tokens ?? tokens.prompt_tokens) + toNonNegativeInteger(tokens.output ?? tokens.output_tokens ?? tokens.completion_tokens) + toNonNegativeInteger(tokens.reasoning ?? tokens.reasoning_tokens) + cacheTokensForMessage(tokens);
|
|
122
|
+
}
|
|
123
|
+
function outputTokensForMessage(message) {
|
|
124
|
+
const msg = message;
|
|
125
|
+
const info = msg?.info;
|
|
126
|
+
const tokens = info?.tokens ?? msg?.tokens ?? msg?.usage ?? {};
|
|
127
|
+
const outputRaw = tokens.output ?? tokens.output_tokens ?? tokens.completion_tokens;
|
|
128
|
+
const output = toNonNegativeInteger(outputRaw);
|
|
129
|
+
if (outputRaw === undefined && (info?.tokens === undefined || info?.tokens === null) && (msg?.tokens === undefined || msg?.tokens === null) && (msg?.usage === undefined || msg?.usage === null))
|
|
130
|
+
return null;
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
function cacheTokensForMessage(tokens) {
|
|
134
|
+
const cache = typeof tokens.cache === "object" && tokens.cache !== null ? tokens.cache : {};
|
|
135
|
+
return toNonNegativeInteger(cache.read ?? tokens.cacheRead ?? tokens.cache_read) + toNonNegativeInteger(cache.write ?? tokens.cacheWrite ?? tokens.cache_write);
|
|
136
|
+
}
|
|
137
|
+
function toNonNegativeInteger(value, fallback = 0) {
|
|
138
|
+
if (value === null || value === undefined)
|
|
139
|
+
return fallback;
|
|
140
|
+
const parsed = Number(value);
|
|
141
|
+
return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : fallback;
|
|
142
|
+
}
|
|
143
|
+
var USAGE_TOKEN_FIELDS, STEP_DETECTION_FIELDS;
|
|
144
|
+
var init_accounting = __esm(() => {
|
|
145
|
+
USAGE_TOKEN_FIELDS = [
|
|
146
|
+
"input",
|
|
147
|
+
"output",
|
|
148
|
+
"reasoning",
|
|
149
|
+
"cacheRead",
|
|
150
|
+
"cacheWrite"
|
|
151
|
+
];
|
|
152
|
+
STEP_DETECTION_FIELDS = [
|
|
153
|
+
"input",
|
|
154
|
+
"output",
|
|
155
|
+
"reasoning",
|
|
156
|
+
"cacheWrite"
|
|
157
|
+
];
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// src/tui-analytics.ts
|
|
161
|
+
function computeAnalytics(goal) {
|
|
162
|
+
const charged = chargedTokens(goal.usage);
|
|
163
|
+
const tokenBudget = goal.tokenBudget ?? null;
|
|
164
|
+
const budgetPercentage = tokenBudget !== null && tokenBudget > 0 ? Math.round(charged / tokenBudget * 100) : null;
|
|
165
|
+
const tokensPerTurn = goal.turnCount > 0 ? Math.round(charged / goal.turnCount) : 0;
|
|
166
|
+
const projectedTotalTokens = goal.turnCount > 0 && goal.maxTurns > 0 ? tokensPerTurn * goal.maxTurns : null;
|
|
167
|
+
const turnsRemaining = tokenBudget !== null && tokensPerTurn > 0 ? Math.max(0, Math.floor((tokenBudget - charged) / tokensPerTurn)) : null;
|
|
168
|
+
const costPerTurn = goal.usage.costKnown && goal.turnCount > 0 ? goal.usage.cost / goal.turnCount : 0;
|
|
169
|
+
const projectedTotalCost = goal.usage.costKnown && goal.turnCount > 0 ? costPerTurn * goal.maxTurns : null;
|
|
170
|
+
const elapsedMs = Date.now() - goal.createdAt;
|
|
171
|
+
const burnRate = elapsedMs >= 1000 ? Math.round(charged / (elapsedMs / 1000)) : 0;
|
|
172
|
+
return {
|
|
173
|
+
chargedTokens: charged,
|
|
174
|
+
tokenBudget,
|
|
175
|
+
budgetPercentage,
|
|
176
|
+
tokensPerTurn,
|
|
177
|
+
projectedTotalTokens,
|
|
178
|
+
turnsRemaining,
|
|
179
|
+
costPerTurn,
|
|
180
|
+
projectedTotalCost,
|
|
181
|
+
burnRate
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function formatAnalyticsSummary(analytics) {
|
|
185
|
+
const parts = [];
|
|
186
|
+
parts.push(`Charged: ${formatNumber(analytics.chargedTokens)}`);
|
|
187
|
+
if (analytics.budgetPercentage !== null) {
|
|
188
|
+
parts.push(`Budget: ${analytics.budgetPercentage}%`);
|
|
189
|
+
}
|
|
190
|
+
if (analytics.tokensPerTurn > 0) {
|
|
191
|
+
parts.push(`${formatNumber(analytics.tokensPerTurn)}/turn`);
|
|
192
|
+
}
|
|
193
|
+
if (analytics.turnsRemaining !== null) {
|
|
194
|
+
parts.push(`${analytics.turnsRemaining} turns left`);
|
|
195
|
+
}
|
|
196
|
+
if (analytics.costPerTurn > 0) {
|
|
197
|
+
parts.push(`$${analytics.costPerTurn.toFixed(4)}/turn`);
|
|
198
|
+
}
|
|
199
|
+
if (analytics.burnRate > 0) {
|
|
200
|
+
parts.push(`${formatNumber(analytics.burnRate)} tok/s`);
|
|
201
|
+
}
|
|
202
|
+
return parts.join(" | ");
|
|
203
|
+
}
|
|
204
|
+
function formatBudgetWarning(analytics) {
|
|
205
|
+
if (analytics.budgetPercentage === null)
|
|
206
|
+
return null;
|
|
207
|
+
if (analytics.budgetPercentage < 80)
|
|
208
|
+
return null;
|
|
209
|
+
if (analytics.budgetPercentage >= 100) {
|
|
210
|
+
return `Budget ${analytics.budgetPercentage}% consumed - limit reached`;
|
|
211
|
+
}
|
|
212
|
+
if (analytics.projectedTotalTokens !== null && analytics.tokenBudget !== null && analytics.projectedTotalTokens > analytics.tokenBudget) {
|
|
213
|
+
return `Projected to exceed budget at current rate (${analytics.budgetPercentage}% used, ${analytics.turnsRemaining} turns left)`;
|
|
214
|
+
}
|
|
215
|
+
return `Budget at ${analytics.budgetPercentage}% - approaching limit`;
|
|
216
|
+
}
|
|
217
|
+
var init_tui_analytics = __esm(() => {
|
|
218
|
+
init_accounting();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// src/brake-format.ts
|
|
222
|
+
function brakeCeiling(limit) {
|
|
223
|
+
return limit > 0 ? limit : UNLIMITED;
|
|
224
|
+
}
|
|
225
|
+
function brakeCeilingFormatted(limit, format) {
|
|
226
|
+
return limit > 0 ? format(limit) : UNLIMITED;
|
|
227
|
+
}
|
|
228
|
+
var UNLIMITED = "unlimited";
|
|
229
|
+
|
|
230
|
+
// src/tui-views.ts
|
|
231
|
+
function wrapText(text, width, continuationIndent = "") {
|
|
232
|
+
const words = text.split(/\s+/).filter(Boolean);
|
|
233
|
+
if (words.length === 0)
|
|
234
|
+
return [text];
|
|
235
|
+
const lines = [];
|
|
236
|
+
let current = "";
|
|
237
|
+
for (const word of words) {
|
|
238
|
+
const candidate = current ? `${current} ${word}` : word;
|
|
239
|
+
if (current && candidate.length > width) {
|
|
240
|
+
lines.push(current);
|
|
241
|
+
current = continuationIndent + word;
|
|
242
|
+
} else {
|
|
243
|
+
current = candidate;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (current)
|
|
247
|
+
lines.push(current);
|
|
248
|
+
return lines;
|
|
249
|
+
}
|
|
250
|
+
function isForeignGoal(goal, activeSessionID) {
|
|
251
|
+
return activeSessionID !== null && goal.sessionID !== activeSessionID;
|
|
252
|
+
}
|
|
253
|
+
function foreignSessionLabel(goal) {
|
|
254
|
+
return goal.sessionID;
|
|
255
|
+
}
|
|
256
|
+
function fallbackNotice(goals, activeSessionID) {
|
|
257
|
+
if (activeSessionID === null)
|
|
258
|
+
return null;
|
|
259
|
+
const foreign = goals.filter((g) => isForeignGoal(g, activeSessionID));
|
|
260
|
+
if (foreign.length === 0)
|
|
261
|
+
return null;
|
|
262
|
+
const mine = goals.length - foreign.length;
|
|
263
|
+
return mine === 0 ? `This session has no goals. Showing ${foreign.length} from other sessions.` : `Showing ${foreign.length} from other sessions alongside this session's ${mine}.`;
|
|
264
|
+
}
|
|
265
|
+
function goalListRow(goal, index, activeSessionID) {
|
|
266
|
+
const foreign = isForeignGoal(goal, activeSessionID);
|
|
267
|
+
return {
|
|
268
|
+
title: `${index + 1}. [${statusTag(goal.status)}] ${goal.condition.substring(0, 60)}`,
|
|
269
|
+
description: (foreign ? `Another session (${foreignSessionLabel(goal)}) | ` : "") + `Tokens: ${goal.totalTokens}/${brakeCeiling(goal.maxTokens)} Turns: ${goal.turnCount}/${brakeCeiling(goal.maxTurns)}`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function dashboardGoalActions(store, targetSessionID, send) {
|
|
273
|
+
const withTarget = (verb) => () => {
|
|
274
|
+
const id = resolveFocusedGoalId(store, targetSessionID());
|
|
275
|
+
if (id)
|
|
276
|
+
send(`${verb} ${id}`);
|
|
277
|
+
};
|
|
278
|
+
return {
|
|
279
|
+
onPause: withTarget("pause"),
|
|
280
|
+
onResume: withTarget("resume"),
|
|
281
|
+
onClear: withTarget("clear")
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function dashboardFooterText(targetGoalId, dashboardChord, pauseChord, resumeChord, clearChord, escLabel) {
|
|
285
|
+
const nav = `${dashboardChord} dashboard | ${escLabel} home`;
|
|
286
|
+
if (!targetGoalId)
|
|
287
|
+
return nav;
|
|
288
|
+
return `${pauseChord} pause | ${resumeChord} resume | ${clearChord} clear | ${nav}`;
|
|
289
|
+
}
|
|
290
|
+
function resolveFocusedGoalId(store, sessionID) {
|
|
291
|
+
if (sessionID === null)
|
|
292
|
+
return null;
|
|
293
|
+
const focused = store.getFocused(sessionID);
|
|
294
|
+
if (focused)
|
|
295
|
+
return focused.goalId;
|
|
296
|
+
const mine = store.getAllSnapshots().filter((g) => !isForeignGoal(g, sessionID));
|
|
297
|
+
return mine.length > 0 ? mine[mine.length - 1].goalId : null;
|
|
298
|
+
}
|
|
299
|
+
function goalCardLines(goal, activeSessionID) {
|
|
300
|
+
const lines = [];
|
|
301
|
+
lines.push({ text: `Objective: ${goal.condition}` });
|
|
302
|
+
lines.push({ text: ` Status: ${goal.status}` });
|
|
303
|
+
if (isForeignGoal(goal, activeSessionID)) {
|
|
304
|
+
lines.push({
|
|
305
|
+
subdued: true,
|
|
306
|
+
text: ` Session: ${foreignSessionLabel(goal)} (another session)`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (goal.stopReason) {
|
|
310
|
+
lines.push({
|
|
311
|
+
subdued: true,
|
|
312
|
+
text: ` Stop: ${stopReasonLabel(goal.stopReason)}`
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
lines.push({ text: ` ${tokenGauge(goal.totalTokens, goal.maxTokens)}` });
|
|
316
|
+
lines.push({
|
|
317
|
+
text: ` Turns: ${goal.turnCount}/${brakeCeiling(goal.maxTurns)}`
|
|
318
|
+
});
|
|
319
|
+
return lines;
|
|
320
|
+
}
|
|
321
|
+
function tokenGauge(used, max) {
|
|
322
|
+
const pct = max > 0 ? Math.round(used / max * 100) : 0;
|
|
323
|
+
const compact = (n) => n >= 1000 ? `${Math.round(n / 1000)}k` : String(n);
|
|
324
|
+
return `Tokens: ${pct}% ${compact(used)} / ${brakeCeilingFormatted(max, compact)}`;
|
|
325
|
+
}
|
|
326
|
+
function formatGoalStatusDashboard(goals, activeSessionID = null) {
|
|
327
|
+
if (goals.length === 0) {
|
|
328
|
+
return [
|
|
329
|
+
{
|
|
330
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
331
|
+
text: "No active goals. Use /goal <condition> to set one."
|
|
332
|
+
}
|
|
333
|
+
];
|
|
334
|
+
}
|
|
335
|
+
const sections = [];
|
|
336
|
+
const notice = fallbackNotice(goals, activeSessionID);
|
|
337
|
+
if (notice) {
|
|
338
|
+
sections.push({ title: "Sessions shown", text: notice });
|
|
339
|
+
}
|
|
340
|
+
for (const goal of goals) {
|
|
341
|
+
const lines = [];
|
|
342
|
+
lines.push(...wrapText(` Objective: ${goal.condition}`, 96, " "));
|
|
343
|
+
lines.push(` Status: ${goal.status}`);
|
|
344
|
+
if (isForeignGoal(goal, activeSessionID)) {
|
|
345
|
+
lines.push(` Session: ${foreignSessionLabel(goal)} (another session)`);
|
|
346
|
+
}
|
|
347
|
+
if (goal.stopReason) {
|
|
348
|
+
lines.push(` Stop: ${stopReasonLabel(goal.stopReason)}`);
|
|
349
|
+
}
|
|
350
|
+
if (goal.blockedReason) {
|
|
351
|
+
lines.push(` Blocked: ${goal.blockedReason}`);
|
|
352
|
+
}
|
|
353
|
+
lines.push("");
|
|
354
|
+
lines.push(formatTokenGauge(goal.totalTokens, goal.maxTokens));
|
|
355
|
+
lines.push(` Turns: ${goal.turnCount} / ${brakeCeiling(goal.maxTurns)}`);
|
|
356
|
+
if (goal.usage.costKnown && goal.usage.cost > 0) {
|
|
357
|
+
lines.push(` Cost: $${goal.usage.cost.toFixed(4)}`);
|
|
358
|
+
}
|
|
359
|
+
const analytics = computeAnalytics(goal);
|
|
360
|
+
const analyticsLine = formatAnalyticsSummary(analytics);
|
|
361
|
+
if (analyticsLine) {
|
|
362
|
+
lines.push(` Analytics: ${analyticsLine}`);
|
|
363
|
+
}
|
|
364
|
+
const warning = formatBudgetWarning(analytics);
|
|
365
|
+
if (warning) {
|
|
366
|
+
lines.push(` ${warning}`);
|
|
367
|
+
}
|
|
368
|
+
if (goal.lastCheckpoint) {
|
|
369
|
+
lines.push("");
|
|
370
|
+
lines.push(` Checkpoint: ${goal.lastCheckpoint.summary}`);
|
|
371
|
+
lines.push(` ${formatRelativeTime(goal.lastCheckpoint.timestamp)}`);
|
|
372
|
+
}
|
|
373
|
+
if (goal.history.length > 0) {
|
|
374
|
+
lines.push("");
|
|
375
|
+
lines.push(formatHistoryList(goal.history));
|
|
376
|
+
}
|
|
377
|
+
sections.push({
|
|
378
|
+
title: `Goal: ${goal.goalId.substring(0, 8)}`,
|
|
379
|
+
text: lines.join(`
|
|
380
|
+
`)
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return sections;
|
|
384
|
+
}
|
|
385
|
+
function formatTokenGauge(used, max) {
|
|
386
|
+
const percentage = max > 0 ? used / max * 100 : 0;
|
|
387
|
+
const maxLabel = max > 0 ? formatNumber(max) : "unlimited";
|
|
388
|
+
return ` Tokens: ${Math.round(percentage)}% ${formatNumber(used)} / ${maxLabel}`;
|
|
389
|
+
}
|
|
390
|
+
function isSignalHistoryEntry(entry) {
|
|
391
|
+
if (entry.type === "tracking")
|
|
392
|
+
return false;
|
|
393
|
+
if (entry.type !== "mutation")
|
|
394
|
+
return true;
|
|
395
|
+
return MUTATION_SIGNAL_PREFIXES.some((prefix) => entry.detail.startsWith(prefix));
|
|
396
|
+
}
|
|
397
|
+
function formatHistoryList(history) {
|
|
398
|
+
const signals = history.filter(isSignalHistoryEntry);
|
|
399
|
+
if (signals.length === 0) {
|
|
400
|
+
return " History: (no lifecycle events)";
|
|
401
|
+
}
|
|
402
|
+
const lines = [" History:"];
|
|
403
|
+
for (const entry of signals) {
|
|
404
|
+
const time = formatRelativeTime(entry.timestamp);
|
|
405
|
+
lines.push(` [${entry.type}] ${entry.detail} (${time})`);
|
|
406
|
+
}
|
|
407
|
+
return lines.join(`
|
|
408
|
+
`);
|
|
409
|
+
}
|
|
410
|
+
var MUTATION_SIGNAL_PREFIXES;
|
|
411
|
+
var init_tui_views = __esm(() => {
|
|
412
|
+
init_tui_analytics();
|
|
413
|
+
init_status_label();
|
|
414
|
+
MUTATION_SIGNAL_PREFIXES = [
|
|
415
|
+
"User ",
|
|
416
|
+
"Human ",
|
|
417
|
+
"Accepted proposal",
|
|
418
|
+
"Rejected proposal",
|
|
419
|
+
"Proposed term changes",
|
|
420
|
+
"Recorded claim",
|
|
421
|
+
"Loaded from persisted state",
|
|
422
|
+
"Paused because",
|
|
423
|
+
"Backgrounded",
|
|
424
|
+
"Queued goal",
|
|
425
|
+
"Started an ordered sequence",
|
|
426
|
+
"Pressure rung"
|
|
427
|
+
];
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// src/tui-snapshot-details.ts
|
|
431
|
+
function isNonNegativeFinite(value) {
|
|
432
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
433
|
+
}
|
|
434
|
+
function asRecord(value) {
|
|
435
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
436
|
+
}
|
|
437
|
+
function stringArray(value) {
|
|
438
|
+
if (!Array.isArray(value))
|
|
439
|
+
return null;
|
|
440
|
+
const strings = [];
|
|
441
|
+
for (const item of value) {
|
|
442
|
+
if (typeof item !== "string")
|
|
443
|
+
return null;
|
|
444
|
+
strings.push(item);
|
|
445
|
+
}
|
|
446
|
+
return strings;
|
|
447
|
+
}
|
|
448
|
+
function copyGoalProposal(proposal) {
|
|
449
|
+
return {
|
|
450
|
+
proposalId: proposal.proposalId,
|
|
451
|
+
proposedAt: proposal.proposedAt,
|
|
452
|
+
reason: proposal.reason,
|
|
453
|
+
...proposal.objective !== undefined ? { objective: proposal.objective } : {},
|
|
454
|
+
...proposal.successCriteria !== undefined ? { successCriteria: proposal.successCriteria } : {},
|
|
455
|
+
...proposal.constraints !== undefined ? { constraints: proposal.constraints } : {},
|
|
456
|
+
...proposal.artifactPointers !== undefined ? { artifactPointers: [...proposal.artifactPointers] } : {}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function copyClaimRecord(claim) {
|
|
460
|
+
return {
|
|
461
|
+
claimId: claim.claimId,
|
|
462
|
+
timestamp: claim.timestamp,
|
|
463
|
+
actor: claim.actor,
|
|
464
|
+
claimedStatus: claim.claimedStatus,
|
|
465
|
+
claimText: claim.claimText,
|
|
466
|
+
check: {
|
|
467
|
+
path: claim.check.path,
|
|
468
|
+
verdict: claim.check.verdict,
|
|
469
|
+
timestamp: claim.check.timestamp,
|
|
470
|
+
...claim.check.target !== undefined ? { target: claim.check.target } : {},
|
|
471
|
+
...claim.check.evidence !== undefined ? { evidence: [...claim.check.evidence] } : {}
|
|
472
|
+
},
|
|
473
|
+
outcome: {
|
|
474
|
+
status: claim.outcome.status,
|
|
475
|
+
detail: claim.outcome.detail,
|
|
476
|
+
timestamp: claim.outcome.timestamp
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
var CLAIM_ACTORS = new Set(["agent", "human", "slash-command"]);
|
|
481
|
+
var CLAIM_VERDICTS = new Set([
|
|
482
|
+
"COMPLETE",
|
|
483
|
+
"WORKING",
|
|
484
|
+
"BLOCKED",
|
|
485
|
+
"NEEDS_INPUT",
|
|
486
|
+
"CANCELLED",
|
|
487
|
+
"JUDGE_APPROVED",
|
|
488
|
+
"JUDGE_REJECTED",
|
|
489
|
+
"JUDGE_FAILURE",
|
|
490
|
+
"VERIFIER_FAILURE",
|
|
491
|
+
"NONE"
|
|
492
|
+
]);
|
|
493
|
+
var CLAIM_OUTCOMES = new Set([
|
|
494
|
+
"verified-complete",
|
|
495
|
+
"claim-refuted",
|
|
496
|
+
"unverifiable-claim",
|
|
497
|
+
"blocked-acknowledged"
|
|
498
|
+
]);
|
|
499
|
+
function parseClaim(value) {
|
|
500
|
+
const claim = asRecord(value);
|
|
501
|
+
const check = asRecord(claim?.check);
|
|
502
|
+
const outcome = asRecord(claim?.outcome);
|
|
503
|
+
if (!claim || !check || !outcome || typeof claim.claimId !== "string" || claim.claimId.length === 0 || !isNonNegativeFinite(claim.timestamp) || typeof claim.actor !== "string" || !CLAIM_ACTORS.has(claim.actor) || claim.claimedStatus !== "complete" && claim.claimedStatus !== "blocked" || typeof claim.claimText !== "string" || check.path !== "judge" && check.path !== "none" || typeof check.verdict !== "string" || !CLAIM_VERDICTS.has(check.verdict) || !isNonNegativeFinite(check.timestamp) || check.target !== undefined && typeof check.target !== "string" || check.evidence !== undefined && stringArray(check.evidence) === null || typeof outcome.status !== "string" || !CLAIM_OUTCOMES.has(outcome.status) || typeof outcome.detail !== "string" || !isNonNegativeFinite(outcome.timestamp))
|
|
504
|
+
return null;
|
|
505
|
+
return copyClaimRecord(claim);
|
|
506
|
+
}
|
|
507
|
+
function parseProposal(value) {
|
|
508
|
+
const proposal = asRecord(value);
|
|
509
|
+
if (!proposal || typeof proposal.proposalId !== "string" || proposal.proposalId.length === 0 || !isNonNegativeFinite(proposal.proposedAt) || typeof proposal.reason !== "string" || ["objective", "successCriteria", "constraints"].some((field) => proposal[field] !== undefined && typeof proposal[field] !== "string") || proposal.artifactPointers !== undefined && stringArray(proposal.artifactPointers) === null)
|
|
510
|
+
return null;
|
|
511
|
+
return copyGoalProposal(proposal);
|
|
512
|
+
}
|
|
513
|
+
function parseTuiSnapshotDetails(snapshot) {
|
|
514
|
+
const result = {};
|
|
515
|
+
if (snapshot.artifactPointers !== undefined) {
|
|
516
|
+
const pointers = stringArray(snapshot.artifactPointers);
|
|
517
|
+
if (pointers === null)
|
|
518
|
+
return null;
|
|
519
|
+
result.artifactPointers = pointers;
|
|
520
|
+
}
|
|
521
|
+
if (snapshot.pendingProposal !== undefined) {
|
|
522
|
+
const proposal = snapshot.pendingProposal === null ? null : parseProposal(snapshot.pendingProposal);
|
|
523
|
+
if (snapshot.pendingProposal !== null && proposal === null)
|
|
524
|
+
return null;
|
|
525
|
+
result.pendingProposal = proposal;
|
|
526
|
+
}
|
|
527
|
+
if (snapshot.claims !== undefined) {
|
|
528
|
+
if (!Array.isArray(snapshot.claims))
|
|
529
|
+
return null;
|
|
530
|
+
const claims = [];
|
|
531
|
+
for (const raw of snapshot.claims) {
|
|
532
|
+
const claim = parseClaim(raw);
|
|
533
|
+
if (!claim)
|
|
534
|
+
return null;
|
|
535
|
+
claims.push(claim);
|
|
536
|
+
}
|
|
537
|
+
result.claims = claims;
|
|
538
|
+
}
|
|
539
|
+
if (snapshot.lastClaim !== undefined) {
|
|
540
|
+
const claim = snapshot.lastClaim === null ? null : parseClaim(snapshot.lastClaim);
|
|
541
|
+
if (snapshot.lastClaim !== null && claim === null)
|
|
542
|
+
return null;
|
|
543
|
+
result.lastClaim = claim;
|
|
544
|
+
}
|
|
545
|
+
if (snapshot.origin !== undefined) {
|
|
546
|
+
if (snapshot.origin !== "live" && snapshot.origin !== "disk")
|
|
547
|
+
return null;
|
|
548
|
+
result.origin = snapshot.origin;
|
|
549
|
+
}
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/tui-state.ts
|
|
554
|
+
var GOAL_TUI_EVENT_TITLE = "fixate-on";
|
|
555
|
+
var VALID_GOAL_STATUSES = new Set([
|
|
556
|
+
"active",
|
|
557
|
+
"paused",
|
|
558
|
+
"blocked",
|
|
559
|
+
"budgetLimited",
|
|
560
|
+
"finalizing",
|
|
561
|
+
"complete"
|
|
562
|
+
]);
|
|
563
|
+
function serializeGoalForTui(state) {
|
|
564
|
+
const snapshot = {
|
|
565
|
+
goalId: state.goalId,
|
|
566
|
+
sessionID: state.sessionID,
|
|
567
|
+
condition: state.condition,
|
|
568
|
+
artifactPointers: state.artifactPointers ? [...state.artifactPointers] : [],
|
|
569
|
+
pendingProposal: state.pendingProposal ? copyGoalProposal(state.pendingProposal) : null,
|
|
570
|
+
claims: state.claims ? state.claims.map(copyClaimRecord) : [],
|
|
571
|
+
lastClaim: state.lastClaim ? copyClaimRecord(state.lastClaim) : null,
|
|
572
|
+
status: state.status,
|
|
573
|
+
revision: state.revision,
|
|
574
|
+
turnCount: state.turnCount,
|
|
575
|
+
totalTokens: state.totalTokens,
|
|
576
|
+
maxTokens: state.maxTokens,
|
|
577
|
+
maxTurns: state.maxTurns,
|
|
578
|
+
tokenBudget: state.tokenBudget,
|
|
579
|
+
usage: {
|
|
580
|
+
input: state.usage.input,
|
|
581
|
+
output: state.usage.output,
|
|
582
|
+
reasoning: state.usage.reasoning,
|
|
583
|
+
cacheRead: state.usage.cacheRead,
|
|
584
|
+
cacheWrite: state.usage.cacheWrite,
|
|
585
|
+
cost: state.usage.cost,
|
|
586
|
+
costKnown: state.usage.costKnown
|
|
587
|
+
},
|
|
588
|
+
stopReason: state.stopReason,
|
|
589
|
+
blockedReason: state.blockedReason,
|
|
590
|
+
pausedAt: state.pausedAt,
|
|
591
|
+
stoppedAt: state.stoppedAt,
|
|
592
|
+
createdAt: state.createdAt,
|
|
593
|
+
updatedAt: state.updatedAt,
|
|
594
|
+
finishedAt: state.finishedAt,
|
|
595
|
+
lastCheckpoint: state.lastCheckpoint ? {
|
|
596
|
+
summary: state.lastCheckpoint.summary,
|
|
597
|
+
timestamp: state.lastCheckpoint.timestamp
|
|
598
|
+
} : null,
|
|
599
|
+
history: state.history.map((entry) => ({
|
|
600
|
+
type: entry.type,
|
|
601
|
+
detail: entry.detail,
|
|
602
|
+
timestamp: entry.timestamp
|
|
603
|
+
}))
|
|
604
|
+
};
|
|
605
|
+
return deepFreeze(snapshot);
|
|
606
|
+
}
|
|
607
|
+
function parseTuiSyncEvent(raw) {
|
|
608
|
+
if (!raw || typeof raw !== "string")
|
|
609
|
+
return null;
|
|
610
|
+
let parsed;
|
|
611
|
+
try {
|
|
612
|
+
parsed = JSON.parse(raw);
|
|
613
|
+
} catch {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
return validateTuiEvent(parsed);
|
|
617
|
+
}
|
|
618
|
+
function validateTuiEvent(value) {
|
|
619
|
+
if (!value || typeof value !== "object")
|
|
620
|
+
return null;
|
|
621
|
+
const obj = value;
|
|
622
|
+
if (obj.title === GOAL_TUI_EVENT_TITLE && obj.payload && typeof obj.payload === "object") {
|
|
623
|
+
return validateTuiEvent(obj.payload);
|
|
624
|
+
}
|
|
625
|
+
const kind = obj.kind;
|
|
626
|
+
if (kind !== "create" && kind !== "transition" && kind !== "usage" && kind !== "remove") {
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
const sessionID = obj.sessionID;
|
|
630
|
+
if (typeof sessionID !== "string" || sessionID.length === 0)
|
|
631
|
+
return null;
|
|
632
|
+
const timestamp = obj.timestamp;
|
|
633
|
+
if (!isNonNegativeFinite(timestamp))
|
|
634
|
+
return null;
|
|
635
|
+
if (kind === "remove") {
|
|
636
|
+
const goalId = obj.goalId;
|
|
637
|
+
if (typeof goalId !== "string" || goalId.length === 0)
|
|
638
|
+
return null;
|
|
639
|
+
return { kind, sessionID, timestamp, goalId };
|
|
640
|
+
}
|
|
641
|
+
const snapshot = validateSnapshot(obj.snapshot);
|
|
642
|
+
if (!snapshot)
|
|
643
|
+
return null;
|
|
644
|
+
if (snapshot.sessionID !== sessionID)
|
|
645
|
+
return null;
|
|
646
|
+
const previousStatus = obj.previousStatus;
|
|
647
|
+
if (previousStatus !== undefined && (typeof previousStatus !== "string" || !VALID_GOAL_STATUSES.has(previousStatus)))
|
|
648
|
+
return null;
|
|
649
|
+
const prior = previousStatus === undefined ? {} : { previousStatus };
|
|
650
|
+
if (kind === "transition") {
|
|
651
|
+
const transition = validateTransition(obj.transition);
|
|
652
|
+
if (!transition)
|
|
653
|
+
return null;
|
|
654
|
+
return { kind, sessionID, timestamp, snapshot, transition, ...prior };
|
|
655
|
+
}
|
|
656
|
+
return { kind, sessionID, timestamp, snapshot, ...prior };
|
|
657
|
+
}
|
|
658
|
+
function validateSnapshot(value) {
|
|
659
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
660
|
+
return null;
|
|
661
|
+
const s = value;
|
|
662
|
+
if (typeof s.goalId !== "string" || s.goalId.length === 0 || typeof s.sessionID !== "string" || s.sessionID.length === 0 || typeof s.condition !== "string" || typeof s.status !== "string" || !VALID_GOAL_STATUSES.has(s.status) || !isNonNegativeFinite(s.revision) || !isNonNegativeFinite(s.turnCount) || !isNonNegativeFinite(s.totalTokens) || !isNonNegativeFinite(s.maxTokens) || !isNonNegativeFinite(s.maxTurns) || s.tokenBudget !== null && !isNonNegativeFinite(s.tokenBudget) || typeof s.stopReason !== "string" || !isNonNegativeFinite(s.pausedAt) || !isNonNegativeFinite(s.stoppedAt) || typeof s.blockedReason !== "string" || !isNonNegativeFinite(s.createdAt) || !isNonNegativeFinite(s.updatedAt)) {
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
if (s.finishedAt !== null && !isNonNegativeFinite(s.finishedAt))
|
|
666
|
+
return null;
|
|
667
|
+
const usage = validateUsage(s.usage);
|
|
668
|
+
if (!usage)
|
|
669
|
+
return null;
|
|
670
|
+
const history = validateHistory(s.history);
|
|
671
|
+
if (history === null)
|
|
672
|
+
return null;
|
|
673
|
+
const checkpoint = validateCheckpoint(s.lastCheckpoint);
|
|
674
|
+
if (checkpoint === INVALID_CHECKPOINT)
|
|
675
|
+
return null;
|
|
676
|
+
const details = parseTuiSnapshotDetails(s);
|
|
677
|
+
if (details === null)
|
|
678
|
+
return null;
|
|
679
|
+
const snapshot = {
|
|
680
|
+
...details,
|
|
681
|
+
goalId: s.goalId,
|
|
682
|
+
sessionID: s.sessionID,
|
|
683
|
+
condition: s.condition,
|
|
684
|
+
status: s.status,
|
|
685
|
+
revision: s.revision,
|
|
686
|
+
turnCount: s.turnCount,
|
|
687
|
+
totalTokens: s.totalTokens,
|
|
688
|
+
maxTokens: s.maxTokens,
|
|
689
|
+
maxTurns: s.maxTurns,
|
|
690
|
+
tokenBudget: s.tokenBudget === null ? null : s.tokenBudget,
|
|
691
|
+
usage,
|
|
692
|
+
stopReason: s.stopReason,
|
|
693
|
+
blockedReason: s.blockedReason,
|
|
694
|
+
pausedAt: s.pausedAt,
|
|
695
|
+
stoppedAt: s.stoppedAt,
|
|
696
|
+
createdAt: s.createdAt,
|
|
697
|
+
updatedAt: s.updatedAt,
|
|
698
|
+
finishedAt: s.finishedAt === null ? null : s.finishedAt,
|
|
699
|
+
lastCheckpoint: checkpoint,
|
|
700
|
+
history
|
|
701
|
+
};
|
|
702
|
+
return deepFreeze(snapshot);
|
|
703
|
+
}
|
|
704
|
+
function validateUsage(value) {
|
|
705
|
+
if (!value || typeof value !== "object")
|
|
706
|
+
return null;
|
|
707
|
+
const u = value;
|
|
708
|
+
if (!isNonNegativeFinite(u.input) || !isNonNegativeFinite(u.output) || !isNonNegativeFinite(u.reasoning) || !isNonNegativeFinite(u.cacheRead) || !isNonNegativeFinite(u.cacheWrite) || !isNonNegativeFinite(u.cost) || typeof u.costKnown !== "boolean") {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
input: u.input,
|
|
713
|
+
output: u.output,
|
|
714
|
+
reasoning: u.reasoning,
|
|
715
|
+
cacheRead: u.cacheRead,
|
|
716
|
+
cacheWrite: u.cacheWrite,
|
|
717
|
+
cost: u.cost,
|
|
718
|
+
costKnown: u.costKnown
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function validateHistory(value) {
|
|
722
|
+
if (!Array.isArray(value))
|
|
723
|
+
return null;
|
|
724
|
+
const result = [];
|
|
725
|
+
for (const entry of value) {
|
|
726
|
+
if (!entry || typeof entry !== "object")
|
|
727
|
+
return null;
|
|
728
|
+
const e = entry;
|
|
729
|
+
if (typeof e.type !== "string" || typeof e.detail !== "string" || !isNonNegativeFinite(e.timestamp)) {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
result.push({ type: e.type, detail: e.detail, timestamp: e.timestamp });
|
|
733
|
+
}
|
|
734
|
+
return result;
|
|
735
|
+
}
|
|
736
|
+
var INVALID_CHECKPOINT = Object.freeze({ summary: "", timestamp: -1 });
|
|
737
|
+
function validateCheckpoint(value) {
|
|
738
|
+
if (value === null)
|
|
739
|
+
return null;
|
|
740
|
+
if (!value || typeof value !== "object")
|
|
741
|
+
return INVALID_CHECKPOINT;
|
|
742
|
+
const c = value;
|
|
743
|
+
if (typeof c.summary !== "string" || !isNonNegativeFinite(c.timestamp))
|
|
744
|
+
return INVALID_CHECKPOINT;
|
|
745
|
+
return { summary: c.summary, timestamp: c.timestamp };
|
|
746
|
+
}
|
|
747
|
+
function validateTransition(value) {
|
|
748
|
+
if (!value || typeof value !== "object")
|
|
749
|
+
return null;
|
|
750
|
+
const t = value;
|
|
751
|
+
if (typeof t.source !== "string" || typeof t.from !== "string" || !VALID_GOAL_STATUSES.has(t.from) || typeof t.to !== "string" || !VALID_GOAL_STATUSES.has(t.to) || typeof t.detail !== "string") {
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
return {
|
|
755
|
+
source: t.source,
|
|
756
|
+
from: t.from,
|
|
757
|
+
to: t.to,
|
|
758
|
+
detail: t.detail
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function createSessionStore() {
|
|
762
|
+
return { goals: new Map, focusedId: null, order: [] };
|
|
763
|
+
}
|
|
764
|
+
function createTuiStateStore() {
|
|
765
|
+
const sessions = new Map;
|
|
766
|
+
const subscribers = new Set;
|
|
767
|
+
function getOrCreateSession(sessionID) {
|
|
768
|
+
let s = sessions.get(sessionID);
|
|
769
|
+
if (!s) {
|
|
770
|
+
s = createSessionStore();
|
|
771
|
+
sessions.set(sessionID, s);
|
|
772
|
+
}
|
|
773
|
+
return s;
|
|
774
|
+
}
|
|
775
|
+
function notify(event) {
|
|
776
|
+
for (const sub of subscribers) {
|
|
777
|
+
try {
|
|
778
|
+
sub(event);
|
|
779
|
+
} catch {}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function applyEvent(event) {
|
|
783
|
+
if (event.kind === "remove") {
|
|
784
|
+
const session = sessions.get(event.sessionID);
|
|
785
|
+
if (session && event.goalId) {
|
|
786
|
+
session.goals.delete(event.goalId);
|
|
787
|
+
session.order = session.order.filter((id) => id !== event.goalId);
|
|
788
|
+
if (session.focusedId === event.goalId) {
|
|
789
|
+
session.focusedId = session.order[session.order.length - 1] ?? null;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
notify(event);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (!event.snapshot)
|
|
796
|
+
return;
|
|
797
|
+
const snapshot = deepFreeze(event.snapshot);
|
|
798
|
+
const session = getOrCreateSession(event.sessionID);
|
|
799
|
+
const existing = session.goals.get(snapshot.goalId);
|
|
800
|
+
if (existing && snapshot.revision < existing.revision) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
if (!existing) {
|
|
804
|
+
session.order.push(snapshot.goalId);
|
|
805
|
+
}
|
|
806
|
+
session.goals.set(snapshot.goalId, snapshot);
|
|
807
|
+
session.focusedId = snapshot.goalId;
|
|
808
|
+
notify(event);
|
|
809
|
+
}
|
|
810
|
+
function getSnapshots(sessionID) {
|
|
811
|
+
const session = sessions.get(sessionID);
|
|
812
|
+
if (!session)
|
|
813
|
+
return [];
|
|
814
|
+
return session.order.map((id) => session.goals.get(id)).filter((s) => !!s);
|
|
815
|
+
}
|
|
816
|
+
function getAllSnapshots() {
|
|
817
|
+
const all = [];
|
|
818
|
+
for (const session of sessions.values()) {
|
|
819
|
+
for (const id of session.order) {
|
|
820
|
+
const snap = session.goals.get(id);
|
|
821
|
+
if (snap)
|
|
822
|
+
all.push(snap);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return all;
|
|
826
|
+
}
|
|
827
|
+
function getSnapshot(sessionID, goalId) {
|
|
828
|
+
const session = sessions.get(sessionID);
|
|
829
|
+
if (!session)
|
|
830
|
+
return;
|
|
831
|
+
return session.goals.get(goalId);
|
|
832
|
+
}
|
|
833
|
+
function getFocused(sessionID) {
|
|
834
|
+
const session = sessions.get(sessionID);
|
|
835
|
+
if (!session || !session.focusedId)
|
|
836
|
+
return;
|
|
837
|
+
return session.goals.get(session.focusedId);
|
|
838
|
+
}
|
|
839
|
+
function setFocused(sessionID, goalId) {
|
|
840
|
+
const session = sessions.get(sessionID);
|
|
841
|
+
if (!session)
|
|
842
|
+
return;
|
|
843
|
+
if (goalId === null) {
|
|
844
|
+
if (session.focusedId === null)
|
|
845
|
+
return;
|
|
846
|
+
session.focusedId = null;
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
if (!session.goals.has(goalId) || session.focusedId === goalId)
|
|
850
|
+
return;
|
|
851
|
+
session.focusedId = goalId;
|
|
852
|
+
const snap = session.goals.get(goalId);
|
|
853
|
+
notify({
|
|
854
|
+
kind: "usage",
|
|
855
|
+
sessionID,
|
|
856
|
+
goalId,
|
|
857
|
+
snapshot: snap,
|
|
858
|
+
timestamp: Date.now()
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
function subscribe(fn) {
|
|
862
|
+
subscribers.add(fn);
|
|
863
|
+
return () => subscribers.delete(fn);
|
|
864
|
+
}
|
|
865
|
+
function clear() {
|
|
866
|
+
sessions.clear();
|
|
867
|
+
subscribers.clear();
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
applyEvent,
|
|
871
|
+
getSnapshots,
|
|
872
|
+
getAllSnapshots,
|
|
873
|
+
getSnapshot,
|
|
874
|
+
getFocused,
|
|
875
|
+
setFocused,
|
|
876
|
+
subscribe,
|
|
877
|
+
clear
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
function createGoalBroadcaster(config) {
|
|
881
|
+
const { publish, onDeliveryFailure } = config;
|
|
882
|
+
async function emit(snapshot, kind, transition) {
|
|
883
|
+
const event = {
|
|
884
|
+
kind,
|
|
885
|
+
sessionID: snapshot.sessionID,
|
|
886
|
+
timestamp: Date.now(),
|
|
887
|
+
snapshot: serializeGoalForTui(snapshot),
|
|
888
|
+
...transition ? { transition, previousStatus: transition.from } : {}
|
|
889
|
+
};
|
|
890
|
+
try {
|
|
891
|
+
await publish(snapshot.sessionID, event);
|
|
892
|
+
} catch (error) {
|
|
893
|
+
try {
|
|
894
|
+
onDeliveryFailure?.({
|
|
895
|
+
kind,
|
|
896
|
+
sessionID: snapshot.sessionID,
|
|
897
|
+
goalId: snapshot.goalId,
|
|
898
|
+
error
|
|
899
|
+
});
|
|
900
|
+
} catch {}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return {
|
|
904
|
+
onCommit: async (snapshot, transition) => {
|
|
905
|
+
await emit(snapshot, "transition", transition);
|
|
906
|
+
},
|
|
907
|
+
emitCreate: async (snapshot) => {
|
|
908
|
+
await emit(snapshot, "create");
|
|
909
|
+
},
|
|
910
|
+
emitRemove: async (sessionID, goalId) => {
|
|
911
|
+
const event = {
|
|
912
|
+
kind: "remove",
|
|
913
|
+
sessionID,
|
|
914
|
+
goalId,
|
|
915
|
+
timestamp: Date.now()
|
|
916
|
+
};
|
|
917
|
+
try {
|
|
918
|
+
await publish(sessionID, event);
|
|
919
|
+
} catch (error) {
|
|
920
|
+
try {
|
|
921
|
+
onDeliveryFailure?.({ kind: "remove", sessionID, goalId, error });
|
|
922
|
+
} catch {}
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
emitUsage: async (snapshot) => {
|
|
926
|
+
await emit(snapshot, "usage");
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
var BUFFER_MAX_EVENTS = 64;
|
|
931
|
+
var GOAL_TUI_METADATA_KEY = "fixate-on";
|
|
932
|
+
function createBufferingTransport() {
|
|
933
|
+
const buffers = new Map;
|
|
934
|
+
function get(sessionID) {
|
|
935
|
+
let buf = buffers.get(sessionID);
|
|
936
|
+
if (!buf) {
|
|
937
|
+
buf = [];
|
|
938
|
+
buffers.set(sessionID, buf);
|
|
939
|
+
}
|
|
940
|
+
return buf;
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
publish: (_sessionID, event) => {
|
|
944
|
+
const sessionID = event.sessionID;
|
|
945
|
+
if (!sessionID)
|
|
946
|
+
return;
|
|
947
|
+
const buf = get(sessionID);
|
|
948
|
+
buf.push(event);
|
|
949
|
+
if (buf.length > BUFFER_MAX_EVENTS) {
|
|
950
|
+
buf.splice(0, buf.length - BUFFER_MAX_EVENTS);
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
drain: (sessionID) => {
|
|
954
|
+
const buf = buffers.get(sessionID);
|
|
955
|
+
if (!buf || buf.length === 0)
|
|
956
|
+
return [];
|
|
957
|
+
return buf.splice(0, buf.length);
|
|
958
|
+
},
|
|
959
|
+
peek: (sessionID) => {
|
|
960
|
+
const buf = buffers.get(sessionID);
|
|
961
|
+
return buf ? buf.slice() : [];
|
|
962
|
+
},
|
|
963
|
+
clear: () => {
|
|
964
|
+
buffers.clear();
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
function encodeGoalToolMetadata(events) {
|
|
969
|
+
if (!events || events.length === 0)
|
|
970
|
+
return;
|
|
971
|
+
return { [GOAL_TUI_METADATA_KEY]: { events } };
|
|
972
|
+
}
|
|
973
|
+
function decodeGoalToolMetadata(metadata) {
|
|
974
|
+
if (!metadata || typeof metadata !== "object")
|
|
975
|
+
return null;
|
|
976
|
+
const envelope = metadata[GOAL_TUI_METADATA_KEY];
|
|
977
|
+
if (!envelope || typeof envelope !== "object")
|
|
978
|
+
return null;
|
|
979
|
+
const events = envelope.events;
|
|
980
|
+
if (!Array.isArray(events))
|
|
981
|
+
return null;
|
|
982
|
+
const valid = [];
|
|
983
|
+
for (const raw of events) {
|
|
984
|
+
const event = validateTuiEvent(raw);
|
|
985
|
+
if (event)
|
|
986
|
+
valid.push(event);
|
|
987
|
+
}
|
|
988
|
+
return valid.length > 0 ? valid : null;
|
|
989
|
+
}
|
|
990
|
+
function deepFreeze(value) {
|
|
991
|
+
if (value === null || typeof value !== "object")
|
|
992
|
+
return value;
|
|
993
|
+
if (Object.isFrozen(value))
|
|
994
|
+
return value;
|
|
995
|
+
if (Array.isArray(value)) {
|
|
996
|
+
for (const item of value)
|
|
997
|
+
deepFreeze(item);
|
|
998
|
+
return Object.freeze(value);
|
|
999
|
+
}
|
|
1000
|
+
for (const key of Object.keys(value)) {
|
|
1001
|
+
deepFreeze(value[key]);
|
|
1002
|
+
}
|
|
1003
|
+
return Object.freeze(value);
|
|
1004
|
+
}
|
|
1005
|
+
// src/tui-disk-state.ts
|
|
1006
|
+
import { resolve as resolve2 } from "path";
|
|
1007
|
+
|
|
1008
|
+
// src/fs-portable.ts
|
|
1009
|
+
import {
|
|
1010
|
+
lstat as fsLstat,
|
|
1011
|
+
mkdir as fsMkdir,
|
|
1012
|
+
rename as fsRename,
|
|
1013
|
+
unlink as fsUnlink
|
|
1014
|
+
} from "fs/promises";
|
|
1015
|
+
var MAX_STATE_FILE_BYTES = 16 * 1024 * 1024;
|
|
1016
|
+
async function portableReadBounded(filePath, maxBytes = MAX_STATE_FILE_BYTES) {
|
|
1017
|
+
const { open } = await import("fs/promises");
|
|
1018
|
+
const info = await fsLstat(filePath).catch(() => null);
|
|
1019
|
+
if (!info || info.isSymbolicLink() || !info.isFile()) {
|
|
1020
|
+
throw new Error(`refusing to read non-regular file: ${filePath}`);
|
|
1021
|
+
}
|
|
1022
|
+
const handle = await open(filePath, "r");
|
|
1023
|
+
try {
|
|
1024
|
+
const opened = await handle.stat();
|
|
1025
|
+
const buf = Buffer.alloc(Math.min(opened.size, maxBytes));
|
|
1026
|
+
const { bytesRead } = await handle.read(buf, 0, buf.length, 0);
|
|
1027
|
+
return {
|
|
1028
|
+
text: buf.subarray(0, bytesRead).toString("utf8"),
|
|
1029
|
+
truncated: opened.size > maxBytes
|
|
1030
|
+
};
|
|
1031
|
+
} finally {
|
|
1032
|
+
await handle.close();
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
async function portableWriteFile(filePath, data, mode = 384, commit) {
|
|
1036
|
+
const { dirname } = await import("path");
|
|
1037
|
+
const { open } = await import("fs/promises");
|
|
1038
|
+
const { randomUUID } = await import("crypto");
|
|
1039
|
+
const { constants, renameSync } = await import("fs");
|
|
1040
|
+
await fsMkdir(dirname(filePath), { recursive: true, mode: 448 });
|
|
1041
|
+
const temporaryPath = `${filePath}.tmp-${randomUUID()}`;
|
|
1042
|
+
let installed = false;
|
|
1043
|
+
let ownsTemporary = false;
|
|
1044
|
+
let backupPath = null;
|
|
1045
|
+
try {
|
|
1046
|
+
const handle = await open(temporaryPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, mode);
|
|
1047
|
+
ownsTemporary = true;
|
|
1048
|
+
try {
|
|
1049
|
+
await handle.writeFile(data, "utf8");
|
|
1050
|
+
await handle.chmod(mode);
|
|
1051
|
+
await handle.sync();
|
|
1052
|
+
} finally {
|
|
1053
|
+
await handle.close();
|
|
1054
|
+
}
|
|
1055
|
+
const existing = await fsLstat(filePath).catch(() => {
|
|
1056
|
+
return;
|
|
1057
|
+
});
|
|
1058
|
+
if (existing?.isSymbolicLink()) {
|
|
1059
|
+
throw new Error(`refusing to replace symlinked state file: ${filePath}`);
|
|
1060
|
+
}
|
|
1061
|
+
if (existing && !existing.isFile()) {
|
|
1062
|
+
throw new Error(`refusing to replace non-regular state file: ${filePath}`);
|
|
1063
|
+
}
|
|
1064
|
+
commit?.beforeInstall();
|
|
1065
|
+
try {
|
|
1066
|
+
if (commit)
|
|
1067
|
+
renameSync(temporaryPath, filePath);
|
|
1068
|
+
else
|
|
1069
|
+
await fsRename(temporaryPath, filePath);
|
|
1070
|
+
installed = true;
|
|
1071
|
+
} catch (renameError) {
|
|
1072
|
+
if (!existing)
|
|
1073
|
+
throw renameError;
|
|
1074
|
+
backupPath = `${filePath}.bak-${randomUUID()}`;
|
|
1075
|
+
if (commit)
|
|
1076
|
+
renameSync(filePath, backupPath);
|
|
1077
|
+
else
|
|
1078
|
+
await fsRename(filePath, backupPath);
|
|
1079
|
+
try {
|
|
1080
|
+
if (commit)
|
|
1081
|
+
renameSync(temporaryPath, filePath);
|
|
1082
|
+
else
|
|
1083
|
+
await fsRename(temporaryPath, filePath);
|
|
1084
|
+
installed = true;
|
|
1085
|
+
} catch (fallbackError) {
|
|
1086
|
+
try {
|
|
1087
|
+
if (commit)
|
|
1088
|
+
renameSync(backupPath, filePath);
|
|
1089
|
+
else
|
|
1090
|
+
await fsRename(backupPath, filePath);
|
|
1091
|
+
} catch (restoreError) {
|
|
1092
|
+
throw new Error(`snapshot replacement failed and prior snapshot restore failed; prior snapshot preserved at ${backupPath}: ${restoreError instanceof Error ? restoreError.message : String(restoreError)}`, { cause: fallbackError });
|
|
1093
|
+
}
|
|
1094
|
+
throw fallbackError;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
commit?.afterInstall();
|
|
1098
|
+
if (backupPath)
|
|
1099
|
+
await fsUnlink(backupPath).catch(() => {});
|
|
1100
|
+
try {
|
|
1101
|
+
const directory = await open(dirname(filePath), constants.O_RDONLY);
|
|
1102
|
+
try {
|
|
1103
|
+
await directory.sync();
|
|
1104
|
+
} finally {
|
|
1105
|
+
await directory.close();
|
|
1106
|
+
}
|
|
1107
|
+
} catch {}
|
|
1108
|
+
installed = true;
|
|
1109
|
+
} finally {
|
|
1110
|
+
if (ownsTemporary && !installed) {
|
|
1111
|
+
await fsUnlink(temporaryPath).catch(() => {});
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
async function portableFileExists(filePath) {
|
|
1116
|
+
try {
|
|
1117
|
+
const info = await fsLstat(filePath);
|
|
1118
|
+
return info.isFile();
|
|
1119
|
+
} catch {
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
async function portableFileSize(filePath) {
|
|
1124
|
+
try {
|
|
1125
|
+
const info = await fsLstat(filePath);
|
|
1126
|
+
return info.isFile() ? info.size : -1;
|
|
1127
|
+
} catch {
|
|
1128
|
+
return -1;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/session-paths.ts
|
|
1133
|
+
import { lstatSync } from "fs";
|
|
1134
|
+
import { dirname, join, relative, resolve, sep } from "path";
|
|
1135
|
+
var SESSIONS_DIRNAME = "sessions";
|
|
1136
|
+
var DEFAULT_STATE_ROOT = ".opencode/goals";
|
|
1137
|
+
var STATE_FILENAME = "state.json";
|
|
1138
|
+
var LEDGER_SUFFIX = ".ledger.jsonl";
|
|
1139
|
+
var SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
|
|
1140
|
+
function assertSafeSessionID(sessionID) {
|
|
1141
|
+
if (typeof sessionID !== "string" || !SESSION_ID_PATTERN.test(sessionID)) {
|
|
1142
|
+
const shown = typeof sessionID === "string" ? sessionID.slice(0, 64) : String(sessionID);
|
|
1143
|
+
throw new Error(`refusing to use ${JSON.stringify(shown)} as a session directory name: a session id must be 1-128 characters of A-Z, a-z, 0-9, '_' or '-'`);
|
|
1144
|
+
}
|
|
1145
|
+
return sessionID;
|
|
1146
|
+
}
|
|
1147
|
+
function sessionStatePaths(stateRoot, sessionID) {
|
|
1148
|
+
const sessionDir = join(stateRoot, SESSIONS_DIRNAME, assertSafeSessionID(sessionID));
|
|
1149
|
+
const statePath = join(sessionDir, STATE_FILENAME);
|
|
1150
|
+
return { sessionDir, statePath, ledgerPath: `${statePath}${LEDGER_SUFFIX}` };
|
|
1151
|
+
}
|
|
1152
|
+
function assertContainedInStateRoot(stateRoot, target) {
|
|
1153
|
+
const root = resolve(stateRoot);
|
|
1154
|
+
const rel = relative(root, target);
|
|
1155
|
+
if (rel.startsWith("..")) {
|
|
1156
|
+
throw new Error(`goal persistence path escapes the state root and is refused: ${target}`);
|
|
1157
|
+
}
|
|
1158
|
+
const rootParent = dirname(root);
|
|
1159
|
+
if (root !== rootParent) {
|
|
1160
|
+
let rootIsSymlink = false;
|
|
1161
|
+
try {
|
|
1162
|
+
rootIsSymlink = lstatSync(root).isSymbolicLink();
|
|
1163
|
+
} catch {}
|
|
1164
|
+
if (rootIsSymlink) {
|
|
1165
|
+
throw new Error(`refusing goal persistence: the state root itself is a symlink (${root}), so goal state would ` + "be written outside it. Point `stateRoot` at a real directory.");
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
if (rel === "")
|
|
1169
|
+
return;
|
|
1170
|
+
let cursor = root;
|
|
1171
|
+
for (const segment of rel.split(sep).filter((s) => s.length > 0)) {
|
|
1172
|
+
cursor = join(cursor, segment);
|
|
1173
|
+
let info;
|
|
1174
|
+
try {
|
|
1175
|
+
info = lstatSync(cursor);
|
|
1176
|
+
} catch {
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
if (info.isSymbolicLink()) {
|
|
1180
|
+
throw new Error(`refusing goal persistence through a symlinked path segment: ${cursor}`);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
async function ensureSessionDir(stateRoot, sessionID) {
|
|
1185
|
+
const { mkdir } = await import("fs/promises");
|
|
1186
|
+
const { sessionDir } = sessionStatePaths(stateRoot, sessionID);
|
|
1187
|
+
assertContainedInStateRoot(stateRoot, sessionDir);
|
|
1188
|
+
await mkdir(sessionDir, { recursive: true, mode: 448 });
|
|
1189
|
+
return sessionDir;
|
|
1190
|
+
}
|
|
1191
|
+
async function listSessionIDs(stateRoot) {
|
|
1192
|
+
let entries;
|
|
1193
|
+
try {
|
|
1194
|
+
const { readdir } = await import("fs/promises");
|
|
1195
|
+
entries = await readdir(join(stateRoot, SESSIONS_DIRNAME), {
|
|
1196
|
+
withFileTypes: true
|
|
1197
|
+
});
|
|
1198
|
+
} catch {
|
|
1199
|
+
return [];
|
|
1200
|
+
}
|
|
1201
|
+
return entries.filter((entry) => entry.isDirectory() && SESSION_ID_PATTERN.test(entry.name)).map((entry) => entry.name).sort();
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// src/tui-disk-state.ts
|
|
1205
|
+
function resolveStateRoot(directory, stateRoot) {
|
|
1206
|
+
const configured = stateRoot ?? process.env.FIXATE_ON_STATE_ROOT;
|
|
1207
|
+
return resolve2(directory ? resolve2(directory) : process.cwd(), configured ?? DEFAULT_STATE_ROOT);
|
|
1208
|
+
}
|
|
1209
|
+
function sessionIDFromStatePath(path) {
|
|
1210
|
+
const parts = path.split(/[\\/]/);
|
|
1211
|
+
const idx = parts.lastIndexOf(SESSIONS_DIRNAME);
|
|
1212
|
+
if (idx < 0 || idx + 1 >= parts.length - 1)
|
|
1213
|
+
return;
|
|
1214
|
+
return parts[idx + 1];
|
|
1215
|
+
}
|
|
1216
|
+
async function discoverStateFiles(directory, explicitPath, stateRoot) {
|
|
1217
|
+
const { readdir, stat } = await import("fs/promises");
|
|
1218
|
+
const { join } = await import("path");
|
|
1219
|
+
if (explicitPath) {
|
|
1220
|
+
const direct = resolve2(explicitPath);
|
|
1221
|
+
try {
|
|
1222
|
+
return (await stat(direct)).isFile() ? [direct] : [];
|
|
1223
|
+
} catch {
|
|
1224
|
+
return [];
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const sessionsRoot = join(resolveStateRoot(directory, stateRoot), SESSIONS_DIRNAME);
|
|
1228
|
+
try {
|
|
1229
|
+
const entries = await readdir(sessionsRoot, { withFileTypes: true });
|
|
1230
|
+
return entries.filter((entry) => entry.isDirectory() && SESSION_ID_PATTERN.test(entry.name)).map((entry) => join(sessionsRoot, entry.name, STATE_FILENAME)).sort();
|
|
1231
|
+
} catch {
|
|
1232
|
+
return [];
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function parseStateJson(content) {
|
|
1236
|
+
try {
|
|
1237
|
+
return JSON.parse(content);
|
|
1238
|
+
} catch {
|
|
1239
|
+
return null;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
function snapshotsFromParsed(parsed, originSessionID) {
|
|
1243
|
+
const rawGoals = Array.isArray(parsed?.goals) ? parsed.goals : [];
|
|
1244
|
+
const out = [];
|
|
1245
|
+
for (const g of rawGoals) {
|
|
1246
|
+
if (!g || typeof g !== "object" || !g.goalId || !g.sessionID)
|
|
1247
|
+
continue;
|
|
1248
|
+
const r = g;
|
|
1249
|
+
if (originSessionID !== undefined && String(r.sessionID) !== originSessionID)
|
|
1250
|
+
continue;
|
|
1251
|
+
out.push({
|
|
1252
|
+
goalId: String(r.goalId),
|
|
1253
|
+
sessionID: String(r.sessionID),
|
|
1254
|
+
condition: String(r.condition ?? ""),
|
|
1255
|
+
artifactPointers: Array.isArray(r.artifactPointers) ? [...r.artifactPointers] : [],
|
|
1256
|
+
pendingProposal: r.pendingProposal ? {
|
|
1257
|
+
...r.pendingProposal
|
|
1258
|
+
} : null,
|
|
1259
|
+
claims: Array.isArray(r.claims) ? r.claims.map((c) => ({
|
|
1260
|
+
...c
|
|
1261
|
+
})) : [],
|
|
1262
|
+
lastClaim: r.lastClaim ? { ...r.lastClaim } : null,
|
|
1263
|
+
status: VALID_GOAL_STATUSES.has(String(r.status)) ? r.status : "active",
|
|
1264
|
+
revision: typeof r.revision === "number" ? r.revision : 0,
|
|
1265
|
+
turnCount: typeof r.turnCount === "number" ? r.turnCount : 0,
|
|
1266
|
+
totalTokens: typeof r.totalTokens === "number" ? r.totalTokens : 0,
|
|
1267
|
+
maxTokens: typeof r.maxTokens === "number" ? r.maxTokens : 0,
|
|
1268
|
+
maxTurns: typeof r.maxTurns === "number" ? r.maxTurns : 0,
|
|
1269
|
+
tokenBudget: typeof r.tokenBudget === "number" ? r.tokenBudget : null,
|
|
1270
|
+
usage: r.usage ?? {
|
|
1271
|
+
input: 0,
|
|
1272
|
+
output: 0,
|
|
1273
|
+
reasoning: 0,
|
|
1274
|
+
cacheRead: 0,
|
|
1275
|
+
cacheWrite: 0,
|
|
1276
|
+
cost: 0,
|
|
1277
|
+
costKnown: false
|
|
1278
|
+
},
|
|
1279
|
+
stopReason: String(r.stopReason ?? ""),
|
|
1280
|
+
blockedReason: String(r.blockedReason ?? ""),
|
|
1281
|
+
pausedAt: typeof r.pausedAt === "number" && Number.isFinite(r.pausedAt) && r.pausedAt > 0 ? r.pausedAt : 0,
|
|
1282
|
+
stoppedAt: typeof r.stoppedAt === "number" && Number.isFinite(r.stoppedAt) && r.stoppedAt > 0 ? r.stoppedAt : 0,
|
|
1283
|
+
createdAt: typeof r.createdAt === "number" ? r.createdAt : Date.now(),
|
|
1284
|
+
updatedAt: typeof r.updatedAt === "number" ? r.updatedAt : Date.now(),
|
|
1285
|
+
finishedAt: typeof r.finishedAt === "number" ? r.finishedAt : null,
|
|
1286
|
+
lastCheckpoint: r.lastCheckpoint ? {
|
|
1287
|
+
summary: String(r.lastCheckpoint.summary),
|
|
1288
|
+
timestamp: Number(r.lastCheckpoint.timestamp)
|
|
1289
|
+
} : null,
|
|
1290
|
+
history: Array.isArray(r.history) ? r.history.map((h) => ({
|
|
1291
|
+
type: String(h.type ?? ""),
|
|
1292
|
+
detail: String(h.detail ?? ""),
|
|
1293
|
+
timestamp: Number(h.timestamp ?? 0)
|
|
1294
|
+
})) : []
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
return out;
|
|
1298
|
+
}
|
|
1299
|
+
function resultsFromParsed(parsed, originSessionID) {
|
|
1300
|
+
const rawResults = Array.isArray(parsed?.results) ? parsed.results : [];
|
|
1301
|
+
const out = [];
|
|
1302
|
+
for (const item of rawResults) {
|
|
1303
|
+
if (!item || typeof item !== "object")
|
|
1304
|
+
continue;
|
|
1305
|
+
const r = item;
|
|
1306
|
+
if (!r.goalId || !r.sessionID)
|
|
1307
|
+
continue;
|
|
1308
|
+
const sid = String(r.sessionID);
|
|
1309
|
+
if (originSessionID !== undefined && sid !== originSessionID)
|
|
1310
|
+
continue;
|
|
1311
|
+
const state = String(r.state ?? "");
|
|
1312
|
+
if (state !== "achieved" && state !== "blocked" && state !== "cleared")
|
|
1313
|
+
continue;
|
|
1314
|
+
out.push({
|
|
1315
|
+
goalId: String(r.goalId),
|
|
1316
|
+
sessionID: sid,
|
|
1317
|
+
condition: String(r.condition ?? ""),
|
|
1318
|
+
state,
|
|
1319
|
+
reason: String(r.reason ?? ""),
|
|
1320
|
+
blockedReason: String(r.blockedReason ?? ""),
|
|
1321
|
+
lastClaim: r.lastClaim ? {
|
|
1322
|
+
...r.lastClaim
|
|
1323
|
+
} : null
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
return out;
|
|
1327
|
+
}
|
|
1328
|
+
function focusedFromParsed(parsed, originSessionID) {
|
|
1329
|
+
const raw = Array.isArray(parsed?.focusedGoalIds) ? parsed.focusedGoalIds : [];
|
|
1330
|
+
const out = new Map;
|
|
1331
|
+
for (const item of raw) {
|
|
1332
|
+
if (!item || typeof item !== "object")
|
|
1333
|
+
continue;
|
|
1334
|
+
const r = item;
|
|
1335
|
+
if (!r.sessionID || !r.goalId)
|
|
1336
|
+
continue;
|
|
1337
|
+
const sid = String(r.sessionID);
|
|
1338
|
+
if (originSessionID !== undefined && sid !== originSessionID)
|
|
1339
|
+
continue;
|
|
1340
|
+
out.set(sid, String(r.goalId));
|
|
1341
|
+
}
|
|
1342
|
+
return out;
|
|
1343
|
+
}
|
|
1344
|
+
async function readDiskGoalSnapshots(directory, explicitPath, stateRoot) {
|
|
1345
|
+
const { join } = await import("path");
|
|
1346
|
+
const foundPaths = await discoverStateFiles(directory, explicitPath, stateRoot);
|
|
1347
|
+
const out = [];
|
|
1348
|
+
const readableSessions = new Set;
|
|
1349
|
+
const archivedResults = new Map;
|
|
1350
|
+
const focusedGoalIds = new Map;
|
|
1351
|
+
let filesRead = 0;
|
|
1352
|
+
for (const p of foundPaths) {
|
|
1353
|
+
try {
|
|
1354
|
+
const { text, truncated } = await portableReadBounded(p);
|
|
1355
|
+
if (truncated)
|
|
1356
|
+
continue;
|
|
1357
|
+
if (!text.trim())
|
|
1358
|
+
continue;
|
|
1359
|
+
const parsed = parseStateJson(text);
|
|
1360
|
+
if (!parsed)
|
|
1361
|
+
continue;
|
|
1362
|
+
filesRead += 1;
|
|
1363
|
+
const pathSession = sessionIDFromStatePath(p);
|
|
1364
|
+
if (pathSession)
|
|
1365
|
+
readableSessions.add(pathSession);
|
|
1366
|
+
const snaps = snapshotsFromParsed(parsed, pathSession);
|
|
1367
|
+
for (const s of snaps)
|
|
1368
|
+
readableSessions.add(s.sessionID);
|
|
1369
|
+
out.push(...snaps);
|
|
1370
|
+
for (const result of resultsFromParsed(parsed, pathSession)) {
|
|
1371
|
+
archivedResults.set(`${result.sessionID}\x00${result.goalId}`, result);
|
|
1372
|
+
}
|
|
1373
|
+
for (const [sid, goalId] of focusedFromParsed(parsed, pathSession)) {
|
|
1374
|
+
focusedGoalIds.set(sid, goalId);
|
|
1375
|
+
}
|
|
1376
|
+
} catch {}
|
|
1377
|
+
}
|
|
1378
|
+
let stateDirMissing = false;
|
|
1379
|
+
try {
|
|
1380
|
+
const { stat } = await import("fs/promises");
|
|
1381
|
+
if (explicitPath) {
|
|
1382
|
+
stateDirMissing = false;
|
|
1383
|
+
} else {
|
|
1384
|
+
await stat(join(resolveStateRoot(directory, stateRoot), SESSIONS_DIRNAME));
|
|
1385
|
+
}
|
|
1386
|
+
} catch {
|
|
1387
|
+
stateDirMissing = true;
|
|
1388
|
+
}
|
|
1389
|
+
return {
|
|
1390
|
+
snapshots: out,
|
|
1391
|
+
filesRead,
|
|
1392
|
+
stateDirMissing,
|
|
1393
|
+
readableSessions,
|
|
1394
|
+
archivedResults,
|
|
1395
|
+
focusedGoalIds
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// src/tui-companion-refresh.ts
|
|
1400
|
+
function keyOf(sessionID, goalId) {
|
|
1401
|
+
return `${sessionID}\x00${goalId}`;
|
|
1402
|
+
}
|
|
1403
|
+
function createDiskRefreshLoop(options) {
|
|
1404
|
+
const { store, onEvent } = options;
|
|
1405
|
+
const intervalMs = options.intervalMs ?? 1000;
|
|
1406
|
+
let timer = null;
|
|
1407
|
+
let pending = null;
|
|
1408
|
+
let cancelRead = null;
|
|
1409
|
+
let generation = 0;
|
|
1410
|
+
let stopped = false;
|
|
1411
|
+
let baselined = false;
|
|
1412
|
+
let previous = new Map;
|
|
1413
|
+
function synthesize(current, readableSessions, archivedResults) {
|
|
1414
|
+
const events = [];
|
|
1415
|
+
const seen = new Set;
|
|
1416
|
+
const now = Date.now();
|
|
1417
|
+
for (const snap of current) {
|
|
1418
|
+
const key = keyOf(snap.sessionID, snap.goalId);
|
|
1419
|
+
seen.add(key);
|
|
1420
|
+
const prev = previous.get(key);
|
|
1421
|
+
if (!prev) {
|
|
1422
|
+
const ev = {
|
|
1423
|
+
kind: "create",
|
|
1424
|
+
sessionID: snap.sessionID,
|
|
1425
|
+
timestamp: now,
|
|
1426
|
+
snapshot: { ...snap, origin: "disk" }
|
|
1427
|
+
};
|
|
1428
|
+
events.push({ storeEvent: ev, notifyEvent: ev });
|
|
1429
|
+
} else if (prev.revision !== snap.revision || prev.status !== snap.status || prev.totalTokens !== snap.totalTokens || prev.turnCount !== snap.turnCount) {
|
|
1430
|
+
const ev = {
|
|
1431
|
+
kind: "transition",
|
|
1432
|
+
sessionID: snap.sessionID,
|
|
1433
|
+
timestamp: now,
|
|
1434
|
+
snapshot: { ...snap, origin: "disk" },
|
|
1435
|
+
previousStatus: prev.status
|
|
1436
|
+
};
|
|
1437
|
+
events.push({ storeEvent: ev, notifyEvent: ev });
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
for (const [key, prev] of previous) {
|
|
1441
|
+
if (seen.has(key))
|
|
1442
|
+
continue;
|
|
1443
|
+
if (!readableSessions.has(prev.sessionID))
|
|
1444
|
+
continue;
|
|
1445
|
+
const removeEvent = {
|
|
1446
|
+
kind: "remove",
|
|
1447
|
+
sessionID: prev.sessionID,
|
|
1448
|
+
goalId: prev.goalId,
|
|
1449
|
+
snapshot: prev,
|
|
1450
|
+
timestamp: now
|
|
1451
|
+
};
|
|
1452
|
+
const archived = archivedResults?.get(key);
|
|
1453
|
+
let notifyEvent = removeEvent;
|
|
1454
|
+
if (archived?.state === "achieved") {
|
|
1455
|
+
notifyEvent = {
|
|
1456
|
+
kind: "transition",
|
|
1457
|
+
sessionID: prev.sessionID,
|
|
1458
|
+
goalId: prev.goalId,
|
|
1459
|
+
previousStatus: prev.status,
|
|
1460
|
+
timestamp: now,
|
|
1461
|
+
snapshot: {
|
|
1462
|
+
...prev,
|
|
1463
|
+
status: "complete",
|
|
1464
|
+
stopReason: archived.reason || prev.stopReason,
|
|
1465
|
+
lastClaim: archived.lastClaim ?? prev.lastClaim,
|
|
1466
|
+
origin: "disk"
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
} else if (archived?.state === "blocked") {
|
|
1470
|
+
notifyEvent = {
|
|
1471
|
+
kind: "transition",
|
|
1472
|
+
sessionID: prev.sessionID,
|
|
1473
|
+
goalId: prev.goalId,
|
|
1474
|
+
previousStatus: prev.status,
|
|
1475
|
+
timestamp: now,
|
|
1476
|
+
snapshot: {
|
|
1477
|
+
...prev,
|
|
1478
|
+
status: "blocked",
|
|
1479
|
+
stopReason: archived.reason || prev.stopReason,
|
|
1480
|
+
blockedReason: archived.blockedReason || prev.blockedReason,
|
|
1481
|
+
lastClaim: archived.lastClaim ?? prev.lastClaim,
|
|
1482
|
+
origin: "disk"
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
events.push({ storeEvent: removeEvent, notifyEvent });
|
|
1487
|
+
}
|
|
1488
|
+
return events;
|
|
1489
|
+
}
|
|
1490
|
+
async function readAndApply() {
|
|
1491
|
+
const started = generation;
|
|
1492
|
+
const changed = new Map;
|
|
1493
|
+
const unsubscribe = store.subscribe((event) => {
|
|
1494
|
+
const goalId = event.goalId ?? event.snapshot?.goalId;
|
|
1495
|
+
if (goalId) {
|
|
1496
|
+
changed.set(keyOf(event.sessionID, goalId), {
|
|
1497
|
+
sessionID: event.sessionID,
|
|
1498
|
+
goalId
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
cancelRead = unsubscribe;
|
|
1503
|
+
try {
|
|
1504
|
+
const read = await readDiskGoalSnapshots(options.directory, options.explicitPath, options.stateRoot);
|
|
1505
|
+
if (stopped || started !== generation)
|
|
1506
|
+
return;
|
|
1507
|
+
unsubscribe();
|
|
1508
|
+
const initial = !baselined;
|
|
1509
|
+
if (!baselined) {
|
|
1510
|
+
if (read.filesRead === 0 && !read.stateDirMissing)
|
|
1511
|
+
return;
|
|
1512
|
+
baselined = true;
|
|
1513
|
+
}
|
|
1514
|
+
if (read.filesRead === 0 && previous.size > 0)
|
|
1515
|
+
return;
|
|
1516
|
+
for (const { storeEvent, notifyEvent } of synthesize(read.snapshots, read.readableSessions, read.archivedResults)) {
|
|
1517
|
+
const goalId = storeEvent.goalId ?? storeEvent.snapshot.goalId;
|
|
1518
|
+
if (changed.has(keyOf(storeEvent.sessionID, goalId)))
|
|
1519
|
+
continue;
|
|
1520
|
+
store.applyEvent(storeEvent);
|
|
1521
|
+
if (!initial)
|
|
1522
|
+
onEvent(notifyEvent);
|
|
1523
|
+
}
|
|
1524
|
+
const changedSessions = new Set([...changed.values()].map((ref) => ref.sessionID));
|
|
1525
|
+
if (read.focusedGoalIds) {
|
|
1526
|
+
for (const [sid, focusedGoalId] of read.focusedGoalIds) {
|
|
1527
|
+
if (changedSessions.has(sid))
|
|
1528
|
+
continue;
|
|
1529
|
+
if (store.getSnapshot(sid, focusedGoalId)) {
|
|
1530
|
+
store.setFocused(sid, focusedGoalId);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
if (initial) {
|
|
1535
|
+
for (const sid of read.readableSessions) {
|
|
1536
|
+
if (changedSessions.has(sid))
|
|
1537
|
+
continue;
|
|
1538
|
+
if (read.focusedGoalIds?.has(sid))
|
|
1539
|
+
continue;
|
|
1540
|
+
if (store.getFocused(sid)?.status === "active")
|
|
1541
|
+
continue;
|
|
1542
|
+
const firstActive = store.getSnapshots(sid).find((s) => s.status === "active");
|
|
1543
|
+
if (firstActive)
|
|
1544
|
+
store.setFocused(sid, firstActive.goalId);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
const oldPrevious = previous;
|
|
1548
|
+
previous = new Map(read.snapshots.map((s) => [keyOf(s.sessionID, s.goalId), s]));
|
|
1549
|
+
for (const [key, snap] of oldPrevious) {
|
|
1550
|
+
if (!read.readableSessions.has(snap.sessionID) && !previous.has(key)) {
|
|
1551
|
+
previous.set(key, snap);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
for (const [key, ref] of changed) {
|
|
1555
|
+
if (!oldPrevious.has(key) && !previous.has(key))
|
|
1556
|
+
continue;
|
|
1557
|
+
const live = store.getSnapshot(ref.sessionID, ref.goalId);
|
|
1558
|
+
if (live) {
|
|
1559
|
+
previous.set(key, live);
|
|
1560
|
+
} else {
|
|
1561
|
+
previous.delete(key);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
} catch {} finally {
|
|
1565
|
+
unsubscribe();
|
|
1566
|
+
if (cancelRead === unsubscribe)
|
|
1567
|
+
cancelRead = null;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
function tick() {
|
|
1571
|
+
if (stopped)
|
|
1572
|
+
return Promise.resolve();
|
|
1573
|
+
if (pending)
|
|
1574
|
+
return pending;
|
|
1575
|
+
const current = readAndApply().finally(() => {
|
|
1576
|
+
if (pending === current)
|
|
1577
|
+
pending = null;
|
|
1578
|
+
});
|
|
1579
|
+
pending = current;
|
|
1580
|
+
return current;
|
|
1581
|
+
}
|
|
1582
|
+
return {
|
|
1583
|
+
tick,
|
|
1584
|
+
getSnapshots: () => [...previous.values()],
|
|
1585
|
+
start() {
|
|
1586
|
+
if (timer)
|
|
1587
|
+
return;
|
|
1588
|
+
stopped = false;
|
|
1589
|
+
if (!baselined)
|
|
1590
|
+
tick();
|
|
1591
|
+
timer = setInterval(() => void tick(), intervalMs);
|
|
1592
|
+
if (typeof timer === "object" && timer !== null && "unref" in timer) {
|
|
1593
|
+
timer.unref();
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
stop() {
|
|
1597
|
+
stopped = true;
|
|
1598
|
+
generation++;
|
|
1599
|
+
cancelRead?.();
|
|
1600
|
+
cancelRead = null;
|
|
1601
|
+
pending = null;
|
|
1602
|
+
if (timer) {
|
|
1603
|
+
clearInterval(timer);
|
|
1604
|
+
timer = null;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// src/tui-action-labels.ts
|
|
1611
|
+
var MUTATING_ROOTS = new Set([
|
|
1612
|
+
"pause",
|
|
1613
|
+
"resume",
|
|
1614
|
+
"clear",
|
|
1615
|
+
"edit",
|
|
1616
|
+
"checkpoint",
|
|
1617
|
+
"focus",
|
|
1618
|
+
"add",
|
|
1619
|
+
"sequence",
|
|
1620
|
+
"accept",
|
|
1621
|
+
"reject",
|
|
1622
|
+
"handback",
|
|
1623
|
+
"review-payload"
|
|
1624
|
+
]);
|
|
1625
|
+
function isMutatingGoalCommand(command) {
|
|
1626
|
+
const root = command.trim().split(/\s+/)[0];
|
|
1627
|
+
return MUTATING_ROOTS.has(root);
|
|
1628
|
+
}
|
|
1629
|
+
function outcomeNeutralLabel(command) {
|
|
1630
|
+
const root = command.trim().split(/\s+/)[0];
|
|
1631
|
+
return `Goal requested: ${root}`;
|
|
1632
|
+
}
|
|
1633
|
+
function watchdogTimeoutMessage(host, command, timeoutMs) {
|
|
1634
|
+
const seconds = Math.round(timeoutMs / 1000);
|
|
1635
|
+
const shown = seconds < 1 ? "<1s" : `${seconds}s`;
|
|
1636
|
+
const root = command.trim().split(/\s+/)[0];
|
|
1637
|
+
const retry = host === "v1" ? `Retry from the Goal palette or /goal ${root}.` : "Retry from the Goal palette.";
|
|
1638
|
+
return `Goal action "${root}" did not land within ${shown}. ${retry}`;
|
|
1639
|
+
}
|
|
1640
|
+
var DEGRADED_MODE_MESSAGE = `${PRODUCT_DISPLAY_NAME} is not loaded: actions from this palette cannot take effect. ` + "Check the server plugin loaded, then reopen this palette.";
|
|
1641
|
+
function createDegradedModeDetector() {
|
|
1642
|
+
let surfaceAlive = false;
|
|
1643
|
+
let announcedThisEpisode = false;
|
|
1644
|
+
return {
|
|
1645
|
+
noteSurfaceAlive() {
|
|
1646
|
+
surfaceAlive = true;
|
|
1647
|
+
announcedThisEpisode = false;
|
|
1648
|
+
},
|
|
1649
|
+
checkDispatch() {
|
|
1650
|
+
if (surfaceAlive || announcedThisEpisode)
|
|
1651
|
+
return null;
|
|
1652
|
+
announcedThisEpisode = true;
|
|
1653
|
+
return DEGRADED_MODE_MESSAGE;
|
|
1654
|
+
},
|
|
1655
|
+
get isDegraded() {
|
|
1656
|
+
return !surfaceAlive;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
function createGoalWatchdogs(host, notifyTimeout, defaultTimeoutMs = 15000) {
|
|
1661
|
+
const active = new Map;
|
|
1662
|
+
const keyOf = (sessionID, command) => `${sessionID}:${command.trim().split(/\s+/)[0]}`;
|
|
1663
|
+
return {
|
|
1664
|
+
arm(sessionID, command, timeoutMs = defaultTimeoutMs) {
|
|
1665
|
+
const key = keyOf(sessionID, command);
|
|
1666
|
+
const existing = active.get(key);
|
|
1667
|
+
if (existing)
|
|
1668
|
+
clearTimeout(existing.timer);
|
|
1669
|
+
const timer = setTimeout(() => {
|
|
1670
|
+
active.delete(key);
|
|
1671
|
+
notifyTimeout(watchdogTimeoutMessage(host, command, timeoutMs));
|
|
1672
|
+
}, timeoutMs);
|
|
1673
|
+
active.set(key, { timer, command, sessionID });
|
|
1674
|
+
},
|
|
1675
|
+
disarmSession(sessionID) {
|
|
1676
|
+
for (const [key, w] of active.entries()) {
|
|
1677
|
+
if (w.sessionID === sessionID) {
|
|
1678
|
+
clearTimeout(w.timer);
|
|
1679
|
+
active.delete(key);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
},
|
|
1683
|
+
cancel(sessionID, command) {
|
|
1684
|
+
const key = keyOf(sessionID, command);
|
|
1685
|
+
const w = active.get(key);
|
|
1686
|
+
if (w) {
|
|
1687
|
+
clearTimeout(w.timer);
|
|
1688
|
+
active.delete(key);
|
|
1689
|
+
}
|
|
1690
|
+
},
|
|
1691
|
+
get armedCount() {
|
|
1692
|
+
return active.size;
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// src/tui-toast-policy.ts
|
|
1698
|
+
init_status_label();
|
|
1699
|
+
var TOAST_MESSAGE_MAX = 120;
|
|
1700
|
+
var REMEMBERED_LIMIT = 4096;
|
|
1701
|
+
var TOAST_MIN_INTERVAL_MS = 2000;
|
|
1702
|
+
var TOAST_COALESCE_WINDOW_MS = 500;
|
|
1703
|
+
var TOAST_QUEUE_MAX = 3;
|
|
1704
|
+
var BRIEFING_SESSION_KEY = "\x00briefing";
|
|
1705
|
+
function truncateCondition(text, max = 60) {
|
|
1706
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
1707
|
+
if (clean.length <= max)
|
|
1708
|
+
return clean;
|
|
1709
|
+
const cut = clean.slice(0, max);
|
|
1710
|
+
const lastSpace = cut.lastIndexOf(" ");
|
|
1711
|
+
return `${(lastSpace > max * 0.5 ? cut.slice(0, lastSpace) : cut).trimEnd()}\u2026`;
|
|
1712
|
+
}
|
|
1713
|
+
function shouldToast(event) {
|
|
1714
|
+
switch (event.kind) {
|
|
1715
|
+
case "create":
|
|
1716
|
+
return true;
|
|
1717
|
+
case "remove":
|
|
1718
|
+
return true;
|
|
1719
|
+
case "usage":
|
|
1720
|
+
return false;
|
|
1721
|
+
case "transition":
|
|
1722
|
+
return lifecycleSide(event) !== null;
|
|
1723
|
+
default:
|
|
1724
|
+
return false;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
function lifecycleSide(event) {
|
|
1728
|
+
const status = event.snapshot?.status;
|
|
1729
|
+
if (!status)
|
|
1730
|
+
return null;
|
|
1731
|
+
const from = previousStatusOf(event);
|
|
1732
|
+
if (from !== undefined && from === status)
|
|
1733
|
+
return null;
|
|
1734
|
+
if (from === undefined) {
|
|
1735
|
+
return status === "active" || status === "finalizing" ? null : "stop";
|
|
1736
|
+
}
|
|
1737
|
+
if (status === "complete" || status === "blocked")
|
|
1738
|
+
return "stop";
|
|
1739
|
+
if (status === "active")
|
|
1740
|
+
return "start";
|
|
1741
|
+
if (STOPPED_STATUSES.has(status)) {
|
|
1742
|
+
return SELF_RESOLVING_STOP_REASONS.has(event.snapshot?.stopReason ?? "") ? null : "stop";
|
|
1743
|
+
}
|
|
1744
|
+
return null;
|
|
1745
|
+
}
|
|
1746
|
+
function previousStatusOf(event) {
|
|
1747
|
+
return event.previousStatus ?? event.transition?.from;
|
|
1748
|
+
}
|
|
1749
|
+
var STOPPED_STATUSES = new Set([
|
|
1750
|
+
"paused",
|
|
1751
|
+
"blocked",
|
|
1752
|
+
"budgetLimited",
|
|
1753
|
+
"complete"
|
|
1754
|
+
]);
|
|
1755
|
+
function isLimitOrEscalationPause(stopReason) {
|
|
1756
|
+
return /recovery exhausted|escalated|max turns|max stall|max context tokens|budget/i.test(stopReason);
|
|
1757
|
+
}
|
|
1758
|
+
var LIMIT_PAUSE_PHRASES = [
|
|
1759
|
+
[/max turns/i, "Goal stopped \u2014 it reached its turn limit"],
|
|
1760
|
+
[/max stall/i, "Goal stopped \u2014 it ran for its time limit without finishing"],
|
|
1761
|
+
[/max context tokens/i, "Goal stopped \u2014 it reached its context limit"],
|
|
1762
|
+
[/budget/i, "Goal stopped \u2014 its token budget ran out"],
|
|
1763
|
+
[
|
|
1764
|
+
/recovery exhausted/i,
|
|
1765
|
+
"Goal paused after repeated failures \u2014 review needed"
|
|
1766
|
+
],
|
|
1767
|
+
[/escalated/i, "Goal escalated \u2014 it needs you to decide how to continue"]
|
|
1768
|
+
];
|
|
1769
|
+
function limitPausePhrase(stopReason) {
|
|
1770
|
+
for (const [pattern, phrase] of LIMIT_PAUSE_PHRASES) {
|
|
1771
|
+
if (pattern.test(stopReason))
|
|
1772
|
+
return phrase;
|
|
1773
|
+
}
|
|
1774
|
+
return isLimitOrEscalationPause(stopReason) ? "Goal stopped by a limit it reached" : null;
|
|
1775
|
+
}
|
|
1776
|
+
var NEEDS_YOU_PHRASES = [
|
|
1777
|
+
[/tool surface unavailable/i, "the goal tools are gone"],
|
|
1778
|
+
[
|
|
1779
|
+
/verifier:\s*(COMPLETE|NEEDS_INPUT|CANCELLED|BLOCKED|WORKING)/i,
|
|
1780
|
+
"a verifier stopped it"
|
|
1781
|
+
],
|
|
1782
|
+
[
|
|
1783
|
+
/unattested completion asserted repeatedly|no attestation|unattestable/i,
|
|
1784
|
+
"the claim could not be attested"
|
|
1785
|
+
],
|
|
1786
|
+
[/judge rejected/i, "the judge rejected the claim"],
|
|
1787
|
+
[/permission rejected/i, "a permission was rejected"],
|
|
1788
|
+
[/session error/i, "a session error"],
|
|
1789
|
+
[/execution (failure|interrupted)|message aborted/i, "an execution error"],
|
|
1790
|
+
[/no tool calls/i, "no tool calls"],
|
|
1791
|
+
[/no progress/i, "no progress"],
|
|
1792
|
+
[/deferred too many times/i, "deferred too many times"],
|
|
1793
|
+
[/compaction loop/i, "the session is stuck compacting"],
|
|
1794
|
+
[/^(paused|explicit pause)$/i, "paused"],
|
|
1795
|
+
[/blocked/i, "blocked"]
|
|
1796
|
+
];
|
|
1797
|
+
var MACHINE_STRING = /[()]|\w+:|[a-z][A-Z]|_/;
|
|
1798
|
+
function needsYouReason(stopReason) {
|
|
1799
|
+
if (stopReason === USER_INTERVENTION_STOP_REASON)
|
|
1800
|
+
return "paused";
|
|
1801
|
+
for (const [pattern, phrase] of NEEDS_YOU_PHRASES) {
|
|
1802
|
+
if (pattern.test(stopReason))
|
|
1803
|
+
return phrase;
|
|
1804
|
+
}
|
|
1805
|
+
const clean = stopReason.trim();
|
|
1806
|
+
if (clean === "" || MACHINE_STRING.test(clean))
|
|
1807
|
+
return "stopped for a reason the plugin did not name";
|
|
1808
|
+
return truncateCondition(clean);
|
|
1809
|
+
}
|
|
1810
|
+
function goalNeedsTheUser(snapshot, _now) {
|
|
1811
|
+
const status = snapshot.status;
|
|
1812
|
+
if (status === "active" || status === "finalizing" || status === "complete")
|
|
1813
|
+
return false;
|
|
1814
|
+
if (isSelfResolvingStop(status, snapshot.stopReason))
|
|
1815
|
+
return false;
|
|
1816
|
+
return true;
|
|
1817
|
+
}
|
|
1818
|
+
function reasonForGoal(snapshot, _now) {
|
|
1819
|
+
if (snapshot.status === "blocked") {
|
|
1820
|
+
return snapshot.blockedReason ? truncateCondition(snapshot.blockedReason, 40) : "blocked";
|
|
1821
|
+
}
|
|
1822
|
+
if (snapshot.status === "budgetLimited" && !snapshot.stopReason)
|
|
1823
|
+
return "the token budget ran out";
|
|
1824
|
+
return needsYouReason(snapshot.stopReason);
|
|
1825
|
+
}
|
|
1826
|
+
function summarizeGoalsNeedingYou(snapshots) {
|
|
1827
|
+
const counts = new Map;
|
|
1828
|
+
let total = 0;
|
|
1829
|
+
for (const snapshot of snapshots) {
|
|
1830
|
+
if (!goalNeedsTheUser(snapshot))
|
|
1831
|
+
continue;
|
|
1832
|
+
const reason = reasonForGoal(snapshot);
|
|
1833
|
+
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
1834
|
+
total += 1;
|
|
1835
|
+
}
|
|
1836
|
+
if (total === 0)
|
|
1837
|
+
return null;
|
|
1838
|
+
const ordered = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
1839
|
+
const goalWord = total === 1 ? "1 goal needs you" : `${total} goals need you`;
|
|
1840
|
+
const budget = TOAST_MESSAGE_MAX - 1;
|
|
1841
|
+
const compose = (parts, dropped) => {
|
|
1842
|
+
const list = parts.map(([reason, count]) => count > 1 ? `${count} ${reason}` : reason).join(", ");
|
|
1843
|
+
const tail = dropped > 0 ? `, +${dropped} more` : "";
|
|
1844
|
+
const text = `${goalWord}: ${list}${tail}`;
|
|
1845
|
+
return text.length <= TOAST_MESSAGE_MAX ? text : `${text.slice(0, TOAST_MESSAGE_MAX - 1)}\u2026`;
|
|
1846
|
+
};
|
|
1847
|
+
let kept = ordered;
|
|
1848
|
+
let dropped = 0;
|
|
1849
|
+
while (kept.length > 1 && compose(kept, 0).length > budget) {
|
|
1850
|
+
const removed = kept[kept.length - 1];
|
|
1851
|
+
dropped += removed[1];
|
|
1852
|
+
kept = kept.slice(0, -1);
|
|
1853
|
+
}
|
|
1854
|
+
return {
|
|
1855
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1856
|
+
variant: "warning",
|
|
1857
|
+
message: compose(kept, dropped)
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
var CLAIM_PLAIN = {
|
|
1861
|
+
"verified-complete": "attested",
|
|
1862
|
+
"unverifiable-claim": "completed, but no attestation could be obtained",
|
|
1863
|
+
"claim-refuted": "claimed done, but the evidence said otherwise",
|
|
1864
|
+
"blocked-acknowledged": "stopped with a known blocker"
|
|
1865
|
+
};
|
|
1866
|
+
function formatCuratedToast(event, startAnnouncement = true) {
|
|
1867
|
+
const condition = truncateCondition(event.snapshot?.condition ?? "goal");
|
|
1868
|
+
switch (event.kind) {
|
|
1869
|
+
case "create":
|
|
1870
|
+
return {
|
|
1871
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1872
|
+
variant: "info",
|
|
1873
|
+
message: `Goal started: ${condition}`
|
|
1874
|
+
};
|
|
1875
|
+
case "remove":
|
|
1876
|
+
return {
|
|
1877
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1878
|
+
variant: "info",
|
|
1879
|
+
message: `Goal cleared: ${truncateCondition(event.snapshot?.condition ?? event.goalId ?? "goal")}`
|
|
1880
|
+
};
|
|
1881
|
+
case "transition": {
|
|
1882
|
+
const status = event.snapshot?.status;
|
|
1883
|
+
if (status === "complete") {
|
|
1884
|
+
const outcomeStatus = event.snapshot?.lastClaim?.outcome.status;
|
|
1885
|
+
const suffix = outcomeStatus && outcomeStatus !== "verified-complete" ? ` (${CLAIM_PLAIN[outcomeStatus] ?? outcomeStatus})` : "";
|
|
1886
|
+
return {
|
|
1887
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1888
|
+
variant: suffix ? "info" : "success",
|
|
1889
|
+
message: `Goal complete: ${condition}${suffix}`
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1892
|
+
if (status === "blocked") {
|
|
1893
|
+
const reason = truncateCondition(event.snapshot?.blockedReason ?? "needs your input");
|
|
1894
|
+
return {
|
|
1895
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1896
|
+
variant: "warning",
|
|
1897
|
+
message: `Paused \u2014 ${reason}`
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
const limitPause = limitPausePhrase(event.snapshot?.stopReason ?? "");
|
|
1901
|
+
if (limitPause) {
|
|
1902
|
+
return {
|
|
1903
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1904
|
+
variant: "error",
|
|
1905
|
+
message: `${limitPause} (${condition})`
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
if (status === "active" && startAnnouncement) {
|
|
1909
|
+
return {
|
|
1910
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1911
|
+
variant: "info",
|
|
1912
|
+
message: `Goal started: ${condition}`
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
if (status === "active") {
|
|
1916
|
+
return {
|
|
1917
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1918
|
+
variant: "info",
|
|
1919
|
+
message: `Goal running again: ${condition}`
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
if (status !== undefined && STOPPED_STATUSES.has(status)) {
|
|
1923
|
+
return {
|
|
1924
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1925
|
+
variant: "warning",
|
|
1926
|
+
message: `Goal stopped \u2014 ${needsYouReason(event.snapshot?.stopReason ?? "")} (${condition})`
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
return {
|
|
1930
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1931
|
+
variant: "info",
|
|
1932
|
+
message: `Goal update: ${condition}`
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
default:
|
|
1936
|
+
return {
|
|
1937
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
1938
|
+
variant: "info",
|
|
1939
|
+
message: `Goal update: ${condition}`
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
class ToastCoalescer {
|
|
1945
|
+
emit;
|
|
1946
|
+
now;
|
|
1947
|
+
autoFlushMs;
|
|
1948
|
+
queues = new Map;
|
|
1949
|
+
lastEmittedAt = new Map;
|
|
1950
|
+
lastMessageBySession = new Map;
|
|
1951
|
+
announced = new Set;
|
|
1952
|
+
pumpTimer = null;
|
|
1953
|
+
constructor(emit, now = Date.now, autoFlushMs = null) {
|
|
1954
|
+
this.emit = emit;
|
|
1955
|
+
this.now = now;
|
|
1956
|
+
this.autoFlushMs = autoFlushMs;
|
|
1957
|
+
}
|
|
1958
|
+
get queuedCount() {
|
|
1959
|
+
let total = 0;
|
|
1960
|
+
for (const queue of this.queues.values())
|
|
1961
|
+
total += queue.length;
|
|
1962
|
+
return total;
|
|
1963
|
+
}
|
|
1964
|
+
accept(event, sessionKey) {
|
|
1965
|
+
this.flush();
|
|
1966
|
+
const goalId = event.snapshot?.goalId;
|
|
1967
|
+
const memoryKey = goalId ? `${sessionKey}|${goalId}` : null;
|
|
1968
|
+
const side = lifecycleSide(event);
|
|
1969
|
+
if (memoryKey) {
|
|
1970
|
+
if (event.kind === "remove" && event.goalId) {
|
|
1971
|
+
this.announced.delete(memoryKey);
|
|
1972
|
+
} else if (event.kind === "create") {
|
|
1973
|
+
this.claimStartAnnouncement(sessionKey, goalId);
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
let firstTime = false;
|
|
1977
|
+
if (!shouldToast(event))
|
|
1978
|
+
return;
|
|
1979
|
+
if (side === "start" && goalId)
|
|
1980
|
+
firstTime = this.claimStartAnnouncement(sessionKey, goalId);
|
|
1981
|
+
this.enqueue(sessionKey, formatCuratedToast(event, firstTime), goalId);
|
|
1982
|
+
}
|
|
1983
|
+
brief(sessionKey, toast) {
|
|
1984
|
+
this.flush();
|
|
1985
|
+
this.enqueue(sessionKey, toast, undefined);
|
|
1986
|
+
}
|
|
1987
|
+
flush() {
|
|
1988
|
+
for (const [sessionKey, queue] of [...this.queues]) {
|
|
1989
|
+
while (queue.length > 0) {
|
|
1990
|
+
const nowTs = this.now();
|
|
1991
|
+
if (nowTs - this.emittedAtFor(sessionKey) < TOAST_MIN_INTERVAL_MS)
|
|
1992
|
+
break;
|
|
1993
|
+
const next = queue.shift();
|
|
1994
|
+
if (!next)
|
|
1995
|
+
break;
|
|
1996
|
+
this.emitNow(sessionKey, next, nowTs);
|
|
1997
|
+
}
|
|
1998
|
+
if (queue.length === 0)
|
|
1999
|
+
this.queues.delete(sessionKey);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
startAutoFlush() {
|
|
2003
|
+
if (this.pumpTimer || this.autoFlushMs === null)
|
|
2004
|
+
return;
|
|
2005
|
+
this.pumpTimer = setInterval(() => this.flush(), this.autoFlushMs);
|
|
2006
|
+
if (typeof this.pumpTimer === "object" && this.pumpTimer !== null && "unref" in this.pumpTimer) {
|
|
2007
|
+
this.pumpTimer.unref();
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
stopAutoFlush() {
|
|
2011
|
+
if (this.pumpTimer) {
|
|
2012
|
+
clearInterval(this.pumpTimer);
|
|
2013
|
+
this.pumpTimer = null;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
claimStartAnnouncement(sessionKey, goalId) {
|
|
2017
|
+
if (!goalId)
|
|
2018
|
+
return true;
|
|
2019
|
+
const key = `${sessionKey}|${goalId}`;
|
|
2020
|
+
if (this.announced.has(key))
|
|
2021
|
+
return false;
|
|
2022
|
+
this.announced.add(key);
|
|
2023
|
+
this.pruneRemembered();
|
|
2024
|
+
return true;
|
|
2025
|
+
}
|
|
2026
|
+
pruneRemembered() {
|
|
2027
|
+
while (this.announced.size > REMEMBERED_LIMIT) {
|
|
2028
|
+
const oldest = this.announced.values().next();
|
|
2029
|
+
if (oldest.done)
|
|
2030
|
+
return;
|
|
2031
|
+
this.announced.delete(oldest.value);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
enqueue(sessionKey, toast, goalId) {
|
|
2035
|
+
const last = this.lastMessageBySession.get(sessionKey);
|
|
2036
|
+
if (last && toast.message === last.message && this.now() - last.at < TOAST_COALESCE_WINDOW_MS) {
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
this.lastMessageBySession.set(sessionKey, {
|
|
2040
|
+
message: toast.message,
|
|
2041
|
+
at: this.now()
|
|
2042
|
+
});
|
|
2043
|
+
const nowTs = this.now();
|
|
2044
|
+
if (nowTs - this.emittedAtFor(sessionKey) >= TOAST_MIN_INTERVAL_MS) {
|
|
2045
|
+
this.emitNow(sessionKey, toast, nowTs);
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
let queue = this.queues.get(sessionKey);
|
|
2049
|
+
if (!queue) {
|
|
2050
|
+
queue = [];
|
|
2051
|
+
this.queues.set(sessionKey, queue);
|
|
2052
|
+
}
|
|
2053
|
+
if (goalId) {
|
|
2054
|
+
const staleAt = queue.findIndex((queued) => queued.goalId === goalId);
|
|
2055
|
+
if (staleAt >= 0)
|
|
2056
|
+
queue.splice(staleAt, 1);
|
|
2057
|
+
}
|
|
2058
|
+
queue.push({ ...toast, goalId });
|
|
2059
|
+
if (queue.length > TOAST_QUEUE_MAX) {
|
|
2060
|
+
queue.shift();
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
emittedAtFor(sessionKey) {
|
|
2064
|
+
return this.lastEmittedAt.get(sessionKey) ?? Number.NEGATIVE_INFINITY;
|
|
2065
|
+
}
|
|
2066
|
+
emitNow(sessionKey, toast, nowTs) {
|
|
2067
|
+
let final = toast;
|
|
2068
|
+
if (final.message.length > TOAST_MESSAGE_MAX) {
|
|
2069
|
+
final = {
|
|
2070
|
+
...final,
|
|
2071
|
+
message: `${final.message.slice(0, TOAST_MESSAGE_MAX - 1)}\u2026`
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
this.lastEmittedAt.set(sessionKey, nowTs);
|
|
2075
|
+
const { goalId: _goalId, ...visible } = final;
|
|
2076
|
+
this.emit(visible);
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
// src/tui-v1.ts
|
|
2081
|
+
init_tui_views();
|
|
2082
|
+
|
|
2083
|
+
// src/tui-sound.ts
|
|
2084
|
+
function soundForEvent(kind, status) {
|
|
2085
|
+
switch (kind) {
|
|
2086
|
+
case "create":
|
|
2087
|
+
return "default";
|
|
2088
|
+
case "transition":
|
|
2089
|
+
switch (status) {
|
|
2090
|
+
case "complete":
|
|
2091
|
+
return "done";
|
|
2092
|
+
case "paused":
|
|
2093
|
+
return "question";
|
|
2094
|
+
case "blocked":
|
|
2095
|
+
return "question";
|
|
2096
|
+
case "budgetLimited":
|
|
2097
|
+
return "error";
|
|
2098
|
+
case "active":
|
|
2099
|
+
return "default";
|
|
2100
|
+
case "finalizing":
|
|
2101
|
+
return;
|
|
2102
|
+
default:
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
case "usage":
|
|
2106
|
+
return;
|
|
2107
|
+
case "remove":
|
|
2108
|
+
return;
|
|
2109
|
+
default:
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// src/tui-v1.ts
|
|
2115
|
+
var GOAL_PREFIX = "ctrl+shift+g";
|
|
2116
|
+
function chord(actionKey) {
|
|
2117
|
+
return `${GOAL_PREFIX} ${actionKey}`;
|
|
2118
|
+
}
|
|
2119
|
+
var GoalTuiPlugin = async (api, options, _meta) => {
|
|
2120
|
+
const opts = {
|
|
2121
|
+
logLevel: options?.logLevel ?? "info",
|
|
2122
|
+
directory: options?.directory,
|
|
2123
|
+
stateRoot: options?.stateRoot
|
|
2124
|
+
};
|
|
2125
|
+
const store = createTuiStateStore();
|
|
2126
|
+
const activeSessionID = () => {
|
|
2127
|
+
const route = api.route.current;
|
|
2128
|
+
if (route.name !== "session" || !route.params || typeof route.params.sessionID !== "string") {
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
return route.params.sessionID;
|
|
2132
|
+
};
|
|
2133
|
+
const log = (level, message) => {
|
|
2134
|
+
if (opts.logLevel === "error" && level !== "error")
|
|
2135
|
+
return;
|
|
2136
|
+
if (opts.logLevel === "info" && level === "debug")
|
|
2137
|
+
return;
|
|
2138
|
+
try {
|
|
2139
|
+
if (level === "error") {
|
|
2140
|
+
api.ui.toast({
|
|
2141
|
+
variant: "error",
|
|
2142
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2143
|
+
message,
|
|
2144
|
+
duration: 6000
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
console[level === "error" ? "error" : "log"](`[${GOAL_TUI_EVENT_TITLE}/tui] ${message}`);
|
|
2148
|
+
} catch {}
|
|
2149
|
+
};
|
|
2150
|
+
const degraded = createDegradedModeDetector();
|
|
2151
|
+
const watchdogs = createGoalWatchdogs("v1", (message) => {
|
|
2152
|
+
api.ui.toast({
|
|
2153
|
+
variant: "warning",
|
|
2154
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2155
|
+
message: degraded.checkDispatch() ?? message,
|
|
2156
|
+
duration: 8000
|
|
2157
|
+
});
|
|
2158
|
+
});
|
|
2159
|
+
store.subscribe((event) => {
|
|
2160
|
+
degraded.noteSurfaceAlive();
|
|
2161
|
+
watchdogs.disarmSession(event.sessionID);
|
|
2162
|
+
});
|
|
2163
|
+
const sendGoalCommand = async (command) => {
|
|
2164
|
+
let sessionID = activeSessionID();
|
|
2165
|
+
if (!sessionID) {
|
|
2166
|
+
try {
|
|
2167
|
+
const created = await api.client.session.create({});
|
|
2168
|
+
const data = created ?? {};
|
|
2169
|
+
const newID = typeof data.data?.id === "string" ? data.data.id : typeof data.id === "string" ? data.id : "";
|
|
2170
|
+
if (newID) {
|
|
2171
|
+
sessionID = newID;
|
|
2172
|
+
api.ui.toast({
|
|
2173
|
+
variant: "info",
|
|
2174
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2175
|
+
message: "Started a new session for the goal."
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
} catch {}
|
|
2179
|
+
}
|
|
2180
|
+
if (!sessionID) {
|
|
2181
|
+
api.ui.toast({
|
|
2182
|
+
variant: "warning",
|
|
2183
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2184
|
+
message: "Open a session before controlling a goal."
|
|
2185
|
+
});
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
try {
|
|
2189
|
+
await api.client.session.command({
|
|
2190
|
+
sessionID,
|
|
2191
|
+
command: "goal",
|
|
2192
|
+
arguments: command
|
|
2193
|
+
});
|
|
2194
|
+
if (isMutatingGoalCommand(command)) {
|
|
2195
|
+
watchdogs.arm(sessionID, command);
|
|
2196
|
+
}
|
|
2197
|
+
} catch (error) {
|
|
2198
|
+
api.ui.toast({
|
|
2199
|
+
variant: "error",
|
|
2200
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2201
|
+
message: `Command failed: ${error instanceof Error ? error.message : String(error)}`
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
const getCockpitSnapshots = () => {
|
|
2206
|
+
const sessionID = activeSessionID();
|
|
2207
|
+
let snaps = sessionID ? store.getSnapshots(sessionID) : [];
|
|
2208
|
+
if (snaps.length === 0) {
|
|
2209
|
+
snaps = store.getAllSnapshots().filter((s) => s.origin === "disk");
|
|
2210
|
+
}
|
|
2211
|
+
return snaps;
|
|
2212
|
+
};
|
|
2213
|
+
const dashboardSections = () => {
|
|
2214
|
+
return formatGoalStatusDashboard(getCockpitSnapshots(), activeSessionID());
|
|
2215
|
+
};
|
|
2216
|
+
const dashboardMessage = () => {
|
|
2217
|
+
return dashboardSections().map((section) => `${section.title}
|
|
2218
|
+
${section.text}`).join(`
|
|
2219
|
+
|
|
2220
|
+
`);
|
|
2221
|
+
};
|
|
2222
|
+
const formatGoalDetail = (snap) => {
|
|
2223
|
+
const sections = formatGoalStatusDashboard([snap], activeSessionID());
|
|
2224
|
+
return sections.map((s) => `${s.title}
|
|
2225
|
+
${s.text}`).join(`
|
|
2226
|
+
|
|
2227
|
+
`);
|
|
2228
|
+
};
|
|
2229
|
+
let dashboardUnsubscribe = null;
|
|
2230
|
+
let cockpitGeneration = 0;
|
|
2231
|
+
const cleanupCockpit = () => {
|
|
2232
|
+
if (dashboardUnsubscribe) {
|
|
2233
|
+
try {
|
|
2234
|
+
dashboardUnsubscribe();
|
|
2235
|
+
} catch {}
|
|
2236
|
+
dashboardUnsubscribe = null;
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
const CHAIN_REOPEN_MS = 30;
|
|
2240
|
+
const chainReplace = (render, onClose) => {
|
|
2241
|
+
api.ui.dialog.clear();
|
|
2242
|
+
setTimeout(() => {
|
|
2243
|
+
api.ui.dialog.replace(render, onClose);
|
|
2244
|
+
}, CHAIN_REOPEN_MS);
|
|
2245
|
+
};
|
|
2246
|
+
const showGoalActions = (goalId, gen) => {
|
|
2247
|
+
if (gen !== cockpitGeneration)
|
|
2248
|
+
return;
|
|
2249
|
+
const actions = [
|
|
2250
|
+
{ title: "Pause", value: "pause", description: "Pause this goal" },
|
|
2251
|
+
{ title: "Resume", value: "resume", description: "Resume this goal" },
|
|
2252
|
+
{ title: "Focus", value: "focus", description: "Focus this goal" },
|
|
2253
|
+
{
|
|
2254
|
+
title: "Edit Objective",
|
|
2255
|
+
value: "edit",
|
|
2256
|
+
description: "Change the objective"
|
|
2257
|
+
},
|
|
2258
|
+
{
|
|
2259
|
+
title: "Checkpoint",
|
|
2260
|
+
value: "checkpoint",
|
|
2261
|
+
description: "Save a checkpoint"
|
|
2262
|
+
},
|
|
2263
|
+
{ title: "Clear", value: "clear", description: "Clear this goal" },
|
|
2264
|
+
{
|
|
2265
|
+
title: "\u2190 Back to Goals",
|
|
2266
|
+
value: "back",
|
|
2267
|
+
description: "Return to goal list"
|
|
2268
|
+
}
|
|
2269
|
+
];
|
|
2270
|
+
chainReplace(() => api.ui.DialogSelect({
|
|
2271
|
+
title: `Actions: ${goalId.substring(0, 8)}`,
|
|
2272
|
+
options: actions,
|
|
2273
|
+
onSelect: (option) => {
|
|
2274
|
+
if (gen !== cockpitGeneration)
|
|
2275
|
+
return;
|
|
2276
|
+
switch (option.value) {
|
|
2277
|
+
case "pause":
|
|
2278
|
+
sendGoalCommand(`pause ${goalId}`);
|
|
2279
|
+
api.ui.toast({
|
|
2280
|
+
variant: "info",
|
|
2281
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2282
|
+
message: outcomeNeutralLabel("pause")
|
|
2283
|
+
});
|
|
2284
|
+
showGoalDetail(goalId, gen);
|
|
2285
|
+
break;
|
|
2286
|
+
case "resume":
|
|
2287
|
+
sendGoalCommand(`resume ${goalId}`);
|
|
2288
|
+
api.ui.toast({
|
|
2289
|
+
variant: "info",
|
|
2290
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2291
|
+
message: outcomeNeutralLabel("resume")
|
|
2292
|
+
});
|
|
2293
|
+
showGoalDetail(goalId, gen);
|
|
2294
|
+
break;
|
|
2295
|
+
case "focus":
|
|
2296
|
+
sendGoalCommand(`focus ${goalId}`);
|
|
2297
|
+
api.ui.toast({
|
|
2298
|
+
variant: "info",
|
|
2299
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2300
|
+
message: outcomeNeutralLabel(`focus ${goalId}`)
|
|
2301
|
+
});
|
|
2302
|
+
showGoalDetail(goalId, gen);
|
|
2303
|
+
break;
|
|
2304
|
+
case "edit":
|
|
2305
|
+
chainReplace(() => api.ui.DialogPrompt({
|
|
2306
|
+
title: "Edit Goal",
|
|
2307
|
+
placeholder: "Updated objective",
|
|
2308
|
+
onConfirm: (objective) => {
|
|
2309
|
+
api.ui.dialog.clear();
|
|
2310
|
+
if (!objective) {
|
|
2311
|
+
showGoalActions(goalId, gen);
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
sendGoalCommand(`edit ${goalId} ${objective}`);
|
|
2315
|
+
api.ui.toast({
|
|
2316
|
+
variant: "info",
|
|
2317
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2318
|
+
message: outcomeNeutralLabel("edit")
|
|
2319
|
+
});
|
|
2320
|
+
showGoalDetail(goalId, gen);
|
|
2321
|
+
}
|
|
2322
|
+
}));
|
|
2323
|
+
break;
|
|
2324
|
+
case "checkpoint":
|
|
2325
|
+
chainReplace(() => api.ui.DialogPrompt({
|
|
2326
|
+
title: "Save Checkpoint",
|
|
2327
|
+
placeholder: "Checkpoint summary",
|
|
2328
|
+
onConfirm: (summary) => {
|
|
2329
|
+
api.ui.dialog.clear();
|
|
2330
|
+
if (!summary) {
|
|
2331
|
+
showGoalActions(goalId, gen);
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
sendGoalCommand(`checkpoint ${goalId} ${summary}`);
|
|
2335
|
+
api.ui.toast({
|
|
2336
|
+
variant: "info",
|
|
2337
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2338
|
+
message: outcomeNeutralLabel("checkpoint")
|
|
2339
|
+
});
|
|
2340
|
+
showGoalDetail(goalId, gen);
|
|
2341
|
+
}
|
|
2342
|
+
}));
|
|
2343
|
+
break;
|
|
2344
|
+
case "clear":
|
|
2345
|
+
sendGoalCommand(`clear ${goalId}`);
|
|
2346
|
+
api.ui.toast({
|
|
2347
|
+
variant: "info",
|
|
2348
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2349
|
+
message: outcomeNeutralLabel("clear")
|
|
2350
|
+
});
|
|
2351
|
+
cleanupCockpit();
|
|
2352
|
+
api.ui.dialog.clear();
|
|
2353
|
+
break;
|
|
2354
|
+
case "back":
|
|
2355
|
+
showDashboard();
|
|
2356
|
+
break;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}), () => {
|
|
2360
|
+
if (gen === cockpitGeneration)
|
|
2361
|
+
cleanupCockpit();
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
const showGoalDetail = (goalId, gen) => {
|
|
2365
|
+
if (gen !== cockpitGeneration)
|
|
2366
|
+
return;
|
|
2367
|
+
const snaps = getCockpitSnapshots();
|
|
2368
|
+
const snap = snaps.find((s) => s.goalId === goalId);
|
|
2369
|
+
if (!snap) {
|
|
2370
|
+
showDashboard();
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
chainReplace(() => api.ui.DialogAlert({
|
|
2374
|
+
title: `Goal: ${goalId.substring(0, 8)}`,
|
|
2375
|
+
message: formatGoalDetail(snap),
|
|
2376
|
+
onConfirm: () => {
|
|
2377
|
+
if (gen === cockpitGeneration) {
|
|
2378
|
+
showGoalActions(goalId, gen);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
}), () => {
|
|
2382
|
+
if (gen === cockpitGeneration)
|
|
2383
|
+
cleanupCockpit();
|
|
2384
|
+
});
|
|
2385
|
+
};
|
|
2386
|
+
const renderGoalList = (snaps, gen) => {
|
|
2387
|
+
api.ui.dialog.replace(() => api.ui.DialogSelect({
|
|
2388
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2389
|
+
options: snaps.map((s, idx) => ({
|
|
2390
|
+
...goalListRow(s, idx, activeSessionID()),
|
|
2391
|
+
value: s.goalId
|
|
2392
|
+
})),
|
|
2393
|
+
onSelect: (option) => {
|
|
2394
|
+
if (gen !== cockpitGeneration)
|
|
2395
|
+
return;
|
|
2396
|
+
cleanupCockpit();
|
|
2397
|
+
showGoalDetail(option.value, gen);
|
|
2398
|
+
}
|
|
2399
|
+
}), () => {
|
|
2400
|
+
if (gen === cockpitGeneration)
|
|
2401
|
+
cleanupCockpit();
|
|
2402
|
+
});
|
|
2403
|
+
};
|
|
2404
|
+
const showDashboard = () => {
|
|
2405
|
+
cockpitGeneration++;
|
|
2406
|
+
const gen = cockpitGeneration;
|
|
2407
|
+
cleanupCockpit();
|
|
2408
|
+
const snaps = getCockpitSnapshots();
|
|
2409
|
+
if (snaps.length === 0) {
|
|
2410
|
+
api.ui.dialog.replace(() => api.ui.DialogAlert({
|
|
2411
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2412
|
+
message: dashboardMessage(),
|
|
2413
|
+
onConfirm: () => {
|
|
2414
|
+
cleanupCockpit();
|
|
2415
|
+
api.ui.dialog.clear();
|
|
2416
|
+
}
|
|
2417
|
+
}), () => cleanupCockpit());
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
renderGoalList(snaps, gen);
|
|
2421
|
+
dashboardUnsubscribe = store.subscribe(() => {
|
|
2422
|
+
if (gen !== cockpitGeneration)
|
|
2423
|
+
return;
|
|
2424
|
+
const currentSnaps = getCockpitSnapshots();
|
|
2425
|
+
if (currentSnaps.length === 0) {
|
|
2426
|
+
api.ui.dialog.replace(() => api.ui.DialogAlert({
|
|
2427
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2428
|
+
message: "No active goals.",
|
|
2429
|
+
onConfirm: () => {
|
|
2430
|
+
cleanupCockpit();
|
|
2431
|
+
api.ui.dialog.clear();
|
|
2432
|
+
}
|
|
2433
|
+
}), () => cleanupCockpit());
|
|
2434
|
+
return;
|
|
2435
|
+
}
|
|
2436
|
+
renderGoalList(currentSnaps, gen);
|
|
2437
|
+
});
|
|
2438
|
+
};
|
|
2439
|
+
const paletteTarget = () => {
|
|
2440
|
+
const sessionID = activeSessionID();
|
|
2441
|
+
if (sessionID === null)
|
|
2442
|
+
return { refusal: "Open a session before controlling a goal." };
|
|
2443
|
+
const snaps = store.getSnapshots(sessionID);
|
|
2444
|
+
if (snaps.length === 0)
|
|
2445
|
+
return { refusal: "This session has no goals." };
|
|
2446
|
+
const goalId = resolveFocusedGoalId(store, sessionID);
|
|
2447
|
+
if (goalId === null)
|
|
2448
|
+
return { refusal: "This session has no goals." };
|
|
2449
|
+
return { goalId };
|
|
2450
|
+
};
|
|
2451
|
+
const refuseWithReason = (refusal) => {
|
|
2452
|
+
api.ui.toast({
|
|
2453
|
+
variant: "warning",
|
|
2454
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2455
|
+
message: refusal
|
|
2456
|
+
});
|
|
2457
|
+
};
|
|
2458
|
+
const handlePause = () => {
|
|
2459
|
+
const target = paletteTarget();
|
|
2460
|
+
if ("refusal" in target) {
|
|
2461
|
+
refuseWithReason(target.refusal);
|
|
2462
|
+
return;
|
|
2463
|
+
}
|
|
2464
|
+
sendGoalCommand(`pause ${target.goalId}`);
|
|
2465
|
+
api.ui.toast({
|
|
2466
|
+
variant: "info",
|
|
2467
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2468
|
+
message: outcomeNeutralLabel("pause")
|
|
2469
|
+
});
|
|
2470
|
+
};
|
|
2471
|
+
const handleResume = () => {
|
|
2472
|
+
const target = paletteTarget();
|
|
2473
|
+
if ("refusal" in target) {
|
|
2474
|
+
refuseWithReason(target.refusal);
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
sendGoalCommand(`resume ${target.goalId}`);
|
|
2478
|
+
api.ui.toast({
|
|
2479
|
+
variant: "info",
|
|
2480
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2481
|
+
message: outcomeNeutralLabel("resume")
|
|
2482
|
+
});
|
|
2483
|
+
};
|
|
2484
|
+
const handleClear = () => {
|
|
2485
|
+
const target = paletteTarget();
|
|
2486
|
+
if ("refusal" in target) {
|
|
2487
|
+
refuseWithReason(target.refusal);
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
sendGoalCommand(`clear ${target.goalId}`);
|
|
2491
|
+
api.ui.toast({
|
|
2492
|
+
variant: "info",
|
|
2493
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2494
|
+
message: outcomeNeutralLabel("clear")
|
|
2495
|
+
});
|
|
2496
|
+
};
|
|
2497
|
+
const handleEdit = () => {
|
|
2498
|
+
const target = paletteTarget();
|
|
2499
|
+
if ("refusal" in target) {
|
|
2500
|
+
refuseWithReason(target.refusal);
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
const goalId = target.goalId;
|
|
2504
|
+
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
2505
|
+
title: "Edit Goal",
|
|
2506
|
+
placeholder: "Updated objective",
|
|
2507
|
+
onConfirm: (objective) => {
|
|
2508
|
+
api.ui.dialog.clear();
|
|
2509
|
+
if (!objective)
|
|
2510
|
+
return;
|
|
2511
|
+
sendGoalCommand(`edit ${goalId} ${objective}`);
|
|
2512
|
+
api.ui.toast({
|
|
2513
|
+
variant: "info",
|
|
2514
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2515
|
+
message: outcomeNeutralLabel("edit")
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
}));
|
|
2519
|
+
};
|
|
2520
|
+
const handleCheckpoint = () => {
|
|
2521
|
+
const target = paletteTarget();
|
|
2522
|
+
if ("refusal" in target) {
|
|
2523
|
+
refuseWithReason(target.refusal);
|
|
2524
|
+
return;
|
|
2525
|
+
}
|
|
2526
|
+
const goalId = target.goalId;
|
|
2527
|
+
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
2528
|
+
title: "Save Checkpoint",
|
|
2529
|
+
placeholder: "Checkpoint summary",
|
|
2530
|
+
onConfirm: (summary) => {
|
|
2531
|
+
api.ui.dialog.clear();
|
|
2532
|
+
if (!summary)
|
|
2533
|
+
return;
|
|
2534
|
+
sendGoalCommand(`checkpoint ${goalId} ${summary}`);
|
|
2535
|
+
api.ui.toast({
|
|
2536
|
+
variant: "info",
|
|
2537
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2538
|
+
message: outcomeNeutralLabel("checkpoint")
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
}));
|
|
2542
|
+
};
|
|
2543
|
+
const unregisterCommands = api.keymap.registerLayer({
|
|
2544
|
+
commands: [
|
|
2545
|
+
{
|
|
2546
|
+
name: "fixate-on.dashboard",
|
|
2547
|
+
namespace: "palette",
|
|
2548
|
+
slashName: "goal-dashboard",
|
|
2549
|
+
title: `${PRODUCT_DISPLAY_NAME}: Dashboard`,
|
|
2550
|
+
description: "Open the live goal dashboard (goal status, tokens, turns)",
|
|
2551
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2552
|
+
run: showDashboard
|
|
2553
|
+
},
|
|
2554
|
+
{
|
|
2555
|
+
name: "fixate-on.pause",
|
|
2556
|
+
namespace: "palette",
|
|
2557
|
+
slashName: "goal-pause",
|
|
2558
|
+
title: `${PRODUCT_DISPLAY_NAME}: Pause Goal`,
|
|
2559
|
+
description: "Pause the active goal",
|
|
2560
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2561
|
+
run: handlePause
|
|
2562
|
+
},
|
|
2563
|
+
{
|
|
2564
|
+
name: "fixate-on.resume",
|
|
2565
|
+
namespace: "palette",
|
|
2566
|
+
slashName: "goal-resume",
|
|
2567
|
+
title: `${PRODUCT_DISPLAY_NAME}: Resume Goal`,
|
|
2568
|
+
description: "Resume a paused goal",
|
|
2569
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2570
|
+
run: handleResume
|
|
2571
|
+
},
|
|
2572
|
+
{
|
|
2573
|
+
name: "fixate-on.clear",
|
|
2574
|
+
namespace: "palette",
|
|
2575
|
+
slashName: "goal-clear",
|
|
2576
|
+
title: `${PRODUCT_DISPLAY_NAME}: Clear Goals`,
|
|
2577
|
+
description: "Clear active goal(s)",
|
|
2578
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2579
|
+
run: handleClear
|
|
2580
|
+
},
|
|
2581
|
+
{
|
|
2582
|
+
name: "fixate-on.edit",
|
|
2583
|
+
namespace: "palette",
|
|
2584
|
+
slashName: "goal-edit",
|
|
2585
|
+
title: `${PRODUCT_DISPLAY_NAME}: Edit Objective`,
|
|
2586
|
+
description: "Edit objective of the active goal",
|
|
2587
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2588
|
+
run: handleEdit
|
|
2589
|
+
},
|
|
2590
|
+
{
|
|
2591
|
+
name: "fixate-on.checkpoint",
|
|
2592
|
+
namespace: "palette",
|
|
2593
|
+
slashName: "goal-checkpoint",
|
|
2594
|
+
title: `${PRODUCT_DISPLAY_NAME}: Save Checkpoint`,
|
|
2595
|
+
description: "Save a checkpoint for the active goal",
|
|
2596
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2597
|
+
run: handleCheckpoint
|
|
2598
|
+
},
|
|
2599
|
+
{
|
|
2600
|
+
name: "fixate-on.list",
|
|
2601
|
+
namespace: "palette",
|
|
2602
|
+
slashName: "goal-list",
|
|
2603
|
+
title: `${PRODUCT_DISPLAY_NAME}: List Goals`,
|
|
2604
|
+
description: "List all active and archived goals",
|
|
2605
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2606
|
+
run: () => {
|
|
2607
|
+
sendGoalCommand("list");
|
|
2608
|
+
}
|
|
2609
|
+
},
|
|
2610
|
+
{
|
|
2611
|
+
name: "fixate-on.history",
|
|
2612
|
+
namespace: "palette",
|
|
2613
|
+
slashName: "goal-history",
|
|
2614
|
+
title: `${PRODUCT_DISPLAY_NAME}: Show History`,
|
|
2615
|
+
description: "Show goal history and transition log",
|
|
2616
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2617
|
+
run: () => {
|
|
2618
|
+
sendGoalCommand("history");
|
|
2619
|
+
}
|
|
2620
|
+
},
|
|
2621
|
+
{
|
|
2622
|
+
name: "fixate-on.focus",
|
|
2623
|
+
namespace: "palette",
|
|
2624
|
+
slashName: "goal-focus",
|
|
2625
|
+
title: `${PRODUCT_DISPLAY_NAME}: Focus Goal`,
|
|
2626
|
+
description: "Focus a specific goal in the session",
|
|
2627
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2628
|
+
run: () => {
|
|
2629
|
+
const sessionID = activeSessionID();
|
|
2630
|
+
const goals = sessionID ? store.getSnapshots(sessionID) : [];
|
|
2631
|
+
if (goals.length === 0) {
|
|
2632
|
+
api.ui.toast({
|
|
2633
|
+
variant: "warning",
|
|
2634
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2635
|
+
message: "No active goals to focus."
|
|
2636
|
+
});
|
|
2637
|
+
return;
|
|
2638
|
+
}
|
|
2639
|
+
api.ui.dialog.replace(() => api.ui.DialogSelect({
|
|
2640
|
+
title: "Focus Goal",
|
|
2641
|
+
options: goals.map((g, idx) => ({
|
|
2642
|
+
title: `${idx + 1}. ${g.condition}`,
|
|
2643
|
+
value: g.goalId,
|
|
2644
|
+
description: `Status: ${g.status}`
|
|
2645
|
+
})),
|
|
2646
|
+
onSelect: (option) => {
|
|
2647
|
+
api.ui.dialog.clear();
|
|
2648
|
+
sendGoalCommand(`focus ${option.value}`);
|
|
2649
|
+
api.ui.toast({
|
|
2650
|
+
variant: "info",
|
|
2651
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2652
|
+
message: outcomeNeutralLabel(`focus ${option.value}`)
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
}));
|
|
2656
|
+
}
|
|
2657
|
+
},
|
|
2658
|
+
{
|
|
2659
|
+
name: "fixate-on.add",
|
|
2660
|
+
namespace: "palette",
|
|
2661
|
+
slashName: "goal-add",
|
|
2662
|
+
title: `${PRODUCT_DISPLAY_NAME}: Add Goal`,
|
|
2663
|
+
description: "Add a new goal to the session",
|
|
2664
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2665
|
+
run: () => {
|
|
2666
|
+
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
2667
|
+
title: "Add New Goal",
|
|
2668
|
+
placeholder: "New goal objective",
|
|
2669
|
+
onConfirm: (objective) => {
|
|
2670
|
+
api.ui.dialog.clear();
|
|
2671
|
+
if (!objective)
|
|
2672
|
+
return;
|
|
2673
|
+
sendGoalCommand(`add ${objective}`);
|
|
2674
|
+
api.ui.toast({
|
|
2675
|
+
variant: "info",
|
|
2676
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2677
|
+
message: outcomeNeutralLabel("add")
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
}));
|
|
2681
|
+
}
|
|
2682
|
+
},
|
|
2683
|
+
{
|
|
2684
|
+
name: "fixate-on.sequence",
|
|
2685
|
+
namespace: "palette",
|
|
2686
|
+
slashName: "goal-sequence",
|
|
2687
|
+
title: `${PRODUCT_DISPLAY_NAME}: Start Sequence`,
|
|
2688
|
+
description: "Start an ordered sequence of goals",
|
|
2689
|
+
category: PRODUCT_DISPLAY_NAME,
|
|
2690
|
+
run: () => {
|
|
2691
|
+
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
2692
|
+
title: "Start Goal Sequence",
|
|
2693
|
+
placeholder: "Objective 1; Objective 2; Objective 3",
|
|
2694
|
+
onConfirm: (text) => {
|
|
2695
|
+
api.ui.dialog.clear();
|
|
2696
|
+
if (!text)
|
|
2697
|
+
return;
|
|
2698
|
+
sendGoalCommand(`sequence ${text}`);
|
|
2699
|
+
api.ui.toast({
|
|
2700
|
+
variant: "info",
|
|
2701
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2702
|
+
message: outcomeNeutralLabel("sequence")
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
}));
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
],
|
|
2709
|
+
bindings: [
|
|
2710
|
+
{ key: chord("d"), cmd: "fixate-on.dashboard" },
|
|
2711
|
+
{ key: chord("p"), cmd: "fixate-on.pause" },
|
|
2712
|
+
{ key: chord("r"), cmd: "fixate-on.resume" },
|
|
2713
|
+
{ key: chord("c"), cmd: "fixate-on.clear" },
|
|
2714
|
+
{ key: chord("e"), cmd: "fixate-on.edit" },
|
|
2715
|
+
{ key: chord("k"), cmd: "fixate-on.checkpoint" }
|
|
2716
|
+
]
|
|
2717
|
+
});
|
|
2718
|
+
log("info", "TUI companion initialized \u2014 subscribing to goal events.");
|
|
2719
|
+
const playSound = (kind, status) => {
|
|
2720
|
+
const soundName = soundForEvent(kind, status);
|
|
2721
|
+
if (!soundName)
|
|
2722
|
+
return;
|
|
2723
|
+
try {
|
|
2724
|
+
Promise.resolve(api.attention.notify({
|
|
2725
|
+
message: `Goal ${kind}${status ? ` \u2192 ${status}` : ""}`,
|
|
2726
|
+
sound: { name: soundName, when: "always" },
|
|
2727
|
+
notification: false
|
|
2728
|
+
})).catch(() => {});
|
|
2729
|
+
} catch {}
|
|
2730
|
+
};
|
|
2731
|
+
const coalescer = new ToastCoalescer((toast) => {
|
|
2732
|
+
try {
|
|
2733
|
+
api.ui.toast({
|
|
2734
|
+
variant: toast.variant,
|
|
2735
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
2736
|
+
message: toast.message,
|
|
2737
|
+
duration: 5000
|
|
2738
|
+
});
|
|
2739
|
+
} catch {}
|
|
2740
|
+
}, Date.now, 500);
|
|
2741
|
+
coalescer.startAutoFlush();
|
|
2742
|
+
const refreshLoop = createDiskRefreshLoop({
|
|
2743
|
+
directory: opts.directory,
|
|
2744
|
+
stateRoot: opts.stateRoot,
|
|
2745
|
+
store,
|
|
2746
|
+
intervalMs: 1000,
|
|
2747
|
+
onEvent: (event) => {
|
|
2748
|
+
playSound(event.kind, event.snapshot?.status);
|
|
2749
|
+
coalescer.accept(event, event.sessionID);
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
let disposed = false;
|
|
2753
|
+
api.lifecycle.onDispose(() => {
|
|
2754
|
+
disposed = true;
|
|
2755
|
+
unregisterCommands();
|
|
2756
|
+
coalescer.stopAutoFlush();
|
|
2757
|
+
refreshLoop.stop();
|
|
2758
|
+
if (dashboardUnsubscribe) {
|
|
2759
|
+
try {
|
|
2760
|
+
dashboardUnsubscribe();
|
|
2761
|
+
} catch {}
|
|
2762
|
+
dashboardUnsubscribe = null;
|
|
2763
|
+
}
|
|
2764
|
+
log("info", "TUI companion disposed.");
|
|
2765
|
+
});
|
|
2766
|
+
await refreshLoop.tick();
|
|
2767
|
+
if (!disposed) {
|
|
2768
|
+
const snapshots = refreshLoop.getSnapshots();
|
|
2769
|
+
log("info", `Hydrated ${snapshots.length} goal(s) from persisted state.`);
|
|
2770
|
+
refreshLoop.start();
|
|
2771
|
+
const briefing = summarizeGoalsNeedingYou(snapshots);
|
|
2772
|
+
if (briefing) {
|
|
2773
|
+
log("info", `Briefing: ${briefing.message}`);
|
|
2774
|
+
coalescer.brief(BRIEFING_SESSION_KEY, briefing);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
};
|
|
2778
|
+
|
|
2779
|
+
// src/tui-v2.ts
|
|
2780
|
+
init_tui_views();
|
|
2781
|
+
|
|
2782
|
+
// src/tui-dashboard-route.tsx
|
|
2783
|
+
init_tui_views();
|
|
2784
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
2785
|
+
import { effect as _$effect } from "@opentui/solid";
|
|
2786
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
2787
|
+
import { use as _$use } from "@opentui/solid";
|
|
2788
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
2789
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
2790
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
2791
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
2792
|
+
import { createMemo } from "solid-js";
|
|
2793
|
+
var STATUS_LINE = 1;
|
|
2794
|
+
function resolveDashboardPalette(theme) {
|
|
2795
|
+
const text = theme.text?.base;
|
|
2796
|
+
const muted = theme.text?.muted ?? theme.text?.faint ?? text;
|
|
2797
|
+
const fb = theme.text?.feedback;
|
|
2798
|
+
return {
|
|
2799
|
+
text,
|
|
2800
|
+
muted,
|
|
2801
|
+
panel: theme.background?.raised?.base ?? theme.background?.base,
|
|
2802
|
+
background: theme.background?.base,
|
|
2803
|
+
border: theme.border?.base,
|
|
2804
|
+
accent: theme.hue?.accent?.[500] ?? theme.text?.base,
|
|
2805
|
+
scrollbar: theme.scrollbar?.base ?? theme.border?.base,
|
|
2806
|
+
status: {
|
|
2807
|
+
active: fb?.success?.base ?? text,
|
|
2808
|
+
paused: fb?.warning?.base ?? text,
|
|
2809
|
+
blocked: fb?.error?.base ?? text,
|
|
2810
|
+
complete: muted,
|
|
2811
|
+
default: text
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2815
|
+
function createScrollHandlers(getEl) {
|
|
2816
|
+
const safeScrollBy = (el, n) => {
|
|
2817
|
+
try {
|
|
2818
|
+
el?.scrollBy(n);
|
|
2819
|
+
} catch {}
|
|
2820
|
+
};
|
|
2821
|
+
const byLines = (n) => safeScrollBy(getEl(), n);
|
|
2822
|
+
const page = (dir) => {
|
|
2823
|
+
const h = getEl()?.viewport?.height;
|
|
2824
|
+
const page = h !== undefined && h > 0 && Number.isFinite(h) ? h : 10;
|
|
2825
|
+
safeScrollBy(getEl(), dir * Math.max(1, Math.floor(page / 2)));
|
|
2826
|
+
};
|
|
2827
|
+
return {
|
|
2828
|
+
up: () => byLines(-1),
|
|
2829
|
+
down: () => byLines(1),
|
|
2830
|
+
pageUp: () => page(-1),
|
|
2831
|
+
pageDown: () => page(1)
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
function goalCardBoxStyle(isFocused, palette) {
|
|
2835
|
+
return {
|
|
2836
|
+
border: true,
|
|
2837
|
+
borderStyle: isFocused ? "rounded" : "single",
|
|
2838
|
+
borderColor: isFocused ? palette.accent ?? palette.border : palette.border,
|
|
2839
|
+
backgroundColor: isFocused ? palette.panel : undefined
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
function DashboardRoute(props) {
|
|
2843
|
+
const palette = createMemo(() => resolveDashboardPalette(typeof props.theme === "function" ? props.theme() : props.theme));
|
|
2844
|
+
const snaps = props.snapshots;
|
|
2845
|
+
const focused = props.focusedGoalId;
|
|
2846
|
+
let scrollEl = null;
|
|
2847
|
+
const handlers = createScrollHandlers(() => scrollEl);
|
|
2848
|
+
props.registerScrollCommands?.(handlers);
|
|
2849
|
+
return (() => {
|
|
2850
|
+
var _el$ = _$createElement("box"), _el$2 = _$createElement("box"), _el$3 = _$createElement("text"), _el$4 = _$createElement("scrollbox"), _el$5 = _$createElement("box"), _el$6 = _$createElement("text");
|
|
2851
|
+
_$insertNode(_el$, _el$2);
|
|
2852
|
+
_$insertNode(_el$, _el$4);
|
|
2853
|
+
_$insertNode(_el$, _el$5);
|
|
2854
|
+
_$setProp(_el$, "flexDirection", "column");
|
|
2855
|
+
_$setProp(_el$, "width", "100%");
|
|
2856
|
+
_$setProp(_el$, "height", "100%");
|
|
2857
|
+
_$insertNode(_el$2, _el$3);
|
|
2858
|
+
_$setProp(_el$2, "flexShrink", 0);
|
|
2859
|
+
_$setProp(_el$2, "paddingLeft", 1);
|
|
2860
|
+
_$setProp(_el$2, "paddingRight", 1);
|
|
2861
|
+
_$setProp(_el$3, "attributes", 1);
|
|
2862
|
+
_$insert(_el$3, PRODUCT_DISPLAY_NAME);
|
|
2863
|
+
_$use((el) => {
|
|
2864
|
+
scrollEl = el;
|
|
2865
|
+
}, _el$4);
|
|
2866
|
+
_$setProp(_el$4, "flexGrow", 1);
|
|
2867
|
+
_$setProp(_el$4, "minHeight", 0);
|
|
2868
|
+
_$setProp(_el$4, "flexDirection", "column");
|
|
2869
|
+
_$setProp(_el$4, "paddingLeft", 1);
|
|
2870
|
+
_$setProp(_el$4, "paddingRight", 1);
|
|
2871
|
+
_$insert(_el$4, (() => {
|
|
2872
|
+
var _c$ = _$memo(() => snaps().length === 0);
|
|
2873
|
+
return () => _c$() ? (() => {
|
|
2874
|
+
var _el$7 = _$createElement("box"), _el$8 = _$createElement("text");
|
|
2875
|
+
_$insertNode(_el$7, _el$8);
|
|
2876
|
+
_$setProp(_el$7, "paddingLeft", 1);
|
|
2877
|
+
_$setProp(_el$7, "paddingRight", 1);
|
|
2878
|
+
_$setProp(_el$7, "paddingTop", 1);
|
|
2879
|
+
_$insert(_el$8, () => props.hydrationText ?? "No active goals. Use /goal <condition> to set one.");
|
|
2880
|
+
_$effect((_$p) => _$setProp(_el$8, "fg", palette().muted, _$p));
|
|
2881
|
+
return _el$7;
|
|
2882
|
+
})() : snaps().map((snap) => {
|
|
2883
|
+
const isFocused = snap.goalId === focused();
|
|
2884
|
+
const cardStyle = goalCardBoxStyle(isFocused, palette());
|
|
2885
|
+
return (() => {
|
|
2886
|
+
var _el$9 = _$createElement("box"), _el$0 = _$createElement("box"), _el$1 = _$createElement("text"), _el$10 = _$createTextNode(`Goal: `), _el$11 = _$createElement("box");
|
|
2887
|
+
_$insertNode(_el$9, _el$0);
|
|
2888
|
+
_$insertNode(_el$9, _el$11);
|
|
2889
|
+
_$setProp(_el$9, "flexDirection", "column");
|
|
2890
|
+
_$setProp(_el$9, "paddingBottom", 1);
|
|
2891
|
+
_$setProp(_el$9, "onMouseUp", () => props.onSelectGoal(snap.goalId));
|
|
2892
|
+
_$insertNode(_el$0, _el$1);
|
|
2893
|
+
_$setProp(_el$0, "paddingLeft", 1);
|
|
2894
|
+
_$setProp(_el$0, "paddingRight", 1);
|
|
2895
|
+
_$setProp(_el$0, "flexDirection", "row");
|
|
2896
|
+
_$insertNode(_el$1, _el$10);
|
|
2897
|
+
_$setProp(_el$1, "attributes", 1);
|
|
2898
|
+
_$insert(_el$1, isFocused ? "\u25B8 " : " ", _el$10);
|
|
2899
|
+
_$insert(_el$1, () => snap.goalId.substring(0, 8), null);
|
|
2900
|
+
_$setProp(_el$11, "paddingLeft", 1);
|
|
2901
|
+
_$setProp(_el$11, "paddingRight", 1);
|
|
2902
|
+
_$setProp(_el$11, "flexDirection", "column");
|
|
2903
|
+
_$insert(_el$11, () => goalCardLines(snap, props.activeSessionID()).map((line, i) => (() => {
|
|
2904
|
+
var _el$12 = _$createElement("text");
|
|
2905
|
+
_$insert(_el$12, () => line.text);
|
|
2906
|
+
_$effect((_$p) => _$setProp(_el$12, "fg", cardLineColor(line, i, snap.status, palette()), _$p));
|
|
2907
|
+
return _el$12;
|
|
2908
|
+
})()));
|
|
2909
|
+
_$effect((_p$) => {
|
|
2910
|
+
var { backgroundColor: _v$7, border: _v$8, borderStyle: _v$9, borderColor: _v$0 } = cardStyle, _v$1 = palette().accent;
|
|
2911
|
+
_v$7 !== _p$.e && (_p$.e = _$setProp(_el$9, "backgroundColor", _v$7, _p$.e));
|
|
2912
|
+
_v$8 !== _p$.t && (_p$.t = _$setProp(_el$9, "border", _v$8, _p$.t));
|
|
2913
|
+
_v$9 !== _p$.a && (_p$.a = _$setProp(_el$9, "borderStyle", _v$9, _p$.a));
|
|
2914
|
+
_v$0 !== _p$.o && (_p$.o = _$setProp(_el$9, "borderColor", _v$0, _p$.o));
|
|
2915
|
+
_v$1 !== _p$.i && (_p$.i = _$setProp(_el$1, "fg", _v$1, _p$.i));
|
|
2916
|
+
return _p$;
|
|
2917
|
+
}, {
|
|
2918
|
+
e: undefined,
|
|
2919
|
+
t: undefined,
|
|
2920
|
+
a: undefined,
|
|
2921
|
+
o: undefined,
|
|
2922
|
+
i: undefined
|
|
2923
|
+
});
|
|
2924
|
+
return _el$9;
|
|
2925
|
+
})();
|
|
2926
|
+
});
|
|
2927
|
+
})(), null);
|
|
2928
|
+
_$insert(_el$4, () => props.sections().map((section) => (() => {
|
|
2929
|
+
var _el$13 = _$createElement("box"), _el$14 = _$createElement("box"), _el$15 = _$createElement("text"), _el$16 = _$createElement("box");
|
|
2930
|
+
_$insertNode(_el$13, _el$14);
|
|
2931
|
+
_$insertNode(_el$13, _el$16);
|
|
2932
|
+
_$setProp(_el$13, "flexDirection", "column");
|
|
2933
|
+
_$setProp(_el$13, "paddingBottom", 1);
|
|
2934
|
+
_$insertNode(_el$14, _el$15);
|
|
2935
|
+
_$setProp(_el$14, "paddingLeft", 1);
|
|
2936
|
+
_$setProp(_el$14, "paddingRight", 1);
|
|
2937
|
+
_$insert(_el$15, () => section.title);
|
|
2938
|
+
_$setProp(_el$16, "paddingLeft", 1);
|
|
2939
|
+
_$setProp(_el$16, "paddingRight", 1);
|
|
2940
|
+
_$setProp(_el$16, "flexDirection", "column");
|
|
2941
|
+
_$insert(_el$16, () => section.text.split(`
|
|
2942
|
+
`).map((line) => (() => {
|
|
2943
|
+
var _el$17 = _$createElement("text");
|
|
2944
|
+
_$insert(_el$17, line);
|
|
2945
|
+
_$effect((_$p) => _$setProp(_el$17, "fg", palette().text, _$p));
|
|
2946
|
+
return _el$17;
|
|
2947
|
+
})()));
|
|
2948
|
+
_$effect((_p$) => {
|
|
2949
|
+
var _v$10 = palette().panel, _v$11 = palette().accent;
|
|
2950
|
+
_v$10 !== _p$.e && (_p$.e = _$setProp(_el$14, "backgroundColor", _v$10, _p$.e));
|
|
2951
|
+
_v$11 !== _p$.t && (_p$.t = _$setProp(_el$15, "fg", _v$11, _p$.t));
|
|
2952
|
+
return _p$;
|
|
2953
|
+
}, {
|
|
2954
|
+
e: undefined,
|
|
2955
|
+
t: undefined
|
|
2956
|
+
});
|
|
2957
|
+
return _el$13;
|
|
2958
|
+
})()), null);
|
|
2959
|
+
_$insertNode(_el$5, _el$6);
|
|
2960
|
+
_$setProp(_el$5, "flexShrink", 0);
|
|
2961
|
+
_$setProp(_el$5, "paddingLeft", 1);
|
|
2962
|
+
_$setProp(_el$5, "paddingRight", 1);
|
|
2963
|
+
_$setProp(_el$5, "flexDirection", "row");
|
|
2964
|
+
_$insert(_el$6, () => props.footer);
|
|
2965
|
+
_$effect((_p$) => {
|
|
2966
|
+
var _v$ = palette().background, _v$2 = palette().panel, _v$3 = palette().accent, _v$4 = {
|
|
2967
|
+
visible: true,
|
|
2968
|
+
trackOptions: {
|
|
2969
|
+
backgroundColor: palette().background,
|
|
2970
|
+
foregroundColor: palette().scrollbar
|
|
2971
|
+
}
|
|
2972
|
+
}, _v$5 = palette().panel, _v$6 = palette().muted;
|
|
2973
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$, "backgroundColor", _v$, _p$.e));
|
|
2974
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$2, "backgroundColor", _v$2, _p$.t));
|
|
2975
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp(_el$3, "fg", _v$3, _p$.a));
|
|
2976
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp(_el$4, "verticalScrollbarOptions", _v$4, _p$.o));
|
|
2977
|
+
_v$5 !== _p$.i && (_p$.i = _$setProp(_el$5, "backgroundColor", _v$5, _p$.i));
|
|
2978
|
+
_v$6 !== _p$.n && (_p$.n = _$setProp(_el$6, "fg", _v$6, _p$.n));
|
|
2979
|
+
return _p$;
|
|
2980
|
+
}, {
|
|
2981
|
+
e: undefined,
|
|
2982
|
+
t: undefined,
|
|
2983
|
+
a: undefined,
|
|
2984
|
+
o: undefined,
|
|
2985
|
+
i: undefined,
|
|
2986
|
+
n: undefined
|
|
2987
|
+
});
|
|
2988
|
+
return _el$;
|
|
2989
|
+
})();
|
|
2990
|
+
}
|
|
2991
|
+
function cardLineColor(line, index, status, palette) {
|
|
2992
|
+
if (index === STATUS_LINE)
|
|
2993
|
+
return palette.status[status] ?? palette.status.default;
|
|
2994
|
+
return line.subdued ? palette.muted : palette.text;
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
// src/tui-v2.ts
|
|
2998
|
+
import { createSignal, onCleanup as onCleanup2 } from "solid-js";
|
|
2999
|
+
// src/state-root-rpc.ts
|
|
3000
|
+
var GOAL_STATE_ROOT_RPC = {
|
|
3001
|
+
id: "fixate-on-state",
|
|
3002
|
+
methods: {
|
|
3003
|
+
root: {
|
|
3004
|
+
input: { type: "object", properties: {}, additionalProperties: false },
|
|
3005
|
+
output: {
|
|
3006
|
+
type: "object",
|
|
3007
|
+
properties: { stateRoot: { type: "string", minLength: 1 } },
|
|
3008
|
+
required: ["stateRoot"],
|
|
3009
|
+
additionalProperties: false
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
},
|
|
3013
|
+
events: {
|
|
3014
|
+
changed: {
|
|
3015
|
+
schema: {
|
|
3016
|
+
type: "object",
|
|
3017
|
+
properties: { stateRoot: { type: "string", minLength: 1 } },
|
|
3018
|
+
required: ["stateRoot"],
|
|
3019
|
+
additionalProperties: false
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
var GOAL_STATE_ROOT_CHANGED = `rpc.${GOAL_STATE_ROOT_RPC.id}.changed`;
|
|
3025
|
+
async function registerStateRootRpc(rpc, stateRoot) {
|
|
3026
|
+
if (!rpc || !stateRoot || stateRoot.trim().length === 0) {
|
|
3027
|
+
return async () => {};
|
|
3028
|
+
}
|
|
3029
|
+
let registration;
|
|
3030
|
+
try {
|
|
3031
|
+
registration = await rpc.register(GOAL_STATE_ROOT_RPC, {
|
|
3032
|
+
root: async () => ({ stateRoot })
|
|
3033
|
+
});
|
|
3034
|
+
} catch {
|
|
3035
|
+
return async () => {};
|
|
3036
|
+
}
|
|
3037
|
+
try {
|
|
3038
|
+
await registration.events?.emit("changed", { stateRoot });
|
|
3039
|
+
} catch {}
|
|
3040
|
+
return async () => {
|
|
3041
|
+
await registration.dispose();
|
|
3042
|
+
};
|
|
3043
|
+
}
|
|
3044
|
+
function parseStateRootReply(value) {
|
|
3045
|
+
if (!value || typeof value !== "object")
|
|
3046
|
+
return;
|
|
3047
|
+
const { stateRoot } = value;
|
|
3048
|
+
return typeof stateRoot === "string" && stateRoot.trim().length > 0 ? stateRoot : undefined;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
// src/tui-v2-events.ts
|
|
3052
|
+
function wireV2Events(args) {
|
|
3053
|
+
const {
|
|
3054
|
+
context,
|
|
3055
|
+
store,
|
|
3056
|
+
stateRoots,
|
|
3057
|
+
resolveWorkspaceDir,
|
|
3058
|
+
disarmWatchdogs,
|
|
3059
|
+
log
|
|
3060
|
+
} = args;
|
|
3061
|
+
const playSound = (kind, status) => {
|
|
3062
|
+
const name = soundForEvent(kind, status);
|
|
3063
|
+
if (!name)
|
|
3064
|
+
return;
|
|
3065
|
+
try {
|
|
3066
|
+
context.attention.notify({
|
|
3067
|
+
message: `Goal ${kind}${status ? ` \u2192 ${status}` : ""}`,
|
|
3068
|
+
sound: { name, when: "always" },
|
|
3069
|
+
notification: false
|
|
3070
|
+
}).catch(() => {});
|
|
3071
|
+
} catch {}
|
|
3072
|
+
};
|
|
3073
|
+
let disposed = false;
|
|
3074
|
+
const coalescer = new ToastCoalescer((toast) => {
|
|
3075
|
+
try {
|
|
3076
|
+
context.ui.toast.show({
|
|
3077
|
+
variant: toast.variant,
|
|
3078
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3079
|
+
message: toast.message,
|
|
3080
|
+
duration: 5000
|
|
3081
|
+
});
|
|
3082
|
+
} catch {}
|
|
3083
|
+
}, Date.now, 500);
|
|
3084
|
+
coalescer.startAutoFlush();
|
|
3085
|
+
let briefingFired = false;
|
|
3086
|
+
const briefIfNeeded = () => {
|
|
3087
|
+
if (briefingFired || disposed)
|
|
3088
|
+
return;
|
|
3089
|
+
briefingFired = true;
|
|
3090
|
+
const briefing = summarizeGoalsNeedingYou(store.getAllSnapshots());
|
|
3091
|
+
if (!briefing)
|
|
3092
|
+
return;
|
|
3093
|
+
log("info", `Briefing: ${briefing.message}`);
|
|
3094
|
+
coalescer.brief(BRIEFING_SESSION_KEY, briefing);
|
|
3095
|
+
};
|
|
3096
|
+
let bound;
|
|
3097
|
+
let binding = null;
|
|
3098
|
+
let generation = 0;
|
|
3099
|
+
const resolveBinding = () => {
|
|
3100
|
+
if (binding)
|
|
3101
|
+
return binding;
|
|
3102
|
+
const pending = (async () => {
|
|
3103
|
+
while (!disposed) {
|
|
3104
|
+
const requested = generation;
|
|
3105
|
+
const directory = await resolveWorkspaceDir();
|
|
3106
|
+
if (disposed)
|
|
3107
|
+
return;
|
|
3108
|
+
if (requested !== generation)
|
|
3109
|
+
continue;
|
|
3110
|
+
if (!directory)
|
|
3111
|
+
return;
|
|
3112
|
+
const root = await stateRoots.resolve(directory);
|
|
3113
|
+
if (disposed)
|
|
3114
|
+
return;
|
|
3115
|
+
if (requested !== generation)
|
|
3116
|
+
continue;
|
|
3117
|
+
if (bound?.directory === directory && bound.root === root)
|
|
3118
|
+
return bound;
|
|
3119
|
+
if (bound) {
|
|
3120
|
+
bound.loop.stop();
|
|
3121
|
+
for (const stale of bound.loop.getSnapshots()) {
|
|
3122
|
+
store.applyEvent({
|
|
3123
|
+
kind: "remove",
|
|
3124
|
+
sessionID: stale.sessionID,
|
|
3125
|
+
goalId: stale.goalId,
|
|
3126
|
+
timestamp: Date.now()
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
const loop = createDiskRefreshLoop({
|
|
3131
|
+
directory,
|
|
3132
|
+
stateRoot: root,
|
|
3133
|
+
store,
|
|
3134
|
+
intervalMs: 1000,
|
|
3135
|
+
onEvent: (event) => {
|
|
3136
|
+
if (disposed)
|
|
3137
|
+
return;
|
|
3138
|
+
playSound(event.kind, event.snapshot?.status);
|
|
3139
|
+
coalescer.accept(event, event.sessionID);
|
|
3140
|
+
}
|
|
3141
|
+
});
|
|
3142
|
+
bound = { directory, root, loop };
|
|
3143
|
+
loop.start();
|
|
3144
|
+
log("info", `disk-refresh loop started (dir=${directory}, root=${root})`);
|
|
3145
|
+
return bound;
|
|
3146
|
+
}
|
|
3147
|
+
return;
|
|
3148
|
+
})().finally(() => {
|
|
3149
|
+
if (binding === pending)
|
|
3150
|
+
binding = null;
|
|
3151
|
+
});
|
|
3152
|
+
binding = pending;
|
|
3153
|
+
return pending;
|
|
3154
|
+
};
|
|
3155
|
+
const refresh = async () => {
|
|
3156
|
+
while (!disposed) {
|
|
3157
|
+
const requested = generation;
|
|
3158
|
+
const current = await resolveBinding();
|
|
3159
|
+
if (disposed)
|
|
3160
|
+
return;
|
|
3161
|
+
if (requested !== generation)
|
|
3162
|
+
continue;
|
|
3163
|
+
if (!current)
|
|
3164
|
+
return;
|
|
3165
|
+
await current.loop.tick();
|
|
3166
|
+
if (disposed)
|
|
3167
|
+
return;
|
|
3168
|
+
if (requested !== generation || current !== bound)
|
|
3169
|
+
continue;
|
|
3170
|
+
return current.directory;
|
|
3171
|
+
}
|
|
3172
|
+
return;
|
|
3173
|
+
};
|
|
3174
|
+
const refreshStateRoot = async () => {
|
|
3175
|
+
if (disposed)
|
|
3176
|
+
return;
|
|
3177
|
+
generation++;
|
|
3178
|
+
stateRoots.invalidate();
|
|
3179
|
+
await refresh();
|
|
3180
|
+
};
|
|
3181
|
+
const startDiskLoop = async () => {
|
|
3182
|
+
for (let attempt = 0;attempt < 12; attempt++) {
|
|
3183
|
+
if (disposed)
|
|
3184
|
+
return;
|
|
3185
|
+
if (await refresh()) {
|
|
3186
|
+
briefIfNeeded();
|
|
3187
|
+
return;
|
|
3188
|
+
}
|
|
3189
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
3190
|
+
}
|
|
3191
|
+
log("info", "disk-refresh loop: workspace directory never resolved; loop not started");
|
|
3192
|
+
};
|
|
3193
|
+
startDiskLoop();
|
|
3194
|
+
const degraded = createDegradedModeDetector();
|
|
3195
|
+
let unsub = null;
|
|
3196
|
+
const rootUnsubs = [];
|
|
3197
|
+
for (const type of [
|
|
3198
|
+
"server.connected",
|
|
3199
|
+
"plugin.updated",
|
|
3200
|
+
GOAL_STATE_ROOT_CHANGED
|
|
3201
|
+
]) {
|
|
3202
|
+
try {
|
|
3203
|
+
rootUnsubs.push(context.data.on(type, () => void refreshStateRoot()));
|
|
3204
|
+
} catch {}
|
|
3205
|
+
}
|
|
3206
|
+
try {
|
|
3207
|
+
unsub = context.data.on("session.tool.success", (event) => {
|
|
3208
|
+
try {
|
|
3209
|
+
const evData = event?.data;
|
|
3210
|
+
if (evData?.sessionID && (evData.tool === "goal-command" || typeof evData.tool === "string" && evData.tool.endsWith("_goal"))) {
|
|
3211
|
+
disarmWatchdogs(evData.sessionID);
|
|
3212
|
+
}
|
|
3213
|
+
const meta = evData?.metadata;
|
|
3214
|
+
const events = decodeGoalToolMetadata(meta);
|
|
3215
|
+
if (!events)
|
|
3216
|
+
return;
|
|
3217
|
+
degraded.noteSurfaceAlive();
|
|
3218
|
+
for (const parsed of events) {
|
|
3219
|
+
disarmWatchdogs(parsed.sessionID);
|
|
3220
|
+
store.applyEvent(parsed);
|
|
3221
|
+
playSound(parsed.kind, parsed.snapshot?.status);
|
|
3222
|
+
}
|
|
3223
|
+
} catch (err) {
|
|
3224
|
+
log("error", `Event error: ${err instanceof Error ? err.message : String(err)}`);
|
|
3225
|
+
}
|
|
3226
|
+
});
|
|
3227
|
+
} catch (err) {
|
|
3228
|
+
log("error", `Subscribe error: ${err instanceof Error ? err.message : String(err)}`);
|
|
3229
|
+
}
|
|
3230
|
+
return {
|
|
3231
|
+
refresh,
|
|
3232
|
+
dispose: () => {
|
|
3233
|
+
disposed = true;
|
|
3234
|
+
stateRoots.dispose();
|
|
3235
|
+
for (const unsubscribe of rootUnsubs) {
|
|
3236
|
+
try {
|
|
3237
|
+
unsubscribe();
|
|
3238
|
+
} catch {}
|
|
3239
|
+
}
|
|
3240
|
+
if (unsub) {
|
|
3241
|
+
try {
|
|
3242
|
+
unsub();
|
|
3243
|
+
} catch {}
|
|
3244
|
+
}
|
|
3245
|
+
bound?.loop.stop();
|
|
3246
|
+
coalescer.stopAutoFlush();
|
|
3247
|
+
}
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
// src/plugin-v2-command-output.ts
|
|
3252
|
+
var outputSchema = {
|
|
3253
|
+
type: "object",
|
|
3254
|
+
properties: {
|
|
3255
|
+
id: { type: "string" },
|
|
3256
|
+
sessionID: { type: "string" },
|
|
3257
|
+
text: { type: "string" },
|
|
3258
|
+
kind: { enum: ["command", "notice"] },
|
|
3259
|
+
timestamp: { type: "number" }
|
|
3260
|
+
},
|
|
3261
|
+
required: ["id", "sessionID", "text", "kind", "timestamp"],
|
|
3262
|
+
additionalProperties: false
|
|
3263
|
+
};
|
|
3264
|
+
var GOAL_OUTPUT_RPC = {
|
|
3265
|
+
id: "fixate-on-output",
|
|
3266
|
+
methods: {
|
|
3267
|
+
latest: {
|
|
3268
|
+
input: {
|
|
3269
|
+
type: "object",
|
|
3270
|
+
properties: { sessionID: { type: "string", minLength: 1 } },
|
|
3271
|
+
required: ["sessionID"],
|
|
3272
|
+
additionalProperties: false
|
|
3273
|
+
},
|
|
3274
|
+
output: { anyOf: [outputSchema, { type: "null" }] }
|
|
3275
|
+
}
|
|
3276
|
+
},
|
|
3277
|
+
events: { output: { schema: outputSchema } }
|
|
3278
|
+
};
|
|
3279
|
+
var MAX_OUTPUT_SESSIONS = 256;
|
|
3280
|
+
function createGoalOutputPublisher(fallback, now = Date.now) {
|
|
3281
|
+
const latest = new Map;
|
|
3282
|
+
let registration;
|
|
3283
|
+
let registering;
|
|
3284
|
+
let disposed = false;
|
|
3285
|
+
let lastTimestamp = Number.NEGATIVE_INFINITY;
|
|
3286
|
+
const register = async (rpc) => {
|
|
3287
|
+
try {
|
|
3288
|
+
const reg = await rpc.register(GOAL_OUTPUT_RPC, {
|
|
3289
|
+
latest: async (input) => {
|
|
3290
|
+
const sessionID = input && typeof input === "object" && "sessionID" in input ? input.sessionID : undefined;
|
|
3291
|
+
return typeof sessionID === "string" ? latest.get(sessionID) ?? null : null;
|
|
3292
|
+
}
|
|
3293
|
+
});
|
|
3294
|
+
if (disposed) {
|
|
3295
|
+
await reg.dispose();
|
|
3296
|
+
return;
|
|
3297
|
+
}
|
|
3298
|
+
registration = reg;
|
|
3299
|
+
} catch {}
|
|
3300
|
+
};
|
|
3301
|
+
return {
|
|
3302
|
+
async register(rpc) {
|
|
3303
|
+
if (!rpc || disposed || registration)
|
|
3304
|
+
return;
|
|
3305
|
+
if (!registering)
|
|
3306
|
+
registering = Promise.resolve().then(() => register(rpc));
|
|
3307
|
+
const pending = registering;
|
|
3308
|
+
try {
|
|
3309
|
+
await pending;
|
|
3310
|
+
} finally {
|
|
3311
|
+
if (registering === pending)
|
|
3312
|
+
registering = undefined;
|
|
3313
|
+
}
|
|
3314
|
+
},
|
|
3315
|
+
async publish(sessionID, text, kind = "notice") {
|
|
3316
|
+
if (disposed)
|
|
3317
|
+
throw new Error("Goal output is unavailable after disposal.");
|
|
3318
|
+
if (!sessionID || !text)
|
|
3319
|
+
return;
|
|
3320
|
+
lastTimestamp = Math.max(now(), lastTimestamp + 1);
|
|
3321
|
+
const output = {
|
|
3322
|
+
id: crypto.randomUUID(),
|
|
3323
|
+
sessionID,
|
|
3324
|
+
text,
|
|
3325
|
+
kind,
|
|
3326
|
+
timestamp: lastTimestamp
|
|
3327
|
+
};
|
|
3328
|
+
latest.delete(sessionID);
|
|
3329
|
+
latest.set(sessionID, output);
|
|
3330
|
+
while (latest.size > MAX_OUTPUT_SESSIONS) {
|
|
3331
|
+
latest.delete(latest.keys().next().value);
|
|
3332
|
+
}
|
|
3333
|
+
if (registration) {
|
|
3334
|
+
try {
|
|
3335
|
+
await registration.events.emit("output", output);
|
|
3336
|
+
} catch {
|
|
3337
|
+
if (fallback)
|
|
3338
|
+
await fallback(sessionID, text).catch(() => {});
|
|
3339
|
+
}
|
|
3340
|
+
} else if (fallback) {
|
|
3341
|
+
await fallback(sessionID, text);
|
|
3342
|
+
} else {
|
|
3343
|
+
throw new Error(`The goal command completed, but this host has no passive output channel.
|
|
3344
|
+
${text}`);
|
|
3345
|
+
}
|
|
3346
|
+
},
|
|
3347
|
+
async dispose() {
|
|
3348
|
+
if (disposed)
|
|
3349
|
+
return;
|
|
3350
|
+
disposed = true;
|
|
3351
|
+
latest.clear();
|
|
3352
|
+
await registration?.dispose();
|
|
3353
|
+
}
|
|
3354
|
+
};
|
|
3355
|
+
}
|
|
3356
|
+
function parseGoalCommandOutput(value) {
|
|
3357
|
+
if (!value || typeof value !== "object")
|
|
3358
|
+
return null;
|
|
3359
|
+
const output = value;
|
|
3360
|
+
return typeof output.id === "string" && output.id.length > 0 && typeof output.sessionID === "string" && output.sessionID.length > 0 && typeof output.text === "string" && output.text.length > 0 && (output.kind === "command" || output.kind === "notice") && typeof output.timestamp === "number" && Number.isFinite(output.timestamp) ? output : null;
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
// src/tui-v2-command-output.ts
|
|
3364
|
+
function wireGoalCommandOutput(context, showReceipt) {
|
|
3365
|
+
if (typeof context.data?.on !== "function")
|
|
3366
|
+
return () => {};
|
|
3367
|
+
const seen = new Set;
|
|
3368
|
+
const unsubscribers = [];
|
|
3369
|
+
let disposed = false;
|
|
3370
|
+
let recovery;
|
|
3371
|
+
const display = (input) => {
|
|
3372
|
+
if (disposed)
|
|
3373
|
+
return null;
|
|
3374
|
+
try {
|
|
3375
|
+
const output = parseGoalCommandOutput(input);
|
|
3376
|
+
if (!output || seen.has(output.id))
|
|
3377
|
+
return null;
|
|
3378
|
+
const route = context.ui.router.current();
|
|
3379
|
+
if (output.kind === "command" && route.type === "session" && route.sessionID === output.sessionID) {
|
|
3380
|
+
showReceipt(output.text);
|
|
3381
|
+
} else {
|
|
3382
|
+
context.ui.toast.show({
|
|
3383
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3384
|
+
message: output.text,
|
|
3385
|
+
variant: "info",
|
|
3386
|
+
sessionID: output.sessionID
|
|
3387
|
+
});
|
|
3388
|
+
}
|
|
3389
|
+
seen.add(output.id);
|
|
3390
|
+
if (seen.size > 256)
|
|
3391
|
+
seen.delete(seen.values().next().value);
|
|
3392
|
+
return output;
|
|
3393
|
+
} catch {
|
|
3394
|
+
return null;
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
const recoverLatest = async () => {
|
|
3398
|
+
if (disposed || typeof context.client.rpc !== "function")
|
|
3399
|
+
return;
|
|
3400
|
+
recovery = undefined;
|
|
3401
|
+
let request;
|
|
3402
|
+
try {
|
|
3403
|
+
const route = context.ui.router.current();
|
|
3404
|
+
if (route.type !== "session" || !route.sessionID)
|
|
3405
|
+
return;
|
|
3406
|
+
const channel = context.client.rpc(GOAL_OUTPUT_RPC);
|
|
3407
|
+
if (typeof channel?.latest !== "function")
|
|
3408
|
+
return;
|
|
3409
|
+
const sessionDirectory = context.data.session?.get(route.sessionID)?.location?.directory?.trim();
|
|
3410
|
+
const workspaceDirectory = context.location?.directory?.trim();
|
|
3411
|
+
const directory = sessionDirectory || workspaceDirectory || undefined;
|
|
3412
|
+
request = {
|
|
3413
|
+
sessionID: route.sessionID,
|
|
3414
|
+
displayedAt: Number.NEGATIVE_INFINITY
|
|
3415
|
+
};
|
|
3416
|
+
recovery = request;
|
|
3417
|
+
const output = parseGoalCommandOutput(await channel.latest({ sessionID: route.sessionID }, directory ? { location: { directory } } : undefined));
|
|
3418
|
+
if (!disposed && request === recovery && output?.sessionID === route.sessionID && output.timestamp > request.displayedAt) {
|
|
3419
|
+
display(output);
|
|
3420
|
+
}
|
|
3421
|
+
} catch {} finally {
|
|
3422
|
+
if (request === recovery)
|
|
3423
|
+
recovery = undefined;
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
try {
|
|
3427
|
+
unsubscribers.push(context.data.on(`rpc.${GOAL_OUTPUT_RPC.id}.output`, (event) => {
|
|
3428
|
+
if (disposed)
|
|
3429
|
+
return;
|
|
3430
|
+
const pending = recovery;
|
|
3431
|
+
const output = display(event?.data);
|
|
3432
|
+
if (output && pending && pending === recovery && pending.sessionID === output.sessionID)
|
|
3433
|
+
pending.displayedAt = Math.max(pending.displayedAt, output.timestamp);
|
|
3434
|
+
}));
|
|
3435
|
+
unsubscribers.push(context.data.on("server.connected", () => void recoverLatest()));
|
|
3436
|
+
recoverLatest();
|
|
3437
|
+
} catch {}
|
|
3438
|
+
return () => {
|
|
3439
|
+
if (disposed)
|
|
3440
|
+
return;
|
|
3441
|
+
disposed = true;
|
|
3442
|
+
recovery = undefined;
|
|
3443
|
+
seen.clear();
|
|
3444
|
+
for (const unsubscribe of unsubscribers) {
|
|
3445
|
+
try {
|
|
3446
|
+
unsubscribe();
|
|
3447
|
+
} catch {}
|
|
3448
|
+
}
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
|
|
3452
|
+
// src/tui-v2-receipt-dialog.tsx
|
|
3453
|
+
import { effect as _$effect2 } from "@opentui/solid";
|
|
3454
|
+
import { createTextNode as _$createTextNode2 } from "@opentui/solid";
|
|
3455
|
+
import { insertNode as _$insertNode2 } from "@opentui/solid";
|
|
3456
|
+
import { use as _$use2 } from "@opentui/solid";
|
|
3457
|
+
import { insert as _$insert2 } from "@opentui/solid";
|
|
3458
|
+
import { setProp as _$setProp2 } from "@opentui/solid";
|
|
3459
|
+
import { createElement as _$createElement2 } from "@opentui/solid";
|
|
3460
|
+
import { useTerminalDimensions } from "@opentui/solid";
|
|
3461
|
+
import { createMemo as createMemo2, onCleanup } from "solid-js";
|
|
3462
|
+
function ReceiptDialog(props) {
|
|
3463
|
+
const dimensions = useTerminalDimensions();
|
|
3464
|
+
const palette = createMemo2(() => {
|
|
3465
|
+
const raw = props.context.theme ?? {};
|
|
3466
|
+
return resolveDashboardPalette(raw.surface?.("dialog") ?? raw);
|
|
3467
|
+
});
|
|
3468
|
+
let mounted = true;
|
|
3469
|
+
let scroll = null;
|
|
3470
|
+
const handlers = createScrollHandlers(() => scroll);
|
|
3471
|
+
const moveTo = (end) => {
|
|
3472
|
+
try {
|
|
3473
|
+
scroll?.scrollTo(end ? scroll.scrollHeight : 0);
|
|
3474
|
+
} catch {}
|
|
3475
|
+
};
|
|
3476
|
+
onCleanup(() => {
|
|
3477
|
+
mounted = false;
|
|
3478
|
+
scroll = null;
|
|
3479
|
+
});
|
|
3480
|
+
props.context.keymap.layer(() => ({
|
|
3481
|
+
mode: "modal",
|
|
3482
|
+
enabled: () => mounted && props.active(),
|
|
3483
|
+
commands: [{
|
|
3484
|
+
bind: "up",
|
|
3485
|
+
title: "Scroll receipt up",
|
|
3486
|
+
run: handlers.up
|
|
3487
|
+
}, {
|
|
3488
|
+
bind: "down",
|
|
3489
|
+
title: "Scroll receipt down",
|
|
3490
|
+
run: handlers.down
|
|
3491
|
+
}, {
|
|
3492
|
+
bind: "pageup",
|
|
3493
|
+
title: "Page receipt up",
|
|
3494
|
+
run: handlers.pageUp
|
|
3495
|
+
}, {
|
|
3496
|
+
bind: "pagedown",
|
|
3497
|
+
title: "Page receipt down",
|
|
3498
|
+
run: handlers.pageDown
|
|
3499
|
+
}, {
|
|
3500
|
+
bind: "home",
|
|
3501
|
+
title: "Start of receipt",
|
|
3502
|
+
run: () => moveTo(false)
|
|
3503
|
+
}, {
|
|
3504
|
+
bind: "end",
|
|
3505
|
+
title: "End of receipt",
|
|
3506
|
+
run: () => moveTo(true)
|
|
3507
|
+
}, {
|
|
3508
|
+
bind: "return",
|
|
3509
|
+
title: "Close receipt",
|
|
3510
|
+
run: () => props.context.ui.dialog.clear()
|
|
3511
|
+
}]
|
|
3512
|
+
}));
|
|
3513
|
+
return (() => {
|
|
3514
|
+
var _el$ = _$createElement2("box"), _el$2 = _$createElement2("text"), _el$3 = _$createElement2("scrollbox"), _el$4 = _$createElement2("text"), _el$5 = _$createElement2("text");
|
|
3515
|
+
_$insertNode2(_el$, _el$2);
|
|
3516
|
+
_$insertNode2(_el$, _el$3);
|
|
3517
|
+
_$insertNode2(_el$, _el$5);
|
|
3518
|
+
_$setProp2(_el$, "flexDirection", "column");
|
|
3519
|
+
_$setProp2(_el$, "paddingLeft", 1);
|
|
3520
|
+
_$setProp2(_el$, "paddingRight", 1);
|
|
3521
|
+
_$setProp2(_el$, "paddingBottom", 1);
|
|
3522
|
+
_$setProp2(_el$2, "flexShrink", 0);
|
|
3523
|
+
_$setProp2(_el$2, "attributes", 1);
|
|
3524
|
+
_$insert2(_el$2, PRODUCT_DISPLAY_NAME);
|
|
3525
|
+
_$insertNode2(_el$3, _el$4);
|
|
3526
|
+
_$use2((el) => {
|
|
3527
|
+
scroll = el;
|
|
3528
|
+
}, _el$3);
|
|
3529
|
+
_$setProp2(_el$3, "flexGrow", 1);
|
|
3530
|
+
_$setProp2(_el$3, "minHeight", 0);
|
|
3531
|
+
_$setProp2(_el$3, "verticalScrollbarOptions", {
|
|
3532
|
+
visible: true
|
|
3533
|
+
});
|
|
3534
|
+
_$setProp2(_el$4, "wrapMode", "word");
|
|
3535
|
+
_$insert2(_el$4, () => props.text);
|
|
3536
|
+
_$insertNode2(_el$5, _$createTextNode2(`\u2191\u2193 scroll \xB7 PgUp/PgDn page \xB7 Home/End \xB7 Esc/Enter close`));
|
|
3537
|
+
_$setProp2(_el$5, "flexShrink", 0);
|
|
3538
|
+
_$effect2((_p$) => {
|
|
3539
|
+
var _v$ = Math.max(1, dimensions().height - 4), _v$2 = palette().accent, _v$3 = palette().text, _v$4 = palette().muted;
|
|
3540
|
+
_v$ !== _p$.e && (_p$.e = _$setProp2(_el$, "height", _v$, _p$.e));
|
|
3541
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp2(_el$2, "fg", _v$2, _p$.t));
|
|
3542
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp2(_el$4, "fg", _v$3, _p$.a));
|
|
3543
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp2(_el$5, "fg", _v$4, _p$.o));
|
|
3544
|
+
return _p$;
|
|
3545
|
+
}, {
|
|
3546
|
+
e: undefined,
|
|
3547
|
+
t: undefined,
|
|
3548
|
+
a: undefined,
|
|
3549
|
+
o: undefined
|
|
3550
|
+
});
|
|
3551
|
+
return _el$;
|
|
3552
|
+
})();
|
|
3553
|
+
}
|
|
3554
|
+
function showGoalCommandReceipt(context, text) {
|
|
3555
|
+
let active = true;
|
|
3556
|
+
context.ui.dialog.show(() => ReceiptDialog({
|
|
3557
|
+
context,
|
|
3558
|
+
text,
|
|
3559
|
+
active: () => active
|
|
3560
|
+
}), () => {
|
|
3561
|
+
active = false;
|
|
3562
|
+
});
|
|
3563
|
+
context.ui.dialog.set({
|
|
3564
|
+
size: "xlarge",
|
|
3565
|
+
centered: true
|
|
3566
|
+
});
|
|
3567
|
+
return () => {
|
|
3568
|
+
if (!active)
|
|
3569
|
+
return;
|
|
3570
|
+
active = false;
|
|
3571
|
+
try {
|
|
3572
|
+
context.ui.dialog.clear();
|
|
3573
|
+
} catch {}
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
// src/tui-v2-state-root.ts
|
|
3578
|
+
var DEFAULT_ATTEMPTS = 6;
|
|
3579
|
+
var DEFAULT_RETRY_MS = 500;
|
|
3580
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 2000;
|
|
3581
|
+
function unrefTimer(timer) {
|
|
3582
|
+
if (timer && typeof timer.unref === "function") {
|
|
3583
|
+
timer.unref();
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
function abortableSleep(ms, signal) {
|
|
3587
|
+
if (signal.aborted)
|
|
3588
|
+
return Promise.resolve();
|
|
3589
|
+
return new Promise((done) => {
|
|
3590
|
+
const onAbort = () => {
|
|
3591
|
+
clearTimeout(timer);
|
|
3592
|
+
done();
|
|
3593
|
+
};
|
|
3594
|
+
const timer = setTimeout(() => {
|
|
3595
|
+
signal.removeEventListener("abort", onAbort);
|
|
3596
|
+
done();
|
|
3597
|
+
}, ms);
|
|
3598
|
+
unrefTimer(timer);
|
|
3599
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
function createStateRootResolver(options) {
|
|
3603
|
+
const explicitRoot = typeof options.explicit === "string" && options.explicit.trim().length > 0 ? options.explicit : undefined;
|
|
3604
|
+
const { client } = options;
|
|
3605
|
+
const attempts = options.attempts ?? DEFAULT_ATTEMPTS;
|
|
3606
|
+
const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
|
|
3607
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
3608
|
+
const cache = new Map;
|
|
3609
|
+
const lastReported = new Map;
|
|
3610
|
+
let generation = 0;
|
|
3611
|
+
let disposed = false;
|
|
3612
|
+
let activeController = new AbortController;
|
|
3613
|
+
const ask = async (directory, signal) => {
|
|
3614
|
+
if (signal.aborted)
|
|
3615
|
+
return;
|
|
3616
|
+
const controller = new AbortController;
|
|
3617
|
+
let timer;
|
|
3618
|
+
let onAbort;
|
|
3619
|
+
try {
|
|
3620
|
+
const channel = client.rpc?.(GOAL_STATE_ROOT_RPC);
|
|
3621
|
+
if (typeof channel?.root !== "function")
|
|
3622
|
+
return;
|
|
3623
|
+
const reply = channel.root({}, { location: { directory }, signal: controller.signal });
|
|
3624
|
+
const cancelled = new Promise((done) => {
|
|
3625
|
+
onAbort = () => {
|
|
3626
|
+
controller.abort();
|
|
3627
|
+
done(undefined);
|
|
3628
|
+
};
|
|
3629
|
+
if (signal.aborted) {
|
|
3630
|
+
onAbort();
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3634
|
+
timer = setTimeout(onAbort, requestTimeoutMs);
|
|
3635
|
+
unrefTimer(timer);
|
|
3636
|
+
});
|
|
3637
|
+
return parseStateRootReply(await Promise.race([reply, cancelled]));
|
|
3638
|
+
} catch {
|
|
3639
|
+
return;
|
|
3640
|
+
} finally {
|
|
3641
|
+
clearTimeout(timer);
|
|
3642
|
+
if (onAbort)
|
|
3643
|
+
signal.removeEventListener("abort", onAbort);
|
|
3644
|
+
}
|
|
3645
|
+
};
|
|
3646
|
+
const query = async (directory, gen, signal) => {
|
|
3647
|
+
if (typeof client.rpc !== "function")
|
|
3648
|
+
return;
|
|
3649
|
+
for (let attempt = 0;attempt < attempts; attempt++) {
|
|
3650
|
+
if (signal.aborted || gen !== generation)
|
|
3651
|
+
return;
|
|
3652
|
+
if (attempt > 0) {
|
|
3653
|
+
await abortableSleep(retryMs, signal);
|
|
3654
|
+
if (signal.aborted || gen !== generation)
|
|
3655
|
+
return;
|
|
3656
|
+
}
|
|
3657
|
+
const root = await ask(directory, signal);
|
|
3658
|
+
if (signal.aborted || gen !== generation)
|
|
3659
|
+
return;
|
|
3660
|
+
if (root !== undefined) {
|
|
3661
|
+
lastReported.set(directory, root);
|
|
3662
|
+
return root;
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
return lastReported.get(directory);
|
|
3666
|
+
};
|
|
3667
|
+
return {
|
|
3668
|
+
resolve(directory) {
|
|
3669
|
+
if (explicitRoot !== undefined)
|
|
3670
|
+
return Promise.resolve(resolveStateRoot(directory, explicitRoot));
|
|
3671
|
+
if (disposed)
|
|
3672
|
+
return Promise.resolve(resolveStateRoot(directory, lastReported.get(directory)));
|
|
3673
|
+
const cached = cache.get(directory);
|
|
3674
|
+
if (cached)
|
|
3675
|
+
return cached;
|
|
3676
|
+
const gen = generation;
|
|
3677
|
+
const signal = activeController.signal;
|
|
3678
|
+
const pending = query(directory, gen, signal).then((reported) => resolveStateRoot(directory, reported ?? lastReported.get(directory)));
|
|
3679
|
+
cache.set(directory, pending);
|
|
3680
|
+
return pending;
|
|
3681
|
+
},
|
|
3682
|
+
invalidate() {
|
|
3683
|
+
generation++;
|
|
3684
|
+
cache.clear();
|
|
3685
|
+
activeController.abort();
|
|
3686
|
+
if (!disposed)
|
|
3687
|
+
activeController = new AbortController;
|
|
3688
|
+
},
|
|
3689
|
+
dispose() {
|
|
3690
|
+
if (disposed)
|
|
3691
|
+
return;
|
|
3692
|
+
disposed = true;
|
|
3693
|
+
generation++;
|
|
3694
|
+
cache.clear();
|
|
3695
|
+
activeController.abort();
|
|
3696
|
+
},
|
|
3697
|
+
isDisposed() {
|
|
3698
|
+
return disposed;
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
// src/tui-v2.ts
|
|
3704
|
+
var GOAL_PREFIX2 = "ctrl+shift+g";
|
|
3705
|
+
function chord2(actionKey) {
|
|
3706
|
+
return `${GOAL_PREFIX2} ${actionKey}`;
|
|
3707
|
+
}
|
|
3708
|
+
function unwrapDirectory(out) {
|
|
3709
|
+
if (!out || typeof out !== "object")
|
|
3710
|
+
return;
|
|
3711
|
+
const direct = out;
|
|
3712
|
+
if (typeof direct.directory === "string" && direct.directory)
|
|
3713
|
+
return direct.directory;
|
|
3714
|
+
if (direct.location && typeof direct.location === "object") {
|
|
3715
|
+
const l = direct.location;
|
|
3716
|
+
if (typeof l.directory === "string" && l.directory)
|
|
3717
|
+
return l.directory;
|
|
3718
|
+
}
|
|
3719
|
+
if (direct.data && typeof direct.data === "object")
|
|
3720
|
+
return unwrapDirectory(direct.data);
|
|
3721
|
+
return;
|
|
3722
|
+
}
|
|
3723
|
+
var GoalTuiPluginV2 = {
|
|
3724
|
+
id: "fixate-on-tui",
|
|
3725
|
+
async setup(context) {
|
|
3726
|
+
if (!context.keymap || typeof context.keymap.layer !== "function") {
|
|
3727
|
+
return () => {};
|
|
3728
|
+
}
|
|
3729
|
+
const opts = {
|
|
3730
|
+
logLevel: context.options?.logLevel ?? "info",
|
|
3731
|
+
stateRoot: context.options?.stateRoot,
|
|
3732
|
+
workspaceDirectory: typeof context.options?.workspaceDirectory === "string" && context.options.workspaceDirectory.trim() ? context.options.workspaceDirectory.trim() : undefined
|
|
3733
|
+
};
|
|
3734
|
+
const store = createTuiStateStore();
|
|
3735
|
+
const activeSessionID = () => {
|
|
3736
|
+
const route = context.ui.router.current();
|
|
3737
|
+
if (route.type !== "session" || !route.sessionID)
|
|
3738
|
+
return null;
|
|
3739
|
+
return route.sessionID;
|
|
3740
|
+
};
|
|
3741
|
+
const log = (level, message) => {
|
|
3742
|
+
if (opts.logLevel === "error" && level !== "error")
|
|
3743
|
+
return;
|
|
3744
|
+
if (opts.logLevel === "info" && level === "debug")
|
|
3745
|
+
return;
|
|
3746
|
+
try {
|
|
3747
|
+
if (level === "error") {
|
|
3748
|
+
context.ui.toast.show({
|
|
3749
|
+
variant: "error",
|
|
3750
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3751
|
+
message,
|
|
3752
|
+
duration: 6000
|
|
3753
|
+
});
|
|
3754
|
+
}
|
|
3755
|
+
console[level === "error" ? "error" : "log"](`[${GOAL_TUI_EVENT_TITLE}/tui] ${message}`);
|
|
3756
|
+
} catch {}
|
|
3757
|
+
};
|
|
3758
|
+
let creatingSession = null;
|
|
3759
|
+
let lastAutoCreated = null;
|
|
3760
|
+
const resolveGoalSession = async () => {
|
|
3761
|
+
const active = activeSessionID();
|
|
3762
|
+
if (active)
|
|
3763
|
+
return active;
|
|
3764
|
+
const directory = context.location?.directory;
|
|
3765
|
+
const workspaceID = context.location?.workspaceID;
|
|
3766
|
+
if (!directory) {
|
|
3767
|
+
context.ui.toast.show({
|
|
3768
|
+
variant: "warning",
|
|
3769
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3770
|
+
message: "Open a session before controlling a goal."
|
|
3771
|
+
});
|
|
3772
|
+
return null;
|
|
3773
|
+
}
|
|
3774
|
+
if (lastAutoCreated && lastAutoCreated.directory === directory && lastAutoCreated.workspaceID === workspaceID) {
|
|
3775
|
+
return lastAutoCreated.sessionID;
|
|
3776
|
+
}
|
|
3777
|
+
if (creatingSession?.key === directory) {
|
|
3778
|
+
return creatingSession.promise;
|
|
3779
|
+
}
|
|
3780
|
+
const promise = (async () => {
|
|
3781
|
+
try {
|
|
3782
|
+
const created = await context.client.session.create({
|
|
3783
|
+
location: { directory }
|
|
3784
|
+
});
|
|
3785
|
+
const sessionID = created?.id;
|
|
3786
|
+
if (!sessionID)
|
|
3787
|
+
throw new Error("session.create returned no session id");
|
|
3788
|
+
const tabbed = context.ui.tabs && typeof context.ui.tabs.enabled === "function" && context.ui.tabs.enabled();
|
|
3789
|
+
const surfaced = tabbed ? context.ui.tabs.open(sessionID) : false;
|
|
3790
|
+
if (!surfaced) {
|
|
3791
|
+
try {
|
|
3792
|
+
context.ui.router.navigate({ type: "session", sessionID });
|
|
3793
|
+
} catch {}
|
|
3794
|
+
}
|
|
3795
|
+
lastAutoCreated = { directory, workspaceID, sessionID };
|
|
3796
|
+
return sessionID;
|
|
3797
|
+
} catch (error) {
|
|
3798
|
+
context.ui.toast.show({
|
|
3799
|
+
variant: "error",
|
|
3800
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3801
|
+
message: `Could not open a session: ${error instanceof Error ? error.message : String(error)}`
|
|
3802
|
+
});
|
|
3803
|
+
return null;
|
|
3804
|
+
}
|
|
3805
|
+
})();
|
|
3806
|
+
creatingSession = { key: directory, promise };
|
|
3807
|
+
try {
|
|
3808
|
+
return await promise;
|
|
3809
|
+
} finally {
|
|
3810
|
+
if (creatingSession?.key === directory)
|
|
3811
|
+
creatingSession = null;
|
|
3812
|
+
}
|
|
3813
|
+
};
|
|
3814
|
+
const activeWatchdogs = new Map;
|
|
3815
|
+
const degraded = createDegradedModeDetector();
|
|
3816
|
+
const armWatchdog = (sessionID, command, timeoutMs = 15000) => {
|
|
3817
|
+
const rootCommand = command.trim().split(/\s+/)[0];
|
|
3818
|
+
const key = `${sessionID}:${rootCommand}`;
|
|
3819
|
+
const existing = activeWatchdogs.get(key);
|
|
3820
|
+
if (existing) {
|
|
3821
|
+
clearTimeout(existing.timer);
|
|
3822
|
+
}
|
|
3823
|
+
const timer = setTimeout(() => {
|
|
3824
|
+
activeWatchdogs.delete(key);
|
|
3825
|
+
context.ui.toast.show({
|
|
3826
|
+
variant: "warning",
|
|
3827
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3828
|
+
message: degraded.checkDispatch() ?? watchdogTimeoutMessage("v2", command, timeoutMs),
|
|
3829
|
+
duration: 8000
|
|
3830
|
+
});
|
|
3831
|
+
}, timeoutMs);
|
|
3832
|
+
activeWatchdogs.set(key, { timer, command, sessionID });
|
|
3833
|
+
};
|
|
3834
|
+
const disarmWatchdogs = (sessionID) => {
|
|
3835
|
+
for (const [key, w] of activeWatchdogs.entries()) {
|
|
3836
|
+
if (w.sessionID === sessionID) {
|
|
3837
|
+
clearTimeout(w.timer);
|
|
3838
|
+
activeWatchdogs.delete(key);
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
};
|
|
3842
|
+
const stateRoots = createStateRootResolver({
|
|
3843
|
+
explicit: opts.stateRoot,
|
|
3844
|
+
client: context.client
|
|
3845
|
+
});
|
|
3846
|
+
const lastHydration = {
|
|
3847
|
+
count: 0
|
|
3848
|
+
};
|
|
3849
|
+
const resolveWorkspaceDir = async () => {
|
|
3850
|
+
const evidence = [];
|
|
3851
|
+
if (opts.workspaceDirectory)
|
|
3852
|
+
return opts.workspaceDirectory;
|
|
3853
|
+
const direct = context.location?.directory;
|
|
3854
|
+
if (direct)
|
|
3855
|
+
return direct;
|
|
3856
|
+
evidence.push("reactive-location:none");
|
|
3857
|
+
try {
|
|
3858
|
+
const client = context.client;
|
|
3859
|
+
const locOut = await client.location?.get?.();
|
|
3860
|
+
const locDir = unwrapDirectory(locOut);
|
|
3861
|
+
if (locDir)
|
|
3862
|
+
return locDir;
|
|
3863
|
+
evidence.push(`location.get=${JSON.stringify(locOut)?.slice(0, 120) ?? "undefined"}`);
|
|
3864
|
+
} catch (err) {
|
|
3865
|
+
evidence.push(`location.get=threw:${err instanceof Error ? err.message : String(err)}`.slice(0, 140));
|
|
3866
|
+
}
|
|
3867
|
+
const sid = activeSessionID();
|
|
3868
|
+
if (sid) {
|
|
3869
|
+
try {
|
|
3870
|
+
const sessOut = await context.client.session?.get?.({ sessionID: sid });
|
|
3871
|
+
const sessDir = unwrapDirectory(sessOut);
|
|
3872
|
+
if (sessDir)
|
|
3873
|
+
return sessDir;
|
|
3874
|
+
evidence.push(`session.get=${JSON.stringify(sessOut)?.slice(0, 120) ?? "undefined"}`);
|
|
3875
|
+
} catch (err) {
|
|
3876
|
+
evidence.push(`session.get=threw:${err instanceof Error ? err.message : String(err)}`.slice(0, 140));
|
|
3877
|
+
}
|
|
3878
|
+
} else {
|
|
3879
|
+
evidence.push("no-active-session");
|
|
3880
|
+
}
|
|
3881
|
+
lastHydration.evidence = evidence.join(" | ");
|
|
3882
|
+
return;
|
|
3883
|
+
};
|
|
3884
|
+
let events = null;
|
|
3885
|
+
const ensureHydrated = async () => {
|
|
3886
|
+
let lastDir;
|
|
3887
|
+
let lastCount = -1;
|
|
3888
|
+
for (let attempt = 0;attempt < 8; attempt++) {
|
|
3889
|
+
if (stateRoots.isDisposed())
|
|
3890
|
+
return;
|
|
3891
|
+
const dir = await events?.refresh();
|
|
3892
|
+
lastDir = dir;
|
|
3893
|
+
if (dir) {
|
|
3894
|
+
lastCount = store.getAllSnapshots().length;
|
|
3895
|
+
if (lastCount > 0) {
|
|
3896
|
+
lastHydration.dir = dir;
|
|
3897
|
+
lastHydration.count = lastCount;
|
|
3898
|
+
return;
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
await new Promise((r) => setTimeout(r, 350));
|
|
3902
|
+
}
|
|
3903
|
+
lastHydration.dir = lastDir;
|
|
3904
|
+
lastHydration.count = Math.max(lastCount, 0);
|
|
3905
|
+
log("info", `hydration exhausted: dir=${lastDir ?? "unresolved"} snapshots=${Math.max(lastCount, 0)}`);
|
|
3906
|
+
};
|
|
3907
|
+
const sendGoalCommand = async (command, opts) => {
|
|
3908
|
+
const sessionID = await resolveGoalSession();
|
|
3909
|
+
if (!sessionID)
|
|
3910
|
+
return;
|
|
3911
|
+
try {
|
|
3912
|
+
const directive = `[${PRODUCT_DISPLAY_NAME}] Execute the following goal command by calling the ` + "`goal-command` tool exactly once, passing its `subcommand` parameter " + `verbatim as the single argument:
|
|
3913
|
+
|
|
3914
|
+
${command}
|
|
3915
|
+
|
|
3916
|
+
` + "Do not ask for confirmation, do not summarize or describe the action, " + "and do not perform any other work. Call the tool now and reply with " + "only its returned output.";
|
|
3917
|
+
await context.client.session.synthetic({
|
|
3918
|
+
sessionID,
|
|
3919
|
+
text: directive,
|
|
3920
|
+
description: `${PRODUCT_DISPLAY_NAME}: ${command}`
|
|
3921
|
+
});
|
|
3922
|
+
armWatchdog(sessionID, command, opts?.timeoutMs);
|
|
3923
|
+
context.ui.toast.show({
|
|
3924
|
+
variant: "info",
|
|
3925
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3926
|
+
message: opts?.label ?? outcomeNeutralLabel(command)
|
|
3927
|
+
});
|
|
3928
|
+
} catch (error) {
|
|
3929
|
+
lastAutoCreated = null;
|
|
3930
|
+
context.ui.toast.show({
|
|
3931
|
+
variant: "error",
|
|
3932
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
3933
|
+
message: `Command failed: ${error instanceof Error ? error.message : String(error)}`
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
};
|
|
3937
|
+
const dashboardRouteName = "goal-dashboard";
|
|
3938
|
+
const dashboardSections = () => {
|
|
3939
|
+
const sid = dashboardSessionID ?? activeSessionID();
|
|
3940
|
+
let snaps = sid ? store.getSnapshots(sid) : [];
|
|
3941
|
+
if (snaps.length === 0) {
|
|
3942
|
+
snaps = store.getAllSnapshots();
|
|
3943
|
+
}
|
|
3944
|
+
if (snaps.length === 0) {
|
|
3945
|
+
if (opts.logLevel === "debug") {
|
|
3946
|
+
log("debug", `hydration evidence: dir=${lastHydration.dir ?? "unresolved"} snapshots=${lastHydration.count}${lastHydration.evidence ? ` ${lastHydration.evidence}` : ""}`);
|
|
3947
|
+
}
|
|
3948
|
+
return [];
|
|
3949
|
+
}
|
|
3950
|
+
return formatGoalStatusDashboard(snaps, sid ?? null);
|
|
3951
|
+
};
|
|
3952
|
+
const dashboardFooter = (targetSessionID) => dashboardFooterText(resolveFocusedGoalId(store, targetSessionID()), chord2("d"), chord2("p"), chord2("r"), chord2("c"), "esc");
|
|
3953
|
+
let dashboardRouteDispose = null;
|
|
3954
|
+
try {
|
|
3955
|
+
dashboardRouteDispose = context.ui.router.register({
|
|
3956
|
+
name: dashboardRouteName,
|
|
3957
|
+
render: () => {
|
|
3958
|
+
const [rev, setRev] = createSignal(0);
|
|
3959
|
+
const unsub = store.subscribe(() => setRev((r) => r + 1));
|
|
3960
|
+
onCleanup2(() => {
|
|
3961
|
+
dashboardOpen = false;
|
|
3962
|
+
dashboardSessionID = null;
|
|
3963
|
+
scrollHandlers = null;
|
|
3964
|
+
try {
|
|
3965
|
+
unsub();
|
|
3966
|
+
} catch {}
|
|
3967
|
+
});
|
|
3968
|
+
const theme = () => dialogTheme();
|
|
3969
|
+
const sections = () => {
|
|
3970
|
+
rev();
|
|
3971
|
+
return dashboardSections();
|
|
3972
|
+
};
|
|
3973
|
+
const snapshots = () => {
|
|
3974
|
+
rev();
|
|
3975
|
+
const sid = dashboardSession();
|
|
3976
|
+
let snaps = sid ? store.getSnapshots(sid) : [];
|
|
3977
|
+
if (snaps.length === 0)
|
|
3978
|
+
snaps = store.getAllSnapshots();
|
|
3979
|
+
return snaps;
|
|
3980
|
+
};
|
|
3981
|
+
const focusedGoalId = () => {
|
|
3982
|
+
rev();
|
|
3983
|
+
const sid = dashboardSession();
|
|
3984
|
+
return resolveFocusedGoalId(store, sid ?? null);
|
|
3985
|
+
};
|
|
3986
|
+
const viewSessionID = () => {
|
|
3987
|
+
rev();
|
|
3988
|
+
return dashboardSession();
|
|
3989
|
+
};
|
|
3990
|
+
const hydrationText = () => {
|
|
3991
|
+
const s = snapshots();
|
|
3992
|
+
return s.length === 0 ? `No goals found on disk for this workspace${lastHydration.dir ? ` (checked ${lastHydration.dir})` : ""}. Use /goal <condition> to set one.` : undefined;
|
|
3993
|
+
};
|
|
3994
|
+
return DashboardRoute({
|
|
3995
|
+
sections,
|
|
3996
|
+
snapshots,
|
|
3997
|
+
activeSessionID: viewSessionID,
|
|
3998
|
+
focusedGoalId,
|
|
3999
|
+
onSelectGoal: (goalId) => {
|
|
4000
|
+
const sid = activeSessionID();
|
|
4001
|
+
if (sid)
|
|
4002
|
+
store.getFocused(sid);
|
|
4003
|
+
sendGoalCommand(`focus ${goalId}`);
|
|
4004
|
+
},
|
|
4005
|
+
...dashboardGoalActions(store, dashboardSession, (c) => void sendGoalCommand(c)),
|
|
4006
|
+
onFocus: (goalId) => {
|
|
4007
|
+
sendGoalCommand(`focus ${goalId}`);
|
|
4008
|
+
},
|
|
4009
|
+
onClose: () => {
|
|
4010
|
+
dashboardOpen = false;
|
|
4011
|
+
dashboardSessionID = null;
|
|
4012
|
+
scrollHandlers = null;
|
|
4013
|
+
try {
|
|
4014
|
+
context.ui.router.navigate({ type: "home" });
|
|
4015
|
+
} catch {}
|
|
4016
|
+
},
|
|
4017
|
+
registerScrollCommands: (handlers) => {
|
|
4018
|
+
scrollHandlers = handlers;
|
|
4019
|
+
},
|
|
4020
|
+
theme,
|
|
4021
|
+
footer: dashboardFooter(dashboardSession),
|
|
4022
|
+
hydrationText: hydrationText()
|
|
4023
|
+
});
|
|
4024
|
+
}
|
|
4025
|
+
});
|
|
4026
|
+
} catch {
|
|
4027
|
+
dashboardRouteDispose = null;
|
|
4028
|
+
}
|
|
4029
|
+
let dashboardGeneration = 0;
|
|
4030
|
+
let dashboardOpen = false;
|
|
4031
|
+
let dashboardSessionID = null;
|
|
4032
|
+
let dashboardUnsubscribe = null;
|
|
4033
|
+
let scrollHandlers = null;
|
|
4034
|
+
const dialogTheme = () => {
|
|
4035
|
+
const raw = context.theme ?? {};
|
|
4036
|
+
try {
|
|
4037
|
+
return typeof raw.surface === "function" ? raw.surface("dialog") : raw;
|
|
4038
|
+
} catch {
|
|
4039
|
+
return raw;
|
|
4040
|
+
}
|
|
4041
|
+
};
|
|
4042
|
+
const isDashboardRouteActive = () => {
|
|
4043
|
+
try {
|
|
4044
|
+
const cur = context.ui.router.current();
|
|
4045
|
+
return cur?.type === "plugin" && cur?.name === dashboardRouteName;
|
|
4046
|
+
} catch {
|
|
4047
|
+
return false;
|
|
4048
|
+
}
|
|
4049
|
+
};
|
|
4050
|
+
const dashboardSession = () => (isDashboardRouteActive() && dashboardSessionID ? dashboardSessionID : activeSessionID()) ?? null;
|
|
4051
|
+
const repaintDashboard = () => {
|
|
4052
|
+
if (!dashboardOpen)
|
|
4053
|
+
return;
|
|
4054
|
+
const generation = ++dashboardGeneration;
|
|
4055
|
+
const renderContent = () => {
|
|
4056
|
+
try {
|
|
4057
|
+
context.keymap.layer(() => ({
|
|
4058
|
+
mode: "modal",
|
|
4059
|
+
enabled: () => dashboardOpen && scrollHandlers !== null && generation === dashboardGeneration,
|
|
4060
|
+
commands: [
|
|
4061
|
+
{
|
|
4062
|
+
bind: "up",
|
|
4063
|
+
title: "Scroll dashboard up",
|
|
4064
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4065
|
+
run: () => {
|
|
4066
|
+
try {
|
|
4067
|
+
scrollHandlers?.up();
|
|
4068
|
+
} catch {}
|
|
4069
|
+
}
|
|
4070
|
+
},
|
|
4071
|
+
{
|
|
4072
|
+
bind: "down",
|
|
4073
|
+
title: "Scroll dashboard down",
|
|
4074
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4075
|
+
run: () => {
|
|
4076
|
+
try {
|
|
4077
|
+
scrollHandlers?.down();
|
|
4078
|
+
} catch {}
|
|
4079
|
+
}
|
|
4080
|
+
},
|
|
4081
|
+
{
|
|
4082
|
+
bind: "pageup",
|
|
4083
|
+
title: "Page dashboard up",
|
|
4084
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4085
|
+
run: () => {
|
|
4086
|
+
try {
|
|
4087
|
+
scrollHandlers?.pageUp();
|
|
4088
|
+
} catch {}
|
|
4089
|
+
}
|
|
4090
|
+
},
|
|
4091
|
+
{
|
|
4092
|
+
bind: "pagedown",
|
|
4093
|
+
title: "Page dashboard down",
|
|
4094
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4095
|
+
run: () => {
|
|
4096
|
+
try {
|
|
4097
|
+
scrollHandlers?.pageDown();
|
|
4098
|
+
} catch {}
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
]
|
|
4102
|
+
}));
|
|
4103
|
+
} catch {}
|
|
4104
|
+
return DashboardRoute({
|
|
4105
|
+
sections: dashboardSections,
|
|
4106
|
+
snapshots: () => {
|
|
4107
|
+
const s = dashboardSessionID ?? activeSessionID();
|
|
4108
|
+
let snaps = s ? store.getSnapshots(s) : [];
|
|
4109
|
+
if (snaps.length === 0)
|
|
4110
|
+
snaps = store.getAllSnapshots();
|
|
4111
|
+
return snaps;
|
|
4112
|
+
},
|
|
4113
|
+
focusedGoalId: () => {
|
|
4114
|
+
const s = dashboardSessionID ?? activeSessionID();
|
|
4115
|
+
return resolveFocusedGoalId(store, s ?? null);
|
|
4116
|
+
},
|
|
4117
|
+
activeSessionID: dashboardSession,
|
|
4118
|
+
onSelectGoal: (goalId) => {
|
|
4119
|
+
sendGoalCommand(`focus ${goalId}`);
|
|
4120
|
+
},
|
|
4121
|
+
...dashboardGoalActions(store, () => dashboardSessionID ?? activeSessionID(), (c) => void sendGoalCommand(c)),
|
|
4122
|
+
onFocus: (goalId) => {
|
|
4123
|
+
sendGoalCommand(`focus ${goalId}`);
|
|
4124
|
+
},
|
|
4125
|
+
onClose: () => {
|
|
4126
|
+
dashboardOpen = false;
|
|
4127
|
+
dashboardSessionID = null;
|
|
4128
|
+
scrollHandlers = null;
|
|
4129
|
+
if (dashboardUnsubscribe) {
|
|
4130
|
+
try {
|
|
4131
|
+
dashboardUnsubscribe();
|
|
4132
|
+
} catch {}
|
|
4133
|
+
dashboardUnsubscribe = null;
|
|
4134
|
+
}
|
|
4135
|
+
try {
|
|
4136
|
+
context.ui.dialog.clear();
|
|
4137
|
+
} catch {}
|
|
4138
|
+
},
|
|
4139
|
+
registerScrollCommands: (handlers) => {
|
|
4140
|
+
scrollHandlers = handlers;
|
|
4141
|
+
},
|
|
4142
|
+
theme: () => dialogTheme(),
|
|
4143
|
+
footer: dashboardFooter(() => dashboardSessionID ?? activeSessionID()),
|
|
4144
|
+
hydrationText: store.getAllSnapshots().length === 0 ? `No goals found on disk for this workspace${lastHydration.dir ? ` (checked ${lastHydration.dir})` : ""}. Use /goal <condition> to set one.` : undefined
|
|
4145
|
+
});
|
|
4146
|
+
};
|
|
4147
|
+
const onClose = () => {
|
|
4148
|
+
if (generation === dashboardGeneration) {
|
|
4149
|
+
dashboardOpen = false;
|
|
4150
|
+
dashboardSessionID = null;
|
|
4151
|
+
scrollHandlers = null;
|
|
4152
|
+
if (dashboardUnsubscribe) {
|
|
4153
|
+
try {
|
|
4154
|
+
dashboardUnsubscribe();
|
|
4155
|
+
} catch {}
|
|
4156
|
+
dashboardUnsubscribe = null;
|
|
4157
|
+
}
|
|
4158
|
+
}
|
|
4159
|
+
};
|
|
4160
|
+
context.ui.dialog.show(renderContent, onClose);
|
|
4161
|
+
try {
|
|
4162
|
+
context.ui.dialog.set({ size: "xlarge", centered: true });
|
|
4163
|
+
} catch {}
|
|
4164
|
+
};
|
|
4165
|
+
const renderDashboard = async () => {
|
|
4166
|
+
const sid = activeSessionID();
|
|
4167
|
+
if (sid && store.getSnapshots(sid).length === 0 || !sid && store.getAllSnapshots().length === 0) {
|
|
4168
|
+
await ensureHydrated();
|
|
4169
|
+
}
|
|
4170
|
+
dashboardOpen = true;
|
|
4171
|
+
dashboardSessionID = sid;
|
|
4172
|
+
repaintDashboard();
|
|
4173
|
+
if (dashboardUnsubscribe) {
|
|
4174
|
+
try {
|
|
4175
|
+
dashboardUnsubscribe();
|
|
4176
|
+
} catch {}
|
|
4177
|
+
}
|
|
4178
|
+
dashboardUnsubscribe = store.subscribe((event) => {
|
|
4179
|
+
if (!dashboardOpen)
|
|
4180
|
+
return;
|
|
4181
|
+
const targetSid = dashboardSessionID ?? activeSessionID();
|
|
4182
|
+
if (targetSid && event.sessionID !== targetSid)
|
|
4183
|
+
return;
|
|
4184
|
+
repaintDashboard();
|
|
4185
|
+
});
|
|
4186
|
+
};
|
|
4187
|
+
const keymapDispatch = async (targeted, bare) => {
|
|
4188
|
+
const sid = dashboardSession();
|
|
4189
|
+
if (sid === null) {
|
|
4190
|
+
await sendGoalCommand(bare);
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
let goalId = resolveFocusedGoalId(store, sid);
|
|
4194
|
+
if (goalId === null) {
|
|
4195
|
+
await events?.refresh();
|
|
4196
|
+
goalId = resolveFocusedGoalId(store, sid);
|
|
4197
|
+
}
|
|
4198
|
+
if (goalId === null)
|
|
4199
|
+
return;
|
|
4200
|
+
await sendGoalCommand(targeted(goalId));
|
|
4201
|
+
};
|
|
4202
|
+
const keymapPromptThen = async (verb, prompt) => {
|
|
4203
|
+
const sid = dashboardSession();
|
|
4204
|
+
let goalId = sid === null ? null : resolveFocusedGoalId(store, sid);
|
|
4205
|
+
if (sid !== null && goalId === null) {
|
|
4206
|
+
await events?.refresh();
|
|
4207
|
+
goalId = resolveFocusedGoalId(store, sid);
|
|
4208
|
+
}
|
|
4209
|
+
if (sid !== null && goalId === null)
|
|
4210
|
+
return;
|
|
4211
|
+
const operand = await prompt();
|
|
4212
|
+
if (!operand)
|
|
4213
|
+
return;
|
|
4214
|
+
await sendGoalCommand(goalId === null ? `${verb} ${operand}` : `${verb} ${goalId} ${operand}`);
|
|
4215
|
+
};
|
|
4216
|
+
context.keymap.layer(() => ({
|
|
4217
|
+
mode: "global",
|
|
4218
|
+
commands: [
|
|
4219
|
+
{
|
|
4220
|
+
id: "fixate-on.dashboard",
|
|
4221
|
+
title: `${PRODUCT_DISPLAY_NAME}: Dashboard`,
|
|
4222
|
+
description: "Open the live goal dashboard",
|
|
4223
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4224
|
+
palette: true,
|
|
4225
|
+
bind: chord2("d"),
|
|
4226
|
+
run: async () => {
|
|
4227
|
+
await renderDashboard();
|
|
4228
|
+
}
|
|
4229
|
+
},
|
|
4230
|
+
{
|
|
4231
|
+
id: "fixate-on.pause",
|
|
4232
|
+
title: `${PRODUCT_DISPLAY_NAME}: Pause Goal`,
|
|
4233
|
+
description: "Pause the active goal",
|
|
4234
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4235
|
+
palette: true,
|
|
4236
|
+
bind: chord2("p"),
|
|
4237
|
+
run: async () => {
|
|
4238
|
+
await keymapDispatch((id) => `pause ${id}`, "pause");
|
|
4239
|
+
}
|
|
4240
|
+
},
|
|
4241
|
+
{
|
|
4242
|
+
id: "fixate-on.resume",
|
|
4243
|
+
title: `${PRODUCT_DISPLAY_NAME}: Resume Goal`,
|
|
4244
|
+
description: "Resume a paused goal",
|
|
4245
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4246
|
+
palette: true,
|
|
4247
|
+
bind: chord2("r"),
|
|
4248
|
+
run: async () => {
|
|
4249
|
+
await keymapDispatch((id) => `resume ${id}`, "resume");
|
|
4250
|
+
}
|
|
4251
|
+
},
|
|
4252
|
+
{
|
|
4253
|
+
id: "fixate-on.clear",
|
|
4254
|
+
title: `${PRODUCT_DISPLAY_NAME}: Clear Goals`,
|
|
4255
|
+
description: "Clear active goal(s)",
|
|
4256
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4257
|
+
palette: true,
|
|
4258
|
+
bind: chord2("c"),
|
|
4259
|
+
run: async () => {
|
|
4260
|
+
await keymapDispatch((id) => `clear ${id}`, "clear");
|
|
4261
|
+
}
|
|
4262
|
+
},
|
|
4263
|
+
{
|
|
4264
|
+
id: "fixate-on.list",
|
|
4265
|
+
title: `${PRODUCT_DISPLAY_NAME}: List Goals`,
|
|
4266
|
+
description: "List all active and archived goals",
|
|
4267
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4268
|
+
palette: true,
|
|
4269
|
+
run: async () => {
|
|
4270
|
+
await sendGoalCommand("list");
|
|
4271
|
+
}
|
|
4272
|
+
},
|
|
4273
|
+
{
|
|
4274
|
+
id: "fixate-on.history",
|
|
4275
|
+
title: `${PRODUCT_DISPLAY_NAME}: Show History`,
|
|
4276
|
+
description: "Show goal history and transition log",
|
|
4277
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4278
|
+
palette: true,
|
|
4279
|
+
run: async () => {
|
|
4280
|
+
await sendGoalCommand("history");
|
|
4281
|
+
}
|
|
4282
|
+
},
|
|
4283
|
+
{
|
|
4284
|
+
id: "fixate-on.edit",
|
|
4285
|
+
title: `${PRODUCT_DISPLAY_NAME}: Edit Objective`,
|
|
4286
|
+
description: "Edit objective of the active goal",
|
|
4287
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4288
|
+
palette: true,
|
|
4289
|
+
bind: chord2("e"),
|
|
4290
|
+
run: async () => {
|
|
4291
|
+
await keymapPromptThen("edit", () => context.ui.dialog.prompt({
|
|
4292
|
+
title: "Edit Goal",
|
|
4293
|
+
placeholder: "Updated objective"
|
|
4294
|
+
}));
|
|
4295
|
+
}
|
|
4296
|
+
},
|
|
4297
|
+
{
|
|
4298
|
+
id: "fixate-on.checkpoint",
|
|
4299
|
+
title: `${PRODUCT_DISPLAY_NAME}: Save Checkpoint`,
|
|
4300
|
+
description: "Save a checkpoint for the active goal",
|
|
4301
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4302
|
+
palette: true,
|
|
4303
|
+
bind: chord2("k"),
|
|
4304
|
+
run: async () => {
|
|
4305
|
+
await keymapPromptThen("checkpoint", () => context.ui.dialog.prompt({
|
|
4306
|
+
title: "Save Checkpoint",
|
|
4307
|
+
placeholder: "Checkpoint summary"
|
|
4308
|
+
}));
|
|
4309
|
+
}
|
|
4310
|
+
},
|
|
4311
|
+
{
|
|
4312
|
+
id: "fixate-on.focus",
|
|
4313
|
+
title: `${PRODUCT_DISPLAY_NAME}: Focus Goal`,
|
|
4314
|
+
description: "Focus a specific goal in the session",
|
|
4315
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4316
|
+
palette: true,
|
|
4317
|
+
bind: chord2("f"),
|
|
4318
|
+
run: async () => {
|
|
4319
|
+
const sid = activeSessionID();
|
|
4320
|
+
let goals = sid ? store.getSnapshots(sid) : [];
|
|
4321
|
+
if (goals.length === 0 && sid) {
|
|
4322
|
+
await ensureHydrated();
|
|
4323
|
+
goals = store.getSnapshots(sid);
|
|
4324
|
+
}
|
|
4325
|
+
if (goals.length === 0) {
|
|
4326
|
+
context.ui.toast.show({
|
|
4327
|
+
variant: "warning",
|
|
4328
|
+
title: PRODUCT_DISPLAY_NAME,
|
|
4329
|
+
message: "No active goals to focus."
|
|
4330
|
+
});
|
|
4331
|
+
return;
|
|
4332
|
+
}
|
|
4333
|
+
const goalId = await context.ui.dialog.select({
|
|
4334
|
+
title: "Focus Goal",
|
|
4335
|
+
options: goals.map((g, idx) => ({
|
|
4336
|
+
title: `${idx + 1}. ${g.condition}`,
|
|
4337
|
+
value: g.goalId,
|
|
4338
|
+
description: `Status: ${g.status}`
|
|
4339
|
+
}))
|
|
4340
|
+
});
|
|
4341
|
+
if (goalId) {
|
|
4342
|
+
await sendGoalCommand(`focus ${goalId}`);
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
},
|
|
4346
|
+
{
|
|
4347
|
+
id: "fixate-on.add",
|
|
4348
|
+
title: `${PRODUCT_DISPLAY_NAME}: Add Goal`,
|
|
4349
|
+
description: "Add a new goal to the session",
|
|
4350
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4351
|
+
palette: true,
|
|
4352
|
+
bind: chord2("a"),
|
|
4353
|
+
run: async () => {
|
|
4354
|
+
const obj = await context.ui.dialog.prompt({
|
|
4355
|
+
title: "Add New Goal",
|
|
4356
|
+
placeholder: "New goal objective"
|
|
4357
|
+
});
|
|
4358
|
+
if (obj) {
|
|
4359
|
+
await sendGoalCommand(`add ${obj}`);
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
},
|
|
4363
|
+
{
|
|
4364
|
+
id: "fixate-on.sequence",
|
|
4365
|
+
title: `${PRODUCT_DISPLAY_NAME}: Start Sequence`,
|
|
4366
|
+
description: "Start an ordered sequence of goals",
|
|
4367
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4368
|
+
palette: true,
|
|
4369
|
+
run: async () => {
|
|
4370
|
+
const t = await context.ui.dialog.prompt({
|
|
4371
|
+
title: "Start Goal Sequence",
|
|
4372
|
+
placeholder: "Objective 1; Objective 2; Objective 3"
|
|
4373
|
+
});
|
|
4374
|
+
if (t) {
|
|
4375
|
+
await sendGoalCommand(`sequence ${t}`);
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
},
|
|
4379
|
+
{
|
|
4380
|
+
id: "fixate-on.handback",
|
|
4381
|
+
title: `${PRODUCT_DISPLAY_NAME}: Handback Deliverables`,
|
|
4382
|
+
description: "Generate reviewable diff and handback deliverables",
|
|
4383
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4384
|
+
palette: true,
|
|
4385
|
+
bind: chord2("h"),
|
|
4386
|
+
run: async () => {
|
|
4387
|
+
await sendGoalCommand("handback");
|
|
4388
|
+
}
|
|
4389
|
+
},
|
|
4390
|
+
{
|
|
4391
|
+
id: "fixate-on.review-payload",
|
|
4392
|
+
title: `${PRODUCT_DISPLAY_NAME}: External Review Payload`,
|
|
4393
|
+
description: "Generate paste-ready external review payload",
|
|
4394
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4395
|
+
palette: true,
|
|
4396
|
+
run: async () => {
|
|
4397
|
+
await sendGoalCommand("review-payload");
|
|
4398
|
+
}
|
|
4399
|
+
},
|
|
4400
|
+
{
|
|
4401
|
+
id: "fixate-on.scroll.up",
|
|
4402
|
+
title: `${PRODUCT_DISPLAY_NAME}: Scroll Dashboard Up`,
|
|
4403
|
+
description: "Scroll the goal dashboard up one line",
|
|
4404
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4405
|
+
bind: "up",
|
|
4406
|
+
enabled: () => dashboardOpen && scrollHandlers !== null,
|
|
4407
|
+
run: () => {
|
|
4408
|
+
try {
|
|
4409
|
+
scrollHandlers?.up();
|
|
4410
|
+
} catch {}
|
|
4411
|
+
}
|
|
4412
|
+
},
|
|
4413
|
+
{
|
|
4414
|
+
id: "fixate-on.scroll.down",
|
|
4415
|
+
title: `${PRODUCT_DISPLAY_NAME}: Scroll Dashboard Down`,
|
|
4416
|
+
description: "Scroll the goal dashboard down one line",
|
|
4417
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4418
|
+
bind: "down",
|
|
4419
|
+
enabled: () => dashboardOpen && scrollHandlers !== null,
|
|
4420
|
+
run: () => {
|
|
4421
|
+
try {
|
|
4422
|
+
scrollHandlers?.down();
|
|
4423
|
+
} catch {}
|
|
4424
|
+
}
|
|
4425
|
+
},
|
|
4426
|
+
{
|
|
4427
|
+
id: "fixate-on.scroll.page-up",
|
|
4428
|
+
title: `${PRODUCT_DISPLAY_NAME}: Page Dashboard Up`,
|
|
4429
|
+
description: "Scroll the goal dashboard up one page",
|
|
4430
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4431
|
+
bind: "pageup",
|
|
4432
|
+
enabled: () => dashboardOpen && scrollHandlers !== null,
|
|
4433
|
+
run: () => {
|
|
4434
|
+
try {
|
|
4435
|
+
scrollHandlers?.pageUp();
|
|
4436
|
+
} catch {}
|
|
4437
|
+
}
|
|
4438
|
+
},
|
|
4439
|
+
{
|
|
4440
|
+
id: "fixate-on.scroll.page-down",
|
|
4441
|
+
title: `${PRODUCT_DISPLAY_NAME}: Page Dashboard Down`,
|
|
4442
|
+
description: "Scroll the goal dashboard down one page",
|
|
4443
|
+
group: PRODUCT_DISPLAY_NAME,
|
|
4444
|
+
bind: "pagedown",
|
|
4445
|
+
enabled: () => dashboardOpen && scrollHandlers !== null,
|
|
4446
|
+
run: () => {
|
|
4447
|
+
try {
|
|
4448
|
+
scrollHandlers?.pageDown();
|
|
4449
|
+
} catch {}
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
]
|
|
4453
|
+
}));
|
|
4454
|
+
log("info", "TUI companion initialized (v2) \u2014 subscribing to goal events.");
|
|
4455
|
+
events = wireV2Events({
|
|
4456
|
+
context,
|
|
4457
|
+
store,
|
|
4458
|
+
stateRoots,
|
|
4459
|
+
resolveWorkspaceDir,
|
|
4460
|
+
disarmWatchdogs,
|
|
4461
|
+
log
|
|
4462
|
+
});
|
|
4463
|
+
let disposeReceipt;
|
|
4464
|
+
const disposeOutput = wireGoalCommandOutput(context, (text) => {
|
|
4465
|
+
disposeReceipt = showGoalCommandReceipt(context, text);
|
|
4466
|
+
});
|
|
4467
|
+
return () => {
|
|
4468
|
+
disposeOutput();
|
|
4469
|
+
disposeReceipt?.();
|
|
4470
|
+
events?.dispose();
|
|
4471
|
+
for (const w of activeWatchdogs.values())
|
|
4472
|
+
clearTimeout(w.timer);
|
|
4473
|
+
activeWatchdogs.clear();
|
|
4474
|
+
if (dashboardRouteDispose) {
|
|
4475
|
+
try {
|
|
4476
|
+
dashboardRouteDispose();
|
|
4477
|
+
} catch {}
|
|
4478
|
+
}
|
|
4479
|
+
};
|
|
4480
|
+
}
|
|
4481
|
+
};
|
|
4482
|
+
|
|
4483
|
+
// src/tui.ts
|
|
4484
|
+
var entry = {
|
|
4485
|
+
id: "fixate-on-tui",
|
|
4486
|
+
tui: GoalTuiPlugin,
|
|
4487
|
+
setup: GoalTuiPluginV2.setup
|
|
4488
|
+
};
|
|
4489
|
+
var tui_default = entry;
|
|
4490
|
+
export {
|
|
4491
|
+
GOAL_TUI_EVENT_TITLE,
|
|
4492
|
+
GoalTuiPlugin,
|
|
4493
|
+
GoalTuiPluginV2,
|
|
4494
|
+
createGoalBroadcaster,
|
|
4495
|
+
createTuiStateStore,
|
|
4496
|
+
tui_default as default,
|
|
4497
|
+
parseTuiSyncEvent,
|
|
4498
|
+
serializeGoalForTui
|
|
4499
|
+
};
|