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,360 @@
|
|
|
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
|
+
|
|
22
|
+
import {
|
|
23
|
+
FitoApiError,
|
|
24
|
+
createFitoApiClient,
|
|
25
|
+
type FitoApiClient,
|
|
26
|
+
type KnowledgeComponent,
|
|
27
|
+
type NearDuplicateMatch,
|
|
28
|
+
} from "../../shared/fito-api/client.ts";
|
|
29
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.ts";
|
|
30
|
+
import {
|
|
31
|
+
generatorPayloadSchema,
|
|
32
|
+
resolveRegisteredTemplate,
|
|
33
|
+
toCreateInput,
|
|
34
|
+
type GeneratorPayload,
|
|
35
|
+
} from "../../shared/knowledge-components/push-payload.ts";
|
|
36
|
+
import { parseKnowledgeReference } from "../../shared/knowledge-components/reference.ts";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The fito-api surface this flow needs: the session lookup, the template read, the technology read
|
|
40
|
+
* (whose `kind` selects the template variant — Task 9c.2), the advisory probe, and the three writes.
|
|
41
|
+
*/
|
|
42
|
+
type PushClient = Pick<
|
|
43
|
+
FitoApiClient,
|
|
44
|
+
| "meWithRefresh"
|
|
45
|
+
| "getKnowledgeTemplates"
|
|
46
|
+
| "getTechnology"
|
|
47
|
+
| "probeNearDuplicates"
|
|
48
|
+
| "createKnowledgeComponent"
|
|
49
|
+
| "createAlternativeDefinition"
|
|
50
|
+
| "createNewVersion"
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The author's explicit 409 resolution, absent on the plain create. `target` / `duplicate` is a
|
|
55
|
+
* canonical component reference (`concept:spring-boot.dependency-injection`) — for `override`, the
|
|
56
|
+
* exact reference the near-duplicate 409 reported.
|
|
57
|
+
*/
|
|
58
|
+
export type PushResolution =
|
|
59
|
+
| { kind: "link"; target: string }
|
|
60
|
+
| { kind: "supersede"; target: string }
|
|
61
|
+
| { kind: "override"; duplicate: string };
|
|
62
|
+
|
|
63
|
+
export interface RunPushOptions {
|
|
64
|
+
/** Path to one generator output payload (`{metadata, content}` JSON). */
|
|
65
|
+
payloadPath: string;
|
|
66
|
+
resolution?: PushResolution;
|
|
67
|
+
/**
|
|
68
|
+
* The author's decision to store despite the advisory probe's near-misses: skips the probe and
|
|
69
|
+
* creates. Meaningless with a resolution flag — those paths never probe (each is already an
|
|
70
|
+
* explicit author decision).
|
|
71
|
+
*/
|
|
72
|
+
proceed?: boolean;
|
|
73
|
+
/** Component version label; omitted → the backend defaults `1.0.0`. */
|
|
74
|
+
version?: string;
|
|
75
|
+
home?: string;
|
|
76
|
+
client?: PushClient;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A push run's result: `created` carries the persisted component; `near-misses` means the
|
|
81
|
+
* advisory probe found similar existing components and nothing was stored — the author chooses
|
|
82
|
+
* how to continue (link / supersede / proceed / skip).
|
|
83
|
+
*/
|
|
84
|
+
export type PushOutcome =
|
|
85
|
+
| { kind: "created"; component: KnowledgeComponent }
|
|
86
|
+
| { kind: "near-misses"; matches: NearDuplicateMatch[] };
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Push one payload: read + validate it, resolve the Fito session and the registered template — by
|
|
90
|
+
* component type *and* the subject technology's kind, which is what selects the right variant when
|
|
91
|
+
* a type has more than one — map it onto the write contract, and POST the endpoint the resolution
|
|
92
|
+
* selects. An unprovisioned technology stops the run here, before anything is written. A plain
|
|
93
|
+
* create first runs the advisory near-duplicate probe (unless [RunPushOptions.proceed]) and stops
|
|
94
|
+
* on any match — storing nothing. Backend conflicts (near-duplicate `duplicateId`,
|
|
95
|
+
* already-superseded `supersededBy`) propagate as `FitoApiError` for the caller to surface —
|
|
96
|
+
* resolving them, like the probe's near-misses, is the human author's call.
|
|
97
|
+
*/
|
|
98
|
+
export async function runPush(options: RunPushOptions): Promise<PushOutcome> {
|
|
99
|
+
const home = options.home ?? os.homedir();
|
|
100
|
+
const client = options.client ?? createFitoApiClient();
|
|
101
|
+
|
|
102
|
+
const payload = readPayload(options.payloadPath);
|
|
103
|
+
const { tokens } = await resolveFitoSession(client, home);
|
|
104
|
+
const template = await resolveRegisteredTemplate(payload.metadata.type, payload.metadata.technology_slug, client);
|
|
105
|
+
const input = toCreateInput(payload, template.id, options.version);
|
|
106
|
+
|
|
107
|
+
const created = async (component: Promise<KnowledgeComponent>): Promise<PushOutcome> => ({
|
|
108
|
+
kind: "created",
|
|
109
|
+
component: await component,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const resolution = options.resolution;
|
|
113
|
+
if (!resolution) {
|
|
114
|
+
if (!options.proceed) {
|
|
115
|
+
const matches = await client.probeNearDuplicates(tokens.accessToken, payload.metadata.type, input);
|
|
116
|
+
if (matches.length > 0) {
|
|
117
|
+
return { kind: "near-misses", matches };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return created(client.createKnowledgeComponent(tokens.accessToken, payload.metadata.type, input));
|
|
121
|
+
}
|
|
122
|
+
switch (resolution.kind) {
|
|
123
|
+
case "link": {
|
|
124
|
+
const target = resolveTarget(resolution.target, payload);
|
|
125
|
+
return created(client.createAlternativeDefinition(tokens.accessToken, target.type, target.slug, input));
|
|
126
|
+
}
|
|
127
|
+
case "supersede": {
|
|
128
|
+
const target = resolveTarget(resolution.target, payload);
|
|
129
|
+
return created(client.createNewVersion(tokens.accessToken, target.type, target.slug, input));
|
|
130
|
+
}
|
|
131
|
+
case "override": {
|
|
132
|
+
return created(
|
|
133
|
+
client.createKnowledgeComponent(tokens.accessToken, payload.metadata.type, {
|
|
134
|
+
...input,
|
|
135
|
+
overrideAcknowledging: resolution.duplicate,
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Parse a resolution target reference and require its type to match the payload's: a link is an
|
|
144
|
+
* alternative definition (same type by the domain model) and a supersede is a version of the same
|
|
145
|
+
* component — a cross-type target is definitionally wrong, so fail before any request.
|
|
146
|
+
*/
|
|
147
|
+
function resolveTarget(reference: string, payload: GeneratorPayload): { type: GeneratorPayload["metadata"]["type"]; slug: string } {
|
|
148
|
+
const target = parseKnowledgeReference(reference);
|
|
149
|
+
if (target.type !== payload.metadata.type) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`The target "${reference}" is a ${target.type} but the payload is a ${payload.metadata.type} — ` +
|
|
152
|
+
`link and supersede must target a component of the payload's own type.`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return target;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Load one generator payload file, failing with an actionable message on any malformed input. */
|
|
159
|
+
function readPayload(payloadPath: string): GeneratorPayload {
|
|
160
|
+
if (!existsSync(payloadPath)) {
|
|
161
|
+
throw new Error(`No payload file at:\n ${payloadPath}`);
|
|
162
|
+
}
|
|
163
|
+
let raw: string;
|
|
164
|
+
try {
|
|
165
|
+
raw = readFileSync(payloadPath, "utf8");
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
168
|
+
throw new Error(`Could not read the payload file:\n ${payloadPath}\n (${detail})`);
|
|
169
|
+
}
|
|
170
|
+
let parsed: unknown;
|
|
171
|
+
try {
|
|
172
|
+
parsed = JSON.parse(raw);
|
|
173
|
+
} catch {
|
|
174
|
+
throw new Error(`The payload file is not valid JSON:\n ${payloadPath}`);
|
|
175
|
+
}
|
|
176
|
+
const result = generatorPayloadSchema.safeParse(parsed);
|
|
177
|
+
if (!result.success) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`The payload file does not match the generator payload shape ({metadata, content}):\n ${payloadPath}\n${result.error.message}`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return result.data;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Render a knowledge write 409 into the block the orchestrator relays to the human author, or
|
|
187
|
+
* `undefined` when the error is not one of the two conflicts. The near-duplicate block names the
|
|
188
|
+
* duplicate and the four choices (link / supersede / skip / override) with their exact re-run
|
|
189
|
+
* commands and override's coexistence consequence; the already-superseded block points the
|
|
190
|
+
* supersede at the chain head the backend reported.
|
|
191
|
+
*/
|
|
192
|
+
export function renderPushConflict(error: FitoApiError, payloadPath: string): string | undefined {
|
|
193
|
+
if (error.duplicateId) {
|
|
194
|
+
const ref = error.duplicateId;
|
|
195
|
+
return [
|
|
196
|
+
`Near-duplicate rejected (409): ${error.message}`,
|
|
197
|
+
"",
|
|
198
|
+
` duplicate: ${ref}`,
|
|
199
|
+
"",
|
|
200
|
+
"The author must choose the resolution — nothing is resubmitted without an explicit choice:",
|
|
201
|
+
` link node push.js ${payloadPath} --link '${ref}'`,
|
|
202
|
+
" store as an alternative definition of the duplicate (preferred)",
|
|
203
|
+
` supersede node push.js ${payloadPath} --supersede '${ref}' [--version <label>]`,
|
|
204
|
+
" store as the duplicate's new version (preferred)",
|
|
205
|
+
" skip do not push this payload (no command — just move on)",
|
|
206
|
+
` override node push.js ${payloadPath} --override '${ref}'`,
|
|
207
|
+
" store an independent near-duplicate component that will coexist with the",
|
|
208
|
+
" duplicate in the vocabulary — the false-positive escape; confirm the author",
|
|
209
|
+
" accepts that consequence before running it",
|
|
210
|
+
].join("\n");
|
|
211
|
+
}
|
|
212
|
+
if (error.supersededBy) {
|
|
213
|
+
const head = error.supersededBy;
|
|
214
|
+
return [
|
|
215
|
+
`Target already superseded (409): ${error.message}`,
|
|
216
|
+
"",
|
|
217
|
+
` supersededBy: ${head}`,
|
|
218
|
+
"",
|
|
219
|
+
"Version chains are linear — a new version must target the chain head. Offer the author",
|
|
220
|
+
"a re-run against the reported successor:",
|
|
221
|
+
` node push.js ${payloadPath} --supersede '${head}' [--version <label>]`,
|
|
222
|
+
].join("\n");
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Render the advisory probe's near-misses into the block the orchestrator relays to the human
|
|
229
|
+
* author. Similarities are shown so the author can judge how close each match really is. Nothing
|
|
230
|
+
* has been stored when this block prints.
|
|
231
|
+
*
|
|
232
|
+
* Each line names both version axes apart — the content revision (ADR-010) and the major lines the
|
|
233
|
+
* match applies to (ADR-011) — plus the server's reading of that scope against the candidate.
|
|
234
|
+
* The re-run commands target the closest **same-line** match rather than the closest overall,
|
|
235
|
+
* because only a same-line match is one the hard gate would refuse: linking to a cross-line match
|
|
236
|
+
* would mint the `alternativeDefinitionOf` edge ADR-011 §7 forbids for divergence across majors,
|
|
237
|
+
* and superseding one is worse still — a new version inherits its predecessor's version scope, so
|
|
238
|
+
* the component would silently land on the wrong line.
|
|
239
|
+
*/
|
|
240
|
+
export function renderNearMisses(matches: NearDuplicateMatch[], payloadPath: string): string {
|
|
241
|
+
const listed = matches.map((match) => {
|
|
242
|
+
const appliesTo = match.technologyVersions.map((version) => version.slug).join(", ");
|
|
243
|
+
const scope = match.sameVersionScope ? "same line" : "different line";
|
|
244
|
+
return (
|
|
245
|
+
` ${match.similarity.toFixed(2)} ${match.id} — "${match.name}" ` +
|
|
246
|
+
`(revision ${match.version}, applies to ${appliesTo} — ${scope})`
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
const closestSameLine = matches.find((match) => match.sameVersionScope);
|
|
250
|
+
// With no same-line match there is nothing to link or supersede against: the gate would admit
|
|
251
|
+
// this candidate, and §7 says divergence across majors is separate components, not links.
|
|
252
|
+
const resolutions =
|
|
253
|
+
closestSameLine === undefined
|
|
254
|
+
? [" every match above is on a different major line, so none is a duplicate of this candidate"]
|
|
255
|
+
: [
|
|
256
|
+
` link node push.js ${payloadPath} --link '${closestSameLine.id}'`,
|
|
257
|
+
" store as an alternative definition of the closest same-line match (preferred)",
|
|
258
|
+
` supersede node push.js ${payloadPath} --supersede '${closestSameLine.id}' [--version <label>]`,
|
|
259
|
+
" store as the closest same-line match's new version (preferred)",
|
|
260
|
+
];
|
|
261
|
+
return [
|
|
262
|
+
"Similar existing components found (advisory probe) — nothing has been stored:",
|
|
263
|
+
"",
|
|
264
|
+
...listed,
|
|
265
|
+
"",
|
|
266
|
+
"The author must choose — nothing is stored without an explicit choice:",
|
|
267
|
+
...resolutions,
|
|
268
|
+
" skip do not push this payload (no command — just move on)",
|
|
269
|
+
` proceed node push.js ${payloadPath} --proceed`,
|
|
270
|
+
" store an independent component that will coexist with the matches; a match",
|
|
271
|
+
" at the hard duplicate bar still rejects this with the 409 and its override echo",
|
|
272
|
+
].join("\n");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const USAGE =
|
|
276
|
+
"Usage: node push.js <payload-file> [--link <ref> | --supersede <ref> | --override <ref> | --proceed] [--version <label>]";
|
|
277
|
+
|
|
278
|
+
function parseArgs(argv: string[]): RunPushOptions | undefined {
|
|
279
|
+
const [payloadPath, ...rest] = argv;
|
|
280
|
+
if (!payloadPath) return undefined;
|
|
281
|
+
const options: RunPushOptions = { payloadPath };
|
|
282
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
283
|
+
const flag = rest[i];
|
|
284
|
+
const value = rest[i + 1];
|
|
285
|
+
if (flag === "--version" && value) {
|
|
286
|
+
options.version = value;
|
|
287
|
+
i += 1;
|
|
288
|
+
} else if (flag === "--proceed") {
|
|
289
|
+
options.proceed = true;
|
|
290
|
+
} else if ((flag === "--link" || flag === "--supersede" || flag === "--override") && value) {
|
|
291
|
+
if (options.resolution) return undefined; // at most one resolution flag
|
|
292
|
+
options.resolution =
|
|
293
|
+
flag === "--link"
|
|
294
|
+
? { kind: "link", target: value }
|
|
295
|
+
: flag === "--supersede"
|
|
296
|
+
? { kind: "supersede", target: value }
|
|
297
|
+
: { kind: "override", duplicate: value };
|
|
298
|
+
i += 1;
|
|
299
|
+
} else {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (options.proceed && options.resolution) return undefined; // proceed only modifies the plain create
|
|
304
|
+
return options;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The success line. It names the payload file alongside the created canonical reference so the
|
|
309
|
+
* orchestrator's file→reference ledger can be reconstructed from the transcript alone — the
|
|
310
|
+
* stateless answer to "which payloads are already pushed?" on an interrupted flow.
|
|
311
|
+
*/
|
|
312
|
+
export function describeOutcome(
|
|
313
|
+
created: KnowledgeComponent,
|
|
314
|
+
payloadPath: string,
|
|
315
|
+
resolution?: PushResolution,
|
|
316
|
+
): string {
|
|
317
|
+
const headline = `✓ Created ${created.id} — "${created.name}" (version ${created.version}) ← ${payloadPath}`;
|
|
318
|
+
if (!resolution) return headline;
|
|
319
|
+
switch (resolution.kind) {
|
|
320
|
+
case "link":
|
|
321
|
+
return `${headline}\n linked as an alternative definition of ${resolution.target}`;
|
|
322
|
+
case "supersede":
|
|
323
|
+
return `${headline}\n supersedes ${resolution.target}`;
|
|
324
|
+
case "override":
|
|
325
|
+
return `${headline}\n stored independently (override acknowledged: ${resolution.duplicate})`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function main(): Promise<void> {
|
|
330
|
+
const options = parseArgs(process.argv.slice(2));
|
|
331
|
+
if (!options) {
|
|
332
|
+
console.error(USAGE);
|
|
333
|
+
process.exitCode = 1;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
const outcome = await runPush(options);
|
|
338
|
+
if (outcome.kind === "near-misses") {
|
|
339
|
+
console.error(renderNearMisses(outcome.matches, options.payloadPath));
|
|
340
|
+
process.exitCode = 1;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
console.log(describeOutcome(outcome.component, options.payloadPath, options.resolution));
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (error instanceof FitoApiError) {
|
|
346
|
+
const conflict = renderPushConflict(error, options.payloadPath);
|
|
347
|
+
console.error(conflict ?? `✗ Push failed (${error.status}): ${error.message}`);
|
|
348
|
+
} else {
|
|
349
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
350
|
+
}
|
|
351
|
+
process.exitCode = 1;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Only auto-invoke the CLI when run directly (`node push.js …`), not when imported. */
|
|
356
|
+
const entry = process.argv[1];
|
|
357
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
358
|
+
if (isMainModule) {
|
|
359
|
+
void main();
|
|
360
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fito-source-ingestion
|
|
3
|
+
description: >
|
|
4
|
+
Bundle a case's local source tree for the Fito knowledge
|
|
5
|
+
pipeline — the preferred ingestion source, over fetched
|
|
6
|
+
documentation URLs — or run the authoring-context check
|
|
7
|
+
that gates the identify prompts' `--source .` offer
|
|
8
|
+
(authoring tree vs learner clone). Driven by the
|
|
9
|
+
/fito-identify-* commands.
|
|
10
|
+
allowed-tools: bash
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Fito Source Ingestion
|
|
14
|
+
|
|
15
|
+
Run the scripts with `node <file>.js`. Both are stateless and safe to re-run.
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
| Env var | Default | Purpose |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `FITO_API_BASE_URL` | `http://localhost:8080` | Backend origin (registry lookup — check only) |
|
|
22
|
+
|
|
23
|
+
## Build a source bundle
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node <fito-source-ingestion skill dir>/bundle.js <source-path> [--output <dir>]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Run it from **your own working directory**, as every Fito skill command is — both
|
|
30
|
+
`<source-path>` and `--output` resolve against the current one (an output resolving
|
|
31
|
+
inside the Fito TUI package is refused). `--output`
|
|
32
|
+
defaults to `./output/1-ingest/source_bundle/`, the pipeline's stage convention (beside the
|
|
33
|
+
URL fetcher's `extracted_links_content/`).
|
|
34
|
+
|
|
35
|
+
Walks the case's local checkout and materializes the ingestible subset for the
|
|
36
|
+
identifier agents: a filtered mirror under `<output>/files/`
|
|
37
|
+
— relative paths preserved, so `read`/`grep`/`find` behave like on the real tree — plus
|
|
38
|
+
`<output>/bundle.json` (per-file path + size, and every skipped file with its reason).
|
|
39
|
+
|
|
40
|
+
Not bundled: VCS / dependency / build directories and lockfiles (the pipeline's own
|
|
41
|
+
`output/` workspace and the `.case/` / `.authoring/` authoring artifacts among them),
|
|
42
|
+
binary files, files over 256 KiB, and symlinks (never followed). An empty result is an error, and a non-empty `--output` dir that is not a
|
|
43
|
+
previous bundle is refused, never overwritten.
|
|
44
|
+
|
|
45
|
+
**Done when** it prints `✓ Bundled <n> files … into <dir>` — hand that directory to the
|
|
46
|
+
identifier agent as its docs path.
|
|
47
|
+
|
|
48
|
+
## Authoring-context check
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
node <fito-source-ingestion skill dir>/authoring-check.js [path]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Classifies the case checkout at `path` (default `.`) before offering `--source .`.
|
|
55
|
+
**Not authoring** ⇔ the checkout's `origin` is a GitHub fork whose parent URL is a
|
|
56
|
+
published case registered in the backend — a learner clone by construction
|
|
57
|
+
(`/fito-case-open`). The case repo itself, a tree without an origin remote, a
|
|
58
|
+
non-GitHub origin, and a fork of an unregistered repo are all **authoring**.
|
|
59
|
+
|
|
60
|
+
Requires `git` and an authenticated `gh` (GitHub CLI); the registry lookup needs the
|
|
61
|
+
backend reachable.
|
|
62
|
+
|
|
63
|
+
**Done when** it prints `verdict: authoring` or `verdict: not-authoring`, with the
|
|
64
|
+
reason (and the fork parent's URL when it got that far). A non-zero exit means the
|
|
65
|
+
check could not decide (`gh` missing or unauthenticated, backend unreachable) — treat
|
|
66
|
+
that as "make no offer", never as a verdict.
|
|
67
|
+
|
|
68
|
+
## Files
|
|
69
|
+
|
|
70
|
+
| File | Role |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `bundle.ts` | Source-bundle builder — `buildSourceBundle` testable core + CLI |
|
|
73
|
+
| `authoring-check.ts` | Authoring-context check — origin → `gh` fork/parent → registry match → verdict |
|
|
74
|
+
| — | The real `git`/`gh` executor is the shared `../../shared/shell-exec/exec.ts` (ADR-006) |
|
|
75
|
+
|
|
76
|
+
See [the fito-api client](../../shared/fito-api/README.md) (the `listCases`
|
|
77
|
+
repository-URL lookup the check uses).
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node authoring-check.js [path]` — the fito-source-ingestion **authoring-context check**
|
|
3
|
+
* (Task 8.2), gating the identify prompts' `--source .` offer on a case checkout.
|
|
4
|
+
*
|
|
5
|
+
* Verdict rule (parent-matches-the-registry): **not authoring** ⇔ the checkout's `origin` is a
|
|
6
|
+
* GitHub fork whose parent URL is a **published case registered in the backend** — learner clones
|
|
7
|
+
* are such forks by construction (`/fito-case-open`). Everything determinate else — no origin,
|
|
8
|
+
* a non-GitHub origin, a non-fork, or a fork of an unregistered repo — is **authoring**. When the
|
|
9
|
+
* check cannot decide (git/gh missing, gh unauthenticated, backend unreachable) it exits non-zero
|
|
10
|
+
* instead of guessing; the prompts treat that as "make no offer" (fail-safe).
|
|
11
|
+
*
|
|
12
|
+
* `checkAuthoringContext` is the testable core (executor + client injectable); `main` is the thin
|
|
13
|
+
* CLI wrapper — the `fito-case-runner` open.ts pattern.
|
|
14
|
+
*/
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { createFitoApiClient } from "../../shared/fito-api/client.js";
|
|
18
|
+
import { parseGithubUrl } from "../../shared/github-url/parse.js";
|
|
19
|
+
import { shellExec } from "../../shared/shell-exec/exec.js";
|
|
20
|
+
/** `git remote get-url origin` — the checkout's origin URL (run in the checked dir). */
|
|
21
|
+
export function gitOriginUrlCommand() {
|
|
22
|
+
return { command: "git", args: ["remote", "get-url", "origin"] };
|
|
23
|
+
}
|
|
24
|
+
/** `gh repo view <slug> --json isFork,parent` — is the origin repo a fork, and of what parent? */
|
|
25
|
+
export function ghRepoViewCommand(slug) {
|
|
26
|
+
return { command: "gh", args: ["repo", "view", slug, "--json", "isFork,parent"] };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse a git origin URL into its GitHub `{ owner, repo }`, or null when the origin is not a
|
|
30
|
+
* GitHub repository (the shared `github-url` grammar's lenient form). Unlike the case-runner's
|
|
31
|
+
* parser this accepts ssh forms too: the URL only names the repo for `gh repo view`, it is never
|
|
32
|
+
* handed to the backend reachability ping.
|
|
33
|
+
*/
|
|
34
|
+
export function parseGithubOwnerRepo(url) {
|
|
35
|
+
return parseGithubUrl(url);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse `gh repo view --json isFork,parent` stdout. For a fork, composes the parent's canonical
|
|
39
|
+
* https URL (`https://github.com/<owner-login>/<name>`) — already in the normalized form the
|
|
40
|
+
* backend's repositoryUrl filter matches. Malformed JSON, or a fork whose parent is missing,
|
|
41
|
+
* throws (the check cannot decide, so it must not guess).
|
|
42
|
+
*/
|
|
43
|
+
export function parseRepoView(stdout) {
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(stdout);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
50
|
+
throw new Error(`gh repo view returned malformed JSON: ${detail}`);
|
|
51
|
+
}
|
|
52
|
+
const record = parsed;
|
|
53
|
+
if (record.isFork !== true)
|
|
54
|
+
return { isFork: false, parentUrl: null };
|
|
55
|
+
const login = record.parent?.owner?.login;
|
|
56
|
+
const name = record.parent?.name;
|
|
57
|
+
if (typeof login !== "string" || login.length === 0 || typeof name !== "string" || name.length === 0) {
|
|
58
|
+
throw new Error("gh repo view reported a fork without a resolvable parent");
|
|
59
|
+
}
|
|
60
|
+
return { isFork: true, parentUrl: `https://github.com/${login}/${name}` };
|
|
61
|
+
}
|
|
62
|
+
/** Origin → `gh` fork/parent → registry match → verdict. */
|
|
63
|
+
export async function checkAuthoringContext(options = {}) {
|
|
64
|
+
const dir = options.dir ?? ".";
|
|
65
|
+
const exec = options.exec ?? shellExec;
|
|
66
|
+
const client = options.client ?? createFitoApiClient();
|
|
67
|
+
let originUrl;
|
|
68
|
+
try {
|
|
69
|
+
originUrl = (await exec(gitOriginUrlCommand(), { cwd: dir })).trim();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// A missing git binary means the check cannot decide — propagate. A failing
|
|
73
|
+
// `remote get-url` (no origin remote, or not a git repo) is a determinate
|
|
74
|
+
// authoring signal: learner clones always have their fork as origin.
|
|
75
|
+
if (error instanceof Error && /not found on PATH/.test(error.message))
|
|
76
|
+
throw error;
|
|
77
|
+
return { verdict: "authoring", reason: "the checkout has no git origin remote" };
|
|
78
|
+
}
|
|
79
|
+
const repo = parseGithubOwnerRepo(originUrl);
|
|
80
|
+
if (repo === null) {
|
|
81
|
+
return { verdict: "authoring", reason: `origin ${originUrl} is not a GitHub repository` };
|
|
82
|
+
}
|
|
83
|
+
const slug = `${repo.owner}/${repo.repo}`;
|
|
84
|
+
const view = parseRepoView(await exec(ghRepoViewCommand(slug), { cwd: dir }));
|
|
85
|
+
if (!view.isFork) {
|
|
86
|
+
return { verdict: "authoring", reason: `origin ${slug} is not a fork` };
|
|
87
|
+
}
|
|
88
|
+
const parentUrl = view.parentUrl;
|
|
89
|
+
const page = await client.listCases({ repositoryUrl: parentUrl });
|
|
90
|
+
if (page.total >= 1) {
|
|
91
|
+
return {
|
|
92
|
+
verdict: "not-authoring",
|
|
93
|
+
reason: `origin ${slug} is a fork of ${parentUrl}, a registered case — this is a learner clone`,
|
|
94
|
+
parentUrl,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
verdict: "authoring",
|
|
99
|
+
reason: `origin ${slug} is a fork, but ${parentUrl} is not a registered case`,
|
|
100
|
+
parentUrl,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const USAGE = "usage: node authoring-check.js [path]";
|
|
104
|
+
/** Parse the check CLI args (`argv` minus the node/script prefix): one optional path. */
|
|
105
|
+
export function parseCheckArgs(args) {
|
|
106
|
+
const [dir, ...rest] = args;
|
|
107
|
+
if (rest.length > 0 || (dir !== undefined && dir.startsWith("--"))) {
|
|
108
|
+
throw new Error(USAGE);
|
|
109
|
+
}
|
|
110
|
+
return { dir: dir ?? "." };
|
|
111
|
+
}
|
|
112
|
+
async function main() {
|
|
113
|
+
const { dir } = parseCheckArgs(process.argv.slice(2));
|
|
114
|
+
const result = await checkAuthoringContext({ dir });
|
|
115
|
+
console.log(`verdict: ${result.verdict}`);
|
|
116
|
+
console.log(`reason: ${result.reason}`);
|
|
117
|
+
if (result.parentUrl)
|
|
118
|
+
console.log(`parent: ${result.parentUrl}`);
|
|
119
|
+
}
|
|
120
|
+
/** Only auto-invoke the CLI when run directly (`node authoring-check.js …`), not when imported. */
|
|
121
|
+
const entry = process.argv[1];
|
|
122
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
123
|
+
if (isMainModule) {
|
|
124
|
+
main().catch((error) => {
|
|
125
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
});
|
|
128
|
+
}
|