Repository navigation
feat: agents know where you are and where the dev server runs #22197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
t3dotgg
wants to merge
1
commit into
main
Choose a base branch
from
t3/turn-sender-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+504
−105
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { assert, describe, it } from "@effect/vitest"; | ||
|
|
||
| import { formatSentFromContext } from "./sentFromContext.ts"; | ||
|
|
||
| describe("formatSentFromContext", () => { | ||
| it("says localhost works when the client dialed loopback directly", () => { | ||
| assert.equal( | ||
| formatSentFromContext({ | ||
| surface: "desktop", | ||
| os: "macOS", | ||
| connectionMethod: "direct", | ||
| host: "127.0.0.1:3773", | ||
| serverLabel: "Mainbook", | ||
| }), | ||
| "<sent_from>The user sent this message from the T3 Code desktop app on macOS to this machine (Mainbook) at 127.0.0.1:3773. The user is at this machine, so localhost URLs work for them.</sent_from>", | ||
| ); | ||
| }); | ||
|
|
||
| it("points at the dialed name when the client is elsewhere on the network", () => { | ||
| assert.include( | ||
| formatSentFromContext({ surface: "web", host: "mainbook.example.ts.net:5733" }), | ||
| "Use mainbook.example.ts.net instead of localhost", | ||
| ); | ||
| }); | ||
|
|
||
| // T3 Connect and SSH tunnels arrive on loopback, so the host alone would mislead. | ||
| it("does not trust a loopback host behind a relay or tunnel", () => { | ||
| for (const connectionMethod of ["relay", "ssh"] as const) { | ||
| const text = formatSentFromContext({ connectionMethod, host: "127.0.0.1:3773" }); | ||
| assert.include(text, "probably not at this machine"); | ||
| assert.notInclude(text, "127.0.0.1"); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { OrchestrationV2MessageSentFrom } from "@t3tools/contracts"; | ||
|
|
||
| const CLIENT_NAMES = { | ||
| desktop: "the T3 Code desktop app", | ||
| web: "a web browser", | ||
| mobile: "the T3 Code mobile app", | ||
| cli: "the T3 Code CLI", | ||
| } as const; | ||
|
|
||
| const LOOPBACK_HOSTNAME = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i; | ||
|
|
||
| function hostnameOf(host: string): string { | ||
| return host.startsWith("[") ? host.slice(0, host.indexOf("]") + 1) : host.replace(/:\d+$/, ""); | ||
| } | ||
|
|
||
| // Relay and SSH tunnels reach the server on loopback, so their route decides | ||
| // before the dialed host can. | ||
| function reachSentence(sentFrom: OrchestrationV2MessageSentFrom): string { | ||
| if (sentFrom.connectionMethod === "relay" || sentFrom.connectionMethod === "ssh") { | ||
| return " The user is probably not at this machine, so localhost URLs do not work for them."; | ||
| } | ||
| if (sentFrom.host === undefined) return ""; | ||
| const hostname = hostnameOf(sentFrom.host); | ||
| return LOOPBACK_HOSTNAME.test(hostname) | ||
| ? " The user is at this machine, so localhost URLs work for them." | ||
| : ` The user is not at this machine. Use ${hostname} instead of localhost in URLs you give them.`; | ||
| } | ||
|
|
||
| /** | ||
| * Tells the agent where the user is, so links it gives (dev servers, previews) | ||
| * work from the user's device and "this machine" means the right one. | ||
| */ | ||
| export function formatSentFromContext(sentFrom: OrchestrationV2MessageSentFrom): string { | ||
| const client = | ||
| sentFrom.surface === undefined ? "a T3 Code client" : CLIENT_NAMES[sentFrom.surface]; | ||
| const os = sentFrom.os === undefined || sentFrom.os === "other" ? "" : ` on ${sentFrom.os}`; | ||
| const device = | ||
| sentFrom.deviceType === "phone" || sentFrom.deviceType === "tablet" | ||
| ? ` (${sentFrom.deviceType})` | ||
| : ""; | ||
| const machine = | ||
| sentFrom.serverLabel === undefined ? "this machine" : `this machine (${sentFrom.serverLabel})`; | ||
| const route = | ||
| sentFrom.connectionMethod === "relay" | ||
| ? " through T3 Connect" | ||
| : sentFrom.connectionMethod === "ssh" | ||
| ? " through an SSH tunnel" | ||
| : sentFrom.host === undefined | ||
| ? "" | ||
| : ` at ${sentFrom.host}`; | ||
| return `<sent_from>The user sent this message from ${client}${os}${device} to ${machine}${route}.${reachSentence(sentFrom)}</sent_from>`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not treat the saved PID as proof that the runner is alive.
If the runner terminates without scoped cleanup,
dev-runner.jsonremains. Its PID can later identify a different process. Tell agents to verify the process identity before trusting the saved URLs or acting on the PID.🤖 Prompt for AI Agents