fito-tui 0.3.0 → 0.5.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 (63) hide show
  1. package/agents/fito-performance-reviewer.md +6 -5
  2. package/extensions/fito-startup.js +27 -3
  3. package/extensions/fito-startup.ts +39 -7
  4. package/package.json +7 -3
  5. package/prompts/fito-auth-refresh.md +4 -4
  6. package/prompts/fito-case-edit.md +2 -2
  7. package/prompts/fito-case-generate.md +1 -1
  8. package/prompts/fito-case-open.md +6 -5
  9. package/prompts/fito-create-or-update-competence.md +2 -2
  10. package/prompts/fito-create-or-update-technology.md +5 -5
  11. package/prompts/fito-delete-competence.md +2 -2
  12. package/prompts/fito-evaluate.md +30 -22
  13. package/prompts/fito-login.md +3 -3
  14. package/prompts/fito-logout.md +4 -4
  15. package/prompts/fito-publish-case.md +3 -3
  16. package/prompts/fito-push-knowledge.md +1 -1
  17. package/prompts/fito-submit.md +55 -36
  18. package/shared/fito-session/credentials.js +27 -15
  19. package/shared/fito-session/credentials.ts +33 -15
  20. package/shared/fito-session/session.js +7 -5
  21. package/shared/fito-session/session.ts +10 -7
  22. package/skills/fito-auth/SKILL.md +14 -13
  23. package/skills/fito-auth/auth-refresh.js +3 -2
  24. package/skills/fito-auth/auth-refresh.ts +3 -2
  25. package/skills/fito-auth/browser.js +3 -2
  26. package/skills/fito-auth/browser.ts +3 -2
  27. package/skills/fito-auth/login.js +24 -8
  28. package/skills/fito-auth/login.ts +25 -8
  29. package/skills/fito-auth/logout.js +3 -2
  30. package/skills/fito-auth/logout.ts +3 -2
  31. package/skills/fito-case-author/SKILL.md +4 -4
  32. package/skills/fito-case-author/checkout.js +22 -5
  33. package/skills/fito-case-author/checkout.ts +22 -5
  34. package/skills/fito-case-author/publish-version.js +1 -1
  35. package/skills/fito-case-author/publish-version.ts +1 -1
  36. package/skills/fito-case-author/publish.js +1 -1
  37. package/skills/fito-case-author/publish.ts +1 -1
  38. package/skills/fito-case-runner/SKILL.md +24 -7
  39. package/skills/fito-case-runner/github.js +20 -2
  40. package/skills/fito-case-runner/github.ts +21 -2
  41. package/skills/fito-case-runner/open.js +3 -3
  42. package/skills/fito-case-runner/open.ts +3 -3
  43. package/skills/fito-case-runner/runner.js +12 -1
  44. package/skills/fito-case-runner/runner.ts +15 -0
  45. package/skills/fito-case-runner/submit.js +1 -1
  46. package/skills/fito-case-runner/submit.ts +1 -1
  47. package/skills/fito-case-runner/temp-file.js +16 -0
  48. package/skills/fito-case-runner/temp-file.ts +17 -0
  49. package/skills/fito-competence-write/SKILL.md +3 -3
  50. package/skills/fito-competence-write/delete.js +1 -1
  51. package/skills/fito-competence-write/delete.ts +1 -1
  52. package/skills/fito-evaluator/SKILL.md +7 -6
  53. package/skills/fito-evaluator/criterion-exec.js +113 -17
  54. package/skills/fito-evaluator/criterion-exec.ts +110 -18
  55. package/skills/fito-evaluator/evaluate-automated.js +7 -3
  56. package/skills/fito-evaluator/evaluate-automated.ts +7 -3
  57. package/skills/fito-knowledge-push/SKILL.md +1 -1
  58. package/skills/fito-knowledge-push/push.js +8 -8
  59. package/skills/fito-knowledge-push/push.ts +8 -8
  60. package/skills/fito-source-ingestion/SKILL.md +4 -4
  61. package/skills/fito-technology-write/SKILL.md +2 -2
  62. package/skills/fito-technology-write/create.js +2 -2
  63. package/skills/fito-technology-write/create.ts +2 -2
@@ -9,27 +9,27 @@ Fito. Drive the steps below in order.
9
9
  If no case id was given, ask the learner for it first — the case's UUID, the same
