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,55 @@
1
+ /**
2
+ * SemVer 2.0.0 **precedence** (§11) for the version-publish strictly-greater guard (Task 9.8) —
3
+ * the TS mirror of the backend's `SemVerPrecedence`, so the local pre-push guard and the backend
4
+ * 422 refuse exactly the same version bumps. The guard matters locally because the push precedes
5
+ * the API call: the current version is always the chain's maximum, so a strictly-greater new
6
+ * version is guaranteed not to collide with (and force-move) any published frozen ref.
7
+ */
8
+ /** SemVer 2.0.0 grammar with capture groups: major, minor, patch, optional pre-release (build metadata matched, ignored). */
9
+ const SEMVER_GRAMMAR = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
10
+ /** Parse a SemVer 2.0.0 string; throws on malformed input — both guard inputs are validated upstream, so this is a bug signal. */
11
+ function parseSemVer(version) {
12
+ const match = SEMVER_GRAMMAR.exec(version);
13
+ if (!match) {
14
+ throw new Error(`"${version}" is not a valid semver string`);
15
+ }
16
+ return {
17
+ triple: [Number(match[1]), Number(match[2]), Number(match[3])],
18
+ prerelease: match[4] === undefined ? [] : match[4].split("."),
19
+ };
20
+ }
21
+ /** Compare two pre-release identifiers per §11.4: numeric < alphanumeric; numeric numerically, alphanumeric lexically. */
22
+ function compareIdentifiers(a, b) {
23
+ const aNumeric = /^\d+$/.test(a);
24
+ const bNumeric = /^\d+$/.test(b);
25
+ if (aNumeric && bNumeric)
26
+ return Number(a) - Number(b);
27
+ if (aNumeric !== bNumeric)
28
+ return aNumeric ? -1 : 1;
29
+ return a < b ? -1 : a > b ? 1 : 0;
30
+ }
31
+ /** SemVer 2.0.0 precedence: negative when `a < b`, zero when equal (build metadata ignored), positive when `a > b`. */
32
+ export function compareSemVerPrecedence(a, b) {
33
+ const left = parseSemVer(a);
34
+ const right = parseSemVer(b);
35
+ for (let i = 0; i < 3; i++) {
36
+ if (left.triple[i] !== right.triple[i])
37
+ return left.triple[i] - right.triple[i];
38
+ }
39
+ // Equal triples: a pre-release ranks below its release (§11.3).
40
+ if (left.prerelease.length === 0 || right.prerelease.length === 0) {
41
+ return right.prerelease.length - left.prerelease.length;
42
+ }
43
+ const shared = Math.min(left.prerelease.length, right.prerelease.length);
44
+ for (let i = 0; i < shared; i++) {
45
+ const order = compareIdentifiers(left.prerelease[i], right.prerelease[i]);
46
+ if (order !== 0)
47
+ return order;
48
+ }
49
+ // All shared identifiers equal: the larger set ranks higher (§11.4.4).
50
+ return left.prerelease.length - right.prerelease.length;
51
+ }
52
+ /** Whether `candidate` strictly outranks `current` — the version-publish pre-push guard. */
53
+ export function isStrictlyGreaterSemVer(candidate, current) {
54
+ return compareSemVerPrecedence(candidate, current) > 0;
55
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * SemVer 2.0.0 **precedence** (§11) for the version-publish strictly-greater guard (Task 9.8) —
3
+ * the TS mirror of the backend's `SemVerPrecedence`, so the local pre-push guard and the backend
4
+ * 422 refuse exactly the same version bumps. The guard matters locally because the push precedes
5
+ * the API call: the current version is always the chain's maximum, so a strictly-greater new
6
+ * version is guaranteed not to collide with (and force-move) any published frozen ref.
7
+ */
8
+
9
+ /** SemVer 2.0.0 grammar with capture groups: major, minor, patch, optional pre-release (build metadata matched, ignored). */
10
+ const SEMVER_GRAMMAR =
11
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
12
+
13
+ interface ParsedSemVer {
14
+ triple: [number, number, number];
15
+ /** Dot-separated pre-release identifiers; empty for a release version. */
16
+ prerelease: string[];
17
+ }
18
+
19
+ /** Parse a SemVer 2.0.0 string; throws on malformed input — both guard inputs are validated upstream, so this is a bug signal. */
20
+ function parseSemVer(version: string): ParsedSemVer {
21
+ const match = SEMVER_GRAMMAR.exec(version);
22
+ if (!match) {
23
+ throw new Error(`"${version}" is not a valid semver string`);
24
+ }
25
+ return {
26
+ triple: [Number(match[1]), Number(match[2]), Number(match[3])],
27
+ prerelease: match[4] === undefined ? [] : match[4].split("."),
28
+ };
29
+ }
30
+
31
+ /** Compare two pre-release identifiers per §11.4: numeric < alphanumeric; numeric numerically, alphanumeric lexically. */
32
+ function compareIdentifiers(a: string, b: string): number {
33
+ const aNumeric = /^\d+$/.test(a);
34
+ const bNumeric = /^\d+$/.test(b);
35
+ if (aNumeric && bNumeric) return Number(a) - Number(b);
36
+ if (aNumeric !== bNumeric) return aNumeric ? -1 : 1;
37
+ return a < b ? -1 : a > b ? 1 : 0;
38
+ }
39
+
40
+ /** SemVer 2.0.0 precedence: negative when `a < b`, zero when equal (build metadata ignored), positive when `a > b`. */
41
+ export function compareSemVerPrecedence(a: string, b: string): number {
42
+ const left = parseSemVer(a);
43
+ const right = parseSemVer(b);
44
+ for (let i = 0; i < 3; i++) {
45
+ if (left.triple[i] !== right.triple[i]) return left.triple[i] - right.triple[i];
46
+ }
47
+ // Equal triples: a pre-release ranks below its release (§11.3).
48
+ if (left.prerelease.length === 0 || right.prerelease.length === 0) {
49
+ return right.prerelease.length - left.prerelease.length;
50
+ }
51
+ const shared = Math.min(left.prerelease.length, right.prerelease.length);
52
+ for (let i = 0; i < shared; i++) {
53
+ const order = compareIdentifiers(left.prerelease[i], right.prerelease[i]);
54
+ if (order !== 0) return order;
55
+ }
56
+ // All shared identifiers equal: the larger set ranks higher (§11.4.4).
57
+ return left.prerelease.length - right.prerelease.length;
58
+ }
59
+
60
+ /** Whether `candidate` strictly outranks `current` — the version-publish pre-push guard. */
61
+ export function isStrictlyGreaterSemVer(candidate: string, current: string): boolean {
62
+ return compareSemVerPrecedence(candidate, current) > 0;
63
+ }
@@ -0,0 +1,34 @@
1
+ const ACTION_PHRASE = {
2
+ checkout: "be checked out for editing",
3
+ publishVersion: "receive a new version",
4
+ };
5
+ /** The ADR-009 deprecation core — the one place this wording lives (Task 9.9). */
6
+ const DEPRECATED_CORE = "This case has been deprecated — it is retired, and its published refs stay frozen.\n" +
7
+ "A correction to a retired case is a new case: design the successor with /fito-case-design";
8
+ const DEPRECATED_HINT = {
9
+ checkout: ".\n(Prior learners can still finish and submit against this case; that needs no edit.)",
10
+ publishVersion: "\nand leave this one deprecated. (Prior learners can still finish and submit against it.)",
11
+ };
12
+ /** The full DEPRECATED refusal for an action — the gates throw it; `--probe` prints it as guidance. */
13
+ export function deprecatedRefusal(action) {
14
+ return DEPRECATED_CORE + DEPRECATED_HINT[action];
15
+ }
16
+ /** The refusal for a case's status under an action, null when the action is allowed. */
17
+ export function statusRefusal(detail, action) {
18
+ if (detail.status === "PUBLISHED")
19
+ return null;
20
+ if (detail.status === "DEPRECATED")
21
+ return deprecatedRefusal(action);
22
+ if (detail.status === "DRAFT" && action === "checkout") {
23
+ return ("This case is registered but has never been published (status: DRAFT).\n" +
24
+ "/fito-case-edit puts a published case back on disk for an update. To finish the initial\n" +
25
+ `publish instead, run /fito-publish-case from your case working directory (its draft id: ${detail.id}).`);
26
+ }
27
+ return `This case is not published (status: ${detail.status}) — only a published case can ${ACTION_PHRASE[action]}.`;
28
+ }
29
+ /** Gate an authoring action on the case's status: pass on PUBLISHED, throw the policy refusal otherwise. */
30
+ export function gateStatus(detail, action) {
31
+ const refusal = statusRefusal(detail, action);
32
+ if (refusal !== null)
33
+ throw new Error(refusal);
34
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * One home for the case-status policy consulted before authoring actions (Task 9.9): only a
3
+ * PUBLISHED case can be checked out for editing or receive a new version, and a DEPRECATED case
4
+ * is retired — a correction to a retired case is a **new case** (ADR-009 §5/6). The wording is
5
+ * authored here once; callers differ only where their contexts genuinely do — the per-action
6
+ * DEPRECATED hints and checkout's DRAFT redirect to the initial publish. Consumed by
7
+ * `checkout.ts`, `runPublishVersion`, and the `--probe` CLI's deprecated-route guidance.
8
+ * In-skill per ADR-006: both consumers are `fito-case-author`; promotion to `shared/` waits
9
+ * for a genuine third consumer.
10
+ */
11
+ import type { CaseDetail } from "../../shared/fito-api/client.ts";
12
+
13
+ /** The authoring action being gated — selects the per-action refusal phrasing. */
14
+ export type GatedAction = "checkout" | "publishVersion";
15
+
16
+ const ACTION_PHRASE: Record<GatedAction, string> = {
17
+ checkout: "be checked out for editing",
18
+ publishVersion: "receive a new version",
19
+ };
20
+
21
+ /** The ADR-009 deprecation core — the one place this wording lives (Task 9.9). */
22
+ const DEPRECATED_CORE =
23
+ "This case has been deprecated — it is retired, and its published refs stay frozen.\n" +
24
+ "A correction to a retired case is a new case: design the successor with /fito-case-design";
25
+
26
+ const DEPRECATED_HINT: Record<GatedAction, string> = {
27
+ checkout: ".\n(Prior learners can still finish and submit against this case; that needs no edit.)",
28
+ publishVersion: "\nand leave this one deprecated. (Prior learners can still finish and submit against it.)",
29
+ };
30
+
31
+ /** The full DEPRECATED refusal for an action — the gates throw it; `--probe` prints it as guidance. */
32
+ export function deprecatedRefusal(action: GatedAction): string {
33
+ return DEPRECATED_CORE + DEPRECATED_HINT[action];
34
+ }
35
+
36
+ /** The refusal for a case's status under an action, null when the action is allowed. */
37
+ export function statusRefusal(detail: Pick<CaseDetail, "id" | "status">, action: GatedAction): string | null {
38
+ if (detail.status === "PUBLISHED") return null;
39
+ if (detail.status === "DEPRECATED") return deprecatedRefusal(action);
40
+ if (detail.status === "DRAFT" && action === "checkout") {
41
+ return (
42
+ "This case is registered but has never been published (status: DRAFT).\n" +
43
+ "/fito-case-edit puts a published case back on disk for an update. To finish the initial\n" +
44
+ `publish instead, run /fito-publish-case from your case working directory (its draft id: ${detail.id}).`
45
+ );
46
+ }
47
+ return `This case is not published (status: ${detail.status}) — only a published case can ${ACTION_PHRASE[action]}.`;
48
+ }
49
+
50
+ /** Gate an authoring action on the case's status: pass on PUBLISHED, throw the policy refusal otherwise. */
51
+ export function gateStatus(detail: Pick<CaseDetail, "id" | "status">, action: GatedAction): void {
52
+ const refusal = statusRefusal(detail, action);
53
+ if (refusal !== null) throw new Error(refusal);
54
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `node validate.js <case-working-dir>` — run the shared `.case/` structural validator
3
+ * (ADR-005, `shared/case-validation/`) over a local case working directory and print the
4
+ * `ValidationResult` as pretty JSON on stdout: on failure the per-file structural errors
5
+ * (exit 1); on success the structural attestation (`pass`, validator + ruleset versions)
6
+ * plus the deduped `(componentId, bloomLevel)` reference set (exit 0).
7
+ *
8
+ * A passing run also carries `optionalFieldsNotUsed` — the optional fields the case left
9
+ * empty, grouped by file (Task 11.10). It is the one thing the ruleset can never report,
10
+ * because an optional field is never rejected, and it belongs to **this CLI** rather than to
11
+ * `ValidationResult`: the same validator is the learner's backstop on `/fito-case-open`, and
12
+ * a learner must not be told which of a case's optional fields its author left blank.
13
+ *
14
+ * Nothing is persisted — the attestation the backend receives must come from the *last*
15
+ * validator run over the finished tree, so the publish flows (Tasks 9.3/9.8) re-run this
16
+ * CLI rather than trusting a saved file. `/fito-case-generate` (Task 9.2) drives it as
17
+ * the generate-time iterate loop.
18
+ */
19
+ import { existsSync, statSync } from "node:fs";
20
+ import * as path from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ import { loadCaseDir, validateLoadedCase } from "../../shared/case-validation/case-loader.js";
23
+ import { optionalFieldsNotUsed } from "../../shared/case-validation/case-schema.js";
24
+ function main() {
25
+ const workdir = process.argv[2];
26
+ if (!workdir) {
27
+ console.error("Usage: node validate.js <case-working-dir>");
28
+ process.exitCode = 2;
29
+ return;
30
+ }
31
+ const resolved = path.resolve(workdir);
32
+ if (!existsSync(resolved) || !statSync(resolved).isDirectory()) {
33
+ console.error(`Not a directory:\n ${resolved}`);
34
+ process.exitCode = 2;
35
+ return;
36
+ }
37
+ // One snapshot serves both: the attestation and the inventory then describe the same bytes.
38
+ const loaded = loadCaseDir(resolved);
39
+ const result = validateLoadedCase(loaded);
40
+ // The optional-field inventory rides along **only on a passing run**, and only here:
41
+ // `validateCaseDir` is also the learner's consumption-time backstop on every
42
+ // `/fito-case-open`, so it stays out of `ValidationResult` (Task 11.10). Printing it on
43
+ // success is the point — a reminder that fires only on failure is absent exactly when the
44
+ // case is finished, which is when the author wants it. A failing run's output is unchanged.
45
+ const output = result.ok ? { ...result, optionalFieldsNotUsed: optionalFieldsNotUsed(loaded) } : result;
46
+ // Pure JSON on stdout — the orchestrator relays errors to the author, and the publish
47
+ // flows forward the attestation + references to the backend.
48
+ process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
49
+ process.exitCode = result.ok ? 0 : 1;
50
+ }
51
+ /** Only auto-invoke the CLI when run directly (`node validate.js …`), not when imported. */
52
+ const entry = process.argv[1];
53
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
54
+ if (isMainModule) {
55
+ try {
56
+ main();
57
+ }
58
+ catch (error) {
59
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
60
+ process.exitCode = 1;
61
+ }
62
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `node validate.js <case-working-dir>` — run the shared `.case/` structural validator
3
+ * (ADR-005, `shared/case-validation/`) over a local case working directory and print the
4
+ * `ValidationResult` as pretty JSON on stdout: on failure the per-file structural errors
5
+ * (exit 1); on success the structural attestation (`pass`, validator + ruleset versions)
6
+ * plus the deduped `(componentId, bloomLevel)` reference set (exit 0).
7
+ *
8
+ * A passing run also carries `optionalFieldsNotUsed` — the optional fields the case left
9
+ * empty, grouped by file (Task 11.10). It is the one thing the ruleset can never report,
10
+ * because an optional field is never rejected, and it belongs to **this CLI** rather than to
11
+ * `ValidationResult`: the same validator is the learner's backstop on `/fito-case-open`, and
12
+ * a learner must not be told which of a case's optional fields its author left blank.
13
+ *
14
+ * Nothing is persisted — the attestation the backend receives must come from the *last*
15
+ * validator run over the finished tree, so the publish flows (Tasks 9.3/9.8) re-run this
16
+ * CLI rather than trusting a saved file. `/fito-case-generate` (Task 9.2) drives it as
17
+ * the generate-time iterate loop.
18
+ */
19
+ import { existsSync, statSync } from "node:fs";
20
+ import * as path from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+
23
+ import { loadCaseDir, validateLoadedCase } from "../../shared/case-validation/case-loader.ts";
24
+ import { optionalFieldsNotUsed } from "../../shared/case-validation/case-schema.ts";
25
+
26
+ function main(): void {
27
+ const workdir = process.argv[2];
28
+ if (!workdir) {
29
+ console.error("Usage: node validate.js <case-working-dir>");
30
+ process.exitCode = 2;
31
+ return;
32
+ }
33
+ const resolved = path.resolve(workdir);
34
+ if (!existsSync(resolved) || !statSync(resolved).isDirectory()) {
35
+ console.error(`Not a directory:\n ${resolved}`);
36
+ process.exitCode = 2;
37
+ return;
38
+ }
39
+ // One snapshot serves both: the attestation and the inventory then describe the same bytes.
40
+ const loaded = loadCaseDir(resolved);
41
+ const result = validateLoadedCase(loaded);
42
+ // The optional-field inventory rides along **only on a passing run**, and only here:
43
+ // `validateCaseDir` is also the learner's consumption-time backstop on every
44
+ // `/fito-case-open`, so it stays out of `ValidationResult` (Task 11.10). Printing it on
45
+ // success is the point — a reminder that fires only on failure is absent exactly when the
46
+ // case is finished, which is when the author wants it. A failing run's output is unchanged.
47
+ const output = result.ok ? { ...result, optionalFieldsNotUsed: optionalFieldsNotUsed(loaded) } : result;
48
+ // Pure JSON on stdout — the orchestrator relays errors to the author, and the publish
49
+ // flows forward the attestation + references to the backend.
50
+ process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
51
+ process.exitCode = result.ok ? 0 : 1;
52
+ }
53
+
54
+ /** Only auto-invoke the CLI when run directly (`node validate.js …`), not when imported. */
55
+ const entry = process.argv[1];
56
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
57
+ if (isMainModule) {
58
+ try {
59
+ main();
60
+ } catch (error: unknown) {
61
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
62
+ process.exitCode = 1;
63
+ }
64
+ }
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: fito-case-runner
3
+ description: >
4
+ Open or submit a Fito case. Use when a learner opens a case to work on (fork,
5
+ checkout, working branch) or submits a solution (push, pull request), or when
6
+ the /fito-case-open orchestrator drives the case loop.
7
+ allowed-tools: bash
8
+ ---
9
+
10
+ # Fito Case Runner
11
+
12
+ Run the scripts with `node <file>.js`. Both take the case's backend UUID and use a fixed
13
+ per-case checkout at `~/.fito/cases/<case-id>/`, so open and submit always agree on the location.
14
+
15
+ ## Prerequisites
16
+
17
+ - **`gh` (GitHub CLI), authenticated** — `gh auth login`. The fork, push, and PR are created under
18
+ this local GitHub account. **Submit** requires it to be the same account linked to the learner's
19
+ Fito profile (see below). Both commands fail with an actionable message if `gh` is missing or
20
+ unauthenticated.
21
+ - **`git`** on `PATH`.
22
+ - **Fito login (submit only)** — `/fito-login`. Submit records a server-side submission and resolves
23
+ the learner's Fito-linked GitHub identity via `GET /me`; open needs no login (the case read is
24
+ public — a logged-in open additionally records participation, see below).
25
+
26
+ ## Configuration
27
+
28
+ | Env var | Default | Purpose |
29
+ |---|---|---|
30
+ | `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin (case lookup) |
31
+
32
+ ## Open a case
33
+
34
+ ```bash
35
+ node <fito-case-runner skill dir>/open.js <case-id>
36
+ ```
37
+
38
+ `<case-id>` is the backend case UUID (cases carry no human-readable slug). Fetches the case, forks
39
+ it to the learner's GitHub account, clones the fork into `~/.fito/cases/<case-id>/`, checks out
40
+ `versionRef`, **structurally re-validates** the `.case/` checkout, then creates the
41
+ `submission.student_branch` working branch.
42
+
43
+ **Done when** it prints `Case opened at … on branch '<name>'`. If the case source is malformed it
44
+ prints the structural errors + a report affordance, creates **no** branch, and exits non-zero — stop
45
+ there; do not submit. (It refuses to overwrite a non-empty existing checkout.)
46
+
47
+ After a successful open it records the learner's participation with the backend (`POST
48
+ /cases/{id}/enrollments` — best-effort, Task 9.5). A `⚠ Fito couldn't record…` warning means only
49
+ that this record failed (no login, backend unreachable): the checkout is fine — relay the warning
50
+ and carry on; submitting records participation anyway. Never treat it as a failed open.
51
+
52
+ **Deprecated cases** (Task 9.6): a retired case takes no new learners. When the case is
53
+ `DEPRECATED`, open verifies the learner's participation with the backend
54
+ (`GET /cases/{id}/enrollments/me`) and **refuses** unless they already participate (an enrollment
55
+ or submission on record) — verifying needs a Fito login, so a logged-out open of a deprecated case
56
+ is refused with `/fito-login` guidance. A participant's open proceeds, printing a
57
+ `⚠ This case has been deprecated…` warning — relay it and continue; finishing and submitting stay
58
+ fully supported. An existing non-empty checkout is pointed at before the gate, so a mid-flight
59
+ learner is never refused their own work.
60
+
61
+ **Re-attempting a case** (Task 7.6): if the fork already carries the student branch from a previous
62
+ attempt, the plain run stops (removing its own clone) and prints the two re-run choices — relay them
63
+ and re-run with the **learner's** pick:
64
+
65
+ ```bash
66
+ node <fito-case-runner skill dir>/open.js <case-id> --resume # continue the previous attempt (keeps its commits + open PR)
67
+ node <fito-case-runner skill dir>/open.js <case-id> --start-over # discard it — deletes the fork branch, closing its PR
68
+ ```
69
+
70
+ ## Submit a case
71
+
72
+ ```bash
73
+ node <fito-case-runner skill dir>/submit.js <case-id>
74
+ ```
75
+
76
+ Commit your work on the student branch first. Pushes that branch to the fork, opens a pull request
77
+ against `submission.target_branch`, then **records the submission with the backend** (`POST
78
+ /submissions`) so it can be evaluated.
79
+
80
+ Before pushing, it confirms the **Fito-linked ↔ `gh`-authenticated** GitHub account match (Task 5.4):
81
+ it refuses (creating no PR, recording nothing) if you are not logged in to Fito, if your Fito account
82
+ has no linked GitHub identity, or if your local `gh` account differs from the linked one — with a
83
+ message telling you to re-authenticate `gh` or link the account.
84
+
85
+ **Idempotent / safe to re-run.** If a submission PR for this branch is already open it reuses it
86
+ instead of failing on a duplicate, and recording the same PR again returns the existing row (the
87
+ backend find-or-creates). So if recording fails *after* the PR was opened, just re-run — it reuses the
88
+ PR and retries the record. It never force-pushes: a push rejected because the fork branch diverged (a
89
+ previous attempt) fails with guidance to re-open with `--resume`/`--start-over` instead.
90
+
91
+ **Done when** it prints the pull-request URL and confirms the submission was recorded.
92
+
93
+ ## Resolve knowledge-component names (for feedback)
94
+
95
+ ```bash
96
+ node <fito-case-runner skill dir>/case-component-names.js <case-id> <component-id...>
97
+ ```
98
+
99
+ Resolves the canonical **names** of the given knowledge components for the `/fito-submit` and
100
+ `/fito-evaluate` feedback (Task 6.5). The reviewer cites components by **id** only; this fetches the
101
+ case detail (`GET /cases/{id}` — public, no login) and prints one `<id>\t<label>` line per requested
102
+ id, where `<label>` is `name (id)` for a declared learning objective/prerequisite, or the bare id for a
103
+ rubric-only component. Pass the distinct `knowledgeComponent` ids from the reviewer's results.
104
+
105
+ ## Files
106
+
107
+ | File | Role |
108
+ |---|---|
109
+ | `open.ts` / `submit.ts` | CLI entrypoints — `runOpen` / `runSubmit` testable core + `main` |
110
+ | `runner.ts` | Orchestration core (fork→clone→checkout→re-validate→branch, push→PR) over an injectable executor |
111
+ | `github.ts` | Repo-URL parse, the GitHub-only gate, and the `gh`/`git` command builders |
112
+ | `manifest.ts` | Read `submission.target_branch` / `student_branch` and derive the checkout's `versionRef` (the submission's version pin, Task 9.4) from the manifest |
113
+ | `case-detail.ts` | Fetch the case pointer + map API errors |
114
+ | `case-component-names.ts` | Resolve KC names for feedback — fetch case detail, label each id `name (id)` (id fallback) |
115
+ | `report.ts` | Render the malformed-case backstop report |
116
+ | — | The real `gh`/`git` executor is the shared `../../shared/shell-exec/exec.ts` (ADR-006) |
117
+ | `workdir.ts` | Resolve `~/.fito/cases/<case-id>/` |
118
+
119
+ See [the `.case/` validator](../../shared/case-validation/) and [the fito-api client](../../shared/fito-api/README.md).
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `node case-component-names.js <case-id> <component-id…>` — resolve knowledge-component **names** for
3
+ * the `/fito-submit` and `/fito-evaluate` feedback (Task 6.5). The `fito-performance-reviewer` subagent
4
+ * cites components by **id** only (it has no backend reach), so the orchestrating prompts run this to
5
+ * label each scored component by its canonical, backend-owned name. It fetches the case detail
6
+ * (`GET /cases/{id}` — public, no token), joins the resolved learning objectives + prerequisites into an
7
+ * `id → name` map, and prints `<id>\t<label>` per requested id — `name (id)`, or the bare id for a
8
+ * rubric-only component (the accepted Task 6.5 gap).
9
+ *
10
+ * `runResolveCaseComponentNames` is the testable core (injectable client); `main` is the thin CLI
11
+ * wrapper. The id→name composition itself lives in `shared/knowledge-components/component-names.ts`.
12
+ */
13
+ import * as path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { createFitoApiClient } from "../../shared/fito-api/client.js";
16
+ import { buildComponentNameMap, labelComponent } from "../../shared/knowledge-components/component-names.js";
17
+ import { fetchCaseDetail } from "./case-detail.js";
18
+ /** Fetch the case detail, then label each requested component id by its resolved name (id fallback). */
19
+ export async function runResolveCaseComponentNames(options) {
20
+ const client = options.client ?? createFitoApiClient();
21
+ const detail = await fetchCaseDetail(client, options.caseId);
22
+ const names = buildComponentNameMap(detail);
23
+ return options.componentIds.map((id) => ({ id, label: labelComponent(id, names) }));
24
+ }
25
+ async function main() {
26
+ const [caseId, ...componentIds] = process.argv.slice(2);
27
+ if (!caseId || componentIds.length === 0) {
28
+ console.error("Usage: node case-component-names.js <case-id> <component-id...>");
29
+ process.exitCode = 1;
30
+ return;
31
+ }
32
+ const labeled = await runResolveCaseComponentNames({ caseId, componentIds });
33
+ for (const { id, label } of labeled) {
34
+ console.log(`${id}\t${label}`);
35
+ }
36
+ }
37
+ /** Only auto-invoke the CLI when run directly (`node case-component-names.js …`), not when imported by tests. */
38
+ const entry = process.argv[1];
39
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
40
+ if (isMainModule) {
41
+ main().catch((error) => {
42
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
43
+ process.exitCode = 1;
44
+ });
45
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * `node case-component-names.js <case-id> <component-id…>` — resolve knowledge-component **names** for
3
+ * the `/fito-submit` and `/fito-evaluate` feedback (Task 6.5). The `fito-performance-reviewer` subagent
4
+ * cites components by **id** only (it has no backend reach), so the orchestrating prompts run this to
5
+ * label each scored component by its canonical, backend-owned name. It fetches the case detail
6
+ * (`GET /cases/{id}` — public, no token), joins the resolved learning objectives + prerequisites into an
7
+ * `id → name` map, and prints `<id>\t<label>` per requested id — `name (id)`, or the bare id for a
8
+ * rubric-only component (the accepted Task 6.5 gap).
9
+ *
10
+ * `runResolveCaseComponentNames` is the testable core (injectable client); `main` is the thin CLI
11
+ * wrapper. The id→name composition itself lives in `shared/knowledge-components/component-names.ts`.
12
+ */
13
+ import * as path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+
16
+ import { type FitoApiClient, createFitoApiClient } from "../../shared/fito-api/client.ts";
17
+ import { buildComponentNameMap, labelComponent } from "../../shared/knowledge-components/component-names.ts";
18
+ import { fetchCaseDetail } from "./case-detail.ts";
19
+
20
+ export interface ResolveCaseComponentNamesOptions {
21
+ caseId: string;
22
+ /** The component ids to label — the distinct `knowledgeComponent` ids from the reviewer's results. */
23
+ componentIds: string[];
24
+ /** Injectable for tests; defaults to a client reading `FITO_API_BASE_URL`. Only the public case read is used. */
25
+ client?: Pick<FitoApiClient, "getCase">;
26
+ }
27
+
28
+ /** One labeled component: its id and the learner-facing label (`name (id)` or the bare id fallback). */
29
+ export interface LabeledComponent {
30
+ id: string;
31
+ label: string;
32
+ }
33
+
34
+ /** Fetch the case detail, then label each requested component id by its resolved name (id fallback). */
35
+ export async function runResolveCaseComponentNames(
36
+ options: ResolveCaseComponentNamesOptions,
37
+ ): Promise<LabeledComponent[]> {
38
+ const client = options.client ?? createFitoApiClient();
39
+ const detail = await fetchCaseDetail(client, options.caseId);
40
+ const names = buildComponentNameMap(detail);
41
+ return options.componentIds.map((id) => ({ id, label: labelComponent(id, names) }));
42
+ }
43
+
44
+ async function main(): Promise<void> {
45
+ const [caseId, ...componentIds] = process.argv.slice(2);
46
+ if (!caseId || componentIds.length === 0) {
47
+ console.error("Usage: node case-component-names.js <case-id> <component-id...>");
48
+ process.exitCode = 1;
49
+ return;
50
+ }
51
+ const labeled = await runResolveCaseComponentNames({ caseId, componentIds });
52
+ for (const { id, label } of labeled) {
53
+ console.log(`${id}\t${label}`);
54
+ }
55
+ }
56
+
57
+ /** Only auto-invoke the CLI when run directly (`node case-component-names.js …`), not when imported by tests. */
58
+ const entry = process.argv[1];
59
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
60
+ if (isMainModule) {
61
+ main().catch((error: unknown) => {
62
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
63
+ process.exitCode = 1;
64
+ });
65
+ }
@@ -0,0 +1,20 @@
1
+ import { FitoApiError } from "../../shared/fito-api/client.js";
2
+ /**
3
+ * Fetch a case's detail (the repo pointer) by id, mapping API errors to learner-facing messages
4
+ * (parity with the knowledge fetch): a 404 → "No case found", any other `FitoApiError` → a status +
5
+ * detail message. A published case is a public read, so no token is sent. Shared by both entrypoints.
6
+ */
7
+ export async function fetchCaseDetail(client, caseId) {
8
+ try {
9
+ return await client.getCase(caseId);
10
+ }
11
+ catch (error) {
12
+ if (error instanceof FitoApiError && error.status === 404) {
13
+ throw new Error(`No case found for id "${caseId}".`);
14
+ }
15
+ if (error instanceof FitoApiError) {
16
+ throw new Error(`Could not fetch case "${caseId}" (${error.status}): ${error.message}`);
17
+ }
18
+ throw error;
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import { type CaseDetail, FitoApiError, type FitoApiClient } from "../../shared/fito-api/client.ts";
2
+
3
+ /**
4
+ * Fetch a case's detail (the repo pointer) by id, mapping API errors to learner-facing messages
5
+ * (parity with the knowledge fetch): a 404 → "No case found", any other `FitoApiError` → a status +
6
+ * detail message. A published case is a public read, so no token is sent. Shared by both entrypoints.
7
+ */
8
+ export async function fetchCaseDetail(client: Pick<FitoApiClient, "getCase">, caseId: string): Promise<CaseDetail> {
9
+ try {
10
+ return await client.getCase(caseId);
11
+ } catch (error) {
12
+ if (error instanceof FitoApiError && error.status === 404) {
13
+ throw new Error(`No case found for id "${caseId}".`);
14
+ }
15
+ if (error instanceof FitoApiError) {
16
+ throw new Error(`Could not fetch case "${caseId}" (${error.status}): ${error.message}`);
17
+ }
18
+ throw error;
19
+ }
20
+ }