@tea-agent/loop-agent 0.36.4-beta.0 → 0.37.1-beta.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/AGENTS.md +2 -6
- package/CHANGELOG.md +72 -163
- package/README.md +1 -1
- package/bin/loop-agent.js +1 -37
- package/dist/application/task-lifecycle/advance.js +0 -1
- package/dist/application/task-lifecycle/observe.js +0 -15
- package/dist/application/task-lifecycle/plan-transitions.js +0 -15
- package/dist/cli/command-definitions.js +0 -7
- package/dist/cli/program.js +3 -8
- package/dist/commands/init-upgrade.js +19 -351
- package/dist/commands/init.js +67 -14
- package/dist/commands/run-dag-progress.js +0 -14
- package/dist/commands/task-advance.js +3 -33
- package/dist/executors/dag-pi-executor.js +30 -47
- package/dist/executors/pi-sdk-executor.js +0 -34
- package/dist/executors/shell-executor.js +95 -6
- package/dist/infrastructure/harness/atomic-write.js +1 -2
- package/dist/shared/operator/capabilities.js +13 -200
- package/dist/shared/package-metadata.js +0 -42
- package/dist/task/frontend-project-capability.js +12 -162
- package/dist/task/source-prepare/completeness.js +0 -17
- package/dist/task/source-prepare/parse-intent.js +1 -15
- package/dist/task/source-prepare/semantic-intake.js +23 -144
- package/dist/worker/console/chat/artifact-card.js +1 -8
- package/dist/worker/console/chat/chat-event-store.js +0 -61
- package/dist/worker/console/chat/human-gate-card.js +1 -9
- package/dist/worker/console/chat/operation-card.js +2 -71
- package/dist/worker/console/chat/pi-runtime.js +62 -86
- package/dist/worker/console/chat/routes.js +8 -36
- package/dist/worker/console/chat/session-store.js +0 -3
- package/dist/worker/console/chat/shortcuts.js +7 -9
- package/dist/worker/console/chat/turn-process.js +23 -97
- package/dist/worker/console/chat/workspace-landing.js +1 -2
- package/dist/worker/console/operation-runner.js +6 -155
- package/dist/worker/console/operator-actions.js +13 -373
- package/dist/worker/console/operator-user-error.js +0 -4
- package/dist/worker/console/recovery-cta.js +3 -50
- package/dist/worker/console/static/assets/index-HX1pbOyl.css +1 -0
- package/dist/worker/console/static/assets/index-M0BLEBfh.js +56 -0
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/app/console-types.js +9 -13
- package/dist/worker/console/static-src/app/useOperatorActions.js +2 -4
- package/dist/worker/console/static-src/app/useRecoveryActions.js +56 -65
- package/dist/worker/console/static-src/app/useRecoveryConsole.js +1 -73
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +30 -89
- package/dist/worker/console/static-src/operator-chat/refs.js +0 -3
- package/dist/worker/console/static-src/operator-chat/spatial-overlay.js +1 -2
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +11 -30
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +6 -12
- package/dist/worker/console/static-src/operator-chat/useComposer.js +8 -45
- package/dist/worker/console/static-src/operator-chat/workspace-layout-mode.js +3 -7
- package/dist/worker/loop-agent/loop-agent-client.js +3 -17
- package/dist/worker/observability/read-model.js +0 -20
- package/dist/worker/observe/spec-evidence.js +8 -3
- package/dist/worker/observe/static/operator-chrome.d.ts +0 -1
- package/dist/worker/observe/static/operator-chrome.js +1 -6
- package/dist/worker/observe/static/views/dag-inspector.js +71 -6
- package/dist/worker/observe/static/views/dag.js +0 -12
- package/dist/worker/preflight.js +1 -2
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +707 -37
- package/dist/workflows/dag/backend-test-case-manifest.js +4 -0
- package/dist/workflows/dag/backend-test-markdown-workflow.js +109 -7
- package/dist/workflows/dag/backend-test-module-stem.js +5 -0
- package/dist/workflows/dag/backend-test-pytest-collection.js +345 -24
- package/dist/workflows/dag/backend-test-scenario-param.js +890 -164
- package/dist/workflows/dag/backend-test-writer-completeness.js +47 -16
- package/dist/workflows/dag/dynamic-runtime/map.js +24 -8
- package/dist/workflows/dag/dynamic-runtime/shared.js +1 -9
- package/dist/workflows/dag/failure-routing.js +4 -9
- package/dist/workflows/dag/frontend-implementation-contract.js +39 -233
- package/dist/workflows/dag/frontend-prewrite-gate.js +62 -394
- package/dist/workflows/dag/frontend-repair.js +18 -219
- package/dist/workflows/dag/frontend-verification-trace.js +32 -47
- package/dist/workflows/dag/init-hybrid.js +86 -238
- package/dist/workflows/dag/lifecycle.js +0 -4
- package/dist/workflows/dag/node-execution.js +6 -105
- package/dist/workflows/dag/recovery-recommendation.js +0 -58
- package/dist/workflows/dag/report.js +0 -6
- package/dist/workflows/dag/retry-policy.js +0 -11
- package/dist/workflows/dag/runner.js +12 -314
- package/dist/workflows/dag/scheduler.js +3 -257
- package/dist/workflows/dag/types.js +9 -132
- package/dist/workflows/dag/validate.js +2 -7
- package/docs/README.md +3 -3
- package/docs/architecture/evolution.md +67 -102
- package/docs/templates/backend-test-dag.json +50 -32
- package/docs/templates/frontend-design-contract.md +14 -34
- package/docs/templates/frontend-task-constraints.md +13 -33
- package/docs/templates/frontend-task-requirement.md +20 -54
- package/docs/templates/init-managed-agents.md +2 -5
- package/harness.json +2 -2
- package/package.json +3 -4
- package/skills/loop-agent/SKILL.md +0 -1
- package/skills/loop-agent/references/command-reference.md +0 -3
- package/dist/build-stamp.json +0 -6
- package/dist/commands/dag-request-interrupt.js +0 -20
- package/dist/worker/console/chat/assistant-content.js +0 -121
- package/dist/worker/console/chat/semantic-activity.js +0 -471
- package/dist/worker/console/operation-run-facts.js +0 -190
- package/dist/worker/console/operation-wait.js +0 -355
- package/dist/worker/console/recovery-error-copy.js +0 -198
- package/dist/worker/console/static/assets/index-D83DYAFG.css +0 -1
- package/dist/worker/console/static/assets/index-IXm7oYjL.js +0 -59
- package/dist/worker/console/static-src/operator-chat/activity-journey.js +0 -125
- package/dist/worker/console/static-src/operator-chat/activity-rail-presentation.js +0 -73
- package/dist/worker/console/static-src/operator-chat/activity-references.js +0 -20
- package/dist/worker/console/static-src/operator-chat/slash-palette-layout.js +0 -24
- package/dist/worker/console/static-src/operator-chat/slash-palette-nav.js +0 -141
- package/dist/worker/console/static-src/operator-chat/useActivityRailTransition.js +0 -59
- package/dist/worker/observability/interrupt-eligibility.js +0 -264
- package/dist/workflows/dag/contract-output-registry.js +0 -14
- package/dist/workflows/dag/contract-validator-registrations.js +0 -8
- package/dist/workflows/dag/frontend-recovery-plan.js +0 -73
- package/dist/workflows/dag/frontend-recovery-root-manifest.js +0 -123
- package/dist/workflows/dag/frontend-recovery-run.js +0 -539
- package/dist/workflows/dag/frontend-writer-recovery.js +0 -106
- package/dist/workflows/dag/frontend-writer-rollback.js +0 -821
- package/dist/workflows/dag/interrupt-request.js +0 -559
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { semanticOperationState, semanticOperationTitle, } from "../../chat/semantic-activity.js";
|
|
2
|
-
import { operationActivityRefs } from "./activity-references.js";
|
|
3
|
-
function operationSequence(operation) {
|
|
4
|
-
return operation.updatedSeq ?? operation.eventSeq;
|
|
5
|
-
}
|
|
6
|
-
function operationTime(operation) {
|
|
7
|
-
const parsed = Date.parse(operation.updatedAt);
|
|
8
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
9
|
-
}
|
|
10
|
-
function compareOperations(a, b) {
|
|
11
|
-
const aSequence = operationSequence(a);
|
|
12
|
-
const bSequence = operationSequence(b);
|
|
13
|
-
if (aSequence !== undefined && bSequence !== undefined) {
|
|
14
|
-
return aSequence - bSequence;
|
|
15
|
-
}
|
|
16
|
-
return operationTime(a) - operationTime(b);
|
|
17
|
-
}
|
|
18
|
-
function taskGroupKey(operation) {
|
|
19
|
-
if (operation.taskId)
|
|
20
|
-
return `task:${operation.taskId}`;
|
|
21
|
-
if (operation.dagRunId)
|
|
22
|
-
return `run:${operation.dagRunId}`;
|
|
23
|
-
return `operation:${operation.operationId}`;
|
|
24
|
-
}
|
|
25
|
-
function taskTitle(operation) {
|
|
26
|
-
if (!operation.taskId)
|
|
27
|
-
return semanticOperationTitle(operation.action);
|
|
28
|
-
const readable = operation.taskId
|
|
29
|
-
.replace(/^\d{4}-\d{2}-\d{2}-/, "")
|
|
30
|
-
.replace(/[-_]+/g, " ")
|
|
31
|
-
.trim();
|
|
32
|
-
return readable || operation.taskId;
|
|
33
|
-
}
|
|
34
|
-
function unique(values) {
|
|
35
|
-
return [...new Set(values)];
|
|
36
|
-
}
|
|
37
|
-
function buildSteps(operations) {
|
|
38
|
-
const latestByAction = new Map();
|
|
39
|
-
for (const operation of operations)
|
|
40
|
-
latestByAction.set(operation.action, operation);
|
|
41
|
-
return [...latestByAction.values()]
|
|
42
|
-
.sort(compareOperations)
|
|
43
|
-
.map((operation) => {
|
|
44
|
-
const semanticState = semanticOperationState(operation.state);
|
|
45
|
-
return {
|
|
46
|
-
id: operation.operationId,
|
|
47
|
-
label: semanticOperationTitle(operation.action),
|
|
48
|
-
stateLabel: semanticState.label,
|
|
49
|
-
kind: semanticState.kind,
|
|
50
|
-
at: operation.updatedAt,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function buildRuns(operations) {
|
|
55
|
-
const byRun = new Map();
|
|
56
|
-
for (const operation of operations) {
|
|
57
|
-
const runId = operation.dagRunId ?? operation.runSummary?.runId;
|
|
58
|
-
if (!runId)
|
|
59
|
-
continue;
|
|
60
|
-
const current = byRun.get(runId) ?? [];
|
|
61
|
-
current.push(operation);
|
|
62
|
-
byRun.set(runId, current);
|
|
63
|
-
}
|
|
64
|
-
return [...byRun.entries()]
|
|
65
|
-
.flatMap(([runId, candidates]) => {
|
|
66
|
-
const sorted = [...candidates].sort((a, b) => compareOperations(b, a));
|
|
67
|
-
const latest = sorted[0];
|
|
68
|
-
if (!latest)
|
|
69
|
-
return [];
|
|
70
|
-
const runSummary = sorted.find((operation) => operation.runSummary)?.runSummary;
|
|
71
|
-
const state = runSummary?.status ?? latest.state;
|
|
72
|
-
const semanticState = semanticOperationState(state);
|
|
73
|
-
return [{
|
|
74
|
-
runId,
|
|
75
|
-
state,
|
|
76
|
-
stateLabel: semanticState.label,
|
|
77
|
-
kind: semanticState.kind,
|
|
78
|
-
updatedAt: latest.updatedAt,
|
|
79
|
-
operationCount: candidates.length,
|
|
80
|
-
firstFailedNode: runSummary?.nodes.find((node) => node.status === "ERROR")?.id,
|
|
81
|
-
failureCategory: runSummary?.failureCategory,
|
|
82
|
-
inspectHref: latest.inspectHref,
|
|
83
|
-
}];
|
|
84
|
-
})
|
|
85
|
-
.sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt));
|
|
86
|
-
}
|
|
87
|
-
export function buildTaskJourneys(operations) {
|
|
88
|
-
const groups = new Map();
|
|
89
|
-
for (const operation of operations) {
|
|
90
|
-
const key = taskGroupKey(operation);
|
|
91
|
-
const current = groups.get(key) ?? [];
|
|
92
|
-
current.push(operation);
|
|
93
|
-
groups.set(key, current);
|
|
94
|
-
}
|
|
95
|
-
return [...groups.entries()]
|
|
96
|
-
.flatMap(([key, candidates]) => {
|
|
97
|
-
const sorted = [...candidates].sort(compareOperations);
|
|
98
|
-
const latestOperation = sorted.at(-1);
|
|
99
|
-
if (!latestOperation)
|
|
100
|
-
return [];
|
|
101
|
-
const semanticState = semanticOperationState(latestOperation.state);
|
|
102
|
-
return [{
|
|
103
|
-
key,
|
|
104
|
-
taskId: latestOperation.taskId,
|
|
105
|
-
displayTitle: taskTitle(latestOperation),
|
|
106
|
-
state: latestOperation.state,
|
|
107
|
-
stateLabel: semanticState.label,
|
|
108
|
-
kind: semanticState.kind,
|
|
109
|
-
updatedAt: latestOperation.updatedAt,
|
|
110
|
-
latestOperation,
|
|
111
|
-
operations: sorted,
|
|
112
|
-
steps: buildSteps(sorted),
|
|
113
|
-
runs: buildRuns(sorted),
|
|
114
|
-
activityRefs: unique(sorted.flatMap(operationActivityRefs)),
|
|
115
|
-
compactEligible: semanticState.kind === "success",
|
|
116
|
-
}];
|
|
117
|
-
})
|
|
118
|
-
.sort((a, b) => {
|
|
119
|
-
const aActive = a.kind === "progress" || a.kind === "error" ? 0 : 1;
|
|
120
|
-
const bActive = b.kind === "progress" || b.kind === "error" ? 0 : 1;
|
|
121
|
-
if (aActive !== bActive)
|
|
122
|
-
return aActive - bActive;
|
|
123
|
-
return Date.parse(b.updatedAt) - Date.parse(a.updatedAt);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useState } from "react";
|
|
2
|
-
export const ACTIVITY_RAIL_WIDTH = 420;
|
|
3
|
-
export const ACTIVITY_RAIL_GAP = 12;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve Activity Rail placement from the actual free space to the right of
|
|
6
|
-
* ChatMain. Activity presence is deliberately not an input: session data may
|
|
7
|
-
* show/hide the Rail, but it must never change the conversation geometry.
|
|
8
|
-
*/
|
|
9
|
-
export function resolveActivityRailPresentation(input) {
|
|
10
|
-
if (input.layoutMode === "narrow")
|
|
11
|
-
return "sheet";
|
|
12
|
-
const railWidth = input.railWidth ?? ACTIVITY_RAIL_WIDTH;
|
|
13
|
-
const gap = input.gap ?? ACTIVITY_RAIL_GAP;
|
|
14
|
-
const available = input.viewportWidth - input.mainRight;
|
|
15
|
-
return available >= railWidth + gap ? "sidecar" : "drawer";
|
|
16
|
-
}
|
|
17
|
-
const INITIAL = {
|
|
18
|
-
presentation: "drawer",
|
|
19
|
-
sidecarRect: null,
|
|
20
|
-
};
|
|
21
|
-
/** Measure ChatMain without feeding Activity state back into the page layout. */
|
|
22
|
-
export function useActivityRailPresentation(mainRef, layoutMode, refreshKey) {
|
|
23
|
-
const [snapshot, setSnapshot] = useState(INITIAL);
|
|
24
|
-
useLayoutEffect(() => {
|
|
25
|
-
const main = mainRef.current;
|
|
26
|
-
if (!main)
|
|
27
|
-
return;
|
|
28
|
-
const verticalAnchor = main.closest(".panel--chat") ?? main;
|
|
29
|
-
let frame = 0;
|
|
30
|
-
const measure = () => {
|
|
31
|
-
window.cancelAnimationFrame(frame);
|
|
32
|
-
frame = window.requestAnimationFrame(() => {
|
|
33
|
-
const rect = main.getBoundingClientRect();
|
|
34
|
-
const verticalRect = verticalAnchor.getBoundingClientRect();
|
|
35
|
-
const presentation = resolveActivityRailPresentation({
|
|
36
|
-
layoutMode,
|
|
37
|
-
viewportWidth: window.innerWidth,
|
|
38
|
-
mainRight: rect.right,
|
|
39
|
-
});
|
|
40
|
-
const sidecarRect = presentation === "sidecar"
|
|
41
|
-
? {
|
|
42
|
-
top: verticalRect.top,
|
|
43
|
-
left: rect.right + ACTIVITY_RAIL_GAP,
|
|
44
|
-
height: verticalRect.height,
|
|
45
|
-
width: ACTIVITY_RAIL_WIDTH,
|
|
46
|
-
}
|
|
47
|
-
: null;
|
|
48
|
-
setSnapshot((current) => {
|
|
49
|
-
if (current.presentation === presentation &&
|
|
50
|
-
current.sidecarRect?.top === sidecarRect?.top &&
|
|
51
|
-
current.sidecarRect?.left === sidecarRect?.left &&
|
|
52
|
-
current.sidecarRect?.height === sidecarRect?.height &&
|
|
53
|
-
current.sidecarRect?.width === sidecarRect?.width) {
|
|
54
|
-
return current;
|
|
55
|
-
}
|
|
56
|
-
return { presentation, sidecarRect };
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
measure();
|
|
61
|
-
const observer = new ResizeObserver(measure);
|
|
62
|
-
observer.observe(main);
|
|
63
|
-
if (verticalAnchor !== main)
|
|
64
|
-
observer.observe(verticalAnchor);
|
|
65
|
-
window.addEventListener("resize", measure);
|
|
66
|
-
return () => {
|
|
67
|
-
window.cancelAnimationFrame(frame);
|
|
68
|
-
observer.disconnect();
|
|
69
|
-
window.removeEventListener("resize", measure);
|
|
70
|
-
};
|
|
71
|
-
}, [layoutMode, mainRef, refreshKey]);
|
|
72
|
-
return snapshot;
|
|
73
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function operationActivityRefs(operation) {
|
|
2
|
-
return [
|
|
3
|
-
operation.activityRef ?? `operation:${operation.operationId}`,
|
|
4
|
-
`operation:${operation.operationId}`,
|
|
5
|
-
...(operation.toolCallId ? [`tool:${operation.toolCallId}`] : []),
|
|
6
|
-
];
|
|
7
|
-
}
|
|
8
|
-
export function humanGateActivityRefs(card) {
|
|
9
|
-
return [card.activityRef ?? `gate:${card.cardId}`];
|
|
10
|
-
}
|
|
11
|
-
export function artifactActivityRefs(card) {
|
|
12
|
-
return [card.activityRef ?? `artifact:${card.artifactId}`];
|
|
13
|
-
}
|
|
14
|
-
export function buildActivityTargetRefs(input) {
|
|
15
|
-
return new Set([
|
|
16
|
-
...input.operations.flatMap(operationActivityRefs),
|
|
17
|
-
...input.gates.flatMap(humanGateActivityRefs),
|
|
18
|
-
...input.artifacts.flatMap(artifactActivityRefs),
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const SHORTCUT_PALETTE_AVAILABLE_HEIGHT_VAR = "--oc-shortcut-palette-available-height";
|
|
2
|
-
export const SHORTCUT_PALETTE_TOP_INSET = 8;
|
|
3
|
-
export const SHORTCUT_PALETTE_ANCHOR_GAP = 8;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the real vertical room above the composer anchor. The palette is
|
|
6
|
-
* clipped by `.oc-main`, while a shifted VisualViewport (for example when the
|
|
7
|
-
* browser UI or virtual keyboard changes) can impose a lower visible top edge.
|
|
8
|
-
*/
|
|
9
|
-
export function resolveShortcutPaletteAvailableHeight(geometry) {
|
|
10
|
-
const viewportTop = geometry.viewportTop ?? 0;
|
|
11
|
-
const topInset = geometry.topInset ?? SHORTCUT_PALETTE_TOP_INSET;
|
|
12
|
-
const anchorGap = geometry.anchorGap ?? SHORTCUT_PALETTE_ANCHOR_GAP;
|
|
13
|
-
const values = [
|
|
14
|
-
geometry.boundaryTop,
|
|
15
|
-
geometry.anchorTop,
|
|
16
|
-
viewportTop,
|
|
17
|
-
topInset,
|
|
18
|
-
anchorGap,
|
|
19
|
-
];
|
|
20
|
-
if (values.some((value) => !Number.isFinite(value)))
|
|
21
|
-
return null;
|
|
22
|
-
const visibleTop = Math.max(geometry.boundaryTop, viewportTop);
|
|
23
|
-
return Math.max(0, Math.floor(geometry.anchorTop - visibleTop - topInset - anchorGap));
|
|
24
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slash palette display + navigation model (UI-12 card grid).
|
|
3
|
-
*
|
|
4
|
-
* Display order (SLASH_GROUP_DISPLAY_ORDER) is intentionally decoupled from
|
|
5
|
-
* the conflict/priority order in shortcuts.ts (SOURCE_PRIORITY): merge and
|
|
6
|
-
* dedupe keep SOURCE_PRIORITY semantics (skill 3 < prompt 4), while rendering
|
|
7
|
-
* follows the display order (prompt group before skill group). buildPaletteModel
|
|
8
|
-
* models that divergence explicitly — every card carries its flat-list
|
|
9
|
-
* globalIndex so keyboard/AT state round-trips from the rendered position back
|
|
10
|
-
* to filteredShortcuts[globalIndex]. shortcuts.ts itself stays untouched.
|
|
11
|
-
*
|
|
12
|
-
* All functions here are pure/DOM-free so the geometric and row-aware
|
|
13
|
-
* navigation can be unit-tested in node with fixture rects.
|
|
14
|
-
*/
|
|
15
|
-
import { SLASH_SOURCE_LABEL, } from "../../chat/shortcuts.js";
|
|
16
|
-
/** Group render order (independent from SOURCE_PRIORITY conflict order). */
|
|
17
|
-
export const SLASH_GROUP_DISPLAY_ORDER = [
|
|
18
|
-
"operator",
|
|
19
|
-
"web",
|
|
20
|
-
"extension",
|
|
21
|
-
"prompt",
|
|
22
|
-
"skill",
|
|
23
|
-
];
|
|
24
|
-
/** Group filtered candidates by display order, skipping empty groups. */
|
|
25
|
-
export function buildPaletteModel(entries) {
|
|
26
|
-
const groups = [];
|
|
27
|
-
for (const source of SLASH_GROUP_DISPLAY_ORDER) {
|
|
28
|
-
const items = [];
|
|
29
|
-
for (let i = 0; i < entries.length; i += 1) {
|
|
30
|
-
if (entries[i].source === source) {
|
|
31
|
-
items.push({ entry: entries[i], globalIndex: i });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (items.length === 0)
|
|
35
|
-
continue;
|
|
36
|
-
groups.push({ source, label: SLASH_SOURCE_LABEL[source], items });
|
|
37
|
-
}
|
|
38
|
-
return groups;
|
|
39
|
-
}
|
|
40
|
-
/** Keep the active option index inside the current candidate range. */
|
|
41
|
-
export function clampShortcutIndex(index, length) {
|
|
42
|
-
if (!Number.isFinite(length) || length <= 0)
|
|
43
|
-
return 0;
|
|
44
|
-
if (!Number.isFinite(index) || index < 0)
|
|
45
|
-
return 0;
|
|
46
|
-
if (index >= length)
|
|
47
|
-
return length - 1;
|
|
48
|
-
return index;
|
|
49
|
-
}
|
|
50
|
-
/** CSS grid columns per workspace layout mode (single source: layoutMode). */
|
|
51
|
-
export function paletteColumnCount(mode) {
|
|
52
|
-
if (mode === "comfortable")
|
|
53
|
-
return 3;
|
|
54
|
-
if (mode === "compact")
|
|
55
|
-
return 2;
|
|
56
|
-
return 1;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Group- and row-aware movement on the displayed card grid.
|
|
60
|
-
*
|
|
61
|
-
* Left/Right move to the adjacent card in the current row and stay inside the
|
|
62
|
-
* current group (row start/end stick; group headers are never entered; narrow
|
|
63
|
-
* 1-column layout is a no-op). Up/Down move within the same column to the
|
|
64
|
-
* adjacent row, may cross group boundaries, and stick at grid edges — never
|
|
65
|
-
* wrapping around and never leaving [0, entries.length - 1].
|
|
66
|
-
*/
|
|
67
|
-
export function movePaletteIndex(currentIndex, model, columns, direction) {
|
|
68
|
-
const groupPos = model.findIndex((group) => group.items.some((card) => card.globalIndex === currentIndex));
|
|
69
|
-
if (groupPos < 0)
|
|
70
|
-
return currentIndex;
|
|
71
|
-
const group = model[groupPos];
|
|
72
|
-
const offset = group.items.findIndex((card) => card.globalIndex === currentIndex);
|
|
73
|
-
if (offset < 0)
|
|
74
|
-
return currentIndex;
|
|
75
|
-
const row = Math.floor(offset / columns);
|
|
76
|
-
const col = offset % columns;
|
|
77
|
-
if (direction === "left" || direction === "right") {
|
|
78
|
-
if (columns <= 1)
|
|
79
|
-
return currentIndex;
|
|
80
|
-
const delta = direction === "left" ? -1 : 1;
|
|
81
|
-
const targetOffset = offset + delta;
|
|
82
|
-
if (targetOffset < 0 || targetOffset >= group.items.length) {
|
|
83
|
-
return currentIndex;
|
|
84
|
-
}
|
|
85
|
-
if (Math.floor(targetOffset / columns) !== row)
|
|
86
|
-
return currentIndex;
|
|
87
|
-
return group.items[targetOffset].globalIndex;
|
|
88
|
-
}
|
|
89
|
-
const delta = direction === "up" ? -1 : 1;
|
|
90
|
-
const targetOffset = offset + delta * columns;
|
|
91
|
-
if (targetOffset >= 0 && targetOffset < group.items.length) {
|
|
92
|
-
return group.items[targetOffset].globalIndex;
|
|
93
|
-
}
|
|
94
|
-
// Cross-group: walk to the previous/next non-empty group and target the
|
|
95
|
-
// same column on its last (up) / first (down) row; stick when that column
|
|
96
|
-
// does not exist in the partial edge row.
|
|
97
|
-
for (let cursor = groupPos + delta; cursor >= 0 && cursor < model.length; cursor += delta) {
|
|
98
|
-
const candidate = model[cursor];
|
|
99
|
-
if (candidate.items.length === 0)
|
|
100
|
-
continue;
|
|
101
|
-
const lastRowStart = Math.floor((candidate.items.length - 1) / columns) * columns;
|
|
102
|
-
const target = direction === "up" ? lastRowStart + col : col;
|
|
103
|
-
if (target >= candidate.items.length)
|
|
104
|
-
return currentIndex;
|
|
105
|
-
return candidate.items[target].globalIndex;
|
|
106
|
-
}
|
|
107
|
-
return currentIndex;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Geometry-first Up/Down targeting: from the active card's measured rect,
|
|
111
|
-
* pick the adjacent row's candidate whose horizontal center is nearest the
|
|
112
|
-
* active card's center (group boundaries may be crossed). Returns null when
|
|
113
|
-
* no candidate exists above/below (or the layout was not measured), so the
|
|
114
|
-
* caller falls back to movePaletteIndex. globalIndex comes from
|
|
115
|
-
* data-shortcut-index — never from the DOM list position.
|
|
116
|
-
*/
|
|
117
|
-
export function pickAdjacentRowTarget(activeRect, cells, direction) {
|
|
118
|
-
const activeCenterX = (activeRect.left + activeRect.right) / 2;
|
|
119
|
-
let best = null;
|
|
120
|
-
for (const cell of cells) {
|
|
121
|
-
if (cell.globalIndex === activeRect.globalIndex)
|
|
122
|
-
continue;
|
|
123
|
-
const gap = direction === "up"
|
|
124
|
-
? activeRect.top - cell.bottom
|
|
125
|
-
: cell.top - activeRect.bottom;
|
|
126
|
-
// Same-row cells overlap vertically (gap < 0) and must be ignored.
|
|
127
|
-
if (gap < 0)
|
|
128
|
-
continue;
|
|
129
|
-
const centerX = (cell.left + cell.right) / 2;
|
|
130
|
-
const dist = Math.abs(centerX - activeCenterX);
|
|
131
|
-
if (best === null ||
|
|
132
|
-
gap < best.gap ||
|
|
133
|
-
(gap === best.gap && dist < best.dist) ||
|
|
134
|
-
(gap === best.gap &&
|
|
135
|
-
dist === best.dist &&
|
|
136
|
-
cell.globalIndex < best.index)) {
|
|
137
|
-
best = { gap, dist, index: cell.globalIndex };
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return best?.index ?? null;
|
|
141
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
export const ACTIVITY_RAIL_ENTER_MS = 160;
|
|
3
|
-
export const ACTIVITY_RAIL_LEAVE_MS = 120;
|
|
4
|
-
export const ACTIVITY_RAIL_SWITCH_MS = 120;
|
|
5
|
-
export function activityRailSnapshotTotal(snapshot) {
|
|
6
|
-
if (!snapshot)
|
|
7
|
-
return 0;
|
|
8
|
-
return (snapshot.operationCards.length +
|
|
9
|
-
snapshot.humanGateCards.length +
|
|
10
|
-
snapshot.artifactCards.length);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Keep the Rail shell independent from ChatMain while sessions change. Old
|
|
14
|
-
* content is non-interactive during the short switching/leaving phase, then is
|
|
15
|
-
* replaced or removed without ever changing conversation geometry.
|
|
16
|
-
*/
|
|
17
|
-
export function useActivityRailTransition(current) {
|
|
18
|
-
const currentTotal = activityRailSnapshotTotal(current);
|
|
19
|
-
const [state, setState] = useState(() => currentTotal > 0
|
|
20
|
-
? { phase: "visible", snapshot: current }
|
|
21
|
-
: { phase: "hidden", snapshot: null });
|
|
22
|
-
const stateRef = useRef(state);
|
|
23
|
-
stateRef.current = state;
|
|
24
|
-
const currentKey = useMemo(() => `${current?.sessionId ?? "none"}:${currentTotal}`, [current?.sessionId, currentTotal]);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const timers = [];
|
|
27
|
-
const displayed = stateRef.current.snapshot;
|
|
28
|
-
if (!current || currentTotal === 0) {
|
|
29
|
-
if (!displayed) {
|
|
30
|
-
setState({ phase: "hidden", snapshot: null });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
setState({ phase: "leaving", snapshot: displayed });
|
|
34
|
-
timers.push(window.setTimeout(() => {
|
|
35
|
-
setState({ phase: "hidden", snapshot: null });
|
|
36
|
-
}, ACTIVITY_RAIL_LEAVE_MS));
|
|
37
|
-
}
|
|
38
|
-
else if (!displayed) {
|
|
39
|
-
setState({ phase: "entering", snapshot: current });
|
|
40
|
-
timers.push(window.setTimeout(() => {
|
|
41
|
-
setState({ phase: "visible", snapshot: current });
|
|
42
|
-
}, ACTIVITY_RAIL_ENTER_MS));
|
|
43
|
-
}
|
|
44
|
-
else if (displayed.sessionId !== current.sessionId) {
|
|
45
|
-
setState({ phase: "switching", snapshot: current });
|
|
46
|
-
timers.push(window.setTimeout(() => {
|
|
47
|
-
setState({ phase: "visible", snapshot: current });
|
|
48
|
-
}, ACTIVITY_RAIL_SWITCH_MS));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
setState({ phase: "visible", snapshot: current });
|
|
52
|
-
}
|
|
53
|
-
return () => {
|
|
54
|
-
for (const timer of timers)
|
|
55
|
-
window.clearTimeout(timer);
|
|
56
|
-
};
|
|
57
|
-
}, [current, currentKey, currentTotal]);
|
|
58
|
-
return state;
|
|
59
|
-
}
|