fito-tui 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +2 -86
  2. package/package.json +8 -4
  3. package/prompts/fito-auth-refresh.md +3 -3
  4. package/prompts/fito-evaluate.md +10 -5
  5. package/prompts/fito-login.md +3 -3
  6. package/prompts/fito-logout.md +3 -3
  7. package/prompts/fito-push-knowledge.md +61 -65
  8. package/prompts/fito-submit.md +7 -2
  9. package/shared/competences/competence-list.js +1 -1
  10. package/shared/competences/competence-list.ts +1 -1
  11. package/shared/fito-api/README.md +1 -1
  12. package/shared/fito-api/client.js +7 -11
  13. package/shared/fito-api/client.ts +8 -12
  14. package/shared/fito-session/credentials.js +27 -15
  15. package/shared/fito-session/credentials.ts +33 -15
  16. package/shared/fito-session/session.js +7 -5
  17. package/shared/fito-session/session.ts +10 -7
  18. package/shared/fito-url/fito-url.js +29 -0
  19. package/shared/fito-url/fito-url.ts +32 -0
  20. package/shared/knowledge-components/knowledge-fetch.js +1 -1
  21. package/shared/knowledge-components/knowledge-fetch.ts +1 -1
  22. package/shared/knowledge-components/knowledge-search.js +1 -1
  23. package/shared/knowledge-components/knowledge-search.ts +1 -1
  24. package/shared/knowledge-components/technology-fetch.js +1 -1
  25. package/shared/knowledge-components/technology-fetch.ts +1 -1
  26. package/{skills/fito-case-author → shared/semver}/semver.js +8 -0
  27. package/{skills/fito-case-author → shared/semver}/semver.ts +9 -0
  28. package/skills/fito-auth/SKILL.md +12 -19
  29. package/skills/fito-auth/auth-refresh.js +3 -2
  30. package/skills/fito-auth/auth-refresh.ts +3 -2
  31. package/skills/fito-auth/login.js +7 -6
  32. package/skills/fito-auth/login.ts +7 -6
  33. package/skills/fito-auth/logout.js +3 -2
  34. package/skills/fito-auth/logout.ts +3 -2
  35. package/skills/fito-case-author/SKILL.md +1 -3
  36. package/skills/fito-case-author/publish-version.js +5 -5
  37. package/skills/fito-case-author/publish-version.ts +7 -7
  38. package/skills/fito-case-author/publish.js +5 -5
  39. package/skills/fito-case-author/publish.ts +7 -7
  40. package/skills/fito-case-runner/SKILL.md +10 -6
  41. package/skills/fito-case-runner/case-component-names.ts +1 -1
  42. package/skills/fito-case-runner/fito-url.js +8 -0
  43. package/skills/fito-case-runner/fito-url.ts +9 -0
  44. package/skills/fito-case-runner/open.ts +1 -1
  45. package/skills/fito-competence-write/SKILL.md +0 -6
  46. package/skills/fito-knowledge-push/SKILL.md +55 -76
  47. package/skills/fito-knowledge-push/push.js +169 -77
  48. package/skills/fito-knowledge-push/push.ts +210 -84
  49. package/skills/fito-source-ingestion/SKILL.md +0 -6
  50. package/skills/fito-source-ingestion/authoring-check.ts +1 -1
  51. package/skills/fito-technology-write/SKILL.md +0 -6
@@ -4,12 +4,15 @@ import * as path from "node:path";
4
4
 
5
5
  import { z } from "zod";
6
6
 
7
+ import { fitoUrl } from "../fito-url/fito-url.ts";
8
+
7
9
  /**
8
- * Persistent store for the TUI's backend credentials at `~/.fito/credentials`
9
- * (file mode `0600`, dir `0700`). Only token material and metadata are stored —
10
- * never a plaintext password (SPEC §841 / PLAN Task 1.5). Pure Node module (no pi
11
- * imports) so it is unit-testable without a pi runtime; `home` is injectable so
12
- * tests can point at a temp directory.
10
+ * Persistent store for the TUI's backend credentials, one file per Fito at
11
+ * `~/.fito/credentials-<host>` (file mode `0600`, dir `0700`). Only token material
12
+ * and metadata are stored — never a plaintext password (SPEC §841 / PLAN Task 1.5).
13
+ * Pure Node module (no pi imports) so it is unit-testable without a pi runtime;
14
+ * `home` and the Fito's address are injectable so tests can point at a temp
15
+ * directory and at any Fito.
13
16
  */
14
17
 
15
18
  /** The token pair + metadata persisted to disk. Mirrors the backend token response. */
@@ -24,14 +27,25 @@ export const credentialsSchema = z.object({
24
27
 
25
28
  export type Credentials = z.infer<typeof credentialsSchema>;
26
29
 
27
- /** The `~/.fito` directory that holds the credentials file. */
30
+ /** The `~/.fito` directory that holds the credentials files. */
28
31
  export function credentialsDir(home: string = os.homedir()): string {
29
32
  return path.join(home, ".fito");
30
33
  }
31
34
 
32
- /** The `~/.fito/credentials` file path. */
33
- export function credentialsPath(home: string = os.homedir()): string {
34
- return path.join(credentialsDir(home), "credentials");
35
+ /**
36
+ * The name of one Fito's credentials file: `credentials-<host>`, where `<host>` is the host of the
37
+ * Fito's address with its port, and a `:` is written as `-`, which every file system accepts
38
+ * (`credentials-localhost-8000`). Each Fito has its own file (Task 17.19), so a login to staging
39
+ * leaves the login to the development stack in place, and two sessions on two Fitos never write
40
+ * the same file.
41
+ */
42
+ export function credentialsFileName(url: string = fitoUrl()): string {
43
+ return `credentials-${new URL(url).host.replaceAll(":", "-")}`;
44
+ }
45
+
46
+ /** The `~/.fito/credentials-<host>` file path of the Fito at `url`. */
47
+ export function credentialsPath(home: string = os.homedir(), url: string = fitoUrl()): string {
48
+ return path.join(credentialsDir(home), credentialsFileName(url));
35
49
  }
36
50
 
37
51
  /**
@@ -40,12 +54,16 @@ export function credentialsPath(home: string = os.homedir()): string {
40
54
  * file is tightened (the `mode` option on `writeFileSync` is ignored when the file
41
55
  * already exists).
42
56
  */
43
- export function writeCredentials(credentials: Credentials, home: string = os.homedir()): void {
57
+ export function writeCredentials(
58
+ credentials: Credentials,
59
+ home: string = os.homedir(),
60
+ url: string = fitoUrl(),
61
+ ): void {
44
62
  const dir = credentialsDir(home);
45
63
  fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
46
64
  fs.chmodSync(dir, 0o700);
47
65
 
48
- const file = credentialsPath(home);
66
+ const file = credentialsPath(home, url);
49
67
  fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}\n`, { mode: 0o600 });
50
68
  fs.chmodSync(file, 0o600);
51
69
  }
@@ -56,8 +74,8 @@ export function writeCredentials(credentials: Credentials, home: string = os.hom
56
74
  * stale shape), so callers treat a corrupt store as "logged out" rather than
57
75
  * crashing.
58
76
  */
59
- export function readCredentials(home: string = os.homedir()): Credentials | null {
60
- const file = credentialsPath(home);
77
+ export function readCredentials(home: string = os.homedir(), url: string = fitoUrl()): Credentials | null {
78
+ const file = credentialsPath(home, url);
61
79
  let raw: string;
62
80
  try {
63
81
  raw = fs.readFileSync(file, "utf8");
@@ -69,8 +87,8 @@ export function readCredentials(home: string = os.homedir()): Credentials | null
69
87
  }
70
88
 
71
89
  /** Delete the credentials file. Returns `true` if a file was removed, `false` if absent. */
72
- export function deleteCredentials(home: string = os.homedir()): boolean {
73
- const file = credentialsPath(home);
90
+ export function deleteCredentials(home: string = os.homedir(), url: string = fitoUrl()): boolean {
91
+ const file = credentialsPath(home, url);
74
92
  try {
75
93
  fs.rmSync(file);
76
94
  return true;
@@ -1,16 +1,18 @@
1
1
  import { readCredentials, writeCredentials } from "./credentials.js";
2
+ import { fitoUrl } from "../fito-url/fito-url.js";
2
3
  /**
3
- * Resolve the learner's Fito session. Throws when no credentials are stored — a backend-writing flow
4
- * needs a logged-in session. Persists rotated tokens so the next call reuses them.
4
+ * Resolve the learner's session on the Fito at `url` — the one the client calls. Throws when no
5
+ * credentials are stored for it — a backend-writing flow needs a logged-in session. Persists rotated
6
+ * tokens so the next call reuses them.
5
7
  */
6
- export async function resolveFitoSession(client, home) {
7
- const credentials = readCredentials(home);
8
+ export async function resolveFitoSession(client, home, url = fitoUrl()) {
9
+ const credentials = readCredentials(home, url);
8
10
  if (!credentials) {
9
11
  throw new Error("You are not logged in to Fito. Run /fito-login first, then re-run this flow.");
10
12
  }
11
13
  const { user, tokens } = await client.meWithRefresh(credentials);
12
14
  if (tokens.accessToken !== credentials.accessToken || tokens.refreshToken !== credentials.refreshToken) {
13
- writeCredentials({ ...tokens, savedAt: new Date().toISOString() }, home);
15
+ writeCredentials({ ...tokens, savedAt: new Date().toISOString() }, home, url);
14
16
  }
15
17
  return { user, tokens };
16
18
  }
@@ -1,11 +1,12 @@
1
1
  import { readCredentials, writeCredentials } from "./credentials.ts";
2
2
  import type { FitoApiClient, SessionUser, TokenResponse } from "../fito-api/client.ts";
3
+ import { fitoUrl } from "../fito-url/fito-url.ts";
3
4
 
4
5
  /**
5
6
  * Resolving the learner's authenticated Fito session for a backend-writing TUI flow (submit, record
6
- * evaluation): read `~/.fito/credentials`, verify it via `GET /me` (refreshing the access token on a
7
- * 401 and persisting any rotated pair), and hand back the user plus the live tokens. The single place
8
- * both `fito-case-runner/submit.ts` and `submit-evaluation.ts` get a session, so the
7
+ * evaluation): read the Fito's `~/.fito/credentials-<host>`, verify it via `GET /me` (refreshing the
8
+ * access token on a 401 and persisting any rotated pair), and hand back the user plus the live tokens.
9
+ * The single place both `fito-case-runner/submit.ts` and `submit-evaluation.ts` get a session, so the
9
10
  * credentials→/me→persist sequence lives once.
10
11
  */
11
12
 
@@ -16,20 +17,22 @@ export interface FitoSession {
16
17
  }
17
18
 
18
19
  /**
19
- * Resolve the learner's Fito session. Throws when no credentials are stored — a backend-writing flow
20
- * needs a logged-in session. Persists rotated tokens so the next call reuses them.
20
+ * Resolve the learner's session on the Fito at `url` — the one the client calls. Throws when no
21
+ * credentials are stored for it — a backend-writing flow needs a logged-in session. Persists rotated
22
+ * tokens so the next call reuses them.
21
23
  */
22
24
  export async function resolveFitoSession(
23
25
  client: Pick<FitoApiClient, "meWithRefresh">,
24
26
  home: string,
27
+ url: string = fitoUrl(),
25
28
  ): Promise<FitoSession> {
26
- const credentials = readCredentials(home);
29
+ const credentials = readCredentials(home, url);
27
30
  if (!credentials) {
28
31
  throw new Error("You are not logged in to Fito. Run /fito-login first, then re-run this flow.");
29
32
  }
30
33
  const { user, tokens } = await client.meWithRefresh(credentials);
31
34
  if (tokens.accessToken !== credentials.accessToken || tokens.refreshToken !== credentials.refreshToken) {
32
- writeCredentials({ ...tokens, savedAt: new Date().toISOString() }, home);
35
+ writeCredentials({ ...tokens, savedAt: new Date().toISOString() }, home, url);
33
36
  }
34
37
  return { user, tokens };
35
38
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The address of the Fito this TUI uses — the one place in `tui/` that holds it (Task 15d.9a).
3
+ *
4
+ * A released TUI reaches the hosted Fito with nothing to set, so the address is built into the
5
+ * package. `FITO_URL` moves the TUI to another Fito: the development stack, or staging. One address
6
+ * serves both halves, because one door serves them in every environment (ADR-020): the web is at
7
+ * `<address>` and the API at `<address>/api`.
8
+ *
9
+ * A subject folder, not part of `fito-api/`: that folder maps API calls only, and the address also
10
+ * serves the login page and the links a script prints.
11
+ */
12
+ /**
13
+ * The hosted Fito. Every installed TUI holds this value, so a change of domain reaches a user only
14
+ * when that user updates; `fito-url.test.ts` pins it, so the change is never an accident.
15
+ */
16
+ const HOSTED_FITO_URL = "https://fito.codes";
17
+ /**
18
+ * The web's address: `FITO_URL`, or the hosted Fito when it is unset or empty. Trailing slashes are
19
+ * dropped, because the login's loopback server compares the browser's `Origin` with this value
20
+ * exactly (`skills/fito-auth/callback-server.ts`), and an `Origin` never ends in one.
21
+ */
22
+ export function fitoUrl(env = process.env) {
23
+ const chosen = (env.FITO_URL ?? "").replace(/\/+$/, "");
24
+ return chosen === "" ? HOSTED_FITO_URL : chosen;
25
+ }
26
+ /** The API's address: the proxy serves the backend under `/api`. */
27
+ export function fitoApiUrl(env = process.env) {
28
+ return `${fitoUrl(env)}/api`;
29
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The address of the Fito this TUI uses — the one place in `tui/` that holds it (Task 15d.9a).
3
+ *
4
+ * A released TUI reaches the hosted Fito with nothing to set, so the address is built into the
5
+ * package. `FITO_URL` moves the TUI to another Fito: the development stack, or staging. One address
6
+ * serves both halves, because one door serves them in every environment (ADR-020): the web is at
7
+ * `<address>` and the API at `<address>/api`.
8
+ *
9
+ * A subject folder, not part of `fito-api/`: that folder maps API calls only, and the address also
10
+ * serves the login page and the links a script prints.
11
+ */
12
+
13
+ /**
14
+ * The hosted Fito. Every installed TUI holds this value, so a change of domain reaches a user only
15
+ * when that user updates; `fito-url.test.ts` pins it, so the change is never an accident.
16
+ */
17
+ const HOSTED_FITO_URL = "https://fito.codes";
18
+
19
+ /**
20
+ * The web's address: `FITO_URL`, or the hosted Fito when it is unset or empty. Trailing slashes are
21
+ * dropped, because the login's loopback server compares the browser's `Origin` with this value
22
+ * exactly (`skills/fito-auth/callback-server.ts`), and an `Origin` never ends in one.
23
+ */
24
+ export function fitoUrl(env: Record<string, string | undefined> = process.env): string {
25
+ const chosen = (env.FITO_URL ?? "").replace(/\/+$/, "");
26
+ return chosen === "" ? HOSTED_FITO_URL : chosen;
27
+ }
28
+
29
+ /** The API's address: the proxy serves the backend under `/api`. */
30
+ export function fitoApiUrl(env: Record<string, string | undefined> = process.env): string {
31
+ return `${fitoUrl(env)}/api`;
32
+ }
@@ -16,7 +16,7 @@ import { parseKnowledgeReference } from "./reference.js";
16
16
  * `options.technologyVersion`, when present, scopes the read to one technology-version slug (9a.5d):
17
17
  * a component live only for another major line then surfaces as the same not-found `Error`, so a
18
18
  * version-aware caller never treats it as live. `options.client` keeps the HTTP boundary injectable
19
- * for tests; production calls create the shared client per invocation (reading `FITO_API_BASE_URL`)
19
+ * for tests; production calls create the shared client per invocation (reading `FITO_URL`)
20
20
  * and send no credentials because the read is public.
21
21
  *
22
22
  * It is named for the axis it filters, matching the wire and the transport client since Task
@@ -22,7 +22,7 @@ import { parseKnowledgeReference } from "./reference.ts";
22
22
  * `options.technologyVersion`, when present, scopes the read to one technology-version slug (9a.5d):
23
23
  * a component live only for another major line then surfaces as the same not-found `Error`, so a
24
24
  * version-aware caller never treats it as live. `options.client` keeps the HTTP boundary injectable
25
- * for tests; production calls create the shared client per invocation (reading `FITO_API_BASE_URL`)
25
+ * for tests; production calls create the shared client per invocation (reading `FITO_URL`)
26
26
  * and send no credentials because the read is public.
27
27
  *
28
28
  * It is named for the axis it filters, matching the wire and the transport client since Task
@@ -67,7 +67,7 @@ function tlDrOf(component) {
67
67
  * tool wrapper lets it propagate so pi marks the call as an error). Unlike its point-read siblings
68
68
  * there is no not-found case: an unknown technology is an empty list, because this is a search and
69
69
  * not an existence check. `options.client` keeps the HTTP boundary injectable for tests; production
70
- * calls create the shared client per invocation (reading `FITO_API_BASE_URL`) and send no
70
+ * calls create the shared client per invocation (reading `FITO_URL`) and send no
71
71
  * credentials because the read is public.
72
72
  */
73
73
  export async function searchKnowledgeComponents(technology, options = {}) {
@@ -102,7 +102,7 @@ function tlDrOf(component: KnowledgeSearchItem): string {
102
102
  * tool wrapper lets it propagate so pi marks the call as an error). Unlike its point-read siblings
103
103
  * there is no not-found case: an unknown technology is an empty list, because this is a search and
104
104
  * not an existence check. `options.client` keeps the HTTP boundary injectable for tests; production
105
- * calls create the shared client per invocation (reading `FITO_API_BASE_URL`) and send no
105
+ * calls create the shared client per invocation (reading `FITO_URL`) and send no
106
106
  * credentials because the read is public.
107
107
  */
108
108
  export async function searchKnowledgeComponents(
@@ -10,7 +10,7 @@ import { FitoApiError, createFitoApiClient, } from "../fito-api/client.js";
10
10
  * Throws a plain `Error` (clear message) on a 404 (no such technology) or any other backend
11
11
  * failure — callers surface `error.message` (the tool wrapper lets it propagate so pi marks the
12
12
  * call as an error). `options.client` keeps the HTTP boundary injectable for tests; production
13
- * calls create the shared client per invocation (reading `FITO_API_BASE_URL`) and send no
13
+ * calls create the shared client per invocation (reading `FITO_URL`) and send no
14
14
  * credentials because the read is public.
15
15
  */
16
16
  export async function fetchTechnology(slug, options = {}) {
@@ -16,7 +16,7 @@ import {
16
16
  * Throws a plain `Error` (clear message) on a 404 (no such technology) or any other backend
17
17
  * failure — callers surface `error.message` (the tool wrapper lets it propagate so pi marks the
18
18
  * call as an error). `options.client` keeps the HTTP boundary injectable for tests; production
19
- * calls create the shared client per invocation (reading `FITO_API_BASE_URL`) and send no
19
+ * calls create the shared client per invocation (reading `FITO_URL`) and send no
20
20
  * credentials because the read is public.
21
21
  */
22
22
  export async function fetchTechnology(
@@ -4,6 +4,10 @@
4
4
  * 422 refuse exactly the same version bumps. The guard matters locally because the push precedes
5
5
  * the API call: the current version is always the chain's maximum, so a strictly-greater new
6
6
  * version is guaranteed not to collide with (and force-move) any published frozen ref.
7
+ *
8
+ * The knowledge push uses the same grammar and precedence for a supersede's revision label, which
9
+ * must be newer than the revision it replaces. Shared here because a skill cannot import another
10
+ * skill's files.
7
11
  */
8
12
  /** SemVer 2.0.0 grammar with capture groups: major, minor, patch, optional pre-release (build metadata matched, ignored). */
9
13
  const SEMVER_GRAMMAR = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
@@ -28,6 +32,10 @@ function compareIdentifiers(a, b) {
28
32
  return aNumeric ? -1 : 1;
29
33
  return a < b ? -1 : a > b ? 1 : 0;
30
34
  }
35
+ /** Whether [version] is a SemVer 2.0.0 string — the precondition of every comparison below. */
36
+ export function isSemVer(version) {
37
+ return SEMVER_GRAMMAR.test(version);
38
+ }
31
39
  /** SemVer 2.0.0 precedence: negative when `a < b`, zero when equal (build metadata ignored), positive when `a > b`. */
32
40
  export function compareSemVerPrecedence(a, b) {
33
41
  const left = parseSemVer(a);
@@ -4,6 +4,10 @@
4
4
  * 422 refuse exactly the same version bumps. The guard matters locally because the push precedes
5
5
  * the API call: the current version is always the chain's maximum, so a strictly-greater new
6
6
  * version is guaranteed not to collide with (and force-move) any published frozen ref.
7
+ *
8
+ * The knowledge push uses the same grammar and precedence for a supersede's revision label, which
9
+ * must be newer than the revision it replaces. Shared here because a skill cannot import another
10
+ * skill's files.
7
11
  */
8
12
 
9
13
  /** SemVer 2.0.0 grammar with capture groups: major, minor, patch, optional pre-release (build metadata matched, ignored). */
@@ -37,6 +41,11 @@ function compareIdentifiers(a: string, b: string): number {
37
41
  return a < b ? -1 : a > b ? 1 : 0;
38
42
  }
39
43
 
44
+ /** Whether [version] is a SemVer 2.0.0 string — the precondition of every comparison below. */
45
+ export function isSemVer(version: string): boolean {
46
+ return SEMVER_GRAMMAR.test(version);
47
+ }
48
+
40
49
  /** SemVer 2.0.0 precedence: negative when `a < b`, zero when equal (build metadata ignored), positive when `a > b`. */
41
50
  export function compareSemVerPrecedence(a: string, b: string): number {
42
51
  const left = parseSemVer(a);
@@ -9,31 +9,24 @@ allowed-tools: bash
9
9
 
10
10
  # Fito Auth
11
11
 
12
- Handles the browser-based login handoff and the `~/.fito/credentials` token store
13
- (file mode `0600`, dir `0700`). Backend access goes through the `fito-api` client
14
- (ADR-003); this skill never sees a password — the browser performs the login and
15
- hands back only the token pair.
12
+ Handles the browser-based login handoff and the token store: one credentials file
13
+ per Fito, `~/.fito/credentials-<host>` (file mode `0600`, dir `0700`). Backend
14
+ access goes through the `fito-api` client (ADR-003); this skill never sees a
15
+ password — the browser performs the login and hands back only the token pair.
16
16
 
17
17
  Run the commands from wherever you are — each one below names this
18
18
  skill's directory itself.
19
19
 
20
- ## Configuration
21
-
22
- | Env var | Default | Purpose |
23
- |---|---|---|
24
- | `FITO_WEB_ORIGIN` | `http://localhost:5173` | Web origin hosting the login page |
25
- | `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin (used by logout/refresh) |
26
-
27
20
  ## Log in
28
21
 
29
22
  ```bash
30
23
  node <fito-auth skill dir>/login.js
31
24
  ```
32
25
 
33
- Starts a loopback server on an ephemeral port, opens the system browser to
34
- `<FITO_WEB_ORIGIN>/auth/login?return_to=tui&port=<port>`, and waits for the
35
- browser to POST the freshly minted token pair back. On success it writes
36
- `~/.fito/credentials` and prints a confirmation. The learner can complete either
26
+ Starts a loopback server on an ephemeral port, opens the system browser to Fito's
27
+ `/auth/login?return_to=tui&port=<port>` page, and waits for the browser to POST the
28
+ freshly minted token pair back. On success it writes this Fito's credentials file
29
+ and prints a confirmation that names it. The learner can complete either
37
30
  auth flow (email/password or "Continue with GitHub") in the browser.
38
31
 
39
32
  ## Log out
@@ -42,8 +35,8 @@ auth flow (email/password or "Continue with GitHub") in the browser.
42
35
  node <fito-auth skill dir>/logout.js
43
36
  ```
44
37
 
45
- Best-effort revokes the refresh token server-side, then deletes
46
- `~/.fito/credentials`. Idempotent — succeeds even when not logged in.
38
+ Best-effort revokes the refresh token server-side, then deletes this Fito's
39
+ credentials file. Idempotent — succeeds even when not logged in.
47
40
 
48
41
  ## Refresh
49
42
 
@@ -52,7 +45,7 @@ node <fito-auth skill dir>/auth-refresh.js
52
45
  ```
53
46
 
54
47
  Exchanges the stored refresh token for a fresh token pair via `POST /auth/refresh`
55
- and rewrites `~/.fito/credentials`. Fails if not logged in.
48
+ and rewrites this Fito's credentials file. Fails if not logged in.
56
49
 
57
50
  ## Files
58
51
 
@@ -62,7 +55,7 @@ and rewrites `~/.fito/credentials`. Fails if not logged in.
62
55
  | `browser.ts` | Per-platform system-browser launcher |
63
56
  | `login.ts` / `logout.ts` / `auth-refresh.ts` | CLI entrypoints (above) |
64
57
 
65
- The `~/.fito/credentials` store (read/write/delete, `0600`, Zod-validated) lives in the
58
+ The credentials store (read/write/delete, `0600`, Zod-validated) lives in the
66
59
  shared [`fito-session`](../../shared/fito-session/credentials.ts) module, reused by `fito-case-runner`.
67
60
 
68
61
  See [the fito-api client](../../shared/fito-api/README.md) for how backend calls are made.
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `/fito-auth-refresh` CLI entrypoint. Exchanges the stored refresh token for a
3
- * fresh token pair via the backend and rewrites `~/.fito/credentials`. Run from
4
- * this skill's directory: `node auth-refresh.js`.
3
+ * fresh token pair via the backend and rewrites this Fito's
4
+ * `~/.fito/credentials-<host>`. Run from this skill's directory:
5
+ * `node auth-refresh.js`.
5
6
  */
6
7
  import { createFitoApiClient } from "../../shared/fito-api/client.js";
7
8
  import { readCredentials, writeCredentials } from "../../shared/fito-session/credentials.js";
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `/fito-auth-refresh` CLI entrypoint. Exchanges the stored refresh token for a
3
- * fresh token pair via the backend and rewrites `~/.fito/credentials`. Run from
4
- * this skill's directory: `node auth-refresh.js`.
3
+ * fresh token pair via the backend and rewrites this Fito's
4
+ * `~/.fito/credentials-<host>`. Run from this skill's directory:
5
+ * `node auth-refresh.js`.
5
6
  */
6
7
  import { createFitoApiClient } from "../../shared/fito-api/client.ts";
7
8
  import { type Credentials, readCredentials, writeCredentials } from "../../shared/fito-session/credentials.ts";
@@ -1,15 +1,16 @@
1
1
  /**
2
2
  * `/fito-login` CLI entrypoint. Starts a loopback server, opens the system
3
3
  * browser to the web `/auth/login?return_to=tui&port=<port>` page, waits for the
4
- * browser to POST the freshly minted token pair back, and writes it to
5
- * `~/.fito/credentials` (0600). Run from this skill's directory: `node login.js`.
4
+ * browser to POST the freshly minted token pair back, and writes it to this Fito's
5
+ * `~/.fito/credentials-<host>` (0600). Run from this skill's directory: `node login.js`.
6
6
  */
7
7
  import * as crypto from "node:crypto";
8
8
  import { openBrowser } from "./browser.js";
9
9
  import { startCallbackServer } from "./callback-server.js";
10
- import { writeCredentials } from "../../shared/fito-session/credentials.js";
11
- /** Web origin hosting the login page; overridable via `FITO_WEB_ORIGIN`. */
12
- const WEB_ORIGIN = process.env.FITO_WEB_ORIGIN ?? "http://localhost:5173";
10
+ import { credentialsFileName, writeCredentials } from "../../shared/fito-session/credentials.js";
11
+ import { fitoUrl } from "../../shared/fito-url/fito-url.js";
12
+ /** Web origin hosting the login page: the address of the Fito this TUI uses. */
13
+ const WEB_ORIGIN = fitoUrl();
13
14
  /** How long to wait for the browser handoff before giving up. */
14
15
  const TIMEOUT_MS = 5 * 60 * 1000;
15
16
  async function main() {
@@ -25,7 +26,7 @@ async function main() {
25
26
  const tokens = await server.waitForTokens();
26
27
  const credentials = { ...tokens, savedAt: new Date().toISOString() };
27
28
  writeCredentials(credentials);
28
- console.log("✓ Logged in. Credentials saved to ~/.fito/credentials (mode 0600).");
29
+ console.log(`✓ Logged in. Credentials saved to ~/.fito/${credentialsFileName()} (mode 0600).`);
29
30
  }
30
31
  finally {
31
32
  server.close();
@@ -1,17 +1,18 @@
1
1
  /**
2
2
  * `/fito-login` CLI entrypoint. Starts a loopback server, opens the system
3
3
  * browser to the web `/auth/login?return_to=tui&port=<port>` page, waits for the
4
- * browser to POST the freshly minted token pair back, and writes it to
5
- * `~/.fito/credentials` (0600). Run from this skill's directory: `node login.js`.
4
+ * browser to POST the freshly minted token pair back, and writes it to this Fito's
5
+ * `~/.fito/credentials-<host>` (0600). Run from this skill's directory: `node login.js`.
6
6
  */
7
7
  import * as crypto from "node:crypto";
8
8
 
9
9
  import { openBrowser } from "./browser.ts";
10
10
  import { startCallbackServer } from "./callback-server.ts";
11
- import { type Credentials, writeCredentials } from "../../shared/fito-session/credentials.ts";
11
+ import { type Credentials, credentialsFileName, writeCredentials } from "../../shared/fito-session/credentials.ts";
12
+ import { fitoUrl } from "../../shared/fito-url/fito-url.ts";
12
13
 
13
- /** Web origin hosting the login page; overridable via `FITO_WEB_ORIGIN`. */
14
- const WEB_ORIGIN = process.env.FITO_WEB_ORIGIN ?? "http://localhost:5173";
14
+ /** Web origin hosting the login page: the address of the Fito this TUI uses. */
15
+ const WEB_ORIGIN = fitoUrl();
15
16
  /** How long to wait for the browser handoff before giving up. */
16
17
  const TIMEOUT_MS = 5 * 60 * 1000;
17
18
 
@@ -30,7 +31,7 @@ async function main(): Promise<void> {
30
31
  const tokens = await server.waitForTokens();
31
32
  const credentials: Credentials = { ...tokens, savedAt: new Date().toISOString() };
32
33
  writeCredentials(credentials);
33
- console.log("✓ Logged in. Credentials saved to ~/.fito/credentials (mode 0600).");
34
+ console.log(`✓ Logged in. Credentials saved to ~/.fito/${credentialsFileName()} (mode 0600).`);
34
35
  } finally {
35
36
  server.close();
36
37
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `/fito-logout` CLI entrypoint. Best-effort revokes the refresh token
3
- * server-side, then deletes `~/.fito/credentials`. Idempotent: succeeds even when
4
- * no credentials are present. Run from this skill's directory: `node logout.js`.
3
+ * server-side, then deletes this Fito's `~/.fito/credentials-<host>`.
4
+ * Idempotent: succeeds even when no credentials are present. Run from this
5
+ * skill's directory: `node logout.js`.
5
6
  */
6
7
  import { createFitoApiClient } from "../../shared/fito-api/client.js";
7
8
  import { deleteCredentials, readCredentials } from "../../shared/fito-session/credentials.js";
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * `/fito-logout` CLI entrypoint. Best-effort revokes the refresh token
3
- * server-side, then deletes `~/.fito/credentials`. Idempotent: succeeds even when
4
- * no credentials are present. Run from this skill's directory: `node logout.js`.
3
+ * server-side, then deletes this Fito's `~/.fito/credentials-<host>`.
4
+ * Idempotent: succeeds even when no credentials are present. Run from this
5
+ * skill's directory: `node logout.js`.
5
6
  */
6
7
  import { createFitoApiClient } from "../../shared/fito-api/client.ts";
7
8
  import { deleteCredentials, readCredentials } from "../../shared/fito-session/credentials.ts";
@@ -156,9 +156,7 @@ registrations — it never guesses which case the checkout is).
156
156
 
157
157
  | Env var | Default | Purpose |
158
158
  |---|---|---|
159
- | `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin (registry writes + session) |
160
159
  | `FITO_PUBLISH_GITHUB_OWNER` | *(unset — falls back to the `gh` login)* | Default repo owner (e.g. an org) for a bare `--repo <name>` |
161
- | `FITO_WEB_ORIGIN` | `http://localhost:5173` | The web origin used in the printed case URL |
162
160
 
163
161
  ## Files
164
162
 
@@ -170,10 +168,10 @@ registrations — it never guesses which case the checkout is).
170
168
  | `publish-version.ts` | CLI entrypoint — `runPublishVersion` core: validate → staleness guards → origin route → frozen-set preflight → push → `POST /cases/{id}/versions`; `--probe` resolves initial vs update |
171
169
  | `publish-payload.ts` | Pure `.case/` → register/publish/version wire-payload mapping (+ publish facts) |
172
170
  | `github-publish.ts` | Pure `gh`/`git` command builders (repo create, explicit-refspec push, guards) |
173
- | `semver.ts` | SemVer 2.0.0 precedence — the strictly-greater pre-push guard (mirrors the backend `SemVerPrecedence`) |
174
171
  | `status-gate.ts` | One home for the case-status policy (ADR-009): the status → allow/refuse/hint mapping behind `checkout.ts`, `runPublishVersion`, and the probe's deprecated route |
175
172
  | `publish-state.ts` | `~/.fito/publish-state.json` — the draft-id retry store |
176
173
  | — | The real `gh`/`git` executor is the shared `../../shared/shell-exec/exec.ts` (ADR-006) |
174
+ | — | The strictly-greater SemVer guard is the shared `../../shared/semver/semver.ts` (mirrors the backend `SemVerPrecedence`) |
177
175
 
178
176
  See [the `.case/` validator](../../shared/case-validation/) for the ruleset itself and
179
177
  [the fito-api client](../../shared/fito-api/README.md) for the registry endpoints.
@@ -31,11 +31,12 @@ import { fileURLToPath } from "node:url";
31
31
  import { manifestSchema } from "../../shared/case-validation/case-schema.js";
32
32
  import { FitoApiError, createFitoApiClient } from "../../shared/fito-api/client.js";
33
33
  import { resolveFitoSession } from "../../shared/fito-session/session.js";
34
+ import { fitoApiUrl, fitoUrl } from "../../shared/fito-url/fito-url.js";
34
35
  import { parseGithubUrl } from "../../shared/github-url/parse.js";
35
36
  import { gitFetchOriginTagsCommand, gitListLocalBranchCommand, gitPushCaseRefsCommand, gitStatusPorcelainCommand, withoutAuthoringHarnessPaths, } from "./github-publish.js";
36
37
  import { buildCaseVersionPayload, readCasePublishFacts } from "./publish-payload.js";
37
38
  import { PublishRejectedError, reconcileSolutionBranchCase, validateOrThrow } from "./publish.js";
38
- import { isStrictlyGreaterSemVer } from "./semver.js";
39
+ import { isStrictlyGreaterSemVer } from "../../shared/semver/semver.js";
39
40
  import { deprecatedRefusal, gateStatus } from "./status-gate.js";
40
41
  /** `git remote get-url origin` — the checkout's origin URL (the authoring-check mechanism, duplicated per ADR-006's single-skill corollary). */
41
42
  export function gitOriginUrlCommand() {
@@ -115,7 +116,7 @@ export async function runPublishVersion(options) {
115
116
  const caseDir = path.resolve(options.caseDir);
116
117
  const home = options.home ?? os.homedir();
117
118
  const env = options.env ?? process.env;
118
- const client = options.client ?? createFitoApiClient();
119
+ const client = options.client ?? createFitoApiClient({ baseUrl: fitoApiUrl(env) });
119
120
  const exec = options.exec ?? (await import("../../shared/shell-exec/exec.js")).shellExec;
120
121
  const run = (command) => exec(command, { cwd: caseDir });
121
122
  if (!existsSync(path.join(caseDir, ".case"))) {
@@ -165,7 +166,7 @@ export async function runPublishVersion(options) {
165
166
  throw new Error(`${origin.reason}.\nThis directory is an initial publish, not an update — run /fito-publish-case's ` +
166
167
  "initial path (publish.js) instead.");
167
168
  }
168
- const session = await resolveFitoSession(client, home);
169
+ const session = await resolveFitoSession(client, home, fitoUrl(env));
169
170
  const detail = await client.getCase(origin.caseId, session.tokens.accessToken);
170
171
  gateStatus(detail, "publishVersion");
171
172
  // The strictly-greater guard, before the push: the current version is the chain's maximum, so a
@@ -199,7 +200,6 @@ export async function runPublishVersion(options) {
199
200
  // here, after the POST, rather than after the push: before the POST a failure tells the author to
200
201
  // re-run, and a re-run re-cuts the same unregistered refs, so refreshing them would be noise.
201
202
  const refreshWarning = await refreshLocalRepoView(run);
202
- const webOrigin = env.FITO_WEB_ORIGIN ?? "http://localhost:5173";
203
203
  return {
204
204
  caseId: response.id,
205
205
  status: response.status,
@@ -209,7 +209,7 @@ export async function runPublishVersion(options) {
209
209
  versionRef: response.versionRef,
210
210
  caseReconciled,
211
211
  title: facts.title,
212
- webUrl: `${webOrigin}/cases/${response.id}`,
212
+ webUrl: `${fitoUrl(env)}/cases/${response.id}`,
213
213
  ...(refreshWarning === undefined ? {} : { refreshWarning }),
214
214
  };
215
215
  }