Sign in and read on the platform itself when nothing names another: login's --url, the variable and the profile still win in that order, the anonymous client calls the platform rather than refusing, Brand names the platform's host once, and the install script, the docs, the Install page, the platform's home and the AGENTS.md block say a bare login
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent 2ee8d82 · Browse files · 20 files·+143 added−109 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+143 added−109 removed
- tests:+93 added−24 removed
- other:+50 added−85 removed
Provenance
- Commit
5578685- Tree
0d6d9a8- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
2ee8d82
20 files changed+143 added−109 removed
modified:apps/cli/src/local/login.ts+14 added-13 removed
215 unmodified lines216 onSome: ({ origin }) => Effect.succeed(origin),217 }218 );219 220-/** `Credentials` reads back only the current profile, so another profile needs `--url`. */220+/**221+ * The flag, then the variable, then the current profile's platform, then the222+ * platform itself. `Credentials` reads back only the current profile, so223+ * another profile with no flag signs in to the platform itself.224+ */225 const platformOf = (226 flag: Option.Option<string>,227 profile: Option.Option<string>,228 env: Readonly<Record<string, string>>6 unmodified lines235 if (Option.isSome(named)) {236 return yield* originOf(named.value);237 }238 235- const name = profileName(profile, env);236-239 const current =238- name === profileName(Option.none(), env)240+ profileName(profile, env) === profileName(Option.none(), env)241 ? yield* (yield* Credentials).current242 : Option.none<Profile>();243 242- if (Option.isSome(current)) {243- return yield* originOf(current.value.url);244- }245-246- return yield* new LoginUsage({247- reason: `no platform to log in to for profile ${name}: run ${Brand.cli} login --url https://git.${Brand.domain}${Option.isSome(profile) ? ` --profile ${name}` : ""}`,248- });244+ return yield* originOf(245+ Option.match(current, {246+ onNone: () => Brand.platformUrl,247+ onSome: ({ url }) => url,248+ })249+ );250 });251 252 const tokenFromStdin = Effect.gen(function* () {253 const { stdin } = yield* Stdio.Stdio;255 unmodified lines509 )510 ),511 url: Flag.String("url").pipe(512 Flag.withDescription(512- `The platform's origin, e.g. https://<host> (default: $${SLUG}_URL, else the profile's)`513+ `The platform's origin, e.g. https://<host> (default: $${SLUG}_URL, else the profile's, else ${Brand.platformUrl})`514 ),515 Flag.optional516 ),517 },45 unmodified lines563 });564 })565 ).pipe(566 Command.withDescription(566- "Sign in to a platform; git and this CLI then use its token."567+ "Sign in (to the platform itself unless --url names another); git and this CLI then use its token."568 )569 );570 571 /** Exit 5 means the line is already gone. */85 unmodified linesmodified:apps/cli/src/main.ts+1 added-4 removed
12 unmodified lines13141516171718192063 unmodified lines84858687899091888990919295 unmodified lines12 unmodified linesimport { holdStdout, Output, OutputLive } from "./output.ts";import { CurrentMode, Policy } from "./policy.ts";import { isTransportFailure, noPlatformOf, RemoteClient, transportMessage,} from "./remote.ts";import { commands, mcp, UnknownCommand } from "./surfaces.ts";63 unmodified lines if (isUsage(failure) || Schema.isSchemaError(failure)) { return Option.some(hinted(failure) ?? failure.message); }
return isTransportFailure(failure) ? Option.map(noPlatformOf(failure), ({ message }) => message) : Option.none(); return Option.none();};
const noteFor = (failure: Failure) => { if (isUnauthenticated(failure)) {95 unmodified linesmodified:apps/cli/src/remote.ts+5 added-53 removed
26 unmodified lines27 import { Credentials } from "./credentials.ts";28 29 const URL_VARIABLE = `${Brand.slug.toUpperCase()}_URL`;30 31-export class NoPlatform extends Schema.TaggedError<NoPlatform>()("NoPlatform", {32- variable: Schema.String,33-}) {34- override get message() {35- return `no platform to call: run ${Brand.cli} login, or set ${this.variable} to call one as anyone`;36- }37-}38-31 const isClientError = Schema.is(RpcClientError.RpcClientError);32 41-const isDefect = Schema.is(RpcClientError.RpcClientDefect);42-43-const isNoPlatformError = Schema.is(NoPlatform);44-33 const isHttpFailure = Schema.is(HttpClientError.HttpClientErrorSchema);34 35 export const isTransportFailure = isClientError;36 4 unmodified lines41 Predicate.isString(failure.reason.cause.message)42 ? failure.reason.cause.message43 : failure.message;44 57-export const noPlatformOf = (58- failure: RpcClientError.RpcClientError59-): Option.Option<NoPlatform> =>60- isDefect(failure.reason) && isNoPlatformError(failure.reason.cause)61- ? Option.some(failure.reason.cause)62- : Option.none();63-45 const isUnauthorized = (failure: RpcClientError.RpcClientError) =>46 Predicate.hasProperty(failure.reason, "cause") &&47 failure.reason.cause instanceof HttpClientError.StatusCodeError &&48 failure.reason.cause.response.status === 401;40 unmodified lines89 ),90 Layer.provide([FetchHttpClient.layer, RpcSerialization.layerJson])91 );92 112-const noPlatform = new NoPlatform({ variable: URL_VARIABLE });113-114-const nowhere = Layer.effect(Client)(RpcClient.make(Contracts)).pipe(115- Layer.provide(116- Layer.effect(RpcClient.Protocol)(117- Effect.flatMap(118- Effect.service(RpcSerialization.RpcSerialization),119- (serialization) =>120- RpcClient.Protocol.make(() =>121- Effect.succeed({122- codecFor: serialization.codecFor,123- send: () =>124- Effect.fail(125- new RpcClientError.RpcClientError({126- reason: new RpcClientError.RpcClientDefect({127- cause: noPlatform,128- message: noPlatform.message,129- }),130- })131- ),132- supportsAck: false,133- supportsTransferables: false,134- })135- )136- )137- )138- ),139- Layer.provide(RpcSerialization.layerJson)140-);141-93 export const RemoteClient: Layer.Layer<Client, never, Credentials> =94 Layer.unwrap(95 Effect.gen(function* () {96 const profile = yield* Effect.flatMap(8 unmodified lines105 const url = yield* Config.option(106 Config.NonEmptyString(URL_VARIABLE)107 ).pipe(Effect.orElseSucceed(() => Option.none()));108 158- return Option.match(url, {159- onNone: () => nowhere,160- onSome: (origin) => over(origin, Option.none()),161- });109+ // With nothing naming a platform, the platform itself, as anyone.110+ return over(111+ Option.getOrElse(url, () => Brand.platformUrl),112+ Option.none()113+ );114 })115 );modified:apps/cli/test/local/login.test.ts+51 added-10 removed
432 unmodified lines433 30_000434 );435 436 it.live(437- "without --url, logs the current profile in again on its platform, but asks for --url for another profile",437+ "without --url, logs the current profile in again on its platform, and another profile in on the platform itself",438 () =>439 Effect.gen(function* () {440 const env = yield* home;441 const platform = yield* seams(signedInAs("alice"));9 unmodified lines451 );452 453 expect({454 again: Exit.isSuccess(again),455- bob: yield* stored(env, "bob"),455+ bob: Option.map(yield* stored(env, "bob"), ({ url: at }) => at),456 checked: (yield* platform.connected).map(({ url: at }) => at),457 other: Exit.isSuccess(other),458 }).toStrictEqual({459 again: true,460- bob: Option.none(),461- checked: [url, url],462- other: false,460+ bob: Option.some(Brand.platformUrl),461+ checked: [url, url, Brand.platformUrl],462+ other: true,463 });464- expect((yield* printed).stderr.join("\n")).toContain("--url");464 }).pipe(Effect.scoped, Effect.provide(testServices)),465 30_000466 );467 468 it.live(470- "with no --url and no stored profile, asks for --url, naming the platform's own host",469+ "with no --url, no variable and no stored profile, signs in to the platform itself",470 () =>471 Effect.gen(function* () {472 const env = yield* home;473 const platform = yield* seams(signedInAs("alice"));3 unmodified lines477 seams: platform.layer,478 stdin: `${given}\n`,479 });480 482- expect(Exit.isFailure(exit)).toBeTruthy();483- expect((yield* printed).stderr.join("\n")).toContain(484- `${Brand.cli} login --url https://git.${Brand.domain}`481+ expect({482+ checked: (yield* platform.connected).map(({ url: at }) => at),483+ signedIn: Exit.isSuccess(exit),484+ stored: Option.map(485+ yield* stored(env, "default"),486+ ({ url: at }) => at487+ ),488+ }).toStrictEqual({489+ checked: [Brand.platformUrl],490+ signedIn: true,491+ stored: Option.some(Brand.platformUrl),492+ });493+ }).pipe(Effect.scoped, Effect.provide(testServices)),494+ 30_000495+ );496+497+ it.live(498+ "takes the platform from --url, then the variable, then the stored profile, then the platform itself",499+ () =>500+ Effect.gen(function* () {501+ const env = yield* home;502+ const platform = yield* seams(signedInAs("alice"));503+ const fromVariable = "https://variable.test";504+ const fromFlag = "https://flag.test";505+506+ const run = (extra: Record<string, string>) => ({507+ env: { ...env, ...extra },508+ seams: platform.layer,509+ stdin: `${given}\n`,510+ });511+512+ yield* cli(["login", "--token-stdin"], run({}));513+ yield* cli(["login", "--url", url, "--token-stdin"], run({}));514+ yield* cli(["login", "--token-stdin"], run({}));515+ yield* cli(516+ ["login", "--token-stdin"],517+ run({ [`${SLUG}_URL`]: fromVariable })518 );519+ yield* cli(520+ ["login", "--url", fromFlag, "--token-stdin"],521+ run({ [`${SLUG}_URL`]: fromVariable })522+ );523+524+ expect(525+ (yield* platform.connected).map(({ url: at }) => at)526+ ).toStrictEqual([Brand.platformUrl, url, url, fromVariable, fromFlag]);527 }).pipe(Effect.scoped, Effect.provide(testServices)),528 30_000529 );530 });286 unmodified linesmodified:apps/cli/test/remote.test.ts+27 added-10 removed
2 unmodified lines3 import { Contracts } from "@repo/protocol/contracts";4 import { AskId, Handle, KindName } from "@repo/protocol/ids";5 import { unanswered } from "@repo/protocol/testing";6 import { ConfigProvider, Effect, Layer, Option, Redacted } from "effect";7+import { FetchHttpClient } from "effect/http";8 9 import { Credentials } from "../src/credentials.ts";10 import type { Profile } from "../src/credentials.ts";11 import { RemoteClient } from "../src/remote.ts";173 unmodified lines185 expect(run.err[0]).toContain(`${origin}/rpc`);186 }).pipe(Effect.scoped)187 );188 188- it.live("with no profile and no url, is a usage error naming login", () =>189- Effect.gen(function* () {190- const run = yield* runProgram(["asks", "--project", "datekit"], {191- client: remote(holding(Option.none())),192- handlers,193- });189+ it.live(190+ "with no profile and no url, calls the platform itself, as anyone",191+ () =>192+ Effect.gen(function* () {193+ const sent: (string | null)[] = [];194 195- expect(run.code).toBe(2);196- expect(run.err).toHaveLength(1);197- expect(run.err[0]).toContain(`${Brand.cli} login`);198- })195+ // The platform itself is never called from a test: the fetch notes196+ // where it was sent and answers 503.197+ const noted: typeof globalThis.fetch = (input, init) => {198+ sent.push(199+ new Request(input, init).url,200+ new Headers(init?.headers).get("authorization")201+ );202+203+ return Promise.resolve(new Response(null, { status: 503 }));204+ };205+206+ const run = yield* runProgram(["asks", "--project", "datekit"], {207+ client: remote(holding(Option.none())).pipe(208+ Layer.provide(Layer.succeed(FetchHttpClient.Fetch)(noted))209+ ),210+ handlers,211+ });212+213+ expect(run.code).toBe(69);214+ expect(sent).toStrictEqual([`${Brand.platformUrl}/rpc/`, null]);215+ })216 );217 });modified:apps/platform/src/home.ts+2 added-1 removed
1 import { commandDocs } from "@repo/agent-kit/command-doc";2 import { frontLlms, MCP_PROTOCOL } from "@repo/agent-kit/host-doc";3+import { loginCommand } from "@repo/agent-kit/install";4 import { Brand } from "@repo/brand";5 import { FrontPage } from "@repo/project/front-page";6 import type { Projects } from "@repo/project/projects";7 import { withStandingPosture } from "@repo/project/standing-posture";94 unmodified lines102 section(103 "CLI",104 pre(`curl -fsSL ${origin}/install.sh | sh`),105 `<p>Releases: ${link(`${origin}/releases/manifest.json`)}</p>`,105- `<p>Then sign in: ${code(`${Brand.cli} login --url ${origin}`)}</p>`106+ `<p>Then sign in: ${code(loginCommand(origin))}</p>`107 ),108 section(109 "Agents",110 list([68 unmodified linesmodified:infra/stages.ts+1 added-1 removed
40 unmodified lines41 42 export const customHosts = (stage: Stage): Option.Option<Hosts> =>43 stage === "prod"44 ? Option.some({45- platform: `git.${Brand.domain}`,45+ platform: Brand.platformHost,46 web: Brand.domain,47 webAliases: [`www.${Brand.domain}`],48 })49 : Option.none();123 unmodified linesmodified:packages/agent-kit/src/docs/answer-an-ask.ts+2 added-2 removed
1 import { Brand } from "@repo/brand";2 3-import { installCommand, pushCommand } from "../install.ts";3+import { installCommand, loginCommand, pushCommand } from "../install.ts";4 import { code } from "../text.ts";5 import type { DocSource } from "./page.ts";6 import { cli, shell } from "./page.ts";7 2 unmodified lines10 export const answerAnAsk: DocSource = {11 body: ({ platformUrl, webUrl }) => [12 "## Install the CLI and sign in",13 "",14- ...shell(installCommand(webUrl), `${Brand.cli} login --url ${platformUrl}`),14+ ...shell(installCommand(webUrl), loginCommand(platformUrl)),15 "",16 "Signing in stores your token, and git uses it from then on through the CLI's credential helper: no token in a URL, and no prompt.",17 "",18 "## Find an ask",54 unmodified linesmodified:packages/agent-kit/src/agent-setup.ts+2 added-2 removed
2 unmodified lines3 import { groups } from "@repo/protocol/refusal";4 import { Array as Arr, Schema } from "effect";5 6 import type { CommandDoc } from "./command-doc.ts";7-import { installCommand } from "./install.ts";7+import { installCommand, loginCommand } from "./install.ts";8 import { mcpServersFor } from "./platform.ts";9 import { span } from "./sections.ts";10 import { code, listed, page, printJson, table } from "./text.ts";11 81 unmodified lines93 {94 label: "Sign in once; git pushes with your token from then on",95 language: "sh",96 name: "Sign in",97- text: `${Brand.cli} login --url ${platformUrl}`,97+ text: loginCommand(platformUrl),98 },99 ]100 : [];101 248 unmodified linesmodified:packages/agent-kit/src/agents-block.ts+1 added-1 removed
45 unmodified lines46 `## Contributing to ${project}`,47 "",48 `This project takes changes through ${Brand.name}: an answer to one of its asks lands only by passing the gate. This block is generated from the config folder, and the gate decides what lands. The full guide is the ${code(contributeSkillName(project))} skill (${code(agentsPath)}).`,49 "",50- `It needs the ${Brand.name} CLI (the install script on the platform's ${code("/install")} page) signed in with ${code(`${Brand.cli} login --url <platform>`)}, and runs in a clone of the project, ${code(`git clone <platform>/${project}.git`)}, where ${code("<platform>")} is the host this project lives on: in such a clone, ${code("git remote get-url origin")} names it.`,50+ `It needs the ${Brand.name} CLI (the install script on the platform's ${code("/install")} page) signed in with ${code(`${Brand.cli} login`)} (adding ${code("--url <platform>")} when that is not ${code(Brand.platformHost)}), and runs in a clone of the project, ${code(`git clone <platform>/${project}.git`)}, where ${code("<platform>")} is the host this project lives on: in such a clone, ${code("git remote get-url origin")} names it.`,51 "",52 ...loopSteps(),53 "",54 ...rules(policy),60 unmodified linesmodified:packages/agent-kit/src/command-doc.ts+2 added-1 removed
36 unmodified lines37 path: ["login"],38 positional: [],39 readOnly: false,40 source: "local",41- summary: "Sign in to a platform; git and this CLI then use its token.",41+ summary:42+ "Sign in (to the platform itself unless --url names another); git and this CLI then use its token.",43 },44 {45 flags: ["--profile", "--json"],46 needsApproval: false,197 unmodified linesmodified:packages/agent-kit/src/host-doc.ts+2 added-2 removed
4 unmodified lines5 import type { Posture } from "@repo/protocol/posture";6 import { Array as Arr, Option } from "effect";7 8 import type { CommandDoc } from "./command-doc.ts";9-import { installCommand, pushCommand } from "./install.ts";9+import { installCommand, loginCommand, pushCommand } from "./install.ts";10 11 type Command = CommandDoc;12 13 type Commands = readonly CommandDoc[];167 unmodified lines181 onSome: () => [182 "Then sign in once; git pushes to the platform with your token from then on:",183 "",184 "```sh",185- `${Brand.cli} login --url ${platformUrl}`,185+ loginCommand(platformUrl),186 "```",187 "",188 ],189 }),118 unmodified linesmodified:packages/agent-kit/src/install.ts+6 added
1 unmodified line2 3 export const installCommand = (webUrl: string) =>4 `curl -fsSL ${webUrl}/install.sh | sh`;5 6+/** Signing in: bare on the platform itself, which `login` defaults to; `--url` only for another. */7+export const loginCommand = (platformUrl: string) =>8+ platformUrl.replace(/\/+$/u, "") === Brand.platformUrl9+ ? `${Brand.cli} login`10+ : `${Brand.cli} login --url ${platformUrl}`;11+12 /** How an answer reaches its fork: the remote the claim's step names, then `main`. */13 export const pushCommand = `git push ${Brand.slug} HEAD:main`;modified:packages/agent-kit/test/golden/agents-block.txt+1 added-1 removed
2 unmodified lines3 ## Contributing to oscabriel/datekit4 5 This project takes changes through __NAME__: an answer to one of its asks lands only by passing the gate. This block is generated from the config folder, and the gate decides what lands. The full guide is the `datekit-contribute` skill (`.agents/skills/datekit-contribute/SKILL.md`).6 7-It needs the __NAME__ CLI (the install script on the platform's `/install` page) signed in with `__CLI__ login --url <platform>`, and runs in a clone of the project, `git clone <platform>/oscabriel/datekit.git`, where `<platform>` is the host this project lives on: in such a clone, `git remote get-url origin` names it.7+It needs the __NAME__ CLI (the install script on the platform's `/install` page) signed in with `__CLI__ login` (adding `--url <platform>` when that is not `git.__SLUG__.technology`), and runs in a clone of the project, `git clone <platform>/oscabriel/datekit.git`, where `<platform>` is the host this project lives on: in such a clone, `git remote get-url origin` names it.8 9 1. Read the ask, then claim it: `__CLI__ ask <ask>`, then `__CLI__ claim <ask>`. The claim prints your fork's remote; add it with `git remote add __SLUG__ <remote>`.10 2. Work inside the ask's territory until its check passes.11 3. Run `__CLI__ check`. It gives the refusals a push would get, then runs the ask's check and the project's lanes; fix everything it reports.14 unmodified linesmodified:packages/agent-kit/test/install-channels.test.ts+11 added
63 unmodified lines64 channels.flatMap(textsOf).filter((each) => /\bnpm install\b/u.test(each))65 ).toStrictEqual([]);66 });67 68+ it("sign in with a bare login on the platform itself, which login defaults to", () => {69+ expect(70+ textsOf(71+ channel(72+ "cli",73+ installChannels({ commands, platformUrl: Brand.platformUrl, webUrl })74+ )75+ )[1]76+ ).toBe(`${Brand.cli} login`);77+ });78+79 it("give Claude Code's settings.json a hook for each event the CLI answers, the edit tools guarded", () => {80 const hooks = channel("cli").snippets.find(({ name }) => name === "Hooks");81 82 expect(hooks?.language).toBe("json");111 unmodified linesmodified:packages/brand/src/index.ts+9 added-1 removed
1 const slug = "myr";2 3+const domain = `${slug}.technology`;4+5+// The platform's own host on prod: where the CLI signs in and reads when6+// nothing names another platform.7+const platformHost = `git.${domain}`;8+9 export const Brand = {10 cli: slug,11 cliPackage: `@${slug}/cli`,12 configDir: `.${slug}`,7- domain: `${slug}.technology`,13+ domain,14 gitCredentialHelper: `git-credential-${slug}`,15 gitRemoteHelper: `git-remote-${slug}`,16 githubOrg: `get${slug}`,17 name: "Myr",18 npmScope: `@${slug}`,19+ platformHost,20+ platformUrl: `https://${platformHost}`,21 refsPrefix: `refs/${slug}/`,22 slug,23 urlScheme: `${slug}://`,24 } as const;modified:packages/config/test/release.test.ts+3 added-3 removed
566 unmodified lines567 posix: true,568 });569 });570 571- it("ends by naming the next step, login on the brand's own platform host", () => {572- expect(script).toContain(`platform='https://git.${Brand.domain}'`);573- expect(script).toContain('echo "next: $name login --url $platform"');571+ it("ends by naming the next step, login, which signs in to the platform itself", () => {572+ expect(script).toContain('echo "next: $name login"');573+ expect(script).not.toContain("--url");574 });575 576 const install = (files: Readonly<Record<string, string>>) =>577 Effect.gen(function* () {169 unmodified linesmodified:scripts/lib/release/install-script.ts+1 added-2 removed
26 unmodified lines27 `base=${quoted(input.baseUrl)}`,28 `version=${quoted(input.version)}`,29 `slug=${quoted(brand.slug)}`,30 `name=${quoted(brand.cli)}`,31- `platform=${quoted(`https://git.${brand.domain}`)}`,31 `helper=${quoted(brand.gitCredentialHelper)}`,32 `dir="\${${installDir}:-$HOME/.local/bin}"`,33 "",34 "fail() {",51 unmodified lines86 'mv -f "$tmp/$asset" "$dir/$name"',87 'ln -sf "$name" "$dir/$helper"',88 "",89 'echo "installed $name $version as $dir/$name, with $helper beside it"',91- 'echo "next: $name login --url $platform"',90+ 'echo "next: $name login"',91 'case ":$PATH:" in',92 ' *":$dir:"*) ;;',93 ' *) echo "add $dir to your PATH to run $name" ;;',94 "esac",3 unmodified linesmodified:scripts/lib/release/readme.ts+1 added-1 removed
26 unmodified lines27 "",28 "## Start",29 "",30 ...fence([31- `${brand.cli} login --url <platform>`,31+ `${brand.cli} login # sign in; --url <platform> names another platform`,32 `${brand.cli} asks # list the open asks you could take`,33 `${brand.cli} claim <ask> # take one; you get a fork to push your answer to`,34 `${brand.cli} check # run the gate's checks locally before you push`,35 ]),21 unmodified linesmodified:README.md+1 added-1 removed
48 unmodified lines49 The CLI comes from the platform itself: the web at `https://myr.technology` serves the installer, and `myr login` signs you in to the platform at `https://git.myr.technology` through the browser and sets up git's credential helper, so plain `git clone` and `git push` work:50 51 ```sh52 curl -fsSL https://myr.technology/install.sh | sh53-myr login --url https://git.myr.technology53+myr login54 myr asks --project oscabriel/datekit55 myr claim <ask> --project oscabriel/datekit56 ```57 79 unmodified lines