fito-tui 0.2.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 +88 -0
- package/agents/fito-case-source-planner.md +265 -0
- package/agents/fito-performance-reviewer.md +231 -0
- package/agents/fito-practice-concept-content-generator.md +318 -0
- package/agents/fito-practice-concept-identifier.md +482 -0
- package/agents/fito-practice-execution-fact-content-generator.md +299 -0
- package/agents/fito-practice-execution-fact-identifier.md +367 -0
- package/agents/fito-practice-usage-scenario-content-generator.md +331 -0
- package/agents/fito-practice-usage-scenario-identifier.md +397 -0
- package/agents/fito-subagent-selftest.md +27 -0
- package/agents/fito-technology-generator.md +207 -0
- package/agents/fito-tool-concept-content-generator.md +282 -0
- package/agents/fito-tool-concept-identifier.md +384 -0
- package/agents/fito-tool-execution-fact-content-generator.md +382 -0
- package/agents/fito-tool-execution-fact-identifier.md +360 -0
- package/agents/fito-tool-usage-scenario-content-generator.md +381 -0
- package/agents/fito-tool-usage-scenario-identifier.md +432 -0
- package/agents/fito-tutor.md +185 -0
- package/extensions/fito-delegate.js +539 -0
- package/extensions/fito-delegate.ts +691 -0
- package/extensions/fito-fetch-tools.js +380 -0
- package/extensions/fito-fetch-tools.ts +419 -0
- package/extensions/fito-startup.js +166 -0
- package/extensions/fito-startup.ts +188 -0
- package/package.json +56 -0
- package/prompts/fito-auth-refresh.md +15 -0
- package/prompts/fito-case-design.md +506 -0
- package/prompts/fito-case-edit.md +91 -0
- package/prompts/fito-case-generate.md +222 -0
- package/prompts/fito-case-open.md +124 -0
- package/prompts/fito-case-plan-source.md +114 -0
- package/prompts/fito-create-or-update-competence.md +261 -0
- package/prompts/fito-create-or-update-technology.md +199 -0
- package/prompts/fito-delete-competence.md +147 -0
- package/prompts/fito-evaluate.md +148 -0
- package/prompts/fito-fetch-urls-content.md +35 -0
- package/prompts/fito-generate-domain-concepts.md +85 -0
- package/prompts/fito-generate-execution-facts.md +85 -0
- package/prompts/fito-generate-usage-scenarios.md +85 -0
- package/prompts/fito-identify-domain-concepts.md +49 -0
- package/prompts/fito-identify-execution-facts.md +49 -0
- package/prompts/fito-identify-usage-scenarios.md +49 -0
- package/prompts/fito-login.md +21 -0
- package/prompts/fito-logout.md +14 -0
- package/prompts/fito-publish-case.md +266 -0
- package/prompts/fito-push-knowledge.md +84 -0
- package/prompts/fito-submit.md +208 -0
- package/prompts/fito-tutor.md +120 -0
- package/shared/case-briefing/briefing.js +221 -0
- package/shared/case-briefing/briefing.ts +261 -0
- package/shared/case-quiz/scoring.js +16 -0
- package/shared/case-quiz/scoring.ts +61 -0
- package/shared/case-validation/case-loader.js +88 -0
- package/shared/case-validation/case-loader.ts +106 -0
- package/shared/case-validation/case-schema.js +716 -0
- package/shared/case-validation/case-schema.ts +895 -0
- package/shared/competences/competence-list.js +29 -0
- package/shared/competences/competence-list.ts +32 -0
- package/shared/fito-api/README.md +192 -0
- package/shared/fito-api/client.js +731 -0
- package/shared/fito-api/client.ts +1426 -0
- package/shared/fito-session/credentials.js +79 -0
- package/shared/fito-session/credentials.ts +88 -0
- package/shared/fito-session/session.js +16 -0
- package/shared/fito-session/session.ts +35 -0
- package/shared/github-url/parse.js +26 -0
- package/shared/github-url/parse.ts +35 -0
- package/shared/knowledge-components/component-names.js +35 -0
- package/shared/knowledge-components/component-names.ts +39 -0
- package/shared/knowledge-components/knowledge-fetch.js +46 -0
- package/shared/knowledge-components/knowledge-fetch.ts +57 -0
- package/shared/knowledge-components/knowledge-search.js +101 -0
- package/shared/knowledge-components/knowledge-search.ts +144 -0
- package/shared/knowledge-components/push-payload.js +104 -0
- package/shared/knowledge-components/push-payload.ts +129 -0
- package/shared/knowledge-components/reference.js +24 -0
- package/shared/knowledge-components/reference.ts +43 -0
- package/shared/knowledge-components/technology-fetch.js +30 -0
- package/shared/knowledge-components/technology-fetch.ts +38 -0
- package/shared/shell-exec/exec.js +22 -0
- package/shared/shell-exec/exec.ts +46 -0
- package/skills/fito-auth/SKILL.md +68 -0
- package/skills/fito-auth/auth-refresh.js +23 -0
- package/skills/fito-auth/auth-refresh.ts +25 -0
- package/skills/fito-auth/browser.js +35 -0
- package/skills/fito-auth/browser.ts +57 -0
- package/skills/fito-auth/callback-server.js +152 -0
- package/skills/fito-auth/callback-server.ts +189 -0
- package/skills/fito-auth/login.js +37 -0
- package/skills/fito-auth/login.ts +42 -0
- package/skills/fito-auth/logout.js +24 -0
- package/skills/fito-auth/logout.ts +25 -0
- package/skills/fito-case-author/SKILL.md +179 -0
- package/skills/fito-case-author/checkout.js +222 -0
- package/skills/fito-case-author/checkout.ts +281 -0
- package/skills/fito-case-author/github-publish.js +218 -0
- package/skills/fito-case-author/github-publish.ts +251 -0
- package/skills/fito-case-author/publish-payload.js +108 -0
- package/skills/fito-case-author/publish-payload.ts +186 -0
- package/skills/fito-case-author/publish-state.js +72 -0
- package/skills/fito-case-author/publish-state.ts +87 -0
- package/skills/fito-case-author/publish-version.js +364 -0
- package/skills/fito-case-author/publish-version.ts +495 -0
- package/skills/fito-case-author/publish.js +284 -0
- package/skills/fito-case-author/publish.ts +394 -0
- package/skills/fito-case-author/semver.js +55 -0
- package/skills/fito-case-author/semver.ts +63 -0
- package/skills/fito-case-author/status-gate.js +34 -0
- package/skills/fito-case-author/status-gate.ts +54 -0
- package/skills/fito-case-author/validate.js +62 -0
- package/skills/fito-case-author/validate.ts +64 -0
- package/skills/fito-case-runner/SKILL.md +119 -0
- package/skills/fito-case-runner/case-component-names.js +45 -0
- package/skills/fito-case-runner/case-component-names.ts +65 -0
- package/skills/fito-case-runner/case-detail.js +20 -0
- package/skills/fito-case-runner/case-detail.ts +20 -0
- package/skills/fito-case-runner/github.js +234 -0
- package/skills/fito-case-runner/github.ts +287 -0
- package/skills/fito-case-runner/manifest.js +56 -0
- package/skills/fito-case-runner/manifest.ts +73 -0
- package/skills/fito-case-runner/open.js +175 -0
- package/skills/fito-case-runner/open.ts +241 -0
- package/skills/fito-case-runner/report.js +22 -0
- package/skills/fito-case-runner/report.ts +24 -0
- package/skills/fito-case-runner/runner.js +158 -0
- package/skills/fito-case-runner/runner.ts +304 -0
- package/skills/fito-case-runner/score-quiz-mc.js +85 -0
- package/skills/fito-case-runner/score-quiz-mc.ts +99 -0
- package/skills/fito-case-runner/submit-evaluation.js +73 -0
- package/skills/fito-case-runner/submit-evaluation.ts +98 -0
- package/skills/fito-case-runner/submit-quiz-result.js +75 -0
- package/skills/fito-case-runner/submit-quiz-result.ts +100 -0
- package/skills/fito-case-runner/submit.js +85 -0
- package/skills/fito-case-runner/submit.ts +111 -0
- package/skills/fito-case-runner/workdir.js +10 -0
- package/skills/fito-case-runner/workdir.ts +11 -0
- package/skills/fito-competence-write/SKILL.md +155 -0
- package/skills/fito-competence-write/create.js +64 -0
- package/skills/fito-competence-write/create.ts +80 -0
- package/skills/fito-competence-write/delete.js +136 -0
- package/skills/fito-competence-write/delete.ts +166 -0
- package/skills/fito-competence-write/display.js +20 -0
- package/skills/fito-competence-write/display.ts +21 -0
- package/skills/fito-competence-write/payload.js +96 -0
- package/skills/fito-competence-write/payload.ts +115 -0
- package/skills/fito-competence-write/update.js +155 -0
- package/skills/fito-competence-write/update.ts +206 -0
- package/skills/fito-evaluator/SKILL.md +73 -0
- package/skills/fito-evaluator/criterion-exec.js +64 -0
- package/skills/fito-evaluator/criterion-exec.ts +73 -0
- package/skills/fito-evaluator/evaluate-automated.js +57 -0
- package/skills/fito-evaluator/evaluate-automated.ts +84 -0
- package/skills/fito-evaluator/evaluate.js +28 -0
- package/skills/fito-evaluator/evaluate.ts +86 -0
- package/skills/fito-evaluator/report.js +112 -0
- package/skills/fito-evaluator/report.ts +128 -0
- package/skills/fito-evaluator/rubric.js +90 -0
- package/skills/fito-evaluator/rubric.ts +170 -0
- package/skills/fito-knowledge-push/SKILL.md +114 -0
- package/skills/fito-knowledge-push/push.js +282 -0
- package/skills/fito-knowledge-push/push.ts +360 -0
- package/skills/fito-source-ingestion/SKILL.md +77 -0
- package/skills/fito-source-ingestion/authoring-check.js +128 -0
- package/skills/fito-source-ingestion/authoring-check.ts +155 -0
- package/skills/fito-source-ingestion/bundle.js +198 -0
- package/skills/fito-source-ingestion/bundle.ts +246 -0
- package/skills/fito-technology-write/SKILL.md +108 -0
- package/skills/fito-technology-write/create.js +134 -0
- package/skills/fito-technology-write/create.ts +161 -0
- package/skills/fito-technology-write/payload.js +64 -0
- package/skills/fito-technology-write/payload.ts +70 -0
- package/skills/fito-technology-write/update.js +122 -0
- package/skills/fito-technology-write/update.ts +171 -0
- package/skills/fito-url-content-fetcher/SKILL.md +213 -0
- package/templates/concept-practice-content-template.md +281 -0
- package/templates/concept-tool-content-template.md +207 -0
- package/templates/execution-fact-practice-content-template.md +372 -0
- package/templates/execution-fact-tool-content-template.md +307 -0
- package/templates/usage-scenario-content-template.md +248 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
import { BRIEFING_KEYS, readCaseBriefing } from "../shared/case-briefing/briefing.ts";
|
|
5
|
+
import { listCompetences } from "../shared/competences/competence-list.ts";
|
|
6
|
+
import { COMPONENT_TYPES } from "../shared/fito-api/client.ts";
|
|
7
|
+
import { fetchKnowledgeComponent } from "../shared/knowledge-components/knowledge-fetch.ts";
|
|
8
|
+
import { searchKnowledgeComponents } from "../shared/knowledge-components/knowledge-search.ts";
|
|
9
|
+
import { fetchTechnology } from "../shared/knowledge-components/technology-fetch.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Side-effect-free registrar for the five Fito read-only fetch tools
|
|
13
|
+
* (`fito_knowledge_fetch`, `fito_knowledge_search`, `fito_technology_fetch`,
|
|
14
|
+
* `fito_competence_list`, `fito_case_partial_fetch`). The first four read the backend over HTTP;
|
|
15
|
+
* the fifth reads the learner's own `.case/` checkout through the `shared/case-briefing/` allow-list. None of them
|
|
16
|
+
* spawns a process or opens a caller-named path, which is what lets a persona denied `bash`,
|
|
17
|
+
* `read`, `edit` and `write` hold them (Success Criterion #9).
|
|
18
|
+
*
|
|
19
|
+
* Split out of `fito-startup.ts` (Task 9a.10) so the tools can be loaded into a
|
|
20
|
+
* `pi-subagents` **child** session via a persona's `subagentOnlyExtensions`: a bare
|
|
21
|
+
* tool name in a persona's `tools:` allowlist is *requested* but never *registered*
|
|
22
|
+
* in the child unless an extension that registers it is loaded there (see
|
|
23
|
+
* `.ai/lessons_learned.md` — subagent custom-tool propagation). The child *also*
|
|
24
|
+
* inherits the package's main extension `fito-startup.ts` (declared in
|
|
25
|
+
* `package.json`) via normal discovery, so **both** files are loaded there — but since
|
|
26
|
+
* Task 9b.11 (fix F28) `fito-startup.ts` registers the tools only when it is *not* in a
|
|
27
|
+
* child (`PI_SUBAGENT_CHILD`), which makes this module the child's **sole registrar** and
|
|
28
|
+
* is what actually prevents the duplicate. Ownership is split by process, not negotiated
|
|
29
|
+
* at registration time: `pi.getAllTools()` cannot be consulted during extension load (the
|
|
30
|
+
* runtime is not yet initialized — "Action methods cannot be called during extension
|
|
31
|
+
* loading"), so a registrar has no way to pre-check the registry. This module carries no
|
|
32
|
+
* `session_start`/persona-sync side effects; `fito-startup.ts` calls the same two
|
|
33
|
+
* registrars for the **main** session, where this module is not loaded at all.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/** Name of the in-process knowledge-fetch custom tool (ADR-006 amendment, Task 5.1b). */
|
|
37
|
+
export const KNOWLEDGE_FETCH_TOOL = "fito_knowledge_fetch";
|
|
38
|
+
|
|
39
|
+
/** Name of the in-process technology-fetch custom tool (ADR-011 §9, Task 9a.6a). */
|
|
40
|
+
export const TECHNOLOGY_FETCH_TOOL = "fito_technology_fetch";
|
|
41
|
+
|
|
42
|
+
/** Name of the in-process knowledge-search custom tool (Task 9c.11). */
|
|
43
|
+
export const KNOWLEDGE_SEARCH_TOOL = "fito_knowledge_search";
|
|
44
|
+
|
|
45
|
+
/** Name of the in-process competence-listing custom tool (Task 15b.6). */
|
|
46
|
+
export const COMPETENCE_LIST_TOOL = "fito_competence_list";
|
|
47
|
+
|
|
48
|
+
/** Name of the in-process case-briefing custom tool (Task 11.2). */
|
|
49
|
+
export const CASE_PARTIAL_FETCH_TOOL = "fito_case_partial_fetch";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Run a `pi.registerTool` call, swallowing *only* a duplicate-name conflict; any other
|
|
53
|
+
* registration error rethrows (Task 9a.10).
|
|
54
|
+
*
|
|
55
|
+
* **This is a belt-and-braces guard, not the mechanism that prevents the conflict.**
|
|
56
|
+
* Under the pinned pi (0.82.1) `registerTool` does not throw on a duplicate at all — it
|
|
57
|
+
* writes to a per-extension `Map` (`dist/core/extensions/loader.js`) and the clash surfaces
|
|
58
|
+
* afterwards from the post-load `detectExtensionConflicts` diagnostic
|
|
59
|
+
* (`dist/core/resource-loader.js`), which no `try`/`catch` here can reach. That is why
|
|
60
|
+
* F28 killed every fetch-tool subagent despite this wrapper. The duplicate is prevented
|
|
61
|
+
* upstream instead, by `fito-startup.ts` standing down inside a subagent child (Task 9b.11).
|
|
62
|
+
* The wrapper is kept because pi has not always behaved this way: on versions where
|
|
63
|
+
* `registerTool` *does* throw (a rollback to 0.80.10, say), removing it would break the
|
|
64
|
+
* child the other way — a load-time exception instead of a diagnostic.
|
|
65
|
+
*/
|
|
66
|
+
function registerToolTolerant(register: () => void): void {
|
|
67
|
+
try {
|
|
68
|
+
register();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (!/conflict|already registered/i.test(String(error))) throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Register the `fito_knowledge_fetch` tool: given a canonical knowledge-component id
|
|
76
|
+
* (`<type>:<tech-slug>.<component-slug>`, e.g. `concept:git.bisect`), resolve it to the
|
|
77
|
+
* component's structured content via the shared `fito-api` client. It is the former
|
|
78
|
+
* `fito-knowledge-fetcher` capability re-surfaced from a bash-skill onto a `pi.registerTool`
|
|
79
|
+
* tool so a no-bash persona — the `fito-tutor` worker (Task 11.3, Success Criterion #9) — can
|
|
80
|
+
* hold it: the tool's only effect is one in-process HTTP call (no shell/filesystem reach).
|
|
81
|
+
* Transport + logic stay in `shared/knowledge-components/` (pi-free); this `execute()` is a thin
|
|
82
|
+
* adapter, and failures throw so pi marks the result `isError`.
|
|
83
|
+
*/
|
|
84
|
+
export function registerFitoKnowledgeFetchTool(pi: ExtensionAPI): void {
|
|
85
|
+
registerToolTolerant(() => {
|
|
86
|
+
pi.registerTool({
|
|
87
|
+
name: KNOWLEDGE_FETCH_TOOL,
|
|
88
|
+
label: "Fetch Fito knowledge",
|
|
89
|
+
description:
|
|
90
|
+
"Fetch a Fito knowledge component's authoritative content from the backend by its " +
|
|
91
|
+
"canonical id (e.g. `concept:git.bisect`). Use whenever you hold a " +
|
|
92
|
+
"`<type>:<tech-slug>.<component-slug>` reference and need the component's real sections, " +
|
|
93
|
+
"version, or technology — to present a case's objectives or prerequisites, to ground an " +
|
|
94
|
+
"answer in the knowledge vocabulary, or when another Fito agent needs a component's text. " +
|
|
95
|
+
"Pass the optional `version` (a technology-version slug, e.g. `7`) to scope the read to one " +
|
|
96
|
+
"major line: a component live only for another version then reads as not-found, so an " +
|
|
97
|
+
"existence check never treats it as live. " +
|
|
98
|
+
"The backend is the source of truth, so fetch rather than recall. The read is public " +
|
|
99
|
+
"(no login). Returns the component as JSON.",
|
|
100
|
+
promptSnippet: "Fetch one Fito knowledge component's authoritative content by its canonical id",
|
|
101
|
+
promptGuidelines: [
|
|
102
|
+
`Use ${KNOWLEDGE_FETCH_TOOL} to ground an answer in the Fito knowledge vocabulary whenever you hold a <type>:<tech-slug>.<component-slug> reference, instead of recalling the component from memory.`,
|
|
103
|
+
],
|
|
104
|
+
parameters: Type.Object({
|
|
105
|
+
id: Type.String({
|
|
106
|
+
description:
|
|
107
|
+
"Canonical knowledge-component id `<type>:<tech-slug>.<component-slug>` " +
|
|
108
|
+
"(e.g. `concept:git.bisect`), where `<type>` is `concept`, `execution-fact`, or " +
|
|
109
|
+
"`usage-scenario` — the same id the backend returns and that cases store.",
|
|
110
|
+
}),
|
|
111
|
+
version: Type.Optional(
|
|
112
|
+
Type.String({
|
|
113
|
+
description:
|
|
114
|
+
"Optional technology-version slug (e.g. `7`) that scopes the read to one major " +
|
|
115
|
+
"line: a component live only for another version reads as not-found, so an " +
|
|
116
|
+
"existence check never treats it as live. Omit for a version-agnostic read.",
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
}),
|
|
120
|
+
async execute(_toolCallId, params) {
|
|
121
|
+
// The one place the two vocabularies meet: `version` is what agents type, and the
|
|
122
|
+
// seven identify/design artifacts type it, so the tool's own parameter cannot move.
|
|
123
|
+
// Everything below this line calls the axis by its name (Task 11.4a6-4).
|
|
124
|
+
const component = await fetchKnowledgeComponent(params.id, {
|
|
125
|
+
technologyVersion: params.version,
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
content: [{ type: "text", text: JSON.stringify(component, null, 2) }],
|
|
129
|
+
details: { component },
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Register the `fito_technology_fetch` tool: given a technology slug, resolve it to the technology
|
|
138
|
+
* and its major-line versions — each version's `description` carrying the compatibility prose
|
|
139
|
+
* (ADR-011 F7, e.g. "Javalin 7 requires Java 17+, runs on Jetty 12"). This is the read that lets
|
|
140
|
+
* the design / plan-source steps soft-cross-check the author's declared toolchain (ADR-011 §9,
|
|
141
|
+
* Task 9a.6a) — a check `fito_knowledge_fetch` cannot serve, since component reads deliberately
|
|
142
|
+
* carry no version prose. Like the knowledge tool, transport + backend-error mapping stay in
|
|
143
|
+
* `shared/knowledge-components/` (`fetchTechnology`); this `execute()` is a thin adapter over one
|
|
144
|
+
* in-process public HTTP read (no shell/filesystem reach), and failures throw so pi marks the
|
|
145
|
+
* result `isError`.
|
|
146
|
+
*/
|
|
147
|
+
export function registerFitoTechnologyFetchTool(pi: ExtensionAPI): void {
|
|
148
|
+
registerToolTolerant(() => {
|
|
149
|
+
pi.registerTool({
|
|
150
|
+
name: TECHNOLOGY_FETCH_TOOL,
|
|
151
|
+
label: "Fetch Fito technology",
|
|
152
|
+
description:
|
|
153
|
+
"Fetch a Fito technology's authoritative record from the backend by its slug (e.g. " +
|
|
154
|
+
"`javalin`), including its major-line versions and each version's compatibility prose " +
|
|
155
|
+
"(e.g. `Javalin 7 requires Java 17+ and runs on Jetty 12`). Use to cross-check a declared " +
|
|
156
|
+
"toolchain against a technology version's stated requirements before grounding a case's " +
|
|
157
|
+
"source in it. The backend is the source of truth, so fetch rather than recall. The read " +
|
|
158
|
+
"is public (no login). Returns the technology as JSON; a version's `description` is null " +
|
|
159
|
+
"when no prose was recorded.",
|
|
160
|
+
promptSnippet: "Fetch one Fito technology's versions and their compatibility prose by its slug",
|
|
161
|
+
promptGuidelines: [
|
|
162
|
+
`Use ${TECHNOLOGY_FETCH_TOOL} to read a technology version's compatibility prose (its \`description\`) when cross-checking a declared toolchain, instead of recalling the requirement from memory.`,
|
|
163
|
+
],
|
|
164
|
+
parameters: Type.Object({
|
|
165
|
+
slug: Type.String({
|
|
166
|
+
description:
|
|
167
|
+
"The technology's slug (e.g. `javalin`, `kotlin`) — the same slug that forms the " +
|
|
168
|
+
"middle segment of a knowledge-component id `<type>:<tech-slug>.<component-slug>`.",
|
|
169
|
+
}),
|
|
170
|
+
}),
|
|
171
|
+
async execute(_toolCallId, params) {
|
|
172
|
+
const technology = await fetchTechnology(params.slug);
|
|
173
|
+
return {
|
|
174
|
+
content: [{ type: "text", text: JSON.stringify(technology, null, 2) }],
|
|
175
|
+
details: { technology },
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Register the `fito_knowledge_search` tool: given a technology slug, list that technology's
|
|
184
|
+
* knowledge components as recognisable summaries. It is the **enumeration** its point-lookup sibling
|
|
185
|
+
* cannot serve — `fito_knowledge_fetch` requires the very id being sought, and `fito_technology_fetch`
|
|
186
|
+
* returns component *counts* with no ids — which left `/fito-case-design` deriving candidate ids from
|
|
187
|
+
* guessed component names and probing them one at a time (Task 9c.11, finding F37).
|
|
188
|
+
*
|
|
189
|
+
* **Why guess-and-probe fails on a practice in particular.** A tool's slugs are derivable from its
|
|
190
|
+
* API, so a model that knows Javalin can guess `context`, `handler`, `route`. A practice's vocabulary
|
|
191
|
+
* is *coined*: the checkpoint run guessed Specification by Example's seven process-pattern names —
|
|
192
|
+
* the most defensible hypothesis available, since the practice's own version description enumerates
|
|
193
|
+
* them — and all seven missed, because the identifier had keyed on the transformation-chain artifacts
|
|
194
|
+
* instead. Two equally sound namings existed and nothing told the caller which was chosen; the run
|
|
195
|
+
* resolved 4 of 21 components across ~20 probes. The prompt was followed exactly — the algorithm is
|
|
196
|
+
* what failed.
|
|
197
|
+
*
|
|
198
|
+
* Transport + logic stay in `shared/knowledge-components/` (pi-free); this `execute()` is a thin
|
|
199
|
+
* adapter, and failures throw so pi marks the result `isError`.
|
|
200
|
+
*/
|
|
201
|
+
export function registerFitoKnowledgeSearchTool(pi: ExtensionAPI): void {
|
|
202
|
+
registerToolTolerant(() => {
|
|
203
|
+
pi.registerTool({
|
|
204
|
+
name: KNOWLEDGE_SEARCH_TOOL,
|
|
205
|
+
label: "Search Fito knowledge",
|
|
206
|
+
description:
|
|
207
|
+
"List a Fito technology's knowledge components — their canonical ids, types, names, " +
|
|
208
|
+
"bound versions, and a short summary — so you can **choose** components instead of " +
|
|
209
|
+
"guessing their ids. Use whenever you need to know what a technology covers: scoping a " +
|
|
210
|
+
"case, checking whether a topic exists in the vocabulary, or finding the id of a " +
|
|
211
|
+
"component you can only describe in words. Prefer this over deriving an id from a " +
|
|
212
|
+
"component's likely name; a practice's vocabulary is coined by whoever authored it and " +
|
|
213
|
+
"is not guessable. Pass the optional `version` (a technology-version slug, e.g. `7`) to " +
|
|
214
|
+
"scope the listing to one major line, so a component that is not live at that version " +
|
|
215
|
+
"never reaches a proposal. Each result's `tl_dr` is **truncated** to roughly 225 " +
|
|
216
|
+
"characters and marked with ` [...]` when cut — fetch the component with " +
|
|
217
|
+
"`fito_knowledge_fetch` for its full summary and all its other content. The backend is " +
|
|
218
|
+
"the source of truth, so search rather than recall. The read is public (no login). " +
|
|
219
|
+
"Returns a JSON array, empty when nothing matches.",
|
|
220
|
+
promptSnippet: "List a Fito technology's knowledge components with their ids, versions and summaries",
|
|
221
|
+
promptGuidelines: [
|
|
222
|
+
`Use ${KNOWLEDGE_SEARCH_TOOL} to enumerate a technology's knowledge components before you reference any of them, instead of deriving a canonical id from a component's likely name.`,
|
|
223
|
+
],
|
|
224
|
+
parameters: Type.Object({
|
|
225
|
+
technology: Type.String({
|
|
226
|
+
description:
|
|
227
|
+
"The technology's slug (e.g. `javalin`, `specification-by-example`) — the middle " +
|
|
228
|
+
"segment of a knowledge-component id `<type>:<tech-slug>.<component-slug>`. " +
|
|
229
|
+
"Required: a version slug is unique only within a technology, so an unscoped " +
|
|
230
|
+
"listing could not be version-filtered meaningfully.",
|
|
231
|
+
}),
|
|
232
|
+
version: Type.Optional(
|
|
233
|
+
Type.String({
|
|
234
|
+
description:
|
|
235
|
+
"Optional technology-version slug (e.g. `7`) that scopes the listing to one " +
|
|
236
|
+
"major line: a component is kept when any version it is bound to matches. " +
|
|
237
|
+
"Omit for a version-agnostic listing.",
|
|
238
|
+
}),
|
|
239
|
+
),
|
|
240
|
+
// A literal union rather than a free string, so an invalid type is rejected at the
|
|
241
|
+
// tool boundary instead of becoming a backend error the caller has to interpret.
|
|
242
|
+
type: Type.Optional(
|
|
243
|
+
Type.Union(
|
|
244
|
+
COMPONENT_TYPES.map((componentType) => Type.Literal(componentType)),
|
|
245
|
+
{
|
|
246
|
+
description:
|
|
247
|
+
"Optional component type — `concept`, `execution-fact`, or " +
|
|
248
|
+
"`usage-scenario`. Omit to list all three.",
|
|
249
|
+
},
|
|
250
|
+
),
|
|
251
|
+
),
|
|
252
|
+
q: Type.Optional(
|
|
253
|
+
Type.String({
|
|
254
|
+
description:
|
|
255
|
+
"Optional free-text filter matched against component names and content. Omit " +
|
|
256
|
+
"to list the technology's components in full, which is the usual case.",
|
|
257
|
+
}),
|
|
258
|
+
),
|
|
259
|
+
}),
|
|
260
|
+
async execute(_toolCallId, params) {
|
|
261
|
+
const components = await searchKnowledgeComponents(params.technology, {
|
|
262
|
+
version: params.version,
|
|
263
|
+
type: params.type,
|
|
264
|
+
q: params.q,
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
content: [{ type: "text", text: JSON.stringify(components, null, 2) }],
|
|
268
|
+
details: { components },
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Register the `fito_competence_list` tool: given a technology slug, list the competences that
|
|
277
|
+
* technology directly demands, each with its sub-competence tree (Task 15b.6). It is the read an
|
|
278
|
+
* author chooses from — none of the other fetch tools touches a competence, so without it the
|
|
279
|
+
* competence-authoring flow could not show what exists or name the one to edit or delete.
|
|
280
|
+
*
|
|
281
|
+
* **A tool rather than a skill-script print-out**, because the sibling flow already reads this way:
|
|
282
|
+
* `/fito-create-or-update-technology` reads what the vocabulary holds with `fito_technology_fetch`
|
|
283
|
+
* before drafting, and splitting reads between a tool and a script would make the competence flow
|
|
284
|
+
* the only one that does.
|
|
285
|
+
*
|
|
286
|
+
* **The record passes through whole**, sub-competences included (author's decision at planning): a
|
|
287
|
+
* delete removes the whole tree, so the author sees what goes. The description names what the wire
|
|
288
|
+
* withholds — the owner, and each element's name and content — so the model asks the write, or
|
|
289
|
+
* `fito_knowledge_fetch`, rather than guessing.
|
|
290
|
+
*
|
|
291
|
+
* Transport + error mapping stay in `shared/` (pi-free); this `execute()` is a thin adapter over one
|
|
292
|
+
* in-process public HTTP read, and failures throw so pi marks the result `isError`.
|
|
293
|
+
*/
|
|
294
|
+
export function registerFitoCompetenceListTool(pi: ExtensionAPI): void {
|
|
295
|
+
registerToolTolerant(() => {
|
|
296
|
+
pi.registerTool({
|
|
297
|
+
name: COMPETENCE_LIST_TOOL,
|
|
298
|
+
label: "List Fito competences",
|
|
299
|
+
description:
|
|
300
|
+
"List the competences a Fito technology demands, by the technology's slug (e.g. " +
|
|
301
|
+
"`javalin`) — each with its id, name, description, element references, and its " +
|
|
302
|
+
"sub-competences nested under `components`. Use it before drafting a competence, to see " +
|
|
303
|
+
"what the technology already holds, and to find the id of a competence to edit or " +
|
|
304
|
+
"delete. The list holds top-level competences only; a sub-competence appears inside its " +
|
|
305
|
+
"parent. Two things are deliberately withheld. The list carries no owner, so it cannot " +
|
|
306
|
+
"tell who may edit or delete a competence — the write itself answers that. And an " +
|
|
307
|
+
"element is a bare `<type>:<tech-slug>.<component-slug>` reference — fetch the " +
|
|
308
|
+
"component with `fito_knowledge_fetch` for its name and content. The backend is the " +
|
|
309
|
+
"source of truth, so list rather than recall. The read is public (no login). Returns a " +
|
|
310
|
+
"JSON array, empty when the technology demands no competence; an unknown technology is " +
|
|
311
|
+
"an error.",
|
|
312
|
+
promptSnippet: "List a Fito technology's competences with their ids, elements and sub-competences",
|
|
313
|
+
promptGuidelines: [
|
|
314
|
+
`Use ${COMPETENCE_LIST_TOOL} to read a technology's competences before drafting, editing or deleting one, instead of recalling which competences exist or deriving a competence id.`,
|
|
315
|
+
],
|
|
316
|
+
parameters: Type.Object({
|
|
317
|
+
technology: Type.String({
|
|
318
|
+
description:
|
|
319
|
+
"The technology's slug (e.g. `javalin`, `specification-by-example`) — the middle " +
|
|
320
|
+
"segment of a knowledge-component id `<type>:<tech-slug>.<component-slug>`.",
|
|
321
|
+
}),
|
|
322
|
+
}),
|
|
323
|
+
async execute(_toolCallId, params) {
|
|
324
|
+
const competences = await listCompetences(params.technology);
|
|
325
|
+
return {
|
|
326
|
+
content: [{ type: "text", text: JSON.stringify(competences, null, 2) }],
|
|
327
|
+
details: { competences },
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Register the `fito_case_partial_fetch` tool: given a case id and one of an enumerated set of
|
|
336
|
+
* document **keys**, return that part of the learner's local `.case/` checkout. It is the read the
|
|
337
|
+
* `fito-tutor` worker (Task 11.3) is given *instead of* filesystem access — the tutor must reach the
|
|
338
|
+
* case it is scoped to without being able to reach the exemplar solution, the rubric scoring key or
|
|
339
|
+
* the quiz answers (Success Criterion #9).
|
|
340
|
+
*
|
|
341
|
+
* **Why a key and not a path.** A path parameter — however filtered — would rest the containment
|
|
342
|
+
* claim on a string check applied to model input, and the model on the other end is in adversarial
|
|
343
|
+
* conversation with a learner by design. The served set is instead a closed constant in
|
|
344
|
+
* `shared/case-briefing/`, so what this tool can reach is a property of the code; the denied
|
|
345
|
+
* artifacts are asserted by name across *every* key there, including keys added later.
|
|
346
|
+
*
|
|
347
|
+
* **The name states the restriction, and the unrestricted name is deliberately left
|
|
348
|
+
* unregistered.** `fito_case_fetch` — a tool serving a case's *whole* `.case/`, the exemplar
|
|
349
|
+
* solution, rubric key and quiz answers included — belongs in a **separate future tool**, added
|
|
350
|
+
* when a real consumer appears. None has: the `fito-performance-reviewer` persona and the
|
|
351
|
+
* authoring prompts all hold direct filesystem access already. Growing *this* tool into that one
|
|
352
|
+
* would silently widen every persona that allow-lists case reads, starting with the one it exists
|
|
353
|
+
* for — a tutor in adversarial conversation with the learner by design.
|
|
354
|
+
*
|
|
355
|
+
* Selection and reading stay in `shared/case-briefing/` (pi-free); this `execute()` is a thin
|
|
356
|
+
* adapter over one in-process read of a directory the learner already has on disk — no shell, no
|
|
357
|
+
* caller-named path — and failures throw so pi marks the result `isError`, carrying the module's
|
|
358
|
+
* single-line message (a raw `ENOENT` would tell the learner nothing).
|
|
359
|
+
*/
|
|
360
|
+
export function registerFitoCasePartialFetchTool(pi: ExtensionAPI): void {
|
|
361
|
+
registerToolTolerant(() => {
|
|
362
|
+
pi.registerTool({
|
|
363
|
+
name: CASE_PARTIAL_FETCH_TOOL,
|
|
364
|
+
label: "Fetch Fito case briefing",
|
|
365
|
+
description:
|
|
366
|
+
"Read one part of a Fito case the learner has open locally, by case id and document " +
|
|
367
|
+
"key. Use it to ground an answer in what the case actually says — its situation, its " +
|
|
368
|
+
"task, the artifacts it points at, the state it starts from, or the knowledge " +
|
|
369
|
+
"components it references — instead of recalling or guessing. Access is **partial by " +
|
|
370
|
+
"design**: the case's exemplar solution, its rubric scoring key and its quiz answers " +
|
|
371
|
+
"are never served through any key, and asking for them is not an error to work " +
|
|
372
|
+
"around. Requires the learner to have opened the case with `/fito-case-open`. Returns " +
|
|
373
|
+
"the key's documents as JSON, each with the `.case/`-relative file it came from so " +
|
|
374
|
+
"you can cite it.",
|
|
375
|
+
promptSnippet: "Read one part of a locally opened Fito case (situation, task, artifacts, …) by key",
|
|
376
|
+
promptGuidelines: [
|
|
377
|
+
`Use ${CASE_PARTIAL_FETCH_TOOL} to read what a case says before answering a question about it, instead of relying on what you were told about the case earlier in the conversation.`,
|
|
378
|
+
],
|
|
379
|
+
parameters: Type.Object({
|
|
380
|
+
caseId: Type.String({
|
|
381
|
+
description:
|
|
382
|
+
"The case's id, as minted by the backend and used for the learner's checkout " +
|
|
383
|
+
"directory — a single path segment, not a path and not a title.",
|
|
384
|
+
}),
|
|
385
|
+
key: Type.String({
|
|
386
|
+
description:
|
|
387
|
+
`Which part of the case to read. One of: ${BRIEFING_KEYS.join(", ")}. ` +
|
|
388
|
+
"`manifest` is the case's title, type, version, tags and estimated duration; " +
|
|
389
|
+
"`situation` the scenario documents in reading order; `task` the objective, " +
|
|
390
|
+
"constraints, steps and deliverables; `artifacts` the annotated map of the files " +
|
|
391
|
+
"the case works on; `starter_state` the baseline the learner starts from; " +
|
|
392
|
+
"`knowledge_refs` the knowledge components the case teaches and assumes (fetch " +
|
|
393
|
+
"those with `fito_knowledge_fetch`).",
|
|
394
|
+
}),
|
|
395
|
+
}),
|
|
396
|
+
async execute(_toolCallId, params) {
|
|
397
|
+
const briefing = readCaseBriefing(params.caseId, params.key);
|
|
398
|
+
return {
|
|
399
|
+
content: [{ type: "text", text: JSON.stringify(briefing, null, 2) }],
|
|
400
|
+
details: { briefing },
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Register all five Fito fetch tools. This is the module's `default` export so it can be
|
|
409
|
+
* named as a persona's `subagentOnlyExtensions` entry — `pi-subagents` loads the file
|
|
410
|
+
* as a `--extension` in the child, and the registered tool names then survive the
|
|
411
|
+
* child's strict `--tools` allowlist (Task 9a.10; pi-subagents README §subagentOnlyExtensions).
|
|
412
|
+
*/
|
|
413
|
+
export default function registerFitoFetchTools(pi: ExtensionAPI): void {
|
|
414
|
+
registerFitoKnowledgeFetchTool(pi);
|
|
415
|
+
registerFitoKnowledgeSearchTool(pi);
|
|
416
|
+
registerFitoTechnologyFetchTool(pi);
|
|
417
|
+
registerFitoCompetenceListTool(pi);
|
|
418
|
+
registerFitoCasePartialFetchTool(pi);
|
|
419
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { FitoApiError, createFitoApiClient } from "../shared/fito-api/client.js";
|
|
4
|
+
import { registerFitoDelegateTool } from "./fito-delegate.js";
|
|
5
|
+
import { registerFitoCasePartialFetchTool, registerFitoCompetenceListTool, registerFitoKnowledgeFetchTool, registerFitoKnowledgeSearchTool, registerFitoTechnologyFetchTool, } from "./fito-fetch-tools.js";
|
|
6
|
+
/**
|
|
7
|
+
* Fito startup extension.
|
|
8
|
+
*
|
|
9
|
+
* **The persona sync is gone.** Until 2026-09-17 this extension copied the
|
|
10
|
+
* package's `agents/*.md` into the session's `.pi/agents/` at every
|
|
11
|
+
* `session_start`, because ADR-002 Decision 3 had verified that `pi-subagents`
|
|
12
|
+
* read personas only from hardcoded roots. That premise expired: `pi-subagents`
|
|
13
|
+
* now discovers a package's own agent directories from its manifest
|
|
14
|
+
* (`{"pi-subagents":{"agents":["agents"]}}`, its `docs/agents.md`), so
|
|
15
|
+
* `tui/package.json` declares `agents/` and the personas are read **in place**.
|
|
16
|
+
* Nothing is copied, so nothing can be copied to the wrong place — the old walk
|
|
17
|
+
* accepted the learner's `~/.pi/` as a project root and, from any directory
|
|
18
|
+
* without a marker of its own, wrote seventeen personas into their home that no
|
|
19
|
+
* reader ever looked at. See ADR-002's 2026-09-17 revision.
|
|
20
|
+
*
|
|
21
|
+
* What remains here is the `session_start` checks — the guard for the missing
|
|
22
|
+
* `subagent` tool, the `pi-subagents` version floor, and the backend's refusal of this
|
|
23
|
+
* TUI's version (both Task 15d.7b) — and registration of Fito-owned custom tools (`pi.registerTool(...)`)
|
|
24
|
+
* for the **main**
|
|
25
|
+
* session: `fito_knowledge_fetch` (Task 5.1b), the in-process knowledge-component
|
|
26
|
+
* read that the `fito-tutor` worker holds while denied bash/filesystem (Success
|
|
27
|
+
* Criterion #9; ADR-006), `fito_technology_fetch` (Task 9a.6a), the
|
|
28
|
+
* technology-version read that grounds the design / plan-source toolchain
|
|
29
|
+
* cross-check (ADR-011 §9), `fito_knowledge_search` (Task 9c.11), the
|
|
30
|
+
* component listing `/fito-case-design` selects from instead of guessing ids —
|
|
31
|
+
* a flow that runs **here**, in the main session, which is why the tool has to be
|
|
32
|
+
* registered at this call site and not only in the child registrar —
|
|
33
|
+
* `fito_competence_list` (Task 15b.6), a technology's competences, registered here for the
|
|
34
|
+
* same reason: the competence-authoring flow that reads it runs in the main session — and
|
|
35
|
+
* `fito_case_partial_fetch` (Task 11.2), the allow-listed read of a locally opened
|
|
36
|
+
* case that the `fito-tutor` worker holds in place of filesystem access. The registrars
|
|
37
|
+
* live in `./fito-fetch-tools.ts` so the
|
|
38
|
+
* same tools can be loaded into a subagent **child** via a persona's
|
|
39
|
+
* `subagentOnlyExtensions` (Task 9a.10) — a bare allowlist name alone does not
|
|
40
|
+
* register the tool in the child's separate pi process.
|
|
41
|
+
*
|
|
42
|
+
* **Registration is main-session-only** (Task 9b.11, fix F28). A `pi-subagents` child
|
|
43
|
+
* loads *both* registrars: this extension still arrives through package auto-discovery
|
|
44
|
+
* — `pi-subagents` passes `--no-extensions` only when a persona declares `extensions:`,
|
|
45
|
+
* and ours declare only `subagentOnlyExtensions` — while the persona additionally loads
|
|
46
|
+
* `./fito-fetch-tools.ts` explicitly. Two extensions owning one tool name is what pi's
|
|
47
|
+
* post-load `detectExtensionConflicts` reports, and in the headless child that diagnostic
|
|
48
|
+
* is **fatal**: every fetch-tool persona died at spawn ("Failed to load extension …").
|
|
49
|
+
* So the child takes every fetch tool from `./fito-fetch-tools.ts` alone, and this extension
|
|
50
|
+
* stands down — detected via `PI_SUBAGENT_CHILD`, which `pi-subagents` sets to `"1"` for
|
|
51
|
+
* every child it spawns and compares the same way in its own extension.
|
|
52
|
+
*
|
|
53
|
+
* That leaves the persona as the child's *only* source for these tools, so the other half
|
|
54
|
+
* of the contract is enforced in `../agents/knowledge-pipeline-artifacts.test.ts`: every
|
|
55
|
+
* persona whose `tools:` names a `fito_*` tool must declare `subagentOnlyExtensions`, or
|
|
56
|
+
* its child allow-lists a tool that nothing registers.
|
|
57
|
+
*
|
|
58
|
+
* The same guard also scopes `fito_delegate` (Task 11.8, `./fito-delegate.ts`) to the main session —
|
|
59
|
+
* for a third reason, neither F28's nor the marker's: delegation is what a session does *to* a
|
|
60
|
+
* child, so registering it in a child would hand a worker the means to delegate onward. It carries
|
|
61
|
+
* `pi-subagents`' launch parameters in TypeScript so no Fito prompt has to name them in prose
|
|
62
|
+
* (lesson 82), and it registers here rather than in `./fito-fetch-tools.ts` precisely because that
|
|
63
|
+
* module is the *child's* registrar.
|
|
64
|
+
*
|
|
65
|
+
* **The run-id marker that used to register here is gone** (Task 11.4a, retired at 11.8b). It
|
|
66
|
+
* appended a Fito-worded run id to every `subagent` tool result, because `/fito-tutor` had to read
|
|
67
|
+
* that id out of prose to resume its thread. `fito_delegate` now runs the tutor's thread and holds
|
|
68
|
+
* the id itself, so there is no vendor tool result left to annotate and no reader for the line.
|
|
69
|
+
*/
|
|
70
|
+
export default function registerFitoStartup(pi) {
|
|
71
|
+
if (process.env.PI_SUBAGENT_CHILD !== "1") {
|
|
72
|
+
registerFitoKnowledgeFetchTool(pi);
|
|
73
|
+
registerFitoKnowledgeSearchTool(pi);
|
|
74
|
+
registerFitoTechnologyFetchTool(pi);
|
|
75
|
+
registerFitoCompetenceListTool(pi);
|
|
76
|
+
registerFitoCasePartialFetchTool(pi);
|
|
77
|
+
registerFitoDelegateTool(pi);
|
|
78
|
+
}
|
|
79
|
+
pi.on("session_start", (_event, ctx) => {
|
|
80
|
+
if (!ctx.hasUI)
|
|
81
|
+
return;
|
|
82
|
+
// Say so when the delegation transport is absent. Eleven Fito commands reach a worker
|
|
83
|
+
// persona through `pi-subagents`, so without it they fail one by one at the point of use;
|
|
84
|
+
// this turns that into a single message naming the install command (ADR-002 Decision 2 —
|
|
85
|
+
// Fito requires it as a separate install and does not bundle it).
|
|
86
|
+
const subagent = pi.getAllTools().find((tool) => tool.name === "subagent");
|
|
87
|
+
if (subagent === undefined) {
|
|
88
|
+
ctx.ui.notify("Fito requires the 'subagent' tool, which is not installed. " +
|
|
89
|
+
"Install it with: pi install npm:pi-subagents", "error");
|
|
90
|
+
}
|
|
91
|
+
if (process.env.PI_SUBAGENT_CHILD === "1")
|
|
92
|
+
return;
|
|
93
|
+
if (subagent !== undefined && isBelowPiSubagentsFloor(subagent.sourceInfo)) {
|
|
94
|
+
ctx.ui.notify(`Fito needs pi-subagents ${PI_SUBAGENTS_FLOOR.join(".")} or newer. Run: \`pi update --extensions\``, "error");
|
|
95
|
+
}
|
|
96
|
+
// Not awaited: pi awaits what a handler returns, so the start would wait for the backend.
|
|
97
|
+
void warnIfTuiTooOld(ctx);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The oldest `pi-subagents` Fito works with (ADR-002 Decision 3, "Version floor"): Fito's personas
|
|
102
|
+
* need a relative `subagentOnlyExtensions` path resolved against the persona's own folder, which
|
|
103
|
+
* 0.68.0 does and 0.50.0 does not. The backend cannot see `pi-subagents`, so this check and its
|
|
104
|
+
* message are built into the TUI (Task 15d.7b).
|
|
105
|
+
*/
|
|
106
|
+
const PI_SUBAGENTS_FLOOR = [0, 68, 0];
|
|
107
|
+
/**
|
|
108
|
+
* Whether the `pi-subagents` that registered the `subagent` tool is older than the floor. pi names
|
|
109
|
+
* that package's folder in `sourceInfo.baseDir`, and the version is its `package.json`'s. `false`
|
|
110
|
+
* whenever the version cannot be read — no folder, no readable file, another package's file, or a
|
|
111
|
+
* version that does not start with three numbers — so a fault in the check never shows a message.
|
|
112
|
+
*/
|
|
113
|
+
function isBelowPiSubagentsFloor(sourceInfo) {
|
|
114
|
+
if (sourceInfo.baseDir === undefined)
|
|
115
|
+
return false;
|
|
116
|
+
let version;
|
|
117
|
+
try {
|
|
118
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(sourceInfo.baseDir, "package.json"), "utf8"));
|
|
119
|
+
version = manifest?.name === "pi-subagents" ? manifest.version : undefined;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (typeof version !== "string")
|
|
125
|
+
return false;
|
|
126
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
127
|
+
if (match === null)
|
|
128
|
+
return false;
|
|
129
|
+
const installed = match.slice(1).map(Number);
|
|
130
|
+
const differing = installed.findIndex((number, index) => number !== PI_SUBAGENTS_FLOOR[index]);
|
|
131
|
+
return differing !== -1 && installed[differing] < PI_SUBAGENTS_FLOOR[differing];
|
|
132
|
+
}
|
|
133
|
+
/** The problem `type` of the backend's refusal of a TUI older than its minimum (Task 15d.7a). */
|
|
134
|
+
const TUI_TOO_OLD = "/problems/tui-too-old";
|
|
135
|
+
/** How long the start check waits for the backend before it gives up and shows nothing. */
|
|
136
|
+
const HEALTH_TIMEOUT_MS = 10_000;
|
|
137
|
+
/**
|
|
138
|
+
* Shows the backend's message when it refuses this TUI's version (Task 15d.7b). The backend refuses
|
|
139
|
+
* an old TUI at its first request (Task 15d.7a), which can be in the middle of a case; this asks once,
|
|
140
|
+
* as pi starts. `GET /actuator/health` needs no login and writes no `learning_events` row.
|
|
141
|
+
*
|
|
142
|
+
* The message is the backend's `detail`, not text built into the TUI: an old TUI is frozen code, and
|
|
143
|
+
* the backend's message can still change. Any other answer shows nothing — the backend is up, down,
|
|
144
|
+
* unreachable or silent past the timeout — because the check exists for one answer only.
|
|
145
|
+
*
|
|
146
|
+
* It never rejects. The answer can arrive after `/new`, `/resume`, `/fork` or `/reload` replaced the
|
|
147
|
+
* session, when pi refuses the old `ctx`, and an unhandled rejection can end the pi process.
|
|
148
|
+
*/
|
|
149
|
+
export async function warnIfTuiTooOld(ctx) {
|
|
150
|
+
let refusal;
|
|
151
|
+
try {
|
|
152
|
+
await createFitoApiClient().getHealth({ signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS) });
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error instanceof FitoApiError && error.type === TUI_TOO_OLD)
|
|
156
|
+
refusal = error.message;
|
|
157
|
+
}
|
|
158
|
+
if (refusal === undefined)
|
|
159
|
+
return;
|
|
160
|
+
try {
|
|
161
|
+
ctx.ui.notify(refusal, "error");
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// The session was replaced while the call was out; the new session runs its own check.
|
|
165
|
+
}
|
|
166
|
+
}
|