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,87 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Publish retry state at `~/.fito/publish-state.json` (Task 9.3): `POST /cases` is **not**
|
|
9
|
+
* idempotent — a repeat run would mint a second, orphaned draft — so the minted case id is
|
|
10
|
+
* remembered here, keyed by the case's `repositoryUrl`, until the publish succeeds. Kept in
|
|
11
|
+
* `~/.fito` (the TUI's local-state home) and **not** in the case repo, where it would trip the
|
|
12
|
+
* publish flow's own clean-tree guard on every retry.
|
|
13
|
+
*
|
|
14
|
+
* An entry is trusted only when its stored `apiBaseUrl` matches the current backend — a
|
|
15
|
+
* dev-vs-prod switch ignores it (and registers fresh) instead of 404ing on a foreign id.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const entrySchema = z.object({
|
|
19
|
+
caseId: z.string().min(1),
|
|
20
|
+
apiBaseUrl: z.string().min(1),
|
|
21
|
+
registeredAt: z.string().min(1),
|
|
22
|
+
});
|
|
23
|
+
const stateSchema = z.record(z.string(), entrySchema);
|
|
24
|
+
|
|
25
|
+
type PublishState = z.infer<typeof stateSchema>;
|
|
26
|
+
|
|
27
|
+
/** The `~/.fito/publish-state.json` file path. */
|
|
28
|
+
export function publishStatePath(home: string = os.homedir()): string {
|
|
29
|
+
return path.join(home, ".fito", "publish-state.json");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The registered-but-unpublished draft id for `repositoryUrl` against the current backend, or
|
|
34
|
+
* `null` when there is none (never written, cleared, corrupt file, or a different `apiBaseUrl`).
|
|
35
|
+
*/
|
|
36
|
+
export function readPublishState(
|
|
37
|
+
repositoryUrl: string,
|
|
38
|
+
apiBaseUrl: string,
|
|
39
|
+
home: string = os.homedir(),
|
|
40
|
+
): string | null {
|
|
41
|
+
const entry = readState(home)[repositoryUrl];
|
|
42
|
+
if (!entry || entry.apiBaseUrl !== apiBaseUrl) return null;
|
|
43
|
+
return entry.caseId;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Remember a freshly minted draft id for `repositoryUrl` (overwrites that URL's entry only). */
|
|
47
|
+
export function writePublishState(
|
|
48
|
+
repositoryUrl: string,
|
|
49
|
+
entry: { caseId: string; apiBaseUrl: string },
|
|
50
|
+
home: string = os.homedir(),
|
|
51
|
+
): void {
|
|
52
|
+
const state = readState(home);
|
|
53
|
+
state[repositoryUrl] = { ...entry, registeredAt: new Date().toISOString() };
|
|
54
|
+
writeState(state, home);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Drop `repositoryUrl`'s entry (the publish succeeded); other repos' entries are kept. */
|
|
58
|
+
export function clearPublishState(repositoryUrl: string, home: string = os.homedir()): void {
|
|
59
|
+
const state = readState(home);
|
|
60
|
+
if (!(repositoryUrl in state)) return;
|
|
61
|
+
delete state[repositoryUrl];
|
|
62
|
+
writeState(state, home);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Read + validate the state file; absent or corrupt reads as empty (a write recovers it). */
|
|
66
|
+
function readState(home: string): PublishState {
|
|
67
|
+
let raw: string;
|
|
68
|
+
try {
|
|
69
|
+
raw = fs.readFileSync(publishStatePath(home), "utf8");
|
|
70
|
+
} catch {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
let parsed: unknown;
|
|
74
|
+
try {
|
|
75
|
+
parsed = JSON.parse(raw);
|
|
76
|
+
} catch {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
const result = stateSchema.safeParse(parsed);
|
|
80
|
+
return result.success ? result.data : {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function writeState(state: PublishState, home: string): void {
|
|
84
|
+
const file = publishStatePath(home);
|
|
85
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
86
|
+
fs.writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`);
|
|
87
|
+
}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node publish-version.js <case-dir> --change-description <file> --overview <file>` — the
|
|
3
|
+
* `fito-case-author` version-publish entrypoint (Task 9.8, ADR-009): publish a correction/
|
|
4
|
+
* perfection **version** of an already-published case from an edited authoring checkout
|
|
5
|
+
* (Task 9.7's output). `node publish-version.js <case-dir> --probe` resolves the route only —
|
|
6
|
+
* how `/fito-publish-case` decides among the initial publish, this flow, and the ADR-009
|
|
7
|
+
* deprecation stop (route `deprecated`, printed with the successor guidance). Driven by that
|
|
8
|
+
* orchestrator; `runPublishVersion` is the testable core (injectable executor + client), `main`
|
|
9
|
+
* the thin CLI wrapper.
|
|
10
|
+
*
|
|
11
|
+
* The sequence: structural validation (in-process — the attestation is from the last run over
|
|
12
|
+
* the finished tree, never a saved file) → update-staleness guards (`submission.target_branch`
|
|
13
|
+
* and `solution.yaml`'s branch must name the new version — they start stale by construction in
|
|
14
|
+
* an update) → clean tree + local exemplar branch → case resolution from the checkout's `origin`
|
|
15
|
+
* URL (the registry repo-URL lookup) → status gate → the **strictly-greater SemVer guard** (the
|
|
16
|
+
* push force-cuts the new refs, and only a version above the current chain maximum is guaranteed
|
|
17
|
+
* not to collide with a published frozen ref) → the **frozen-reference-set preflight** against
|
|
18
|
+
* the backend's structured views (a reference-changing correction is a new case — caught before
|
|
19
|
+
* any push) → reconcile the solution branch's `.case/` with the canonical branch's (Task 9a.7
|
|
20
|
+
* parity) → explicit-refspec push of `main` + `vX.Y.Z` branch/tag + `case/solution-vX.Y.Z` →
|
|
21
|
+
* `POST /cases/{id}/versions`.
|
|
22
|
+
*
|
|
23
|
+
* Failure leaves the local checkout intact for fix-and-retry: backend rejections surface their
|
|
24
|
+
* problem detail **verbatim**, nothing is registered until the POST succeeds, and a re-run
|
|
25
|
+
* re-cuts the same unregistered refs safely. No retry state is needed — the case id is known.
|
|
26
|
+
*/
|
|
27
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
28
|
+
import * as os from "node:os";
|
|
29
|
+
import * as path from "node:path";
|
|
30
|
+
import { fileURLToPath } from "node:url";
|
|
31
|
+
import { manifestSchema } from "../../shared/case-validation/case-schema.js";
|
|
32
|
+
import { FitoApiError, createFitoApiClient } from "../../shared/fito-api/client.js";
|
|
33
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.js";
|
|
34
|
+
import { parseGithubUrl } from "../../shared/github-url/parse.js";
|
|
35
|
+
import { gitFetchOriginTagsCommand, gitListLocalBranchCommand, gitPushCaseRefsCommand, gitStatusPorcelainCommand, withoutAuthoringHarnessPaths, } from "./github-publish.js";
|
|
36
|
+
import { buildCaseVersionPayload, readCasePublishFacts } from "./publish-payload.js";
|
|
37
|
+
import { PublishRejectedError, reconcileSolutionBranchCase, validateOrThrow } from "./publish.js";
|
|
38
|
+
import { isStrictlyGreaterSemVer } from "./semver.js";
|
|
39
|
+
import { deprecatedRefusal, gateStatus } from "./status-gate.js";
|
|
40
|
+
/** `git remote get-url origin` — the checkout's origin URL (the authoring-check mechanism, duplicated per ADR-006's single-skill corollary). */
|
|
41
|
+
export function gitOriginUrlCommand() {
|
|
42
|
+
return { command: "git", args: ["remote", "get-url", "origin"] };
|
|
43
|
+
}
|
|
44
|
+
/** Resolve the checkout's `origin` into a registered case via the `listCases` repo-URL lookup. */
|
|
45
|
+
async function resolveOriginCase(client, run) {
|
|
46
|
+
let originUrl;
|
|
47
|
+
try {
|
|
48
|
+
originUrl = (await run(gitOriginUrlCommand())).trim();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// A missing git binary means nothing can work — propagate. A failing `remote get-url`
|
|
52
|
+
// (no origin remote, or not a git repo) is a determinate initial-route signal: every
|
|
53
|
+
// authoring checkout is a direct clone whose origin is the case repo (Task 9.7).
|
|
54
|
+
if (error instanceof Error && /not found on PATH/.test(error.message))
|
|
55
|
+
throw error;
|
|
56
|
+
return {
|
|
57
|
+
repositoryUrl: null,
|
|
58
|
+
caseId: null,
|
|
59
|
+
reason: "the directory has no git origin remote — not an authoring checkout of a published case",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const repo = parseGithubUrl(originUrl);
|
|
63
|
+
if (repo === null) {
|
|
64
|
+
return { repositoryUrl: null, caseId: null, reason: `origin ${originUrl} is not a GitHub repository` };
|
|
65
|
+
}
|
|
66
|
+
// The canonical https form — what the registry stores and its URL filter matches (lesson 46).
|
|
67
|
+
const repositoryUrl = `https://github.com/${repo.owner}/${repo.repo}`;
|
|
68
|
+
const page = await client.listCases({ repositoryUrl });
|
|
69
|
+
if (page.total < 1) {
|
|
70
|
+
return { repositoryUrl, caseId: null, reason: `origin ${repositoryUrl} is not a registered published case` };
|
|
71
|
+
}
|
|
72
|
+
// One URL should map to one case (the published-guard enforces it on the TUI path); more than
|
|
73
|
+
// one means out-of-band registrations — stop rather than guess which case this checkout is.
|
|
74
|
+
if (page.total > 1) {
|
|
75
|
+
throw new Error(`${page.total} registered cases match ${repositoryUrl} — Fito expects one case per repository URL,\n` +
|
|
76
|
+
`so this checkout cannot be resolved to a case automatically. Inspect the registry ` +
|
|
77
|
+
`(GET /cases?repositoryUrl=...) and resolve the duplicate registration before publishing a version.`);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
repositoryUrl,
|
|
81
|
+
caseId: page.items[0].id,
|
|
82
|
+
reason: `origin ${repositoryUrl} is the registered case ${page.items[0].id}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the publish route for a case directory (`--probe`): `update` when its `origin` URL is a
|
|
87
|
+
* registered published case (with the case's identity and currently published version for
|
|
88
|
+
* orientation), `deprecated` when that case is retired — the ADR-009 stop is decided here, not by
|
|
89
|
+
* the prompt (Task 9.9) — and `initial` otherwise. Anonymous — published and deprecated cases are
|
|
90
|
+
* public reads.
|
|
91
|
+
*/
|
|
92
|
+
export async function probePublishRoute(options) {
|
|
93
|
+
const caseDir = path.resolve(options.caseDir);
|
|
94
|
+
const client = options.client ?? createFitoApiClient();
|
|
95
|
+
const exec = options.exec ?? (await import("../../shared/shell-exec/exec.js")).shellExec;
|
|
96
|
+
const run = (command) => exec(command, { cwd: caseDir });
|
|
97
|
+
const origin = await resolveOriginCase(client, run);
|
|
98
|
+
if (origin.caseId === null) {
|
|
99
|
+
return { route: "initial", reason: origin.reason };
|
|
100
|
+
}
|
|
101
|
+
const detail = await client.getCase(origin.caseId);
|
|
102
|
+
return {
|
|
103
|
+
route: detail.status === "DEPRECATED" ? "deprecated" : "update",
|
|
104
|
+
reason: origin.reason,
|
|
105
|
+
caseId: detail.id,
|
|
106
|
+
status: detail.status,
|
|
107
|
+
currentVersion: detail.version,
|
|
108
|
+
currentVersionRef: detail.versionRef,
|
|
109
|
+
title: detail.title,
|
|
110
|
+
repositoryUrl: detail.repositoryUrl,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Publish a new version of an edited authoring checkout: validate → guard → resolve → preflight → push → POST. */
|
|
114
|
+
export async function runPublishVersion(options) {
|
|
115
|
+
const caseDir = path.resolve(options.caseDir);
|
|
116
|
+
const home = options.home ?? os.homedir();
|
|
117
|
+
const env = options.env ?? process.env;
|
|
118
|
+
const client = options.client ?? createFitoApiClient();
|
|
119
|
+
const exec = options.exec ?? (await import("../../shared/shell-exec/exec.js")).shellExec;
|
|
120
|
+
const run = (command) => exec(command, { cwd: caseDir });
|
|
121
|
+
if (!existsSync(path.join(caseDir, ".case"))) {
|
|
122
|
+
throw new Error(`Not a case working directory (no .case/):\n ${caseDir}\nCheck the case out for editing first: /fito-case-edit <case-id>`);
|
|
123
|
+
}
|
|
124
|
+
const overview = readAuthoringFile(options.overviewFile, "description-overview");
|
|
125
|
+
const changeDescription = readAuthoringFile(options.changeDescriptionFile, "change-description");
|
|
126
|
+
// Fresh structural validation over the tree as it stands — the attestation forwarded to the
|
|
127
|
+
// backend is from THIS run (ADR-005: never a saved file).
|
|
128
|
+
const { content, attestation } = validateOrThrow(caseDir);
|
|
129
|
+
const facts = readCasePublishFacts(content);
|
|
130
|
+
// Update-only staleness guards: these fields start stale by construction in an update — every
|
|
131
|
+
// version bump must move them, and nothing else checks them (`target_branch` in particular
|
|
132
|
+
// would fail silently: learners' PRs would target the previous frozen branch).
|
|
133
|
+
const manifest = manifestSchema.parse(content.manifest);
|
|
134
|
+
if (manifest.submission.target_branch !== facts.versionRef) {
|
|
135
|
+
throw new Error(`.case/manifest.yaml is stale for the new version: submission.target_branch is "${manifest.submission.target_branch}" ` +
|
|
136
|
+
`but this publish freezes ${facts.versionRef}.\nA learner's PR targets the frozen version branch — ` +
|
|
137
|
+
`set target_branch: ${facts.versionRef}, commit, and re-run.`);
|
|
138
|
+
}
|
|
139
|
+
const expectedSolutionBranch = `case/solution-${facts.versionRef}`;
|
|
140
|
+
if (facts.solutionBranch !== expectedSolutionBranch) {
|
|
141
|
+
throw new Error(`.case/solution.yaml is stale for the new version: branch is "${facts.solutionBranch}" ` +
|
|
142
|
+
`but this publish freezes ${facts.versionRef}.\nThe backend pings the new exemplar branch — ` +
|
|
143
|
+
`set branch: ${expectedSolutionBranch}, build the exemplar on it, commit, and re-run.`);
|
|
144
|
+
}
|
|
145
|
+
// Build the payload before any git/network write, so a payload problem fails with nothing touched.
|
|
146
|
+
const payload = buildCaseVersionPayload({ content, descriptionOverview: overview, changeDescription, attestation });
|
|
147
|
+
// Local guards, before any network write. An untracked legacy `.pi-subagents/` run-store (F23 —
|
|
148
|
+
// where pi-subagents v0.35.1 wrote it), `output/` (the knowledge pipeline's stage workspace, F30) or
|
|
149
|
+
// `.pi/` (the pi project dir, F31) is filtered out — authoring-harness noise a designed workflow
|
|
150
|
+
// writes into the case dir, never a case artifact, never pushed; every other change still gates. The
|
|
151
|
+
// shipped 0.50.0 writes the run-store to `.pi/subagents` instead, which the `.pi/` member already
|
|
152
|
+
// covers, so the legacy entry stays for authors on an older copy — see `AUTHORING_HARNESS_PATHS`.
|
|
153
|
+
const dirty = withoutAuthoringHarnessPaths(await run(gitStatusPorcelainCommand()));
|
|
154
|
+
if (dirty.length > 0) {
|
|
155
|
+
throw new Error(`The working tree has uncommitted changes — commit (or stash) them first; what is validated must be exactly what is pushed:\n${dirty}`);
|
|
156
|
+
}
|
|
157
|
+
if ((await run(gitListLocalBranchCommand(facts.solutionBranch))).trim().length === 0) {
|
|
158
|
+
throw new Error(`The local solution branch \`${facts.solutionBranch}\` (named by .case/solution.yaml) does not exist.\n` +
|
|
159
|
+
"The version publish pushes it as the new version's exemplar. Rebuild it for this version (start from\n" +
|
|
160
|
+
"the previous version's solution branch and re-apply it onto the updated main), then re-run.");
|
|
161
|
+
}
|
|
162
|
+
// Initial-vs-update routing by registration state — the registry repo-URL lookup on `origin`.
|
|
163
|
+
const origin = await resolveOriginCase(client, run);
|
|
164
|
+
if (origin.caseId === null) {
|
|
165
|
+
throw new Error(`${origin.reason}.\nThis directory is an initial publish, not an update — run /fito-publish-case's ` +
|
|
166
|
+
"initial path (publish.js) instead.");
|
|
167
|
+
}
|
|
168
|
+
const session = await resolveFitoSession(client, home);
|
|
169
|
+
const detail = await client.getCase(origin.caseId, session.tokens.accessToken);
|
|
170
|
+
gateStatus(detail, "publishVersion");
|
|
171
|
+
// The strictly-greater guard, before the push: the current version is the chain's maximum, so a
|
|
172
|
+
// strictly greater new version is guaranteed not to collide with — and force-move — any
|
|
173
|
+
// published frozen ref (the push `+`-forces the new refs for fix-and-retry).
|
|
174
|
+
if (!isStrictlyGreaterSemVer(facts.version, detail.version)) {
|
|
175
|
+
const bumpHint = "Bump manifest.version (with submission.target_branch and solution.yaml's branch), re-validate, commit, and re-run";
|
|
176
|
+
if (facts.version === detail.version) {
|
|
177
|
+
throw new Error(`manifest.version is still ${facts.version} — the currently published version. ${bumpHint}.`);
|
|
178
|
+
}
|
|
179
|
+
throw new Error(`manifest.version ${facts.version} must be strictly greater than the published ${detail.version} ` +
|
|
180
|
+
`(SemVer precedence) — pushing a lower version could force-move an already-published frozen ref. ${bumpHint}.`);
|
|
181
|
+
}
|
|
182
|
+
// The frozen-reference-set preflight (ADR-009): catch the common mismatch locally, before any push.
|
|
183
|
+
await preflightFrozenReferences(client, detail.id, payload);
|
|
184
|
+
// F9 parity: the solution branch's .case/ must equal the canonical branch's before both refs
|
|
185
|
+
// are pushed. Local mutation, so it runs after every guard and before the push.
|
|
186
|
+
const caseReconciled = await reconcileSolutionBranchCase(run, facts.solutionBranch);
|
|
187
|
+
await run(gitPushCaseRefsCommand(detail.repositoryUrl, facts.versionRef, facts.solutionBranch));
|
|
188
|
+
let response;
|
|
189
|
+
try {
|
|
190
|
+
response = await client.publishCaseVersion(session.tokens.accessToken, detail.id, payload);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error instanceof FitoApiError) {
|
|
194
|
+
throw new PublishRejectedError(error.message, error.status, detail.id);
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
// The refs are live and registered — now let the author's own checkout learn that (F58). It runs
|
|
199
|
+
// here, after the POST, rather than after the push: before the POST a failure tells the author to
|
|
200
|
+
// re-run, and a re-run re-cuts the same unregistered refs, so refreshing them would be noise.
|
|
201
|
+
const refreshWarning = await refreshLocalRepoView(run);
|
|
202
|
+
const webOrigin = env.FITO_WEB_ORIGIN ?? "http://localhost:5173";
|
|
203
|
+
return {
|
|
204
|
+
caseId: response.id,
|
|
205
|
+
status: response.status,
|
|
206
|
+
repositoryUrl: detail.repositoryUrl,
|
|
207
|
+
previousVersion: detail.version,
|
|
208
|
+
version: response.version,
|
|
209
|
+
versionRef: response.versionRef,
|
|
210
|
+
caseReconciled,
|
|
211
|
+
title: facts.title,
|
|
212
|
+
webUrl: `${webOrigin}/cases/${response.id}`,
|
|
213
|
+
...(refreshWarning === undefined ? {} : { refreshWarning }),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The best-effort post-publish refresh (Task 12a.8, F58): the push went to an explicit URL, never
|
|
218
|
+
* through a named remote, so git updated nothing locally — `git status` reports a false *ahead*,
|
|
219
|
+
* the new tag is missing, and `origin/vX.Y.Z` does not exist. One fetch clears all of it.
|
|
220
|
+
*
|
|
221
|
+
* Never fatal. The version is already published and registered by the time this runs, so an
|
|
222
|
+
* offline machine, a credential prompt or a slow remote must not turn a successful publish into a
|
|
223
|
+
* failure the author would try to fix by re-running it — the failure becomes the warning the
|
|
224
|
+
* caller prints, exactly as `runOpen` does with its enrollment record.
|
|
225
|
+
*/
|
|
226
|
+
async function refreshLocalRepoView(run) {
|
|
227
|
+
try {
|
|
228
|
+
await run(gitFetchOriginTagsCommand());
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
233
|
+
// The reassurance leads, deliberately: the author is reading a `⚠` immediately after a
|
|
234
|
+
// publish, and the reflex it invites — re-run the publish — is the one thing that must not
|
|
235
|
+
// happen, since the version is already registered.
|
|
236
|
+
return (`The version was published — but Fito couldn't refresh this checkout's view of the case repo (${reason.trimEnd()})\n` +
|
|
237
|
+
` Only this checkout's tags and origin/… refs are stale.\n` +
|
|
238
|
+
` Refresh them yourself when you can: git fetch origin --tags`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** Read an author-approved `.authoring/` text, failing with the flow that drafts it. */
|
|
242
|
+
function readAuthoringFile(file, label) {
|
|
243
|
+
try {
|
|
244
|
+
return readFileSync(file, "utf8");
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
throw new Error(`Cannot read the ${label} file:\n ${file}\n/fito-publish-case drafts it with you into .authoring/${label}.md.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* ADR-009's equality guard, run locally against the backend's structured views: the tree's
|
|
252
|
+
* role-grouped references must equal the stored edges as a set of `(componentId, bloomLevel,
|
|
253
|
+
* role)`. Drift is itemized in the backend's own `componentId (ROLE @ BLOOM)` shape so both
|
|
254
|
+
* rejections read alike; only learning-objective descriptions/weights, prerequisite descriptions
|
|
255
|
+
* (Task 12a.3) and the quiz may change.
|
|
256
|
+
*/
|
|
257
|
+
async function preflightFrozenReferences(client, caseId, payload) {
|
|
258
|
+
const [learningObjectives, prerequisites, rubric] = await Promise.all([
|
|
259
|
+
client.getCaseLearningObjectives(caseId),
|
|
260
|
+
client.getCasePrerequisites(caseId),
|
|
261
|
+
client.getCaseRubric(caseId),
|
|
262
|
+
]);
|
|
263
|
+
const identity = (componentId, role, bloomLevel) => `${componentId} (${role} @ ${bloomLevel})`;
|
|
264
|
+
const stored = new Set([
|
|
265
|
+
...learningObjectives.map((r) => identity(r.componentId, "LEARNING_OBJECTIVE", r.bloomLevel)),
|
|
266
|
+
...prerequisites.map((r) => identity(r.componentId, "PREREQUISITE", r.bloomLevel)),
|
|
267
|
+
...rubric.map((r) => identity(r.componentId, "RUBRIC", r.bloomLevel)),
|
|
268
|
+
]);
|
|
269
|
+
const local = new Set([
|
|
270
|
+
...payload.learningObjectives.map((r) => identity(r.componentId, "LEARNING_OBJECTIVE", r.bloomLevel)),
|
|
271
|
+
...payload.prerequisites.map((r) => identity(r.componentId, "PREREQUISITE", r.bloomLevel)),
|
|
272
|
+
...payload.rubric.map((r) => identity(r.componentId, "RUBRIC", r.bloomLevel)),
|
|
273
|
+
]);
|
|
274
|
+
const added = [...local].filter((entry) => !stored.has(entry)).sort();
|
|
275
|
+
const removed = [...stored].filter((entry) => !local.has(entry)).sort();
|
|
276
|
+
if (added.length === 0 && removed.length === 0)
|
|
277
|
+
return;
|
|
278
|
+
const lines = [...added.map((entry) => ` added: ${entry}`), ...removed.map((entry) => ` removed: ${entry}`)];
|
|
279
|
+
throw new Error(`The knowledge-reference set is frozen across versions, and this tree changes it:\n${lines.join("\n")}\n` +
|
|
280
|
+
`A reference-changing correction is a new case: design it with /fito-case-design and deprecate this one.\n` +
|
|
281
|
+
`If the change is unintended, revert the .case/ references, re-validate, commit, and re-run.`);
|
|
282
|
+
}
|
|
283
|
+
const USAGE = "Usage: node publish-version.js <case-dir> --change-description <file> --overview <file>\n" +
|
|
284
|
+
" node publish-version.js <case-dir> --probe";
|
|
285
|
+
async function main() {
|
|
286
|
+
const args = process.argv.slice(2);
|
|
287
|
+
const positionals = [];
|
|
288
|
+
let changeDescriptionFile;
|
|
289
|
+
let overviewFile;
|
|
290
|
+
let probe = false;
|
|
291
|
+
for (let i = 0; i < args.length; i++) {
|
|
292
|
+
const arg = args[i];
|
|
293
|
+
if (arg === "--change-description")
|
|
294
|
+
changeDescriptionFile = args[++i];
|
|
295
|
+
else if (arg === "--overview")
|
|
296
|
+
overviewFile = args[++i];
|
|
297
|
+
else if (arg === "--probe")
|
|
298
|
+
probe = true;
|
|
299
|
+
else
|
|
300
|
+
positionals.push(arg);
|
|
301
|
+
}
|
|
302
|
+
const caseDir = positionals[0];
|
|
303
|
+
if (!caseDir) {
|
|
304
|
+
console.error(USAGE);
|
|
305
|
+
process.exitCode = 2;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (probe) {
|
|
309
|
+
const result = await probePublishRoute({ caseDir });
|
|
310
|
+
console.log(`route: ${result.route}`);
|
|
311
|
+
console.log(`reason: ${result.reason}`);
|
|
312
|
+
if (result.route !== "initial") {
|
|
313
|
+
console.log(`case: ${result.caseId} (status: ${result.status})`);
|
|
314
|
+
console.log(`currently published: ${result.currentVersion} (${result.currentVersionRef})`);
|
|
315
|
+
console.log(`title: ${result.title ?? "(untitled)"}`);
|
|
316
|
+
}
|
|
317
|
+
if (result.route === "deprecated") {
|
|
318
|
+
console.log("");
|
|
319
|
+
console.log(deprecatedRefusal("publishVersion"));
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!changeDescriptionFile || !overviewFile) {
|
|
324
|
+
console.error(USAGE);
|
|
325
|
+
process.exitCode = 2;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
const result = await runPublishVersion({ caseDir, changeDescriptionFile, overviewFile });
|
|
330
|
+
if (result.caseReconciled) {
|
|
331
|
+
console.log("✓ Reconciled the solution branch's .case/ with main (it had diverged) before the push.");
|
|
332
|
+
}
|
|
333
|
+
console.log(`✓ Pushed main and the new frozen refs: ${result.versionRef} (branch + tag) + case/solution-${result.versionRef}.`);
|
|
334
|
+
console.log(`✓ Published version ${result.version} of "${result.title}" (${result.previousVersion} → ${result.version}).`);
|
|
335
|
+
console.log(`✓ Case ${result.caseId} now serves ${result.versionRef}; prior learners keep their pinned versions.`);
|
|
336
|
+
console.log(`✓ Listed at: ${result.webUrl}`);
|
|
337
|
+
if (result.refreshWarning) {
|
|
338
|
+
console.error(`⚠ ${result.refreshWarning}`);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
console.log(`✓ Refreshed this checkout: ${result.versionRef} and the new origin/… refs are now local.`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
if (error instanceof PublishRejectedError) {
|
|
346
|
+
console.error(`✗ The backend rejected the version publish (HTTP ${error.status}):\n ${error.message}`);
|
|
347
|
+
console.error("\nThe local tree is untouched and nothing was registered — fix the cause and re-run this flow;\n" +
|
|
348
|
+
"a re-run re-cuts the same unregistered refs safely.");
|
|
349
|
+
process.exitCode = 1;
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
353
|
+
process.exitCode = 1;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/** Only auto-invoke the CLI when run directly (`node publish-version.js …`), not when imported (e.g. by tests). */
|
|
357
|
+
const entry = process.argv[1];
|
|
358
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
359
|
+
if (isMainModule) {
|
|
360
|
+
main().catch((error) => {
|
|
361
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
362
|
+
process.exitCode = 1;
|
|
363
|
+
});
|
|
364
|
+
}
|