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,75 @@
1
+ /**
2
+ * `node submit-quiz-result.js <submission-id> <scores-json-path>` — records a submission's quiz
3
+ * outcome (Task 7.3). After `submit.ts` has recorded the submission and the `fito-performance-reviewer`
4
+ * subagent has scored the quiz, the `/fito-submit` orchestrator writes the reviewer's per-question JSON
5
+ * array to a file and runs this to POST it to `POST /submissions/{id}/quiz-result`. The reviewer never
6
+ * touches the backend (its persona is network-free); this is where the recorded quiz scores reach Fito.
7
+ * (`/fito-evaluate` administers the same quiz as a local practice run and does **not** call this — it
8
+ * records nothing.)
9
+ *
10
+ * `runSubmitQuizResult` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
11
+ * Re-runnable: the backend replaces a submission's quiz result, so a retried `/fito-submit` re-POSTs safely.
12
+ */
13
+ import { existsSync, readFileSync } from "node:fs";
14
+ import * as os from "node:os";
15
+ import * as path from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+ import { z } from "zod";
18
+ import { createFitoApiClient, questionScoreResultSchema, } from "../../shared/fito-api/client.js";
19
+ import { resolveFitoSession } from "../../shared/fito-session/session.js";
20
+ /** The reviewer hands its quiz scores as a JSON array of per-question results. */
21
+ const scoresFileSchema = z.array(questionScoreResultSchema);
22
+ /** Read + validate the reviewer's scores file, resolve the Fito session, and POST the quiz result. */
23
+ export async function runSubmitQuizResult(options) {
24
+ const home = options.home ?? os.homedir();
25
+ const client = options.client ?? createFitoApiClient();
26
+ const perQuestionScores = readScores(options.scoresPath);
27
+ const { tokens } = await resolveFitoSession(client, home);
28
+ return client.submitQuizResult(tokens.accessToken, options.submissionId, perQuestionScores);
29
+ }
30
+ /** Load the reviewer's JSON scores file, failing with an actionable message on any malformed input. */
31
+ function readScores(scoresPath) {
32
+ if (!existsSync(scoresPath)) {
33
+ throw new Error(`No quiz scores file at:\n ${scoresPath}`);
34
+ }
35
+ let raw;
36
+ try {
37
+ raw = readFileSync(scoresPath, "utf8");
38
+ }
39
+ catch (error) {
40
+ const detail = error instanceof Error ? error.message : String(error);
41
+ throw new Error(`Could not read the quiz scores file:\n ${scoresPath}\n (${detail})`);
42
+ }
43
+ let parsed;
44
+ try {
45
+ parsed = JSON.parse(raw);
46
+ }
47
+ catch {
48
+ throw new Error(`The quiz scores file is not valid JSON:\n ${scoresPath}`);
49
+ }
50
+ const result = scoresFileSchema.safeParse(parsed);
51
+ if (!result.success) {
52
+ throw new Error(`The quiz scores do not match the expected shape (a JSON array of per-question scores):\n${result.error.message}`);
53
+ }
54
+ return result.data;
55
+ }
56
+ async function main() {
57
+ const submissionId = process.argv[2];
58
+ const scoresPath = process.argv[3];
59
+ if (!submissionId || !scoresPath) {
60
+ console.error("Usage: node submit-quiz-result.js <submission-id> <scores-json-path>");
61
+ process.exitCode = 1;
62
+ return;
63
+ }
64
+ const submission = await runSubmitQuizResult({ submissionId, scoresPath });
65
+ console.log(`✓ Quiz result recorded for submission ${submission.id} (status: ${submission.status}).`);
66
+ }
67
+ /** Only auto-invoke the CLI when run directly (`node submit-quiz-result.js …`), not when imported. */
68
+ const entry = process.argv[1];
69
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
70
+ if (isMainModule) {
71
+ main().catch((error) => {
72
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
73
+ process.exitCode = 1;
74
+ });
75
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * `node submit-quiz-result.js <submission-id> <scores-json-path>` — records a submission's quiz
3
+ * outcome (Task 7.3). After `submit.ts` has recorded the submission and the `fito-performance-reviewer`
4
+ * subagent has scored the quiz, the `/fito-submit` orchestrator writes the reviewer's per-question JSON
5
+ * array to a file and runs this to POST it to `POST /submissions/{id}/quiz-result`. The reviewer never
6
+ * touches the backend (its persona is network-free); this is where the recorded quiz scores reach Fito.
7
+ * (`/fito-evaluate` administers the same quiz as a local practice run and does **not** call this — it
8
+ * records nothing.)
9
+ *
10
+ * `runSubmitQuizResult` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
11
+ * Re-runnable: the backend replaces a submission's quiz result, so a retried `/fito-submit` re-POSTs safely.
12
+ */
13
+ import { existsSync, readFileSync } from "node:fs";
14
+ import * as os from "node:os";
15
+ import * as path from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ import { z } from "zod";
19
+
20
+ import {
21
+ type FitoApiClient,
22
+ type QuestionScoreResult,
23
+ type SubmissionResponse,
24
+ createFitoApiClient,
25
+ questionScoreResultSchema,
26
+ } from "../../shared/fito-api/client.ts";
27
+ import { resolveFitoSession } from "../../shared/fito-session/session.ts";
28
+
29
+ /** The fito-api surface this flow needs: the authenticated session lookup + the quiz-result POST. */
30
+ type SubmitQuizResultClient = Pick<FitoApiClient, "meWithRefresh" | "submitQuizResult">;
31
+
32
+ /** The reviewer hands its quiz scores as a JSON array of per-question results. */
33
+ const scoresFileSchema = z.array(questionScoreResultSchema);
34
+
35
+ export interface RunSubmitQuizResultOptions {
36
+ submissionId: string;
37
+ /** Path to the JSON file holding the reviewer's per-question scores array. */
38
+ scoresPath: string;
39
+ home?: string;
40
+ client?: SubmitQuizResultClient;
41
+ }
42
+
43
+ /** Read + validate the reviewer's scores file, resolve the Fito session, and POST the quiz result. */
44
+ export async function runSubmitQuizResult(options: RunSubmitQuizResultOptions): Promise<SubmissionResponse> {
45
+ const home = options.home ?? os.homedir();
46
+ const client = options.client ?? createFitoApiClient();
47
+
48
+ const perQuestionScores = readScores(options.scoresPath);
49
+ const { tokens } = await resolveFitoSession(client, home);
50
+ return client.submitQuizResult(tokens.accessToken, options.submissionId, perQuestionScores);
51
+ }
52
+
53
+ /** Load the reviewer's JSON scores file, failing with an actionable message on any malformed input. */
54
+ function readScores(scoresPath: string): QuestionScoreResult[] {
55
+ if (!existsSync(scoresPath)) {
56
+ throw new Error(`No quiz scores file at:\n ${scoresPath}`);
57
+ }
58
+ let raw: string;
59
+ try {
60
+ raw = readFileSync(scoresPath, "utf8");
61
+ } catch (error) {
62
+ const detail = error instanceof Error ? error.message : String(error);
63
+ throw new Error(`Could not read the quiz scores file:\n ${scoresPath}\n (${detail})`);
64
+ }
65
+ let parsed: unknown;
66
+ try {
67
+ parsed = JSON.parse(raw);
68
+ } catch {
69
+ throw new Error(`The quiz scores file is not valid JSON:\n ${scoresPath}`);
70
+ }
71
+ const result = scoresFileSchema.safeParse(parsed);
72
+ if (!result.success) {
73
+ throw new Error(
74
+ `The quiz scores do not match the expected shape (a JSON array of per-question scores):\n${result.error.message}`,
75
+ );
76
+ }
77
+ return result.data;
78
+ }
79
+
80
+ async function main(): Promise<void> {
81
+ const submissionId = process.argv[2];
82
+ const scoresPath = process.argv[3];
83
+ if (!submissionId || !scoresPath) {
84
+ console.error("Usage: node submit-quiz-result.js <submission-id> <scores-json-path>");
85
+ process.exitCode = 1;
86
+ return;
87
+ }
88
+ const submission = await runSubmitQuizResult({ submissionId, scoresPath });
89
+ console.log(`✓ Quiz result recorded for submission ${submission.id} (status: ${submission.status}).`);
90
+ }
91
+
92
+ /** Only auto-invoke the CLI when run directly (`node submit-quiz-result.js …`), not when imported. */
93
+ const entry = process.argv[1];
94
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
95
+ if (isMainModule) {
96
+ main().catch((error: unknown) => {
97
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
98
+ process.exitCode = 1;
99
+ });
100
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `node submit.js <case-id>` — the `fito-case-runner` submit entrypoint (Task 5.2). Re-fetches the
3
+ * case pointer, then runs the runner's push → PR flow from the learner's open checkout at
4
+ * `~/.fito/cases/<case-id>/` and prints the new PR URL. GitHub writes go through the local `gh` CLI.
5
+ *
6
+ * `runSubmit` is the testable core (injectable); `main` is the thin CLI wrapper, invoked by the
7
+ * `/fito-submit` orchestrator (Task 5.3).
8
+ */
9
+ import { existsSync } from "node:fs";
10
+ import * as os from "node:os";
11
+ import * as path from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { createFitoApiClient } from "../../shared/fito-api/client.js";
14
+ import { resolveFitoSession } from "../../shared/fito-session/session.js";
15
+ import { shellExec } from "../../shared/shell-exec/exec.js";
16
+ import { fetchCaseDetail } from "./case-detail.js";
17
+ import { readCheckoutVersionRef, readSubmissionBranches } from "./manifest.js";
18
+ import { submitSolution } from "./runner.js";
19
+ import { caseWorkDir } from "./workdir.js";
20
+ /** Fetch case pointer → guard the open checkout → push the student branch and open a PR; returns the PR URL. */
21
+ export async function runSubmit(options) {
22
+ const home = options.home ?? os.homedir();
23
+ const client = options.client ?? createFitoApiClient();
24
+ const detail = await fetchCaseDetail(client, options.caseId);
25
+ const targetDir = caseWorkDir(options.caseId, home);
26
+ if (!existsSync(targetDir)) {
27
+ throw new Error(`No open case at:\n ${targetDir}\nRun open first: node open.js ${options.caseId}`);
28
+ }
29
+ // The version pin comes from the local tree, not the case detail: after a case update the
30
+ // backend serves the *current* version, while the learner solved this checkout's version.
31
+ const versionRef = (options.readVersionRef ?? readCheckoutVersionRef)(targetDir);
32
+ // Resolve the Fito session once — it feeds both the identity match (the linked login) and the
33
+ // submission record (the access token) below, so there is a single `/me` round-trip.
34
+ const session = await resolveSession(client, home);
35
+ return submitSolution({
36
+ pointer: {
37
+ repositoryUrl: detail.repositoryUrl,
38
+ versionRef: detail.versionRef,
39
+ gitPlatform: detail.gitPlatform,
40
+ },
41
+ targetDir,
42
+ exec: options.exec ?? shellExec,
43
+ readBranches: options.readBranches ?? readSubmissionBranches,
44
+ resolveLinkedGithubLogin: () => Promise.resolve(session.linkedLogin),
45
+ recordSubmission: async (prUrl) => {
46
+ const recorded = await client.createSubmission(session.tokens.accessToken, {
47
+ caseId: options.caseId,
48
+ prUrl,
49
+ versionRef,
50
+ });
51
+ return recorded.id;
52
+ },
53
+ });
54
+ }
55
+ /**
56
+ * Resolve the learner's Fito session for the submit flow ([resolveFitoSession]: `GET /me`, refreshing
57
+ * + persisting on a 401). Returns the linked GitHub login (null when none is linked) for the identity
58
+ * match, plus the live token pair that authorizes the `POST /submissions` record. Throws when the
59
+ * learner is not logged in to Fito — submitting records a server-side submission and so needs a session.
60
+ */
61
+ async function resolveSession(client, home) {
62
+ const { user, tokens } = await resolveFitoSession(client, home);
63
+ return { linkedLogin: user.githubLogin ?? null, tokens };
64
+ }
65
+ async function main() {
66
+ const caseId = process.argv[2];
67
+ if (!caseId) {
68
+ console.error("Usage: node submit.js <case-id>");
69
+ process.exitCode = 1;
70
+ return;
71
+ }
72
+ const result = await runSubmit({ caseId });
73
+ console.log(`✓ Submitted as GitHub @${result.login}.`);
74
+ console.log(`✓ Pull request:\n ${result.prUrl}`);
75
+ console.log(`✓ Submission recorded with Fito (id: ${result.submissionId}).`);
76
+ }
77
+ /** Only auto-invoke the CLI when run directly (`node submit.js …`), not when imported (e.g. by tests). */
78
+ const entry = process.argv[1];
79
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
80
+ if (isMainModule) {
81
+ main().catch((error) => {
82
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
83
+ process.exitCode = 1;
84
+ });
85
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * `node submit.js <case-id>` — the `fito-case-runner` submit entrypoint (Task 5.2). Re-fetches the
3
+ * case pointer, then runs the runner's push → PR flow from the learner's open checkout at
4
+ * `~/.fito/cases/<case-id>/` and prints the new PR URL. GitHub writes go through the local `gh` CLI.
5
+ *
6
+ * `runSubmit` is the testable core (injectable); `main` is the thin CLI wrapper, invoked by the
7
+ * `/fito-submit` orchestrator (Task 5.3).
8
+ */
9
+ import { existsSync } from "node:fs";
10
+ import * as os from "node:os";
11
+ import * as path from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+
14
+ import { type FitoApiClient, type TokenResponse, createFitoApiClient } from "../../shared/fito-api/client.ts";
15
+ import { resolveFitoSession } from "../../shared/fito-session/session.ts";
16
+ import { shellExec } from "../../shared/shell-exec/exec.ts";
17
+ import { fetchCaseDetail } from "./case-detail.ts";
18
+ import { readCheckoutVersionRef, readSubmissionBranches } from "./manifest.ts";
19
+ import { type BranchReader, type Executor, type SubmitSolutionResult, submitSolution } from "./runner.ts";
20
+ import { caseWorkDir } from "./workdir.ts";
21
+
22
+ /** The fito-api surface the submit flow needs: the public case read, the authenticated `/me` lookup, and the submission record. */
23
+ type SubmitClient = Pick<FitoApiClient, "getCase" | "meWithRefresh" | "createSubmission">;
24
+
25
+ export interface RunSubmitOptions {
26
+ caseId: string;
27
+ home?: string;
28
+ client?: SubmitClient;
29
+ exec?: Executor;
30
+ readBranches?: BranchReader;
31
+ /** Reads the checkout's frozen version ref from the local tree (the version pin, Task 9.4). */
32
+ readVersionRef?: (repoRoot: string) => string;
33
+ }
34
+
35
+ /** Fetch case pointer → guard the open checkout → push the student branch and open a PR; returns the PR URL. */
36
+ export async function runSubmit(options: RunSubmitOptions): Promise<SubmitSolutionResult> {
37
+ const home = options.home ?? os.homedir();
38
+ const client = options.client ?? createFitoApiClient();
39
+
40
+ const detail = await fetchCaseDetail(client, options.caseId);
41
+ const targetDir = caseWorkDir(options.caseId, home);
42
+
43
+ if (!existsSync(targetDir)) {
44
+ throw new Error(`No open case at:\n ${targetDir}\nRun open first: node open.js ${options.caseId}`);
45
+ }
46
+
47
+ // The version pin comes from the local tree, not the case detail: after a case update the
48
+ // backend serves the *current* version, while the learner solved this checkout's version.
49
+ const versionRef = (options.readVersionRef ?? readCheckoutVersionRef)(targetDir);
50
+
51
+ // Resolve the Fito session once — it feeds both the identity match (the linked login) and the
52
+ // submission record (the access token) below, so there is a single `/me` round-trip.
53
+ const session = await resolveSession(client, home);
54
+
55
+ return submitSolution({
56
+ pointer: {
57
+ repositoryUrl: detail.repositoryUrl,
58
+ versionRef: detail.versionRef,
59
+ gitPlatform: detail.gitPlatform,
60
+ },
61
+ targetDir,
62
+ exec: options.exec ?? shellExec,
63
+ readBranches: options.readBranches ?? readSubmissionBranches,
64
+ resolveLinkedGithubLogin: () => Promise.resolve(session.linkedLogin),
65
+ recordSubmission: async (prUrl) => {
66
+ const recorded = await client.createSubmission(session.tokens.accessToken, {
67
+ caseId: options.caseId,
68
+ prUrl,
69
+ versionRef,
70
+ });
71
+ return recorded.id;
72
+ },
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Resolve the learner's Fito session for the submit flow ([resolveFitoSession]: `GET /me`, refreshing
78
+ * + persisting on a 401). Returns the linked GitHub login (null when none is linked) for the identity
79
+ * match, plus the live token pair that authorizes the `POST /submissions` record. Throws when the
80
+ * learner is not logged in to Fito — submitting records a server-side submission and so needs a session.
81
+ */
82
+ async function resolveSession(
83
+ client: SubmitClient,
84
+ home: string,
85
+ ): Promise<{ linkedLogin: string | null; tokens: TokenResponse }> {
86
+ const { user, tokens } = await resolveFitoSession(client, home);
87
+ return { linkedLogin: user.githubLogin ?? null, tokens };
88
+ }
89
+
90
+ async function main(): Promise<void> {
91
+ const caseId = process.argv[2];
92
+ if (!caseId) {
93
+ console.error("Usage: node submit.js <case-id>");
94
+ process.exitCode = 1;
95
+ return;
96
+ }
97
+ const result = await runSubmit({ caseId });
98
+ console.log(`✓ Submitted as GitHub @${result.login}.`);
99
+ console.log(`✓ Pull request:\n ${result.prUrl}`);
100
+ console.log(`✓ Submission recorded with Fito (id: ${result.submissionId}).`);
101
+ }
102
+
103
+ /** Only auto-invoke the CLI when run directly (`node submit.js …`), not when imported (e.g. by tests). */
104
+ const entry = process.argv[1];
105
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
106
+ if (isMainModule) {
107
+ main().catch((error: unknown) => {
108
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
109
+ process.exitCode = 1;
110
+ });
111
+ }
@@ -0,0 +1,10 @@
1
+ import * as os from "node:os";
2
+ import * as path from "node:path";
3
+ /**
4
+ * The per-case working directory, `~/.fito/cases/<caseId>/`. Deterministic and keyed by the case id
5
+ * so `open` and `submit` resolve the same checkout without the learner tracking a path. `home` is
6
+ * injectable so tests can point at a temp directory.
7
+ */
8
+ export function caseWorkDir(caseId, home = os.homedir()) {
9
+ return path.join(home, ".fito", "cases", caseId);
10
+ }
@@ -0,0 +1,11 @@
1
+ import * as os from "node:os";
2
+ import * as path from "node:path";
3
+
4
+ /**
5
+ * The per-case working directory, `~/.fito/cases/<caseId>/`. Deterministic and keyed by the case id
6
+ * so `open` and `submit` resolve the same checkout without the learner tracking a path. `home` is
7
+ * injectable so tests can point at a temp directory.
8
+ */
9
+ export function caseWorkDir(caseId: string, home: string = os.homedir()): string {
10
+ return path.join(home, ".fito", "cases", caseId);
11
+ }
@@ -0,0 +1,155 @@
1
+ ---
2
+ name: fito-competence-write
3
+ description: >
4
+ Write a competence into the Fito backend — the write tail of
5
+ competence authoring. Create one top-level competence from the
6
+ author-confirmed payload file, edit its name or description in
7
+ place, delete it with everything beneath it, and relay any
8
+ backend refusal word for word, since it names the author's next
9
+ step. Driven by /fito-create-or-update-competence and
10
+ /fito-delete-competence.
11
+ allowed-tools: bash
12
+ ---
13
+
14
+ # Fito Competence Write
15
+
16
+ Run the scripts from wherever you are — each command below names this skill's directory
17
+ itself.
18
+
19
+ ## Prerequisites
20
+
21
+ - **Fito login** — `/fito-login`. Competence writes are bearer-authenticated; a script that writes
22
+ fails with that guidance when no session exists, and `delete.js` checks for a session before its
23
+ preview too, because an author with no session can delete nothing. The one read-only path that needs
24
+ no session is an update naming no axis.
25
+ - **A confirmed payload** — a YAML file holding exactly what the author confirmed. `create.js` and
26
+ `update.js` read one each, and each section below shows its shape. Both are read verbatim.
27
+ - **The competence's id** — `update.js` and `delete.js` address a competence by it. `create.js` prints
28
+ it, and `fito_competence_list` reports it for every competence a technology demands.
29
+
30
+ ## Configuration
31
+
32
+ | Env var | Default | Purpose |
33
+ |---|---|---|
34
+ | `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin |
35
+
36
+ ## Create the competence
37
+
38
+ ```bash
39
+ node <fito-competence-write skill dir>/create.js <payload-file>
40
+ ```
41
+
42
+ POSTs the payload to `POST /competences`. The author becomes the competence's owner.
43
+
44
+ ```yaml
45
+ technologySlug: javalin
46
+ name: Routing basics
47
+ description: >-
48
+ Map a request to a handler and read what the request carries.
49
+ elements:
50
+ - concept:javalin.handler
51
+ - concept:javalin.context
52
+ ```
53
+
54
+ Every key is required. A competence with no description carries `description: null`. `elements` lists
55
+ knowledge-component references in order, and they are **frozen** once created: a different element
56
+ list is a new competence.
57
+
58
+ Each successful run adds a new competence, even under a name that already exists, so a re-run is a
59
+ deliberate second create. After a failure the refusal table below does not cover — a lost connection,
60
+ a timeout, a 5xx — list the technology's competences with `fito_competence_list` first, and re-run
61
+ only when this competence is absent from it.
62
+
63
+ **Done when** it prints `✓ Created competence "<name>" (<id>) ← <payload-file>` and the author has
64
+ seen the id — an edit or a delete addresses the competence by it.
65
+
66
+ ## Edit the name or the description
67
+
68
+ ```bash
69
+ node <fito-competence-write skill dir>/update.js <competence-id> <payload-file> [--name] [--description]
70
+ ```
71
+
72
+ PATCHes `/competences/{id}`, in place: the competence keeps its id, its elements and its learners'
73
+ recorded proficiency. Each flag names one axis the author confirmed — an edit writes that, not
74
+ everything the payload carries — and both flags go in one request, so no run half-lands.
75
+
76
+ The payload is a second, smaller file, carrying only the two axes an edit can write:
77
+
78
+ ```yaml
79
+ name: Routing fundamentals
80
+ description: >-
81
+ Map a request to a handler and read what the request carries.
82
+ ```
83
+
84
+ Both keys are required. A file carrying `elements` or `technologySlug` is refused before any request,
85
+ since a different element list is a new competence rather than an edit.
86
+
87
+ A `description` of `null` is refused before any request too: the backend reads a null the way it reads
88
+ a missing key — leave the stored one alone — so an edit can set a description and replace one, and
89
+ there is no way to clear one.
90
+
91
+ With **neither** flag the script writes nothing, and it checks rather than assumes. It reads the
92
+ competence and compares the two axes against the payload:
93
+
94
+ - They match — it prints `✓ Nothing to write — competence … already carries what was confirmed`, and exits 0. The author's edit was already applied.
95
+ - They differ — it exits non-zero naming which axes differ and the flags that would write them. The payload says this competence should read differently, so a silent "nothing to do" would tell the author an edit had landed when it never left.
96
+
97
+ **Done when** it prints `✓ Updated …` naming every axis the author confirmed, or `✓ Nothing to write …`
98
+ on a no-axis run.
99
+
100
+ ## Delete the competence and everything beneath it
101
+
102
+ ```bash
103
+ node <fito-competence-write skill dir>/delete.js <competence-id> [--confirm]
104
+ ```
105
+
106
+ Without `--confirm` nothing is deleted. The script reads the competence and prints what a delete would
107
+ take — every sub-competence by name, and how many — then exits non-zero showing the exact `--confirm`
108
+ re-run. Show the author that block word for word and get their answer before running it.
109
+
110
+ `--confirm` prints the same block, then DELETEs `/competences/{id}`. The backend takes the whole
111
+ subtree in one write. No learner's recorded proficiency is touched.
112
+
113
+ A delete stands: re-creating the competence mints a new id, and every sub-competence under it has to
114
+ be created again.
115
+
116
+ The block is a **point-in-time read**, and the delete is a second request. Another owner or admin can
117
+ add a sub-competence between the two, and it would go with the rest without ever appearing in the block
118
+ the author approved. When the review takes a while, or anyone else may be writing, re-run without
119
+ `--confirm` immediately before confirming.
120
+
121
+ **Done when** it prints `✓ Deleted competence "<name>" (<id>)…` and the author has seen what went.
122
+
123
+ ## A refusal — relay it word for word
124
+
125
+ A refusal exits non-zero with nothing written and prints
126
+ `✗ <Create|Update|Delete> failed (<status>): <message>`. Show the author that line exactly as printed:
127
+ the message is the backend's own. Then give the next step for its status:
128
+
129
+ | Script | Status | What the backend refused | Next step |
130
+ |---|---|---|---|
131
+ | `create.ts` | 422 | Element references that name no knowledge component — the message lists every one | Run the knowledge pipeline for those components, then create again with the same elements |
132
+ | `create.ts` | 403 | An author who is neither a curator nor an admin | Creating a competence needs one of those two roles |
133
+ | `create.ts` | 404 | A `technologySlug` no technology has | Check the slug, or create the technology with `/fito-create-or-update-technology` |
134
+ | `update.ts`, `delete.ts` | 403 | An author who is neither the competence's owner nor an admin — the message names both ways in, so the author can tell which one they lack | The owner runs it, or an admin does. A seeded competence has no owner, so an admin is the only way in |
135
+ | `update.ts`, `delete.ts` | 404 | No competence has that id | Read the id back with `fito_competence_list`, which reports every competence a technology demands |
136
+ | any | 400 | A payload or an id breaking a rule — no elements, a duplicate element, a blank name, text over the limit, or an id that is not a UUID | Fix it with the author, confirm it again, and re-run |
137
+
138
+ Keep every element the author confirmed. When references are missing, the vocabulary grows to meet
139
+ the competence.
140
+
141
+ A payload file a script cannot read — absent, not YAML, or the wrong shape — fails before any request,
142
+ with the reason.
143
+
144
+ ## Files
145
+
146
+ | File | Role |
147
+ |---|---|
148
+ | `create.ts` | `runCreate` core + CLI — POST the payload, print the success line or the refusal verbatim |
149
+ | `update.ts` | `runUpdate` core + CLI — PATCH the name and/or the description behind their own flags |
150
+ | `delete.ts` | `runDelete` core + CLI — report the subtree, then DELETE it behind `--confirm` |
151
+ | `payload.ts` | The create and edit payloads' Zod shapes + loaders |
152
+ | `display.ts` | `quoted` — escape a stored name before printing it, so an escape sequence in one cannot rewrite the line the author is reading |
153
+
154
+ Transport lives in [the fito-api client](../../shared/fito-api/README.md) (`createCompetence`,
155
+ `getCompetence`, `updateCompetence`, `deleteCompetence`).
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `node create.js <payload-file>` — create one top-level competence from the author-confirmed payload
3
+ * (PLAN Task 15b.7). The caller becomes its owner.
4
+ *
5
+ * The backend refuses a caller who is neither a curator nor an admin (403), an unknown technology
6
+ * (404), and element references naming no component (422, every one of them named in the message).
7
+ * Each refusal is printed exactly as the backend wrote it: the 422's list of missing components is the
8
+ * author's next action, so it reaches them unparaphrased.
9
+ *
10
+ * `runCreate` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
11
+ */
12
+ import * as os from "node:os";
13
+ import * as path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { FitoApiError, createFitoApiClient } from "../../shared/fito-api/client.js";
16
+ import { resolveFitoSession } from "../../shared/fito-session/session.js";
17
+ import { quoted } from "./display.js";
18
+ import { loadCompetencePayload } from "./payload.js";
19
+ /**
20
+ * Create the payload's competence: load and validate it, resolve the Fito session, and POST its four
21
+ * keys unchanged. A backend refusal propagates as the `FitoApiError` the client raised.
22
+ */
23
+ export async function runCreate(options) {
24
+ const home = options.home ?? os.homedir();
25
+ const client = options.client ?? createFitoApiClient();
26
+ const payload = loadCompetencePayload(options.payloadPath);
27
+ const { tokens } = await resolveFitoSession(client, home);
28
+ return client.createCompetence(tokens.accessToken, payload);
29
+ }
30
+ /**
31
+ * The success line: the competence's name, and the id an edit or a delete addresses — the id is
32
+ * printed nowhere else.
33
+ */
34
+ export function describeCreated(competence, payloadPath) {
35
+ return `✓ Created competence ${quoted(competence.name)} (${competence.id}) ← ${payloadPath}`;
36
+ }
37
+ const USAGE = "Usage: node create.js <payload-file>";
38
+ async function main() {
39
+ const args = process.argv.slice(2);
40
+ if (args.length !== 1) {
41
+ console.error(USAGE);
42
+ process.exitCode = 1;
43
+ return;
44
+ }
45
+ const [payloadPath] = args;
46
+ try {
47
+ console.log(describeCreated(await runCreate({ payloadPath }), payloadPath));
48
+ }
49
+ catch (error) {
50
+ if (error instanceof FitoApiError) {
51
+ console.error(`✗ Create failed (${error.status}): ${error.message}`);
52
+ }
53
+ else {
54
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
55
+ }
56
+ process.exitCode = 1;
57
+ }
58
+ }
59
+ /** Only auto-invoke the CLI when run directly (`node create.js …`), not when imported. */
60
+ const entry = process.argv[1];
61
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
62
+ if (isMainModule) {
63
+ void main();
64
+ }