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