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,170 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { loadCaseDir } from "../../shared/case-validation/case-loader.ts";
|
|
4
|
+
import type { BloomLevel } from "../../shared/case-validation/case-schema.ts";
|
|
5
|
+
import { rubricSchema } from "../../shared/case-validation/case-schema.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Rubric reading + per-type criteria selection for the `fito-performance-reviewer` (Tasks 6.1 + 6.2).
|
|
9
|
+
*
|
|
10
|
+
* Flattens each `evaluation_method` type to exactly what evaluation + scoring need:
|
|
11
|
+
* - `automated` (Task 6.1): a `command` + `passingCondition` run deterministically for evidence.
|
|
12
|
+
* - `ai` (Task 6.2): a `promptHint` the reviewer judges the learner's work against.
|
|
13
|
+
* - `hybrid` (Task 6.2): an automated gate run first, then judged against `passingCondition`; on pass
|
|
14
|
+
* it takes `onPass`, on fail it falls back per `onFail` (`ai`/`human`).
|
|
15
|
+
* Only `human` criteria remain truly unscorable here ({@link selectSkippedCriteria}). Reuses the
|
|
16
|
+
* canonical `.case/` reader + `rubricSchema` from `shared/case-validation/` rather than re-parsing YAML.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export type Rubric = z.infer<typeof rubricSchema>;
|
|
20
|
+
|
|
21
|
+
export interface RubricLevel {
|
|
22
|
+
score: number;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One automated rubric criterion, flattened to exactly what evaluation + scoring need. */
|
|
28
|
+
export interface AutomatedCriterion {
|
|
29
|
+
id: string;
|
|
30
|
+
title: string;
|
|
31
|
+
knowledgeComponent: string;
|
|
32
|
+
bloomLevel: BloomLevel;
|
|
33
|
+
/** The shell command to run in the learner's checkout (free-form; runs via `sh -c`). */
|
|
34
|
+
command: string;
|
|
35
|
+
/** Natural-language pass description the reviewer judges the captured output against. */
|
|
36
|
+
passingCondition: string;
|
|
37
|
+
/** The 0–3 scoring band (always covers all four scores — enforced by the structural validator). */
|
|
38
|
+
levels: RubricLevel[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Keep only the `automated` criteria, flattened to {@link AutomatedCriterion}; preserves rubric order. */
|
|
42
|
+
export function selectAutomatedCriteria(rubric: Rubric): AutomatedCriterion[] {
|
|
43
|
+
const automated: AutomatedCriterion[] = [];
|
|
44
|
+
for (const criterion of rubric.criteria) {
|
|
45
|
+
if (criterion.evaluation_method.type !== "automated") continue;
|
|
46
|
+
automated.push({
|
|
47
|
+
id: criterion.id,
|
|
48
|
+
title: criterion.title,
|
|
49
|
+
knowledgeComponent: criterion.knowledge_component,
|
|
50
|
+
bloomLevel: criterion.bloom_level,
|
|
51
|
+
command: criterion.evaluation_method.command,
|
|
52
|
+
passingCondition: criterion.evaluation_method.passing_condition,
|
|
53
|
+
levels: criterion.levels.map((l) => ({ score: l.score, label: l.label, description: l.description })),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return automated;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** One `ai` rubric criterion, flattened to what the reviewer needs to score it via the local LLM. */
|
|
60
|
+
export interface AICriterion {
|
|
61
|
+
id: string;
|
|
62
|
+
title: string;
|
|
63
|
+
knowledgeComponent: string;
|
|
64
|
+
bloomLevel: BloomLevel;
|
|
65
|
+
/** The case author's hint guiding the reviewer on what to look for in the learner's work. */
|
|
66
|
+
promptHint: string;
|
|
67
|
+
/** The 0–3 scoring band (always covers all four scores — enforced by the structural validator). */
|
|
68
|
+
levels: RubricLevel[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Keep only the `ai` criteria, flattened to {@link AICriterion}; preserves rubric order. */
|
|
72
|
+
export function selectAICriteria(rubric: Rubric): AICriterion[] {
|
|
73
|
+
const ai: AICriterion[] = [];
|
|
74
|
+
for (const criterion of rubric.criteria) {
|
|
75
|
+
if (criterion.evaluation_method.type !== "ai") continue;
|
|
76
|
+
ai.push({
|
|
77
|
+
id: criterion.id,
|
|
78
|
+
title: criterion.title,
|
|
79
|
+
knowledgeComponent: criterion.knowledge_component,
|
|
80
|
+
bloomLevel: criterion.bloom_level,
|
|
81
|
+
promptHint: criterion.evaluation_method.prompt_hint,
|
|
82
|
+
levels: criterion.levels.map((l) => ({ score: l.score, label: l.label, description: l.description })),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return ai;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** One `hybrid` rubric criterion: an automated gate run first, then an AI/human fallback on fail. */
|
|
89
|
+
export interface HybridCriterion {
|
|
90
|
+
id: string;
|
|
91
|
+
title: string;
|
|
92
|
+
knowledgeComponent: string;
|
|
93
|
+
bloomLevel: BloomLevel;
|
|
94
|
+
/** The automated gate command run first; the reviewer judges its evidence against `passingCondition`. */
|
|
95
|
+
gateCommand: string;
|
|
96
|
+
/** Natural-language pass description the reviewer judges the gate's captured output against. */
|
|
97
|
+
passingCondition: string;
|
|
98
|
+
/** Level label to assign when the gate passes (e.g. "achieved"); mapped to its score via `levels`. */
|
|
99
|
+
onPass: string;
|
|
100
|
+
/** Where a failed gate falls back: `ai` → AI scoring; `human` → manual review (unscorable here). */
|
|
101
|
+
onFail: "ai" | "human";
|
|
102
|
+
/** Optional hint for the AI fallback when the gate fails. */
|
|
103
|
+
fallbackPromptHint?: string;
|
|
104
|
+
/** The 0–3 scoring band (always covers all four scores — enforced by the structural validator). */
|
|
105
|
+
levels: RubricLevel[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Keep only the `hybrid` criteria, flattened to {@link HybridCriterion}; preserves rubric order. */
|
|
109
|
+
export function selectHybridCriteria(rubric: Rubric): HybridCriterion[] {
|
|
110
|
+
const hybrid: HybridCriterion[] = [];
|
|
111
|
+
for (const criterion of rubric.criteria) {
|
|
112
|
+
const method = criterion.evaluation_method;
|
|
113
|
+
if (method.type !== "hybrid") continue;
|
|
114
|
+
hybrid.push({
|
|
115
|
+
id: criterion.id,
|
|
116
|
+
title: criterion.title,
|
|
117
|
+
knowledgeComponent: criterion.knowledge_component,
|
|
118
|
+
bloomLevel: criterion.bloom_level,
|
|
119
|
+
gateCommand: method.automated.command,
|
|
120
|
+
passingCondition: method.automated.passing_condition,
|
|
121
|
+
onPass: method.on_pass,
|
|
122
|
+
onFail: method.on_fail,
|
|
123
|
+
fallbackPromptHint: method.fallback_prompt_hint,
|
|
124
|
+
levels: criterion.levels.map((l) => ({ score: l.score, label: l.label, description: l.description })),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return hybrid;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A criterion the reviewer cannot score at all — only `human` remains, now that `ai` and `hybrid`
|
|
132
|
+
* are handled (Task 6.2). The preview lists these so the learner knows that part needs a person.
|
|
133
|
+
*/
|
|
134
|
+
export interface SkippedCriterion {
|
|
135
|
+
id: string;
|
|
136
|
+
title: string;
|
|
137
|
+
evaluationType: "human";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The `human`-only criteria, so the preview can tell the learner which criteria need manual review. */
|
|
141
|
+
export function selectSkippedCriteria(rubric: Rubric): SkippedCriterion[] {
|
|
142
|
+
const skipped: SkippedCriterion[] = [];
|
|
143
|
+
for (const criterion of rubric.criteria) {
|
|
144
|
+
if (criterion.evaluation_method.type !== "human") continue;
|
|
145
|
+
skipped.push({ id: criterion.id, title: criterion.title, evaluationType: "human" });
|
|
146
|
+
}
|
|
147
|
+
return skipped;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Read + validate `<repoRoot>/.case/rubric.yaml` from a local case checkout. Throws an actionable
|
|
152
|
+
* error if the rubric is absent or malformed (the checkout was already structurally re-validated on
|
|
153
|
+
* open — Task 5.2 — so this is a focused, fail-loud read, not the full structural backstop).
|
|
154
|
+
*/
|
|
155
|
+
export function loadRubric(repoRoot: string): Rubric {
|
|
156
|
+
const loaded = loadCaseDir(repoRoot);
|
|
157
|
+
if (loaded.parseErrors.length > 0) {
|
|
158
|
+
const detail = loaded.parseErrors.map((e) => `${e.file}: ${e.message}`).join("; ");
|
|
159
|
+
throw new Error(`Could not parse the case rubric: ${detail}`);
|
|
160
|
+
}
|
|
161
|
+
if (loaded.content.rubric === undefined) {
|
|
162
|
+
throw new Error(`No .case/rubric.yaml found under ${repoRoot}`);
|
|
163
|
+
}
|
|
164
|
+
const parsed = rubricSchema.safeParse(loaded.content.rubric);
|
|
165
|
+
if (!parsed.success) {
|
|
166
|
+
const detail = parsed.error.issues.map((i) => i.message).join("; ");
|
|
167
|
+
throw new Error(`.case/rubric.yaml is malformed: ${detail}`);
|
|
168
|
+
}
|
|
169
|
+
return parsed.data;
|
|
170
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fito-knowledge-push
|
|
3
|
+
description: >
|
|
4
|
+
Push generator-produced knowledge components to the backend
|
|
5
|
+
Knowledge Repository — the PUSH step of the Fito knowledge
|
|
6
|
+
pipeline. One payload per run; a near-duplicate 409 stops the
|
|
7
|
+
push for the human author's resolution (link, supersede, skip,
|
|
8
|
+
or acknowledged override). Driven by /fito-push-knowledge.
|
|
9
|
+
allowed-tools: bash
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Fito Knowledge Push
|
|
13
|
+
|
|
14
|
+
Run the script from wherever you are — the command below names this
|
|
15
|
+
skill's directory itself. One payload file per run — the
|
|
16
|
+
`/fito-push-knowledge` orchestrator loops over the generated files, so every push (and every
|
|
17
|
+
409 resolution) is an explicit, per-component action.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- **Fito login** — `/fito-login`. Knowledge writes are bearer-authenticated; the script fails
|
|
22
|
+
with that guidance when no session exists.
|
|
23
|
+
- **Backend reachable**, with the knowledge vocabulary seeded and the payload's technology
|
|
24
|
+
provisioned — every push pulls the registered `Template`s for the component type and the
|
|
25
|
+
technology whose `kind` selects among them.
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
| Env var | Default | Purpose |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin |
|
|
32
|
+
|
|
33
|
+
## Push one payload
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
node <fito-knowledge-push skill dir>/push.js <payload-file> [--version <label>]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`<payload-file>` is one generator output (`{metadata, content}` JSON, e.g.
|
|
40
|
+
`./output/3-generate/concept_content/1-dependency-injection.json`). The script validates the
|
|
41
|
+
payload shape, resolves the registered template — by component type and by the technology's `kind`,
|
|
42
|
+
which selects the variant when a type has more than one — maps it onto the write contract
|
|
43
|
+
(`technology`, `templateId`, `name`, `version`, `content`), asks the backend's **advisory
|
|
44
|
+
near-duplicate probe** (nothing stored yet — see the next section), and POSTs
|
|
45
|
+
`POST /knowledge/{type}`. `--version` labels the component; omitted, the backend defaults `1.0.0`.
|
|
46
|
+
|
|
47
|
+
**Done when** it prints `✓ Created <canonical-reference> — "<name>" (version <v>)` — record
|
|
48
|
+
that reference for the flow's final report.
|
|
49
|
+
|
|
50
|
+
## Similar components (advisory probe) — the author decides
|
|
51
|
+
|
|
52
|
+
Before storing, the plain push probes for existing components similar to the payload — including
|
|
53
|
+
genuine near-duplicates *reframed* below the hard duplicate bar, which the 409 gate alone would
|
|
54
|
+
let coexist unseen (the Task 8.6 smoke-run finding). On any match the script exits **non-zero**
|
|
55
|
+
with nothing stored, printing each match with its similarity and the choices:
|
|
56
|
+
|
|
57
|
+
- **link** / **supersede** — as on the 409 (preferred); the printed commands target the closest
|
|
58
|
+
match.
|
|
59
|
+
- **skip** — push nothing; move to the next payload.
|
|
60
|
+
- **proceed** — `--proceed`: store an independent component that will **coexist** with the
|
|
61
|
+
matches. This is the author's call after seeing the similarities; a match at the hard duplicate
|
|
62
|
+
bar still rejects the proceed with the near-duplicate 409 and its override echo.
|
|
63
|
+
|
|
64
|
+
Never pick for the author, and never re-run without their choice — the probe stop is an author
|
|
65
|
+
decision point exactly like the 409.
|
|
66
|
+
|
|
67
|
+
**Done when** the author's chosen re-run prints `✓ Created …` (or the author chose skip).
|
|
68
|
+
|
|
69
|
+
## Near-duplicate 409 — the resolution is the author's call
|
|
70
|
+
|
|
71
|
+
When the backend flags a near-duplicate, the script exits **non-zero** and prints the
|
|
72
|
+
duplicate's canonical reference plus the four choices with their exact re-run commands:
|
|
73
|
+
|
|
74
|
+
- **link** — `--link '<duplicate-ref>'`: store as an **alternative definition** of the
|
|
75
|
+
duplicate (preferred).
|
|
76
|
+
- **supersede** — `--supersede '<duplicate-ref>' [--version <label>]`: store as the
|
|
77
|
+
duplicate's **new version** (preferred). If the target is itself already superseded, the
|
|
78
|
+
backend answers 409 with the chain head under `supersededBy`; the script prints the re-run
|
|
79
|
+
against that head — relay it and let the author retarget.
|
|
80
|
+
- **skip** — push nothing; move to the next payload.
|
|
81
|
+
- **override** — `--override '<duplicate-ref>'`: re-POST echoing the reported reference as
|
|
82
|
+
`overrideAcknowledging` — the false-positive escape. Consequence: an **independent
|
|
83
|
+
near-duplicate component is stored and will coexist** with the duplicate in the vocabulary.
|
|
84
|
+
Only run it after the author explicitly confirms that consequence.
|
|
85
|
+
|
|
86
|
+
Never pick a resolution yourself, and never re-run without one — nothing is resubmitted
|
|
87
|
+
without an explicit human choice.
|
|
88
|
+
|
|
89
|
+
**Re-pushing an already-pushed payload** (an interrupted or repeated run over the same
|
|
90
|
+
directory) surfaces as this same 409 — with the duplicate being the component created from
|
|
91
|
+
that very file earlier (same name, matching content). The expected resolution there is
|
|
92
|
+
**skip**: the payload is already in the vocabulary.
|
|
93
|
+
|
|
94
|
+
**Done when** the author's chosen re-run prints `✓ Created …` (or the author chose skip).
|
|
95
|
+
|
|
96
|
+
## Other failures
|
|
97
|
+
|
|
98
|
+
Malformed payload files, an unknown technology, and field-schema violations (422 — the
|
|
99
|
+
backend itemizes the offending fields) fail with the reason printed. The script never retries
|
|
100
|
+
by itself and is safe to re-run — each run POSTs at most once.
|
|
101
|
+
|
|
102
|
+
**Payload files are read-only inputs.** `push.js` only ever reads them (tripwired by a static
|
|
103
|
+
guard on its source), and the flow never edits one to make it pass — a wrong payload is
|
|
104
|
+
surfaced to the author, whose fix is regeneration, not an in-place patch.
|
|
105
|
+
|
|
106
|
+
## Files
|
|
107
|
+
|
|
108
|
+
| File | Role |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `push.ts` | CLI + `runPush` testable core — read/validate payload, resolve session + template, probe, POST, render the near-miss and 409 resolution blocks |
|
|
111
|
+
|
|
112
|
+
Payload→request mapping and template resolution live in
|
|
113
|
+
[`shared/knowledge-components/push-payload.ts`](../../shared/knowledge-components/push-payload.ts);
|
|
114
|
+
transport in [the fito-api client](../../shared/fito-api/README.md).
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node push.js <payload-file> [--link <ref> | --supersede <ref> | --override <ref> | --proceed] [--version <label>]`
|
|
3
|
+
* — push one generator output payload to the backend Knowledge Repository (PLAN Task 8.5, the
|
|
4
|
+
* pipeline's PUSH step). The plain run first asks the backend's advisory near-duplicate probe
|
|
5
|
+
* (Task 8.7): similar existing components — even below the hard 409 bar — stop the push with
|
|
6
|
+
* their similarities and the choices printed, before anything is stored; `--proceed` is the
|
|
7
|
+
* author's decision to store anyway and skips the probe. Then it creates-and-publishes; on a
|
|
8
|
+
* near-duplicate 409 it stops and prints the duplicate + the resolution commands for the
|
|
9
|
+
* `/fito-push-knowledge` orchestrator to relay — it never resolves a 409 or a probe stop itself.
|
|
10
|
+
* The author's explicit choice comes back as a re-run with exactly one flag: `--link`
|
|
11
|
+
* (alternative definition of the duplicate), `--supersede` (the duplicate's new version;
|
|
12
|
+
* `--version` bumps the label), `--override` (store an independent near-duplicate, echoing the
|
|
13
|
+
* exact reference the 409 reported), or `--proceed`. Skipping is simply not re-running.
|
|
14
|
+
*
|
|
15
|
+
* `runPush` is the testable core (injectable client/home); `main` is the thin CLI wrapper.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
18
|
+
import * as os from "node:os";
|
|
19
|
+
import * as path from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import { FitoApiError, createFitoApiClient, } from "../../shared/fito-api/client.js";
|
|
22
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.js";
|
|
23
|
+
import { generatorPayloadSchema, resolveRegisteredTemplate, toCreateInput, } from "../../shared/knowledge-components/push-payload.js";
|
|
24
|
+
import { parseKnowledgeReference } from "../../shared/knowledge-components/reference.js";
|
|
25
|
+
/**
|
|
26
|
+
* Push one payload: read + validate it, resolve the Fito session and the registered template — by
|
|
27
|
+
* component type *and* the subject technology's kind, which is what selects the right variant when
|
|
28
|
+
* a type has more than one — map it onto the write contract, and POST the endpoint the resolution
|
|
29
|
+
* selects. An unprovisioned technology stops the run here, before anything is written. A plain
|
|
30
|
+
* create first runs the advisory near-duplicate probe (unless [RunPushOptions.proceed]) and stops
|
|
31
|
+
* on any match — storing nothing. Backend conflicts (near-duplicate `duplicateId`,
|
|
32
|
+
* already-superseded `supersededBy`) propagate as `FitoApiError` for the caller to surface —
|
|
33
|
+
* resolving them, like the probe's near-misses, is the human author's call.
|
|
34
|
+
*/
|
|
35
|
+
export async function runPush(options) {
|
|
36
|
+
const home = options.home ?? os.homedir();
|
|
37
|
+
const client = options.client ?? createFitoApiClient();
|
|
38
|
+
const payload = readPayload(options.payloadPath);
|
|
39
|
+
const { tokens } = await resolveFitoSession(client, home);
|
|
40
|
+
const template = await resolveRegisteredTemplate(payload.metadata.type, payload.metadata.technology_slug, client);
|
|
41
|
+
const input = toCreateInput(payload, template.id, options.version);
|
|
42
|
+
const created = async (component) => ({
|
|
43
|
+
kind: "created",
|
|
44
|
+
component: await component,
|
|
45
|
+
});
|
|
46
|
+
const resolution = options.resolution;
|
|
47
|
+
if (!resolution) {
|
|
48
|
+
if (!options.proceed) {
|
|
49
|
+
const matches = await client.probeNearDuplicates(tokens.accessToken, payload.metadata.type, input);
|
|
50
|
+
if (matches.length > 0) {
|
|
51
|
+
return { kind: "near-misses", matches };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return created(client.createKnowledgeComponent(tokens.accessToken, payload.metadata.type, input));
|
|
55
|
+
}
|
|
56
|
+
switch (resolution.kind) {
|
|
57
|
+
case "link": {
|
|
58
|
+
const target = resolveTarget(resolution.target, payload);
|
|
59
|
+
return created(client.createAlternativeDefinition(tokens.accessToken, target.type, target.slug, input));
|
|
60
|
+
}
|
|
61
|
+
case "supersede": {
|
|
62
|
+
const target = resolveTarget(resolution.target, payload);
|
|
63
|
+
return created(client.createNewVersion(tokens.accessToken, target.type, target.slug, input));
|
|
64
|
+
}
|
|
65
|
+
case "override": {
|
|
66
|
+
return created(client.createKnowledgeComponent(tokens.accessToken, payload.metadata.type, {
|
|
67
|
+
...input,
|
|
68
|
+
overrideAcknowledging: resolution.duplicate,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parse a resolution target reference and require its type to match the payload's: a link is an
|
|
75
|
+
* alternative definition (same type by the domain model) and a supersede is a version of the same
|
|
76
|
+
* component — a cross-type target is definitionally wrong, so fail before any request.
|
|
77
|
+
*/
|
|
78
|
+
function resolveTarget(reference, payload) {
|
|
79
|
+
const target = parseKnowledgeReference(reference);
|
|
80
|
+
if (target.type !== payload.metadata.type) {
|
|
81
|
+
throw new Error(`The target "${reference}" is a ${target.type} but the payload is a ${payload.metadata.type} — ` +
|
|
82
|
+
`link and supersede must target a component of the payload's own type.`);
|
|
83
|
+
}
|
|
84
|
+
return target;
|
|
85
|
+
}
|
|
86
|
+
/** Load one generator payload file, failing with an actionable message on any malformed input. */
|
|
87
|
+
function readPayload(payloadPath) {
|
|
88
|
+
if (!existsSync(payloadPath)) {
|
|
89
|
+
throw new Error(`No payload file at:\n ${payloadPath}`);
|
|
90
|
+
}
|
|
91
|
+
let raw;
|
|
92
|
+
try {
|
|
93
|
+
raw = readFileSync(payloadPath, "utf8");
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
97
|
+
throw new Error(`Could not read the payload file:\n ${payloadPath}\n (${detail})`);
|
|
98
|
+
}
|
|
99
|
+
let parsed;
|
|
100
|
+
try {
|
|
101
|
+
parsed = JSON.parse(raw);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new Error(`The payload file is not valid JSON:\n ${payloadPath}`);
|
|
105
|
+
}
|
|
106
|
+
const result = generatorPayloadSchema.safeParse(parsed);
|
|
107
|
+
if (!result.success) {
|
|
108
|
+
throw new Error(`The payload file does not match the generator payload shape ({metadata, content}):\n ${payloadPath}\n${result.error.message}`);
|
|
109
|
+
}
|
|
110
|
+
return result.data;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Render a knowledge write 409 into the block the orchestrator relays to the human author, or
|
|
114
|
+
* `undefined` when the error is not one of the two conflicts. The near-duplicate block names the
|
|
115
|
+
* duplicate and the four choices (link / supersede / skip / override) with their exact re-run
|
|
116
|
+
* commands and override's coexistence consequence; the already-superseded block points the
|
|
117
|
+
* supersede at the chain head the backend reported.
|
|
118
|
+
*/
|
|
119
|
+
export function renderPushConflict(error, payloadPath) {
|
|
120
|
+
if (error.duplicateId) {
|
|
121
|
+
const ref = error.duplicateId;
|
|
122
|
+
return [
|
|
123
|
+
`Near-duplicate rejected (409): ${error.message}`,
|
|
124
|
+
"",
|
|
125
|
+
` duplicate: ${ref}`,
|
|
126
|
+
"",
|
|
127
|
+
"The author must choose the resolution — nothing is resubmitted without an explicit choice:",
|
|
128
|
+
` link node push.js ${payloadPath} --link '${ref}'`,
|
|
129
|
+
" store as an alternative definition of the duplicate (preferred)",
|
|
130
|
+
` supersede node push.js ${payloadPath} --supersede '${ref}' [--version <label>]`,
|
|
131
|
+
" store as the duplicate's new version (preferred)",
|
|
132
|
+
" skip do not push this payload (no command — just move on)",
|
|
133
|
+
` override node push.js ${payloadPath} --override '${ref}'`,
|
|
134
|
+
" store an independent near-duplicate component that will coexist with the",
|
|
135
|
+
" duplicate in the vocabulary — the false-positive escape; confirm the author",
|
|
136
|
+
" accepts that consequence before running it",
|
|
137
|
+
].join("\n");
|
|
138
|
+
}
|
|
139
|
+
if (error.supersededBy) {
|
|
140
|
+
const head = error.supersededBy;
|
|
141
|
+
return [
|
|
142
|
+
`Target already superseded (409): ${error.message}`,
|
|
143
|
+
"",
|
|
144
|
+
` supersededBy: ${head}`,
|
|
145
|
+
"",
|
|
146
|
+
"Version chains are linear — a new version must target the chain head. Offer the author",
|
|
147
|
+
"a re-run against the reported successor:",
|
|
148
|
+
` node push.js ${payloadPath} --supersede '${head}' [--version <label>]`,
|
|
149
|
+
].join("\n");
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Render the advisory probe's near-misses into the block the orchestrator relays to the human
|
|
155
|
+
* author. Similarities are shown so the author can judge how close each match really is. Nothing
|
|
156
|
+
* has been stored when this block prints.
|
|
157
|
+
*
|
|
158
|
+
* Each line names both version axes apart — the content revision (ADR-010) and the major lines the
|
|
159
|
+
* match applies to (ADR-011) — plus the server's reading of that scope against the candidate.
|
|
160
|
+
* The re-run commands target the closest **same-line** match rather than the closest overall,
|
|
161
|
+
* because only a same-line match is one the hard gate would refuse: linking to a cross-line match
|
|
162
|
+
* would mint the `alternativeDefinitionOf` edge ADR-011 §7 forbids for divergence across majors,
|
|
163
|
+
* and superseding one is worse still — a new version inherits its predecessor's version scope, so
|
|
164
|
+
* the component would silently land on the wrong line.
|
|
165
|
+
*/
|
|
166
|
+
export function renderNearMisses(matches, payloadPath) {
|
|
167
|
+
const listed = matches.map((match) => {
|
|
168
|
+
const appliesTo = match.technologyVersions.map((version) => version.slug).join(", ");
|
|
169
|
+
const scope = match.sameVersionScope ? "same line" : "different line";
|
|
170
|
+
return (` ${match.similarity.toFixed(2)} ${match.id} — "${match.name}" ` +
|
|
171
|
+
`(revision ${match.version}, applies to ${appliesTo} — ${scope})`);
|
|
172
|
+
});
|
|
173
|
+
const closestSameLine = matches.find((match) => match.sameVersionScope);
|
|
174
|
+
// With no same-line match there is nothing to link or supersede against: the gate would admit
|
|
175
|
+
// this candidate, and §7 says divergence across majors is separate components, not links.
|
|
176
|
+
const resolutions = closestSameLine === undefined
|
|
177
|
+
? [" every match above is on a different major line, so none is a duplicate of this candidate"]
|
|
178
|
+
: [
|
|
179
|
+
` link node push.js ${payloadPath} --link '${closestSameLine.id}'`,
|
|
180
|
+
" store as an alternative definition of the closest same-line match (preferred)",
|
|
181
|
+
` supersede node push.js ${payloadPath} --supersede '${closestSameLine.id}' [--version <label>]`,
|
|
182
|
+
" store as the closest same-line match's new version (preferred)",
|
|
183
|
+
];
|
|
184
|
+
return [
|
|
185
|
+
"Similar existing components found (advisory probe) — nothing has been stored:",
|
|
186
|
+
"",
|
|
187
|
+
...listed,
|
|
188
|
+
"",
|
|
189
|
+
"The author must choose — nothing is stored without an explicit choice:",
|
|
190
|
+
...resolutions,
|
|
191
|
+
" skip do not push this payload (no command — just move on)",
|
|
192
|
+
` proceed node push.js ${payloadPath} --proceed`,
|
|
193
|
+
" store an independent component that will coexist with the matches; a match",
|
|
194
|
+
" at the hard duplicate bar still rejects this with the 409 and its override echo",
|
|
195
|
+
].join("\n");
|
|
196
|
+
}
|
|
197
|
+
const USAGE = "Usage: node push.js <payload-file> [--link <ref> | --supersede <ref> | --override <ref> | --proceed] [--version <label>]";
|
|
198
|
+
function parseArgs(argv) {
|
|
199
|
+
const [payloadPath, ...rest] = argv;
|
|
200
|
+
if (!payloadPath)
|
|
201
|
+
return undefined;
|
|
202
|
+
const options = { payloadPath };
|
|
203
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
204
|
+
const flag = rest[i];
|
|
205
|
+
const value = rest[i + 1];
|
|
206
|
+
if (flag === "--version" && value) {
|
|
207
|
+
options.version = value;
|
|
208
|
+
i += 1;
|
|
209
|
+
}
|
|
210
|
+
else if (flag === "--proceed") {
|
|
211
|
+
options.proceed = true;
|
|
212
|
+
}
|
|
213
|
+
else if ((flag === "--link" || flag === "--supersede" || flag === "--override") && value) {
|
|
214
|
+
if (options.resolution)
|
|
215
|
+
return undefined; // at most one resolution flag
|
|
216
|
+
options.resolution =
|
|
217
|
+
flag === "--link"
|
|
218
|
+
? { kind: "link", target: value }
|
|
219
|
+
: flag === "--supersede"
|
|
220
|
+
? { kind: "supersede", target: value }
|
|
221
|
+
: { kind: "override", duplicate: value };
|
|
222
|
+
i += 1;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (options.proceed && options.resolution)
|
|
229
|
+
return undefined; // proceed only modifies the plain create
|
|
230
|
+
return options;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The success line. It names the payload file alongside the created canonical reference so the
|
|
234
|
+
* orchestrator's file→reference ledger can be reconstructed from the transcript alone — the
|
|
235
|
+
* stateless answer to "which payloads are already pushed?" on an interrupted flow.
|
|
236
|
+
*/
|
|
237
|
+
export function describeOutcome(created, payloadPath, resolution) {
|
|
238
|
+
const headline = `✓ Created ${created.id} — "${created.name}" (version ${created.version}) ← ${payloadPath}`;
|
|
239
|
+
if (!resolution)
|
|
240
|
+
return headline;
|
|
241
|
+
switch (resolution.kind) {
|
|
242
|
+
case "link":
|
|
243
|
+
return `${headline}\n linked as an alternative definition of ${resolution.target}`;
|
|
244
|
+
case "supersede":
|
|
245
|
+
return `${headline}\n supersedes ${resolution.target}`;
|
|
246
|
+
case "override":
|
|
247
|
+
return `${headline}\n stored independently (override acknowledged: ${resolution.duplicate})`;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function main() {
|
|
251
|
+
const options = parseArgs(process.argv.slice(2));
|
|
252
|
+
if (!options) {
|
|
253
|
+
console.error(USAGE);
|
|
254
|
+
process.exitCode = 1;
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const outcome = await runPush(options);
|
|
259
|
+
if (outcome.kind === "near-misses") {
|
|
260
|
+
console.error(renderNearMisses(outcome.matches, options.payloadPath));
|
|
261
|
+
process.exitCode = 1;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
console.log(describeOutcome(outcome.component, options.payloadPath, options.resolution));
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error instanceof FitoApiError) {
|
|
268
|
+
const conflict = renderPushConflict(error, options.payloadPath);
|
|
269
|
+
console.error(conflict ?? `✗ Push failed (${error.status}): ${error.message}`);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
273
|
+
}
|
|
274
|
+
process.exitCode = 1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** Only auto-invoke the CLI when run directly (`node push.js …`), not when imported. */
|
|
278
|
+
const entry = process.argv[1];
|
|
279
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
280
|
+
if (isMainModule) {
|
|
281
|
+
void main();
|
|
282
|
+
}
|