opencode-sesh 0.5.0 → 0.7.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 +18 -0
- package/CHANGELOG.md +29 -1
- package/README.md +8 -1
- package/bin/sesh +4 -0
- package/bin/sesh-cmux-sync.sh +146 -0
- package/contrib/cmux/README.md +13 -0
- package/install.sh +1 -0
- package/package.json +1 -1
- package/tui/sesh-panel.tsx +98 -2
package/AGENTS.md
CHANGED
|
@@ -147,6 +147,24 @@ Resume happens in place (`exec` after `cd` to the session's cwd).
|
|
|
147
147
|
Sessions waiting on the user (unanswered questions, stuck runs) pin a
|
|
148
148
|
**Needs input** group above the directories, with the count in the heading —
|
|
149
149
|
same `NEEDS_INPUT_SQL` heuristic as `bin/sesh-waiting.sh`.
|
|
150
|
+
- **cmux bridge (cmux-only, opt-out by absence).** When `CMUX_WORKSPACE_ID` is
|
|
151
|
+
set the sidebar talks to the `cmux` CLI; outside cmux no cmux call is made and
|
|
152
|
+
every click opens locally. Two behaviors, both keyed on cmux's *own* per-
|
|
153
|
+
surface resume record (`cmux surface resume show` → `restore_record.
|
|
154
|
+
checkpoint_id`), not on anything sesh writes:
|
|
155
|
+
- **Click-to-focus.** `pickFocusWorkspace` (pure, covered by `tests/tui.mjs`)
|
|
156
|
+
scans `cmux tree --json --all` plus each surface's checkpoint and, when
|
|
157
|
+
another workspace runs the clicked session, runs
|
|
158
|
+
`cmux workspace select <ref>` instead of `api.route.navigate`. The caller's
|
|
159
|
+
own surface/workspace never match (a same-workspace focus is a no-op, so it
|
|
160
|
+
opens locally). Works for background agents and older panels too.
|
|
161
|
+
- **Workspace naming.** The poll renames this workspace to the current
|
|
162
|
+
session title (`cmux workspace rename <id> --title …`), skipping titles that
|
|
163
|
+
are still the pre-first-turn placeholder. `bin/sesh-cmux-sync.sh` does the
|
|
164
|
+
same for every workspace at once. The session title is the source of truth;
|
|
165
|
+
a manual cmux rename is overwritten on the next session-title change.
|
|
166
|
+
These are the only cmux calls in the panel; keep them behind the
|
|
167
|
+
`CMUX_WORKSPACE_ID` guard.
|
|
150
168
|
- **Picker:** a custom dialog (not `DialogSelect`) grouped by
|
|
151
169
|
project/directory, recency-ordered, resume via
|
|
152
170
|
`api.route.navigate("session", …)`. `ctrl+o` and the command palette open it;
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-09-24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- The sidebar renames its cmux workspace to the current session title, so the
|
|
15
|
+
workspace list matches the session. Pre-first-turn placeholder titles
|
|
16
|
+
(`New session - …`) are never pushed.
|
|
17
|
+
- `sesh cmux-sync [--dry-run] [--json]` names every cmux workspace after the
|
|
18
|
+
opencode session it is running, using cmux's own per-surface resume record.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Click-to-focus now reads cmux's per-surface resume record (`checkpoint_id`)
|
|
23
|
+
instead of heartbeat files, so it also finds background agents and panes
|
|
24
|
+
running an older panel, and has no files to sweep.
|
|
25
|
+
## [0.6.0] - 2026-09-24
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- Clicking (or Enter on) a sidebar session now switches to the live cmux
|
|
30
|
+
workspace already showing it, instead of opening a duplicate in the current
|
|
31
|
+
pane. Panes advertise their open session (cmux-only, one heartbeat file per
|
|
32
|
+
session, ~45 s TTL); outside cmux or with no live claimant, the click opens
|
|
33
|
+
the session locally as before.
|
|
34
|
+
|
|
10
35
|
## [0.5.0] - 2026-09-24
|
|
11
36
|
|
|
12
37
|
### Added
|
|
@@ -16,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
41
|
- `/sesh-needs` opens the sessions waiting on you as an openable list (Enter
|
|
17
42
|
opens, Esc closes). Both new slashes are read-only; prune and retitle stay
|
|
18
43
|
CLI-only.
|
|
44
|
+
|
|
19
45
|
## [0.4.0] - 2026-09-24
|
|
20
46
|
|
|
21
47
|
### Added
|
|
@@ -267,7 +293,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
267
293
|
- Fixture-database regression suite, TypeScript typechecking, and ShellCheck in
|
|
268
294
|
CI.
|
|
269
295
|
|
|
270
|
-
[Unreleased]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.
|
|
296
|
+
[Unreleased]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.7.0...HEAD
|
|
297
|
+
[0.7.0]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.6.0...v0.7.0
|
|
298
|
+
[0.6.0]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.5.0...v0.6.0
|
|
271
299
|
[0.5.0]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.4.0...v0.5.0
|
|
272
300
|
[0.4.0]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.3.0...v0.4.0
|
|
273
301
|
[0.3.0]: https://github.com/ozandogrultan/opencode-sesh/compare/v0.2.1...v0.3.0
|
package/README.md
CHANGED
|
@@ -145,6 +145,10 @@ per-project record.
|
|
|
145
145
|
(`New session - …`) with the start of the session's first user message. Only
|
|
146
146
|
placeholder titles are touched, and the same dry-run/`--yes` gating applies.
|
|
147
147
|
|
|
148
|
+
`sesh cmux-sync [--dry-run] [--json]` names every [cmux](https://cmux.dev)
|
|
149
|
+
workspace after the opencode session its pane is running, so the sidebar and the
|
|
150
|
+
workspace list agree. cmux-only; a no-op without the cmux CLI.
|
|
151
|
+
|
|
148
152
|
When searching, title matches outrank transcript-only matches and the current
|
|
149
153
|
project rises, so the list answers "where was that thing I worked on" before it
|
|
150
154
|
answers "what is newest". Pins still win outright.
|
|
@@ -188,7 +192,10 @@ Sessions waiting on you (unanswered agent questions, runs stuck mid-tool) pin
|
|
|
188
192
|
themselves to a **Needs input** group above the directories, with the count in
|
|
189
193
|
the heading; `sesh --needs-input` lists the same set in the terminal.
|
|
190
194
|
Hovering a row while keyboard navigation is active selects it for the next
|
|
191
|
-
shortcut.
|
|
195
|
+
shortcut. Clicking (or Enter on) a session opens it here — unless another cmux
|
|
196
|
+
workspace is already running that session, in which case the sidebar focuses
|
|
197
|
+
that workspace instead of opening a duplicate (and the workspace is kept named
|
|
198
|
+
after its session). The full picker is one keystroke away.
|
|
192
199
|
|
|
193
200
|
The full picker pages through your whole global session list (no fixed window)
|
|
194
201
|
and indexes transcript text for every session in the background, showing
|
package/bin/sesh
CHANGED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Name each cmux workspace after the opencode session it is running.
|
|
3
|
+
#
|
|
4
|
+
# cmux records the session behind every terminal surface (its resume
|
|
5
|
+
# `checkpoint_id`), so the mapping needs no bookkeeping: for each surface whose
|
|
6
|
+
# checkpoint is an opencode session (`ses_…`), rename its workspace to that
|
|
7
|
+
# session's current title. Titles are the opencode session title (the source of
|
|
8
|
+
# truth) unless it is still the pre-first-turn placeholder, which is skipped.
|
|
9
|
+
#
|
|
10
|
+
# cmux-only: exits cleanly when the cmux CLI is unavailable. Renames are
|
|
11
|
+
# lossless (a title), so there is no confirmation; --dry-run previews instead.
|
|
12
|
+
#
|
|
13
|
+
# Usage: sesh-cmux-sync.sh [--dry-run] [--json]
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
|
|
16
|
+
OPENCODE_BIN=${SESH_OPENCODE:-opencode}
|
|
17
|
+
CMUX_BIN=${SESH_CMUX:-cmux}
|
|
18
|
+
dry_run=0
|
|
19
|
+
emit_json=0
|
|
20
|
+
while [ "$#" -gt 0 ]; do
|
|
21
|
+
case "$1" in
|
|
22
|
+
--dry-run) dry_run=1 ;;
|
|
23
|
+
--json) emit_json=1 ;;
|
|
24
|
+
--help) echo "usage: ${0##*/} [--dry-run] [--json]"; exit 0 ;;
|
|
25
|
+
*) echo "unknown option: $1" >&2; exit 2 ;;
|
|
26
|
+
esac
|
|
27
|
+
shift
|
|
28
|
+
done
|
|
29
|
+
|
|
30
|
+
command -v "$CMUX_BIN" >/dev/null 2>&1 || { echo 'sesh: cmux is not available' >&2; exit 1; }
|
|
31
|
+
export CMUX_QUIET=1
|
|
32
|
+
|
|
33
|
+
resolve_db() {
|
|
34
|
+
if [ -n "${SESH_DB:-}" ]; then printf '%s\n' "$SESH_DB"; return 0; fi
|
|
35
|
+
local from_cli=''
|
|
36
|
+
if command -v "$OPENCODE_BIN" >/dev/null 2>&1; then
|
|
37
|
+
from_cli=$("$OPENCODE_BIN" db path 2>/dev/null || true)
|
|
38
|
+
fi
|
|
39
|
+
if [ -n "$from_cli" ] && [ -f "$from_cli" ]; then printf '%s\n' "$from_cli"; return 0; fi
|
|
40
|
+
if [ -f "$HOME/.local/share/opencode/opencode.db" ]; then printf '%s\n' "$HOME/.local/share/opencode/opencode.db"; return 0; fi
|
|
41
|
+
return 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
SQLITE_BIN=''
|
|
45
|
+
if [ -n "${SESH_SQLITE:-}" ]; then
|
|
46
|
+
SQLITE_BIN=$SESH_SQLITE
|
|
47
|
+
elif command -v sqlite3 >/dev/null 2>&1; then
|
|
48
|
+
SQLITE_BIN=sqlite3
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
JQ_BIN=${SESH_JQ:-$(command -v jq || true)}
|
|
52
|
+
[ -n "$JQ_BIN" ] || { echo 'sesh: jq is required' >&2; exit 1; }
|
|
53
|
+
|
|
54
|
+
DB_PATH=$(resolve_db) || { echo 'sesh: session database unavailable' >&2; exit 1; }
|
|
55
|
+
[ -f "$DB_PATH" ] || { echo 'sesh: session database unavailable' >&2; exit 1; }
|
|
56
|
+
|
|
57
|
+
# 1. Every terminal surface cmux knows about, with its workspace.
|
|
58
|
+
SURFACES=$("$CMUX_BIN" tree --json --all 2>/dev/null | "$JQ_BIN" -c '
|
|
59
|
+
[ .windows[]?.workspaces[]? as $w
|
|
60
|
+
| $w.panes[]?.surfaces[]?
|
|
61
|
+
| select(.type == "terminal" and (.ref | type) == "string")
|
|
62
|
+
| {surface: .ref, workspace: $w.ref} ]') || SURFACES='[]'
|
|
63
|
+
[ -n "$SURFACES" ] || SURFACES='[]'
|
|
64
|
+
|
|
65
|
+
# 2. The opencode session each surface is running (cmux resume checkpoint).
|
|
66
|
+
PAIRS='[]'
|
|
67
|
+
while IFS=$'\t' read -r surface workspace; do
|
|
68
|
+
[ -n "$surface" ] || continue
|
|
69
|
+
checkpoint=$("$CMUX_BIN" surface resume show --surface "$surface" --json 2>/dev/null \
|
|
70
|
+
| "$JQ_BIN" -r '.restore_record.checkpoint_id // empty' 2>/dev/null || true)
|
|
71
|
+
case "$checkpoint" in
|
|
72
|
+
ses_[A-Za-z0-9]*) ;;
|
|
73
|
+
*) continue ;;
|
|
74
|
+
esac
|
|
75
|
+
PAIRS=$(printf '%s' "$PAIRS" | "$JQ_BIN" -c \
|
|
76
|
+
--arg ws "$workspace" --arg sid "$checkpoint" \
|
|
77
|
+
'. + [{workspace: $ws, session: $sid}]')
|
|
78
|
+
done < <(printf '%s' "$SURFACES" | "$JQ_BIN" -r '.[] | [.surface, .workspace] | @tsv')
|
|
79
|
+
|
|
80
|
+
if [ "$(printf '%s' "$PAIRS" | "$JQ_BIN" 'length')" = 0 ]; then
|
|
81
|
+
echo 'No cmux workspace is running an opencode session.'
|
|
82
|
+
exit 0
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# 3. Session titles (one query) and current workspace titles.
|
|
86
|
+
IN_LIST=''
|
|
87
|
+
for id in $(printf '%s' "$PAIRS" | "$JQ_BIN" -r '.[].session'); do
|
|
88
|
+
case "$id" in
|
|
89
|
+
ses_[A-Za-z0-9]*) IN_LIST="$IN_LIST'$id'," ;;
|
|
90
|
+
*) echo 'sesh: unexpected session id shape' >&2; exit 1 ;;
|
|
91
|
+
esac
|
|
92
|
+
done
|
|
93
|
+
IN_LIST=${IN_LIST%,}
|
|
94
|
+
if [ -n "$SQLITE_BIN" ]; then
|
|
95
|
+
TITLE_ROWS=$("$SQLITE_BIN" -json -readonly "$DB_PATH" "SELECT id, title FROM session WHERE id IN ($IN_LIST);")
|
|
96
|
+
else
|
|
97
|
+
TITLE_ROWS=$("$OPENCODE_BIN" db "SELECT id, title FROM session WHERE id IN ($IN_LIST);" --format json)
|
|
98
|
+
fi
|
|
99
|
+
[ -n "$TITLE_ROWS" ] || TITLE_ROWS='[]'
|
|
100
|
+
|
|
101
|
+
CURRENT=$("$CMUX_BIN" workspace list --json 2>/dev/null | "$JQ_BIN" -c \
|
|
102
|
+
'[.workspaces[] | {workspace: .ref, title: (.custom_title // .title // "")}]') || CURRENT='[]'
|
|
103
|
+
[ -n "$CURRENT" ] || CURRENT='[]'
|
|
104
|
+
|
|
105
|
+
# 4. Keep only the real renames: a non-placeholder session title that differs
|
|
106
|
+
# from what the workspace already shows.
|
|
107
|
+
FINAL=$(printf '%s' "$PAIRS" | "$JQ_BIN" -c \
|
|
108
|
+
--slurpfile sessions <(printf '%s' "$TITLE_ROWS") \
|
|
109
|
+
--slurpfile current <(printf '%s' "$CURRENT") '
|
|
110
|
+
($sessions[0] | map({key: .id, value: .title}) | from_entries) as $byId
|
|
111
|
+
| ($current[0] | map({key: .workspace, value: .title}) | from_entries) as $shown
|
|
112
|
+
| [ .[]
|
|
113
|
+
| ($byId[.session] // "" | gsub("^ +| +$"; "")) as $t
|
|
114
|
+
| select($t != "" and ($t | test("^New session\\b"; "i") | not))
|
|
115
|
+
| select(($shown[.workspace] // "") != $t)
|
|
116
|
+
| . + {title: $t} ]')
|
|
117
|
+
|
|
118
|
+
COUNT=$(printf '%s' "$FINAL" | "$JQ_BIN" 'length')
|
|
119
|
+
if [ "$COUNT" = 0 ]; then
|
|
120
|
+
echo 'Every cmux workspace already matches its session.'
|
|
121
|
+
exit 0
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
if [ "$emit_json" = 1 ]; then
|
|
125
|
+
printf '%s\n' "$FINAL"
|
|
126
|
+
exit 0
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
printf '%s' "$FINAL" | "$JQ_BIN" -r '.[] | "\(.workspace)\t\(.title)"' | while IFS=$'\t' read -r ws title; do
|
|
130
|
+
printf '%s → %s\n' "$ws" "$title"
|
|
131
|
+
done
|
|
132
|
+
|
|
133
|
+
if [ "$dry_run" = 1 ]; then
|
|
134
|
+
printf 'Would rename %s workspace(s) (--dry-run: nothing changed).\n' "$COUNT" >&2
|
|
135
|
+
exit 0
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
renamed=0
|
|
139
|
+
while IFS=$'\t' read -r ws title; do
|
|
140
|
+
if "$CMUX_BIN" workspace rename "$ws" --title "$title" >/dev/null 2>&1; then
|
|
141
|
+
renamed=$((renamed + 1))
|
|
142
|
+
else
|
|
143
|
+
echo "sesh: could not rename $ws" >&2
|
|
144
|
+
fi
|
|
145
|
+
done < <(printf '%s' "$FINAL" | "$JQ_BIN" -r '.[] | [.workspace, .title] | @tsv')
|
|
146
|
+
echo "Renamed $renamed workspace(s)."
|
package/contrib/cmux/README.md
CHANGED
|
@@ -35,6 +35,19 @@ sesh --print --json --query "auth refactor" \
|
|
|
35
35
|
Wrap that in a cmux `command` action (as above) or a shell function; it is
|
|
36
36
|
caller-side on purpose, so sesh stays terminal-agnostic.
|
|
37
37
|
|
|
38
|
+
## Keep workspace names in step
|
|
39
|
+
|
|
40
|
+
The sidebar renames its workspace to the opencode session title as you work, and
|
|
41
|
+
`sesh cmux-sync` does it for every workspace at once:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
sesh cmux-sync --dry-run # preview
|
|
45
|
+
sesh cmux-sync # rename to match
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
It reads cmux's own per-surface resume record, so it also names workspaces whose
|
|
49
|
+
agent was started outside the sidebar.
|
|
50
|
+
|
|
38
51
|
## Needs-input triage from cmux
|
|
39
52
|
|
|
40
53
|
`sesh --needs-input` prints (or `--json` emits) the sessions with unanswered
|
package/install.sh
CHANGED
package/package.json
CHANGED
package/tui/sesh-panel.tsx
CHANGED
|
@@ -4,6 +4,8 @@ import type { Project, Session } from "@opencode-ai/sdk/v2"
|
|
|
4
4
|
import { createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js"
|
|
5
5
|
import { mkdir, readFile, rename, rmdir, unlink, writeFile } from "node:fs/promises"
|
|
6
6
|
import { dirname, join } from "node:path"
|
|
7
|
+
import { execFile } from "node:child_process"
|
|
8
|
+
import { promisify } from "node:util"
|
|
7
9
|
import { getTreeSitterClient, RGBA, SyntaxStyle, TextAttributes } from "@opentui/core"
|
|
8
10
|
|
|
9
11
|
type ThemeColors = TuiPluginApi["theme"]["current"]
|
|
@@ -175,6 +177,9 @@ function pinnedFirst(entries: Entry[], pins: Pins): Entry[] {
|
|
|
175
177
|
// dialog). Native `/sessions` and session_list (<leader>l) stay untouched.
|
|
176
178
|
const BASE_MODE = "base"
|
|
177
179
|
const POLL_MS = 15_000
|
|
180
|
+
// opencode names a session only after its first turn; until then the title is
|
|
181
|
+
// a placeholder that should not become a cmux workspace name.
|
|
182
|
+
const PLACEHOLDER_TITLE = /^New session\b/i
|
|
178
183
|
|
|
179
184
|
function shortDir(dir: string, home: string): string {
|
|
180
185
|
if (!dir || dir === "/") return "other"
|
|
@@ -388,6 +393,64 @@ async function queryWaitingIds(db: any): Promise<Map<string, string>> {
|
|
|
388
393
|
return out
|
|
389
394
|
}
|
|
390
395
|
|
|
396
|
+
// cmux bridge: which surface is running which agent session, so opening a
|
|
397
|
+
// session that is live in another cmux workspace focuses that workspace
|
|
398
|
+
// instead of opening a duplicate here. The truth is cmux's own resume record
|
|
399
|
+
// (`checkpoint_id` per surface), not anything this panel writes — so it also
|
|
400
|
+
// covers background agents and panes running an older panel. Outside cmux
|
|
401
|
+
// (no CMUX_WORKSPACE_ID) no cmux call is made.
|
|
402
|
+
type CmuxSurface = { ref: string; workspaceRef: string; here: boolean; checkpoint?: string }
|
|
403
|
+
|
|
404
|
+
async function cmuxJson(args: string[]): Promise<any | undefined> {
|
|
405
|
+
try {
|
|
406
|
+
const { stdout } = await promisify(execFile)("cmux", args)
|
|
407
|
+
return JSON.parse(stdout)
|
|
408
|
+
} catch {
|
|
409
|
+
return undefined
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async function cmuxSurfaces(): Promise<CmuxSurface[]> {
|
|
414
|
+
const tree = await cmuxJson(["tree", "--json", "--all"])
|
|
415
|
+
if (!tree) return []
|
|
416
|
+
const surfaces: CmuxSurface[] = []
|
|
417
|
+
for (const w of tree.windows ?? []) {
|
|
418
|
+
for (const ws of w.workspaces ?? []) {
|
|
419
|
+
if (typeof ws?.ref !== "string") continue
|
|
420
|
+
for (const pane of ws.panes ?? []) {
|
|
421
|
+
for (const s of pane.surfaces ?? []) {
|
|
422
|
+
if (s?.type === "terminal" && typeof s.ref === "string") {
|
|
423
|
+
surfaces.push({ ref: s.ref, workspaceRef: ws.ref, here: s.here === true })
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
await Promise.all(
|
|
430
|
+
surfaces.map(async (surface) => {
|
|
431
|
+
const info = await cmuxJson(["surface", "resume", "show", "--surface", surface.ref, "--json"])
|
|
432
|
+
const checkpoint = info?.restore_record?.checkpoint_id
|
|
433
|
+
if (typeof checkpoint === "string") surface.checkpoint = checkpoint
|
|
434
|
+
}),
|
|
435
|
+
)
|
|
436
|
+
return surfaces
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Pure selection: the workspace to focus for a session, or undefined to open
|
|
440
|
+
// locally. Prefers a live surface in a different workspace; ignores the
|
|
441
|
+
// caller's own surface and workspace (focusing where you already are is a
|
|
442
|
+
// no-op, so a local open is the better answer).
|
|
443
|
+
function pickFocusWorkspace(surfaces: CmuxSurface[], sessionID: string): string | undefined {
|
|
444
|
+
const self = surfaces.find((surface) => surface.here)
|
|
445
|
+
for (const surface of surfaces) {
|
|
446
|
+
if (self && surface.ref === self.ref) continue
|
|
447
|
+
if (surface.checkpoint !== sessionID) continue
|
|
448
|
+
if (self && surface.workspaceRef === self.workspaceRef) continue
|
|
449
|
+
return surface.workspaceRef
|
|
450
|
+
}
|
|
451
|
+
return undefined
|
|
452
|
+
}
|
|
453
|
+
|
|
391
454
|
function addTranscript(index: Map<string, string>, sid: string, data: string): void {
|
|
392
455
|
try {
|
|
393
456
|
const part = JSON.parse(data) as { type?: unknown; text?: unknown }
|
|
@@ -661,6 +724,7 @@ function SidebarSessions(props: { api: TuiPluginApi } & PinProps) {
|
|
|
661
724
|
const [pendingDelete, setPendingDelete] = createSignal<string>()
|
|
662
725
|
const [waiting, setWaiting] = createSignal<Map<string, string>>(new Map())
|
|
663
726
|
let confirmTimer: ReturnType<typeof setTimeout> | undefined
|
|
727
|
+
let lastSyncedTitle: string | undefined
|
|
664
728
|
const currentID = createMemo(() => {
|
|
665
729
|
const route = props.api.route.current
|
|
666
730
|
if (route.name !== "session") return undefined
|
|
@@ -696,6 +760,20 @@ function SidebarSessions(props: { api: TuiPluginApi } & PinProps) {
|
|
|
696
760
|
} catch {
|
|
697
761
|
// leave the previous waiting set in place rather than flashing
|
|
698
762
|
}
|
|
763
|
+
// Keep this cmux workspace named after the session it is showing, so the
|
|
764
|
+
// sidebar and the workspace list agree. The session title is the source
|
|
765
|
+
// of truth; a placeholder title is never pushed. cmux-only.
|
|
766
|
+
try {
|
|
767
|
+
const workspace = process.env.CMUX_WORKSPACE_ID
|
|
768
|
+
const id = currentID()
|
|
769
|
+
const title = id ? (props.api.state.session.get(id)?.title ?? "").trim() : ""
|
|
770
|
+
if (workspace && title && !PLACEHOLDER_TITLE.test(title) && title !== lastSyncedTitle) {
|
|
771
|
+
await promisify(execFile)("cmux", ["workspace", "rename", workspace, "--title", title])
|
|
772
|
+
lastSyncedTitle = title
|
|
773
|
+
}
|
|
774
|
+
} catch {
|
|
775
|
+
// renaming is best-effort; a failure leaves the workspace name alone
|
|
776
|
+
}
|
|
699
777
|
}
|
|
700
778
|
void load()
|
|
701
779
|
const clock = setInterval(() => void load(), POLL_MS)
|
|
@@ -774,6 +852,24 @@ function SidebarSessions(props: { api: TuiPluginApi } & PinProps) {
|
|
|
774
852
|
setSectionCollapsed((value) => !value)
|
|
775
853
|
}
|
|
776
854
|
|
|
855
|
+
// Open a session. If a cmux surface is already running it in another
|
|
856
|
+
// workspace, focus that workspace instead of opening a duplicate here;
|
|
857
|
+
// otherwise open it locally. `cmux` calls only run inside cmux.
|
|
858
|
+
const openSession = async (entry: Entry) => {
|
|
859
|
+
if (process.env.CMUX_WORKSPACE_ID) {
|
|
860
|
+
const target = pickFocusWorkspace(await cmuxSurfaces(), entry.id)
|
|
861
|
+
if (target) {
|
|
862
|
+
try {
|
|
863
|
+
await promisify(execFile)("cmux", ["workspace", "select", target])
|
|
864
|
+
return
|
|
865
|
+
} catch {
|
|
866
|
+
// cmux unavailable; fall through to a local open
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
props.api.route.navigate("session", { sessionID: entry.id })
|
|
871
|
+
}
|
|
872
|
+
|
|
777
873
|
// Flat order of the rows a cursor can land on, so keyboard navigation and
|
|
778
874
|
// mouse hover resolve to the same row.
|
|
779
875
|
const itemRows = createMemo(() => tree().flatMap((row) => (row.kind === "item" ? [row.entry] : [])))
|
|
@@ -1007,7 +1103,7 @@ function SidebarSessions(props: { api: TuiPluginApi } & PinProps) {
|
|
|
1007
1103
|
preventDefault: true,
|
|
1008
1104
|
cmd: () => {
|
|
1009
1105
|
const entry = itemRows()[cursor()]
|
|
1010
|
-
if (entry)
|
|
1106
|
+
if (entry) void openSession(entry)
|
|
1011
1107
|
},
|
|
1012
1108
|
},
|
|
1013
1109
|
{
|
|
@@ -1138,7 +1234,7 @@ function SidebarSessions(props: { api: TuiPluginApi } & PinProps) {
|
|
|
1138
1234
|
}
|
|
1139
1235
|
}}
|
|
1140
1236
|
onMouseOut={() => setHovered(undefined)}
|
|
1141
|
-
onMouseDown={() =>
|
|
1237
|
+
onMouseDown={() => void openSession(row.entry)}
|
|
1142
1238
|
>
|
|
1143
1239
|
<text flexShrink={0}>
|
|
1144
1240
|
<span style={{ fg: theme().textMuted }}>{row.last ? "└" : "├"}</span>
|