From 65f1c7037731eb93b080438126209730d8809bc1 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 27 Jul 2026 07:00:13 -0700 Subject: [PATCH] feat(release): publish fork-owned CLI package (#3) --- .github/workflows/release.yml | 54 ++++++++++++++++++++- apps/server/package.json | 3 +- apps/server/scripts/cli.test.ts | 26 ++++++++++ apps/server/scripts/cli.ts | 29 ++++++----- apps/server/src/cloud/bootService.test.ts | 45 +++++++++++------ apps/server/src/cloud/bootService.ts | 4 +- apps/server/src/cloud/pinnedRuntime.test.ts | 12 +++++ apps/server/src/cloud/pinnedRuntime.ts | 21 +++++--- apps/server/src/cloud/selfUpdate.test.ts | 54 +++++++++++++++------ apps/server/src/cloud/selfUpdate.ts | 33 ++++++++++--- apps/server/src/packageIdentity.test.ts | 16 ++++++ apps/server/src/packageIdentity.ts | 3 ++ docs/operations/release.md | 22 ++++++--- scripts/release-workflow.test.ts | 9 ++++ 14 files changed, 263 insertions(+), 68 deletions(-) create mode 100644 apps/server/scripts/cli.test.ts create mode 100644 apps/server/src/packageIdentity.test.ts create mode 100644 apps/server/src/packageIdentity.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d5072f8c194bc..6bed0e68d4836 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -225,10 +225,60 @@ jobs: path: release-publish/* if-no-files-found: error + publish_fork_cli: + name: Publish fork CLI to npm + needs: preflight + if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }} + runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: read + id-token: write + env: + VERSION: ${{ needs.preflight.outputs.version }} + IS_PRERELEASE: ${{ needs.preflight.outputs.is_prerelease }} + steps: + - name: Checkout immutable release commit + uses: actions/checkout@v6 + with: + ref: ${{ needs.preflight.outputs.commit_sha }} + fetch-depth: 0 + + - name: Setup Vite+ + uses: voidzero-dev/setup-vp@v1 + with: + node-version-file: package.json + cache: true + run-install: true + + - name: Align package metadata to the release version + run: node scripts/update-release-package-versions.ts "$VERSION" + + - name: Build web package for the CLI bundle + run: vp run --filter @t3tools/web build + + - name: Build fork CLI package + run: node apps/server/scripts/cli.ts build + + - name: Publish and verify the exact fork CLI version + shell: bash + run: | + set -euo pipefail + dist_tag=latest + if [[ "$IS_PRERELEASE" == "true" ]]; then + dist_tag=next + fi + node apps/server/scripts/cli.ts publish --tag "$dist_tag" --app-version "$VERSION" --provenance --verbose + published_version="$(npm view "@ag-jin/t3code@${VERSION}" version)" + if [[ "$published_version" != "$VERSION" ]]; then + echo "Published fork CLI version did not match the release tag." >&2 + exit 1 + fi + release: name: Publish fork GitHub Release - needs: [preflight, build] - if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' }} + needs: [preflight, build, publish_fork_cli] + if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' && needs.publish_fork_cli.result == 'success' }} runs-on: ubuntu-24.04 timeout-minutes: 15 permissions: diff --git a/apps/server/package.json b/apps/server/package.json index 6be498e803d0a..46f37a08aa76c 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -1,10 +1,11 @@ { "name": "t3", "version": "0.0.28", + "private": true, "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/pingdotgg/t3code", + "url": "https://github.com/ag-jin/t3code-2K", "directory": "apps/server" }, "bin": { diff --git a/apps/server/scripts/cli.test.ts b/apps/server/scripts/cli.test.ts new file mode 100644 index 0000000000000..df1c2de07e539 --- /dev/null +++ b/apps/server/scripts/cli.test.ts @@ -0,0 +1,26 @@ +import { assert, it } from "@effect/vitest"; + +import { createVpPmPublishArgs } from "./cli.ts"; + +it("publishes the fork package rather than the private workspace package", () => { + assert.deepEqual( + createVpPmPublishArgs({ + access: "public", + tag: "next", + provenance: true, + dryRun: true, + }), + [ + "publish", + "--filter", + "@ag-jin/t3code", + "--access", + "public", + "--tag", + "next", + "--no-git-checks", + "--provenance", + "--dry-run", + ], + ); +}); diff --git a/apps/server/scripts/cli.ts b/apps/server/scripts/cli.ts index 517f633577c1c..365f400d80970 100644 --- a/apps/server/scripts/cli.ts +++ b/apps/server/scripts/cli.ts @@ -20,6 +20,11 @@ import { fromJsonStringPretty } from "@t3tools/shared/schemaJson"; import { fromYaml } from "@t3tools/shared/schemaYaml"; import { resolveSpawnCommand } from "@t3tools/shared/shell"; import serverPackageJson from "../package.json" with { type: "json" }; +import { + forkServerCliBinary, + forkServerPackageName, + forkServerRepositoryUrl, +} from "../src/packageIdentity.ts"; import { ServerCliBuildAssetMissingError, ServerCliCommandExitError, @@ -186,11 +191,11 @@ interface PublishCommandConfig { readonly dryRun: boolean; } -const createVpPmPublishArgs = (config: PublishCommandConfig): ReadonlyArray => { +export const createVpPmPublishArgs = (config: PublishCommandConfig): ReadonlyArray => { const args = [ "publish", "--filter", - "t3", + forkServerPackageName, "--access", config.access, "--tag", @@ -238,9 +243,9 @@ const publishCmd = Command.make( const workspaceCatalog = workspaceConfig.catalog ?? {}; const workspaceOverrides = workspaceConfig.overrides ?? {}; const pkg: PackageJson = { - name: serverPackageJson.name, - repository: serverPackageJson.repository, - bin: serverPackageJson.bin, + name: forkServerPackageName, + repository: { ...serverPackageJson.repository, url: forkServerRepositoryUrl }, + bin: { [forkServerCliBinary]: "./dist/bin.mjs" }, type: serverPackageJson.type, version, engines: serverPackageJson.engines, @@ -303,13 +308,15 @@ const publishCmd = Command.make( // root command // --------------------------------------------------------------------------- -const cli = Command.make("cli").pipe( +export const cli = Command.make("cli").pipe( Command.withDescription("T3 server build & publish CLI."), Command.withSubcommands([buildCmd, publishCmd]), ); -Command.run(cli, { version: "0.0.0" }).pipe( - Effect.scoped, - Effect.provide([Logger.layer([Logger.consolePretty()]), NodeServices.layer]), - NodeRuntime.runMain, -); +if (import.meta.main) { + Command.run(cli, { version: "0.0.0" }).pipe( + Effect.scoped, + Effect.provide([Logger.layer([Logger.consolePretty()]), NodeServices.layer]), + NodeRuntime.runMain, + ); +} diff --git a/apps/server/src/cloud/bootService.test.ts b/apps/server/src/cloud/bootService.test.ts index 46e9a1da98785..cd27215ec0533 100644 --- a/apps/server/src/cloud/bootService.test.ts +++ b/apps/server/src/cloud/bootService.test.ts @@ -91,7 +91,7 @@ const makeTestContext = Effect.fn("test.makeTestContext")(function* () { it("renders a systemd unit with absolute paths and append-mode logging", () => { const unit = BootService.renderBootServiceUnit({ nodePath: "/usr/local/bin/node", - t3EntryPath: "/home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs", + t3EntryPath: "/home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs", baseDir: "/home/theo/.t3", logPath: "/home/theo/.t3/userdata/logs/boot-service.log", unitPath: "/home/theo/.config/systemd/user/t3code.service", @@ -110,7 +110,7 @@ it("renders a systemd unit with absolute paths and append-mode logging", () => { "WorkingDirectory=%h", "Environment=T3CODE_HOME=/home/theo/.t3", "Environment=T3_BOOT_SERVICE_UNIT=t3code.service", - "ExecStart=/usr/local/bin/node /home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs serve", + "ExecStart=/usr/local/bin/node /home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs serve", "Restart=always", "RestartSec=5", "StandardOutput=append:/home/theo/.t3/userdata/logs/boot-service.log", @@ -145,28 +145,34 @@ it("quotes systemd values containing spaces and escapes percent specifiers", () it("flags package-manager cache entry points as ephemeral", () => { assert.isTrue( - BootService.isEphemeralCacheEntry("/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs"), + BootService.isEphemeralCacheEntry( + "/home/theo/.npm/_npx/abc123/node_modules/@ag-jin/t3code/dist/bin.mjs", + ), ); assert.isTrue( BootService.isEphemeralCacheEntry("C:\\Users\\theo\\AppData\\npm-cache\\_npx\\abc\\bin.mjs"), ); assert.isTrue( BootService.isEphemeralCacheEntry( - "/home/theo/.cache/pnpm/dlx/abc/node_modules/t3/dist/bin.mjs", + "/home/theo/.cache/pnpm/dlx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs", ), ); assert.isTrue( - BootService.isEphemeralCacheEntry("/home/theo/.bun/install/cache/t3@0.0.27/dist/bin.mjs"), + BootService.isEphemeralCacheEntry( + "/home/theo/.bun/install/cache/@ag-jin/t3code@0.0.27/dist/bin.mjs", + ), + ); + assert.isFalse( + BootService.isEphemeralCacheEntry("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"), ); - assert.isFalse(BootService.isEphemeralCacheEntry("/usr/local/lib/node_modules/t3/dist/bin.mjs")); assert.isFalse( BootService.isEphemeralCacheEntry( - "/home/theo/dev/pnpm/dlx-tools/t3/node_modules/t3/dist/bin.mjs", + "/home/theo/dev/pnpm/dlx-tools/t3/node_modules/@ag-jin/t3code/dist/bin.mjs", ), ); assert.isFalse( BootService.isEphemeralCacheEntry( - "/home/theo/.t3/runtime/versions/0.0.27/node_modules/t3/dist/bin.mjs", + "/home/theo/.t3/runtime/versions/0.0.27/node_modules/@ag-jin/t3code/dist/bin.mjs", ), ); }); @@ -254,7 +260,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"), + host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe(Effect.provide(makeRecordingRunnerLayer(commands)), provideHostRefs(dirs.home)); const plan = yield* service.install; @@ -262,11 +268,18 @@ it.layer(NodeServices.layer)("BootService", (it) => { const runtimeDir = path.join(dirs.baseDir, "runtime", "versions", "0.0.27"); assert.equal( plan.t3EntryPath, - path.join(runtimeDir, "node_modules", "t3", "dist", "bin.mjs"), + path.join(runtimeDir, "node_modules", "@ag-jin", "t3code", "dist", "bin.mjs"), ); assert.deepEqual(commands[0], { command: "npm", - args: ["install", "--prefix", runtimeDir, "--no-fund", "--no-audit", "t3@0.0.27"], + args: [ + "install", + "--prefix", + runtimeDir, + "--no-fund", + "--no-audit", + "@ag-jin/t3code@0.0.27", + ], }); // Success is recorded via a sentinel so interrupted installs re-run. assert.isTrue(yield* fs.exists(path.join(runtimeDir, ".install-complete"))); @@ -281,7 +294,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"), + host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe(Effect.provide(makeRecordingRunnerLayer(commands)), provideHostRefs(dirs.home)); const plan = yield* service.install; @@ -325,7 +338,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/home/theo/.npm/_npx/abc/node_modules/t3/dist/bin.mjs"), + host: makeHost("/home/theo/.npm/_npx/abc/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe( Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "npm" })), provideHostRefs(dirs.home), @@ -396,7 +409,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"), + host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe( Effect.provide(makeRecordingRunnerLayer(commands)), provideHostRefs(dirs.home, "darwin"), @@ -423,7 +436,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"), + host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe( Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "loginctl" })), provideHostRefs(dirs.home), @@ -538,7 +551,7 @@ it.layer(NodeServices.layer)("BootService", (it) => { baseDir: dirs.baseDir, logsDir: dirs.logsDir, cliVersion: "0.0.27", - host: makeHost("/usr/local/lib/node_modules/t3/dist/bin.mjs"), + host: makeHost("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"), }).pipe( Effect.provide(makeRecordingRunnerLayer(commands, { failCommand: "systemctl" })), provideHostRefs(dirs.home), diff --git a/apps/server/src/cloud/bootService.ts b/apps/server/src/cloud/bootService.ts index d7e13e834f447..fbe4d5e8cc336 100644 --- a/apps/server/src/cloud/bootService.ts +++ b/apps/server/src/cloud/bootService.ts @@ -21,7 +21,7 @@ import { ensurePinnedRuntimeInstalled, pinnedRuntimePaths } from "./pinnedRuntim /** * Installs T3 Code as a per-user boot service. Linux-only for now: systemd * user unit + loginctl enable-linger. The service runs a stable or pinned - * runtime — never an ephemeral `npx t3` cache whose eviction could break + * runtime — never an ephemeral `npx @ag-jin/t3code` cache whose eviction could break * startup. */ @@ -39,7 +39,7 @@ const EPHEMERAL_CACHE_SEGMENTS = [ ]; /** - * `npx t3` (and pnpm dlx / bunx) run out of ephemeral package-manager + * `npx @ag-jin/t3code` (and pnpm dlx / bunx) run out of ephemeral package-manager * caches that can be evicted at any time — a boot service must never point * there. Global installs, repo checkouts, and the pinned runtime below are * all stable. diff --git a/apps/server/src/cloud/pinnedRuntime.test.ts b/apps/server/src/cloud/pinnedRuntime.test.ts index 9b46c0038ec01..0531ce0223150 100644 --- a/apps/server/src/cloud/pinnedRuntime.test.ts +++ b/apps/server/src/cloud/pinnedRuntime.test.ts @@ -15,6 +15,18 @@ import { } from "./pinnedRuntime.ts"; it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => { + it.effect("resolves the fork package as the pinned runtime entry", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const paths = pinnedRuntimePaths(path, "/tmp/t3", "0.0.30"); + + assert.equal( + paths.entryPath, + "/tmp/t3/runtime/versions/0.0.30/node_modules/@ag-jin/t3code/dist/bin.mjs", + ); + }), + ); + it.effect("serializes concurrent installs of the same runtime", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/cloud/pinnedRuntime.ts b/apps/server/src/cloud/pinnedRuntime.ts index e3e095ce081bd..a578260a96c43 100644 --- a/apps/server/src/cloud/pinnedRuntime.ts +++ b/apps/server/src/cloud/pinnedRuntime.ts @@ -6,17 +6,20 @@ import * as Schema from "effect/Schema"; import * as Semaphore from "effect/Semaphore"; import * as ProcessRunner from "../processRunner.ts"; +import { forkServerPackageName } from "../packageIdentity.ts"; /** - * A pinned runtime is an exact `t3@` npm-installed into + * A pinned runtime is an exact `@ag-jin/t3code@` npm-installed into * /runtime/versions/. The boot service points its systemd * unit here, and server self-update installs the target version here before - * switching over — never `npx t3`, whose cache is ephemeral and whose + * switching over — never `npx @ag-jin/t3code`, whose cache is ephemeral and whose * registry fetch at boot would make startup depend on the network. */ const PINNED_RUNTIME_DIR = "runtime"; const PINNED_RUNTIME_INSTALL_TIMEOUT = Duration.minutes(10); +const PUBLISHED_SERVER_PACKAGE_NAME = forkServerPackageName; +const PUBLISHED_SERVER_PACKAGE_PATH = PUBLISHED_SERVER_PACKAGE_NAME.split("/"); // Boot-service setup and remote self-update share this module but can be // constructed in separate layers. Serialize the complete check/install/ // sentinel transaction across all callers in this process. @@ -36,7 +39,13 @@ export function pinnedRuntimePaths( const versionDir = path.join(baseDir, PINNED_RUNTIME_DIR, "versions", version); return { versionDir, - entryPath: path.join(versionDir, "node_modules", "t3", "dist", "bin.mjs"), + entryPath: path.join( + versionDir, + "node_modules", + ...PUBLISHED_SERVER_PACKAGE_PATH, + "dist", + "bin.mjs", + ), sentinelPath: path.join(versionDir, ".install-complete"), }; } @@ -59,7 +68,7 @@ export class PinnedRuntimeInstallError extends Schema.TaggedErrorClass` into the pinned runtime directory unless a complete + * Installs `@ag-jin/t3code@` into the pinned runtime directory unless a complete * install is already there, and returns its paths. The sentinel is written * only after npm exits 0; checking the entry file alone is not enough — npm * extracts files before running native builds (node-pty), so a killed @@ -103,7 +112,7 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu ), ); - const installStep = "installing the pinned t3 runtime (this can take a few minutes)"; + const installStep = `installing the pinned ${PUBLISHED_SERVER_PACKAGE_NAME} runtime (this can take a few minutes)`; yield* runner .run({ command: "npm", @@ -113,7 +122,7 @@ export const ensurePinnedRuntimeInstalled = Effect.fn("cloud.pinned_runtime.ensu paths.versionDir, "--no-fund", "--no-audit", - `t3@${input.version}`, + `${PUBLISHED_SERVER_PACKAGE_NAME}@${input.version}`, ], // Native deps (node-pty) can compile from source on slow boxes; the // ProcessRunner default of 60s would kill a healthy install. diff --git a/apps/server/src/cloud/selfUpdate.test.ts b/apps/server/src/cloud/selfUpdate.test.ts index 9d6e3801704df..f92b2941d9aae 100644 --- a/apps/server/src/cloud/selfUpdate.test.ts +++ b/apps/server/src/cloud/selfUpdate.test.ts @@ -80,15 +80,20 @@ const provideHostRefs = (input: { ); it("recognizes published npm artifacts as swappable entry points", () => { - assert.isTrue(SelfUpdate.isPublishedCliEntry("/usr/local/lib/node_modules/t3/dist/bin.mjs")); assert.isTrue( - SelfUpdate.isPublishedCliEntry("/home/theo/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs"), + SelfUpdate.isPublishedCliEntry("/usr/local/lib/node_modules/@ag-jin/t3code/dist/bin.mjs"), ); assert.isTrue( SelfUpdate.isPublishedCliEntry( - "C:\\Users\\theo\\AppData\\Roaming\\npm\\node_modules\\t3\\dist\\bin.mjs", + "/home/theo/.npm/_npx/abc123/node_modules/@ag-jin/t3code/dist/bin.mjs", ), ); + assert.isTrue( + SelfUpdate.isPublishedCliEntry( + "C:\\Users\\theo\\AppData\\Roaming\\npm\\node_modules\\@ag-jin\\t3code\\dist\\bin.mjs", + ), + ); + assert.isFalse(SelfUpdate.isPublishedCliEntry("/usr/local/lib/node_modules/t3/dist/bin.mjs")); // Dev checkouts and the desktop bundle run apps/server/dist directly. assert.isFalse(SelfUpdate.isPublishedCliEntry("/home/theo/dev/t3/apps/server/dist/bin.mjs")); assert.isFalse(SelfUpdate.isPublishedCliEntry("")); @@ -125,7 +130,10 @@ it.layer(NodeServices.layer)("resolveServerSelfUpdateCapability", (it) => { it.effect("reports boot-service for the systemd-spawned unit process", () => Effect.gen(function* () { const { home, path } = yield* makeHome(); - const entryPath = path.join(home, ".t3/runtime/versions/0.0.28/node_modules/t3/dist/bin.mjs"); + const entryPath = path.join( + home, + ".t3/runtime/versions/0.0.28/node_modules/@ag-jin/t3code/dist/bin.mjs", + ); yield* writeUnitReferencing(home, entryPath); const method = yield* SelfUpdate.resolveServerSelfUpdateCapability({ desktopManaged: false, @@ -147,7 +155,10 @@ it.layer(NodeServices.layer)("resolveServerSelfUpdateCapability", (it) => { it.effect("does not claim a systemd process owned by another unit", () => Effect.gen(function* () { const { home, path } = yield* makeHome(); - const entryPath = path.join(home, ".t3/runtime/versions/0.0.28/node_modules/t3/dist/bin.mjs"); + const entryPath = path.join( + home, + ".t3/runtime/versions/0.0.28/node_modules/@ag-jin/t3code/dist/bin.mjs", + ); yield* writeUnitReferencing(home, entryPath); const method = yield* SelfUpdate.resolveServerSelfUpdateCapability({ desktopManaged: false, @@ -165,7 +176,10 @@ it.layer(NodeServices.layer)("resolveServerSelfUpdateCapability", (it) => { it.effect("reports respawn for a manual run of the pinned artifact", () => Effect.gen(function* () { const { home, path } = yield* makeHome(); - const entryPath = path.join(home, ".t3/runtime/versions/0.0.28/node_modules/t3/dist/bin.mjs"); + const entryPath = path.join( + home, + ".t3/runtime/versions/0.0.28/node_modules/@ag-jin/t3code/dist/bin.mjs", + ); yield* writeUnitReferencing(home, entryPath); // Same unit on disk, but no INVOCATION_ID: restarting the unit would // not replace this process, so it must respawn itself instead. @@ -185,7 +199,7 @@ it.layer(NodeServices.layer)("resolveServerSelfUpdateCapability", (it) => { provideHostRefs({ platform: "darwin", env: { HOME: home }, - entryPath: `${home}/.npm/_npx/abc123/node_modules/t3/dist/bin.mjs`, + entryPath: `${home}/.npm/_npx/abc123/node_modules/@ag-jin/t3code/dist/bin.mjs`, }), ); assert.equal(method, "respawn"); @@ -197,7 +211,10 @@ it.layer(NodeServices.layer)("resolveServerSelfUpdateCapability", (it) => { const { home, path } = yield* makeHome(); // Desktop ownership wins over every process-shape heuristic: even a // systemd-looking pinned artifact belongs to the app that spawned it. - const entryPath = path.join(home, ".t3/runtime/versions/0.0.28/node_modules/t3/dist/bin.mjs"); + const entryPath = path.join( + home, + ".t3/runtime/versions/0.0.28/node_modules/@ag-jin/t3code/dist/bin.mjs", + ); yield* writeUnitReferencing(home, entryPath); const method = yield* SelfUpdate.resolveServerSelfUpdateCapability({ desktopManaged: true, @@ -264,7 +281,7 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { const baseDir = path.join(home, ".t3"); const entryPath = options?.entryPath ?? - path.join(home, ".t3/runtime/versions/0.0.28/node_modules/t3/dist/bin.mjs"); + path.join(home, ".t3/runtime/versions/0.0.28/node_modules/@ag-jin/t3code/dist/bin.mjs"); const env: NodeJS.ProcessEnv = options?.bootService === true ? { @@ -352,7 +369,7 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { Effect.gen(function* () { const context = yield* makeContext(); const error = yield* context.service.update({ targetVersion: "latest" }).pipe(Effect.flip); - assert.include(error.reason, "not an exact t3 version"); + assert.include(error.reason, "not an exact @ag-jin/t3code version"); assert.lengthOf(context.commands, 0); }), ); @@ -382,7 +399,7 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { Effect.gen(function* () { const context = yield* makeContext({ failWhen: (command) => command === "npm" }); const error = yield* context.service.update({ targetVersion: "0.0.29" }).pipe(Effect.flip); - assert.equal(error.reason, "Could not install the requested t3 version."); + assert.equal(error.reason, "Could not install the requested @ag-jin/t3code version."); yield* TestClock.adjust(Duration.seconds(10)); assert.lengthOf(context.spawns, 0); assert.equal(context.exitCount(), 0); @@ -400,7 +417,14 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { }, }); const versionDir = context.path.join(context.baseDir, "runtime", "versions", "0.0.29"); - const entryPath = context.path.join(versionDir, "node_modules", "t3", "dist", "bin.mjs"); + const entryPath = context.path.join( + versionDir, + "node_modules", + "@ag-jin", + "t3code", + "dist", + "bin.mjs", + ); yield* context.fs.makeDirectory(context.path.dirname(entryPath), { recursive: true }); yield* context.fs.writeFileString(entryPath, "export {};\n"); yield* context.fs.writeFileString( @@ -468,12 +492,12 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { const pinnedEntry = context.path.join( context.baseDir, - "runtime/versions/0.0.29/node_modules/t3/dist/bin.mjs", + "runtime/versions/0.0.29/node_modules/@ag-jin/t3code/dist/bin.mjs", ); assert.deepEqual( context.commands.map((entry) => [entry.command, ...entry.args].join(" ")), [ - `npm install --prefix ${context.path.join(context.baseDir, "runtime/versions/0.0.29")} --no-fund --no-audit t3@0.0.29`, + `npm install --prefix ${context.path.join(context.baseDir, "runtime/versions/0.0.29")} --no-fund --no-audit @ag-jin/t3code@0.0.29`, `${NODE_PATH} ${pinnedEntry} --version`, ], ); @@ -498,7 +522,7 @@ it.layer(NodeServices.layer)("ServerSelfUpdate.update", (it) => { const pinnedEntry = context.path.join( context.baseDir, - "runtime/versions/0.0.29/node_modules/t3/dist/bin.mjs", + "runtime/versions/0.0.29/node_modules/@ag-jin/t3code/dist/bin.mjs", ); const unit = yield* context.fs.readFileString( context.path.join(context.home, ".config", "systemd", "user", "t3code.service"), diff --git a/apps/server/src/cloud/selfUpdate.ts b/apps/server/src/cloud/selfUpdate.ts index 62bd07fbbc8bd..22bdd0d569b10 100644 --- a/apps/server/src/cloud/selfUpdate.ts +++ b/apps/server/src/cloud/selfUpdate.ts @@ -33,9 +33,10 @@ import { renderBootServiceUnit, } from "./bootService.ts"; import { ensurePinnedRuntimeInstalled, removePinnedRuntimeInstallation } from "./pinnedRuntime.ts"; +import { forkServerPackageName } from "../packageIdentity.ts"; /** - * Lets a connected client replace this server with another published `t3` + * Lets a connected client replace this server with another published `@ag-jin/t3code` * version over RPC — the only update path that works when the user is not at * the machine (phone against a home server, relay-managed box). The target * version is npm-installed into the pinned runtime and verified before @@ -43,6 +44,7 @@ import { ensurePinnedRuntimeInstalled, removePinnedRuntimeInstallation } from ". */ const PREFLIGHT_TIMEOUT = Duration.seconds(30); +const PUBLISHED_SERVER_PACKAGE_NAME = forkServerPackageName; /** Grace between acknowledging the RPC and killing the process, so the response (and its relay hop) flushes before the socket drops. */ const RESTART_DELAY = Duration.seconds(2); @@ -75,7 +77,9 @@ function normalizeEntryPath(entryPath: string): string { * npm identity, and the desktop manages its own updates. */ export function isPublishedCliEntry(entryPath: string): boolean { - return normalizeEntryPath(entryPath).includes("/node_modules/t3/dist/"); + return normalizeEntryPath(entryPath).includes( + `/node_modules/${PUBLISHED_SERVER_PACKAGE_NAME}/dist/`, + ); } /** @@ -241,7 +245,9 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option const activeMethod = capability; const targetVersion = input.targetVersion.trim(); if (!EXACT_VERSION_PATTERN.test(targetVersion)) { - return yield* failWith(`'${targetVersion}' is not an exact t3 version.`); + return yield* failWith( + `'${targetVersion}' is not an exact ${PUBLISHED_SERVER_PACKAGE_NAME} version.`, + ); } const alreadyRunning = yield* Ref.getAndSet(inFlight, true); @@ -257,7 +263,12 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option path, runner, }).pipe( - Effect.mapError((error) => failWith("Could not install the requested t3 version.", error)), + Effect.mapError((error) => + failWith( + `Could not install the requested ${PUBLISHED_SERVER_PACKAGE_NAME} version.`, + error, + ), + ), ); // A broken artifact (failed native build, incompatible node) must be @@ -270,7 +281,10 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option }) .pipe( Effect.mapError((cause) => - failWith(`Could not verify the installed t3@${targetVersion}.`, cause), + failWith( + `Could not verify the installed ${PUBLISHED_SERVER_PACKAGE_NAME}@${targetVersion}.`, + cause, + ), ), ); // Effect CLI's unstable formatVersion currently emits `${name} v${version}`. @@ -287,13 +301,16 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option path, }).pipe( Effect.mapError((error) => - failWith(`Could not remove the failed t3@${targetVersion} installation.`, error), + failWith( + `Could not remove the failed ${PUBLISHED_SERVER_PACKAGE_NAME}@${targetVersion} installation.`, + error, + ), ), ); return yield* failWith( preflight.code !== 0 - ? `The installed t3@${targetVersion} failed its version check (exit code ${String(preflight.code)}).` - : `The installed runtime did not report the requested t3@${targetVersion} version.`, + ? `The installed ${PUBLISHED_SERVER_PACKAGE_NAME}@${targetVersion} failed its version check (exit code ${String(preflight.code)}).` + : `The installed runtime did not report the requested ${PUBLISHED_SERVER_PACKAGE_NAME}@${targetVersion} version.`, ); } diff --git a/apps/server/src/packageIdentity.test.ts b/apps/server/src/packageIdentity.test.ts new file mode 100644 index 0000000000000..cd043d557128d --- /dev/null +++ b/apps/server/src/packageIdentity.test.ts @@ -0,0 +1,16 @@ +import { assert, it } from "@effect/vitest"; + +import serverPackageJson from "../package.json" with { type: "json" }; +import { + forkServerCliBinary, + forkServerPackageName, + forkServerRepositoryUrl, +} from "./packageIdentity.ts"; + +it("keeps the workspace package private while publishing the fork-owned CLI identity", () => { + assert.equal(serverPackageJson.name, "t3"); + assert.equal(serverPackageJson.private, true); + assert.equal(serverPackageJson.repository.url, forkServerRepositoryUrl); + assert.equal(forkServerPackageName, "@ag-jin/t3code"); + assert.equal(forkServerCliBinary, "t3code"); +}); diff --git a/apps/server/src/packageIdentity.ts b/apps/server/src/packageIdentity.ts new file mode 100644 index 0000000000000..3fc8be62f78f6 --- /dev/null +++ b/apps/server/src/packageIdentity.ts @@ -0,0 +1,3 @@ +export const forkServerPackageName = "@ag-jin/t3code"; +export const forkServerCliBinary = "t3code"; +export const forkServerRepositoryUrl = "https://github.com/ag-jin/t3code-2K"; diff --git a/docs/operations/release.md b/docs/operations/release.md index e86df409b11ea..37c8e94751276 100644 --- a/docs/operations/release.md +++ b/docs/operations/release.md @@ -6,11 +6,12 @@ creates one GitHub Release from an already-pushed immutable tag in `ag-jin/t3code-2K`. -It deliberately does not publish an npm package, deploy Relay or hosted Web, -write version commits, send notifications, or read signing credentials. Those -concerns are owned by the later release tickets. Do not call a release produced -by this workflow a production release until the CLI/self-update and signing -requirements are completed and verified. +It publishes only the fork-owned `@ag-jin/t3code` CLI package alongside the +desktop release; it does not publish unrelated npm packages, deploy Relay or +hosted Web, write version commits, send notifications, or read signing +credentials. Do not call a release produced by this workflow a production +release until the CLI/self-update and signing requirements are completed and +verified. ## Trigger and provenance @@ -68,8 +69,15 @@ that the tag already exists, and targets the resolved tag commit. ## Remaining gates -- Fork-owned CLI package and server self-update identity are required before a - production desktop release can expose server self-update. +- The fork publishes `@ag-jin/t3code` with the `t3code` executable. The + development workspace package remains private so it cannot publish upstream + `t3`; the release CLI writes the fork package metadata only for publishing. + Installing the fork does not replace an existing upstream `t3` command. Use + `t3code` explicitly and choose a separate `--base-dir` when its standalone + server state must remain isolated from an existing installation. + Configure npm OIDC trusted publishing for this repository before release; the + workflow publishes and reads back the exact tagged version before creating a + GitHub Release. - Fork-owned macOS notarization and Windows Trusted Signing are required before calling the corresponding installers signed. - Fork-owned Relay, Clerk, Cloudflare, and Web configuration must be added only diff --git a/scripts/release-workflow.test.ts b/scripts/release-workflow.test.ts index dc17b3e80b8ce..7f81902049cfd 100644 --- a/scripts/release-workflow.test.ts +++ b/scripts/release-workflow.test.ts @@ -53,6 +53,15 @@ it.layer(NodeServices.layer)("fork release workflow", (it) => { assert.match(workflow, /- name: Check\n run: vp check/); assert.match(workflow, /- name: Typecheck\n run: vp run typecheck/); assert.match(workflow, /- name: Test\n run: vp run test/); + assert.match(workflow, /publish_fork_cli:/); + assert.match(workflow, /needs: \[preflight, build, publish_fork_cli\]/); + assert.match(workflow, /needs\.publish_fork_cli\.result == 'success'/); + assert.match(workflow, /id-token: write/); + assert.match( + workflow, + /node apps\/server\/scripts\/cli\.ts publish --tag "\$dist_tag" --app-version "\$VERSION" --provenance --verbose/, + ); + assert.match(workflow, /npm view "@ag-jin\/t3code@\$\{VERSION\}" version/); assert.notMatch( workflow,