10
10
  id they opened with `/fito-case-open` — and don't run anything until you have it.
11
11
 
12
- The submit step pushes whatever is **committed** on the case's working branch, so
13
- first make sure their work is committed. If there are uncommitted changes in
14
- `~/.fito/cases/$1/`, tell the learner to commit them on the working branch before
15
- continuing.
16
-
17
12
  ## 1. Record the submission (push + open the PR)
18
13
 
19
14
  Use the `fito-case-runner` skill (read its `SKILL.md`), then run:
20
15
 
21
16
  ```bash
22
- node <fito-case-runner skill dir>/submit.js $1
17
+ node "<fito-case-runner skill dir>/submit.js" $1
23
18
  ```
24
19
 
25
20
  This pushes the working branch to the learner's fork, opens a pull request against
26
- the case's submission target branch, and records the submission with Fito. Stream
27
- the output. It is safe to re-run: it reuses an already-open PR and re-recording the
28
- same PR is idempotent.
21
+ the case's submission target branch, and records the submission with Fito. It pushes
22
+ only what is **committed**, so it first refuses a checkout with work that is not.
23
+ Stream the output. It is safe to re-run: it reuses an already-open PR and
24
+ re-recording the same PR is idempotent.
29
25
 
30
26
  **Note the submission id** it prints (`Submission recorded with Fito (id: <uuid>)`) —
31
27
  you need it in step 4.
32
28
 
29
+ - If it reports changes that are not committed, nothing was pushed. Relay the files
30
+ it lists, and tell the learner to commit them on the working branch — or delete
31
+ the ones that are not part of their work — then re-run `/fito-submit $1`. Stop
32
+ here until they do.
33
33
  - If it reports the PR is open but recording the submission failed, the PR is on
34
34
  GitHub but Fito did not record it — have the learner re-run `/fito-submit $1`,
35
35
  which reuses the PR and retries the record.
@@ -49,18 +49,20 @@ you need it in step 4.
49
49
  Use the `fito-evaluator` skill (read its `SKILL.md`), then run:
50
50
 
51
51
  ```bash
52
- node <fito-evaluator skill dir>/evaluate-automated.js $1
52
+ node "<fito-evaluator skill dir>/evaluate-automated.js" $1
53
53
  ```
54
54
 
55
- Stream the output. In `~/.fito/cases/$1/` it runs the automated criteria's commands
56
- and the hybrid criteria's gate commands, and prints one **evaluation report**: the
57
- automated evidence, the `ai` criteria + their prompt hints, the `hybrid` gate
58
- evidence, and any `human` criteria under **Needs human review**.
55
+ Stream the output. In the case's checkout it runs the automated criteria's commands
56
+ and the hybrid criteria's gate commands, and prints one **evaluation report**. Its
57
+ first line, `Case checkout: <path>`, is the checkout's absolute path: every later
58
+ step uses that path, exactly as printed. Then come the automated evidence, the `ai`
59
+ criteria + their prompt hints, the `hybrid` gate evidence, and any `human` criteria
60
+ under **Needs human review**.
59
61
 
60
62
  If the report has **no scorable criteria** (nothing automated, ai, or hybrid), there
61
63
  is no rubric to score — skip the rubric steps (3–4) and go straight to the quiz
62
- (step 5). If there is also no `~/.fito/cases/$1/.case/quiz.yaml`, tell the learner
63
- the submission is recorded but has nothing to score, and stop. (The PR and
64
+ (step 5). If the checkout also has no `.case/quiz.yaml`, tell the learner the
65
+ submission is recorded but has nothing to score, and stop. (The PR and
64
66
  submission from step 1 still stand.)
65
67
 
66
68
  ## 3. Score the report
@@ -69,8 +71,8 @@ Delegate to the `fito-performance-reviewer` **subagent** via the `fito_delegate`
69
71
  tool. Hand it **both**:
70
72
 
71
73
  - the **full evaluation report** from step 2, and
72
- - the **case checkout path** `~/.fito/cases/$1/`, which it needs to score the `ai`
73
- and `hybrid` criteria from the learner's actual changes.
74
+ - the **case checkout path** from the report's first line, which it needs to score
75
+ the `ai` and `hybrid` criteria from the learner's actual changes.
74
76
 
75
77
  It returns, as a fenced ```json array, one object per criterion —
76
78
  `criterionId`, `knowledgeComponent`, `bloomLevel`, `evaluationType`, `score`
@@ -84,12 +86,17 @@ This delegation blocks — you read the child's summary from the tool result.
84
86
  ## 4. Record the evaluation with Fito
85
87
 
86
88
  Save the subagent's JSON array **exactly as returned** (just the array from the
87
- fenced ```json block) to a temporary file outside the checkout — e.g. write it to
88
- `$(mktemp)` and note the path — the submission id from step 1 and that path are the
89
- two arguments:
89
+ fenced ```json block) to a new temp file. Get the file's path with:
90
90
 
91
91
  ```bash
