fito-tui 0.3.0 → 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.
- package/package.json +5 -1
- package/prompts/fito-auth-refresh.md +3 -3
- package/prompts/fito-login.md +3 -3
- package/prompts/fito-logout.md +3 -3
- package/shared/fito-session/credentials.js +27 -15
- package/shared/fito-session/credentials.ts +33 -15
- package/shared/fito-session/session.js +7 -5
- package/shared/fito-session/session.ts +10 -7
- package/skills/fito-auth/SKILL.md +10 -10
- package/skills/fito-auth/auth-refresh.js +3 -2
- package/skills/fito-auth/auth-refresh.ts +3 -2
- package/skills/fito-auth/login.js +4 -4
- package/skills/fito-auth/login.ts +4 -4
- package/skills/fito-auth/logout.js +3 -2
- package/skills/fito-auth/logout.ts +3 -2
- package/skills/fito-case-author/publish-version.js +1 -1
- package/skills/fito-case-author/publish-version.ts +1 -1
- package/skills/fito-case-author/publish.js +1 -1
- package/skills/fito-case-author/publish.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fito-tui",
|
|
3
|
-
"version": "0.
|
|
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": [
|
|
@@ -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
|
|
14
|
-
that and exits non-zero — in that case suggest running
|
|
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.
|
package/prompts/fito-login.md
CHANGED
|
@@ -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
|
|
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
|
package/prompts/fito-logout.md
CHANGED
|
@@ -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
|
|
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.
|
|
@@ -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
|
|
7
|
-
* (file mode `0600`, dir `0700`). Only token material
|
|
8
|
-
* never a plaintext password (SPEC §841 / PLAN Task 1.5).
|
|
9
|
-
* imports) so it is unit-testable without a pi runtime;
|
|
10
|
-
* tests can point at a temp
|
|
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
|
|
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
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
9
|
-
* (file mode `0600`, dir `0700`). Only token material
|
|
10
|
-
* never a plaintext password (SPEC §841 / PLAN Task 1.5).
|
|
11
|
-
* imports) so it is unit-testable without a pi runtime;
|
|
12
|
-
* tests can point at a temp
|
|
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
|
|
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
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
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(
|
|
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
|
|
4
|
-
* needs a logged-in session. Persists rotated
|
|
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
|
|
7
|
-
* 401 and persisting any rotated pair), and hand back the user plus the live tokens.
|
|
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
|
|
20
|
-
* needs a logged-in session. Persists rotated
|
|
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,10 @@ allowed-tools: bash
|
|
|
9
9
|
|
|
10
10
|
# Fito Auth
|
|
11
11
|
|
|
12
|
-
Handles the browser-based login handoff and the
|
|
13
|
-
(file mode `0600`, dir `0700`). Backend
|
|
14
|
-
(ADR-003); this skill never sees a
|
|
15
|
-
hands back only the token pair.
|
|
12
|
+
Handles the browser-based login handoff and the token store: one credentials file
|
|
13
|
+
per Fito, `~/.fito/credentials-<host>` (file mode `0600`, dir `0700`). Backend
|
|
14
|
+
access goes through the `fito-api` client (ADR-003); this skill never sees a
|
|
15
|
+
password — the browser performs the login and hands back only the token pair.
|
|
16
16
|
|
|
17
17
|
Run the commands from wherever you are — each one below names this
|
|
18
18
|
skill's directory itself.
|
|
@@ -25,8 +25,8 @@ node <fito-auth skill dir>/login.js
|
|
|
25
25
|
|
|
26
26
|
Starts a loopback server on an ephemeral port, opens the system browser to Fito's
|
|
27
27
|
`/auth/login?return_to=tui&port=<port>` page, and waits for the browser to POST the
|
|
28
|
-
freshly minted token pair back. On success it writes
|
|
29
|
-
|
|
28
|
+
freshly minted token pair back. On success it writes this Fito's credentials file
|
|
29
|
+
and prints a confirmation that names it. The learner can complete either
|
|
30
30
|
auth flow (email/password or "Continue with GitHub") in the browser.
|
|
31
31
|
|
|
32
32
|
## Log out
|
|
@@ -35,8 +35,8 @@ auth flow (email/password or "Continue with GitHub") in the browser.
|
|
|
35
35
|
node <fito-auth skill dir>/logout.js
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Best-effort revokes the refresh token server-side, then deletes
|
|
39
|
-
|
|
38
|
+
Best-effort revokes the refresh token server-side, then deletes this Fito's
|
|
39
|
+
credentials file. Idempotent — succeeds even when not logged in.
|
|
40
40
|
|
|
41
41
|
## Refresh
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ node <fito-auth skill dir>/auth-refresh.js
|
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Exchanges the stored refresh token for a fresh token pair via `POST /auth/refresh`
|
|
48
|
-
and rewrites
|
|
48
|
+
and rewrites this Fito's credentials file. Fails if not logged in.
|
|
49
49
|
|
|
50
50
|
## Files
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ and rewrites `~/.fito/credentials`. Fails if not logged in.
|
|
|
55
55
|
| `browser.ts` | Per-platform system-browser launcher |
|
|
56
56
|
| `login.ts` / `logout.ts` / `auth-refresh.ts` | CLI entrypoints (above) |
|
|
57
57
|
|
|
58
|
-
The
|
|
58
|
+
The credentials store (read/write/delete, `0600`, Zod-validated) lives in the
|
|
59
59
|
shared [`fito-session`](../../shared/fito-session/credentials.ts) module, reused by `fito-case-runner`.
|
|
60
60
|
|
|
61
61
|
See [the fito-api client](../../shared/fito-api/README.md) for how backend calls are made.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/fito-auth-refresh` CLI entrypoint. Exchanges the stored refresh token for a
|
|
3
|
-
* fresh token pair via the backend and rewrites
|
|
4
|
-
* this skill's directory:
|
|
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
|
|
4
|
-
* this skill's directory:
|
|
3
|
+
* fresh token pair via the backend and rewrites this Fito's
|
|
4
|
+
* `~/.fito/credentials-<host>`. Run from this skill's directory:
|
|
5
|
+
* `node auth-refresh.js`.
|
|
5
6
|
*/
|
|
6
7
|
import { createFitoApiClient } from "../../shared/fito-api/client.ts";
|
|
7
8
|
import { type Credentials, readCredentials, writeCredentials } from "../../shared/fito-session/credentials.ts";
|
|
@@ -1,13 +1,13 @@
|
|
|
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
|
|
4
|
+
* browser to POST the freshly minted token pair back, and writes it to this Fito's
|
|
5
|
+
* `~/.fito/credentials-<host>` (0600). Run from this skill's directory: `node login.js`.
|
|
6
6
|
*/
|
|
7
7
|
import * as crypto from "node:crypto";
|
|
8
8
|
import { openBrowser } from "./browser.js";
|
|
9
9
|
import { startCallbackServer } from "./callback-server.js";
|
|
10
|
-
import { writeCredentials } from "../../shared/fito-session/credentials.js";
|
|
10
|
+
import { credentialsFileName, writeCredentials } from "../../shared/fito-session/credentials.js";
|
|
11
11
|
import { fitoUrl } from "../../shared/fito-url/fito-url.js";
|
|
12
12
|
/** Web origin hosting the login page: the address of the Fito this TUI uses. */
|
|
13
13
|
const WEB_ORIGIN = fitoUrl();
|
|
@@ -26,7 +26,7 @@ async function main() {
|
|
|
26
26
|
const tokens = await server.waitForTokens();
|
|
27
27
|
const credentials = { ...tokens, savedAt: new Date().toISOString() };
|
|
28
28
|
writeCredentials(credentials);
|
|
29
|
-
console.log(
|
|
29
|
+
console.log(`✓ Logged in. Credentials saved to ~/.fito/${credentialsFileName()} (mode 0600).`);
|
|
30
30
|
}
|
|
31
31
|
finally {
|
|
32
32
|
server.close();
|
|
@@ -1,14 +1,14 @@
|
|
|
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
|
|
4
|
+
* browser to POST the freshly minted token pair back, and writes it to this Fito's
|
|
5
|
+
* `~/.fito/credentials-<host>` (0600). Run from this skill's directory: `node login.js`.
|
|
6
6
|
*/
|
|
7
7
|
import * as crypto from "node:crypto";
|
|
8
8
|
|
|
9
9
|
import { openBrowser } from "./browser.ts";
|
|
10
10
|
import { startCallbackServer } from "./callback-server.ts";
|
|
11
|
-
import { type Credentials, writeCredentials } from "../../shared/fito-session/credentials.ts";
|
|
11
|
+
import { type Credentials, credentialsFileName, writeCredentials } from "../../shared/fito-session/credentials.ts";
|
|
12
12
|
import { fitoUrl } from "../../shared/fito-url/fito-url.ts";
|
|
13
13
|
|
|
14
14
|
/** Web origin hosting the login page: the address of the Fito this TUI uses. */
|
|
@@ -31,7 +31,7 @@ async function main(): Promise<void> {
|
|
|
31
31
|
const tokens = await server.waitForTokens();
|
|
32
32
|
const credentials: Credentials = { ...tokens, savedAt: new Date().toISOString() };
|
|
33
33
|
writeCredentials(credentials);
|
|
34
|
-
console.log(
|
|
34
|
+
console.log(`✓ Logged in. Credentials saved to ~/.fito/${credentialsFileName()} (mode 0600).`);
|
|
35
35
|
} finally {
|
|
36
36
|
server.close();
|
|
37
37
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/fito-logout` CLI entrypoint. Best-effort revokes the refresh token
|
|
3
|
-
* server-side, then deletes `~/.fito/credentials
|
|
4
|
-
* no credentials are present. Run from this
|
|
3
|
+
* server-side, then deletes this Fito's `~/.fito/credentials-<host>`.
|
|
4
|
+
* Idempotent: succeeds even when no credentials are present. Run from this
|
|
5
|
+
* skill's directory: `node logout.js`.
|
|
5
6
|
*/
|
|
6
7
|
import { createFitoApiClient } from "../../shared/fito-api/client.js";
|
|
7
8
|
import { deleteCredentials, readCredentials } from "../../shared/fito-session/credentials.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/fito-logout` CLI entrypoint. Best-effort revokes the refresh token
|
|
3
|
-
* server-side, then deletes `~/.fito/credentials
|
|
4
|
-
* no credentials are present. Run from this
|
|
3
|
+
* server-side, then deletes this Fito's `~/.fito/credentials-<host>`.
|
|
4
|
+
* Idempotent: succeeds even when no credentials are present. Run from this
|
|
5
|
+
* skill's directory: `node logout.js`.
|
|
5
6
|
*/
|
|
6
7
|
import { createFitoApiClient } from "../../shared/fito-api/client.ts";
|
|
7
8
|
import { deleteCredentials, readCredentials } from "../../shared/fito-session/credentials.ts";
|
|
@@ -166,7 +166,7 @@ export async function runPublishVersion(options) {
|
|
|
166
166
|
throw new Error(`${origin.reason}.\nThis directory is an initial publish, not an update — run /fito-publish-case's ` +
|
|
167
167
|
"initial path (publish.js) instead.");
|
|
168
168
|
}
|
|
169
|
-
const session = await resolveFitoSession(client, home);
|
|
169
|
+
const session = await resolveFitoSession(client, home, fitoUrl(env));
|
|
170
170
|
const detail = await client.getCase(origin.caseId, session.tokens.accessToken);
|
|
171
171
|
gateStatus(detail, "publishVersion");
|
|
172
172
|
// The strictly-greater guard, before the push: the current version is the chain's maximum, so a
|
|
@@ -272,7 +272,7 @@ export async function runPublishVersion(options: RunPublishVersionOptions): Prom
|
|
|
272
272
|
);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
const session = await resolveFitoSession(client, home);
|
|
275
|
+
const session = await resolveFitoSession(client, home, fitoUrl(env));
|
|
276
276
|
const detail = await client.getCase(origin.caseId, session.tokens.accessToken);
|
|
277
277
|
gateStatus(detail, "publishVersion");
|
|
278
278
|
|
|
@@ -76,7 +76,7 @@ export async function runPublish(options) {
|
|
|
76
76
|
"executed outside Fito), then re-run.");
|
|
77
77
|
}
|
|
78
78
|
const ghLogin = (await run(ghCurrentLoginCommand())).trim();
|
|
79
|
-
const session = await resolveFitoSession(client, home);
|
|
79
|
+
const session = await resolveFitoSession(client, home, fitoUrl(env));
|
|
80
80
|
// Decision 4 (2026-07-08): a gh↔Fito identity mismatch warns and stops for the author's explicit
|
|
81
81
|
// confirmation — never refuses outright (publishing under an org is supported).
|
|
82
82
|
const linkedLogin = session.user.githubLogin ?? null;
|
|
@@ -151,7 +151,7 @@ export async function runPublish(options: RunPublishOptions): Promise<RunPublish
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
const ghLogin = (await run(ghCurrentLoginCommand())).trim();
|
|
154
|
-
const session = await resolveFitoSession(client, home);
|
|
154
|
+
const session = await resolveFitoSession(client, home, fitoUrl(env));
|
|
155
155
|
|
|
156
156
|
// Decision 4 (2026-07-08): a gh↔Fito identity mismatch warns and stops for the author's explicit
|
|
157
157
|
// confirmation — never refuses outright (publishing under an org is supported).
|