fito-tui 0.8.0 → 0.9.1

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.
@@ -1,7 +1,9 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { getShellConfig, } from "@earendil-works/pi-coding-agent";
4
+ import packageJson from "../package.json" with { type: "json" };
4
5
  import { FitoApiError, createFitoApiClient } from "../shared/fito-api/client.js";
6
+ import { fitoApiUrl } from "../shared/fito-url/fito-url.js";
5
7
  import { registerFitoDelegateTool } from "./fito-delegate.js";
6
8
  import { registerFitoCasePartialFetchTool, registerFitoCompetenceListTool, registerFitoKnowledgeFetchTool, registerFitoKnowledgeSearchTool, registerFitoTechnologyFetchTool, registerFitoTemplateFetchTool, } from "./fito-fetch-tools.js";
7
9
  /**
@@ -21,7 +23,8 @@ import { registerFitoCasePartialFetchTool, registerFitoCompetenceListTool, regis
21
23
  *
22
24
  * What remains here is the `session_start` checks — the guard for the missing
23
25
  * `subagent` tool, the `pi-subagents` version floor, and the backend's refusal of this
24
- * TUI's version (both Task 15d.7b), and Bash on Windows (Task 17a.3) — and registration
26
+ * TUI's version (both Task 15d.7b), and Bash on Windows (Task 17a.3) — the footer line
27
+ * that names this Fito's version and API address (Task 17.26), and registration
25
28
  * of Fito-owned custom tools (`pi.registerTool(...)`) for the **main**
26
29
  * session: `fito_knowledge_fetch` (Task 5.1b), the in-process knowledge-component
27
30
  * read that the `fito-tutor` worker holds while denied bash/filesystem (Success
@@ -95,6 +98,10 @@ export default function registerFitoStartup(pi, options = {}) {
95
98
  }
96
99
  if (process.env.PI_SUBAGENT_CHILD === "1")
97
100
  return;
101
+ // Which Fito runs and which API it uses, in the footer for the whole session (Task 17.26). It
102
+ // is set at every start — `/new`, `/resume`, `/fork` and `/reload` included — and asks nothing
103
+ // of the backend, so a backend that is down or slow neither delays it nor changes it.
104
+ ctx.ui.setStatus("fito", fitoStatusLine(ctx.ui.theme));
98
105
  if (subagent !== undefined && isBelowPiSubagentsFloor(subagent.sourceInfo)) {
99
106
  ctx.ui.notify(`Fito needs pi-subagents ${PI_SUBAGENTS_FLOOR.join(".")} or newer. Run: \`pi update --extensions\``, "error");
100
107
  }
@@ -109,6 +116,31 @@ export default function registerFitoStartup(pi, options = {}) {
109
116
  void warnIfTuiTooOld(ctx);
110
117
  });
111
118
  }
119
+ /**
120
+ * The Fito mark's three ascending pills, each in its own colour, drawn in text because a terminal
121
+ * line holds no image. The colours are copied from `web/src/lib/components/shell/Logo.svelte`, where
122
+ * the mark was drawn and approved; `web/static/favicon.svg` and `guide/` hold the other copies. The
123
+ * mark's amber dot is left out (Task 17.26, author's call).
124
+ */
125
+ const MARK_PILLS = [
126
+ ["▂", "#a8d4c4"],
127
+ ["▄", "#f7a6be"],
128
+ ["▆", "#9d7bc7"],
129
+ ];
130
+ /** `text` in the 24-bit colour `hex`, then the terminal's default colour again. */
131
+ function trueColour(hex, text) {
132
+ const rgb = Number.parseInt(hex.slice(1), 16);
133
+ return `\x1b[38;2;${rgb >> 16};${(rgb >> 8) & 255};${rgb & 255}m${text}\x1b[39m`;
134
+ }
135
+ /**
136
+ * The footer line: the mark, then `Fito <version> · API <address>` in the theme's `dim` colour, as
137
+ * pi's own footer lines are. The version is this package's, and the address is `fitoApiUrl()`, the
138
+ * one every Fito call uses, so the line cannot disagree with the calls.
139
+ */
140
+ export function fitoStatusLine(theme, env = process.env) {
141
+ const mark = MARK_PILLS.map(([pill, hex]) => trueColour(hex, pill)).join("");
142
+ return `${mark} ${theme.fg("dim", `Fito ${packageJson.version} · API ${fitoApiUrl(env)}`)}`;
143
+ }
112
144
  /**
113
145
  * The oldest `pi-subagents` Fito works with (ADR-002 Decision 3, "Version floor"): Fito's personas
114
146
  * need a relative `subagentOnlyExtensions` path resolved against the persona's own folder, which
@@ -5,10 +5,13 @@ import {
5
5
  type ExtensionAPI,
6
6
  type ExtensionContext,
7
7
  type SourceInfo,
8
+ type Theme,
8
9
  getShellConfig,
9
10
  } from "@earendil-works/pi-coding-agent";
10
11
 
12
+ import packageJson from "../package.json" with { type: "json" };
11
13
  import { FitoApiError, createFitoApiClient } from "../shared/fito-api/client.ts";
14
+ import { fitoApiUrl } from "../shared/fito-url/fito-url.ts";
12
15
  import { registerFitoDelegateTool } from "./fito-delegate.ts";
13
16
  import {
14
17
  registerFitoCasePartialFetchTool,
@@ -36,7 +39,8 @@ import {
36
39
  *
37
40
  * What remains here is the `session_start` checks — the guard for the missing
38
41
  * `subagent` tool, the `pi-subagents` version floor, and the backend's refusal of this
39
- * TUI's version (both Task 15d.7b), and Bash on Windows (Task 17a.3) — and registration
42
+ * TUI's version (both Task 15d.7b), and Bash on Windows (Task 17a.3) — the footer line
43
+ * that names this Fito's version and API address (Task 17.26), and registration
40
44
  * of Fito-owned custom tools (`pi.registerTool(...)`) for the **main**
41
45
  * session: `fito_knowledge_fetch` (Task 5.1b), the in-process knowledge-component
42
46
  * read that the `fito-tutor` worker holds while denied bash/filesystem (Success
@@ -119,6 +123,11 @@ export default function registerFitoStartup(
119
123
 
120
124
  if (process.env.PI_SUBAGENT_CHILD === "1") return;
121
125
 
126
+ // Which Fito runs and which API it uses, in the footer for the whole session (Task 17.26). It
127
+ // is set at every start — `/new`, `/resume`, `/fork` and `/reload` included — and asks nothing
128
+ // of the backend, so a backend that is down or slow neither delays it nor changes it.
129
+ ctx.ui.setStatus("fito", fitoStatusLine(ctx.ui.theme));
130
+
122
131
  if (subagent !== undefined && isBelowPiSubagentsFloor(subagent.sourceInfo)) {
123
132
  ctx.ui.notify(
124
133
  `Fito needs pi-subagents ${PI_SUBAGENTS_FLOOR.join(".")} or newer. Run: \`pi update --extensions\``,
@@ -142,6 +151,37 @@ export default function registerFitoStartup(
142
151
  });
143
152
  }
144
153
 
154
+ /**
155
+ * The Fito mark's three ascending pills, each in its own colour, drawn in text because a terminal
156
+ * line holds no image. The colours are copied from `web/src/lib/components/shell/Logo.svelte`, where
157
+ * the mark was drawn and approved; `web/static/favicon.svg` and `guide/` hold the other copies. The
158
+ * mark's amber dot is left out (Task 17.26, author's call).
159
+ */
160
+ const MARK_PILLS = [
161
+ ["▂", "#a8d4c4"],
162
+ ["▄", "#f7a6be"],
163
+ ["▆", "#9d7bc7"],
164
+ ] as const;
165
+
166
+ /** `text` in the 24-bit colour `hex`, then the terminal's default colour again. */
167
+ function trueColour(hex: string, text: string): string {
168
+ const rgb = Number.parseInt(hex.slice(1), 16);
169
+ return `\x1b[38;2;${rgb >> 16};${(rgb >> 8) & 255};${rgb & 255}m${text}\x1b[39m`;
170
+ }
171
+
172
+ /**
173
+ * The footer line: the mark, then `Fito <version> · API <address>` in the theme's `dim` colour, as
174
+ * pi's own footer lines are. The version is this package's, and the address is `fitoApiUrl()`, the
175
+ * one every Fito call uses, so the line cannot disagree with the calls.
176
+ */
177
+ export function fitoStatusLine(
178
+ theme: Pick<Theme, "fg">,
179
+ env: Record<string, string | undefined> = process.env,
180
+ ): string {
181
+ const mark = MARK_PILLS.map(([pill, hex]) => trueColour(hex, pill)).join("");
182
+ return `${mark} ${theme.fg("dim", `Fito ${packageJson.version} · API ${fitoApiUrl(env)}`)}`;
183
+ }
184
+
145
185
  /**
146
186
  * The oldest `pi-subagents` Fito works with (ADR-002 Decision 3, "Version floor"): Fito's personas
147
187
  * need a relative `subagentOnlyExtensions` path resolved against the persona's own folder, which
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fito-tui",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Fito for pi: case-based practice for software engineers, in your terminal.",
5
5
  "keywords": [
6
6
  "pi-package"