92
- node <fito-case-runner skill dir>/submit-evaluation.js <submission-id> <results-file>
92
+ node "<fito-case-runner skill dir>/temp-file.js"
93
+ ```
94
+
95
+ Write the array to the path it prints, exactly as printed. The submission id from
96
+ step 1 and that path are the two arguments:
97
+
98
+ ```bash
99
+ node "<fito-case-runner skill dir>/submit-evaluation.js" <submission-id> "<results-file>"
93
100
  ```
94
101
 
95
102
  This POSTs the scores to Fito (`POST /submissions/{id}/results`), which records the
@@ -106,7 +113,7 @@ submission's results, so re-running `/fito-submit $1` re-evaluates and re-record
106
113
 
107
114
  ## 5. Administer and record the quiz (if the case has one)
108
115
 
109
- If `~/.fito/cases/$1/.case/quiz.yaml` exists, the case has a knowledge-check quiz;
116
+ If the checkout has a `.case/quiz.yaml`, the case has a knowledge-check quiz;
110
117
  administer, score, and record it against the submission from step 1. If the file is
111
118
  absent, skip this step.
112
119
 
@@ -117,31 +124,43 @@ absent, skip this step.
117
124
  for scoring only. Collect the learner's `multiple_choice` answers as a
118
125
  `{ "<questionId>": "<choiceId>" }` map, and hold their `short_answer` /
119
126
  `code_snippet` answers for the reviewer.
120
- 2. **Score the `multiple_choice` questions in code.** Write the MC answers map to a
121
- temp file (e.g. `$(mktemp)`), then run:
127
+ 2. **Score the `multiple_choice` questions in code.** Get a new temp file's path
128
+ with:
122
129
 
123
130
  ```bash
124
- node <fito-case-runner skill dir>/score-quiz-mc.js $1 <answers-file>
131
+ node "<fito-case-runner skill dir>/temp-file.js"
132
+ ```
133
+
134
+ Write the MC answers map to the path it prints, exactly as printed, then run:
135
+
136
+ ```bash
137
+ node "<fito-case-runner skill dir>/score-quiz-mc.js" $1 "<answers-file>"
125
138
  ```
126
139
 
127
140
  Capture its JSON array of scored `multiple_choice` questions (`[]` if the quiz
128
141
  has none).
129
142
  3. **Score the `short_answer` / `code_snippet` questions via the reviewer.** If the
130
143
  quiz has any, delegate to the `fito-performance-reviewer` **subagent** via
131
- the `fito_delegate` tool, handing it the **case checkout path**
132
- `~/.fito/cases/$1/` (it reads `.case/quiz.yaml` — including the `evaluation`
133
- block — itself) and the **learner's answers** to those questions, keyed by
134
- question id. It returns, as a fenced ```json array, one object per question —
144
+ the `fito_delegate` tool, handing it the **case checkout path** from the report's
145
+ first line (it reads `.case/quiz.yaml` — including the `evaluation` block —
146
+ itself) and the **learner's answers** to those questions, keyed by question
147
+ id. It returns, as a fenced ```json array, one object per question —
135
148
  `questionId`, `knowledgeComponents`, `bloomLevel`, `score` (0–3, or `null` for a
136
149
  question needing human review), and `justification`. Do not score anything yourself.
137
150
  This delegation blocks — you read the child's summary from the tool result.
138
151
  4. **Record the quiz result with Fito.** Merge the code-scored (step 2) and
139
- reviewer-scored (step 3) questions into one JSON array of per-question scores,
140
- write it to a temp file outside the checkout (e.g. `$(mktemp)`) — the submission id
141
- from step 1 and that path are the two arguments:
152
+ reviewer-scored (step 3) questions into one JSON array of per-question scores.
153
+ Get a new temp file's path with:
154
+
155
+ ```bash
156
+ node "<fito-case-runner skill dir>/temp-file.js"
157
+ ```
158
+
159
+ Write the array to the path it prints, exactly as printed. The submission id from
160
+ step 1 and that path are the two arguments:
142
161
 
143
162
  ```bash
