fixate-on 0.1.0 → 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/README.md +236 -257
- package/completion-verdict.schema.json +14 -20
- package/docs/tui-integration.md +46 -298
- package/index.d.ts +51 -49
- package/package.json +24 -21
- package/plugin/fixate-on/plugin.js +10417 -6044
- package/plugin/fixate-on/tui.js +2129 -204
- package/tui.d.ts +32 -14
- package/plugin/fixate-on/tui-v2.js +0 -2797
- package/tui-v2.d.ts +0 -27
package/plugin/fixate-on/tui.js
CHANGED
|
@@ -31,50 +31,26 @@ function formatRelativeTime(timestamp, now = Date.now()) {
|
|
|
31
31
|
var PRODUCT_DISPLAY_NAME = "Fixate";
|
|
32
32
|
|
|
33
33
|
// src/status-label.ts
|
|
34
|
-
function
|
|
35
|
-
const since = stoppedAt && stoppedAt > 0 ? stoppedAt : updatedAt;
|
|
36
|
-
if (!since || since <= 0)
|
|
37
|
-
return false;
|
|
38
|
-
if (since > now)
|
|
39
|
-
return true;
|
|
40
|
-
return now - since >= promiseMs;
|
|
41
|
-
}
|
|
42
|
-
function isSelfResolvingStop(status, stopReason, stoppedAt, now = Date.now(), updatedAt) {
|
|
34
|
+
function isSelfResolvingStop(status, stopReason) {
|
|
43
35
|
if (status !== "paused")
|
|
44
36
|
return false;
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
if (stopReason === USER_INTERVENTION_STOP_REASON && isYieldPastPromise(stoppedAt, now, YIELD_PROMISE_MS, updatedAt))
|
|
48
|
-
return false;
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
function isYieldingPause(status, stopReason) {
|
|
52
|
-
return status === "paused" && stopReason === USER_INTERVENTION_STOP_REASON;
|
|
53
|
-
}
|
|
54
|
-
function isLiveYield(status, stopReason, stoppedAt, now, updatedAt) {
|
|
55
|
-
if (!isYieldingPause(status, stopReason))
|
|
56
|
-
return false;
|
|
57
|
-
return !isYieldPastPromise(stoppedAt, now ?? Date.now(), YIELD_PROMISE_MS, updatedAt);
|
|
37
|
+
return SELF_RESOLVING_STOP_REASONS.has(stopReason ?? "");
|
|
58
38
|
}
|
|
59
|
-
function statusTag(status,
|
|
60
|
-
return
|
|
39
|
+
function statusTag(status, _stopReason) {
|
|
40
|
+
return status;
|
|
61
41
|
}
|
|
62
|
-
function stopReasonLabel(stopReason
|
|
63
|
-
if (stopReason
|
|
64
|
-
return
|
|
65
|
-
if (status !== undefined && !isLiveYield(status, stopReason, stoppedAt, now, updatedAt)) {
|
|
66
|
-
return "yielding to your message; did not re-arm";
|
|
42
|
+
function stopReasonLabel(stopReason) {
|
|
43
|
+
if (stopReason === USER_INTERVENTION_STOP_REASON) {
|
|
44
|
+
return "paused by an earlier message; run /goal resume";
|
|
67
45
|
}
|
|
68
|
-
return
|
|
46
|
+
return stopReason;
|
|
69
47
|
}
|
|
70
|
-
var USER_INTERVENTION_STOP_REASON = "user intervention", SELF_RESOLVING_STOP_REASONS
|
|
48
|
+
var USER_INTERVENTION_STOP_REASON = "user intervention", SELF_RESOLVING_STOP_REASONS;
|
|
71
49
|
var init_status_label = __esm(() => {
|
|
72
50
|
SELF_RESOLVING_STOP_REASONS = new Set([
|
|
73
51
|
"recovery",
|
|
74
|
-
"user intervention",
|
|
75
52
|
"queued"
|
|
76
53
|
]);
|
|
77
|
-
YIELD_PROMISE_MS = 15 * 60000;
|
|
78
54
|
});
|
|
79
55
|
|
|
80
56
|
// src/accounting.ts
|
|
@@ -121,14 +97,6 @@ function normalizeMessageUsage(message) {
|
|
|
121
97
|
costKnown: rawCost != null && Number.isFinite(Number(rawCost)) && Number(rawCost) >= 0
|
|
122
98
|
};
|
|
123
99
|
}
|
|
124
|
-
function addToUsageField(total, field, delta) {
|
|
125
|
-
const next = normalizeUsage(total);
|
|
126
|
-
const current = next[field];
|
|
127
|
-
if (typeof current === "number") {
|
|
128
|
-
next[field] = current + delta;
|
|
129
|
-
}
|
|
130
|
-
return next;
|
|
131
|
-
}
|
|
132
100
|
function addUsageDelta(total, current, previous, isNewStep = false) {
|
|
133
101
|
const next = normalizeUsage(total);
|
|
134
102
|
const cur = normalizeUsage(current);
|
|
@@ -297,7 +265,7 @@ function fallbackNotice(goals, activeSessionID) {
|
|
|
297
265
|
function goalListRow(goal, index, activeSessionID) {
|
|
298
266
|
const foreign = isForeignGoal(goal, activeSessionID);
|
|
299
267
|
return {
|
|
300
|
-
title: `${index + 1}. [${statusTag(goal.status
|
|
268
|
+
title: `${index + 1}. [${statusTag(goal.status)}] ${goal.condition.substring(0, 60)}`,
|
|
301
269
|
description: (foreign ? `Another session (${foreignSessionLabel(goal)}) | ` : "") + `Tokens: ${goal.totalTokens}/${brakeCeiling(goal.maxTokens)} Turns: ${goal.turnCount}/${brakeCeiling(goal.maxTurns)}`
|
|
302
270
|
};
|
|
303
271
|
}
|
|
@@ -341,7 +309,7 @@ function goalCardLines(goal, activeSessionID) {
|
|
|
341
309
|
if (goal.stopReason) {
|
|
342
310
|
lines.push({
|
|
343
311
|
subdued: true,
|
|
344
|
-
text: ` Stop: ${stopReasonLabel(goal.stopReason
|
|
312
|
+
text: ` Stop: ${stopReasonLabel(goal.stopReason)}`
|
|
345
313
|
});
|
|
346
314
|
}
|
|
347
315
|
lines.push({ text: ` ${tokenGauge(goal.totalTokens, goal.maxTokens)}` });
|
|
@@ -377,7 +345,7 @@ function formatGoalStatusDashboard(goals, activeSessionID = null) {
|
|
|
377
345
|
lines.push(` Session: ${foreignSessionLabel(goal)} (another session)`);
|
|
378
346
|
}
|
|
379
347
|
if (goal.stopReason) {
|
|
380
|
-
lines.push(` Stop: ${stopReasonLabel(goal.stopReason
|
|
348
|
+
lines.push(` Stop: ${stopReasonLabel(goal.stopReason)}`);
|
|
381
349
|
}
|
|
382
350
|
if (goal.blockedReason) {
|
|
383
351
|
lines.push(` Blocked: ${goal.blockedReason}`);
|
|
@@ -459,6 +427,129 @@ var init_tui_views = __esm(() => {
|
|
|
459
427
|
];
|
|
460
428
|
});
|
|
461
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
|
+
|
|
462
553
|
// src/tui-state.ts
|
|
463
554
|
var GOAL_TUI_EVENT_TITLE = "fixate-on";
|
|
464
555
|
var VALID_GOAL_STATUSES = new Set([
|
|
@@ -469,31 +560,15 @@ var VALID_GOAL_STATUSES = new Set([
|
|
|
469
560
|
"finalizing",
|
|
470
561
|
"complete"
|
|
471
562
|
]);
|
|
472
|
-
var memoHistoryRef = null;
|
|
473
|
-
var memoHistoryLen = -1;
|
|
474
|
-
var memoHistoryFrozen = [];
|
|
475
|
-
function frozenHistory(history) {
|
|
476
|
-
if (history === memoHistoryRef && history.length === memoHistoryLen) {
|
|
477
|
-
return memoHistoryFrozen;
|
|
478
|
-
}
|
|
479
|
-
memoHistoryRef = history;
|
|
480
|
-
memoHistoryLen = history.length;
|
|
481
|
-
memoHistoryFrozen = deepFreeze(history.map((h) => ({
|
|
482
|
-
type: h.type,
|
|
483
|
-
detail: h.detail,
|
|
484
|
-
timestamp: h.timestamp
|
|
485
|
-
})));
|
|
486
|
-
return memoHistoryFrozen;
|
|
487
|
-
}
|
|
488
563
|
function serializeGoalForTui(state) {
|
|
489
564
|
const snapshot = {
|
|
490
565
|
goalId: state.goalId,
|
|
491
566
|
sessionID: state.sessionID,
|
|
492
567
|
condition: state.condition,
|
|
493
568
|
artifactPointers: state.artifactPointers ? [...state.artifactPointers] : [],
|
|
494
|
-
pendingProposal: state.pendingProposal ?
|
|
495
|
-
claims: state.claims ? state.claims.map(
|
|
496
|
-
lastClaim: state.lastClaim ?
|
|
569
|
+
pendingProposal: state.pendingProposal ? copyGoalProposal(state.pendingProposal) : null,
|
|
570
|
+
claims: state.claims ? state.claims.map(copyClaimRecord) : [],
|
|
571
|
+
lastClaim: state.lastClaim ? copyClaimRecord(state.lastClaim) : null,
|
|
497
572
|
status: state.status,
|
|
498
573
|
revision: state.revision,
|
|
499
574
|
turnCount: state.turnCount,
|
|
@@ -521,7 +596,11 @@ function serializeGoalForTui(state) {
|
|
|
521
596
|
summary: state.lastCheckpoint.summary,
|
|
522
597
|
timestamp: state.lastCheckpoint.timestamp
|
|
523
598
|
} : null,
|
|
524
|
-
history:
|
|
599
|
+
history: state.history.map((entry) => ({
|
|
600
|
+
type: entry.type,
|
|
601
|
+
detail: entry.detail,
|
|
602
|
+
timestamp: entry.timestamp
|
|
603
|
+
}))
|
|
525
604
|
};
|
|
526
605
|
return deepFreeze(snapshot);
|
|
527
606
|
}
|
|
@@ -551,7 +630,7 @@ function validateTuiEvent(value) {
|
|
|
551
630
|
if (typeof sessionID !== "string" || sessionID.length === 0)
|
|
552
631
|
return null;
|
|
553
632
|
const timestamp = obj.timestamp;
|
|
554
|
-
if (
|
|
633
|
+
if (!isNonNegativeFinite(timestamp))
|
|
555
634
|
return null;
|
|
556
635
|
if (kind === "remove") {
|
|
557
636
|
const goalId = obj.goalId;
|
|
@@ -564,22 +643,26 @@ function validateTuiEvent(value) {
|
|
|
564
643
|
return null;
|
|
565
644
|
if (snapshot.sessionID !== sessionID)
|
|
566
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 };
|
|
567
650
|
if (kind === "transition") {
|
|
568
651
|
const transition = validateTransition(obj.transition);
|
|
569
652
|
if (!transition)
|
|
570
653
|
return null;
|
|
571
|
-
return { kind, sessionID, timestamp, snapshot, transition };
|
|
654
|
+
return { kind, sessionID, timestamp, snapshot, transition, ...prior };
|
|
572
655
|
}
|
|
573
|
-
return { kind, sessionID, timestamp, snapshot };
|
|
656
|
+
return { kind, sessionID, timestamp, snapshot, ...prior };
|
|
574
657
|
}
|
|
575
658
|
function validateSnapshot(value) {
|
|
576
|
-
if (!value || typeof value !== "object")
|
|
659
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
577
660
|
return null;
|
|
578
661
|
const s = value;
|
|
579
|
-
if (typeof s.goalId !== "string" || typeof s.sessionID !== "string" || typeof s.condition !== "string" || typeof s.status !== "string" || !VALID_GOAL_STATUSES.has(s.status) ||
|
|
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)) {
|
|
580
663
|
return null;
|
|
581
664
|
}
|
|
582
|
-
if (s.finishedAt !== null &&
|
|
665
|
+
if (s.finishedAt !== null && !isNonNegativeFinite(s.finishedAt))
|
|
583
666
|
return null;
|
|
584
667
|
const usage = validateUsage(s.usage);
|
|
585
668
|
if (!usage)
|
|
@@ -590,7 +673,11 @@ function validateSnapshot(value) {
|
|
|
590
673
|
const checkpoint = validateCheckpoint(s.lastCheckpoint);
|
|
591
674
|
if (checkpoint === INVALID_CHECKPOINT)
|
|
592
675
|
return null;
|
|
676
|
+
const details = parseTuiSnapshotDetails(s);
|
|
677
|
+
if (details === null)
|
|
678
|
+
return null;
|
|
593
679
|
const snapshot = {
|
|
680
|
+
...details,
|
|
594
681
|
goalId: s.goalId,
|
|
595
682
|
sessionID: s.sessionID,
|
|
596
683
|
condition: s.condition,
|
|
@@ -618,7 +705,7 @@ function validateUsage(value) {
|
|
|
618
705
|
if (!value || typeof value !== "object")
|
|
619
706
|
return null;
|
|
620
707
|
const u = value;
|
|
621
|
-
if (
|
|
708
|
+
if (!isNonNegativeFinite(u.input) || !isNonNegativeFinite(u.output) || !isNonNegativeFinite(u.reasoning) || !isNonNegativeFinite(u.cacheRead) || !isNonNegativeFinite(u.cacheWrite) || !isNonNegativeFinite(u.cost) || typeof u.costKnown !== "boolean") {
|
|
622
709
|
return null;
|
|
623
710
|
}
|
|
624
711
|
return {
|
|
@@ -639,7 +726,7 @@ function validateHistory(value) {
|
|
|
639
726
|
if (!entry || typeof entry !== "object")
|
|
640
727
|
return null;
|
|
641
728
|
const e = entry;
|
|
642
|
-
if (typeof e.type !== "string" || typeof e.detail !== "string" ||
|
|
729
|
+
if (typeof e.type !== "string" || typeof e.detail !== "string" || !isNonNegativeFinite(e.timestamp)) {
|
|
643
730
|
return null;
|
|
644
731
|
}
|
|
645
732
|
result.push({ type: e.type, detail: e.detail, timestamp: e.timestamp });
|
|
@@ -653,7 +740,7 @@ function validateCheckpoint(value) {
|
|
|
653
740
|
if (!value || typeof value !== "object")
|
|
654
741
|
return INVALID_CHECKPOINT;
|
|
655
742
|
const c = value;
|
|
656
|
-
if (typeof c.summary !== "string" ||
|
|
743
|
+
if (typeof c.summary !== "string" || !isNonNegativeFinite(c.timestamp))
|
|
657
744
|
return INVALID_CHECKPOINT;
|
|
658
745
|
return { summary: c.summary, timestamp: c.timestamp };
|
|
659
746
|
}
|
|
@@ -661,7 +748,7 @@ function validateTransition(value) {
|
|
|
661
748
|
if (!value || typeof value !== "object")
|
|
662
749
|
return null;
|
|
663
750
|
const t = value;
|
|
664
|
-
if (typeof t.source !== "string" || typeof t.from !== "string" || typeof t.to !== "string" || typeof t.detail !== "string") {
|
|
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") {
|
|
665
752
|
return null;
|
|
666
753
|
}
|
|
667
754
|
return {
|
|
@@ -749,6 +836,28 @@ function createTuiStateStore() {
|
|
|
749
836
|
return;
|
|
750
837
|
return session.goals.get(session.focusedId);
|
|
751
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
|
+
}
|
|
752
861
|
function subscribe(fn) {
|
|
753
862
|
subscribers.add(fn);
|
|
754
863
|
return () => subscribers.delete(fn);
|
|
@@ -763,6 +872,7 @@ function createTuiStateStore() {
|
|
|
763
872
|
getAllSnapshots,
|
|
764
873
|
getSnapshot,
|
|
765
874
|
getFocused,
|
|
875
|
+
setFocused,
|
|
766
876
|
subscribe,
|
|
767
877
|
clear
|
|
768
878
|
};
|
|
@@ -922,11 +1032,11 @@ async function portableReadBounded(filePath, maxBytes = MAX_STATE_FILE_BYTES) {
|
|
|
922
1032
|
await handle.close();
|
|
923
1033
|
}
|
|
924
1034
|
}
|
|
925
|
-
async function portableWriteFile(filePath, data, mode = 384) {
|
|
1035
|
+
async function portableWriteFile(filePath, data, mode = 384, commit) {
|
|
926
1036
|
const { dirname } = await import("path");
|
|
927
1037
|
const { open } = await import("fs/promises");
|
|
928
1038
|
const { randomUUID } = await import("crypto");
|
|
929
|
-
const { constants } = await import("fs");
|
|
1039
|
+
const { constants, renameSync } = await import("fs");
|
|
930
1040
|
await fsMkdir(dirname(filePath), { recursive: true, mode: 448 });
|
|
931
1041
|
const temporaryPath = `${filePath}.tmp-${randomUUID()}`;
|
|
932
1042
|
let installed = false;
|
|
@@ -951,27 +1061,42 @@ async function portableWriteFile(filePath, data, mode = 384) {
|
|
|
951
1061
|
if (existing && !existing.isFile()) {
|
|
952
1062
|
throw new Error(`refusing to replace non-regular state file: ${filePath}`);
|
|
953
1063
|
}
|
|
1064
|
+
commit?.beforeInstall();
|
|
954
1065
|
try {
|
|
955
|
-
|
|
1066
|
+
if (commit)
|
|
1067
|
+
renameSync(temporaryPath, filePath);
|
|
1068
|
+
else
|
|
1069
|
+
await fsRename(temporaryPath, filePath);
|
|
956
1070
|
installed = true;
|
|
957
1071
|
} catch (renameError) {
|
|
958
1072
|
if (!existing)
|
|
959
1073
|
throw renameError;
|
|
960
1074
|
backupPath = `${filePath}.bak-${randomUUID()}`;
|
|
961
|
-
|
|
1075
|
+
if (commit)
|
|
1076
|
+
renameSync(filePath, backupPath);
|
|
1077
|
+
else
|
|
1078
|
+
await fsRename(filePath, backupPath);
|
|
962
1079
|
try {
|
|
963
|
-
|
|
1080
|
+
if (commit)
|
|
1081
|
+
renameSync(temporaryPath, filePath);
|
|
1082
|
+
else
|
|
1083
|
+
await fsRename(temporaryPath, filePath);
|
|
964
1084
|
installed = true;
|
|
965
1085
|
} catch (fallbackError) {
|
|
966
1086
|
try {
|
|
967
|
-
|
|
1087
|
+
if (commit)
|
|
1088
|
+
renameSync(backupPath, filePath);
|
|
1089
|
+
else
|
|
1090
|
+
await fsRename(backupPath, filePath);
|
|
968
1091
|
} catch (restoreError) {
|
|
969
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 });
|
|
970
1093
|
}
|
|
971
1094
|
throw fallbackError;
|
|
972
1095
|
}
|
|
973
|
-
await fsUnlink(backupPath).catch(() => {});
|
|
974
1096
|
}
|
|
1097
|
+
commit?.afterInstall();
|
|
1098
|
+
if (backupPath)
|
|
1099
|
+
await fsUnlink(backupPath).catch(() => {});
|
|
975
1100
|
try {
|
|
976
1101
|
const directory = await open(dirname(filePath), constants.O_RDONLY);
|
|
977
1102
|
try {
|
|
@@ -1107,40 +1232,6 @@ async function discoverStateFiles(directory, explicitPath, stateRoot) {
|
|
|
1107
1232
|
return [];
|
|
1108
1233
|
}
|
|
1109
1234
|
}
|
|
1110
|
-
async function hydrateStoreFromDisk(store, directory, explicitPath, stateRoot) {
|
|
1111
|
-
const foundPaths = await discoverStateFiles(directory, explicitPath, stateRoot);
|
|
1112
|
-
let hydratedCount = 0;
|
|
1113
|
-
for (const foundPath of foundPaths) {
|
|
1114
|
-
const count = await hydrateFromStateFile(store, foundPath);
|
|
1115
|
-
hydratedCount += count;
|
|
1116
|
-
}
|
|
1117
|
-
return { hydratedCount };
|
|
1118
|
-
}
|
|
1119
|
-
async function hydrateFromStateFile(store, filePath) {
|
|
1120
|
-
try {
|
|
1121
|
-
const { text, truncated } = await portableReadBounded(filePath);
|
|
1122
|
-
if (truncated)
|
|
1123
|
-
return 0;
|
|
1124
|
-
if (!text.trim())
|
|
1125
|
-
return 0;
|
|
1126
|
-
const parsed = parseStateJson(text);
|
|
1127
|
-
if (!parsed)
|
|
1128
|
-
return 0;
|
|
1129
|
-
const snapshots = snapshotsFromParsed(parsed, sessionIDFromStatePath(filePath));
|
|
1130
|
-
for (const snapshot of snapshots) {
|
|
1131
|
-
store.applyEvent({
|
|
1132
|
-
kind: "create",
|
|
1133
|
-
sessionID: snapshot.sessionID,
|
|
1134
|
-
goalId: snapshot.goalId,
|
|
1135
|
-
snapshot: { ...snapshot, origin: "disk" },
|
|
1136
|
-
timestamp: Date.now()
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
return snapshots.length;
|
|
1140
|
-
} catch {
|
|
1141
|
-
return 0;
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
1235
|
function parseStateJson(content) {
|
|
1145
1236
|
try {
|
|
1146
1237
|
return JSON.parse(content);
|
|
@@ -1173,7 +1264,7 @@ function snapshotsFromParsed(parsed, originSessionID) {
|
|
|
1173
1264
|
revision: typeof r.revision === "number" ? r.revision : 0,
|
|
1174
1265
|
turnCount: typeof r.turnCount === "number" ? r.turnCount : 0,
|
|
1175
1266
|
totalTokens: typeof r.totalTokens === "number" ? r.totalTokens : 0,
|
|
1176
|
-
maxTokens: typeof r.maxTokens === "number" ? r.maxTokens :
|
|
1267
|
+
maxTokens: typeof r.maxTokens === "number" ? r.maxTokens : 0,
|
|
1177
1268
|
maxTurns: typeof r.maxTurns === "number" ? r.maxTurns : 0,
|
|
1178
1269
|
tokenBudget: typeof r.tokenBudget === "number" ? r.tokenBudget : null,
|
|
1179
1270
|
usage: r.usage ?? {
|
|
@@ -1205,11 +1296,58 @@ function snapshotsFromParsed(parsed, originSessionID) {
|
|
|
1205
1296
|
}
|
|
1206
1297
|
return out;
|
|
1207
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
|
+
}
|
|
1208
1344
|
async function readDiskGoalSnapshots(directory, explicitPath, stateRoot) {
|
|
1209
1345
|
const { join } = await import("path");
|
|
1210
1346
|
const foundPaths = await discoverStateFiles(directory, explicitPath, stateRoot);
|
|
1211
1347
|
const out = [];
|
|
1212
1348
|
const readableSessions = new Set;
|
|
1349
|
+
const archivedResults = new Map;
|
|
1350
|
+
const focusedGoalIds = new Map;
|
|
1213
1351
|
let filesRead = 0;
|
|
1214
1352
|
for (const p of foundPaths) {
|
|
1215
1353
|
try {
|
|
@@ -1229,6 +1367,12 @@ async function readDiskGoalSnapshots(directory, explicitPath, stateRoot) {
|
|
|
1229
1367
|
for (const s of snaps)
|
|
1230
1368
|
readableSessions.add(s.sessionID);
|
|
1231
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
|
+
}
|
|
1232
1376
|
} catch {}
|
|
1233
1377
|
}
|
|
1234
1378
|
let stateDirMissing = false;
|
|
@@ -1242,7 +1386,14 @@ async function readDiskGoalSnapshots(directory, explicitPath, stateRoot) {
|
|
|
1242
1386
|
} catch {
|
|
1243
1387
|
stateDirMissing = true;
|
|
1244
1388
|
}
|
|
1245
|
-
return {
|
|
1389
|
+
return {
|
|
1390
|
+
snapshots: out,
|
|
1391
|
+
filesRead,
|
|
1392
|
+
stateDirMissing,
|
|
1393
|
+
readableSessions,
|
|
1394
|
+
archivedResults,
|
|
1395
|
+
focusedGoalIds
|
|
1396
|
+
};
|
|
1246
1397
|
}
|
|
1247
1398
|
|
|
1248
1399
|
// src/tui-companion-refresh.ts
|
|
@@ -1253,31 +1404,37 @@ function createDiskRefreshLoop(options) {
|
|
|
1253
1404
|
const { store, onEvent } = options;
|
|
1254
1405
|
const intervalMs = options.intervalMs ?? 1000;
|
|
1255
1406
|
let timer = null;
|
|
1256
|
-
let
|
|
1407
|
+
let pending = null;
|
|
1408
|
+
let cancelRead = null;
|
|
1409
|
+
let generation = 0;
|
|
1410
|
+
let stopped = false;
|
|
1257
1411
|
let baselined = false;
|
|
1258
1412
|
let previous = new Map;
|
|
1259
|
-
function synthesize(current, readableSessions) {
|
|
1413
|
+
function synthesize(current, readableSessions, archivedResults) {
|
|
1260
1414
|
const events = [];
|
|
1261
1415
|
const seen = new Set;
|
|
1416
|
+
const now = Date.now();
|
|
1262
1417
|
for (const snap of current) {
|
|
1263
1418
|
const key = keyOf(snap.sessionID, snap.goalId);
|
|
1264
1419
|
seen.add(key);
|
|
1265
1420
|
const prev = previous.get(key);
|
|
1266
1421
|
if (!prev) {
|
|
1267
|
-
|
|
1422
|
+
const ev = {
|
|
1268
1423
|
kind: "create",
|
|
1269
1424
|
sessionID: snap.sessionID,
|
|
1270
|
-
timestamp:
|
|
1425
|
+
timestamp: now,
|
|
1271
1426
|
snapshot: { ...snap, origin: "disk" }
|
|
1272
|
-
}
|
|
1427
|
+
};
|
|
1428
|
+
events.push({ storeEvent: ev, notifyEvent: ev });
|
|
1273
1429
|
} else if (prev.revision !== snap.revision || prev.status !== snap.status || prev.totalTokens !== snap.totalTokens || prev.turnCount !== snap.turnCount) {
|
|
1274
|
-
|
|
1430
|
+
const ev = {
|
|
1275
1431
|
kind: "transition",
|
|
1276
1432
|
sessionID: snap.sessionID,
|
|
1277
|
-
timestamp:
|
|
1433
|
+
timestamp: now,
|
|
1278
1434
|
snapshot: { ...snap, origin: "disk" },
|
|
1279
1435
|
previousStatus: prev.status
|
|
1280
|
-
}
|
|
1436
|
+
};
|
|
1437
|
+
events.push({ storeEvent: ev, notifyEvent: ev });
|
|
1281
1438
|
}
|
|
1282
1439
|
}
|
|
1283
1440
|
for (const [key, prev] of previous) {
|
|
@@ -1285,34 +1442,107 @@ function createDiskRefreshLoop(options) {
|
|
|
1285
1442
|
continue;
|
|
1286
1443
|
if (!readableSessions.has(prev.sessionID))
|
|
1287
1444
|
continue;
|
|
1288
|
-
|
|
1445
|
+
const removeEvent = {
|
|
1289
1446
|
kind: "remove",
|
|
1290
1447
|
sessionID: prev.sessionID,
|
|
1291
1448
|
goalId: prev.goalId,
|
|
1292
|
-
|
|
1293
|
-
|
|
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 });
|
|
1294
1487
|
}
|
|
1295
1488
|
return events;
|
|
1296
1489
|
}
|
|
1297
|
-
async function
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
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;
|
|
1301
1503
|
try {
|
|
1302
1504
|
const read = await readDiskGoalSnapshots(options.directory, options.explicitPath, options.stateRoot);
|
|
1505
|
+
if (stopped || started !== generation)
|
|
1506
|
+
return;
|
|
1507
|
+
unsubscribe();
|
|
1508
|
+
const initial = !baselined;
|
|
1303
1509
|
if (!baselined) {
|
|
1304
1510
|
if (read.filesRead === 0 && !read.stateDirMissing)
|
|
1305
1511
|
return;
|
|
1306
1512
|
baselined = true;
|
|
1307
|
-
previous = new Map(read.snapshots.map((s) => [keyOf(s.sessionID, s.goalId), s]));
|
|
1308
|
-
return;
|
|
1309
1513
|
}
|
|
1310
1514
|
if (read.filesRead === 0 && previous.size > 0)
|
|
1311
1515
|
return;
|
|
1312
|
-
for (const
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
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
|
+
}
|
|
1316
1546
|
}
|
|
1317
1547
|
const oldPrevious = previous;
|
|
1318
1548
|
previous = new Map(read.snapshots.map((s) => [keyOf(s.sessionID, s.goalId), s]));
|
|
@@ -1321,19 +1551,41 @@ function createDiskRefreshLoop(options) {
|
|
|
1321
1551
|
previous.set(key, snap);
|
|
1322
1552
|
}
|
|
1323
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
|
+
}
|
|
1324
1564
|
} catch {} finally {
|
|
1325
|
-
|
|
1565
|
+
unsubscribe();
|
|
1566
|
+
if (cancelRead === unsubscribe)
|
|
1567
|
+
cancelRead = null;
|
|
1326
1568
|
}
|
|
1327
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
|
+
}
|
|
1328
1582
|
return {
|
|
1329
1583
|
tick,
|
|
1330
|
-
|
|
1331
|
-
baselined = true;
|
|
1332
|
-
previous = new Map(snapshots.map((s) => [keyOf(s.sessionID, s.goalId), s]));
|
|
1333
|
-
},
|
|
1584
|
+
getSnapshots: () => [...previous.values()],
|
|
1334
1585
|
start() {
|
|
1335
1586
|
if (timer)
|
|
1336
1587
|
return;
|
|
1588
|
+
stopped = false;
|
|
1337
1589
|
if (!baselined)
|
|
1338
1590
|
tick();
|
|
1339
1591
|
timer = setInterval(() => void tick(), intervalMs);
|
|
@@ -1342,6 +1594,11 @@ function createDiskRefreshLoop(options) {
|
|
|
1342
1594
|
}
|
|
1343
1595
|
},
|
|
1344
1596
|
stop() {
|
|
1597
|
+
stopped = true;
|
|
1598
|
+
generation++;
|
|
1599
|
+
cancelRead?.();
|
|
1600
|
+
cancelRead = null;
|
|
1601
|
+
pending = null;
|
|
1345
1602
|
if (timer) {
|
|
1346
1603
|
clearInterval(timer);
|
|
1347
1604
|
timer = null;
|
|
@@ -1516,9 +1773,6 @@ function limitPausePhrase(stopReason) {
|
|
|
1516
1773
|
}
|
|
1517
1774
|
return isLimitOrEscalationPause(stopReason) ? "Goal stopped by a limit it reached" : null;
|
|
1518
1775
|
}
|
|
1519
|
-
var YIELDING_STOP_REASONS = new Set([
|
|
1520
|
-
USER_INTERVENTION_STOP_REASON
|
|
1521
|
-
]);
|
|
1522
1776
|
var NEEDS_YOU_PHRASES = [
|
|
1523
1777
|
[/tool surface unavailable/i, "the goal tools are gone"],
|
|
1524
1778
|
[
|
|
@@ -1526,7 +1780,7 @@ var NEEDS_YOU_PHRASES = [
|
|
|
1526
1780
|
"a verifier stopped it"
|
|
1527
1781
|
],
|
|
1528
1782
|
[
|
|
1529
|
-
/unattested completion asserted repeatedly|no attestation/i,
|
|
1783
|
+
/unattested completion asserted repeatedly|no attestation|unattestable/i,
|
|
1530
1784
|
"the claim could not be attested"
|
|
1531
1785
|
],
|
|
1532
1786
|
[/judge rejected/i, "the judge rejected the claim"],
|
|
@@ -1542,6 +1796,8 @@ var NEEDS_YOU_PHRASES = [
|
|
|
1542
1796
|
];
|
|
1543
1797
|
var MACHINE_STRING = /[()]|\w+:|[a-z][A-Z]|_/;
|
|
1544
1798
|
function needsYouReason(stopReason) {
|
|
1799
|
+
if (stopReason === USER_INTERVENTION_STOP_REASON)
|
|
1800
|
+
return "paused";
|
|
1545
1801
|
for (const [pattern, phrase] of NEEDS_YOU_PHRASES) {
|
|
1546
1802
|
if (pattern.test(stopReason))
|
|
1547
1803
|
return phrase;
|
|
@@ -1551,21 +1807,18 @@ function needsYouReason(stopReason) {
|
|
|
1551
1807
|
return "stopped for a reason the plugin did not name";
|
|
1552
1808
|
return truncateCondition(clean);
|
|
1553
1809
|
}
|
|
1554
|
-
function goalNeedsTheUser(snapshot,
|
|
1810
|
+
function goalNeedsTheUser(snapshot, _now) {
|
|
1555
1811
|
const status = snapshot.status;
|
|
1556
1812
|
if (status === "active" || status === "finalizing" || status === "complete")
|
|
1557
1813
|
return false;
|
|
1558
|
-
if (isSelfResolvingStop(status, snapshot.stopReason
|
|
1814
|
+
if (isSelfResolvingStop(status, snapshot.stopReason))
|
|
1559
1815
|
return false;
|
|
1560
1816
|
return true;
|
|
1561
1817
|
}
|
|
1562
|
-
function reasonForGoal(snapshot,
|
|
1818
|
+
function reasonForGoal(snapshot, _now) {
|
|
1563
1819
|
if (snapshot.status === "blocked") {
|
|
1564
1820
|
return snapshot.blockedReason ? truncateCondition(snapshot.blockedReason, 40) : "blocked";
|
|
1565
1821
|
}
|
|
1566
|
-
if (isYieldingPause(snapshot.status, snapshot.stopReason) && !isLiveYield(snapshot.status, snapshot.stopReason, snapshot.stoppedAt, now ?? Date.now(), snapshot.updatedAt)) {
|
|
1567
|
-
return "it did not pick your message back up";
|
|
1568
|
-
}
|
|
1569
1822
|
if (snapshot.status === "budgetLimited" && !snapshot.stopReason)
|
|
1570
1823
|
return "the token budget ran out";
|
|
1571
1824
|
return needsYouReason(snapshot.stopReason);
|
|
@@ -1632,7 +1885,7 @@ function formatCuratedToast(event, startAnnouncement = true) {
|
|
|
1632
1885
|
const suffix = outcomeStatus && outcomeStatus !== "verified-complete" ? ` (${CLAIM_PLAIN[outcomeStatus] ?? outcomeStatus})` : "";
|
|
1633
1886
|
return {
|
|
1634
1887
|
title: PRODUCT_DISPLAY_NAME,
|
|
1635
|
-
variant: "info",
|
|
1888
|
+
variant: suffix ? "info" : "success",
|
|
1636
1889
|
message: `Goal complete: ${condition}${suffix}`
|
|
1637
1890
|
};
|
|
1638
1891
|
}
|
|
@@ -1696,7 +1949,6 @@ class ToastCoalescer {
|
|
|
1696
1949
|
lastEmittedAt = new Map;
|
|
1697
1950
|
lastMessageBySession = new Map;
|
|
1698
1951
|
announced = new Set;
|
|
1699
|
-
yielding = new Set;
|
|
1700
1952
|
pumpTimer = null;
|
|
1701
1953
|
constructor(emit, now = Date.now, autoFlushMs = null) {
|
|
1702
1954
|
this.emit = emit;
|
|
@@ -1717,23 +1969,13 @@ class ToastCoalescer {
|
|
|
1717
1969
|
if (memoryKey) {
|
|
1718
1970
|
if (event.kind === "remove" && event.goalId) {
|
|
1719
1971
|
this.announced.delete(memoryKey);
|
|
1720
|
-
this.yielding.delete(memoryKey);
|
|
1721
1972
|
} else if (event.kind === "create") {
|
|
1722
1973
|
this.claimStartAnnouncement(sessionKey, goalId);
|
|
1723
|
-
} else if (event.snapshot?.status === "paused" && YIELDING_STOP_REASONS.has(event.snapshot.stopReason)) {
|
|
1724
|
-
this.yielding.add(memoryKey);
|
|
1725
|
-
this.pruneRemembered();
|
|
1726
1974
|
}
|
|
1727
1975
|
}
|
|
1728
1976
|
let firstTime = false;
|
|
1729
1977
|
if (!shouldToast(event))
|
|
1730
1978
|
return;
|
|
1731
|
-
if (side === "start" && memoryKey) {
|
|
1732
|
-
if (this.yielding.has(memoryKey)) {
|
|
1733
|
-
this.yielding.delete(memoryKey);
|
|
1734
|
-
return;
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
1979
|
if (side === "start" && goalId)
|
|
1738
1980
|
firstTime = this.claimStartAnnouncement(sessionKey, goalId);
|
|
1739
1981
|
this.enqueue(sessionKey, formatCuratedToast(event, firstTime), goalId);
|
|
@@ -1782,16 +2024,11 @@ class ToastCoalescer {
|
|
|
1782
2024
|
return true;
|
|
1783
2025
|
}
|
|
1784
2026
|
pruneRemembered() {
|
|
1785
|
-
while (this.announced.size
|
|
2027
|
+
while (this.announced.size > REMEMBERED_LIMIT) {
|
|
1786
2028
|
const oldest = this.announced.values().next();
|
|
1787
|
-
if (
|
|
1788
|
-
this.announced.delete(oldest.value);
|
|
1789
|
-
continue;
|
|
1790
|
-
}
|
|
1791
|
-
const oldestYield = this.yielding.values().next();
|
|
1792
|
-
if (oldestYield.done)
|
|
2029
|
+
if (oldest.done)
|
|
1793
2030
|
return;
|
|
1794
|
-
this.
|
|
2031
|
+
this.announced.delete(oldest.value);
|
|
1795
2032
|
}
|
|
1796
2033
|
}
|
|
1797
2034
|
enqueue(sessionKey, toast, goalId) {
|
|
@@ -1840,7 +2077,7 @@ class ToastCoalescer {
|
|
|
1840
2077
|
}
|
|
1841
2078
|
}
|
|
1842
2079
|
|
|
1843
|
-
// src/tui.ts
|
|
2080
|
+
// src/tui-v1.ts
|
|
1844
2081
|
init_tui_views();
|
|
1845
2082
|
|
|
1846
2083
|
// src/tui-sound.ts
|
|
@@ -1874,7 +2111,7 @@ function soundForEvent(kind, status) {
|
|
|
1874
2111
|
}
|
|
1875
2112
|
}
|
|
1876
2113
|
|
|
1877
|
-
// src/tui.ts
|
|
2114
|
+
// src/tui-v1.ts
|
|
1878
2115
|
var GOAL_PREFIX = "ctrl+shift+g";
|
|
1879
2116
|
function chord(actionKey) {
|
|
1880
2117
|
return `${GOAL_PREFIX} ${actionKey}`;
|
|
@@ -2526,46 +2763,1734 @@ ${s.text}`).join(`
|
|
|
2526
2763
|
}
|
|
2527
2764
|
log("info", "TUI companion disposed.");
|
|
2528
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;
|
|
2529
3030
|
try {
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
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
|
+
}
|
|
2539
3141
|
});
|
|
3142
|
+
bound = { directory, root, loop };
|
|
3143
|
+
loop.start();
|
|
3144
|
+
log("info", `disk-refresh loop started (dir=${directory}, root=${root})`);
|
|
3145
|
+
return bound;
|
|
2540
3146
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
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;
|
|
2554
3188
|
}
|
|
3189
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
2555
3190
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
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 {}
|
|
2559
3205
|
}
|
|
2560
|
-
|
|
2561
|
-
|
|
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 = {
|
|
2562
4485
|
id: "fixate-on-tui",
|
|
2563
|
-
tui: GoalTuiPlugin
|
|
4486
|
+
tui: GoalTuiPlugin,
|
|
4487
|
+
setup: GoalTuiPluginV2.setup
|
|
2564
4488
|
};
|
|
2565
|
-
var tui_default =
|
|
4489
|
+
var tui_default = entry;
|
|
2566
4490
|
export {
|
|
2567
4491
|
GOAL_TUI_EVENT_TITLE,
|
|
2568
4492
|
GoalTuiPlugin,
|
|
4493
|
+
GoalTuiPluginV2,
|
|
2569
4494
|
createGoalBroadcaster,
|
|
2570
4495
|
createTuiStateStore,
|
|
2571
4496
|
tui_default as default,
|