fito-tui 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/agents/fito-case-source-planner.md +265 -0
- package/agents/fito-performance-reviewer.md +231 -0
- package/agents/fito-practice-concept-content-generator.md +318 -0
- package/agents/fito-practice-concept-identifier.md +482 -0
- package/agents/fito-practice-execution-fact-content-generator.md +299 -0
- package/agents/fito-practice-execution-fact-identifier.md +367 -0
- package/agents/fito-practice-usage-scenario-content-generator.md +331 -0
- package/agents/fito-practice-usage-scenario-identifier.md +397 -0
- package/agents/fito-subagent-selftest.md +27 -0
- package/agents/fito-technology-generator.md +207 -0
- package/agents/fito-tool-concept-content-generator.md +282 -0
- package/agents/fito-tool-concept-identifier.md +384 -0
- package/agents/fito-tool-execution-fact-content-generator.md +382 -0
- package/agents/fito-tool-execution-fact-identifier.md +360 -0
- package/agents/fito-tool-usage-scenario-content-generator.md +381 -0
- package/agents/fito-tool-usage-scenario-identifier.md +432 -0
- package/agents/fito-tutor.md +185 -0
- package/extensions/fito-delegate.js +539 -0
- package/extensions/fito-delegate.ts +691 -0
- package/extensions/fito-fetch-tools.js +380 -0
- package/extensions/fito-fetch-tools.ts +419 -0
- package/extensions/fito-startup.js +166 -0
- package/extensions/fito-startup.ts +188 -0
- package/package.json +56 -0
- package/prompts/fito-auth-refresh.md +15 -0
- package/prompts/fito-case-design.md +506 -0
- package/prompts/fito-case-edit.md +91 -0
- package/prompts/fito-case-generate.md +222 -0
- package/prompts/fito-case-open.md +124 -0
- package/prompts/fito-case-plan-source.md +114 -0
- package/prompts/fito-create-or-update-competence.md +261 -0
- package/prompts/fito-create-or-update-technology.md +199 -0
- package/prompts/fito-delete-competence.md +147 -0
- package/prompts/fito-evaluate.md +148 -0
- package/prompts/fito-fetch-urls-content.md +35 -0
- package/prompts/fito-generate-domain-concepts.md +85 -0
- package/prompts/fito-generate-execution-facts.md +85 -0
- package/prompts/fito-generate-usage-scenarios.md +85 -0
- package/prompts/fito-identify-domain-concepts.md +49 -0
- package/prompts/fito-identify-execution-facts.md +49 -0
- package/prompts/fito-identify-usage-scenarios.md +49 -0
- package/prompts/fito-login.md +21 -0
- package/prompts/fito-logout.md +14 -0
- package/prompts/fito-publish-case.md +266 -0
- package/prompts/fito-push-knowledge.md +84 -0
- package/prompts/fito-submit.md +208 -0
- package/prompts/fito-tutor.md +120 -0
- package/shared/case-briefing/briefing.js +221 -0
- package/shared/case-briefing/briefing.ts +261 -0
- package/shared/case-quiz/scoring.js +16 -0
- package/shared/case-quiz/scoring.ts +61 -0
- package/shared/case-validation/case-loader.js +88 -0
- package/shared/case-validation/case-loader.ts +106 -0
- package/shared/case-validation/case-schema.js +716 -0
- package/shared/case-validation/case-schema.ts +895 -0
- package/shared/competences/competence-list.js +29 -0
- package/shared/competences/competence-list.ts +32 -0
- package/shared/fito-api/README.md +192 -0
- package/shared/fito-api/client.js +731 -0
- package/shared/fito-api/client.ts +1426 -0
- package/shared/fito-session/credentials.js +79 -0
- package/shared/fito-session/credentials.ts +88 -0
- package/shared/fito-session/session.js +16 -0
- package/shared/fito-session/session.ts +35 -0
- package/shared/github-url/parse.js +26 -0
- package/shared/github-url/parse.ts +35 -0
- package/shared/knowledge-components/component-names.js +35 -0
- package/shared/knowledge-components/component-names.ts +39 -0
- package/shared/knowledge-components/knowledge-fetch.js +46 -0
- package/shared/knowledge-components/knowledge-fetch.ts +57 -0
- package/shared/knowledge-components/knowledge-search.js +101 -0
- package/shared/knowledge-components/knowledge-search.ts +144 -0
- package/shared/knowledge-components/push-payload.js +104 -0
- package/shared/knowledge-components/push-payload.ts +129 -0
- package/shared/knowledge-components/reference.js +24 -0
- package/shared/knowledge-components/reference.ts +43 -0
- package/shared/knowledge-components/technology-fetch.js +30 -0
- package/shared/knowledge-components/technology-fetch.ts +38 -0
- package/shared/shell-exec/exec.js +22 -0
- package/shared/shell-exec/exec.ts +46 -0
- package/skills/fito-auth/SKILL.md +68 -0
- package/skills/fito-auth/auth-refresh.js +23 -0
- package/skills/fito-auth/auth-refresh.ts +25 -0
- package/skills/fito-auth/browser.js +35 -0
- package/skills/fito-auth/browser.ts +57 -0
- package/skills/fito-auth/callback-server.js +152 -0
- package/skills/fito-auth/callback-server.ts +189 -0
- package/skills/fito-auth/login.js +37 -0
- package/skills/fito-auth/login.ts +42 -0
- package/skills/fito-auth/logout.js +24 -0
- package/skills/fito-auth/logout.ts +25 -0
- package/skills/fito-case-author/SKILL.md +179 -0
- package/skills/fito-case-author/checkout.js +222 -0
- package/skills/fito-case-author/checkout.ts +281 -0
- package/skills/fito-case-author/github-publish.js +218 -0
- package/skills/fito-case-author/github-publish.ts +251 -0
- package/skills/fito-case-author/publish-payload.js +108 -0
- package/skills/fito-case-author/publish-payload.ts +186 -0
- package/skills/fito-case-author/publish-state.js +72 -0
- package/skills/fito-case-author/publish-state.ts +87 -0
- package/skills/fito-case-author/publish-version.js +364 -0
- package/skills/fito-case-author/publish-version.ts +495 -0
- package/skills/fito-case-author/publish.js +284 -0
- package/skills/fito-case-author/publish.ts +394 -0
- package/skills/fito-case-author/semver.js +55 -0
- package/skills/fito-case-author/semver.ts +63 -0
- package/skills/fito-case-author/status-gate.js +34 -0
- package/skills/fito-case-author/status-gate.ts +54 -0
- package/skills/fito-case-author/validate.js +62 -0
- package/skills/fito-case-author/validate.ts +64 -0
- package/skills/fito-case-runner/SKILL.md +119 -0
- package/skills/fito-case-runner/case-component-names.js +45 -0
- package/skills/fito-case-runner/case-component-names.ts +65 -0
- package/skills/fito-case-runner/case-detail.js +20 -0
- package/skills/fito-case-runner/case-detail.ts +20 -0
- package/skills/fito-case-runner/github.js +234 -0
- package/skills/fito-case-runner/github.ts +287 -0
- package/skills/fito-case-runner/manifest.js +56 -0
- package/skills/fito-case-runner/manifest.ts +73 -0
- package/skills/fito-case-runner/open.js +175 -0
- package/skills/fito-case-runner/open.ts +241 -0
- package/skills/fito-case-runner/report.js +22 -0
- package/skills/fito-case-runner/report.ts +24 -0
- package/skills/fito-case-runner/runner.js +158 -0
- package/skills/fito-case-runner/runner.ts +304 -0
- package/skills/fito-case-runner/score-quiz-mc.js +85 -0
- package/skills/fito-case-runner/score-quiz-mc.ts +99 -0
- package/skills/fito-case-runner/submit-evaluation.js +73 -0
- package/skills/fito-case-runner/submit-evaluation.ts +98 -0
- package/skills/fito-case-runner/submit-quiz-result.js +75 -0
- package/skills/fito-case-runner/submit-quiz-result.ts +100 -0
- package/skills/fito-case-runner/submit.js +85 -0
- package/skills/fito-case-runner/submit.ts +111 -0
- package/skills/fito-case-runner/workdir.js +10 -0
- package/skills/fito-case-runner/workdir.ts +11 -0
- package/skills/fito-competence-write/SKILL.md +155 -0
- package/skills/fito-competence-write/create.js +64 -0
- package/skills/fito-competence-write/create.ts +80 -0
- package/skills/fito-competence-write/delete.js +136 -0
- package/skills/fito-competence-write/delete.ts +166 -0
- package/skills/fito-competence-write/display.js +20 -0
- package/skills/fito-competence-write/display.ts +21 -0
- package/skills/fito-competence-write/payload.js +96 -0
- package/skills/fito-competence-write/payload.ts +115 -0
- package/skills/fito-competence-write/update.js +155 -0
- package/skills/fito-competence-write/update.ts +206 -0
- package/skills/fito-evaluator/SKILL.md +73 -0
- package/skills/fito-evaluator/criterion-exec.js +64 -0
- package/skills/fito-evaluator/criterion-exec.ts +73 -0
- package/skills/fito-evaluator/evaluate-automated.js +57 -0
- package/skills/fito-evaluator/evaluate-automated.ts +84 -0
- package/skills/fito-evaluator/evaluate.js +28 -0
- package/skills/fito-evaluator/evaluate.ts +86 -0
- package/skills/fito-evaluator/report.js +112 -0
- package/skills/fito-evaluator/report.ts +128 -0
- package/skills/fito-evaluator/rubric.js +90 -0
- package/skills/fito-evaluator/rubric.ts +170 -0
- package/skills/fito-knowledge-push/SKILL.md +114 -0
- package/skills/fito-knowledge-push/push.js +282 -0
- package/skills/fito-knowledge-push/push.ts +360 -0
- package/skills/fito-source-ingestion/SKILL.md +77 -0
- package/skills/fito-source-ingestion/authoring-check.js +128 -0
- package/skills/fito-source-ingestion/authoring-check.ts +155 -0
- package/skills/fito-source-ingestion/bundle.js +198 -0
- package/skills/fito-source-ingestion/bundle.ts +246 -0
- package/skills/fito-technology-write/SKILL.md +108 -0
- package/skills/fito-technology-write/create.js +134 -0
- package/skills/fito-technology-write/create.ts +161 -0
- package/skills/fito-technology-write/payload.js +64 -0
- package/skills/fito-technology-write/payload.ts +70 -0
- package/skills/fito-technology-write/update.js +122 -0
- package/skills/fito-technology-write/update.ts +171 -0
- package/skills/fito-url-content-fetcher/SKILL.md +213 -0
- package/templates/concept-practice-content-template.md +281 -0
- package/templates/concept-tool-content-template.md +207 -0
- package/templates/execution-fact-practice-content-template.md +372 -0
- package/templates/execution-fact-tool-content-template.md +307 -0
- package/templates/usage-scenario-content-template.md +248 -0
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
|
|
16
|
+
import { FitoApiError, createFitoApiClient, type Competence, type FitoApiClient } from "../../shared/fito-api/client.ts";
|
|
17
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.ts";
|
|
18
|
+
import { quoted } from "./display.ts";
|
|
19
|
+
import { loadCompetencePayload } from "./payload.ts";
|
|
20
|
+
|
|
21
|
+
/** The fito-api surface this flow needs: the session lookup and the one write. */
|
|
22
|
+
type CreateClient = Pick<FitoApiClient, "meWithRefresh" | "createCompetence">;
|
|
23
|
+
|
|
24
|
+
export interface RunCreateOptions {
|
|
25
|
+
/** Path to the confirmed competence payload (`competence.yaml`). */
|
|
26
|
+
payloadPath: string;
|
|
27
|
+
home?: string;
|
|
28
|
+
client?: CreateClient;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create the payload's competence: load and validate it, resolve the Fito session, and POST its four
|
|
33
|
+
* keys unchanged. A backend refusal propagates as the `FitoApiError` the client raised.
|
|
34
|
+
*/
|
|
35
|
+
export async function runCreate(options: RunCreateOptions): Promise<Competence> {
|
|
36
|
+
const home = options.home ?? os.homedir();
|
|
37
|
+
const client = options.client ?? createFitoApiClient();
|
|
38
|
+
|
|
39
|
+
const payload = loadCompetencePayload(options.payloadPath);
|
|
40
|
+
const { tokens } = await resolveFitoSession(client, home);
|
|
41
|
+
|
|
42
|
+
return client.createCompetence(tokens.accessToken, payload);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The success line: the competence's name, and the id an edit or a delete addresses — the id is
|
|
47
|
+
* printed nowhere else.
|
|
48
|
+
*/
|
|
49
|
+
export function describeCreated(competence: Competence, payloadPath: string): string {
|
|
50
|
+
return `✓ Created competence ${quoted(competence.name)} (${competence.id}) ← ${payloadPath}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const USAGE = "Usage: node create.js <payload-file>";
|
|
54
|
+
|
|
55
|
+
async function main(): Promise<void> {
|
|
56
|
+
const args = process.argv.slice(2);
|
|
57
|
+
if (args.length !== 1) {
|
|
58
|
+
console.error(USAGE);
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const [payloadPath] = args;
|
|
63
|
+
try {
|
|
64
|
+
console.log(describeCreated(await runCreate({ payloadPath }), payloadPath));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error instanceof FitoApiError) {
|
|
67
|
+
console.error(`✗ Create failed (${error.status}): ${error.message}`);
|
|
68
|
+
} else {
|
|
69
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
70
|
+
}
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Only auto-invoke the CLI when run directly (`node create.js …`), not when imported. */
|
|
76
|
+
const entry = process.argv[1];
|
|
77
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
78
|
+
if (isMainModule) {
|
|
79
|
+
void main();
|
|
80
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node delete.js <competence-id> [--confirm]` — delete one competence and every sub-competence
|
|
3
|
+
* beneath it (PLAN Task 15b.8). The backend takes the whole subtree in one write, so what goes is
|
|
4
|
+
* everything under the id, not the one row the author named.
|
|
5
|
+
*
|
|
6
|
+
* `--confirm` is what makes the delete deliberate, and the run is honest about what it is about to
|
|
7
|
+
* take either way: it reads the competence first (`GET /competences/{id}`, a public read) and prints
|
|
8
|
+
* the whole subtree — every sub-competence by name, and how many — **before** any delete. Without the
|
|
9
|
+
* flag that block is all that happens, and the run exits non-zero having deleted nothing.
|
|
10
|
+
*
|
|
11
|
+
* The backend refuses a caller who is neither the competence's owner nor an admin (403) — its message
|
|
12
|
+
* names both ways in, so the author can tell which one they lack — and an unknown id (404). Each
|
|
13
|
+
* refusal is printed exactly as the backend wrote it.
|
|
14
|
+
*
|
|
15
|
+
* `runDelete` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
|
|
16
|
+
*/
|
|
17
|
+
import * as os from "node:os";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
import { FitoApiError, createFitoApiClient } from "../../shared/fito-api/client.js";
|
|
21
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.js";
|
|
22
|
+
import { quoted } from "./display.js";
|
|
23
|
+
/**
|
|
24
|
+
* Read the competence, report its subtree, and — with [RunDeleteOptions.confirm] — delete it.
|
|
25
|
+
*
|
|
26
|
+
* The session is resolved **before** the read, even though the read itself is public: an author with
|
|
27
|
+
* no session cannot delete anything, so they are told to sign in rather than shown a preview of a
|
|
28
|
+
* write they cannot make. Backend refusals (403, 404) propagate as `FitoApiError` for the caller to
|
|
29
|
+
* surface verbatim.
|
|
30
|
+
*/
|
|
31
|
+
export async function runDelete(options) {
|
|
32
|
+
const home = options.home ?? os.homedir();
|
|
33
|
+
const client = options.client ?? createFitoApiClient();
|
|
34
|
+
const { tokens } = await resolveFitoSession(client, home);
|
|
35
|
+
const competence = await client.getCompetence(options.competenceId);
|
|
36
|
+
const descendants = flattenDescendants(competence);
|
|
37
|
+
if (!options.confirm)
|
|
38
|
+
return { competence, descendants, deleted: false };
|
|
39
|
+
options.announce?.(describeWhatGoes({ competence, descendants, deleted: false }));
|
|
40
|
+
await client.deleteCompetence(tokens.accessToken, options.competenceId);
|
|
41
|
+
return { competence, descendants, deleted: true };
|
|
42
|
+
}
|
|
43
|
+
/** Every competence beneath [competence], depth-first — the subtree the one delete takes. */
|
|
44
|
+
function flattenDescendants(competence) {
|
|
45
|
+
return competence.components.flatMap((child) => [child, ...flattenDescendants(child)]);
|
|
46
|
+
}
|
|
47
|
+
/** How many sub-competences go with the competence, in the sentence the author reads. */
|
|
48
|
+
function countClause(descendants) {
|
|
49
|
+
if (descendants.length === 0)
|
|
50
|
+
return "No sub-competence goes with it.";
|
|
51
|
+
const plural = descendants.length === 1 ? "sub-competence goes" : "sub-competences go";
|
|
52
|
+
return `${descendants.length} ${plural} with it.`;
|
|
53
|
+
}
|
|
54
|
+
/** What the delete will take: the competence, every sub-competence by name, and the count. */
|
|
55
|
+
function describeWhatGoes(result) {
|
|
56
|
+
const { competence, descendants } = result;
|
|
57
|
+
const headline = descendants.length === 0
|
|
58
|
+
? `This will delete competence ${quoted(competence.name)} (${competence.id}).`
|
|
59
|
+
: `This will delete competence ${quoted(competence.name)} (${competence.id}) and everything beneath it:`;
|
|
60
|
+
const listed = descendants.map((child) => ` - ${quoted(child.name)} (${child.id})`);
|
|
61
|
+
return [
|
|
62
|
+
headline,
|
|
63
|
+
...listed,
|
|
64
|
+
`${countClause(descendants)} No learner's recorded proficiency is touched.`,
|
|
65
|
+
].join("\n");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The stop with no `--confirm`: what would go, that nothing did, and the exact re-run that deletes it.
|
|
69
|
+
* The command is spelled out rather than described — a destructive re-run the author has to reassemble
|
|
70
|
+
* is a re-run they can get wrong.
|
|
71
|
+
*/
|
|
72
|
+
export function describeStopped(result) {
|
|
73
|
+
return [
|
|
74
|
+
describeWhatGoes(result),
|
|
75
|
+
"",
|
|
76
|
+
"Nothing has been deleted. A delete needs the author's explicit confirmation:",
|
|
77
|
+
` node delete.js ${result.competence.id} --confirm`,
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
/** The success line: the competence deleted, and how much went with it. */
|
|
81
|
+
export function describeDeleted(result) {
|
|
82
|
+
const headline = `✓ Deleted competence ${quoted(result.competence.name)} (${result.competence.id})`;
|
|
83
|
+
if (result.descendants.length === 0)
|
|
84
|
+
return headline;
|
|
85
|
+
const plural = result.descendants.length === 1 ? "sub-competence" : "sub-competences";
|
|
86
|
+
return `${headline} and its ${result.descendants.length} ${plural}`;
|
|
87
|
+
}
|
|
88
|
+
const USAGE = "Usage: node delete.js <competence-id> [--confirm]";
|
|
89
|
+
function parseArgs(argv) {
|
|
90
|
+
const [competenceId, ...rest] = argv;
|
|
91
|
+
if (!competenceId)
|
|
92
|
+
return undefined;
|
|
93
|
+
const options = { competenceId };
|
|
94
|
+
for (const flag of rest) {
|
|
95
|
+
if (flag === "--confirm") {
|
|
96
|
+
options.confirm = true;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
async function main() {
|
|
105
|
+
const options = parseArgs(process.argv.slice(2));
|
|
106
|
+
if (!options) {
|
|
107
|
+
console.error(USAGE);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const result = await runDelete({ ...options, announce: (block) => console.log(block) });
|
|
113
|
+
if (result.deleted) {
|
|
114
|
+
console.log(describeDeleted(result));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.error(describeStopped(result));
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error instanceof FitoApiError) {
|
|
123
|
+
console.error(`✗ Delete failed (${error.status}): ${error.message}`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
127
|
+
}
|
|
128
|
+
process.exitCode = 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Only auto-invoke the CLI when run directly (`node delete.js …`), not when imported. */
|
|
132
|
+
const entry = process.argv[1];
|
|
133
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
134
|
+
if (isMainModule) {
|
|
135
|
+
void main();
|
|
136
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node delete.js <competence-id> [--confirm]` — delete one competence and every sub-competence
|
|
3
|
+
* beneath it (PLAN Task 15b.8). The backend takes the whole subtree in one write, so what goes is
|
|
4
|
+
* everything under the id, not the one row the author named.
|
|
5
|
+
*
|
|
6
|
+
* `--confirm` is what makes the delete deliberate, and the run is honest about what it is about to
|
|
7
|
+
* take either way: it reads the competence first (`GET /competences/{id}`, a public read) and prints
|
|
8
|
+
* the whole subtree — every sub-competence by name, and how many — **before** any delete. Without the
|
|
9
|
+
* flag that block is all that happens, and the run exits non-zero having deleted nothing.
|
|
10
|
+
*
|
|
11
|
+
* The backend refuses a caller who is neither the competence's owner nor an admin (403) — its message
|
|
12
|
+
* names both ways in, so the author can tell which one they lack — and an unknown id (404). Each
|
|
13
|
+
* refusal is printed exactly as the backend wrote it.
|
|
14
|
+
*
|
|
15
|
+
* `runDelete` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
|
|
16
|
+
*/
|
|
17
|
+
import * as os from "node:os";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
|
|
21
|
+
import { FitoApiError, createFitoApiClient, type Competence, type FitoApiClient } from "../../shared/fito-api/client.ts";
|
|
22
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.ts";
|
|
23
|
+
import { quoted } from "./display.ts";
|
|
24
|
+
|
|
25
|
+
/** The fito-api surface this flow needs: the session lookup, the subtree read, and the one write. */
|
|
26
|
+
type DeleteClient = Pick<FitoApiClient, "meWithRefresh" | "getCompetence" | "deleteCompetence">;
|
|
27
|
+
|
|
28
|
+
export interface RunDeleteOptions {
|
|
29
|
+
/** The competence to delete, by the id the create printed. */
|
|
30
|
+
competenceId: string;
|
|
31
|
+
/** Actually delete. Without it the run reads and reports, and writes nothing. */
|
|
32
|
+
confirm?: boolean;
|
|
33
|
+
home?: string;
|
|
34
|
+
client?: DeleteClient;
|
|
35
|
+
/** Called with the "what goes" block immediately before the delete request, and only then. */
|
|
36
|
+
announce?: (block: string) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What a run found, and whether it went on to delete it. */
|
|
40
|
+
export interface DeleteResult {
|
|
41
|
+
competence: Competence;
|
|
42
|
+
/** Every competence beneath it, depth-first — the rest of what the one write takes. */
|
|
43
|
+
descendants: Competence[];
|
|
44
|
+
deleted: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read the competence, report its subtree, and — with [RunDeleteOptions.confirm] — delete it.
|
|
49
|
+
*
|
|
50
|
+
* The session is resolved **before** the read, even though the read itself is public: an author with
|
|
51
|
+
* no session cannot delete anything, so they are told to sign in rather than shown a preview of a
|
|
52
|
+
* write they cannot make. Backend refusals (403, 404) propagate as `FitoApiError` for the caller to
|
|
53
|
+
* surface verbatim.
|
|
54
|
+
*/
|
|
55
|
+
export async function runDelete(options: RunDeleteOptions): Promise<DeleteResult> {
|
|
56
|
+
const home = options.home ?? os.homedir();
|
|
57
|
+
const client = options.client ?? createFitoApiClient();
|
|
58
|
+
|
|
59
|
+
const { tokens } = await resolveFitoSession(client, home);
|
|
60
|
+
const competence = await client.getCompetence(options.competenceId);
|
|
61
|
+
const descendants = flattenDescendants(competence);
|
|
62
|
+
|
|
63
|
+
if (!options.confirm) return { competence, descendants, deleted: false };
|
|
64
|
+
|
|
65
|
+
options.announce?.(describeWhatGoes({ competence, descendants, deleted: false }));
|
|
66
|
+
await client.deleteCompetence(tokens.accessToken, options.competenceId);
|
|
67
|
+
|
|
68
|
+
return { competence, descendants, deleted: true };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Every competence beneath [competence], depth-first — the subtree the one delete takes. */
|
|
72
|
+
function flattenDescendants(competence: Competence): Competence[] {
|
|
73
|
+
return competence.components.flatMap((child) => [child, ...flattenDescendants(child)]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** How many sub-competences go with the competence, in the sentence the author reads. */
|
|
77
|
+
function countClause(descendants: Competence[]): string {
|
|
78
|
+
if (descendants.length === 0) return "No sub-competence goes with it.";
|
|
79
|
+
const plural = descendants.length === 1 ? "sub-competence goes" : "sub-competences go";
|
|
80
|
+
return `${descendants.length} ${plural} with it.`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** What the delete will take: the competence, every sub-competence by name, and the count. */
|
|
84
|
+
function describeWhatGoes(result: DeleteResult): string {
|
|
85
|
+
const { competence, descendants } = result;
|
|
86
|
+
const headline =
|
|
87
|
+
descendants.length === 0
|
|
88
|
+
? `This will delete competence ${quoted(competence.name)} (${competence.id}).`
|
|
89
|
+
: `This will delete competence ${quoted(competence.name)} (${competence.id}) and everything beneath it:`;
|
|
90
|
+
const listed = descendants.map((child) => ` - ${quoted(child.name)} (${child.id})`);
|
|
91
|
+
return [
|
|
92
|
+
headline,
|
|
93
|
+
...listed,
|
|
94
|
+
`${countClause(descendants)} No learner's recorded proficiency is touched.`,
|
|
95
|
+
].join("\n");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The stop with no `--confirm`: what would go, that nothing did, and the exact re-run that deletes it.
|
|
100
|
+
* The command is spelled out rather than described — a destructive re-run the author has to reassemble
|
|
101
|
+
* is a re-run they can get wrong.
|
|
102
|
+
*/
|
|
103
|
+
export function describeStopped(result: DeleteResult): string {
|
|
104
|
+
return [
|
|
105
|
+
describeWhatGoes(result),
|
|
106
|
+
"",
|
|
107
|
+
"Nothing has been deleted. A delete needs the author's explicit confirmation:",
|
|
108
|
+
` node delete.js ${result.competence.id} --confirm`,
|
|
109
|
+
].join("\n");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The success line: the competence deleted, and how much went with it. */
|
|
113
|
+
export function describeDeleted(result: DeleteResult): string {
|
|
114
|
+
const headline = `✓ Deleted competence ${quoted(result.competence.name)} (${result.competence.id})`;
|
|
115
|
+
if (result.descendants.length === 0) return headline;
|
|
116
|
+
const plural = result.descendants.length === 1 ? "sub-competence" : "sub-competences";
|
|
117
|
+
return `${headline} and its ${result.descendants.length} ${plural}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const USAGE = "Usage: node delete.js <competence-id> [--confirm]";
|
|
121
|
+
|
|
122
|
+
function parseArgs(argv: string[]): RunDeleteOptions | undefined {
|
|
123
|
+
const [competenceId, ...rest] = argv;
|
|
124
|
+
if (!competenceId) return undefined;
|
|
125
|
+
const options: RunDeleteOptions = { competenceId };
|
|
126
|
+
for (const flag of rest) {
|
|
127
|
+
if (flag === "--confirm") {
|
|
128
|
+
options.confirm = 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
|
+
const result = await runDelete({ ...options, announce: (block) => console.log(block) });
|
|
145
|
+
if (result.deleted) {
|
|
146
|
+
console.log(describeDeleted(result));
|
|
147
|
+
} else {
|
|
148
|
+
console.error(describeStopped(result));
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof FitoApiError) {
|
|
153
|
+
console.error(`✗ Delete failed (${error.status}): ${error.message}`);
|
|
154
|
+
} else {
|
|
155
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
156
|
+
}
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Only auto-invoke the CLI when run directly (`node delete.js …`), not when imported. */
|
|
162
|
+
const entry = process.argv[1];
|
|
163
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
164
|
+
if (isMainModule) {
|
|
165
|
+
void main();
|
|
166
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering helpers shared by this skill's three scripts (Task 15b.8 review).
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists for one reason: a competence's name is **stored text written by another
|
|
5
|
+
* author**, and these scripts echo it straight into a terminal. A name carrying an escape sequence
|
|
6
|
+
* can move the cursor, blank the screen, or overwrite the line it was printed on — and the line it
|
|
7
|
+
* would overwrite is the one telling the author what a delete is about to take. The display must not
|
|
8
|
+
* be something the displayed data can rewrite.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* One stored name, quoted and safe to print: control characters become their `\u….` escapes, and an
|
|
12
|
+
* embedded quote or backslash is escaped rather than closing the quoting early.
|
|
13
|
+
*
|
|
14
|
+
* `JSON.stringify` **includes** the surrounding double quotes, so call sites interpolate it bare —
|
|
15
|
+
* `Competence ${quoted(name)}`, never `"${quoted(name)}"`. A plain name is unchanged apart from those
|
|
16
|
+
* quotes, so ordinary output reads exactly as it did before.
|
|
17
|
+
*/
|
|
18
|
+
export function quoted(name) {
|
|
19
|
+
return JSON.stringify(name);
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering helpers shared by this skill's three scripts (Task 15b.8 review).
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists for one reason: a competence's name is **stored text written by another
|
|
5
|
+
* author**, and these scripts echo it straight into a terminal. A name carrying an escape sequence
|
|
6
|
+
* can move the cursor, blank the screen, or overwrite the line it was printed on — and the line it
|
|
7
|
+
* would overwrite is the one telling the author what a delete is about to take. The display must not
|
|
8
|
+
* be something the displayed data can rewrite.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* One stored name, quoted and safe to print: control characters become their `\u….` escapes, and an
|
|
13
|
+
* embedded quote or backslash is escaped rather than closing the quoting early.
|
|
14
|
+
*
|
|
15
|
+
* `JSON.stringify` **includes** the surrounding double quotes, so call sites interpolate it bare —
|
|
16
|
+
* `Competence ${quoted(name)}`, never `"${quoted(name)}"`. A plain name is unchanged apart from those
|
|
17
|
+
* quotes, so ordinary output reads exactly as it did before.
|
|
18
|
+
*/
|
|
19
|
+
export function quoted(name: string): string {
|
|
20
|
+
return JSON.stringify(name);
|
|
21
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two author-confirmed payload files this skill reads.
|
|
3
|
+
*
|
|
4
|
+
* `competence.yaml` (Task 15b.7) is one **new** competence: the demanding technology's slug, the name,
|
|
5
|
+
* the description, and the element references in order — the `POST /competences` body.
|
|
6
|
+
*
|
|
7
|
+
* `edit.yaml` (Task 15b.8) is a **change to one that exists**: the name and the description, and
|
|
8
|
+
* nothing else, because a competence's elements are frozen once created. It is a second file rather
|
|
9
|
+
* than the first one re-read, so nothing an edit cannot write can sit in it and be quietly dropped.
|
|
10
|
+
*
|
|
11
|
+
* Each file is what the author confirmed, so it is read verbatim: nothing here rewrites, trims, or
|
|
12
|
+
* fills a field. Only the file's *shape* is checked. The backend's own rules — a non-empty element
|
|
13
|
+
* list, no duplicate element, every reference naming a component — stay the backend's, and its refusal
|
|
14
|
+
* reaches the author word for word.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
import { parse as parseYaml } from "yaml";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
/**
|
|
20
|
+
* The create payload's shape. `description` is required and nullable, as in the technology payload: a
|
|
21
|
+
* competence with no description says so with the literal `null`, so a forgotten key is caught here
|
|
22
|
+
* rather than read as "none".
|
|
23
|
+
*/
|
|
24
|
+
export const competencePayloadSchema = z.object({
|
|
25
|
+
technologySlug: z.string(),
|
|
26
|
+
name: z.string(),
|
|
27
|
+
description: z.string().nullable(),
|
|
28
|
+
elements: z.array(z.string()),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* The edit payload's shape — the two axes `PATCH /competences/{id}` writes. Both keys are required for
|
|
32
|
+
* the create payload's reason: a dropped key would lose the value the author confirmed, silently.
|
|
33
|
+
* Which of the two is actually sent is the caller's `--name` / `--description` decision, not this
|
|
34
|
+
* file's.
|
|
35
|
+
*/
|
|
36
|
+
export const competenceEditPayloadSchema = z.object({
|
|
37
|
+
name: z.string(),
|
|
38
|
+
description: z.string().nullable(),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Keys that belong to a competence but that an edit can never write. Present in an edit file they are
|
|
42
|
+
* refused rather than ignored: Zod strips an undeclared key without a word, so an author who changed
|
|
43
|
+
* the elements here would read `✓ Updated` over a stored element list that never moved.
|
|
44
|
+
*/
|
|
45
|
+
const FROZEN_KEYS = ["technologySlug", "elements"];
|
|
46
|
+
/** Read one payload file as YAML, failing with an actionable message on any unreadable input. */
|
|
47
|
+
function readPayloadFile(payloadPath, nextStep) {
|
|
48
|
+
if (!existsSync(payloadPath)) {
|
|
49
|
+
throw new Error(`No competence payload file at:\n ${payloadPath}\n${nextStep}`);
|
|
50
|
+
}
|
|
51
|
+
let raw;
|
|
52
|
+
try {
|
|
53
|
+
raw = readFileSync(payloadPath, "utf8");
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
57
|
+
throw new Error(`Could not read the competence payload file:\n ${payloadPath}\n (${detail})`);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return parseYaml(raw);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`The competence payload file is not valid YAML:\n ${payloadPath}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Load one competence payload file, failing with an actionable message on any malformed input. */
|
|
67
|
+
export function loadCompetencePayload(payloadPath) {
|
|
68
|
+
const parsed = readPayloadFile(payloadPath, "Confirm the competence with the author, save it as a YAML payload file, then re-run.");
|
|
69
|
+
const result = competencePayloadSchema.safeParse(parsed);
|
|
70
|
+
if (!result.success) {
|
|
71
|
+
throw new Error(`The payload file does not match the competence payload shape ({technologySlug, name, description, elements}):\n ${payloadPath}\n` +
|
|
72
|
+
`${result.error.message}\n` +
|
|
73
|
+
"Every key is required; a competence with no description is the literal `null`, and `elements` is a " +
|
|
74
|
+
"list of knowledge-component references.");
|
|
75
|
+
}
|
|
76
|
+
return result.data;
|
|
77
|
+
}
|
|
78
|
+
/** Load one competence edit payload file, failing with an actionable message on any malformed input. */
|
|
79
|
+
export function loadCompetenceEditPayload(payloadPath) {
|
|
80
|
+
const parsed = readPayloadFile(payloadPath, "Confirm the edit with the author, save it as a YAML payload file, then re-run.");
|
|
81
|
+
const frozen = FROZEN_KEYS.filter((key) => typeof parsed === "object" && parsed !== null && key in parsed);
|
|
82
|
+
if (frozen.length > 0) {
|
|
83
|
+
throw new Error(`The edit payload file carries keys an edit can never write: ${frozen.join(", ")}\n ${payloadPath}\n` +
|
|
84
|
+
"A competence's elements are frozen once created, and the technology that demands it is fixed — a " +
|
|
85
|
+
"different element list is a new competence. Remove those keys; an edit file carries `name` and " +
|
|
86
|
+
"`description` only.");
|
|
87
|
+
}
|
|
88
|
+
const result = competenceEditPayloadSchema.safeParse(parsed);
|
|
89
|
+
if (!result.success) {
|
|
90
|
+
throw new Error(`The payload file does not match the competence edit payload shape ({name, description}):\n ${payloadPath}\n` +
|
|
91
|
+
`${result.error.message}\n` +
|
|
92
|
+
"Both keys are required; a competence with no description is the literal `null`. Which of the two is " +
|
|
93
|
+
"written is the `--name` / `--description` decision, not the file's.");
|
|
94
|
+
}
|
|
95
|
+
return result.data;
|
|
96
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two author-confirmed payload files this skill reads.
|
|
3
|
+
*
|
|
4
|
+
* `competence.yaml` (Task 15b.7) is one **new** competence: the demanding technology's slug, the name,
|
|
5
|
+
* the description, and the element references in order — the `POST /competences` body.
|
|
6
|
+
*
|
|
7
|
+
* `edit.yaml` (Task 15b.8) is a **change to one that exists**: the name and the description, and
|
|
8
|
+
* nothing else, because a competence's elements are frozen once created. It is a second file rather
|
|
9
|
+
* than the first one re-read, so nothing an edit cannot write can sit in it and be quietly dropped.
|
|
10
|
+
*
|
|
11
|
+
* Each file is what the author confirmed, so it is read verbatim: nothing here rewrites, trims, or
|
|
12
|
+
* fills a field. Only the file's *shape* is checked. The backend's own rules — a non-empty element
|
|
13
|
+
* list, no duplicate element, every reference naming a component — stay the backend's, and its refusal
|
|
14
|
+
* reaches the author word for word.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
|
|
18
|
+
import { parse as parseYaml } from "yaml";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The create payload's shape. `description` is required and nullable, as in the technology payload: a
|
|
23
|
+
* competence with no description says so with the literal `null`, so a forgotten key is caught here
|
|
24
|
+
* rather than read as "none".
|
|
25
|
+
*/
|
|
26
|
+
export const competencePayloadSchema = z.object({
|
|
27
|
+
technologySlug: z.string(),
|
|
28
|
+
name: z.string(),
|
|
29
|
+
description: z.string().nullable(),
|
|
30
|
+
elements: z.array(z.string()),
|
|
31
|
+
});
|
|
32
|
+
export type CompetencePayload = z.infer<typeof competencePayloadSchema>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The edit payload's shape — the two axes `PATCH /competences/{id}` writes. Both keys are required for
|
|
36
|
+
* the create payload's reason: a dropped key would lose the value the author confirmed, silently.
|
|
37
|
+
* Which of the two is actually sent is the caller's `--name` / `--description` decision, not this
|
|
38
|
+
* file's.
|
|
39
|
+
*/
|
|
40
|
+
export const competenceEditPayloadSchema = z.object({
|
|
41
|
+
name: z.string(),
|
|
42
|
+
description: z.string().nullable(),
|
|
43
|
+
});
|
|
44
|
+
export type CompetenceEditPayload = z.infer<typeof competenceEditPayloadSchema>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Keys that belong to a competence but that an edit can never write. Present in an edit file they are
|
|
48
|
+
* refused rather than ignored: Zod strips an undeclared key without a word, so an author who changed
|
|
49
|
+
* the elements here would read `✓ Updated` over a stored element list that never moved.
|
|
50
|
+
*/
|
|
51
|
+
const FROZEN_KEYS = ["technologySlug", "elements"] as const;
|
|
52
|
+
|
|
53
|
+
/** Read one payload file as YAML, failing with an actionable message on any unreadable input. */
|
|
54
|
+
function readPayloadFile(payloadPath: string, nextStep: string): unknown {
|
|
55
|
+
if (!existsSync(payloadPath)) {
|
|
56
|
+
throw new Error(`No competence payload file at:\n ${payloadPath}\n${nextStep}`);
|
|
57
|
+
}
|
|
58
|
+
let raw: string;
|
|
59
|
+
try {
|
|
60
|
+
raw = readFileSync(payloadPath, "utf8");
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
63
|
+
throw new Error(`Could not read the competence payload file:\n ${payloadPath}\n (${detail})`);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return parseYaml(raw);
|
|
67
|
+
} catch {
|
|
68
|
+
throw new Error(`The competence payload file is not valid YAML:\n ${payloadPath}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Load one competence payload file, failing with an actionable message on any malformed input. */
|
|
73
|
+
export function loadCompetencePayload(payloadPath: string): CompetencePayload {
|
|
74
|
+
const parsed = readPayloadFile(
|
|
75
|
+
payloadPath,
|
|
76
|
+
"Confirm the competence with the author, save it as a YAML payload file, then re-run.",
|
|
77
|
+
);
|
|
78
|
+
const result = competencePayloadSchema.safeParse(parsed);
|
|
79
|
+
if (!result.success) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`The payload file does not match the competence payload shape ({technologySlug, name, description, elements}):\n ${payloadPath}\n` +
|
|
82
|
+
`${result.error.message}\n` +
|
|
83
|
+
"Every key is required; a competence with no description is the literal `null`, and `elements` is a " +
|
|
84
|
+
"list of knowledge-component references.",
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return result.data;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Load one competence edit payload file, failing with an actionable message on any malformed input. */
|
|
91
|
+
export function loadCompetenceEditPayload(payloadPath: string): CompetenceEditPayload {
|
|
92
|
+
const parsed = readPayloadFile(
|
|
93
|
+
payloadPath,
|
|
94
|
+
"Confirm the edit with the author, save it as a YAML payload file, then re-run.",
|
|
95
|
+
);
|
|
96
|
+
const frozen = FROZEN_KEYS.filter((key) => typeof parsed === "object" && parsed !== null && key in parsed);
|
|
97
|
+
if (frozen.length > 0) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`The edit payload file carries keys an edit can never write: ${frozen.join(", ")}\n ${payloadPath}\n` +
|
|
100
|
+
"A competence's elements are frozen once created, and the technology that demands it is fixed — a " +
|
|
101
|
+
"different element list is a new competence. Remove those keys; an edit file carries `name` and " +
|
|
102
|
+
"`description` only.",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const result = competenceEditPayloadSchema.safeParse(parsed);
|
|
106
|
+
if (!result.success) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`The payload file does not match the competence edit payload shape ({name, description}):\n ${payloadPath}\n` +
|
|
109
|
+
`${result.error.message}\n` +
|
|
110
|
+
"Both keys are required; a competence with no description is the literal `null`. Which of the two is " +
|
|
111
|
+
"written is the `--name` / `--description` decision, not the file's.",
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return result.data;
|
|
115
|
+
}
|