144
- node <fito-case-runner skill dir>/submit-quiz-result.js <submission-id> <scores-file>
163
+ node "<fito-case-runner skill dir>/submit-quiz-result.js" <submission-id> "<scores-file>"
145
164
  ```
146
165
 
147
166
  This POSTs to `POST /submissions/{id}/quiz-result`, which records the scores,
@@ -166,7 +185,7 @@ and, if you administered a quiz (step 5), the `knowledgeComponents` of every que
166
185
  in the merged quiz array you recorded — then run:
167
186
 
168
187
  ```bash
169
- node <fito-case-runner skill dir>/case-component-names.js $1 <component-id...>
188
+ node "<fito-case-runner skill dir>/case-component-names.js" $1 <component-id...>
170
189
  ```
171
190
 
172
191
  passing those ids. It prints one `<id>\t<label>` line per id, where `<label>` is
@@ -182,7 +201,7 @@ component names could not be resolved (the backend may be unavailable).
182
201
  Get Fito's address, for the links in the summary:
183
202
 
184
203
  ```bash
185
- node <fito-case-runner skill dir>/fito-url.js
204
+ node "<fito-case-runner skill dir>/fito-url.js"
186
205
  ```
187
206
 
188
207
  Then relay the subagent's **learner-facing summary** — one block per criterion: the
@@ -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;
@@ -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
  }
@@ -9,10 +9,11 @@ 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>` (off Windows, file mode `0600` and dir
14
+ `0700`). Backend access goes through the `fito-api` client (ADR-003); this skill
15
+ never sees a password — the browser performs the login and hands back only the
16
+ token pair.
16
17
 
17
18
  Run the commands from wherever you are — each one below names this
18
19
  skill's directory itself.
@@ -20,32 +21,32 @@ skill's directory itself.
20
21
  ## Log in
21
22
 
22
23
  ```bash
23
- node <fito-auth skill dir>/login.js
24
+ node "<fito-auth skill dir>/login.js"
24
25
  ```
25
26
 
26
27
  Starts a loopback server on an ephemeral port, opens the system browser to Fito's
27
28
  `/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
29
- `~/.fito/credentials` and prints a confirmation. The learner can complete either
29
+ freshly minted token pair back. On success it writes this Fito's credentials file
30
+ and prints a confirmation that names it. The learner can complete either
30
31
  auth flow (email/password or "Continue with GitHub") in the browser.
31
32
 
32
33
  ## Log out
33
34
 
34
35
  ```bash
35
- node <fito-auth skill dir>/logout.js
36
+ node "<fito-auth skill dir>/logout.js"
36
37
  ```
37
38
 
38
- Best-effort revokes the refresh token server-side, then deletes
39
- `~/.fito/credentials`. Idempotent — succeeds even when not logged in.
39
+ Best-effort revokes the refresh token server-side, then deletes this Fito's
40
+ credentials file. Idempotent — succeeds even when not logged in.
40
41
 
41
42
  ## Refresh
42
43
 
43
44
  ```bash
