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,108 @@
1
+ ---
2
+ name: fito-technology-write
3
+ description: >
4
+ Write a technology and one major line into the backend
5
+ knowledge vocabulary — the create-or-update tail of the Fito
6
+ technology pipeline. Create-or-resolve from the confirmed
7
+ generator payload, then write the author-confirmed
8
+ descriptions onto the technology overview and the major
9
+ line. A near-duplicate 409 stops the write for the human
10
+ author's resolution (reuse, re-declare, or acknowledged
11
+ override). Driven by /fito-create-or-update-technology.
12
+ allowed-tools: bash
13
+ ---
14
+
15
+ # Fito Technology Write
16
+
17
+ Run the scripts from wherever you are — each command below names this
18
+ skill's directory itself. Both read the same
19
+ `fito-technology-generator` payload — the author-confirmed `technology.yaml` — and both are safe to
20
+ re-run.
21
+
22
+ Two scripts because a technology reaches the vocabulary two ways: `create.js` admits one that is not
23
+ there yet, `update.js` enriches the descriptions of one that is. A create the backend resolves to an
24
+ existing row stores no descriptions, so most update runs follow a create.
25
+
26
+ ## Prerequisites
27
+
28
+ - **Fito login** — `/fito-login`. Technology writes are bearer-authenticated; both scripts fail with
29
+ that guidance when no session exists.
30
+ - **A confirmed payload** — `./output/2-technology/technology.yaml`, drafted by the
31
+ `fito-technology-generator` subagent and confirmed by the author. Both scripts read it verbatim.
32
+
33
+ ## Configuration
34
+
35
+ | Env var | Default | Purpose |
36
+ |---|---|---|
37
+ | `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin |
38
+
39
+ ## Create or resolve the technology
40
+
41
+ ```bash
42
+ node <fito-technology-write skill dir>/create.js <payload-file> [--override]
43
+ ```
44
+
45
+ POSTs the payload's two blocks to `POST /technologies`. The backend picks the branch and reports it
46
+ as the run's `outcome`:
47
+
48
+ - **`created`** — the technology was new; both submitted descriptions are stored.
49
+ - **`version-added`** — the technology existed and this major line did not; the major line is added
50
+ with its prose, and the **submitted overview is not stored** (a technology's overview persists only
51
+ when its row is created).
52
+ - **`reused`** — the technology and this major line both existed; the write was a **no-op** and
53
+ **neither** submitted description is stored.
54
+
55
+ The success line names the branch and, on the last two, the exact `update.js` re-run that writes the
56
+ descriptions the branch skipped. Run it — otherwise the author's confirmed prose never reaches the
57
+ vocabulary.
58
+
59
+ **Done when** it prints `✓ <outcome> <slug>@<version> …`, and any `update.js` command it named has
60
+ been run.
61
+
62
+ ## Near-duplicate 409 — the resolution is the author's call
63
+
64
+ When the two-layer guard flags an existing technology, the script exits **non-zero** with nothing
65
+ created, printing each match with the layer that flagged it — `dedup-key` (a deterministic
66
+ normalized-slug collision) or `trigram` (a fuzzy candidate) — plus the three resolutions:
67
+
68
+ - **reuse** — the match *is* this technology: re-run `/fito-create-or-update-technology` declaring
69
+ the matched slug, which turns the run into an update of its descriptions (preferred).
70
+ - **re-declare** — the match only resembles this technology: re-run with a distinct `--technology`
71
+ slug.
72
+ - **override** — `--override`: create an independent technology that will **coexist** with every
73
+ match. The false-positive escape; run it only after the author explicitly confirms that
74
+ consequence.
75
+
76
+ Never pick a resolution yourself, and never re-run without one — the vocabulary is never
77
+ de-duplicated on an author's behalf.
78
+
79
+ **Done when** the author's chosen re-run prints its `✓` line, or the author chose to reuse a match.
80
+
81
+ ## Update the descriptions
82
+
83
+ ```bash
84
+ node <fito-technology-write skill dir>/update.js <payload-file> [--overview] [--version-prose]
85
+ ```
86
+
87
+ Writes the payload's confirmed prose onto the two axes, each behind its own flag: `--overview` is the
88
+ version-agnostic overview (what the technology *is*, across every major line), `--version-prose` is
89
+ the declared major line's own compatibility prose. At least one flag is required — an update writes
90
+ what the author confirmed, not everything the payload carries.
91
+
92
+ Both are **enrichment** endpoints with no "clear it" path, so a `null` or blank description on a
93
+ named axis is refused before any request, and a run that cannot write one axis writes neither. An
94
+ unknown technology or major line is a 404: check the declared `<slug>@<version>` against the
95
+ backend, or create it with `create.js` first.
96
+
97
+ **Done when** it prints `✓ Updated …` naming every axis the author confirmed.
98
+
99
+ ## Files
100
+
101
+ | File | Role |
102
+ |---|---|
103
+ | `create.ts` | `runCreate` core + CLI — create-or-resolve, render the 409 matches and the outcome's unstored axes |
104
+ | `update.ts` | `runUpdate` core + CLI — PATCH the overview and/or the major line's prose |
105
+ | `payload.ts` | The generator payload's Zod shape + loader, shared by both scripts |
106
+
107
+ Transport lives in [the fito-api client](../../shared/fito-api/README.md)
108
+ (`createOrResolveTechnology`, `updateTechnologyDescription`, `updateTechnologyVersionDescription`).
@@ -0,0 +1,134 @@
1
+ /**
2
+ * `node create.js <payload-file> [--override]` — create-or-resolve a technology and one major line
3
+ * from the confirmed `fito-technology-generator` payload (PLAN Task 9b.7, ADR-012). The backend
4
+ * decides the branch: a brand-new technology is created, an exact-slug hit is reused, and a missing
5
+ * major line is added to an existing technology — the `outcome` reports which, and with it which of
6
+ * the two submitted descriptions actually landed (a submitted overview is persisted only when the
7
+ * technology row is created).
8
+ *
9
+ * On a near-duplicate `409` the script stops and prints the flagged technologies for the
10
+ * `/fito-create-or-update-technology` orchestrator to relay — it never resolves one itself. The
11
+ * author's resolution comes back as a re-run: against the matched slug (which makes the run an
12
+ * update), under a distinct slug, or with `--override` to create past the matches.
13
+ *
14
+ * `runCreate` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
15
+ */
16
+ import * as os from "node:os";
17
+ import * as path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ import { FitoApiError, createFitoApiClient, } from "../../shared/fito-api/client.js";
20
+ import { resolveFitoSession } from "../../shared/fito-session/session.js";
21
+ import { loadTechnologyPayload } from "./payload.js";
22
+ /**
23
+ * Create-or-resolve the payload's technology: load and validate it, resolve the Fito session, and
24
+ * POST the two blocks unchanged. The near-duplicate `409` propagates as a `FitoApiError` carrying
25
+ * its `matches` for the caller to surface — resolving it is the human author's call.
26
+ */
27
+ export async function runCreate(options) {
28
+ const home = options.home ?? os.homedir();
29
+ const client = options.client ?? createFitoApiClient();
30
+ const payload = loadTechnologyPayload(options.payloadPath);
31
+ const { tokens } = await resolveFitoSession(client, home);
32
+ const input = {
33
+ technology: payload.technology,
34
+ version: payload.version,
35
+ ...(options.override ? { override: true } : {}),
36
+ };
37
+ return client.createOrResolveTechnology(tokens.accessToken, input);
38
+ }
39
+ /**
40
+ * Render a near-duplicate `409` into the block the orchestrator relays to the human author, or
41
+ * `undefined` when the error is any other failure. Every match is listed with the layer that flagged
42
+ * it — `dedup-key` (Layer 1, the deterministic normalized-slug collision) or `trigram` (Layer 2,
43
+ * fuzzy) — so the author can judge how close each really is. Nothing has been created when this
44
+ * block prints, and the block picks no resolution.
45
+ */
46
+ export function renderNearDuplicates(error, payloadPath) {
47
+ const matches = error.matches;
48
+ if (!matches || matches.length === 0)
49
+ return undefined;
50
+ const listed = matches.map((match) => ` ${match.slug} — "${match.name}" (${match.reason})`);
51
+ return [
52
+ `Near-duplicate technologies found (409): ${error.message}`,
53
+ "",
54
+ ...listed,
55
+ "",
56
+ "Nothing has been created. The author must choose — the vocabulary is never de-duplicated on",
57
+ "their behalf:",
58
+ " reuse re-run /fito-create-or-update-technology declaring a matched slug — the",
59
+ " technology already exists, so the run becomes an update of its descriptions",
60
+ " re-declare re-run with a distinct --technology slug, when this is genuinely a different",
61
+ " technology that the matches only resemble",
62
+ ` override node create.js ${payloadPath} --override`,
63
+ " create an independent technology that will coexist with every match above —",
64
+ " the false-positive escape; run it only after the author confirms that consequence",
65
+ ].join("\n");
66
+ }
67
+ /**
68
+ * The success line. Beyond naming the branch the backend took, it names the submitted descriptions
69
+ * that branch did **not** store, with the exact `update.ts` re-run that writes them: a `reused`
70
+ * create is a no-op and a `version-added` one persists no overview, so author-confirmed prose
71
+ * reaches the vocabulary on those branches only through the update path.
72
+ */
73
+ export function describeOutcome(response, payloadPath) {
74
+ const { outcome, technology, version } = response;
75
+ const headline = `✓ ${outcome} ${technology.slug}@${version.slug} — "${technology.name}" ` +
76
+ `(${technology.kind}) ← ${payloadPath}`;
77
+ if (outcome === "created")
78
+ return headline;
79
+ const [note, flags] = outcome === "version-added"
80
+ ? [
81
+ "the major line was added with its own prose, but the technology row already existed — " +
82
+ "a submitted overview is stored only when the row is created",
83
+ "--overview",
84
+ ]
85
+ : [
86
+ "the technology and this major line both already existed — the write was a no-op, so " +
87
+ "neither submitted description was stored",
88
+ "--overview --version-prose",
89
+ ];
90
+ return [headline, ` ${note}.`, ` Write the confirmed prose with: node update.js ${payloadPath} ${flags}`].join("\n");
91
+ }
92
+ const USAGE = "Usage: node create.js <payload-file> [--override]";
93
+ function parseArgs(argv) {
94
+ const [payloadPath, ...rest] = argv;
95
+ if (!payloadPath)
96
+ return undefined;
97
+ const options = { payloadPath };
98
+ for (const flag of rest) {
99
+ if (flag === "--override") {
100
+ options.override = true;
101
+ }
102
+ else {
103
+ return undefined;
104
+ }
105
+ }
106
+ return options;
107
+ }
108
+ async function main() {
109
+ const options = parseArgs(process.argv.slice(2));
110
+ if (!options) {
111
+ console.error(USAGE);
112
+ process.exitCode = 1;
113
+ return;
114
+ }
115
+ try {
116
+ console.log(describeOutcome(await runCreate(options), options.payloadPath));
117
+ }
118
+ catch (error) {
119
+ if (error instanceof FitoApiError) {
120
+ const nearDuplicates = renderNearDuplicates(error, options.payloadPath);
121
+ console.error(nearDuplicates ?? `✗ Create failed (${error.status}): ${error.message}`);
122
+ }
123
+ else {
124
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
125
+ }
126
+ process.exitCode = 1;
127
+ }
128
+ }
129
+ /** Only auto-invoke the CLI when run directly (`node create.js …`), not when imported. */
130
+ const entry = process.argv[1];
131
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
132
+ if (isMainModule) {
133
+ void main();
134
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * `node create.js <payload-file> [--override]` — create-or-resolve a technology and one major line
3
+ * from the confirmed `fito-technology-generator` payload (PLAN Task 9b.7, ADR-012). The backend
4
+ * decides the branch: a brand-new technology is created, an exact-slug hit is reused, and a missing
5
+ * major line is added to an existing technology — the `outcome` reports which, and with it which of
6
+ * the two submitted descriptions actually landed (a submitted overview is persisted only when the
7
+ * technology row is created).
8
+ *
9
+ * On a near-duplicate `409` the script stops and prints the flagged technologies for the
10
+ * `/fito-create-or-update-technology` orchestrator to relay — it never resolves one itself. The
11
+ * author's resolution comes back as a re-run: against the matched slug (which makes the run an
12
+ * update), under a distinct slug, or with `--override` to create past the matches.
13
+ *
14
+ * `runCreate` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
15
+ */
16
+ import * as os from "node:os";
17
+ import * as path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+
20
+ import {
21
+ FitoApiError,
22
+ createFitoApiClient,
23
+ type CreateTechnologyInput,
24
+ type FitoApiClient,
25
+ type TechnologyWriteResponse,
26
+ } from "../../shared/fito-api/client.ts";
27
+ import { resolveFitoSession } from "../../shared/fito-session/session.ts";
28
+ import { loadTechnologyPayload } from "./payload.ts";
29
+
30
+ /** The fito-api surface this flow needs: the session lookup and the one write. */
31
+ type CreateClient = Pick<FitoApiClient, "meWithRefresh" | "createOrResolveTechnology">;
32
+
33
+ export interface RunCreateOptions {
34
+ /** Path to the confirmed technology payload (`technology.yaml`). */
35
+ payloadPath: string;
36
+ /**
37
+ * The author's decision to create past the near-duplicate matches a previous run reported. Set
38
+ * only after they explicitly resolved the `409`, never automatically (ADR-012 Decision 4).
39
+ */
40
+ override?: boolean;
41
+ home?: string;
42
+ client?: CreateClient;
43
+ }
44
+
45
+ /**
46
+ * Create-or-resolve the payload's technology: load and validate it, resolve the Fito session, and
47
+ * POST the two blocks unchanged. The near-duplicate `409` propagates as a `FitoApiError` carrying
48
+ * its `matches` for the caller to surface — resolving it is the human author's call.
49
+ */
50
+ export async function runCreate(options: RunCreateOptions): Promise<TechnologyWriteResponse> {
51
+ const home = options.home ?? os.homedir();
52
+ const client = options.client ?? createFitoApiClient();
53
+
54
+ const payload = loadTechnologyPayload(options.payloadPath);
55
+ const { tokens } = await resolveFitoSession(client, home);
56
+
57
+ const input: CreateTechnologyInput = {
58
+ technology: payload.technology,
59
+ version: payload.version,
60
+ ...(options.override ? { override: true } : {}),
61
+ };
62
+ return client.createOrResolveTechnology(tokens.accessToken, input);
63
+ }
64
+
65
+ /**
66
+ * Render a near-duplicate `409` into the block the orchestrator relays to the human author, or
67
+ * `undefined` when the error is any other failure. Every match is listed with the layer that flagged
68
+ * it — `dedup-key` (Layer 1, the deterministic normalized-slug collision) or `trigram` (Layer 2,
69
+ * fuzzy) — so the author can judge how close each really is. Nothing has been created when this
70
+ * block prints, and the block picks no resolution.
71
+ */
72
+ export function renderNearDuplicates(error: FitoApiError, payloadPath: string): string | undefined {
73
+ const matches = error.matches;
74
+ if (!matches || matches.length === 0) return undefined;
75
+ const listed = matches.map((match) => ` ${match.slug} — "${match.name}" (${match.reason})`);
76
+ return [
77
+ `Near-duplicate technologies found (409): ${error.message}`,
78
+ "",
79
+ ...listed,
80
+ "",
81
+ "Nothing has been created. The author must choose — the vocabulary is never de-duplicated on",
82
+ "their behalf:",
83
+ " reuse re-run /fito-create-or-update-technology declaring a matched slug — the",
84
+ " technology already exists, so the run becomes an update of its descriptions",
85
+ " re-declare re-run with a distinct --technology slug, when this is genuinely a different",
86
+ " technology that the matches only resemble",
87
+ ` override node create.js ${payloadPath} --override`,
88
+ " create an independent technology that will coexist with every match above —",
89
+ " the false-positive escape; run it only after the author confirms that consequence",
90
+ ].join("\n");
91
+ }
92
+
93
+ /**
94
+ * The success line. Beyond naming the branch the backend took, it names the submitted descriptions
95
+ * that branch did **not** store, with the exact `update.ts` re-run that writes them: a `reused`
96
+ * create is a no-op and a `version-added` one persists no overview, so author-confirmed prose
97
+ * reaches the vocabulary on those branches only through the update path.
98
+ */
99
+ export function describeOutcome(response: TechnologyWriteResponse, payloadPath: string): string {
100
+ const { outcome, technology, version } = response;
101
+ const headline =
102
+ `✓ ${outcome} ${technology.slug}@${version.slug} — "${technology.name}" ` +
103
+ `(${technology.kind}) ← ${payloadPath}`;
104
+ if (outcome === "created") return headline;
105
+ const [note, flags] =
106
+ outcome === "version-added"
107
+ ? [
108
+ "the major line was added with its own prose, but the technology row already existed — " +
109
+ "a submitted overview is stored only when the row is created",
110
+ "--overview",
111
+ ]
112
+ : [
113
+ "the technology and this major line both already existed — the write was a no-op, so " +
114
+ "neither submitted description was stored",
115
+ "--overview --version-prose",
116
+ ];
117
+ return [headline, ` ${note}.`, ` Write the confirmed prose with: node update.js ${payloadPath} ${flags}`].join("\n");
118
+ }
119
+
120
+ const USAGE = "Usage: node create.js <payload-file> [--override]";
121
+
122
+ function parseArgs(argv: string[]): RunCreateOptions | undefined {
123
+ const [payloadPath, ...rest] = argv;
124
+ if (!payloadPath) return undefined;
125
+ const options: RunCreateOptions = { payloadPath };
126
+ for (const flag of rest) {
127
+ if (flag === "--override") {
128
+ options.override = true;
129
+ } else {
130
+ return undefined;
131
+ }
132
+ }
133
+ return options;
134
+ }
135
+
136
+ async function main(): Promise<void> {
137
+ const options = parseArgs(process.argv.slice(2));
138
+ if (!options) {
139
+ console.error(USAGE);
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ try {
144
+ console.log(describeOutcome(await runCreate(options), options.payloadPath));
145
+ } catch (error) {
146
+ if (error instanceof FitoApiError) {
147
+ const nearDuplicates = renderNearDuplicates(error, options.payloadPath);
148
+ console.error(nearDuplicates ?? `✗ Create failed (${error.status}): ${error.message}`);
149
+ } else {
150
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
151
+ }
152
+ process.exitCode = 1;
153
+ }
154
+ }
155
+
156
+ /** Only auto-invoke the CLI when run directly (`node create.js …`), not when imported. */
157
+ const entry = process.argv[1];
158
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
159
+ if (isMainModule) {
160
+ void main();
161
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The `fito-technology-generator` payload (`technology.yaml`, Task 9b.6) — read and validated once
3
+ * for both writes in this skill. The worker emits a complete `POST /technologies` body: the declared
4
+ * `slug`s and the major line's `label` carried through verbatim from the author's
5
+ * `--technology <slug>@<version>` (ADR-012 Decision 1), with `name`, `kind`, and the two
6
+ * descriptions drafted from the ingested sources. A description the sources did not ground is the
7
+ * literal `null` — *unknown*, never an approximation (ADR-012 Decision 2).
8
+ *
9
+ * The file is the author-confirmed record of what goes into the shared vocabulary, so it is read
10
+ * verbatim: nothing here rewrites, trims, or fills a field.
11
+ */
12
+ import { existsSync, readFileSync } from "node:fs";
13
+ import { parse as parseYaml } from "yaml";
14
+ import { z } from "zod";
15
+ /**
16
+ * The payload's shape. `kind` is closed to the two wire tokens the backend accepts — this validates
17
+ * a *file* a worker wrote, where a wrong kind is a permanent, unpatchable mistake (nothing updates
18
+ * `kind`), so it is worth catching before the request rather than as a 400 round-trip. Both
19
+ * `version` strings stay strings: an unquoted `7` in YAML parses as a number, and a major line
20
+ * addressed as one would desync the payload from the slug the author declared.
21
+ */
22
+ export const technologyPayloadSchema = z.object({
23
+ technology: z.object({
24
+ name: z.string(),
25
+ kind: z.enum(["tool", "practice"]),
26
+ slug: z.string(),
27
+ description: z.string().nullable(),
28
+ }),
29
+ version: z.object({
30
+ label: z.string(),
31
+ slug: z.string(),
32
+ description: z.string().nullable(),
33
+ }),
34
+ });
35
+ /** Load one technology payload file, failing with an actionable message on any malformed input. */
36
+ export function loadTechnologyPayload(payloadPath) {
37
+ if (!existsSync(payloadPath)) {
38
+ throw new Error(`No technology payload file at:\n ${payloadPath}\n` +
39
+ "Run /fito-create-or-update-technology so the fito-technology-generator drafts one.");
40
+ }
41
+ let raw;
42
+ try {
43
+ raw = readFileSync(payloadPath, "utf8");
44
+ }
45
+ catch (error) {
46
+ const detail = error instanceof Error ? error.message : String(error);
47
+ throw new Error(`Could not read the technology payload file:\n ${payloadPath}\n (${detail})`);
48
+ }
49
+ let parsed;
50
+ try {
51
+ parsed = parseYaml(raw);
52
+ }
53
+ catch {
54
+ throw new Error(`The technology payload file is not valid YAML:\n ${payloadPath}`);
55
+ }
56
+ const result = technologyPayloadSchema.safeParse(parsed);
57
+ if (!result.success) {
58
+ throw new Error(`The payload file does not match the technology payload shape ({technology, version}):\n ${payloadPath}\n` +
59
+ `${result.error.message}\n` +
60
+ "Every key is required; a description the sources did not ground is the literal `null`, and " +
61
+ "the version `label`/`slug` are quoted strings.");
62
+ }
63
+ return result.data;
64
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The `fito-technology-generator` payload (`technology.yaml`, Task 9b.6) — read and validated once
3
+ * for both writes in this skill. The worker emits a complete `POST /technologies` body: the declared
4
+ * `slug`s and the major line's `label` carried through verbatim from the author's
5
+ * `--technology <slug>@<version>` (ADR-012 Decision 1), with `name`, `kind`, and the two
6
+ * descriptions drafted from the ingested sources. A description the sources did not ground is the
7
+ * literal `null` — *unknown*, never an approximation (ADR-012 Decision 2).
8
+ *
9
+ * The file is the author-confirmed record of what goes into the shared vocabulary, so it is read
10
+ * verbatim: nothing here rewrites, trims, or fills a field.
11
+ */
12
+ import { existsSync, readFileSync } from "node:fs";
13
+
14
+ import { parse as parseYaml } from "yaml";
15
+ import { z } from "zod";
16
+
17
+ /**
18
+ * The payload's shape. `kind` is closed to the two wire tokens the backend accepts — this validates
19
+ * a *file* a worker wrote, where a wrong kind is a permanent, unpatchable mistake (nothing updates
20
+ * `kind`), so it is worth catching before the request rather than as a 400 round-trip. Both
21
+ * `version` strings stay strings: an unquoted `7` in YAML parses as a number, and a major line
22
+ * addressed as one would desync the payload from the slug the author declared.
23
+ */
24
+ export const technologyPayloadSchema = z.object({
25
+ technology: z.object({
26
+ name: z.string(),
27
+ kind: z.enum(["tool", "practice"]),
28
+ slug: z.string(),
29
+ description: z.string().nullable(),
30
+ }),
31
+ version: z.object({
32
+ label: z.string(),
33
+ slug: z.string(),
34
+ description: z.string().nullable(),
35
+ }),
36
+ });
37
+ export type TechnologyPayload = z.infer<typeof technologyPayloadSchema>;
38
+
39
+ /** Load one technology payload file, failing with an actionable message on any malformed input. */
40
+ export function loadTechnologyPayload(payloadPath: string): TechnologyPayload {
41
+ if (!existsSync(payloadPath)) {
42
+ throw new Error(
43
+ `No technology payload file at:\n ${payloadPath}\n` +
44
+ "Run /fito-create-or-update-technology so the fito-technology-generator drafts one.",
45
+ );
46
+ }
47
+ let raw: string;
48
+ try {
49
+ raw = readFileSync(payloadPath, "utf8");
50
+ } catch (error) {
51
+ const detail = error instanceof Error ? error.message : String(error);
52
+ throw new Error(`Could not read the technology payload file:\n ${payloadPath}\n (${detail})`);
53
+ }
54
+ let parsed: unknown;
55
+ try {
56
+ parsed = parseYaml(raw);
57
+ } catch {
58
+ throw new Error(`The technology payload file is not valid YAML:\n ${payloadPath}`);
59
+ }
60
+ const result = technologyPayloadSchema.safeParse(parsed);
61
+ if (!result.success) {
62
+ throw new Error(
63
+ `The payload file does not match the technology payload shape ({technology, version}):\n ${payloadPath}\n` +
64
+ `${result.error.message}\n` +
65
+ "Every key is required; a description the sources did not ground is the literal `null`, and " +
66
+ "the version `label`/`slug` are quoted strings.",
67
+ );
68
+ }
69
+ return result.data;
70
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * `node update.js <payload-file> [--overview] [--version-prose]` — write the confirmed descriptions
3
+ * of a technology that already exists onto the two axes ADR-011 Decision 2 keeps apart: the
4
+ * version-agnostic overview (`PATCH /technologies/{slug}`) and the declared major line's prose
5
+ * (`PATCH /technologies/{slug}/versions/{versionSlug}`). This is the create-or-update tail of
6
+ * `/fito-create-or-update-technology` (PLAN Task 9b.7, ADR-012 Decision 5) — the only path by which
7
+ * author-confirmed prose reaches a row `create.ts` reused rather than created.
8
+ *
9
+ * The flags are what makes an update deliberate: each names one axis the author confirmed, so a run
10
+ * never overwrites prose the author did not look at. Both endpoints are enrichment and have no
11
+ * "clear it" path, so an ungrounded (`null`) or blank description is refused here rather than sent
12
+ * as a 400.
13
+ *
14
+ * `runUpdate` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
15
+ */
16
+ import * as os from "node:os";
17
+ import * as path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ import { FitoApiError, createFitoApiClient, } from "../../shared/fito-api/client.js";
20
+ import { resolveFitoSession } from "../../shared/fito-session/session.js";
21
+ import { loadTechnologyPayload } from "./payload.js";
22
+ /**
23
+ * Write the named axes. Every named description is checked for substance **before** the first
24
+ * request, so a run that cannot write one axis writes neither — a half-applied update would leave
25
+ * the author guessing which half landed. Backend rejections (an unknown technology or major line →
26
+ * 404) propagate as `FitoApiError` for the caller to surface verbatim.
27
+ */
28
+ export async function runUpdate(options) {
29
+ const home = options.home ?? os.homedir();
30
+ const client = options.client ?? createFitoApiClient();
31
+ if (!options.overview && !options.versionProse) {
32
+ throw new Error("Name the description to write: --overview (the version-agnostic overview), --version-prose " +
33
+ "(the declared major line), or both. An update writes what the author confirmed, not everything " +
34
+ "the payload happens to carry.");
35
+ }
36
+ const payload = loadTechnologyPayload(options.payloadPath);
37
+ const overview = options.overview ? requireProse(payload, "technology") : undefined;
38
+ const versionProse = options.versionProse ? requireProse(payload, "version") : undefined;
39
+ const { tokens } = await resolveFitoSession(client, home);
40
+ const slug = payload.technology.slug;
41
+ const result = { slug };
42
+ if (overview !== undefined) {
43
+ result.overview = await client.updateTechnologyDescription(tokens.accessToken, slug, overview);
44
+ }
45
+ if (versionProse !== undefined) {
46
+ result.versionProse = await client.updateTechnologyVersionDescription(tokens.accessToken, slug, payload.version.slug, versionProse);
47
+ }
48
+ return result;
49
+ }
50
+ /**
51
+ * The description on one axis, or an actionable refusal. `null` is the generator's honest "the
52
+ * sources ground nothing here" and blank is the same gap spelled with whitespace; neither is prose
53
+ * worth putting on a field every author and learner afterwards reads, and the endpoints reject both
54
+ * anyway. The fix is the author supplementing the draft, not a request.
55
+ */
56
+ function requireProse(payload, axis) {
57
+ const description = payload[axis].description;
58
+ if (description === null) {
59
+ throw new Error(`The payload's ${axis}.description is \`null\` — the sources grounded nothing for it, and there ` +
60
+ "is no way to write an empty description. Supplement the draft with the author's own prose, " +
61
+ "then re-run.");
62
+ }
63
+ if (description.trim() === "") {
64
+ throw new Error(`The payload's ${axis}.description is blank — there is no way to write an empty description. ` +
65
+ "Supplement the draft with the author's own prose, then re-run.");
66
+ }
67
+ return description;
68
+ }
69
+ /** The success line: which axes were written, on which technology and major line. */
70
+ export function describeUpdate(result, payloadPath) {
71
+ const written = [];
72
+ if (result.overview)
73
+ written.push(`the ${result.slug} overview`);
74
+ if (result.versionProse)
75
+ written.push(`the ${result.slug}@${result.versionProse.slug} major line`);
76
+ return `✓ Updated ${written.join(" and ")} ← ${payloadPath}`;
77
+ }
78
+ const USAGE = "Usage: node update.js <payload-file> [--overview] [--version-prose]";
79
+ function parseArgs(argv) {
80
+ const [payloadPath, ...rest] = argv;
81
+ if (!payloadPath)
82
+ return undefined;
83
+ const options = { payloadPath };
84
+ for (const flag of rest) {
85
+ if (flag === "--overview") {
86
+ options.overview = true;
87
+ }
88
+ else if (flag === "--version-prose") {
89
+ options.versionProse = true;
90
+ }
91
+ else {
92
+ return undefined;
93
+ }
94
+ }
95
+ return options;
96
+ }
97
+ async function main() {
98
+ const options = parseArgs(process.argv.slice(2));
99
+ if (!options) {
100
+ console.error(USAGE);
101
+ process.exitCode = 1;
102
+ return;
103
+ }
104
+ try {
105
+ console.log(describeUpdate(await runUpdate(options), options.payloadPath));
106
+ }
107
+ catch (error) {
108
+ if (error instanceof FitoApiError) {
109
+ console.error(`✗ Update failed (${error.status}): ${error.message}`);
110
+ }
111
+ else {
112
+ console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
113
+ }
114
+ process.exitCode = 1;
115
+ }
116
+ }
117
+ /** Only auto-invoke the CLI when run directly (`node update.js …`), not when imported. */
118
+ const entry = process.argv[1];
119
+ const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
120
+ if (isMainModule) {
121
+ void main();
122
+ }