fito-tui 0.2.1 → 0.3.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.
- package/README.md +2 -86
- package/package.json +4 -4
- package/prompts/fito-evaluate.md +10 -5
- package/prompts/fito-push-knowledge.md +61 -65
- package/prompts/fito-submit.md +7 -2
- package/shared/competences/competence-list.js +1 -1
- package/shared/competences/competence-list.ts +1 -1
- package/shared/fito-api/README.md +1 -1
- package/shared/fito-api/client.js +7 -11
- package/shared/fito-api/client.ts +8 -12
- package/shared/fito-url/fito-url.js +29 -0
- package/shared/fito-url/fito-url.ts +32 -0
- package/shared/knowledge-components/knowledge-fetch.js +1 -1
- package/shared/knowledge-components/knowledge-fetch.ts +1 -1
- package/shared/knowledge-components/knowledge-search.js +1 -1
- package/shared/knowledge-components/knowledge-search.ts +1 -1
- package/shared/knowledge-components/technology-fetch.js +1 -1
- package/shared/knowledge-components/technology-fetch.ts +1 -1
- package/{skills/fito-case-author → shared/semver}/semver.js +8 -0
- package/{skills/fito-case-author → shared/semver}/semver.ts +9 -0
- package/skills/fito-auth/SKILL.md +3 -10
- package/skills/fito-auth/login.js +3 -2
- package/skills/fito-auth/login.ts +3 -2
- package/skills/fito-case-author/SKILL.md +1 -3
- package/skills/fito-case-author/publish-version.js +4 -4
- package/skills/fito-case-author/publish-version.ts +6 -6
- package/skills/fito-case-author/publish.js +4 -4
- package/skills/fito-case-author/publish.ts +6 -6
- package/skills/fito-case-runner/SKILL.md +10 -6
- package/skills/fito-case-runner/case-component-names.ts +1 -1
- package/skills/fito-case-runner/fito-url.js +8 -0
- package/skills/fito-case-runner/fito-url.ts +9 -0
- package/skills/fito-case-runner/open.ts +1 -1
- package/skills/fito-competence-write/SKILL.md +0 -6
- package/skills/fito-knowledge-push/SKILL.md +55 -76
- package/skills/fito-knowledge-push/push.js +169 -77
- package/skills/fito-knowledge-push/push.ts +210 -84
- package/skills/fito-source-ingestion/SKILL.md +0 -6
- package/skills/fito-source-ingestion/authoring-check.ts +1 -1
- package/skills/fito-technology-write/SKILL.md +0 -6
package/README.md
CHANGED
|
@@ -1,88 +1,4 @@
|
|
|
1
1
|
# Fito TUI
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fito-tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fito for pi: case-based practice for software engineers, in your terminal.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"build": "tsc -p tsconfig.build.json",
|
|
23
23
|
"lint": "tsc --noEmit && npm run build",
|
|
24
24
|
"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"
|
|
25
|
+
"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",
|
|
26
|
+
"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
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"yaml": "2.9.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^24.13.2",
|
|
53
|
-
"typebox": "1.
|
|
53
|
+
"typebox": "1.3.27",
|
|
54
54
|
"typescript": "6.0.3"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/prompts/fito-evaluate.md
CHANGED
|
@@ -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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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 —
|
|
@@ -1,84 +1,80 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
3
|
-
argument-hint: "[
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
##
|
|
9
|
+
## Talking to the author
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
+
If no component files are found, stop and tell the author:
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
46
|
+
For each component file, in order, run:
|
|
36
47
|
|
|
37
48
|
```bash
|
|
38
|
-
node <fito-knowledge-push skill dir>/push.js <
|
|
49
|
+
node <fito-knowledge-push skill dir>/push.js <component-file>
|
|
39
50
|
```
|
|
40
51
|
|
|
41
|
-
- **
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
-
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
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.
|
package/prompts/fito-submit.md
CHANGED
|
@@ -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
|
|
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
|
-
* `
|
|
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
|
-
* `
|
|
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
|
|
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).
|
|
264
|
-
* 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
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
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 ??
|
|
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).
|
|
383
|
-
* 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
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
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 ??
|
|
1044
|
+
const baseUrl = options.baseUrl ?? fitoApiUrl();
|
|
1049
1045
|
const doFetch = options.fetch ?? fetch;
|
|
1050
1046
|
|
|
1051
1047
|
async function request<T>(
|
|
@@ -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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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);
|