44
- node <fito-auth skill dir>/auth-refresh.js
45
+ node "<fito-auth skill dir>/auth-refresh.js"
45
46
  ```
46
47
 
47
48
  Exchanges the stored refresh token for a fresh token pair via `POST /auth/refresh`
48
- and rewrites `~/.fito/credentials`. Fails if not logged in.
49
+ and rewrites this Fito's credentials file. Fails if not logged in.
49
50
 
50
51
  ## Files
51
52
 
@@ -55,7 +56,7 @@ and rewrites `~/.fito/credentials`. Fails if not logged in.
55
56
  | `browser.ts` | Per-platform system-browser launcher |
56
57
  | `login.ts` / `logout.ts` / `auth-refresh.ts` | CLI entrypoints (above) |
57
58
 
58
- The `~/.fito/credentials` store (read/write/delete, `0600`, Zod-validated) lives in the
59
+ The credentials store (read/write/delete, Zod-validated) lives in the
59
60
  shared [`fito-session`](../../shared/fito-session/credentials.ts) module, reused by `fito-case-runner`.
60
61
 
61
62
  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";
@@ -5,8 +5,9 @@ export function browserOpenCommand(platform, url) {
5
5
  case "darwin":
6
6
  return { command: "open", args: [url] };
7
7
  case "win32":
8
- // `start` is a cmd builtin; the empty "" is the (required) window-title arg.
9
- return { command: "cmd", args: ["/c", "start", "", url] };
8
+ // No shell: `cmd /c start` cut the URL at its first `&`, losing the port and the handoff
9
+ // secret (Phase 17a, finding 1). pi's own browser opener uses this form.
10
+ return { command: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
10
11
  default:
11
12
  return { command: "xdg-open", args: [url] };
12
13
  }
@@ -20,8 +20,9 @@ export function browserOpenCommand(platform: Platform, url: string): BrowserComm
20
20
  case "darwin":
21
21
  return { command: "open", args: [url] };
22
22
  case "win32":
23
- // `start` is a cmd builtin; the empty "" is the (required) window-title arg.
24
- return { command: "cmd", args: ["/c", "start", "", url] };
23
+ // No shell: `cmd /c start` cut the URL at its first `&`, losing the port and the handoff
24
+ // secret (Phase 17a, finding 1). pi's own browser opener uses this form.
25
+ return { command: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
25
26
  default:
26
27
  return { command: "xdg-open", args: [url] };
27
28
  }
@@ -1,18 +1,29 @@
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 off Windows). Run from this skill's directory: `node login.js`.
6
6
  */
7
7
  import * as crypto from "node:crypto";
8
+ import * as path from "node:path";
9
+ import { fileURLToPath } from "node:url";
8
10
  import { openBrowser } from "./browser.js";
9
11
  import { startCallbackServer } from "./callback-server.js";
10
- import { writeCredentials } from "../../shared/fito-session/credentials.js";
12
+ import { credentialsFileName, writeCredentials } from "../../shared/fito-session/credentials.js";
11
13
  import { fitoUrl } from "../../shared/fito-url/fito-url.js";
12
14
  /** Web origin hosting the login page: the address of the Fito this TUI uses. */
13
15
  const WEB_ORIGIN = fitoUrl();
14
16
  /** How long to wait for the browser handoff before giving up. */
15
17
  const TIMEOUT_MS = 5 * 60 * 1000;
18
+ /**
19
+ * The line printed once the credentials are saved. It names the file mode off Windows only: there
20
+ * `chmod` sets no mode, and the user folder's own access list protects the file (Phase 17a,
21
+ * findings 12 and 13).
22
+ */
23
+ export function loginSuccessMessage(fileName, platform = process.platform) {
24
+ const mode = platform === "win32" ? "" : " (mode 0600)";
25
+ return `✓ Logged in. Credentials saved to ~/.fito/${fileName}${mode}.`;
26
+ }
16
27
  async function main() {
17
28
  // Single-use secret binding this login to the browser handoff: the page must echo it
18
29
  // back, so a malicious page that guesses the loopback port cannot inject tokens.
@@ -26,13 +37,18 @@ async function main() {
26
37
  const tokens = await server.waitForTokens();
27
38
  const credentials = { ...tokens, savedAt: new Date().toISOString() };
28
39
  writeCredentials(credentials);
29
- console.log("✓ Logged in. Credentials saved to ~/.fito/credentials (mode 0600).");
40
+ console.log(loginSuccessMessage(credentialsFileName()));
30
41
  }
31
42
  finally {
32
43
  server.close();
33
44
  }
34
45
  }
35
- main().catch((error) => {
36
- console.error(`✗ Login failed: ${error instanceof Error ? error.message : String(error)}`);
37
- process.exitCode = 1;
38
- });
46
+ /** Only auto-invoke the CLI when run directly (`node login.js`), not when imported. */
47
+ const entry = process.argv[1];
48
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
49
+ if (isMainModule) {
50
+ main().catch((error) => {
51
+ console.error(`✗ Login failed: ${error instanceof Error ? error.message : String(error)}`);
52
+ process.exitCode = 1;
53
+ });
54
+ }