Skip to content

feat(bin): port the experimental Tern runtime backend - #6

Merged
Asaki14 merged 7 commits into
mainfrom
fm/tern-port-trial
Oct 14, 2026
Merged

Asaki14 merged 7 commits into
mainfrom
fm/tern-port-trial

Conversation

@Asaki14

@Asaki14 Asaki14 commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Intent

Port the experimental Tern runtime backend from danielkuykendall23-boop/firstmate onto this fork, so a home can run ship and scout workers as Tern tabs.
Secondmate spawns on Tern stay refused; secondmate support is out of scope.

What changed

Effect on existing backends

The shared idle-placeholder pattern in bin/fm-composer-lib.sh gains two full-row, anchored omp hints (⇧⇥ to change thinking effort, ←← to see N running agent(s)).
On tmux and Herdr an omp composer showing only that hint now reads empty instead of pending; typed text still reads pending.
Tern auto-detection runs only when both TERN_PANE and TERM_PROGRAM=tern are set, after tmux and Herdr; a home with config/backend set is unaffected.

Testing

  • tests/fm-backend-tern.test.sh: 26 ok.
  • tests/fm-composer-lib.test.sh: 46 ok.
  • tests/fm-bootstrap.test.sh and tests/fm-teardown-endpoint-safety.test.sh: pass.
  • bin/fm-lint.sh and bin/fm-doc-audience-check.sh: pass.
  • tests/fm-backend-tern-smoke.test.sh against an isolated Tern 0.8.3 (own TERN_CONFIG_DIR, daemon socket, and window): 7 of 7 ok.
  • Live, same isolated Tern: a real omp worker spawned with --backend tern, two fm-send steers were acted on, agent state read alive, and teardown closed the tab and returned the worktree.
  • tests/fm-omp-harness.test.sh was not usable on this machine: its first case fails identically on unchanged main when run under omp, so its later launch-line cases did not run.

* feat(backend): add experimental Tern session backend

Adds bin/backends/tern.sh (one Tern session per home, one fm-<id> tab per
task, target tern:<session>/<block>), runtime detection from TERN_PANE with
TERM_PROGRAM=tern, process-level agent state, plugin-fed busy state, a
window-side Tern plugin that publishes agent state and colors task tabs,
PI_TUI_NATIVE=0 for Tern task panes, bin/fm-tern-autostart.sh, the omp idle
hint in the shared composer placeholder set, tests, and docs.

* test: clear the Tern pane marker in the shared test library

Suites run from a Tern pane otherwise auto-detect the tern backend where they
expect the no-marker tmux fallback.

* no-mistakes(review): Close exited Tern task blocks on kill; test fm-send routing

* no-mistakes(test): Gate Tern agent-state file on writer window pid, not age

* no-mistakes(document): Add Tern to stale backend lists across docs

* no-mistakes(lint): Silence intentional SC2016 warnings in Tern backend tests

* no-mistakes(ci): Lint 1 (ci-2) was caused by this PR, and I fixed it. ShellCheck SC2034 fired on `tests/fm-backend-tern.test.sh:101` because the test reset the Tern state-file cache with the assignment `FM_BACKEND_TERN_STATE_FILE_CACHED=`, a variable that is only read inside the sourced `bin/backends/tern.sh`. The invariant is that the shared lint must pass on every changed shell file, and that assignment was the only site that broke it. I changed the line to `unset FM_BACKEND_TERN_STATE_FILE_CACHED`. The behaviour is the same because tern.sh reads the variable as `${FM_BACKEND_TERN_STATE_FILE_CACHED:-}`, so unset and empty both force a fresh lookup. `bin/fm-lint.sh tests/fm-backend-tern.test.sh` now passes with the pinned ShellCheck 0.11.0, and `tests/fm-backend-tern.test.sh` passes with no failures. Behavior portable serial 2 (ci-1) was not caused by this PR, so I made no code change for it. The only failing test was `tests/fm-calm-pi-extension.test.sh`, with the error "grep disappeared from /export calm.html HTML while calm mode was on". The PR doesn't touch any Calm or Pi extension files. CI installs `@earendil-works/pi-coding-agent` unpinned (`.github/workflows/ci.yml:111,224`), so this run got Pi 1.0.4. The 1.0.x line came out on 2026-10-01 at 19:15, after main's last green run at 02:04 that day, and 1.0.4 was published on 2026-10-05. With Pi 1.0.4 installed locally in temp, the test failed the same way on this branch and on the untouched base commit b95d776. The failure comes from upstream Pi 1.0.4 changing its `/export` HTML, not from the Tern backend. It needs a separate Calm/Pi compatibility fix or a pinned Pi version in CI, both outside this PR's scope
…unchenguid#25)

* tern plugin: publish current-format state as soon as window_pid is known

window.luau's last_signature started equal to the empty string, which is
also the signature of a window with no agent panes and no fm-* task tabs.
A freshly loaded window that resolves window_pid before any pane/tab
activity therefore skipped its first scan's write forever, leaving a stale
or old-format agents.json from an earlier window in place for however long
the window stayed idle - the reader in bin/backends/tern.sh then trusted
that stale file as current.

Fix: start last_signature as nil, a sentinel no real signature (including
the empty one) can ever equal, so the first scan after window_pid is known
always publishes. Writes stay change-driven after that.

Adds a regression test that drives the real window.luau through a stubbed
window-host API via the luau CLI, reproducing the exact empty-signature
race and asserting the first write happens in current format (version,
window_pid, blocks). Skips cleanly without luau on PATH, matching this
suite's existing jq/tern skip convention.

* docs: note window.luau's first-write guarantee and its luau-driven test
…t hint as an idle composer (kunchenguid#28)

* fix(spawn): opt omp workers out of ONNX Runtime telemetry so no :memory:.ses lands in the worktree

omp's local tiny-model worker runs onnxruntime-node 1.30 with the worktree
as its cwd. Inside the worker sandbox its Microsoft 1DS telemetry cannot
write its database under ~/Library, falls back to an in-memory store, and
writes an untracked ':memory:.ses' stamp into the worktree, which made
fm-teardown.sh refuse cleanup of finished work. Every omp launch now
carries ORT_DISABLE_TELEMETRY=1, ORT's own whole-process opt-out.

* fix(composer): read omp's running-agent hint as an idle composer

While a subagent runs, omp 18.6.1 right-aligns '←← to see N running
agent(s)' on its empty composer row. Its bright keycap survived ghost
stripping, so the row read as pending input and doorbells to a worker
waiting on its subagent were skipped until the subagent finished. The hint
joins the shared idle-placeholder set beside omp's thinking-effort hint;
typed text stays pending. A status row carrying the right-aligned session
title is pinned as furniture too.
…mate-agents within the timer budget (kunchenguid#30)

* tern: keep firstmate-agents inside the timer budget; stop omp title spinner in Tern workers

* docs: record Tern 0.6.2 title-overlay and plugin timing evidence

* no-mistakes(review): Test Tern omp overlay; stop pid lookup starving scans

* no-mistakes(document): Document why plugin pid lookup skips consecutive ticks

* no-mistakes(document): Show Tern overlay in omp launch shape
Main now preflights each backend adapter and its sibling libraries from an
explicit per-backend list and refuses any backend missing from it, so the
ported Tern adapter could not be sourced at all. Add tern with the three
libraries bin/backends/tern.sh sources.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Asaki14
Asaki14 merged commit 912965c into main Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants