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
package/README.md CHANGED
@@ -1,88 +1,4 @@
1
1
  # Fito TUI
2
2
 
3
- Fito is case-based practice for software engineers. You work a code case in your own terminal,
4
- a tutor answers your questions about it, and Fito scores what you did against the knowledge the
5
- case teaches. This package brings Fito into [pi](https://github.com/earendil-works/pi), a
6
- coding agent that runs in your terminal.
7
-
8
- The tutor and the scoring run in pi, on your own LLM subscription. The Fito server holds no LLM
9
- key and makes no model call.
10
-
11
- ## Prerequisites
12
-
13
- - **Node.js 24 or newer.**
14
- - **pi.** The command is `pi`, from the npm package `@earendil-works/pi-coding-agent`:
15
-
16
- ```bash
17
- npm i -g @earendil-works/pi-coding-agent
18
- ```
19
-
20
- - **The `pi-subagents` package**, which the tutor and the scoring run through:
21
-
22
- ```bash
23
- pi install npm:pi-subagents
24
- ```
25
-
26
- - **`git`, and `gh` authenticated** with the GitHub account you use for Fito. Fito forks each
27
- case to that account and opens your submission pull request there:
28
-
29
- ```bash
30
- gh auth login
31
- ```
32
-
33
- - **An LLM provider in pi**, for the tutor and the scoring. Start `pi`, run `/login`, and
34
- select your provider. Installing Fito needs no provider.
35
-
36
- ## Install
37
-
38
- ```bash
39
- pi install npm:fito-tui
40
- ```
41
-
42
- Fito then loads in every pi session, in any folder. To turn it off without removing it, run
43
- `pi config`.
44
-
45
- When a new version of Fito is out, pi tells you as it starts. To update:
46
-
47
- ```bash
48
- pi update --extensions
49
- ```
50
-
51
- ## Move off a clone install
52
-
53
- If you installed Fito earlier from a clone of its repository, remove that install before you
54
- install from npm. With both, pi loads Fito twice and fails with
55
- `Tool "fito_knowledge_fetch" conflicts with …`.
56
-
57
- 1. To find the clone install and its path, run `pi list` in the folder you installed it from.
58
- 2. Remove it. Replace `PATH` with the path that `pi list` shows:
59
- - For an install made with `pi install -l`, run this in the same folder:
60
-
61
- ```bash
62
- pi remove -l PATH
63
- ```
64
-
65
- If pi answers `Project is not trusted`, add `--approve`.
66
-
67
- - For any other install:
68
-
69
- ```bash
70
- pi remove PATH
71
- ```
72
-
73
- 3. Install from npm, as in [Install](#install).
74
-
75
- ## Log in
76
-
77
- Start pi in any folder, and run:
78
-
79
- ```text
80
- /fito-login
81
- ```
82
-
83
- It opens your browser to sign in, and stores your tokens in `~/.fito/credentials`.
84
-
85
- ## Attribution
86
-
87
- Fito needs [`pi-subagents`](https://github.com/nicobailon/pi-subagents), by Nico Bailon, under
88
- the MIT license. You install it separately, as in [Prerequisites](#prerequisites).
3
+ - **To use Fito**, read the [Fito user guide](https://docs.fito.codes/).
4
+ - **To develop this package**, read [`README-DEV.md`](README-DEV.md). This link works on GitHub only.
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "fito-tui",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Fito for pi: case-based practice for software engineers, in your terminal.",
5
+ "keywords": [
6
+ "pi-package"
7
+ ],
8
+ "homepage": "https://docs.fito.codes/",
5
9
  "license": "UNLICENSED",
6
10
  "type": "module",
7
11
  "files": [
@@ -22,8 +26,8 @@
22
26
  "build": "tsc -p tsconfig.build.json",
23
27
  "lint": "tsc --noEmit && npm run build",
24
28
  "prepare": "npm run build",
25
- "test": "node --test agents/*.test.ts extensions/*.test.ts prompts/*.test.ts skills/*/*.test.ts shared/*/*.test.ts",
26
- "test:coverage": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=tap --test-reporter-destination=tui-tap.txt --test-reporter=lcov --test-reporter-destination=lcov.info agents/*.test.ts extensions/*.test.ts prompts/*.test.ts skills/*/*.test.ts shared/*/*.test.ts"
29
+ "test": "FITO_URL=http://127.0.0.1:9 node --test agents/*.test.ts extensions/*.test.ts prompts/*.test.ts skills/*/*.test.ts shared/*/*.test.ts",
30
+ "test:coverage": "FITO_URL=http://127.0.0.1:9 node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=tap --test-reporter-destination=tui-tap.txt --test-reporter=lcov --test-reporter-destination=lcov.info agents/*.test.ts extensions/*.test.ts prompts/*.test.ts skills/*/*.test.ts shared/*/*.test.ts"
27
31
  },
28
32
  "dependencies": {
29
33
  "yaml": "2.9.0",
@@ -50,7 +54,7 @@
50
54
  },
51
55
  "devDependencies": {
52
56
  "@types/node": "^24.13.2",
53
- "typebox": "1.1.38",
57
+ "typebox": "1.3.27",
54
58
  "typescript": "6.0.3"
55
59
  }
56
60
  }
@@ -10,6 +10,6 @@ node <fito-auth skill dir>/auth-refresh.js
10
10
  ```
11
11
 
12
12
  This exchanges the stored refresh token for a fresh token pair via the backend
13
- and rewrites `~/.fito/credentials`. If the learner is not logged in, it reports
14
- that and exits non-zero — in that case suggest running `/fito-login`. Report the
15
- result.
13
+ and rewrites this Fito's `~/.fito/credentials-<host>`. If the learner is not
14
+ logged in, it reports that and exits non-zero — in that case suggest running
15
+ `/fito-login`. Report the result.
@@ -74,16 +74,21 @@ preview — name resolution is additive. Relay the summary with the bare compone
74
74
  instead, and add a brief note that the component names could not be resolved (the
75
75
  backend may be unavailable).
76
76
 
77
+ Get Fito's address, for the links in the summary:
78
+
79
+ ```bash
80
+ node <fito-case-runner skill dir>/fito-url.js
81
+ ```
82
+
77
83
  Then relay the subagent's **learner-facing summary** — one block per criterion: the
78
84
  criterion, its knowledge component **labeled by name** (replace the bare
79
85
  `knowledgeComponent` id with its label from the map; fall back to the id if absent),
80
86
  its Bloom level, the score (`<n>/3` + label), the proficiency the score maps to, the
81
87
  `/knowledge/...` link, and the one-sentence justification. Make each link clickable by
82
- prefixing it with the web origin — read `$FITO_WEB_ORIGIN` (`echo $FITO_WEB_ORIGIN`),
83
- falling back to `http://localhost:5173` if it is unset. Because this is a preview,
84
- frame the proficiency as **what a submission would record** — not as already on their
85
- profile. Where an `automated` criterion scored below 3, surface the captured
86
- stdout/stderr from the report so the learner sees **why**.
88
+ prefixing it with Fito's address. Because this is a preview, frame the proficiency as
89
+ **what a submission would record** — not as already on their profile. Where an
90
+ `automated` criterion scored below 3, surface the captured stdout/stderr from the
91
+ report so the learner sees **why**.
87
92
 
88
93
  If any criterion came back as **needs human review** (a `human` evaluation
89
94
  method), tell the learner it can't be scored locally and needs a human reviewer —
@@ -11,9 +11,9 @@ node <fito-auth skill dir>/login.js
11
11
 
12
12
  This starts a local loopback server, opens the system browser to the Fito web
13
13
  login page (`/auth/login?return_to=tui&port=<port>`), and waits for the browser
14
- to hand back the freshly minted token pair, which it writes to
15
- `~/.fito/credentials` (mode `0600`). The learner can use either email/password or
16
- "Continue with GitHub" in the browser.
14
+ to hand back the freshly minted token pair, which it writes to this Fito's own
15
+ file, `~/.fito/credentials-<host>` (mode `0600`). The learner can use either
16
+ email/password or "Continue with GitHub" in the browser.
17
17
 
18
18
  Stream the command output so the learner sees the login URL (in case the browser
19
19
  does not open automatically). When it prints the success line, confirm they are
@@ -9,6 +9,6 @@ Use the `fito-auth` skill (read its `SKILL.md`), then run:
9
9
  node <fito-auth skill dir>/logout.js
10
10
  ```
11
11
 
12
- This best-effort revokes the refresh token on the backend and deletes
13
- `~/.fito/credentials`. It is idempotent — it succeeds even if the learner was not
14
- logged in. Report the result.
12
+ This best-effort revokes the refresh token on the backend and deletes this
13
+ Fito's `~/.fito/credentials-<host>`. It is idempotent — it succeeds even if the
14
+ learner was not logged in. Report the result.
@@ -1,84 +1,80 @@
1
1
  ---
2
- description: Push generated knowledge components to the backend Knowledge Repository, resolving near-duplicates with the author
3
- argument-hint: "[payload-dir-or-files]"
2
+ description: Store your generated knowledge components in Fito, and decide what happens to similar or duplicate ones
3
+ argument-hint: "[folder-or-files]"
4
4
  ---
5
- The author wants to push generated knowledge-component payloads to the backend Knowledge
6
- Repository — the PUSH step of the Fito knowledge pipeline, after `/fito-generate-*` produced
7
- them. Drive the whole flow below with the `fito-knowledge-push` skill (read its `SKILL.md`).
5
+ The author wants to store generated knowledge components in Fito — the last step of the Fito
6
+ knowledge pipeline, after `/fito-generate-*` wrote the component files. Drive the whole flow below
7
+ with the `fito-knowledge-push` skill (read its `SKILL.md`).
8
8
 
9
- ## 1. Resolve the payloads
9
+ ## Talking to the author
10
10
 
11
- Take the payload files from `$ARGUMENTS`: each argument is a payload file or a directory of
12
- them (collect `*.json` inside, non-recursive). With no arguments, default to the generate
13
- stage's output — every `*.json` under `./output/3-generate/*/` (the
14
- `concept_content/`, `execution_fact_content/`, and `usage_scenario_content/` directories).
11
+ Every message the push script prints for the author ends at the line
12
+ `--- Commands for the agent ---`. Show the author everything above that line **word for word**,
13
+ then ask with exactly the choices it lists. The commands below the line are yours to run: run the
14
+ one that matches the author's choice, and when it holds `<label>`, put the author's answer there.
15
15
 
16
- If no payload files are found, stop and tell the author:
16
+ In your own sentences, use the words the messages use: a **component file**, a **similar
17
+ component**, a **duplicate**, a **revision**, a **reference id**. Name a file the way the messages
18
+ do — by its component's name and its file name.
17
19
 
18
- > "No generated payloads found under `<path>`. Run `/fito-generate-domain-concepts`,
19
- > `/fito-generate-execution-facts`, or `/fito-generate-usage-scenarios` first, or pass the
20
- > payload directory: `/fito-push-knowledge <payload-dir-or-files>`"
20
+ ## 1. Find the component files
21
21
 
22
- List the resolved files and their count before pushing so the author sees what is about to
23
- be pushed. Pushing requires a Fito login — if a push fails with the not-logged-in message,
24
- relay it: run `/fito-login`, then re-run `/fito-push-knowledge`.
22
+ Take the component files from `$ARGUMENTS`: each argument is a component file or a folder of them
23
+ (collect `*.json` inside, non-recursive). With no arguments, default to the generate stage's
24
+ output — every `*.json` under `./output/3-generate/*/` (the `concept_content/`,
25
+ `execution_fact_content/`, and `usage_scenario_content/` folders).
25
26
 
26
- ## 2. Push one payload at a time
27
+ If no component files are found, stop and tell the author:
27
28
 
28
- **Payloads are read-only.** Never edit, overwrite, or regenerate a payload file by any means —
29
- editor, `python3`, shell redirection — for any reason: not to force a name match, not to fix a
30
- validation error, not to satisfy a resolution. When a payload looks wrong, surface the problem
31
- to the author and stop; the fix is the author's call (usually regenerating with the generator
32
- prompt, then pushing fresh). *(A pipeline run saw a worker patch `metadata.name` on disk to
29
+ > "No generated component files found in `<path>`. Run `/fito-generate-domain-concepts`,
30
+ > `/fito-generate-execution-facts`, or `/fito-generate-usage-scenarios` first, or name the
31
+ > folder: `/fito-push-knowledge <folder-or-files>`"
32
+
33
+ List the files and their count before storing anything, so the author sees what is about to be
34
+ stored. Storing requires a Fito login — if a push fails with the not-logged-in message, relay it:
35
+ run `/fito-login`, then re-run `/fito-push-knowledge`.
36
+
37
+ ## 2. Store one component file at a time
38
+
39
+ **Component files are read-only.** Never edit, overwrite, or regenerate a component file by any
40
+ means — editor, `python3`, shell redirection — for any reason: not to force a name match, not to
41
+ fix a validation error, not to satisfy a choice. When a file looks wrong, surface the problem to
42
+ the author and stop; the fix is the author's call (usually regenerating it with the generator
43
+ prompt, then storing it fresh). *(A pipeline run saw a worker patch `metadata.name` on disk to
33
44
  force an outcome — this rule exists because that happened.)*
34
45
 
35
- For each payload file, in order, run:
46
+ For each component file, in order, run:
36
47
 
37
48
  ```bash
38
- node <fito-knowledge-push skill dir>/push.js <payload-file>
49
+ node <fito-knowledge-push skill dir>/push.js <component-file>
39
50
  ```
40
51
 
41
- - **Created** (`✓ Created <canonical-reference> …`) — record the canonical reference and move
42
- to the next file.
43
- - **Similar components found (advisory probe)** — the script stops **before storing anything**
44
- and prints each similar existing component with its similarity plus the choices (link /
45
- supersede / skip / proceed) and their exact re-run commands. **The choice is the author's —
46
- never yours.** Relay the block and wait for their pick; link and supersede work as on the 409
47
- below, and **proceed** (`--proceed`) stores an independent component that will coexist with
48
- the matches — restate that consequence before running it. If a proceed is then rejected with
49
- the near-duplicate 409, resolve it through the 409 block below.
50
- - **Near-duplicate 409** — the script stops and prints the duplicate's reference and the four
51
- choices (link / supersede / skip / override) with their exact re-run commands. **The
52
- resolution call is the author's — never yours.** Relay the block, then wait for their pick:
53
- - **link** or **supersede** are the preferred resolutions. For supersede, ask whether to
54
- label the new version (`--version <label>`, e.g. `2.0.0`) — the backend otherwise defaults
55
- `1.0.0`, the same label as the predecessor. If the supersede re-run reports the target is
56
- already superseded, relay the printed chain-head re-run and let the author retarget.
57
- - **skip** — record the payload as skipped; push nothing for it. When the reported
58
- duplicate is a component already pushed from this very payload file (an interrupted or
59
- repeated run — same name, matching content; the earlier `✓ Created` lines name each
60
- source file), tell the author skip is the expected resolution: it is already in the
61
- vocabulary.
62
- - **override** — before running it, restate the consequence: an independent near-duplicate
63
- component will be stored and **coexist** with the duplicate in the vocabulary. Run it only
64
- after the author explicitly confirms; the printed command already echoes the exact
65
- reported reference.
66
-
67
- Then run the author's exact chosen command and record the outcome.
68
- - **Any other failure** (malformed payload, unknown technology, unknown technology version,
69
- field-schema violations) — relay the printed reason, record the payload as failed, and continue
70
- with the remaining files (payloads are read-only — the rule above). A payload that names no
71
- technology version, or one the backend does not have, is a generator-side fix: regenerate with
72
- the right `--technology-version`, never hand-edit the payload's `technology_versions`.
73
-
74
- **Done when every resolved payload file is accounted for**: created (with its canonical
75
- reference), skipped, or failed — none silently dropped.
52
+ - **Stored** (`✓ Stored …`) — record the reference id and move to the next file.
53
+ - **A stop** — similar components, a duplicate, a revision label, or a newer revision. Nothing was
54
+ stored. Show the message and ask (see *Talking to the author*). **The choice is the author's —
55
+ never yours**; wait for it, then run its command and record the outcome. Skip runs nothing:
56
+ record the file as skipped by the author. The description of **Create new component** already
57
+ states its consequence, so the author's choice is the confirmation.
58
+ - **A file stored earlier** — when a stop names the reference id that an earlier `✓ Stored …` line
59
+ shows for this same file (an interrupted or repeated run), add this sentence below the message:
60
+
61
+ > This file was already stored earlier, as `<reference id>`. Choose Skip: Fito already has it.
62
+
63
+ - **Any other failure** (`✗ …`: a malformed file, an unknown technology, an unknown technology
64
+ version, a field that breaks the template's rules) — show the line, record the file as not
65
+ stored with its reason, and continue with the remaining files (component files are read-only —
66
+ the rule above). A file that names no technology version, or one Fito does not have, is fixed on
67
+ the generator side: regenerate it with the right `--technology-version`, never hand-edit its
68
+ `technology_versions`.
69
+
70
+ **Done when every component file is accounted for**: stored (with its reference id), skipped by
71
+ the author, or not stored because of an error — none silently dropped.
76
72
 
77
73
  ## 3. Report
78
74
 
79
- Summarize for the author:
75
+ Summarize for the author in three lists, each item naming the component and its file:
80
76
 
81
- - every created component's **canonical reference** (plain create, link, supersede, or
82
- override alike) and the **total created count**;
83
- - payloads skipped at the author's choice;
84
- - payloads failed, each with its reason.
77
+ - **Stored** — each component's **reference id**, whatever the choice that stored it, and the
78
+ total count;
79
+ - **Skipped by you**;
80
+ - **Not stored because of an error** — each with its reason.
@@ -179,13 +179,18 @@ feedback — name resolution is additive, and the evaluation is already recorded
179
179
  the summary with the bare component ids instead, and add a brief note that the
180
180
  component names could not be resolved (the backend may be unavailable).
181
181
 
182
+ Get Fito's address, for the links in the summary:
183
+
184
+ ```bash
185
+ node <fito-case-runner skill dir>/fito-url.js
186
+ ```
187
+
182
188
  Then relay the subagent's **learner-facing summary** — one block per criterion: the
183
189
  criterion, its knowledge component **labeled by name** (replace the bare
184
190
  `knowledgeComponent` id with its label from the map; fall back to the id if absent),
185
191
  its Bloom level, the score (`<n>/3` + label), the **proficiency recorded** for that
186
192
  component, the `/knowledge/...` link, and the one-sentence justification. Make each
187
- link clickable by prefixing it with the web origin — read `$FITO_WEB_ORIGIN`
188
- (`echo $FITO_WEB_ORIGIN`), falling back to `http://localhost:5173` if it is unset.
193
+ link clickable by prefixing it with Fito's address.
189
194
 
190
195
  If you administered a quiz (step 5), also relay one block per quiz question — the
191
196
  code-scored `multiple_choice` ones and the reviewer's, as you merged them in step 5:
@@ -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 failure —
11
11
  * the tool wrapper lets it propagate so pi marks the call as an error. `options.client` keeps the HTTP
12
12
  * boundary injectable for tests; production calls create the shared client per invocation (reading
13
- * `FITO_API_BASE_URL`) and send no credentials because the read is public.
13
+ * `FITO_URL`) and send no credentials because the read is public.
14
14
  */
15
15
  export async function listCompetences(technology, options = {}) {
16
16
  const client = options.client ?? createFitoApiClient();
@@ -11,7 +11,7 @@ import { type Competence, type FitoApiClient, FitoApiError, createFitoApiClient
11
11
  * Throws a plain `Error` (clear message) on a 404 (no such technology) or any other backend failure —
12
12
  * the tool wrapper lets it propagate so pi marks the call as an error. `options.client` keeps the HTTP
13
13
  * boundary injectable for tests; production calls create the shared client per invocation (reading
14
- * `FITO_API_BASE_URL`) and send no credentials because the read is public.
14
+ * `FITO_URL`) and send no credentials because the read is public.
15
15
  */
16
16
  export async function listCompetences(
17
17
  technology: string,
@@ -30,7 +30,7 @@ into `FitoApiError`, and centralises `401 → /auth/refresh → retry`.
30
30
  ```ts
31
31
  import { createFitoApiClient } from "../../shared/fito-api/client.ts";
32
32
 
33
- const api = createFitoApiClient(); // baseUrl from FITO_API_BASE_URL (default :8080)
33
+ const api = createFitoApiClient(); // baseUrl from shared/fito-url/: <FITO_URL>/api
34
34
 
35
35
  await api.refresh(refreshToken); // POST /auth/refresh -> new token pair
36
36
  await api.logout(refreshToken); // POST /auth/logout -> revoke
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import packageJson from "../../package.json" with { type: "json" };
3
+ import { fitoApiUrl } from "../fito-url/fito-url.js";
3
4
  /**
4
5
  * The TUI's backend HTTP **transport boundary** (ADR-003): a thin client that mirrors backend
5
6
  * REST endpoints one method per endpoint, attaches auth, validates every response with Zod, and
@@ -12,8 +13,6 @@ import packageJson from "../../package.json" with { type: "json" };
12
13
  * it grows per phase. At Task 1.5 it mapped only `refresh`, `logout`, `me`, plus the
13
14
  * `401 → /auth/refresh → retry` helper `meWithRefresh`.
14
15
  */
15
- /** Default backend origin; overridable via `FITO_API_BASE_URL`. */
16
- export const DEFAULT_BASE_URL = process.env.FITO_API_BASE_URL ?? "http://localhost:8080";
17
16
  /**
18
17
  * Sent on every request, so the backend can refuse a TUI older than the minimum version it serves,
19
18
  * with a message that says how to update (Task 15d.7a). Without it, Node's `fetch` sends `node`,
@@ -260,22 +259,19 @@ const competenceListSchema = z.object({ items: z.array(competenceSchema) });
260
259
  * Both dedup thresholds — the soft reporting floor and the hard 409 bar — live server-side
261
260
  * (`PublishKnowledgeComponentUseCase`); the client only relays what the probe reports.
262
261
  *
263
- * `technologyVersions` are the major lines the match applies to (Task 9a.5e). The probe, unlike
264
- * the hard gate, still reports a match whose version scope is disjoint from the candidate's — the
265
- * gate would admit it — so the author needs the scope to judge it. Two distinct axes: `version` is
262
+ * `technologyVersions` are the major lines the match applies to (Task 9a.5e). Like the hard gate,
263
+ * the probe reports only matches sharing a line with the candidate. Two distinct axes: `version` is
266
264
  * the match's own content revision, `technologyVersions` is what it applies to.
267
265
  *
268
- * `sameVersionScope` is the server's own reading of that scope against the probed candidate: true
269
- * when they share a line (the gate would 409), false when disjoint (the gate would admit). It
270
- * decides which of link / supersede / skip / proceed even applies, so it is relayed rather than
271
- * re-derived here.
266
+ * The response also carries `sameVersionScope`, always true since the probe was scoped. It is not
267
+ * declared here, so the parse drops it: the backend keeps sending it only for TUIs released before
268
+ * then, whose schema requires it.
272
269
  */
273
270
  export const nearDuplicateMatchSchema = z.object({
274
271
  id: z.string(),
275
272
  name: z.string(),
276
273
  version: z.string(),
277
274
  technologyVersions: z.array(technologyVersionSchema),
278
- sameVersionScope: z.boolean(),
279
275
  urlPath: z.string(),
280
276
  similarity: z.number(),
281
277
  });
@@ -485,7 +481,7 @@ const problemDetailSchema = z.object({
485
481
  matches: z.array(technologyNearDuplicateMatchSchema).optional().catch(undefined),
486
482
  });
487
483
  export function createFitoApiClient(options = {}) {
488
- const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
484
+ const baseUrl = options.baseUrl ?? fitoApiUrl();
489
485
  const doFetch = options.fetch ?? fetch;
490
486
  async function request(path, schema, init) {
491
487
  const response = await doFetch(`${baseUrl}${path}`, {
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  import packageJson from "../../package.json" with { type: "json" };
4
+ import { fitoApiUrl } from "../fito-url/fito-url.ts";
4
5
 
5
6
  /**
6
7
  * The TUI's backend HTTP **transport boundary** (ADR-003): a thin client that mirrors backend
@@ -15,9 +16,6 @@ import packageJson from "../../package.json" with { type: "json" };
15
16
  * `401 → /auth/refresh → retry` helper `meWithRefresh`.
16
17
  */
17
18
 
18
- /** Default backend origin; overridable via `FITO_API_BASE_URL`. */
19
- export const DEFAULT_BASE_URL = process.env.FITO_API_BASE_URL ?? "http://localhost:8080";
20
-
21
19
  /**
22
20
  * Sent on every request, so the backend can refuse a TUI older than the minimum version it serves,
23
21
  * with a message that says how to update (Task 15d.7a). Without it, Node's `fetch` sends `node`,
@@ -379,22 +377,19 @@ export interface UpdateCompetenceInput {
379
377
  * Both dedup thresholds — the soft reporting floor and the hard 409 bar — live server-side
380
378
  * (`PublishKnowledgeComponentUseCase`); the client only relays what the probe reports.
381
379
  *
382
- * `technologyVersions` are the major lines the match applies to (Task 9a.5e). The probe, unlike
383
- * the hard gate, still reports a match whose version scope is disjoint from the candidate's — the
384
- * gate would admit it — so the author needs the scope to judge it. Two distinct axes: `version` is
380
+ * `technologyVersions` are the major lines the match applies to (Task 9a.5e). Like the hard gate,
381
+ * the probe reports only matches sharing a line with the candidate. Two distinct axes: `version` is
385
382
  * the match's own content revision, `technologyVersions` is what it applies to.
386
383
  *
387
- * `sameVersionScope` is the server's own reading of that scope against the probed candidate: true
388
- * when they share a line (the gate would 409), false when disjoint (the gate would admit). It
389
- * decides which of link / supersede / skip / proceed even applies, so it is relayed rather than
390
- * re-derived here.
384
+ * The response also carries `sameVersionScope`, always true since the probe was scoped. It is not
385
+ * declared here, so the parse drops it: the backend keeps sending it only for TUIs released before
386
+ * then, whose schema requires it.
391
387
  */
392
388
  export const nearDuplicateMatchSchema = z.object({
393
389
  id: z.string(),
394
390
  name: z.string(),
395
391
  version: z.string(),
396
392
  technologyVersions: z.array(technologyVersionSchema),
397
- sameVersionScope: z.boolean(),
398
393
  urlPath: z.string(),
399
394
  similarity: z.number(),
400
395
  });
@@ -718,6 +713,7 @@ const problemDetailSchema = z.object({
718
713
  });
719
714
 
720
715
  export interface FitoApiClientOptions {
716
+ /** The API's address; defaults to the one `shared/fito-url/` gives (`<FITO_URL>/api`). */
721
717
  baseUrl?: string;
722
718
  fetch?: typeof fetch;
723
719
  }
@@ -1045,7 +1041,7 @@ export interface FitoApiClient {
1045
1041
  }
1046
1042
 
1047
1043
  export function createFitoApiClient(options: FitoApiClientOptions = {}): FitoApiClient {
1048
- const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
1044
+ const baseUrl = options.baseUrl ?? fitoApiUrl();
1049
1045
  const doFetch = options.fetch ?? fetch;
1050
1046
 
1051
1047
  async function request<T>(
@@ -2,12 +2,14 @@ import * as fs from "node:fs";
2
2
  import * as os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import { z } from "zod";
5
+ import { fitoUrl } from "../fito-url/fito-url.js";
5
6
  /**
6
- * Persistent store for the TUI's backend credentials at `~/.fito/credentials`
7
- * (file mode `0600`, dir `0700`). Only token material and metadata are stored —
8
- * never a plaintext password (SPEC §841 / PLAN Task 1.5). Pure Node module (no pi
9
- * imports) so it is unit-testable without a pi runtime; `home` is injectable so
10
- * tests can point at a temp directory.
7
+ * Persistent store for the TUI's backend credentials, one file per Fito at
8
+ * `~/.fito/credentials-<host>` (file mode `0600`, dir `0700`). Only token material
9
+ * and metadata are stored — never a plaintext password (SPEC §841 / PLAN Task 1.5).
10
+ * Pure Node module (no pi imports) so it is unit-testable without a pi runtime;
11
+ * `home` and the Fito's address are injectable so tests can point at a temp
12
+ * directory and at any Fito.
11
13
  */
12
14
  /** The token pair + metadata persisted to disk. Mirrors the backend token response. */
13
15
  export const credentialsSchema = z.object({
@@ -18,13 +20,23 @@ export const credentialsSchema = z.object({
18
20
  /** ISO-8601 timestamp of when these tokens were written. */
19
21
  savedAt: z.string().min(1),
20
22
  });
21
- /** The `~/.fito` directory that holds the credentials file. */
23
+ /** The `~/.fito` directory that holds the credentials files. */
22
24
  export function credentialsDir(home = os.homedir()) {
23
25
  return path.join(home, ".fito");
24
26
  }
25
- /** The `~/.fito/credentials` file path. */
26
- export function credentialsPath(home = os.homedir()) {
27
- return path.join(credentialsDir(home), "credentials");
27
+ /**
28
+ * The name of one Fito's credentials file: `credentials-<host>`, where `<host>` is the host of the
29
+ * Fito's address with its port, and a `:` is written as `-`, which every file system accepts
30
+ * (`credentials-localhost-8000`). Each Fito has its own file (Task 17.19), so a login to staging
31
+ * leaves the login to the development stack in place, and two sessions on two Fitos never write
32
+ * the same file.
33
+ */
34
+ export function credentialsFileName(url = fitoUrl()) {
35
+ return `credentials-${new URL(url).host.replaceAll(":", "-")}`;
36
+ }
37
+ /** The `~/.fito/credentials-<host>` file path of the Fito at `url`. */
38
+ export function credentialsPath(home = os.homedir(), url = fitoUrl()) {
39
+ return path.join(credentialsDir(home), credentialsFileName(url));
28
40
  }
29
41
  /**
30
42
  * Write the credentials as JSON, enforcing dir `0700` and file `0600`. The mode
@@ -32,11 +44,11 @@ export function credentialsPath(home = os.homedir()) {
32
44
  * file is tightened (the `mode` option on `writeFileSync` is ignored when the file
33
45
  * already exists).
34
46
  */
35
- export function writeCredentials(credentials, home = os.homedir()) {
47
+ export function writeCredentials(credentials, home = os.homedir(), url = fitoUrl()) {
36
48
  const dir = credentialsDir(home);
37
49
  fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
38
50
  fs.chmodSync(dir, 0o700);
39
- const file = credentialsPath(home);
51
+ const file = credentialsPath(home, url);
40
52
  fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}\n`, { mode: 0o600 });
41
53
  fs.chmodSync(file, 0o600);
42
54
  }
@@ -46,8 +58,8 @@ export function writeCredentials(credentials, home = os.homedir()) {
46
58
  * stale shape), so callers treat a corrupt store as "logged out" rather than
47
59
  * crashing.
48
60
  */
49
- export function readCredentials(home = os.homedir()) {
50
- const file = credentialsPath(home);
61
+ export function readCredentials(home = os.homedir(), url = fitoUrl()) {
62
+ const file = credentialsPath(home, url);
51
63
  let raw;
52
64
  try {
53
65
  raw = fs.readFileSync(file, "utf8");
@@ -59,8 +71,8 @@ export function readCredentials(home = os.homedir()) {
59
71
  return parsed.success ? parsed.data : null;
60
72
  }
61
73
  /** Delete the credentials file. Returns `true` if a file was removed, `false` if absent. */
62
- export function deleteCredentials(home = os.homedir()) {
63
- const file = credentialsPath(home);
74
+ export function deleteCredentials(home = os.homedir(), url = fitoUrl()) {
75
+ const file = credentialsPath(home, url);
64
76
  try {
65
77
  fs.rmSync(file);
66
78
  return true;