Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6bbc5af31 | ||
|
|
d8ec10a5b1 | ||
|
|
f30413f93d | ||
|
|
8bc37bee2e |
No files matched your search
@@ -23,6 +23,5 @@ __screenshots__/
|
||||
.tanstack
|
||||
squashfs-root/
|
||||
.vercel
|
||||
.gstack/
|
||||
dist-electron/
|
||||
.electron-runtime/
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.23",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist-electron/main.cjs",
|
||||
@@ -16,10 +16,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/ssh": "workspace:*",
|
||||
"@t3tools/tailscale": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
"electron": "41.5.0",
|
||||
"electron-updater": "^6.6.2"
|
||||
@@ -27,7 +23,13 @@
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@t3tools/client-runtime": "workspace:*",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/ssh": "workspace:*",
|
||||
"@t3tools/tailscale": "workspace:*",
|
||||
"@types/node": "catalog:",
|
||||
"effect-acp": "workspace:*",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as NodeOS from "node:os";
|
||||
import {
|
||||
createAdvertisedEndpoint,
|
||||
type CreateAdvertisedEndpointInput,
|
||||
} from "@t3tools/shared/advertisedEndpoint";
|
||||
} from "@t3tools/client-runtime";
|
||||
import type {
|
||||
AdvertisedEndpoint,
|
||||
AdvertisedEndpointProvider,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -16,7 +15,10 @@ const unusedTailscaleExternalServicesLayer = Layer.mergeAll(
|
||||
HttpClient.HttpClient,
|
||||
HttpClient.make(() => Effect.die("unexpected Tailscale HTTPS probe")),
|
||||
),
|
||||
Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {}),
|
||||
Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() => Effect.die("unexpected tailscale status process")),
|
||||
),
|
||||
);
|
||||
|
||||
describe("tailscale endpoint provider", () => {
|
||||
@@ -32,8 +34,8 @@ describe("tailscale endpoint provider", () => {
|
||||
const dnsName = yield* parseTailscaleMagicDnsName(
|
||||
`{"Self":{"DNSName":"desktop.tail.ts.net."}}`,
|
||||
);
|
||||
assert.deepEqual(dnsName, Option.some("desktop.tail.ts.net"));
|
||||
assert.deepEqual(yield* parseTailscaleMagicDnsName("{}"), Option.none());
|
||||
assert.equal(dnsName, "desktop.tail.ts.net");
|
||||
assert.equal(yield* parseTailscaleMagicDnsName("{}"), null);
|
||||
const malformed = yield* Effect.result(parseTailscaleMagicDnsName("not-json"));
|
||||
assert.isTrue(malformed._tag === "Failure");
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createAdvertisedEndpoint } from "@t3tools/shared/advertisedEndpoint";
|
||||
import { createAdvertisedEndpoint } from "@t3tools/client-runtime";
|
||||
import type { AdvertisedEndpoint, AdvertisedEndpointProvider } from "@t3tools/contracts";
|
||||
import {
|
||||
buildTailscaleHttpsBaseUrl,
|
||||
@@ -61,17 +61,17 @@ function resolveTailscaleIpAdvertisedEndpoints(input: {
|
||||
const resolveTailscaleMagicDnsAdvertisedEndpoint = Effect.fn(
|
||||
"resolveTailscaleMagicDnsAdvertisedEndpoint",
|
||||
)(function* (input: {
|
||||
readonly dnsName: Option.Option<string>;
|
||||
readonly dnsName: string | null;
|
||||
readonly serveEnabled: boolean;
|
||||
readonly servePort?: number;
|
||||
readonly probe?: (baseUrl: string) => Effect.Effect<boolean, never, HttpClient.HttpClient>;
|
||||
}): Effect.fn.Return<Option.Option<AdvertisedEndpoint>, never, HttpClient.HttpClient> {
|
||||
if (Option.isNone(input.dnsName)) {
|
||||
if (!input.dnsName) {
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
const httpBaseUrl = buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName: input.dnsName.value,
|
||||
magicDnsName: input.dnsName,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
});
|
||||
const probe =
|
||||
@@ -116,13 +116,13 @@ export const resolveTailscaleAdvertisedEndpoints = Effect.fn("resolveTailscaleAd
|
||||
input.statusJson === undefined
|
||||
? yield* readTailscaleStatus.pipe(
|
||||
Effect.map((status) => status.magicDnsName),
|
||||
Effect.catch(() => Effect.succeed(Option.none())),
|
||||
Effect.catch(() => Effect.succeed(null)),
|
||||
)
|
||||
: input.statusJson
|
||||
? yield* parseTailscaleMagicDnsName(input.statusJson).pipe(
|
||||
Effect.catch(() => Effect.succeed(Option.none())),
|
||||
Effect.catch(() => Effect.succeed(null)),
|
||||
)
|
||||
: Option.none();
|
||||
: null;
|
||||
const magicDnsEndpoint = yield* resolveTailscaleMagicDnsAdvertisedEndpoint({
|
||||
dnsName,
|
||||
serveEnabled: input.serveEnabled === true,
|
||||
|
||||
@@ -12,7 +12,7 @@ export default defineConfig([
|
||||
...shared,
|
||||
entry: ["src/main.ts"],
|
||||
clean: true,
|
||||
noExternal: (id) => id.startsWith("@t3tools/"),
|
||||
noExternal: (id) => id.startsWith("@t3tools/") || id.startsWith("effect-acp"),
|
||||
},
|
||||
{
|
||||
...shared,
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 244 B |
|
Before Width: | Height: | Size: 358 B |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="257" preserveAspectRatio="xMidYMid" viewBox="0 0 256 257"><path fill="#D97757" d="m50.228 170.321 50.357-28.257.843-2.463-.843-1.361h-2.462l-8.426-.518-28.775-.778-24.952-1.037-24.175-1.296-6.092-1.297L0 125.796l.583-3.759 5.12-3.434 7.324.648 16.202 1.101 24.304 1.685 17.629 1.037 26.118 2.722h4.148l.583-1.685-1.426-1.037-1.101-1.037-25.147-17.045-27.22-18.017-14.258-10.37-7.713-5.25-3.888-4.925-1.685-10.758 7-7.713 9.397.649 2.398.648 9.527 7.323 20.35 15.75L94.817 91.9l3.889 3.24 1.555-1.102.195-.777-1.75-2.917-14.453-26.118-15.425-26.572-6.87-11.018-1.814-6.61c-.648-2.723-1.102-4.991-1.102-7.778l7.972-10.823L71.42 0 82.05 1.426l4.472 3.888 6.61 15.101 10.694 23.786 16.591 32.34 4.861 9.592 2.592 8.879.973 2.722h1.685v-1.556l1.36-18.211 2.528-22.36 2.463-28.776.843-8.1 4.018-9.722 7.971-5.25 6.222 2.981 5.12 7.324-.713 4.73-3.046 19.768-5.962 30.98-3.889 20.739h2.268l2.593-2.593 10.499-13.934 17.628-22.036 7.778-8.749 9.073-9.657 5.833-4.601h11.018l8.1 12.055-3.628 12.443-11.342 14.388-9.398 12.184-13.48 18.147-8.426 14.518.778 1.166 2.01-.194 30.46-6.481 16.462-2.982 19.637-3.37 8.88 4.148.971 4.213-3.5 8.62-20.998 5.184-24.628 4.926-36.682 8.685-.454.324.519.648 16.526 1.555 7.065.389h17.304l32.21 2.398 8.426 5.574 5.055 6.805-.843 5.184-12.962 6.611-17.498-4.148-40.83-9.721-14-3.5h-1.944v1.167l11.666 11.406 21.387 19.314 26.767 24.887 1.36 6.157-3.434 4.86-3.63-.518-23.526-17.693-9.073-7.972-20.545-17.304h-1.36v1.814l4.73 6.935 25.017 37.59 1.296 11.536-1.814 3.76-6.481 2.268-7.13-1.297-14.647-20.544-15.1-23.138-12.185-20.739-1.49.843-7.194 77.448-3.37 3.953-7.778 2.981-6.48-4.925-3.436-7.972 3.435-15.749 4.148-20.544 3.37-16.333 3.046-20.285 1.815-6.74-.13-.454-1.49.194-15.295 20.999-23.267 31.433-18.406 19.702-4.407 1.75-7.648-3.954.713-7.064 4.277-6.286 25.47-32.405 15.36-20.092 9.917-11.6-.065-1.686h-.583L44.07 198.125l-12.055 1.555-5.185-4.86.648-7.972 2.463-2.593 20.35-13.999-.064.065Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><svg id="cursor_light__Ebene_1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 466.73 532.09"><defs></defs><path class="cursor_light__st0" d="M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 649 B |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="260" preserveAspectRatio="xMidYMid" viewBox="0 0 256 260"><path fill="#fff" d="M239.184 106.203a64.716 64.716 0 0 0-5.576-53.103C219.452 28.459 191 15.784 163.213 21.74A65.586 65.586 0 0 0 52.096 45.22a64.716 64.716 0 0 0-43.23 31.36c-14.31 24.602-11.061 55.634 8.033 76.74a64.665 64.665 0 0 0 5.525 53.102c14.174 24.65 42.644 37.324 70.446 31.36a64.72 64.72 0 0 0 48.754 21.744c28.481.025 53.714-18.361 62.414-45.481a64.767 64.767 0 0 0 43.229-31.36c14.137-24.558 10.875-55.423-8.083-76.483Zm-97.56 136.338a48.397 48.397 0 0 1-31.105-11.255l1.535-.87 51.67-29.825a8.595 8.595 0 0 0 4.247-7.367v-72.85l21.845 12.636c.218.111.37.32.409.563v60.367c-.056 26.818-21.783 48.545-48.601 48.601Zm-104.466-44.61a48.345 48.345 0 0 1-5.781-32.589l1.534.921 51.722 29.826a8.339 8.339 0 0 0 8.441 0l63.181-36.425v25.221a.87.87 0 0 1-.358.665l-52.335 30.184c-23.257 13.398-52.97 5.431-66.404-17.803ZM23.549 85.38a48.499 48.499 0 0 1 25.58-21.333v61.39a8.288 8.288 0 0 0 4.195 7.316l62.874 36.272-21.845 12.636a.819.819 0 0 1-.767 0L41.353 151.53c-23.211-13.454-31.171-43.144-17.804-66.405v.256Zm179.466 41.695-63.08-36.63L161.73 77.86a.819.819 0 0 1 .768 0l52.233 30.184a48.6 48.6 0 0 1-7.316 87.635v-61.391a8.544 8.544 0 0 0-4.4-7.213Zm21.742-32.69-1.535-.922-51.619-30.081a8.39 8.39 0 0 0-8.492 0L99.98 99.808V74.587a.716.716 0 0 1 .307-.665l52.233-30.133a48.652 48.652 0 0 1 72.236 50.391v.205ZM88.061 139.097l-21.845-12.585a.87.87 0 0 1-.41-.614V65.685a48.652 48.652 0 0 1 79.757-37.346l-1.535.87-51.67 29.825a8.595 8.595 0 0 0-4.246 7.367l-.051 72.697Zm11.868-25.58 28.138-16.217 28.188 16.218v32.434l-28.086 16.218-28.188-16.218-.052-32.434Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 1.7 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512"><svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="512" height="512" fill="#131010"></rect><path d="M320 224V352H192V224H320Z" fill="#5A5858"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M384 416H128V96H384V416ZM320 160H192V352H320V160Z" fill="white"></path></svg></svg>
|
||||
|
Before Width: | Height: | Size: 464 B |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 138 B |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 652 KiB |
|
Before Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 110 KiB |
@@ -1,53 +0,0 @@
|
||||
---
|
||||
interface Props {
|
||||
class?: string;
|
||||
idPrefix: string;
|
||||
}
|
||||
|
||||
const { class: className, idPrefix } = Astro.props;
|
||||
---
|
||||
|
||||
<svg
|
||||
class={className}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 256 295"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id={`${idPrefix}0`} x1="48.548%" x2="51.047%" y1="115.276%" y2="41.364%">
|
||||
<stop offset="0%" stop-color="#FFEED7" />
|
||||
<stop offset="100%" stop-color="#BDBFC2" />
|
||||
</linearGradient>
|
||||
<linearGradient id={`${idPrefix}6`} x1="49.984%" x2="49.984%" y1="89.845%" y2="40.632%">
|
||||
<stop offset="0%" stop-color="#FFEED7" />
|
||||
<stop offset="100%" stop-color="#BDBFC2" />
|
||||
</linearGradient>
|
||||
<linearGradient id={`${idPrefix}8`} x1="49.841%" x2="50.241%" y1="13.229%" y2="94.673%">
|
||||
<stop offset="0%" stop-color="#FFF" stop-opacity=".8" />
|
||||
<stop offset="100%" stop-color="#FFF" stop-opacity="0" />
|
||||
</linearGradient>
|
||||
<linearGradient id={`${idPrefix}c`} x1="53.467%" x2="38.949%" y1="48.921%" y2="98.1%">
|
||||
<stop offset="0%" stop-color="#FFA63F" />
|
||||
<stop offset="100%" stop-color="#FF0" />
|
||||
</linearGradient>
|
||||
<linearGradient id={`${idPrefix}e`} x1="30.581%" x2="65.887%" y1="34.024%" y2="89.175%">
|
||||
<stop offset="0%" stop-color="#FFA63F" />
|
||||
<stop offset="100%" stop-color="#FF0" />
|
||||
</linearGradient>
|
||||
<linearGradient id={`${idPrefix}i`} x1="49.733%" x2="50.558%" y1="17.609%" y2="99.385%">
|
||||
<stop offset="0%" stop-color="#FFA63F" />
|
||||
<stop offset="100%" stop-color="#FF0" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g fill="none">
|
||||
<path fill="#000" d="M63.213 215.474c-11.387-16.346-13.591-69.606 12.947-102.39C89.292 97.383 92.69 86.455 93.7 71.67c.734-16.805-11.846-66.851 35.537-70.616 48.027-3.857 45.364 43.526 45.088 68.596-.183 21.12 15.52 33.15 26.355 49.68 19.927 30.303 18.274 82.461-3.765 110.745-27.916 35.354-51.791 20.018-67.678 21.304-29.752 1.745-30.762 17.54-66.024-35.905" />
|
||||
<path fill={`url(#${idPrefix}6)`} d="M81.027 145.684c6.52-14.785 20.386-40.772 20.662-60.883 0-15.978 47.843-19.835 51.7-3.856 3.856 15.978 13.59 39.853 19.834 51.424 6.245 11.478 24.335 48.118 5.051 80.074-17.356 28.284-69.973 50.69-98.073-3.856-9.55-18.917-7.806-42.333.826-62.903" />
|
||||
<path fill={`url(#${idPrefix}8)`} d="M166.428 151.285c0 16.162-15.519 37.1-42.15 36.916-27.456.183-39.118-20.754-39.118-36.916 0-16.161 18.182-29.293 40.588-29.293 22.498.092 40.68 13.132 40.68 29.293" />
|
||||
<path fill="#000" stroke="#000" stroke-width=".977" d="M176.805 117.86c13.59 11.02 38.292 49.587 2.204 74.748-11.846 7.806 10.468 32.508 23.049 19.927 43.618-43.894-1.102-94.308-16.53-111.664-13.774-15.151-25.987 3.49-8.723 16.989z" />
|
||||
<path fill="#000" stroke="#000" stroke-width="1.25" d="M79.925 122.727c-8.907 14.509-30.211 48.669-1.652 66.484 38.384 23.6 27.548 47.108-7.53 25.895-49.404-29.568-5.97-89.257 13.774-112.03 22.59-25.529 4.316 4.683-4.592 19.65z" />
|
||||
<path fill={`url(#${idPrefix}c)`} stroke="#E68C3F" stroke-width="6.25" d="M51.835 258.542c-20.57-10.928-50.414 2.112-39.578-27.457 2.204-6.704-3.214-16.805.275-23.325 4.133-7.989 13.04-6.244 18.366-11.57 5.234-5.51 8.54-15.06 18.366-13.59 9.734 1.468 16.254 13.406 23.049 28.099 5.05 10.468 22.865 25.253 21.672 37.007-1.47 17.998-21.948 21.396-42.15 10.836z" transform="translate(10)" />
|
||||
<path fill={`url(#${idPrefix}e)`} stroke="#E68C3F" stroke-width="6.251" d="M194.445 253.49c15.06-18.273 48.578-14.508 25.988-39.577-4.775-5.418-3.306-16.989-9.183-21.947-6.887-6.061-14.509-1.102-21.488-4.224-6.979-3.398-14.325-9.918-22.865-5.327-8.54 4.684-9.459 16.805-10.285 32.783-.735 11.479-11.203 30.671-5.602 41.231 8.081 16.346 29.11 14.142 43.435-2.938z" transform="translate(10)" />
|
||||
<path fill={`url(#${idPrefix}i)`} stroke="#E68C3F" stroke-width="3.75" d="M97.107 66.344c3.673-3.398 12.58-13.774 29.477-2.939 3.122 2.02 5.693 2.204 11.662 4.775 12.03 4.96 6.336 16.897-6.52 20.937-5.51 1.745-10.468 8.449-20.386 7.806-8.54-.46-10.744-6.06-15.978-9.091-9.275-5.234-10.652-12.305-5.602-16.07 5.051-3.765 6.98-5.143 7.347-5.418z" transform="translate(10)" />
|
||||
<path fill="#000" d="M133.186 57.712c-.092 5.234 2.48 9.458 5.877 9.458 3.306 0 6.153-4.224 6.245-9.366.091-5.234-2.48-9.459-5.878-9.459-3.397 0-6.152 4.225-6.244 9.367m-21.212.092c.459 4.316-1.194 7.989-3.582 8.356-2.387.276-4.683-2.938-5.142-7.254-.46-4.316 1.194-7.99 3.581-8.357 2.388-.275 4.684 2.939 5.143 7.255" />
|
||||
</g>
|
||||
</svg>
|
||||
@@ -6,7 +6,7 @@ interface Props {
|
||||
|
||||
const {
|
||||
title = "T3 Code",
|
||||
description = "T3 Code — The open-source control plane for coding agents.",
|
||||
description = "T3 Code — The best way to code with AI.",
|
||||
} = Astro.props;
|
||||
---
|
||||
|
||||
@@ -18,7 +18,7 @@ const {
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,[email protected],400;9..40,500;9..40,600&family=JetBrains+Mono:wght@400;500&display=swap"
|
||||
href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,[email protected],400;9..40,500;9..40,600&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
||||
@@ -30,25 +30,18 @@ const {
|
||||
<body>
|
||||
<div class="page">
|
||||
<nav class="nav">
|
||||
<div class="nav-inner">
|
||||
<a href="/" class="nav-brand" aria-label="T3 Code home">
|
||||
<span class="nav-brand-name">T3 Code</span>
|
||||
</a>
|
||||
<div class="nav-right">
|
||||
<a
|
||||
class="nav-gh"
|
||||
href="https://github.com/pingdotgg/t3code"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<path d="M12 .5C5.65.5.5 5.65.5 12a11.5 11.5 0 007.86 10.93c.58.1.79-.25.79-.56v-2c-3.2.69-3.88-1.37-3.88-1.37-.52-1.33-1.27-1.69-1.27-1.69-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.18 1.76 1.18 1.02 1.76 2.68 1.25 3.33.96.1-.75.4-1.25.72-1.54-2.55-.29-5.24-1.27-5.24-5.67 0-1.25.45-2.28 1.18-3.08-.12-.29-.51-1.45.11-3.02 0 0 .96-.31 3.15 1.18a10.96 10.96 0 015.74 0c2.19-1.49 3.15-1.18 3.15-1.18.62 1.57.23 2.73.11 3.02.74.8 1.18 1.83 1.18 3.08 0 4.41-2.7 5.38-5.27 5.66.41.36.78 1.06.78 2.13v3.16c0 .31.21.67.8.56A11.5 11.5 0 0023.5 12C23.5 5.65 18.35.5 12 .5z"/>
|
||||
</svg>
|
||||
<span>GitHub</span>
|
||||
</a>
|
||||
<a class="btn btn-primary" href="/#download">Download</a>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/" class="nav-brand">
|
||||
<img src="/icon.png" alt="T3" class="nav-icon" />
|
||||
</a>
|
||||
<a
|
||||
href="https://github.com/pingdotgg/t3code"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="nav-github"
|
||||
>
|
||||
GitHub
|
||||
<span class="nav-github-arrow" aria-hidden="true">↗</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<main class="main">
|
||||
@@ -56,54 +49,23 @@ const {
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="footer-inner">
|
||||
<div class="footer-brand">
|
||||
<img src="/icon.webp" alt="" />
|
||||
<span>© {new Date().getFullYear()} T3 Tools Inc · MIT licensed</span>
|
||||
</div>
|
||||
<div class="footer-links">
|
||||
<a href="https://github.com/pingdotgg/t3code" target="_blank" rel="noopener noreferrer">GitHub</a>
|
||||
<a href="https://discord.gg/jn4EGJjrvv" target="_blank" rel="noopener noreferrer">Discord</a>
|
||||
<a href="/download">Download</a>
|
||||
</div>
|
||||
<span class="footer-copy">© {new Date().getFullYear()} T3 Tools Inc</span>
|
||||
<div class="footer-links">
|
||||
<a href="https://github.com/pingdotgg/t3code" target="_blank" rel="noopener noreferrer">GitHub</a>
|
||||
<a href="https://discord.gg/jn4EGJjrvv" target="_blank" rel="noopener noreferrer">Discord</a>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const nav = document.querySelector(".nav");
|
||||
const onScroll = () => {
|
||||
if (!nav) return;
|
||||
if (window.scrollY > 12) nav.classList.add("is-scrolled");
|
||||
else nav.classList.remove("is-scrolled");
|
||||
};
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
onScroll();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style is:global>
|
||||
:root {
|
||||
--bg: #09090b;
|
||||
--bg-elev: #0c0c0e;
|
||||
--bg-card: #111113;
|
||||
--fg: #fafafa;
|
||||
--fg-muted: #a1a1aa;
|
||||
--fg-dim: #71717a;
|
||||
--fg-faint: #52525b;
|
||||
--border: rgba(255, 255, 255, 0.08);
|
||||
--border-strong: rgba(255, 255, 255, 0.14);
|
||||
--accent-h: 250;
|
||||
--accent: oklch(0.68 0.17 var(--accent-h));
|
||||
--accent-dim: oklch(0.68 0.17 var(--accent-h) / 0.15);
|
||||
--ok: oklch(0.72 0.16 150);
|
||||
--warn: oklch(0.76 0.15 75);
|
||||
--font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
||||
--font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
|
||||
--radius: 12px;
|
||||
--radius-sm: 8px;
|
||||
--radius-lg: 16px;
|
||||
}
|
||||
|
||||
* {
|
||||
@@ -114,19 +76,16 @@ const {
|
||||
|
||||
html {
|
||||
color-scheme: dark;
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font-family: var(--font-sans);
|
||||
font-feature-settings: "ss01", "ss02";
|
||||
font-family: "DM Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
min-height: 100vh;
|
||||
overflow-x: hidden;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
body::after {
|
||||
@@ -146,103 +105,11 @@ const {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button {
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
img,
|
||||
svg {
|
||||
img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: var(--fg-dim);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.display {
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.035em;
|
||||
line-height: 1.05;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1240px;
|
||||
margin: 0 auto;
|
||||
padding: 0 32px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
padding: 10px 18px;
|
||||
border-radius: 8px;
|
||||
transition: transform 0.18s ease, background 0.18s ease,
|
||||
border-color 0.18s ease, color 0.18s ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--fg);
|
||||
color: #09090b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-1px);
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
color: var(--fg-muted);
|
||||
border: 1px solid var(--border);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.btn-ghost:hover {
|
||||
color: var(--fg);
|
||||
border-color: var(--border-strong);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 14px 22px;
|
||||
font-size: 15px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.tile {
|
||||
position: relative;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0));
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
@@ -253,26 +120,11 @@ const {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
50% { opacity: 0.4; }
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes floatDrift {
|
||||
0%, 100% { translate: 0 0; }
|
||||
50% { translate: 0 -10px; }
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
50% { opacity: 0; }
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* ── Page ── */
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
@@ -280,131 +132,97 @@ const {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
/* ── Navbar ── */
|
||||
|
||||
.nav {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
backdrop-filter: blur(18px);
|
||||
-webkit-backdrop-filter: blur(18px);
|
||||
background: color-mix(in srgb, var(--bg) 75%, transparent);
|
||||
border-bottom: 1px solid transparent;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.nav.is-scrolled {
|
||||
border-bottom-color: var(--border);
|
||||
}
|
||||
|
||||
.nav-inner {
|
||||
max-width: 1240px;
|
||||
margin: 0 auto;
|
||||
padding: 12px 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
padding: 1.5rem 2.5rem;
|
||||
opacity: 0.5;
|
||||
transition: opacity 0.4s ease;
|
||||
}
|
||||
|
||||
.nav:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.nav-brand {
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--fg);
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-brand:hover {
|
||||
color: #fff;
|
||||
.nav-icon {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.nav-brand-name {
|
||||
font-size: 16px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.025em;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.nav-right {
|
||||
display: inline-flex;
|
||||
.nav-github {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.nav-gh {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 7px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
gap: 0.35rem;
|
||||
color: var(--fg-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
|
||||
font-size: 0.875rem;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-gh:hover {
|
||||
.nav-github:hover {
|
||||
color: var(--fg);
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border-color: var(--border-strong);
|
||||
}
|
||||
|
||||
.nav-github-arrow {
|
||||
display: inline-block;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-github:hover .nav-github-arrow {
|
||||
transform: translateX(2px) translateY(-1px);
|
||||
}
|
||||
|
||||
/* ── Main content ── */
|
||||
|
||||
.main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* ── Footer ── */
|
||||
|
||||
.footer {
|
||||
margin-top: auto;
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 40px 0 32px;
|
||||
}
|
||||
|
||||
.footer-inner {
|
||||
max-width: 1240px;
|
||||
margin: 0 auto;
|
||||
padding: 0 32px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 24px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.footer-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 13px;
|
||||
padding: 1.5rem 2.5rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--fg-dim);
|
||||
}
|
||||
|
||||
.footer-brand img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.footer-links {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.footer-links a {
|
||||
font-size: 13px;
|
||||
color: var(--fg-dim);
|
||||
transition: color 0.2s ease;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.footer-links a:hover {
|
||||
color: var(--fg);
|
||||
}
|
||||
|
||||
@media (max-width: 820px) {
|
||||
.nav-inner,
|
||||
.footer-inner {
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
/* ── Mobile ── */
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.nav {
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 1.25rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,123 +0,0 @@
|
||||
export type Tweet = {
|
||||
handle: string;
|
||||
content: string;
|
||||
excerpt?: string;
|
||||
link: string;
|
||||
};
|
||||
|
||||
export const tweets = [
|
||||
{
|
||||
handle: "Shay_Benshabtay",
|
||||
content:
|
||||
"T3 code is not perfect, but it's damn good. Open and fun , I can make my own fork for my uses and use the great tooling with my own needs.",
|
||||
link: "https://x.com/Shay_Benshabtay/status/2054668503857156326",
|
||||
},
|
||||
{
|
||||
handle: "teja2495",
|
||||
content:
|
||||
"I’ve completely switched to T3 Code for all my workflows. I just switch between different subscriptions and harnesses depending on what I need.",
|
||||
excerpt: "I’ve completely switched to T3 Code for all my workflows.",
|
||||
link: "https://x.com/teja2495/status/2052420254991581623",
|
||||
},
|
||||
{
|
||||
handle: "developedbyed",
|
||||
content: "might say alpha but T3 code is pretty awesome, really fast too",
|
||||
link: "https://x.com/developedbyed/status/2030627970532921605",
|
||||
},
|
||||
{
|
||||
handle: "tannerlinsley",
|
||||
content:
|
||||
"The minute T3 Code supports Claude Code, it could potentially become my daily driver. There's something special there.",
|
||||
link: "https://x.com/tannerlinsley/status/2031102771529920966",
|
||||
},
|
||||
{
|
||||
handle: "aronprins",
|
||||
content:
|
||||
"I already loved T3 Code by @theo and @jullerino, but their Connections implementation is next level epic and for this they should both earn maximum repect 🔥🫡",
|
||||
excerpt: "I already loved T3 Code, but their Connections implementation is next level epic.",
|
||||
link: "https://x.com/aronprins/status/2045102518196183109",
|
||||
},
|
||||
{
|
||||
handle: "BennettBuhner",
|
||||
content:
|
||||
"T3 Code is literally Codex but better; all your favorite models and harnesses, accessible anywhere! The app is great but the website is even greater, so instead of needing to SSH into a machine, T3 IS my SSH!",
|
||||
excerpt:
|
||||
"T3 Code is literally Codex but better; all your favorite models and harnesses, accessible anywhere.",
|
||||
link: "https://x.com/BennettBuhner/status/2054667115697754387",
|
||||
},
|
||||
{
|
||||
handle: "ex0t1clol",
|
||||
content: "T3 Code is proof electron apps don't have to suck",
|
||||
link: "https://x.com/ex0t1clol/status/2054666870008021197",
|
||||
},
|
||||
{
|
||||
handle: "Josikinz",
|
||||
content:
|
||||
"T3 code is better because it’s like if the codex Mac app didn’t make my computer run like shit 😋",
|
||||
link: "https://x.com/Josikinz/status/2030367951694745870",
|
||||
},
|
||||
{
|
||||
handle: "jetpackjoe_",
|
||||
content: "T3 code is pretty alright I guess",
|
||||
link: "https://x.com/jetpackjoe_/status/2054666792933404959",
|
||||
},
|
||||
{
|
||||
handle: "mil000",
|
||||
content: "T3 code saved my relationship!",
|
||||
link: "https://x.com/mil000/status/2030120041451246071",
|
||||
},
|
||||
{
|
||||
handle: "_winter_wonders",
|
||||
content: "Heartbreaking: AI-hater has to admit T3 Code is really good.",
|
||||
link: "https://x.com/_winter_wonders/status/2052350198764970434",
|
||||
},
|
||||
{
|
||||
handle: "kostyniuk00",
|
||||
content:
|
||||
"I was not expecting a year ago, that my anti-AI colleagues would thank me a year later, for persuading them to try T3 Code Beta, that really helped them with organizing their workflows. \n\nFantastic product by @jullerino and @theo. Go try it out if you haven’t yet!",
|
||||
excerpt:
|
||||
"My anti-AI colleagues thanked me for persuading them to try T3 Code Beta. Fantastic product.",
|
||||
link: "https://x.com/kostyniuk00/status/2052041388179468521",
|
||||
},
|
||||
{
|
||||
handle: "gnukeith",
|
||||
content:
|
||||
"I tried T3 Code it actually fixed issues that Opus couldn’t solve in Claude Code + Theo has replied with “UwU” under my post. Dario has not.",
|
||||
link: "https://x.com/gnukeith/status/2054670073579630730",
|
||||
},
|
||||
{
|
||||
handle: "peculiarnewbie",
|
||||
content: "T3 Code is iOS and other harnesses are androids",
|
||||
link: "https://x.com/peculiarnewbie/status/2054671685027233827",
|
||||
},
|
||||
{
|
||||
handle: "leodev",
|
||||
content:
|
||||
"T3 Code is probably the first coding gui that didn't suck performance wise and had a smart team behind it.",
|
||||
link: "https://x.com/leodev/status/2054679746353537042",
|
||||
},
|
||||
{
|
||||
handle: "pocarles",
|
||||
content:
|
||||
"Only using Codex and T3 now.\n\nI thought all AI coding harnesses had roughly the same impact. Using T3 Code taught me how wrong I was. The interface between you and the model changes everything.",
|
||||
excerpt:
|
||||
"Using T3 Code taught me how wrong I was. The interface between you and the model changes everything.",
|
||||
link: "https://x.com/pocarles/status/2054673964274758046",
|
||||
},
|
||||
{
|
||||
handle: "DavidKPiano",
|
||||
content: "It's like Claude Code if they didn't vibe-code the entire thing",
|
||||
link: "https://x.com/DavidKPiano/status/2054682983504719930",
|
||||
},
|
||||
{
|
||||
handle: "iamkaffe",
|
||||
content: "T3Code was the first one to truly care about Linux users.",
|
||||
link: "https://x.com/iamkaffe/status/2054675539311411280",
|
||||
},
|
||||
{
|
||||
handle: "uwunetes",
|
||||
content:
|
||||
"claude code make me go *whine whine whine* and t3 code make me go woof woof awooooo!!!",
|
||||
link: "https://x.com/uwunetes/status/2054683356022120640",
|
||||
},
|
||||
] satisfies Tweet[];
|
||||
@@ -4,7 +4,6 @@ import { RELEASES_URL } from "../lib/releases";
|
||||
---
|
||||
|
||||
<Layout title="Download — T3 Code" description="Download T3 Code for macOS, Windows, or Linux.">
|
||||
<div class="download-page">
|
||||
<h1 class="heading">Download T3 Code</h1>
|
||||
<p class="subheading">
|
||||
<span id="version-label">Loading latest release…</span>
|
||||
@@ -65,7 +64,6 @@ import { RELEASES_URL } from "../lib/releases";
|
||||
GitHub releases page<span aria-hidden="true"> ↗</span>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
@@ -113,11 +111,7 @@ import { RELEASES_URL } from "../lib/releases";
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.download-page {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
.main {
|
||||
padding: 8vh 1.5rem 4rem;
|
||||
}
|
||||
|
||||
@@ -263,7 +257,7 @@ import { RELEASES_URL } from "../lib/releases";
|
||||
/* ── Mobile ── */
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.download-page {
|
||||
.main {
|
||||
padding: 5vh 1.25rem 4rem;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
https://x.com/Shay_Benshabtay/status/2054668503857156326
|
||||
https://x.com/teja2495/status/2052420254991581623
|
||||
https://x.com/developedbyed/status/2030627970532921605
|
||||
https://x.com/tannerlinsley/status/2031102771529920966
|
||||
https://x.com/aronprins/status/2045102518196183109
|
||||
https://x.com/BennettBuhner/status/2054667115697754387
|
||||
https://x.com/ex0t1clol/status/2054666870008021197
|
||||
https://x.com/Josikinz/status/2030367951694745870
|
||||
https://x.com/jetpackjoe_/status/2054666792933404959
|
||||
https://x.com/mil000/status/2030120041451246071
|
||||
https://x.com/_winter_wonders/status/2052350198764970434
|
||||
https://x.com/kostyniuk00/status/2052041388179468521
|
||||
https://x.com/gnukeith/status/2054670073579630730
|
||||
https://x.com/peculiarnewbie/status/2054671685027233827
|
||||
https://x.com/leodev/status/2054679746353537042
|
||||
https://x.com/pocarles/status/2054673964274758046
|
||||
https://x.com/DavidKPiano/status/2054682983504719930
|
||||
https://x.com/iamkaffe/status/2054675539311411280
|
||||
https://x.com/uwunetes/status/2054683356022120640
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.23",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -20,13 +20,13 @@
|
||||
"build:bundle": "tsdown",
|
||||
"start": "node dist/bin.mjs",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
"test": "vitest run",
|
||||
"test:process-reaper": "vitest run src/server.test.ts src/provider/Layers/ClaudeAdapter.test.ts src/provider/Layers/ProviderSessionDirectory.test.ts src/provider/Layers/ProviderSessionReaper.test.ts src/provider/Layers/CodexAdapter.test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.2.111",
|
||||
"@effect/platform-bun": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/platform-node-shared": "catalog:",
|
||||
"@effect/sql-sqlite-bun": "catalog:",
|
||||
"@opencode-ai/sdk": "^1.3.15",
|
||||
"@pierre/diffs": "catalog:",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import { assert, describe, expect, it } from "@effect/vitest";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -41,7 +41,7 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
assert.deepEqual(rows, [
|
||||
expect(rows).toEqual([
|
||||
{
|
||||
pid: 10,
|
||||
ppid: 1,
|
||||
@@ -66,32 +66,15 @@ describe("ProcessDiagnostics", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("parses Windows process JSON through schema decoding", () =>
|
||||
it.effect("parses Windows process JSON with the schema decoder", () =>
|
||||
Effect.sync(() => {
|
||||
const rows = ProcessDiagnostics.parseWindowsProcessRows(
|
||||
JSON.stringify([
|
||||
{
|
||||
ProcessId: 10,
|
||||
ParentProcessId: 1,
|
||||
Name: "node.exe",
|
||||
CommandLine: "node server.js",
|
||||
Status: "Running",
|
||||
WorkingSetSize: 1024,
|
||||
PercentProcessorTime: 1.5,
|
||||
},
|
||||
{
|
||||
ProcessId: 11,
|
||||
ParentProcessId: 10,
|
||||
Name: "child.exe",
|
||||
CommandLine: "",
|
||||
WorkingSetSize: 2048.2,
|
||||
},
|
||||
{
|
||||
ProcessId: "bad",
|
||||
ParentProcessId: 10,
|
||||
Name: "ignored.exe",
|
||||
},
|
||||
]),
|
||||
[
|
||||
"[",
|
||||
'{"ProcessId":10,"ParentProcessId":1,"Name":"node.exe","CommandLine":"node server.js","Status":null,"WorkingSetSize":2048,"PercentProcessorTime":1.25},',
|
||||
'{"ProcessId":11,"ParentProcessId":10,"Name":"agent.exe","CommandLine":null,"Status":"Running","WorkingSetSize":4096,"PercentProcessorTime":0}',
|
||||
"]",
|
||||
].join(""),
|
||||
);
|
||||
|
||||
assert.deepEqual(rows, [
|
||||
@@ -99,9 +82,9 @@ describe("ProcessDiagnostics", () => {
|
||||
pid: 10,
|
||||
ppid: 1,
|
||||
pgid: null,
|
||||
status: "Running",
|
||||
cpuPercent: 1.5,
|
||||
rssBytes: 1024,
|
||||
status: "Live",
|
||||
cpuPercent: 1.25,
|
||||
rssBytes: 2048,
|
||||
elapsed: "",
|
||||
command: "node server.js",
|
||||
},
|
||||
@@ -109,15 +92,14 @@ describe("ProcessDiagnostics", () => {
|
||||
pid: 11,
|
||||
ppid: 10,
|
||||
pgid: null,
|
||||
status: "Live",
|
||||
status: "Running",
|
||||
cpuPercent: 0,
|
||||
rssBytes: 2048,
|
||||
rssBytes: 4096,
|
||||
elapsed: "",
|
||||
command: "child.exe",
|
||||
command: "agent.exe",
|
||||
},
|
||||
]);
|
||||
|
||||
assert.deepEqual(ProcessDiagnostics.parseWindowsProcessRows("not-json"), []);
|
||||
assert.deepEqual(ProcessDiagnostics.parseWindowsProcessRows("{"), []);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -180,21 +162,15 @@ describe("ProcessDiagnostics", () => {
|
||||
],
|
||||
});
|
||||
|
||||
assert.equal(diagnostics.serverPid, 100);
|
||||
assert.equal(DateTime.formatIso(diagnostics.readAt), "2026-05-05T10:00:00.000Z");
|
||||
assert.equal(diagnostics.processCount, 2);
|
||||
assert.equal(diagnostics.totalRssBytes, 6_000);
|
||||
assert.equal(diagnostics.totalCpuPercent, 4.75);
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[101, 102],
|
||||
);
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.depth),
|
||||
[0, 1],
|
||||
);
|
||||
assert.equal(Option.getOrNull(diagnostics.processes[0]!.pgid), 100);
|
||||
assert.deepEqual(diagnostics.processes[0]?.childPids, [102]);
|
||||
expect(diagnostics.serverPid).toBe(100);
|
||||
expect(DateTime.formatIso(diagnostics.readAt)).toBe("2026-05-05T10:00:00.000Z");
|
||||
expect(diagnostics.processCount).toBe(2);
|
||||
expect(diagnostics.totalRssBytes).toBe(6_000);
|
||||
expect(diagnostics.totalCpuPercent).toBe(4.75);
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([101, 102]);
|
||||
expect(diagnostics.processes.map((process) => process.depth)).toEqual([0, 1]);
|
||||
expect(Option.getOrNull(diagnostics.processes[0]!.pgid)).toBe(100);
|
||||
expect(diagnostics.processes[0]?.childPids).toEqual([102]);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -237,10 +213,7 @@ describe("ProcessDiagnostics", () => {
|
||||
],
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[101, 102, 103],
|
||||
);
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([101, 102, 103]);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -248,8 +221,9 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.gen(function* () {
|
||||
const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> =
|
||||
[];
|
||||
const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: (command) => {
|
||||
const spawnerLayer = Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make((command) => {
|
||||
const childProcess = command as unknown as {
|
||||
readonly command: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
@@ -263,8 +237,8 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
const layer = ProcessDiagnostics.layer.pipe(Layer.provide(spawnerLayer));
|
||||
|
||||
const diagnostics = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
|
||||
@@ -272,11 +246,8 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.provide(layer),
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
diagnostics.processes.map((process) => process.pid),
|
||||
[4242],
|
||||
);
|
||||
assert.deepEqual(commands, [
|
||||
expect(diagnostics.processes.map((process) => process.pid)).toEqual([4242]);
|
||||
expect(commands).toEqual([
|
||||
{
|
||||
command: "ps",
|
||||
args: ["-axo", "pid=,ppid=,pgid=,stat=,pcpu=,rss=,etime=,command="],
|
||||
@@ -287,8 +258,9 @@ describe("ProcessDiagnostics", () => {
|
||||
|
||||
it.effect("does not allow signaling the diagnostics query process", () =>
|
||||
Effect.gen(function* () {
|
||||
const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: () =>
|
||||
const spawnerLayer = Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() =>
|
||||
Effect.succeed(
|
||||
mockHandle({
|
||||
stdout: [
|
||||
@@ -297,7 +269,8 @@ describe("ProcessDiagnostics", () => {
|
||||
].join("\n"),
|
||||
}),
|
||||
),
|
||||
});
|
||||
),
|
||||
);
|
||||
const layer = ProcessDiagnostics.layer.pipe(Layer.provide(spawnerLayer));
|
||||
|
||||
const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
|
||||
@@ -305,7 +278,7 @@ describe("ProcessDiagnostics", () => {
|
||||
Effect.provide(layer),
|
||||
);
|
||||
|
||||
assert.deepEqual(result, {
|
||||
expect(result).toEqual({
|
||||
pid: 4242,
|
||||
signal: "SIGINT",
|
||||
signaled: false,
|
||||
|
||||
@@ -15,7 +15,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { collectUint8StreamText } from "../stream/collectUint8StreamText.ts";
|
||||
|
||||
export interface ProcessRow {
|
||||
interface ProcessRow {
|
||||
readonly pid: number;
|
||||
readonly ppid: number;
|
||||
readonly pgid: number | null;
|
||||
@@ -52,6 +52,20 @@ class ProcessDiagnosticsError extends Schema.TaggedErrorClass<ProcessDiagnostics
|
||||
) {}
|
||||
const isProcessDiagnosticsError = Schema.is(ProcessDiagnosticsError);
|
||||
|
||||
const WindowsProcessRecord = Schema.Struct({
|
||||
ProcessId: Schema.Number,
|
||||
ParentProcessId: Schema.Number,
|
||||
CommandLine: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
Name: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
PercentProcessorTime: Schema.optional(Schema.NullOr(Schema.Number)),
|
||||
Status: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
WorkingSetSize: Schema.optional(Schema.NullOr(Schema.Number)),
|
||||
});
|
||||
type WindowsProcessRecord = typeof WindowsProcessRecord.Type;
|
||||
|
||||
const decodeWindowsProcessJson = Schema.decodeOption(Schema.fromJsonString(Schema.Unknown));
|
||||
const decodeWindowsProcessRecord = Schema.decodeUnknownOption(WindowsProcessRecord);
|
||||
|
||||
function toProcessDiagnosticsError(message: string, cause?: unknown): ProcessDiagnosticsError {
|
||||
return new ProcessDiagnosticsError({
|
||||
message,
|
||||
@@ -74,21 +88,11 @@ function parseNumber(value: string): number | null {
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
const WindowsProcessRecord = Schema.Struct({
|
||||
CommandLine: Schema.optional(Schema.Unknown),
|
||||
Name: Schema.optional(Schema.Unknown),
|
||||
ParentProcessId: Schema.optional(Schema.Unknown),
|
||||
PercentProcessorTime: Schema.optional(Schema.Unknown),
|
||||
ProcessId: Schema.optional(Schema.Unknown),
|
||||
Status: Schema.optional(Schema.Unknown),
|
||||
WorkingSetSize: Schema.optional(Schema.Unknown),
|
||||
});
|
||||
type WindowsProcessRecord = typeof WindowsProcessRecord.Type;
|
||||
|
||||
const WindowsProcessOutput = Schema.fromJsonString(
|
||||
Schema.Union([WindowsProcessRecord, Schema.Array(WindowsProcessRecord)]),
|
||||
);
|
||||
const decodeWindowsProcessOutput = Schema.decodeUnknownOption(WindowsProcessOutput);
|
||||
const trimNonEmptyOption = (value: string | null | undefined): Option.Option<string> =>
|
||||
Option.fromNullishOr(value).pipe(
|
||||
Option.map((entry) => entry.trim()),
|
||||
Option.filter((entry) => entry.length > 0),
|
||||
);
|
||||
|
||||
export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
const rows: ProcessRow[] = [];
|
||||
@@ -155,52 +159,57 @@ export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow>
|
||||
return rows;
|
||||
}
|
||||
|
||||
function normalizeWindowsProcessRow(record: WindowsProcessRecord): ProcessRow | null {
|
||||
const pid = typeof record.ProcessId === "number" ? record.ProcessId : null;
|
||||
const ppid = typeof record.ParentProcessId === "number" ? record.ParentProcessId : null;
|
||||
const commandLine =
|
||||
typeof record.CommandLine === "string" && record.CommandLine.trim().length > 0
|
||||
? record.CommandLine
|
||||
: typeof record.Name === "string"
|
||||
? record.Name
|
||||
: null;
|
||||
const workingSet =
|
||||
typeof record.WorkingSetSize === "number" && Number.isFinite(record.WorkingSetSize)
|
||||
? Math.max(0, Math.round(record.WorkingSetSize))
|
||||
: 0;
|
||||
const cpuPercent =
|
||||
typeof record.PercentProcessorTime === "number" && Number.isFinite(record.PercentProcessorTime)
|
||||
? Math.max(0, record.PercentProcessorTime)
|
||||
: 0;
|
||||
function normalizeWindowsProcessRow(value: unknown): Option.Option<ProcessRow> {
|
||||
return decodeWindowsProcessRecord(value).pipe(
|
||||
Option.flatMap((record: WindowsProcessRecord) => {
|
||||
const commandLine = trimNonEmptyOption(record.CommandLine).pipe(
|
||||
Option.orElse(() => trimNonEmptyOption(record.Name)),
|
||||
);
|
||||
if (
|
||||
!Number.isInteger(record.ProcessId) ||
|
||||
record.ProcessId <= 0 ||
|
||||
!Number.isInteger(record.ParentProcessId) ||
|
||||
record.ParentProcessId < 0 ||
|
||||
Option.isNone(commandLine)
|
||||
) {
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
if (!pid || pid <= 0 || ppid === null || ppid < 0 || !commandLine) return null;
|
||||
return {
|
||||
pid,
|
||||
ppid,
|
||||
pgid: null,
|
||||
status: typeof record.Status === "string" && record.Status.length > 0 ? record.Status : "Live",
|
||||
cpuPercent,
|
||||
rssBytes: workingSet,
|
||||
elapsed: "",
|
||||
command: commandLine,
|
||||
};
|
||||
return Option.some({
|
||||
pid: record.ProcessId,
|
||||
ppid: record.ParentProcessId,
|
||||
pgid: null,
|
||||
status: Option.getOrElse(trimNonEmptyOption(record.Status), () => "Live"),
|
||||
cpuPercent:
|
||||
typeof record.PercentProcessorTime === "number" &&
|
||||
Number.isFinite(record.PercentProcessorTime)
|
||||
? Math.max(0, record.PercentProcessorTime)
|
||||
: 0,
|
||||
rssBytes:
|
||||
typeof record.WorkingSetSize === "number" && Number.isFinite(record.WorkingSetSize)
|
||||
? Math.max(0, Math.round(record.WorkingSetSize))
|
||||
: 0,
|
||||
elapsed: "",
|
||||
command: commandLine.value,
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
|
||||
if (output.trim().length === 0) return [];
|
||||
const parsed = decodeWindowsProcessOutput(output);
|
||||
if (Option.isNone(parsed)) {
|
||||
return [];
|
||||
}
|
||||
const parsed = decodeWindowsProcessJson(output);
|
||||
if (Option.isNone(parsed)) return [];
|
||||
|
||||
const records = Array.isArray(parsed.value) ? parsed.value : [parsed.value];
|
||||
return records.flatMap((record) => {
|
||||
const row = normalizeWindowsProcessRow(record);
|
||||
return row ? [row] : [];
|
||||
});
|
||||
return records.flatMap((record) =>
|
||||
Option.match(normalizeWindowsProcessRow(record), {
|
||||
onNone: () => [],
|
||||
onSome: (row) => [row],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function buildDescendantEntries(
|
||||
function buildDescendantEntries(
|
||||
rows: ReadonlyArray<ProcessRow>,
|
||||
serverPid: number,
|
||||
): ReadonlyArray<ServerProcessDiagnosticsEntry> {
|
||||
@@ -244,7 +253,7 @@ export function buildDescendantEntries(
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function isDiagnosticsQueryProcess(row: ProcessRow, serverPid: number): boolean {
|
||||
function isDiagnosticsQueryProcess(row: ProcessRow, serverPid: number): boolean {
|
||||
if (row.ppid !== serverPid) return false;
|
||||
|
||||
const command = row.command.trim();
|
||||
@@ -384,7 +393,7 @@ function readWindowsProcessRows(): Effect.Effect<
|
||||
);
|
||||
}
|
||||
|
||||
export const readProcessRows = (platform = process.platform) =>
|
||||
const readProcessRows = (platform = process.platform) =>
|
||||
platform === "win32" ? readWindowsProcessRows() : readPosixProcessRows();
|
||||
|
||||
export function aggregateProcessDiagnostics(input: {
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import {
|
||||
aggregateProcessResourceHistory,
|
||||
collectMonitoredSamples,
|
||||
} from "./ProcessResourceMonitor.ts";
|
||||
|
||||
describe("ProcessResourceMonitor", () => {
|
||||
it.effect("samples the server root process and descendants", () =>
|
||||
Effect.sync(() => {
|
||||
const sampledAt = DateTime.makeUnsafe("2026-05-05T10:00:00.000Z");
|
||||
const samples = collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(sampledAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 2,
|
||||
rssBytes: 1_000,
|
||||
elapsed: "01:00",
|
||||
command: "t3 server",
|
||||
},
|
||||
{
|
||||
pid: 101,
|
||||
ppid: 100,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 10,
|
||||
rssBytes: 2_000,
|
||||
elapsed: "00:20",
|
||||
command: "codex app-server",
|
||||
},
|
||||
{
|
||||
pid: 102,
|
||||
ppid: 101,
|
||||
pgid: 100,
|
||||
status: "R",
|
||||
cpuPercent: 50,
|
||||
rssBytes: 3_000,
|
||||
elapsed: "00:05",
|
||||
command: "rg needle",
|
||||
},
|
||||
{
|
||||
pid: 200,
|
||||
ppid: 1,
|
||||
pgid: 200,
|
||||
status: "R",
|
||||
cpuPercent: 99,
|
||||
rssBytes: 9_000,
|
||||
elapsed: "00:05",
|
||||
command: "unrelated",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(samples.map((sample) => sample.pid)).toEqual([100, 101, 102]);
|
||||
expect(samples.map((sample) => sample.depth)).toEqual([0, 1, 2]);
|
||||
expect(samples[0]?.isServerRoot).toBe(true);
|
||||
expect(samples[1]?.isServerRoot).toBe(false);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rolls samples up by process and CPU time", () =>
|
||||
Effect.sync(() => {
|
||||
const firstAt = DateTime.makeUnsafe("2026-05-05T10:00:00.000Z");
|
||||
const secondAt = DateTime.makeUnsafe("2026-05-05T10:00:05.000Z");
|
||||
const samples = [
|
||||
...collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt: firstAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(firstAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 10,
|
||||
rssBytes: 1_000,
|
||||
elapsed: "01:00",
|
||||
command: "t3 server",
|
||||
},
|
||||
],
|
||||
}),
|
||||
...collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt: secondAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(secondAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 30,
|
||||
rssBytes: 2_000,
|
||||
elapsed: "01:05",
|
||||
command: "t3 server",
|
||||
},
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const result = aggregateProcessResourceHistory({
|
||||
samples,
|
||||
readAt: secondAt,
|
||||
readAtMs: DateTime.toEpochMillis(secondAt),
|
||||
windowMs: 60_000,
|
||||
bucketMs: 10_000,
|
||||
lastError: null,
|
||||
});
|
||||
|
||||
expect(Option.isNone(result.error)).toBe(true);
|
||||
expect(result.topProcesses).toHaveLength(1);
|
||||
expect(result.topProcesses[0]?.avgCpuPercent).toBe(20);
|
||||
expect(result.topProcesses[0]?.maxCpuPercent).toBe(30);
|
||||
expect(result.topProcesses[0]?.cpuSecondsApprox).toBe(2);
|
||||
expect(result.totalCpuSecondsApprox).toBe(2);
|
||||
expect(result.buckets.some((bucket) => bucket.maxCpuPercent === 30)).toBe(true);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps a process grouped when elapsed time drifts between samples", () =>
|
||||
Effect.sync(() => {
|
||||
const firstAt = DateTime.makeUnsafe("2026-05-05T10:00:00.400Z");
|
||||
const secondAt = DateTime.makeUnsafe("2026-05-05T10:00:05.900Z");
|
||||
const samples = [
|
||||
...collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt: firstAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(firstAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 1,
|
||||
rssBytes: 1_000,
|
||||
elapsed: "01:00",
|
||||
command: "t3 server",
|
||||
},
|
||||
],
|
||||
}),
|
||||
...collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt: secondAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(secondAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 2,
|
||||
rssBytes: 2_000,
|
||||
elapsed: "01:06",
|
||||
command: "t3 server",
|
||||
},
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const result = aggregateProcessResourceHistory({
|
||||
samples,
|
||||
readAt: secondAt,
|
||||
readAtMs: DateTime.toEpochMillis(secondAt),
|
||||
windowMs: 60_000,
|
||||
bucketMs: 10_000,
|
||||
lastError: null,
|
||||
});
|
||||
|
||||
expect(result.topProcesses).toHaveLength(1);
|
||||
expect(result.topProcesses[0]?.isServerRoot).toBe(true);
|
||||
expect(result.topProcesses[0]?.sampleCount).toBe(2);
|
||||
expect(result.topProcesses[0]?.maxRssBytes).toBe(2_000);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("returns all process summaries in the selected window", () =>
|
||||
Effect.sync(() => {
|
||||
const sampledAt = DateTime.makeUnsafe("2026-05-05T10:00:00.000Z");
|
||||
const samples = collectMonitoredSamples({
|
||||
serverPid: 100,
|
||||
sampledAt,
|
||||
sampledAtMs: DateTime.toEpochMillis(sampledAt),
|
||||
rows: [
|
||||
{
|
||||
pid: 100,
|
||||
ppid: 1,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 1,
|
||||
rssBytes: 1_000,
|
||||
elapsed: "01:00",
|
||||
command: "t3 server",
|
||||
},
|
||||
...Array.from({ length: 35 }, (_, index) => ({
|
||||
pid: 200 + index,
|
||||
ppid: index === 0 ? 100 : 199 + index,
|
||||
pgid: 100,
|
||||
status: "S",
|
||||
cpuPercent: 35 - index,
|
||||
rssBytes: 2_000 + index,
|
||||
elapsed: "00:10",
|
||||
command: `worker ${index}`,
|
||||
})),
|
||||
],
|
||||
});
|
||||
|
||||
const result = aggregateProcessResourceHistory({
|
||||
samples,
|
||||
readAt: sampledAt,
|
||||
readAtMs: DateTime.toEpochMillis(sampledAt),
|
||||
windowMs: 60_000,
|
||||
bucketMs: 10_000,
|
||||
lastError: null,
|
||||
});
|
||||
|
||||
expect(result.topProcesses).toHaveLength(36);
|
||||
expect(result.topProcesses.some((process) => process.command === "worker 34")).toBe(true);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -1,299 +0,0 @@
|
||||
import type {
|
||||
ServerProcessResourceHistoryBucket,
|
||||
ServerProcessResourceHistoryInput,
|
||||
ServerProcessResourceHistoryResult,
|
||||
ServerProcessResourceHistorySummary,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Ref from "effect/Ref";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import {
|
||||
buildDescendantEntries,
|
||||
isDiagnosticsQueryProcess,
|
||||
type ProcessRow,
|
||||
readProcessRows,
|
||||
} from "./ProcessDiagnostics.ts";
|
||||
|
||||
const SAMPLE_INTERVAL_MS = 5_000;
|
||||
const RETENTION_MS = 60 * 60_000;
|
||||
const MAX_RETAINED_SAMPLES = 20_000;
|
||||
|
||||
export interface ProcessResourceSample {
|
||||
readonly sampledAt: DateTime.Utc;
|
||||
readonly sampledAtMs: number;
|
||||
readonly processKey: string;
|
||||
readonly pid: number;
|
||||
readonly ppid: number;
|
||||
readonly command: string;
|
||||
readonly cpuPercent: number;
|
||||
readonly rssBytes: number;
|
||||
readonly depth: number;
|
||||
readonly isServerRoot: boolean;
|
||||
}
|
||||
|
||||
interface MonitorState {
|
||||
readonly samples: ReadonlyArray<ProcessResourceSample>;
|
||||
readonly lastError: string | null;
|
||||
}
|
||||
|
||||
export interface ProcessResourceMonitorShape {
|
||||
readonly readHistory: (
|
||||
input: ServerProcessResourceHistoryInput,
|
||||
) => Effect.Effect<ServerProcessResourceHistoryResult>;
|
||||
}
|
||||
|
||||
export class ProcessResourceMonitor extends Context.Service<
|
||||
ProcessResourceMonitor,
|
||||
ProcessResourceMonitorShape
|
||||
>()("t3/diagnostics/ProcessResourceMonitor") {}
|
||||
|
||||
function dateTimeFromMillis(ms: number): DateTime.Utc {
|
||||
return DateTime.makeUnsafe(ms);
|
||||
}
|
||||
|
||||
function sampleKey(row: Pick<ProcessRow, "pid" | "command">): string {
|
||||
return `${row.pid}:${row.command}`;
|
||||
}
|
||||
|
||||
function findServerRootRow(rows: ReadonlyArray<ProcessRow>, serverPid: number): ProcessRow | null {
|
||||
return rows.find((row) => row.pid === serverPid) ?? null;
|
||||
}
|
||||
|
||||
export function collectMonitoredSamples(input: {
|
||||
readonly rows: ReadonlyArray<ProcessRow>;
|
||||
readonly serverPid: number;
|
||||
readonly sampledAt: DateTime.Utc;
|
||||
readonly sampledAtMs: number;
|
||||
}): ReadonlyArray<ProcessResourceSample> {
|
||||
const rows = input.rows.filter((row) => !isDiagnosticsQueryProcess(row, input.serverPid));
|
||||
const root = findServerRootRow(rows, input.serverPid);
|
||||
const descendants = buildDescendantEntries(rows, input.serverPid);
|
||||
const samples: ProcessResourceSample[] = [];
|
||||
|
||||
if (root) {
|
||||
samples.push({
|
||||
sampledAt: input.sampledAt,
|
||||
sampledAtMs: input.sampledAtMs,
|
||||
processKey: sampleKey(root),
|
||||
pid: root.pid,
|
||||
ppid: root.ppid,
|
||||
command: root.command,
|
||||
cpuPercent: root.cpuPercent,
|
||||
rssBytes: root.rssBytes,
|
||||
depth: 0,
|
||||
isServerRoot: true,
|
||||
});
|
||||
}
|
||||
|
||||
for (const process of descendants) {
|
||||
samples.push({
|
||||
sampledAt: input.sampledAt,
|
||||
sampledAtMs: input.sampledAtMs,
|
||||
processKey: sampleKey(process),
|
||||
pid: process.pid,
|
||||
ppid: process.ppid,
|
||||
command: process.command,
|
||||
cpuPercent: process.cpuPercent,
|
||||
rssBytes: process.rssBytes,
|
||||
depth: process.depth + 1,
|
||||
isServerRoot: false,
|
||||
});
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
function trimSamples(
|
||||
samples: ReadonlyArray<ProcessResourceSample>,
|
||||
nowMs: number,
|
||||
): ReadonlyArray<ProcessResourceSample> {
|
||||
const minSampledAtMs = nowMs - RETENTION_MS;
|
||||
const retained = samples.filter((sample) => sample.sampledAtMs >= minSampledAtMs);
|
||||
return retained.length <= MAX_RETAINED_SAMPLES
|
||||
? retained
|
||||
: retained.slice(retained.length - MAX_RETAINED_SAMPLES);
|
||||
}
|
||||
|
||||
function summarizeProcesses(
|
||||
samples: ReadonlyArray<ProcessResourceSample>,
|
||||
): ReadonlyArray<ServerProcessResourceHistorySummary> {
|
||||
const groups = new Map<string, ProcessResourceSample[]>();
|
||||
for (const sample of samples) {
|
||||
const processSamples = groups.get(sample.processKey) ?? [];
|
||||
processSamples.push(sample);
|
||||
groups.set(sample.processKey, processSamples);
|
||||
}
|
||||
|
||||
return [...groups.entries()]
|
||||
.map(([processKey, processSamples]) => {
|
||||
const sorted = processSamples.toSorted((left, right) => left.sampledAtMs - right.sampledAtMs);
|
||||
const first = sorted[0]!;
|
||||
const latest = sorted[sorted.length - 1]!;
|
||||
const cpuPercentTotal = sorted.reduce((total, sample) => total + sample.cpuPercent, 0);
|
||||
const maxCpuPercent = Math.max(...sorted.map((sample) => sample.cpuPercent));
|
||||
const maxRssBytes = Math.max(...sorted.map((sample) => sample.rssBytes));
|
||||
const cpuSecondsApprox = sorted.reduce(
|
||||
(total, sample) => total + (sample.cpuPercent / 100) * (SAMPLE_INTERVAL_MS / 1_000),
|
||||
0,
|
||||
);
|
||||
|
||||
return {
|
||||
processKey,
|
||||
pid: latest.pid,
|
||||
ppid: latest.ppid,
|
||||
command: latest.command,
|
||||
depth: latest.depth,
|
||||
isServerRoot: latest.isServerRoot,
|
||||
firstSeenAt: first.sampledAt,
|
||||
lastSeenAt: latest.sampledAt,
|
||||
currentCpuPercent: latest.cpuPercent,
|
||||
avgCpuPercent: cpuPercentTotal / sorted.length,
|
||||
maxCpuPercent,
|
||||
cpuSecondsApprox,
|
||||
currentRssBytes: latest.rssBytes,
|
||||
maxRssBytes,
|
||||
sampleCount: sorted.length,
|
||||
} satisfies ServerProcessResourceHistorySummary;
|
||||
})
|
||||
.toSorted((left, right) => right.cpuSecondsApprox - left.cpuSecondsApprox);
|
||||
}
|
||||
|
||||
function buildBuckets(input: {
|
||||
readonly samples: ReadonlyArray<ProcessResourceSample>;
|
||||
readonly nowMs: number;
|
||||
readonly windowMs: number;
|
||||
readonly bucketMs: number;
|
||||
}): ReadonlyArray<ServerProcessResourceHistoryBucket> {
|
||||
const bucketMs = Math.max(1_000, input.bucketMs);
|
||||
const windowStartMs = input.nowMs - input.windowMs;
|
||||
const buckets: ServerProcessResourceHistoryBucket[] = [];
|
||||
|
||||
for (let startedAtMs = windowStartMs; startedAtMs < input.nowMs; startedAtMs += bucketMs) {
|
||||
const endedAtMs = Math.min(input.nowMs, startedAtMs + bucketMs);
|
||||
const bucketSamples = input.samples.filter(
|
||||
(sample) =>
|
||||
sample.sampledAtMs >= startedAtMs &&
|
||||
(endedAtMs === input.nowMs
|
||||
? sample.sampledAtMs <= endedAtMs
|
||||
: sample.sampledAtMs < endedAtMs),
|
||||
);
|
||||
const samplesByRead = new Map<number, ProcessResourceSample[]>();
|
||||
for (const sample of bucketSamples) {
|
||||
const samplesAtTime = samplesByRead.get(sample.sampledAtMs) ?? [];
|
||||
samplesAtTime.push(sample);
|
||||
samplesByRead.set(sample.sampledAtMs, samplesAtTime);
|
||||
}
|
||||
|
||||
const readTotals = [...samplesByRead.values()].map((samplesAtTime) => ({
|
||||
cpuPercent: samplesAtTime.reduce((total, sample) => total + sample.cpuPercent, 0),
|
||||
rssBytes: samplesAtTime.reduce((total, sample) => total + sample.rssBytes, 0),
|
||||
processCount: samplesAtTime.length,
|
||||
}));
|
||||
const avgCpuPercent =
|
||||
readTotals.length === 0
|
||||
? 0
|
||||
: readTotals.reduce((total, read) => total + read.cpuPercent, 0) / readTotals.length;
|
||||
|
||||
buckets.push({
|
||||
startedAt: dateTimeFromMillis(startedAtMs),
|
||||
endedAt: dateTimeFromMillis(endedAtMs),
|
||||
avgCpuPercent,
|
||||
maxCpuPercent: readTotals.length ? Math.max(...readTotals.map((read) => read.cpuPercent)) : 0,
|
||||
maxRssBytes: readTotals.length ? Math.max(...readTotals.map((read) => read.rssBytes)) : 0,
|
||||
maxProcessCount: readTotals.length
|
||||
? Math.max(...readTotals.map((read) => read.processCount))
|
||||
: 0,
|
||||
});
|
||||
}
|
||||
|
||||
return buckets;
|
||||
}
|
||||
|
||||
export function aggregateProcessResourceHistory(input: {
|
||||
readonly samples: ReadonlyArray<ProcessResourceSample>;
|
||||
readonly readAt: DateTime.Utc;
|
||||
readonly readAtMs: number;
|
||||
readonly windowMs: number;
|
||||
readonly bucketMs: number;
|
||||
readonly lastError: string | null;
|
||||
}): ServerProcessResourceHistoryResult {
|
||||
const windowMs = Math.max(1_000, input.windowMs);
|
||||
const bucketMs = Math.max(1_000, input.bucketMs);
|
||||
const minSampledAtMs = input.readAtMs - windowMs;
|
||||
const samples = input.samples.filter((sample) => sample.sampledAtMs >= minSampledAtMs);
|
||||
const topProcesses = summarizeProcesses(samples);
|
||||
const totalCpuSecondsApprox = samples.reduce(
|
||||
(total, sample) => total + (sample.cpuPercent / 100) * (SAMPLE_INTERVAL_MS / 1_000),
|
||||
0,
|
||||
);
|
||||
|
||||
return {
|
||||
readAt: input.readAt,
|
||||
windowMs,
|
||||
bucketMs,
|
||||
sampleIntervalMs: SAMPLE_INTERVAL_MS,
|
||||
retainedSampleCount: input.samples.length,
|
||||
totalCpuSecondsApprox,
|
||||
buckets: buildBuckets({ samples, nowMs: input.readAtMs, windowMs, bucketMs }),
|
||||
topProcesses,
|
||||
error: input.lastError ? Option.some({ message: input.lastError }) : Option.none(),
|
||||
};
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeProcessResourceMonitor")(function* () {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const state = yield* Ref.make<MonitorState>({ samples: [], lastError: null });
|
||||
|
||||
const sampleOnce = Effect.gen(function* () {
|
||||
const sampledAt = yield* DateTime.now;
|
||||
const sampledAtMs = DateTime.toEpochMillis(sampledAt);
|
||||
const rows = yield* readProcessRows().pipe(
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
);
|
||||
const samples = collectMonitoredSamples({
|
||||
rows,
|
||||
serverPid: process.pid,
|
||||
sampledAt,
|
||||
sampledAtMs,
|
||||
});
|
||||
yield* Ref.update(state, (current) => ({
|
||||
samples: trimSamples([...current.samples, ...samples], sampledAtMs),
|
||||
lastError: null,
|
||||
}));
|
||||
}).pipe(
|
||||
Effect.catch((error: unknown) =>
|
||||
Ref.update(state, (current) => ({
|
||||
...current,
|
||||
lastError: error instanceof Error ? error.message : "Failed to sample process resources.",
|
||||
})),
|
||||
),
|
||||
);
|
||||
|
||||
yield* Effect.forever(sampleOnce.pipe(Effect.andThen(Effect.sleep(SAMPLE_INTERVAL_MS)))).pipe(
|
||||
Effect.forkScoped,
|
||||
);
|
||||
|
||||
const readHistory: ProcessResourceMonitorShape["readHistory"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
const readAt = yield* DateTime.now;
|
||||
const readAtMs = DateTime.toEpochMillis(readAt);
|
||||
const current = yield* Ref.get(state);
|
||||
return aggregateProcessResourceHistory({
|
||||
samples: current.samples,
|
||||
readAt,
|
||||
readAtMs,
|
||||
windowMs: input.windowMs,
|
||||
bucketMs: input.bucketMs,
|
||||
lastError: current.lastError,
|
||||
});
|
||||
});
|
||||
|
||||
return ProcessResourceMonitor.of({ readHistory });
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(ProcessResourceMonitor, make());
|
||||
@@ -18,7 +18,6 @@ const DEFAULT_RPC_SPAN_ATTRIBUTES = {
|
||||
const RPC_METHODS_WITH_TRACING_DISABLED: ReadonlySet<string> = new Set([
|
||||
WS_METHODS.serverGetTraceDiagnostics,
|
||||
WS_METHODS.serverGetProcessDiagnostics,
|
||||
WS_METHODS.serverGetProcessResourceHistory,
|
||||
WS_METHODS.serverSignalProcess,
|
||||
]);
|
||||
|
||||
|
||||
@@ -115,7 +115,6 @@ import * as SourceControlRepositoryService from "./sourceControl/SourceControlRe
|
||||
import { ServerSecretStoreLive } from "./auth/Layers/ServerSecretStore.ts";
|
||||
import { ServerAuthLive } from "./auth/Layers/ServerAuth.ts";
|
||||
import * as ProcessDiagnostics from "./diagnostics/ProcessDiagnostics.ts";
|
||||
import * as ProcessResourceMonitor from "./diagnostics/ProcessResourceMonitor.ts";
|
||||
import * as TraceDiagnostics from "./diagnostics/TraceDiagnostics.ts";
|
||||
import * as Data from "effect/Data";
|
||||
|
||||
@@ -565,22 +564,6 @@ const buildAppUnderTest = (options?: {
|
||||
}),
|
||||
}),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(ProcessResourceMonitor.ProcessResourceMonitor)({
|
||||
readHistory: (input) =>
|
||||
Effect.succeed({
|
||||
readAt: TEST_EPOCH,
|
||||
windowMs: input.windowMs,
|
||||
bucketMs: input.bucketMs,
|
||||
sampleIntervalMs: 5_000,
|
||||
retainedSampleCount: 0,
|
||||
totalCpuSecondsApprox: 0,
|
||||
buckets: [],
|
||||
topProcesses: [],
|
||||
error: Option.none(),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(TraceDiagnostics.TraceDiagnostics)({
|
||||
read: () =>
|
||||
|
||||
@@ -76,7 +76,6 @@ import {
|
||||
import { ServerSecretStoreLive } from "./auth/Layers/ServerSecretStore.ts";
|
||||
import { ServerAuthLive } from "./auth/Layers/ServerAuth.ts";
|
||||
import * as ProcessDiagnostics from "./diagnostics/ProcessDiagnostics.ts";
|
||||
import * as ProcessResourceMonitor from "./diagnostics/ProcessResourceMonitor.ts";
|
||||
import * as TraceDiagnostics from "./diagnostics/TraceDiagnostics.ts";
|
||||
import { OrchestrationLayerLive } from "./orchestration/runtimeLayer.ts";
|
||||
import {
|
||||
@@ -281,7 +280,6 @@ const RuntimeCoreDependenciesLive = ReactorLayerLive.pipe(
|
||||
const RuntimeDependenciesLive = RuntimeCoreDependenciesLive.pipe(
|
||||
// Misc.
|
||||
Layer.provideMerge(ProcessDiagnostics.layer),
|
||||
Layer.provideMerge(ProcessResourceMonitor.layer),
|
||||
Layer.provideMerge(TraceDiagnostics.layer),
|
||||
Layer.provideMerge(AnalyticsServiceLayerLive),
|
||||
Layer.provideMerge(ExternalLauncher.layer),
|
||||
|
||||
@@ -310,29 +310,6 @@ describe("VcsStatusBroadcaster", () => {
|
||||
}).pipe(Effect.provide(makeTestLayer(state)));
|
||||
});
|
||||
|
||||
it("backs off remote refresh failures exponentially and honors larger configured intervals", () => {
|
||||
assert.equal(
|
||||
Duration.toMillis(VcsStatusBroadcaster.remoteRefreshFailureDelay(1, Duration.seconds(1))),
|
||||
30_000,
|
||||
);
|
||||
assert.equal(
|
||||
Duration.toMillis(VcsStatusBroadcaster.remoteRefreshFailureDelay(2, Duration.seconds(1))),
|
||||
60_000,
|
||||
);
|
||||
assert.equal(
|
||||
Duration.toMillis(VcsStatusBroadcaster.remoteRefreshFailureDelay(3, Duration.seconds(1))),
|
||||
120_000,
|
||||
);
|
||||
assert.equal(
|
||||
Duration.toMillis(VcsStatusBroadcaster.remoteRefreshFailureDelay(1, Duration.minutes(5))),
|
||||
300_000,
|
||||
);
|
||||
assert.equal(
|
||||
Duration.toMillis(VcsStatusBroadcaster.remoteRefreshFailureDelay(20, Duration.seconds(1))),
|
||||
900_000,
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("stops the remote poller after the last stream subscriber disconnects", () => {
|
||||
const state = {
|
||||
currentLocalStatus: baseLocalStatus,
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as SynchronizedRef from "effect/SynchronizedRef";
|
||||
@@ -24,8 +23,6 @@ import { mergeGitStatusParts } from "@t3tools/shared/git";
|
||||
import * as GitWorkflowService from "../git/GitWorkflowService.ts";
|
||||
|
||||
const DEFAULT_VCS_STATUS_REFRESH_INTERVAL = Duration.seconds(30);
|
||||
const VCS_STATUS_REFRESH_FAILURE_BASE_DELAY = Duration.seconds(30);
|
||||
const VCS_STATUS_REFRESH_FAILURE_MAX_DELAY = Duration.minutes(15);
|
||||
|
||||
interface VcsStatusChange {
|
||||
readonly cwd: string;
|
||||
@@ -51,20 +48,6 @@ interface StreamStatusOptions {
|
||||
readonly automaticRemoteRefreshInterval?: Effect.Effect<Duration.Duration, never>;
|
||||
}
|
||||
|
||||
export function remoteRefreshFailureDelay(
|
||||
consecutiveFailures: number,
|
||||
configuredInterval: Duration.Duration,
|
||||
) {
|
||||
const exponent = Math.max(0, consecutiveFailures - 1);
|
||||
const backoffMs =
|
||||
Duration.toMillis(VCS_STATUS_REFRESH_FAILURE_BASE_DELAY) * Math.pow(2, exponent);
|
||||
const cappedBackoff = Duration.min(
|
||||
Duration.millis(backoffMs),
|
||||
VCS_STATUS_REFRESH_FAILURE_MAX_DELAY,
|
||||
);
|
||||
return Duration.max(configuredInterval, cappedBackoff);
|
||||
}
|
||||
|
||||
export interface VcsStatusBroadcasterShape {
|
||||
readonly getStatus: (
|
||||
input: VcsStatusInput,
|
||||
@@ -258,46 +241,32 @@ export const layer = Layer.effect(
|
||||
cwd: string,
|
||||
automaticRemoteRefreshInterval: Effect.Effect<Duration.Duration, never>,
|
||||
) => {
|
||||
return Effect.gen(function* () {
|
||||
const consecutiveFailuresRef = yield* Ref.make(0);
|
||||
const refreshRemoteStatusIfEnabled = Effect.gen(function* () {
|
||||
const configuredInterval = yield* automaticRemoteRefreshInterval;
|
||||
const activeInterval = Duration.isZero(configuredInterval)
|
||||
? DEFAULT_VCS_STATUS_REFRESH_INTERVAL
|
||||
: configuredInterval;
|
||||
if (Duration.isZero(configuredInterval)) {
|
||||
return activeInterval;
|
||||
}
|
||||
|
||||
const exit = yield* refreshRemoteStatus(cwd).pipe(Effect.exit);
|
||||
if (Exit.isSuccess(exit)) {
|
||||
yield* Ref.set(consecutiveFailuresRef, 0);
|
||||
return activeInterval;
|
||||
}
|
||||
|
||||
const consecutiveFailures = yield* Ref.updateAndGet(
|
||||
consecutiveFailuresRef,
|
||||
(count) => count + 1,
|
||||
);
|
||||
const nextDelay = remoteRefreshFailureDelay(consecutiveFailures, activeInterval);
|
||||
yield* Effect.logWarning("VCS remote status refresh failed", {
|
||||
cwd,
|
||||
detail: exit.cause.toString(),
|
||||
consecutiveFailures,
|
||||
nextDelayMs: Duration.toMillis(nextDelay),
|
||||
});
|
||||
return nextDelay;
|
||||
const logRefreshFailure = (error: GitManagerServiceError) =>
|
||||
Effect.logWarning("VCS remote status refresh failed", {
|
||||
cwd,
|
||||
detail: error.message,
|
||||
});
|
||||
const refreshRemoteStatusIfEnabled = automaticRemoteRefreshInterval.pipe(
|
||||
Effect.flatMap((interval) =>
|
||||
Duration.isZero(interval) ? Effect.void : refreshRemoteStatus(cwd).pipe(Effect.asVoid),
|
||||
),
|
||||
);
|
||||
const sleepForConfiguredInterval = automaticRemoteRefreshInterval.pipe(
|
||||
Effect.flatMap((interval) =>
|
||||
Effect.sleep(Duration.isZero(interval) ? DEFAULT_VCS_STATUS_REFRESH_INTERVAL : interval),
|
||||
),
|
||||
);
|
||||
|
||||
return yield* refreshRemoteStatusIfEnabled.pipe(
|
||||
Effect.repeat(
|
||||
Schedule.identity<Duration.Duration>().pipe(
|
||||
Schedule.addDelay((delay) => Effect.succeed(delay)),
|
||||
return refreshRemoteStatusIfEnabled.pipe(
|
||||
Effect.catch(logRefreshFailure),
|
||||
Effect.andThen(
|
||||
Effect.forever(
|
||||
sleepForConfiguredInterval.pipe(
|
||||
Effect.andThen(refreshRemoteStatusIfEnabled.pipe(Effect.catch(logRefreshFailure))),
|
||||
),
|
||||
),
|
||||
Effect.asVoid,
|
||||
);
|
||||
});
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const retainRemotePoller = Effect.fn("VcsStatusBroadcaster.retainRemotePoller")(function* (
|
||||
|
||||
@@ -66,7 +66,6 @@ import { RepositoryIdentityResolver } from "./project/Services/RepositoryIdentit
|
||||
import { ServerEnvironment } from "./environment/Services/ServerEnvironment.ts";
|
||||
import { ServerAuth } from "./auth/Services/ServerAuth.ts";
|
||||
import * as ProcessDiagnostics from "./diagnostics/ProcessDiagnostics.ts";
|
||||
import * as ProcessResourceMonitor from "./diagnostics/ProcessResourceMonitor.ts";
|
||||
import * as TraceDiagnostics from "./diagnostics/TraceDiagnostics.ts";
|
||||
import * as SourceControlDiscoveryLayer from "./sourceControl/SourceControlDiscovery.ts";
|
||||
import { SourceControlRepositoryService } from "./sourceControl/SourceControlRepositoryService.ts";
|
||||
@@ -194,7 +193,6 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
const bootstrapCredentials = yield* BootstrapCredentialService;
|
||||
const sessions = yield* SessionCredentialService;
|
||||
const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics;
|
||||
const processResourceMonitor = yield* ProcessResourceMonitor.ProcessResourceMonitor;
|
||||
const serverCommandId = (tag: string) =>
|
||||
CommandId.make(`server:${tag}:${crypto.randomUUID()}`);
|
||||
|
||||
@@ -911,14 +909,6 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
observeRpcEffect(WS_METHODS.serverGetProcessDiagnostics, processDiagnostics.read, {
|
||||
"rpc.aggregate": "server",
|
||||
}),
|
||||
[WS_METHODS.serverGetProcessResourceHistory]: (input) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.serverGetProcessResourceHistory,
|
||||
processResourceMonitor.readHistory(input),
|
||||
{
|
||||
"rpc.aggregate": "server",
|
||||
},
|
||||
),
|
||||
[WS_METHODS.serverSignalProcess]: (input) =>
|
||||
observeRpcEffect(WS_METHODS.serverSignalProcess, processDiagnostics.signal(input), {
|
||||
"rpc.aggregate": "server",
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { defineConfig } from "tsdown";
|
||||
|
||||
const internalPackagePrefixes = ["@t3tools/", "effect-acp", "effect-codex-app-server"];
|
||||
|
||||
export default defineConfig({
|
||||
entry: ["src/bin.ts"],
|
||||
format: ["esm", "cjs"],
|
||||
checks: {
|
||||
legacyCjs: false,
|
||||
},
|
||||
outDir: "dist",
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
noExternal: (id) => internalPackagePrefixes.some((prefix) => id.startsWith(prefix)),
|
||||
noExternal: (id) => id.startsWith("@t3tools/") || id.startsWith("effect-acp"),
|
||||
inlineOnly: false,
|
||||
banner: {
|
||||
js: "#!/usr/bin/env node\n",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.23",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -727,16 +727,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
}),
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1025,23 +1018,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
|
||||
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -197,7 +196,6 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -210,7 +208,6 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -231,12 +228,11 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -347,7 +343,6 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -436,7 +431,6 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -36,7 +35,6 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -78,17 +76,8 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -99,7 +88,6 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -8,11 +8,7 @@ import {
|
||||
RefreshCwIcon,
|
||||
} from "lucide-react";
|
||||
import { useCallback, useMemo, useState, type ReactNode } from "react";
|
||||
import type {
|
||||
ServerProcessDiagnosticsEntry,
|
||||
ServerProcessResourceHistorySummary,
|
||||
ServerProcessSignal,
|
||||
} from "@t3tools/contracts";
|
||||
import type { ServerProcessDiagnosticsEntry, ServerProcessSignal } from "@t3tools/contracts";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
@@ -21,10 +17,7 @@ import { cn } from "../../lib/utils";
|
||||
import { resolveAndPersistPreferredEditor } from "../../editorPreferences";
|
||||
import { formatRelativeTime } from "../../timestampFormat";
|
||||
import { useServerAvailableEditors, useServerObservability } from "../../rpc/serverState";
|
||||
import {
|
||||
useProcessDiagnostics,
|
||||
useProcessResourceHistory,
|
||||
} from "../../lib/processDiagnosticsState";
|
||||
import { useProcessDiagnostics } from "../../lib/processDiagnosticsState";
|
||||
import { useTraceDiagnostics } from "../../lib/traceDiagnosticsState";
|
||||
import { Button } from "../ui/button";
|
||||
import { ScrollArea } from "../ui/scroll-area";
|
||||
@@ -316,7 +309,7 @@ function ProcessNameCell({
|
||||
return (
|
||||
<div
|
||||
className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
|
||||
style={{ paddingLeft: `${Math.min(process.depth, 6) * 10}px` }}
|
||||
style={{ paddingLeft: `${Math.min(process.depth, 8) * 16}px` }}
|
||||
>
|
||||
{hasChildren ? (
|
||||
<button
|
||||
@@ -331,17 +324,7 @@ function ProcessNameCell({
|
||||
<span className="size-5 shrink-0" aria-hidden="true" />
|
||||
)}
|
||||
<span className="size-1.5 shrink-0 rounded-full bg-emerald-500/80" />
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
|
||||
/>
|
||||
<TooltipPopup
|
||||
side="top"
|
||||
className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
|
||||
>
|
||||
{process.command}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
<span className="min-w-0 truncate font-medium text-foreground">{name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -439,7 +422,7 @@ function ProcessDiagnosticsTable({
|
||||
chainVerticalScroll
|
||||
scrollFade
|
||||
hideScrollbars
|
||||
className="max-h-[min(64vh,44rem)] w-full max-w-full rounded-none border-t border-border/60"
|
||||
className="w-full max-w-full rounded-none border-t border-border/60"
|
||||
>
|
||||
<table className="w-full min-w-[1040px] table-fixed text-left text-xs">
|
||||
<colgroup>
|
||||
@@ -451,7 +434,7 @@ function ProcessDiagnosticsTable({
|
||||
<col className="w-[11%]" />
|
||||
<col className="w-[6%]" />
|
||||
</colgroup>
|
||||
<thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
|
||||
<thead className="border-b border-border/60 bg-muted/15 text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
|
||||
<tr>
|
||||
<th className="px-4 py-2 font-semibold sm:pl-5">Name</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">CPU</th>
|
||||
@@ -459,7 +442,7 @@ function ProcessDiagnosticsTable({
|
||||
<th className="px-3 py-2 font-semibold">Command</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">PID</th>
|
||||
<th className="px-3 py-2 font-semibold">Type</th>
|
||||
<th className="p-2 text-right font-semibold sm:pr-4">Kill</th>
|
||||
<th className="px-2 py-2 text-right font-semibold sm:pr-4">Kill</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/50">
|
||||
@@ -504,7 +487,7 @@ function ProcessDiagnosticsTable({
|
||||
<td className="truncate px-3 py-2 align-middle text-muted-foreground">
|
||||
{formatProcessType(process)}
|
||||
</td>
|
||||
<td className="p-2 align-middle sm:pr-4">
|
||||
<td className="px-2 py-2 align-middle sm:pr-4">
|
||||
<ProcessSignalActions
|
||||
process={process}
|
||||
isSignaling={signalingPid === process.pid}
|
||||
@@ -519,238 +502,6 @@ function ProcessDiagnosticsTable({
|
||||
);
|
||||
}
|
||||
|
||||
const RESOURCE_HISTORY_WINDOWS = [
|
||||
{ label: "5m", windowMs: 5 * 60_000, bucketMs: 30_000 },
|
||||
{ label: "15m", windowMs: 15 * 60_000, bucketMs: 60_000 },
|
||||
{ label: "30m", windowMs: 30 * 60_000, bucketMs: 2 * 60_000 },
|
||||
{ label: "1h", windowMs: 60 * 60_000, bucketMs: 5 * 60_000 },
|
||||
] as const;
|
||||
|
||||
function formatCpuTime(seconds: number): string {
|
||||
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2)}s`;
|
||||
const minutes = seconds / 60;
|
||||
if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2)}m`;
|
||||
return `${(minutes / 60).toFixed(2)}h`;
|
||||
}
|
||||
|
||||
function formatShortProcessName(command: string): string {
|
||||
const name = formatProcessName(command);
|
||||
return name.length > 42 ? `${name.slice(0, 39)}...` : name;
|
||||
}
|
||||
|
||||
function ResourceHistoryProcessNameCell({
|
||||
process,
|
||||
visualDepth,
|
||||
}: {
|
||||
process: ServerProcessResourceHistorySummary;
|
||||
visualDepth: number;
|
||||
}) {
|
||||
const name = formatShortProcessName(process.command);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
|
||||
style={{ paddingLeft: `${Math.min(visualDepth, 6) * 10}px` }}
|
||||
aria-label={`${process.isServerRoot ? "Root" : "Child"} process ${name}`}
|
||||
>
|
||||
<span className="size-5 shrink-0" aria-hidden="true" />
|
||||
<span
|
||||
className={cn(
|
||||
"size-1.5 shrink-0 rounded-full",
|
||||
process.isServerRoot ? "bg-amber-500/90" : "bg-emerald-500/80",
|
||||
)}
|
||||
/>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
|
||||
/>
|
||||
<TooltipPopup
|
||||
side="top"
|
||||
className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
|
||||
>
|
||||
{process.command}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProcessResourceHistoryChart({
|
||||
buckets,
|
||||
}: {
|
||||
buckets: ReadonlyArray<{
|
||||
readonly startedAt: DateTime.Utc;
|
||||
readonly avgCpuPercent: number;
|
||||
readonly maxCpuPercent: number;
|
||||
}>;
|
||||
}) {
|
||||
const maxCpuPercent = Math.max(1, ...buckets.map((bucket) => bucket.maxCpuPercent));
|
||||
|
||||
return (
|
||||
<div className="border-t border-border/60 px-4 py-3 sm:px-5">
|
||||
<div className="flex h-28 items-end gap-1 overflow-hidden rounded-sm bg-muted/10 p-2">
|
||||
{buckets.map((bucket) => {
|
||||
const peakHeight = Math.max(2, (bucket.maxCpuPercent / maxCpuPercent) * 100);
|
||||
const averageHeight = Math.max(2, (bucket.avgCpuPercent / maxCpuPercent) * 100);
|
||||
return (
|
||||
<Tooltip key={DateTime.formatIso(bucket.startedAt)}>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<div className="flex h-full min-w-1 flex-1 items-end">
|
||||
<div
|
||||
className="relative h-full w-full"
|
||||
aria-label={`Average CPU ${bucket.avgCpuPercent.toFixed(1)}%, peak CPU ${bucket.maxCpuPercent.toFixed(1)}%`}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-x-0 bottom-0 rounded-t-sm bg-foreground/15 transition-colors"
|
||||
style={{ height: `${peakHeight}%` }}
|
||||
/>
|
||||
<div
|
||||
className="absolute inset-x-0 bottom-0 rounded-t-sm bg-foreground/60 transition-colors"
|
||||
style={{ height: `${averageHeight}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="top">
|
||||
Avg {bucket.avgCpuPercent.toFixed(1)}%, peak {bucket.maxCpuPercent.toFixed(1)}%
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ResourceHistoryWindowSelector({
|
||||
selectedWindowMs,
|
||||
onSelect,
|
||||
}: {
|
||||
selectedWindowMs: number;
|
||||
onSelect: (windowMs: number) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-center rounded-md border border-border/60 p-0.5">
|
||||
{RESOURCE_HISTORY_WINDOWS.map((option) => (
|
||||
<button
|
||||
key={option.windowMs}
|
||||
type="button"
|
||||
className={cn(
|
||||
"h-6 rounded-sm px-2 text-[11px] font-medium text-muted-foreground hover:text-foreground",
|
||||
selectedWindowMs === option.windowMs && "bg-muted text-foreground",
|
||||
)}
|
||||
onClick={() => onSelect(option.windowMs)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProcessResourceHistoryTable({
|
||||
processes,
|
||||
emptyLabel,
|
||||
}: {
|
||||
processes: ReadonlyArray<ServerProcessResourceHistorySummary>;
|
||||
emptyLabel: string;
|
||||
}) {
|
||||
const shallowestChildDepth = processes.reduce<number | null>((minDepth, process) => {
|
||||
if (process.isServerRoot) return minDepth;
|
||||
return minDepth === null ? process.depth : Math.min(minDepth, process.depth);
|
||||
}, null);
|
||||
|
||||
return (
|
||||
<ScrollArea
|
||||
chainVerticalScroll
|
||||
scrollFade
|
||||
hideScrollbars
|
||||
className="max-h-[min(64vh,44rem)] w-full max-w-full border-t border-border/60"
|
||||
>
|
||||
<table className="w-full min-w-[980px] table-fixed text-left text-xs">
|
||||
<colgroup>
|
||||
<col className="w-[24%]" />
|
||||
<col className="w-[10%]" />
|
||||
<col className="w-[10%]" />
|
||||
<col className="w-[10%]" />
|
||||
<col className="w-[10%]" />
|
||||
<col className="w-[10%]" />
|
||||
<col className="w-[16%]" />
|
||||
<col className="w-[10%]" />
|
||||
</colgroup>
|
||||
<thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
|
||||
<tr>
|
||||
<th className="px-4 py-2 font-semibold sm:pl-5">Process</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">CPU Time</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">Current</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">Average</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">Peak</th>
|
||||
<th className="px-3 py-2 text-right font-semibold">Max Mem</th>
|
||||
<th className="px-3 py-2 font-semibold">Command</th>
|
||||
<th className="px-3 py-2 text-right font-semibold sm:pr-5">PID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/50">
|
||||
{processes.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={8} className="px-4 py-4 text-xs text-muted-foreground sm:px-5">
|
||||
{emptyLabel}
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
{processes.map((process) => (
|
||||
<tr key={process.processKey} className="hover:bg-muted/20">
|
||||
<td className="px-4 py-2 align-middle sm:pl-5">
|
||||
<ResourceHistoryProcessNameCell
|
||||
process={process}
|
||||
visualDepth={
|
||||
process.isServerRoot || shallowestChildDepth === null
|
||||
? 0
|
||||
: Math.max(1, process.depth - shallowestChildDepth + 1)
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
|
||||
{formatCpuTime(process.cpuSecondsApprox)}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
|
||||
{process.currentCpuPercent.toFixed(1)}%
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
|
||||
{process.avgCpuPercent.toFixed(1)}%
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
|
||||
{process.maxCpuPercent.toFixed(1)}%
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
|
||||
{formatBytes(process.maxRssBytes)}
|
||||
</td>
|
||||
<td className="px-3 py-2 align-middle text-muted-foreground">
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="block truncate">{process.command}</span>}
|
||||
/>
|
||||
<TooltipPopup
|
||||
side="top"
|
||||
className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
|
||||
>
|
||||
{process.command}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right align-middle font-mono tabular-nums text-muted-foreground sm:pr-5">
|
||||
{process.pid}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
|
||||
function DiagnosticsLastChecked({ checkedAt }: { checkedAt: DateTime.Utc | null }) {
|
||||
useRelativeTimeTick();
|
||||
const relative = checkedAt ? formatRelativeTime(DateTime.formatIso(checkedAt)) : null;
|
||||
@@ -805,10 +556,6 @@ function DiagnosticsRefreshButton({
|
||||
export function DiagnosticsSettingsPanel() {
|
||||
const observability = useServerObservability();
|
||||
const availableEditors = useServerAvailableEditors();
|
||||
const [resourceWindowMs, setResourceWindowMs] = useState(15 * 60_000);
|
||||
const selectedResourceWindow =
|
||||
RESOURCE_HISTORY_WINDOWS.find((option) => option.windowMs === resourceWindowMs) ??
|
||||
RESOURCE_HISTORY_WINDOWS[1];
|
||||
const { data, error, isPending, refresh } = useTraceDiagnostics();
|
||||
const {
|
||||
data: processData,
|
||||
@@ -816,15 +563,6 @@ export function DiagnosticsSettingsPanel() {
|
||||
isPending: isProcessPending,
|
||||
refresh: refreshProcesses,
|
||||
} = useProcessDiagnostics();
|
||||
const {
|
||||
data: resourceData,
|
||||
error: resourceError,
|
||||
isPending: isResourcePending,
|
||||
refresh: refreshResources,
|
||||
} = useProcessResourceHistory({
|
||||
windowMs: selectedResourceWindow.windowMs,
|
||||
bucketMs: selectedResourceWindow.bucketMs,
|
||||
});
|
||||
const [isOpeningLogsDirectory, setIsOpeningLogsDirectory] = useState(false);
|
||||
const [openLogsDirectoryError, setOpenLogsDirectoryError] = useState<string | null>(null);
|
||||
const [signalingPid, setSignalingPid] = useState<number | null>(null);
|
||||
@@ -905,7 +643,6 @@ export function DiagnosticsSettingsPanel() {
|
||||
);
|
||||
|
||||
const processDiagnosticsError = processData ? Option.getOrNull(processData.error) : null;
|
||||
const processResourceError = resourceData ? Option.getOrNull(resourceData.error) : null;
|
||||
const traceDiagnosticsError = data ? Option.getOrNull(data.error) : null;
|
||||
const traceDiagnosticsPartialFailure = data
|
||||
? Option.getOrElse(data.partialFailure, () => false)
|
||||
@@ -974,70 +711,6 @@ export function DiagnosticsSettingsPanel() {
|
||||
/>
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
title="Resource History"
|
||||
headerAction={
|
||||
<div className="flex items-center gap-1.5">
|
||||
<ResourceHistoryWindowSelector
|
||||
selectedWindowMs={resourceWindowMs}
|
||||
onSelect={setResourceWindowMs}
|
||||
/>
|
||||
<DiagnosticsLastChecked checkedAt={resourceData?.readAt ?? null} />
|
||||
<DiagnosticsRefreshButton
|
||||
isPending={isResourcePending}
|
||||
label="Refresh resource history"
|
||||
onClick={refreshResources}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<StatsGrid>
|
||||
<StatBlock
|
||||
label="CPU Time"
|
||||
value={resourceData ? formatCpuTime(resourceData.totalCpuSecondsApprox) : "..."}
|
||||
tooltip="Approximate active CPU time for the T3 server root process and its descendants during the selected window. It grows only while sampled processes use CPU and older samples leave as the window moves."
|
||||
/>
|
||||
<StatBlock
|
||||
label="Samples"
|
||||
value={resourceData ? formatCount(resourceData.retainedSampleCount) : "..."}
|
||||
tooltip="In-memory process samples retained by the server. This resets when the server restarts."
|
||||
/>
|
||||
<StatBlock
|
||||
label="Interval"
|
||||
value={resourceData ? formatDuration(resourceData.sampleIntervalMs) : "..."}
|
||||
/>
|
||||
<StatBlock
|
||||
label="Processes"
|
||||
value={resourceData ? formatCount(resourceData.topProcesses.length) : "..."}
|
||||
/>
|
||||
</StatsGrid>
|
||||
{processResourceError || resourceError ? (
|
||||
<div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
|
||||
{processResourceError ? (
|
||||
<div className="flex items-start gap-2 text-destructive">
|
||||
<AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span>{processResourceError.message}</span>
|
||||
</div>
|
||||
) : null}
|
||||
{resourceError ? (
|
||||
<div className="flex items-start gap-2 text-destructive">
|
||||
<AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span>{resourceError}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
<ProcessResourceHistoryChart buckets={resourceData?.buckets ?? []} />
|
||||
<ProcessResourceHistoryTable
|
||||
processes={resourceData?.topProcesses ?? []}
|
||||
emptyLabel={
|
||||
isResourcePending && resourceData === null
|
||||
? "Collecting process resource samples..."
|
||||
: "No process resource samples found for this window."
|
||||
}
|
||||
/>
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
title="Trace Diagnostics"
|
||||
headerAction={
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
ProviderDriverKind,
|
||||
ProviderInstanceId,
|
||||
type ServerConfig,
|
||||
type ServerProcessResourceHistoryResult,
|
||||
type ServerProvider,
|
||||
type SourceControlDiscoveryResult,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -269,20 +268,6 @@ function makeUtc(value: string) {
|
||||
return DateTime.makeUnsafe(value);
|
||||
}
|
||||
|
||||
function createEmptyProcessResourceHistoryResult(): ServerProcessResourceHistoryResult {
|
||||
return {
|
||||
readAt: makeUtc("2036-04-07T00:00:00.000Z"),
|
||||
windowMs: 15 * 60_000,
|
||||
bucketMs: 60_000,
|
||||
sampleIntervalMs: 5_000,
|
||||
retainedSampleCount: 0,
|
||||
totalCpuSecondsApprox: 0,
|
||||
buckets: [],
|
||||
topProcesses: [],
|
||||
error: Option.none(),
|
||||
};
|
||||
}
|
||||
|
||||
function makePairingLink(input: {
|
||||
readonly id: string;
|
||||
readonly credential: string;
|
||||
@@ -1080,9 +1065,6 @@ describe("GeneralSettingsPanel observability", () => {
|
||||
processes: [],
|
||||
error: Option.none(),
|
||||
}),
|
||||
getProcessResourceHistory: vi
|
||||
.fn()
|
||||
.mockResolvedValue(createEmptyProcessResourceHistoryResult()),
|
||||
getTraceDiagnostics: vi.fn().mockResolvedValue({
|
||||
traceFilePath: "/repo/project/.t3/traces.jsonl",
|
||||
scannedFilePaths: ["/repo/project/.t3/traces.jsonl"],
|
||||
|
||||
@@ -21,7 +21,6 @@ import { createModelSelection } from "@t3tools/shared/model";
|
||||
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
|
||||
// in production; these aliases keep the legacy-key migration tests concise.
|
||||
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
|
||||
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
|
||||
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
|
||||
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
|
||||
const CODEX_DRIVER = ProviderDriverKind.make("codex");
|
||||
@@ -1202,43 +1201,6 @@ describe("composerDraftStore modelSelection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("stores provider option changes on a selected custom instance", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadRef,
|
||||
CODEX_DRIVER,
|
||||
toSelections({ reasoningEffort: "low" }),
|
||||
{
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
model: "gpt-5-codex",
|
||||
persistSticky: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(
|
||||
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
|
||||
@@ -371,7 +371,6 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2457,7 +2456,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2502,9 +2501,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2517,7 +2514,6 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
|
||||
modelSelectionByProvider: nextMap,
|
||||
};
|
||||
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };
|
||||
|
||||
@@ -176,7 +176,6 @@ describe("retainThreadDetailSubscription", () => {
|
||||
},
|
||||
})),
|
||||
},
|
||||
isHeartbeatFresh: vi.fn(() => true),
|
||||
orchestration: {
|
||||
subscribeThread: mockSubscribeThread,
|
||||
},
|
||||
@@ -383,7 +382,7 @@ describe("retainThreadDetailSubscription", () => {
|
||||
await resetEnvironmentServiceForTests();
|
||||
});
|
||||
|
||||
it("keeps healthy environment streams connected when the browser resumes from the background", async () => {
|
||||
it("reconnects environment streams when the browser resumes from the background", async () => {
|
||||
let visibilityState: DocumentVisibilityState = "visible";
|
||||
const documentTarget = new EventTarget();
|
||||
const windowTarget = new EventTarget();
|
||||
@@ -409,57 +408,6 @@ describe("retainThreadDetailSubscription", () => {
|
||||
documentTarget.dispatchEvent(new Event("visibilitychange"));
|
||||
expect(mockConnectionReconnects[0]).not.toHaveBeenCalled();
|
||||
|
||||
visibilityState = "visible";
|
||||
documentTarget.dispatchEvent(new Event("visibilitychange"));
|
||||
expect(mockConnectionReconnects[0]).not.toHaveBeenCalled();
|
||||
|
||||
stop();
|
||||
await resetEnvironmentServiceForTests();
|
||||
});
|
||||
|
||||
it("reconnects stale environment streams when the browser resumes from the background", async () => {
|
||||
let visibilityState: DocumentVisibilityState = "visible";
|
||||
const documentTarget = new EventTarget();
|
||||
const windowTarget = new EventTarget();
|
||||
vi.stubGlobal("document", {
|
||||
addEventListener: documentTarget.addEventListener.bind(documentTarget),
|
||||
removeEventListener: documentTarget.removeEventListener.bind(documentTarget),
|
||||
get visibilityState() {
|
||||
return visibilityState;
|
||||
},
|
||||
});
|
||||
vi.stubGlobal("window", {
|
||||
addEventListener: windowTarget.addEventListener.bind(windowTarget),
|
||||
removeEventListener: windowTarget.removeEventListener.bind(windowTarget),
|
||||
});
|
||||
mockCreateWsRpcClient.mockReturnValue({
|
||||
server: {
|
||||
getConfig: vi.fn(async () => ({
|
||||
environment: {
|
||||
environmentId: EnvironmentId.make("env-remote"),
|
||||
label: "Remote env",
|
||||
platform: { os: "darwin", arch: "arm64" },
|
||||
serverVersion: "0.0.0-test",
|
||||
capabilities: { repositoryIdentity: true },
|
||||
},
|
||||
})),
|
||||
},
|
||||
isHeartbeatFresh: vi.fn(() => false),
|
||||
orchestration: {
|
||||
subscribeThread: mockSubscribeThread,
|
||||
},
|
||||
});
|
||||
|
||||
const { resetEnvironmentServiceForTests, startEnvironmentConnectionService } =
|
||||
await import("./service");
|
||||
|
||||
const stop = startEnvironmentConnectionService(new QueryClient());
|
||||
expect(mockConnectionReconnects).toHaveLength(1);
|
||||
|
||||
visibilityState = "hidden";
|
||||
documentTarget.dispatchEvent(new Event("visibilitychange"));
|
||||
expect(mockConnectionReconnects[0]).not.toHaveBeenCalled();
|
||||
|
||||
visibilityState = "visible";
|
||||
documentTarget.dispatchEvent(new Event("visibilitychange"));
|
||||
expect(mockConnectionReconnects[0]).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -1482,12 +1482,9 @@ function reconnectEnvironmentConnectionsAfterBrowserResume(reason: string): void
|
||||
if (now - lastBrowserResumeReconnectAt < BROWSER_RESUME_RECONNECT_COOLDOWN_MS) {
|
||||
return;
|
||||
}
|
||||
lastBrowserResumeReconnectAt = now;
|
||||
|
||||
for (const connection of environmentConnections.values()) {
|
||||
if (connection.client.isHeartbeatFresh()) {
|
||||
continue;
|
||||
}
|
||||
lastBrowserResumeReconnectAt = now;
|
||||
void connection.reconnect().catch((error) => {
|
||||
console.warn("Environment reconnect after browser resume failed", {
|
||||
environmentId: connection.environmentId,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import type {
|
||||
ServerProcessDiagnosticsResult,
|
||||
ServerProcessResourceHistoryResult,
|
||||
} from "@t3tools/contracts";
|
||||
import type { ServerProcessDiagnosticsResult } from "@t3tools/contracts";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
@@ -14,8 +11,6 @@ import { appAtomRegistry } from "../rpc/atomRegistry";
|
||||
|
||||
const PROCESS_DIAGNOSTICS_STALE_TIME_MS = 2_000;
|
||||
const PROCESS_DIAGNOSTICS_IDLE_TTL_MS = 5 * 60_000;
|
||||
const PROCESS_RESOURCE_HISTORY_STALE_TIME_MS = 5_000;
|
||||
const PROCESS_RESOURCE_HISTORY_INPUT_SEPARATOR = ":";
|
||||
|
||||
const processDiagnosticsAtom = Atom.make(
|
||||
Effect.promise(() => ensureLocalApi().server.getProcessDiagnostics()),
|
||||
@@ -28,38 +23,6 @@ const processDiagnosticsAtom = Atom.make(
|
||||
Atom.withLabel("process-diagnostics"),
|
||||
);
|
||||
|
||||
function formatProcessResourceHistoryKey(input: {
|
||||
readonly windowMs: number;
|
||||
readonly bucketMs: number;
|
||||
}): string {
|
||||
return `${input.windowMs}${PROCESS_RESOURCE_HISTORY_INPUT_SEPARATOR}${input.bucketMs}`;
|
||||
}
|
||||
|
||||
function parseProcessResourceHistoryKey(key: string): {
|
||||
readonly windowMs: number;
|
||||
readonly bucketMs: number;
|
||||
} {
|
||||
const [windowMs = "0", bucketMs = "0"] = key.split(PROCESS_RESOURCE_HISTORY_INPUT_SEPARATOR);
|
||||
return {
|
||||
windowMs: Number(windowMs),
|
||||
bucketMs: Number(bucketMs),
|
||||
};
|
||||
}
|
||||
|
||||
const processResourceHistoryAtom = Atom.family((key: string) => {
|
||||
const input = parseProcessResourceHistoryKey(key);
|
||||
return Atom.make(
|
||||
Effect.promise(() => ensureLocalApi().server.getProcessResourceHistory(input)),
|
||||
).pipe(
|
||||
Atom.swr({
|
||||
staleTime: PROCESS_RESOURCE_HISTORY_STALE_TIME_MS,
|
||||
revalidateOnMount: true,
|
||||
}),
|
||||
Atom.setIdleTTL(PROCESS_DIAGNOSTICS_IDLE_TTL_MS),
|
||||
Atom.withLabel(`process-resource-history:${key}`),
|
||||
);
|
||||
});
|
||||
|
||||
export interface ProcessDiagnosticsState {
|
||||
readonly data: ServerProcessDiagnosticsResult | null;
|
||||
readonly error: string | null;
|
||||
@@ -67,13 +30,6 @@ export interface ProcessDiagnosticsState {
|
||||
readonly refresh: () => void;
|
||||
}
|
||||
|
||||
export interface ProcessResourceHistoryState {
|
||||
readonly data: ServerProcessResourceHistoryResult | null;
|
||||
readonly error: string | null;
|
||||
readonly isPending: boolean;
|
||||
readonly refresh: () => void;
|
||||
}
|
||||
|
||||
function formatProcessDiagnosticsError(error: unknown): string {
|
||||
return error instanceof Error ? error.message : "Failed to load process diagnostics.";
|
||||
}
|
||||
@@ -89,17 +45,6 @@ function readProcessDiagnosticsError(
|
||||
return formatProcessDiagnosticsError(squashed);
|
||||
}
|
||||
|
||||
function readProcessResourceHistoryError(
|
||||
result: AsyncResult.AsyncResult<ServerProcessResourceHistoryResult, unknown>,
|
||||
): string | null {
|
||||
if (result._tag !== "Failure") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const squashed = Cause.squash(result.cause);
|
||||
return formatProcessDiagnosticsError(squashed);
|
||||
}
|
||||
|
||||
export function refreshProcessDiagnostics(): void {
|
||||
appAtomRegistry.refresh(processDiagnosticsAtom);
|
||||
}
|
||||
@@ -118,23 +63,3 @@ export function useProcessDiagnostics(): ProcessDiagnosticsState {
|
||||
refresh,
|
||||
};
|
||||
}
|
||||
|
||||
export function useProcessResourceHistory(input: {
|
||||
readonly windowMs: number;
|
||||
readonly bucketMs: number;
|
||||
}): ProcessResourceHistoryState {
|
||||
const atom = processResourceHistoryAtom(formatProcessResourceHistoryKey(input));
|
||||
const result = useAtomValue(atom);
|
||||
const data = Option.getOrNull(AsyncResult.value(result));
|
||||
|
||||
const refresh = useCallback(() => {
|
||||
appAtomRegistry.refresh(atom);
|
||||
}, [atom]);
|
||||
|
||||
return {
|
||||
data,
|
||||
error: readProcessResourceHistoryError(result),
|
||||
isPending: result.waiting,
|
||||
refresh,
|
||||
};
|
||||
}
|
||||
@@ -155,10 +155,6 @@ function createBrowserLocalApi(rpcClient?: WsRpcClient): LocalApi {
|
||||
rpcClient
|
||||
? rpcClient.server.getProcessDiagnostics()
|
||||
: Promise.reject(unavailableLocalBackendError()),
|
||||
getProcessResourceHistory: (input) =>
|
||||
rpcClient
|
||||
? rpcClient.server.getProcessResourceHistory(input)
|
||||
: Promise.reject(unavailableLocalBackendError()),
|
||||
signalProcess: (input) =>
|
||||
rpcClient
|
||||
? rpcClient.server.signalProcess(input)
|
||||
|
||||
@@ -56,7 +56,6 @@ interface GitRunStackedActionOptions {
|
||||
export interface WsRpcClient {
|
||||
readonly dispose: () => Promise<void>;
|
||||
readonly reconnect: () => Promise<void>;
|
||||
readonly isHeartbeatFresh: () => boolean;
|
||||
readonly terminal: {
|
||||
readonly open: RpcUnaryMethod<typeof WS_METHODS.terminalOpen>;
|
||||
readonly write: RpcUnaryMethod<typeof WS_METHODS.terminalWrite>;
|
||||
@@ -135,9 +134,6 @@ export interface WsRpcClient {
|
||||
readonly getProcessDiagnostics: RpcUnaryNoArgMethod<
|
||||
typeof WS_METHODS.serverGetProcessDiagnostics
|
||||
>;
|
||||
readonly getProcessResourceHistory: RpcUnaryMethod<
|
||||
typeof WS_METHODS.serverGetProcessResourceHistory
|
||||
>;
|
||||
readonly signalProcess: RpcUnaryMethod<typeof WS_METHODS.serverSignalProcess>;
|
||||
readonly subscribeConfig: RpcStreamMethod<typeof WS_METHODS.subscribeServerConfig>;
|
||||
readonly subscribeLifecycle: RpcStreamMethod<typeof WS_METHODS.subscribeServerLifecycle>;
|
||||
@@ -162,7 +158,6 @@ export function createWsRpcClient(transport: WsTransport): WsRpcClient {
|
||||
resetWsReconnectBackoff();
|
||||
await transport.reconnect();
|
||||
},
|
||||
isHeartbeatFresh: () => transport.isHeartbeatFresh(),
|
||||
terminal: {
|
||||
open: (input) => transport.request((client) => client[WS_METHODS.terminalOpen](input)),
|
||||
write: (input) => transport.request((client) => client[WS_METHODS.terminalWrite](input)),
|
||||
@@ -269,12 +264,6 @@ export function createWsRpcClient(transport: WsTransport): WsRpcClient {
|
||||
transport.request((client) =>
|
||||
client[WS_METHODS.serverGetProcessDiagnostics]({}).pipe(Effect.withTracerEnabled(false)),
|
||||
),
|
||||
getProcessResourceHistory: (input) =>
|
||||
transport.request((client) =>
|
||||
client[WS_METHODS.serverGetProcessResourceHistory](input).pipe(
|
||||
Effect.withTracerEnabled(false),
|
||||
),
|
||||
),
|
||||
signalProcess: (input) =>
|
||||
transport.request((client) =>
|
||||
client[WS_METHODS.serverSignalProcess](input).pipe(Effect.withTracerEnabled(false)),
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
"version": "0.0.23",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/ssh": "workspace:*",
|
||||
"@t3tools/tailscale": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
"electron": "41.5.0",
|
||||
"electron-updater": "^6.6.2",
|
||||
@@ -31,7 +27,13 @@
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"@t3tools/client-runtime": "workspace:*",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/ssh": "workspace:*",
|
||||
"@t3tools/tailscale": "workspace:*",
|
||||
"@types/node": "catalog:",
|
||||
"effect-acp": "workspace:*",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
@@ -58,7 +60,6 @@
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.2.111",
|
||||
"@effect/platform-bun": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/platform-node-shared": "catalog:",
|
||||
"@effect/sql-sqlite-bun": "catalog:",
|
||||
"@opencode-ai/sdk": "^1.3.15",
|
||||
"@pierre/diffs": "catalog:",
|
||||
@@ -152,9 +153,9 @@
|
||||
},
|
||||
"packages/client-runtime": {
|
||||
"name": "@t3tools/client-runtime",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -172,6 +173,7 @@
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
},
|
||||
@@ -186,6 +188,7 @@
|
||||
"@effect/openapi-generator": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
},
|
||||
@@ -200,12 +203,14 @@
|
||||
"@effect/openapi-generator": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
},
|
||||
},
|
||||
"packages/shared": {
|
||||
"name": "@t3tools/shared",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
@@ -221,6 +226,7 @@
|
||||
},
|
||||
"packages/ssh": {
|
||||
"name": "@t3tools/ssh",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
@@ -237,6 +243,7 @@
|
||||
},
|
||||
"packages/tailscale": {
|
||||
"name": "@t3tools/tailscale",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"effect": "catalog:",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/client-runtime",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
@@ -14,7 +15,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"effect": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1 +1,78 @@
|
||||
export * from "@t3tools/shared/advertisedEndpoint";
|
||||
import type {
|
||||
AdvertisedEndpoint,
|
||||
AdvertisedEndpointHostedHttpsCompatibility,
|
||||
AdvertisedEndpointProvider,
|
||||
AdvertisedEndpointReachability,
|
||||
AdvertisedEndpointSource,
|
||||
AdvertisedEndpointStatus,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export interface CreateAdvertisedEndpointInput {
|
||||
readonly id: string;
|
||||
readonly label: string;
|
||||
readonly provider: AdvertisedEndpointProvider;
|
||||
readonly httpBaseUrl: string;
|
||||
readonly reachability: AdvertisedEndpointReachability;
|
||||
readonly hostedHttpsCompatibility?: AdvertisedEndpointHostedHttpsCompatibility;
|
||||
readonly desktopCompatibility?: "compatible" | "unknown";
|
||||
readonly source: AdvertisedEndpointSource;
|
||||
readonly status?: AdvertisedEndpointStatus;
|
||||
readonly isDefault?: boolean;
|
||||
readonly description?: string;
|
||||
}
|
||||
|
||||
export function normalizeHttpBaseUrl(rawValue: string): string {
|
||||
const url = new URL(rawValue);
|
||||
if (url.protocol === "ws:") {
|
||||
url.protocol = "http:";
|
||||
} else if (url.protocol === "wss:") {
|
||||
url.protocol = "https:";
|
||||
}
|
||||
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
||||
throw new Error(`Endpoint must use HTTP or HTTPS. Received ${url.protocol}`);
|
||||
}
|
||||
|
||||
url.pathname = "/";
|
||||
url.search = "";
|
||||
url.hash = "";
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
export function deriveWsBaseUrl(httpBaseUrl: string): string {
|
||||
const url = new URL(normalizeHttpBaseUrl(httpBaseUrl));
|
||||
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
export function classifyHostedHttpsCompatibility(
|
||||
httpBaseUrl: string,
|
||||
fallback: AdvertisedEndpointHostedHttpsCompatibility = "unknown",
|
||||
): AdvertisedEndpointHostedHttpsCompatibility {
|
||||
const url = new URL(normalizeHttpBaseUrl(httpBaseUrl));
|
||||
if (url.protocol === "http:") {
|
||||
return "mixed-content-blocked";
|
||||
}
|
||||
return fallback === "mixed-content-blocked" ? "unknown" : fallback;
|
||||
}
|
||||
|
||||
export function createAdvertisedEndpoint(input: CreateAdvertisedEndpointInput): AdvertisedEndpoint {
|
||||
const httpBaseUrl = normalizeHttpBaseUrl(input.httpBaseUrl);
|
||||
return {
|
||||
id: input.id,
|
||||
label: input.label,
|
||||
provider: input.provider,
|
||||
httpBaseUrl,
|
||||
wsBaseUrl: deriveWsBaseUrl(httpBaseUrl),
|
||||
reachability: input.reachability,
|
||||
compatibility: {
|
||||
hostedHttpsApp:
|
||||
input.hostedHttpsCompatibility ?? classifyHostedHttpsCompatibility(httpBaseUrl),
|
||||
desktopApp: input.desktopCompatibility ?? "compatible",
|
||||
},
|
||||
source: input.source,
|
||||
status: input.status ?? "available",
|
||||
...(input.isDefault === undefined ? {} : { isDefault: input.isDefault }),
|
||||
...(input.description === undefined ? {} : { description: input.description }),
|
||||
};
|
||||
}
|
||||
@@ -1,22 +1,29 @@
|
||||
{
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.24",
|
||||
"version": "0.0.23",
|
||||
"private": true,
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./src/index.ts"
|
||||
},
|
||||
"./settings": {
|
||||
"types": "./src/settings.ts",
|
||||
"import": "./src/settings.ts"
|
||||
"import": "./src/settings.ts",
|
||||
"require": "./src/settings.ts"
|
||||
},
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./src/index.ts",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsdown src/index.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/index.ts --format esm,cjs --dts --clean",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
@@ -26,6 +33,7 @@
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ import type { ProviderInstanceId } from "./providerInstance.ts";
|
||||
import type {
|
||||
ServerConfig,
|
||||
ServerProcessDiagnosticsResult,
|
||||
ServerProcessResourceHistoryInput,
|
||||
ServerProcessResourceHistoryResult,
|
||||
ServerProviderUpdateInput,
|
||||
ServerProviderUpdatedPayload,
|
||||
ServerRemoveKeybindingResult,
|
||||
@@ -477,9 +475,6 @@ export interface LocalApi {
|
||||
discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
|
||||
getTraceDiagnostics: () => Promise<ServerTraceDiagnosticsResult>;
|
||||
getProcessDiagnostics: () => Promise<ServerProcessDiagnosticsResult>;
|
||||
getProcessResourceHistory: (
|
||||
input: ServerProcessResourceHistoryInput,
|
||||
) => Promise<ServerProcessResourceHistoryResult>;
|
||||
signalProcess: (input: ServerSignalProcessInput) => Promise<ServerSignalProcessResult>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,8 +79,6 @@ import {
|
||||
ServerProviderUpdatedPayload,
|
||||
ServerTraceDiagnosticsResult,
|
||||
ServerProcessDiagnosticsResult,
|
||||
ServerProcessResourceHistoryInput,
|
||||
ServerProcessResourceHistoryResult,
|
||||
ServerSignalProcessInput,
|
||||
ServerSignalProcessResult,
|
||||
ServerUpsertKeybindingInput,
|
||||
@@ -147,7 +145,6 @@ export const WS_METHODS = {
|
||||
serverDiscoverSourceControl: "server.discoverSourceControl",
|
||||
serverGetTraceDiagnostics: "server.getTraceDiagnostics",
|
||||
serverGetProcessDiagnostics: "server.getProcessDiagnostics",
|
||||
serverGetProcessResourceHistory: "server.getProcessResourceHistory",
|
||||
serverSignalProcess: "server.signalProcess",
|
||||
|
||||
// Source control methods
|
||||
@@ -227,14 +224,6 @@ export const WsServerGetProcessDiagnosticsRpc = Rpc.make(WS_METHODS.serverGetPro
|
||||
success: ServerProcessDiagnosticsResult,
|
||||
});
|
||||
|
||||
export const WsServerGetProcessResourceHistoryRpc = Rpc.make(
|
||||
WS_METHODS.serverGetProcessResourceHistory,
|
||||
{
|
||||
payload: ServerProcessResourceHistoryInput,
|
||||
success: ServerProcessResourceHistoryResult,
|
||||
},
|
||||
);
|
||||
|
||||
export const WsServerSignalProcessRpc = Rpc.make(WS_METHODS.serverSignalProcess, {
|
||||
payload: ServerSignalProcessInput,
|
||||
success: ServerSignalProcessResult,
|
||||
@@ -483,7 +472,6 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsServerDiscoverSourceControlRpc,
|
||||
WsServerGetTraceDiagnosticsRpc,
|
||||
WsServerGetProcessDiagnosticsRpc,
|
||||
WsServerGetProcessResourceHistoryRpc,
|
||||
WsServerSignalProcessRpc,
|
||||
WsSourceControlLookupRepositoryRpc,
|
||||
WsSourceControlCloneRepositoryRpc,
|
||||
|
||||
@@ -328,58 +328,6 @@ export const ServerProcessDiagnosticsResult = Schema.Struct({
|
||||
});
|
||||
export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
|
||||
|
||||
export const ServerProcessResourceHistoryInput = Schema.Struct({
|
||||
windowMs: NonNegativeInt,
|
||||
bucketMs: NonNegativeInt,
|
||||
});
|
||||
export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
|
||||
|
||||
export const ServerProcessResourceHistoryBucket = Schema.Struct({
|
||||
startedAt: Schema.DateTimeUtc,
|
||||
endedAt: Schema.DateTimeUtc,
|
||||
avgCpuPercent: Schema.Number,
|
||||
maxCpuPercent: Schema.Number,
|
||||
maxRssBytes: NonNegativeInt,
|
||||
maxProcessCount: NonNegativeInt,
|
||||
});
|
||||
export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
|
||||
|
||||
export const ServerProcessResourceHistorySummary = Schema.Struct({
|
||||
processKey: TrimmedNonEmptyString,
|
||||
pid: PositiveInt,
|
||||
ppid: NonNegativeInt,
|
||||
command: TrimmedNonEmptyString,
|
||||
depth: NonNegativeInt,
|
||||
isServerRoot: Schema.Boolean,
|
||||
firstSeenAt: Schema.DateTimeUtc,
|
||||
lastSeenAt: Schema.DateTimeUtc,
|
||||
currentCpuPercent: Schema.Number,
|
||||
avgCpuPercent: Schema.Number,
|
||||
maxCpuPercent: Schema.Number,
|
||||
cpuSecondsApprox: Schema.Number,
|
||||
currentRssBytes: NonNegativeInt,
|
||||
maxRssBytes: NonNegativeInt,
|
||||
sampleCount: NonNegativeInt,
|
||||
});
|
||||
export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
|
||||
|
||||
export const ServerProcessResourceHistoryResult = Schema.Struct({
|
||||
readAt: Schema.DateTimeUtc,
|
||||
windowMs: NonNegativeInt,
|
||||
bucketMs: NonNegativeInt,
|
||||
sampleIntervalMs: NonNegativeInt,
|
||||
retainedSampleCount: NonNegativeInt,
|
||||
totalCpuSecondsApprox: Schema.Number,
|
||||
buckets: Schema.Array(ServerProcessResourceHistoryBucket),
|
||||
topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
|
||||
error: Schema.Option(
|
||||
Schema.Struct({
|
||||
message: TrimmedNonEmptyString,
|
||||
}),
|
||||
),
|
||||
});
|
||||
export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
|
||||
|
||||
export const ServerSignalProcessInput = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
signal: ServerProcessSignal,
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsdown src/client.ts src/agent.ts src/_generated/schema.gen.ts src/rpc.ts src/protocol.ts src/terminal.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/client.ts src/agent.ts src/_generated/schema.gen.ts src/rpc.ts src/protocol.ts src/terminal.ts --format esm,cjs --dts --clean",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"generate": "bun run scripts/generate.ts"
|
||||
@@ -45,6 +47,7 @@
|
||||
"@effect/openapi-generator": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsdown src/client.ts src/rpc.ts src/protocol.ts src/schema.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/client.ts src/rpc.ts src/protocol.ts src/schema.ts --format esm,cjs --dts --clean",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"generate": "bun run scripts/generate.ts",
|
||||
@@ -38,6 +40,7 @@
|
||||
"@effect/openapi-generator": "catalog:",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/vitest": "catalog:",
|
||||
"tsdown": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/shared",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
@@ -7,10 +8,6 @@
|
||||
"types": "./src/model.ts",
|
||||
"import": "./src/model.ts"
|
||||
},
|
||||
"./advertisedEndpoint": {
|
||||
"types": "./src/advertisedEndpoint.ts",
|
||||
"import": "./src/advertisedEndpoint.ts"
|
||||
},
|
||||
"./git": {
|
||||
"types": "./src/git.ts",
|
||||
"import": "./src/git.ts"
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import type {
|
||||
AdvertisedEndpoint,
|
||||
AdvertisedEndpointHostedHttpsCompatibility,
|
||||
AdvertisedEndpointProvider,
|
||||
AdvertisedEndpointReachability,
|
||||
AdvertisedEndpointSource,
|
||||
AdvertisedEndpointStatus,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export interface CreateAdvertisedEndpointInput {
|
||||
readonly id: string;
|
||||
readonly label: string;
|
||||
readonly provider: AdvertisedEndpointProvider;
|
||||
readonly httpBaseUrl: string;
|
||||
readonly reachability: AdvertisedEndpointReachability;
|
||||
readonly hostedHttpsCompatibility?: AdvertisedEndpointHostedHttpsCompatibility;
|
||||
readonly desktopCompatibility?: "compatible" | "unknown";
|
||||
readonly source: AdvertisedEndpointSource;
|
||||
readonly status?: AdvertisedEndpointStatus;
|
||||
readonly isDefault?: boolean;
|
||||
readonly description?: string;
|
||||
}
|
||||
|
||||
export function normalizeHttpBaseUrl(rawValue: string): string {
|
||||
const url = new URL(rawValue);
|
||||
if (url.protocol === "ws:") {
|
||||
url.protocol = "http:";
|
||||
} else if (url.protocol === "wss:") {
|
||||
url.protocol = "https:";
|
||||
}
|
||||
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
||||
throw new Error(`Endpoint must use HTTP or HTTPS. Received ${url.protocol}`);
|
||||
}
|
||||
|
||||
url.pathname = "/";
|
||||
url.search = "";
|
||||
url.hash = "";
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
export function deriveWsBaseUrl(httpBaseUrl: string): string {
|
||||
const url = new URL(normalizeHttpBaseUrl(httpBaseUrl));
|
||||
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
export function classifyHostedHttpsCompatibility(
|
||||
httpBaseUrl: string,
|
||||
fallback: AdvertisedEndpointHostedHttpsCompatibility = "unknown",
|
||||
): AdvertisedEndpointHostedHttpsCompatibility {
|
||||
const url = new URL(normalizeHttpBaseUrl(httpBaseUrl));
|
||||
if (url.protocol === "http:") {
|
||||
return "mixed-content-blocked";
|
||||
}
|
||||
return fallback === "mixed-content-blocked" ? "unknown" : fallback;
|
||||
}
|
||||
|
||||
export function createAdvertisedEndpoint(input: CreateAdvertisedEndpointInput): AdvertisedEndpoint {
|
||||
const httpBaseUrl = normalizeHttpBaseUrl(input.httpBaseUrl);
|
||||
return {
|
||||
id: input.id,
|
||||
label: input.label,
|
||||
provider: input.provider,
|
||||
httpBaseUrl,
|
||||
wsBaseUrl: deriveWsBaseUrl(httpBaseUrl),
|
||||
reachability: input.reachability,
|
||||
compatibility: {
|
||||
hostedHttpsApp:
|
||||
input.hostedHttpsCompatibility ?? classifyHostedHttpsCompatibility(httpBaseUrl),
|
||||
desktopApp: input.desktopCompatibility ?? "compatible",
|
||||
},
|
||||
source: input.source,
|
||||
status: input.status ?? "available",
|
||||
...(input.isDefault === undefined ? {} : { isDefault: input.isDefault }),
|
||||
...(input.description === undefined ? {} : { description: input.description }),
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/ssh",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/tailscale",
|
||||
"version": "0.0.0-alpha.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Result from "effect/Result";
|
||||
import * as Sink from "effect/Sink";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import {
|
||||
@@ -36,21 +39,47 @@ function mockHandle(result: { stdout?: string; stderr?: string; code?: number })
|
||||
});
|
||||
}
|
||||
|
||||
function mockNeverFinishingHandle() {
|
||||
let finish: ((exitCode: ChildProcessSpawner.ExitCode) => void) | null = null;
|
||||
return ChildProcessSpawner.makeHandle({
|
||||
pid: ChildProcessSpawner.ProcessId(1),
|
||||
exitCode: Effect.callback<ChildProcessSpawner.ExitCode>((resume) => {
|
||||
finish = (exitCode) => resume(Effect.succeed(exitCode));
|
||||
return Effect.sync(() => {
|
||||
finish = null;
|
||||
});
|
||||
}),
|
||||
isRunning: Effect.succeed(true),
|
||||
kill: () =>
|
||||
Effect.sync(() => {
|
||||
finish?.(ChildProcessSpawner.ExitCode(143));
|
||||
}),
|
||||
unref: Effect.succeed(Effect.void),
|
||||
stdin: Sink.drain,
|
||||
stdout: Stream.empty,
|
||||
stderr: Stream.empty,
|
||||
all: Stream.empty,
|
||||
getInputFd: () => Sink.drain,
|
||||
getOutputFd: () => Stream.empty,
|
||||
});
|
||||
}
|
||||
|
||||
function mockSpawnerLayer(
|
||||
handler: (
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
) => { stdout?: string; stderr?: string; code?: number },
|
||||
) {
|
||||
return Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
|
||||
spawn: (command) => {
|
||||
return Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make((command) => {
|
||||
const childProcess = command as unknown as {
|
||||
readonly command: string;
|
||||
readonly args: ReadonlyArray<string>;
|
||||
};
|
||||
return Effect.succeed(mockHandle(handler(childProcess.command, childProcess.args)));
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
describe("tailscale", () => {
|
||||
@@ -66,8 +95,8 @@ describe("tailscale", () => {
|
||||
it.effect("parses MagicDNS names from tailscale status", () =>
|
||||
Effect.gen(function* () {
|
||||
const dnsName = yield* parseTailscaleMagicDnsName(tailscaleStatusJson);
|
||||
assert.deepEqual(dnsName, Option.some("desktop.tail.ts.net"));
|
||||
assert.deepEqual(yield* parseTailscaleMagicDnsName("{}"), Option.none());
|
||||
assert.equal(dnsName, "desktop.tail.ts.net");
|
||||
assert.equal(yield* parseTailscaleMagicDnsName("{}"), null);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -75,7 +104,7 @@ describe("tailscale", () => {
|
||||
Effect.gen(function* () {
|
||||
const status = yield* parseTailscaleStatus(tailscaleStatusJson);
|
||||
assert.deepEqual(status, {
|
||||
magicDnsName: Option.some("desktop.tail.ts.net"),
|
||||
magicDnsName: "desktop.tail.ts.net",
|
||||
tailnetIpv4Addresses: ["100.100.100.100"],
|
||||
});
|
||||
}),
|
||||
@@ -106,12 +135,33 @@ describe("tailscale", () => {
|
||||
return Effect.gen(function* () {
|
||||
const status = yield* readTailscaleStatus.pipe(Effect.provide(layer));
|
||||
assert.deepEqual(status, {
|
||||
magicDnsName: Option.some("desktop.tail.ts.net"),
|
||||
magicDnsName: "desktop.tail.ts.net",
|
||||
tailnetIpv4Addresses: ["100.90.1.2"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("times out status reads using the test clock", () => {
|
||||
const spawnerLayer = Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() => Effect.succeed(mockNeverFinishingHandle())),
|
||||
);
|
||||
const layer = Layer.mergeAll(spawnerLayer, TestClock.layer());
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const fiber = yield* Effect.forkChild(Effect.result(readTailscaleStatus));
|
||||
yield* Effect.yieldNow;
|
||||
yield* TestClock.adjust(Duration.seconds(2));
|
||||
|
||||
const result = yield* Fiber.join(fiber);
|
||||
assert.isTrue(Result.isFailure(result));
|
||||
if (Result.isFailure(result)) {
|
||||
assert.equal(result.failure._tag, "TailscaleCommandError");
|
||||
assert.equal(result.failure.message, "Tailscale status timed out.");
|
||||
}
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("configures tailscale serve through the process spawner service", () => {
|
||||
const layer = mockSpawnerLayer((command, args) => {
|
||||
assert.equal(command, "tailscale");
|
||||
|
||||
@@ -16,7 +16,7 @@ export class TailscaleCommandError extends Schema.TaggedErrorClass<TailscaleComm
|
||||
{
|
||||
command: Schema.Array(Schema.String),
|
||||
message: Schema.String,
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
exitCode: Schema.NullOr(Schema.Int),
|
||||
stderr: Schema.String,
|
||||
},
|
||||
) {}
|
||||
@@ -48,7 +48,7 @@ export type TailscaleStatusSelf = typeof TailscaleStatusSelf.Type;
|
||||
export type TailscaleStatusJson = typeof TailscaleStatusJson.Type;
|
||||
|
||||
export interface TailscaleStatus {
|
||||
readonly magicDnsName: Option.Option<string>;
|
||||
readonly magicDnsName: string | null;
|
||||
readonly tailnetIpv4Addresses: readonly string[];
|
||||
}
|
||||
|
||||
@@ -78,19 +78,19 @@ const tailscaleCommandError = (
|
||||
|
||||
const decodeTailscaleStatusJson = Schema.decodeEffect(Schema.fromJsonString(TailscaleStatusJson));
|
||||
|
||||
function normalizeMagicDnsName(status: TailscaleStatusJson): Option.Option<string> {
|
||||
function normalizeMagicDnsName(status: TailscaleStatusJson): string | null {
|
||||
const dnsName = status.Self?.DNSName;
|
||||
if (typeof dnsName !== "string") {
|
||||
return Option.none();
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized = dnsName.trim().replace(/\.$/u, "");
|
||||
return normalized.length > 0 ? Option.some(normalized) : Option.none();
|
||||
return normalized.length > 0 ? normalized : null;
|
||||
}
|
||||
|
||||
export const parseTailscaleMagicDnsName = (
|
||||
rawStatusJson: string,
|
||||
): Effect.Effect<Option.Option<string>, TailscaleStatusParseError> =>
|
||||
): Effect.Effect<string | null, TailscaleStatusParseError> =>
|
||||
decodeTailscaleStatusJson(rawStatusJson).pipe(
|
||||
Effect.mapError((cause) => new TailscaleStatusParseError({ cause })),
|
||||
Effect.map(normalizeMagicDnsName),
|
||||
@@ -317,17 +317,17 @@ export const resolveTailscaleHttpsBaseUrl = (
|
||||
readonly servePort?: number;
|
||||
} = {},
|
||||
): Effect.Effect<
|
||||
Option.Option<string>,
|
||||
string | null,
|
||||
TailscaleCommandError | TailscaleStatusParseError,
|
||||
ChildProcessSpawner.ChildProcessSpawner
|
||||
> =>
|
||||
readTailscaleStatus.pipe(
|
||||
Effect.map((status) =>
|
||||
Option.map(status.magicDnsName, (magicDnsName) =>
|
||||
buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
}),
|
||||
),
|
||||
status.magicDnsName
|
||||
? buildTailscaleHttpsBaseUrl({
|
||||
magicDnsName: status.magicDnsName,
|
||||
...(input.servePort === undefined ? {} : { servePort: input.servePort }),
|
||||
})
|
||||
: null,
|
||||
),
|
||||
);
|
||||
@@ -5,7 +5,6 @@ import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import {
|
||||
resolveDesktopRuntimeDependencies,
|
||||
resolveBuildOptions,
|
||||
resolveDesktopBuildIconAssets,
|
||||
resolveDesktopProductName,
|
||||
@@ -40,30 +39,6 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
});
|
||||
});
|
||||
|
||||
it("omits bundled workspace packages from staged desktop dependencies", () => {
|
||||
assert.deepStrictEqual(
|
||||
resolveDesktopRuntimeDependencies(
|
||||
{
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@t3tools/ssh": "workspace:*",
|
||||
"@t3tools/tailscale": "workspace:*",
|
||||
effect: "catalog:",
|
||||
electron: "41.5.0",
|
||||
},
|
||||
{
|
||||
"@effect/platform-node": "4.0.0-beta.59",
|
||||
effect: "4.0.0-beta.59",
|
||||
},
|
||||
),
|
||||
{
|
||||
"@effect/platform-node": "4.0.0-beta.59",
|
||||
effect: "4.0.0-beta.59",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to the default mock update port when the configured port is blank", () => {
|
||||
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
|
||||
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
|
||||
|
||||
@@ -484,7 +484,7 @@ function validateBundledClientAssets(clientDir: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveDesktopRuntimeDependencies(
|
||||
function resolveDesktopRuntimeDependencies(
|
||||
dependencies: Record<string, string> | undefined,
|
||||
catalog: Record<string, string>,
|
||||
): Record<string, string> {
|
||||
@@ -493,10 +493,7 @@ export function resolveDesktopRuntimeDependencies(
|
||||
}
|
||||
|
||||
const runtimeDependencies = Object.fromEntries(
|
||||
Object.entries(dependencies).filter(
|
||||
([dependencyName, dependencySpec]) =>
|
||||
dependencyName !== "electron" && !dependencySpec.startsWith("workspace:"),
|
||||
),
|
||||
Object.entries(dependencies).filter(([dependencyName]) => dependencyName !== "electron"),
|
||||
);
|
||||
|
||||
return resolveCatalogDependencies(runtimeDependencies, catalog, "apps/desktop");
|
||||
|
||||