Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ herdr plugin link .

## What It Shows

When a useful task title is available, the plugin also **renames the focused Herdr pane** and publishes `pane.report-metadata` (`--title` / `--display-agent`) so the Herdr sidebar matches the outer terminal title. Tab-number fallbacks are not written back as pane names.

The plugin chooses the first available title:

1. Herdr pane metadata title, when an integration reports one.
Expand Down
52 changes: 52 additions & 0 deletions sync-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,63 @@ function saveTitle(title) {
writeFileSync(statePath, `${title}\n`);
}

/**
* When we derive a useful task title (not a bare tab fallback), also push it
* into Herdr pane metadata + pane rename. Official integrations only report
* lifecycle state today; this closes the loop so the Herdr sidebar and other
* plugins see the same task identity we put in the outer terminal title.
*
* Fail open: never block outer title sync if metadata/rename fails.
*/
function pushPaneTitle(title) {
try {
const pane = json(["pane", "current"])?.result?.pane;
const paneId = pane?.pane_id;
if (!paneId) return;

// Skip pure tab fallbacks like "2" / "2 / tab" / "tab 2".
const core = cleanPart(title).replace(/\s*\([^)]*\)\s*$/, "");
if (!core || /^(tab\s*)?\d+(\s*\/.*)?$/i.test(core)) return;
if (/^tab\s+\d+/i.test(core)) return;

// Prefer a short pane label without the workspace parenthetical.
const paneLabel = core.slice(0, 60);

try {
run(["pane", "rename", paneId, paneLabel]);
} catch {
// ignore
}
try {
run([
"pane",
"report-metadata",
paneId,
"--source",
"plugin:herdr-window-title-sync",
"--title",
paneLabel,
"--display-agent",
paneLabel,
"--token",
`task=${paneLabel}`,
"--ttl-ms",
"86400000",
]);
} catch {
// ignore
}
} catch {
// ignore
}
}

try {
const title = buildTitle();
if (title !== lastTitle()) {
run(["terminal", "title", "set", title]);
saveTitle(title);
pushPaneTitle(title);
}
console.log(title);
} catch (error) {
Expand Down