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,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node checkout.js <case-id> [--dir <target>]` — the `fito-case-author` authoring-checkout
|
|
3
|
+
* entrypoint (Task 9.7, ADR-009 §6): put a published case's source back on the author's disk in
|
|
4
|
+
* **authoring** shape. A **direct clone** of the case repo — the author's own repo, never a fork —
|
|
5
|
+
* so `authoring-check.ts` classifies the tree `authoring` and the knowledge-pipeline `--source .`
|
|
6
|
+
* offer stays available; checked out on **`main`**, the development branch (every case repo has
|
|
7
|
+
* one — the publish flow lands it), not the frozen `vX.Y.Z` ref.
|
|
8
|
+
*
|
|
9
|
+
* Driven by the `/fito-case-edit` orchestrator; `runCheckout` is the testable core (injectable
|
|
10
|
+
* executor + client — the open.ts pattern), `main` the thin CLI wrapper. The Fito session is
|
|
11
|
+
* resolved **best-effort**: no login is needed to check out a published case, but a logged-in
|
|
12
|
+
* owner's `DRAFT` resolves to its "never published" routing instead of a bare 404. A gh↔repo-owner
|
|
13
|
+
* mismatch **warns and proceeds** — the push would fail later anyway, and warning early is the
|
|
14
|
+
* kindness; refusing is not this script's call.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
17
|
+
import * as os from "node:os";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
import type { z } from "zod";
|
|
21
|
+
|
|
22
|
+
import { loadCaseDir } from "../../shared/case-validation/case-loader.ts";
|
|
23
|
+
import { manifestSchema } from "../../shared/case-validation/case-schema.ts";
|
|
24
|
+
import { FitoApiError, createFitoApiClient } from "../../shared/fito-api/client.ts";
|
|
25
|
+
import type { CaseDetail, FitoApiClient } from "../../shared/fito-api/client.ts";
|
|
26
|
+
import { resolveFitoSession } from "../../shared/fito-session/session.ts";
|
|
27
|
+
import { parseGithubHttpsUrl } from "../../shared/github-url/parse.ts";
|
|
28
|
+
import { ghCurrentLoginCommand } from "./github-publish.ts";
|
|
29
|
+
import type { ShellCommand } from "./github-publish.ts";
|
|
30
|
+
import type { Executor } from "./publish.ts";
|
|
31
|
+
import { gateStatus } from "./status-gate.ts";
|
|
32
|
+
|
|
33
|
+
/** The parsed `.case/manifest.yaml` — the checkout's local summary of the tree it just produced. */
|
|
34
|
+
export type CaseManifest = z.infer<typeof manifestSchema>;
|
|
35
|
+
|
|
36
|
+
/** The fito-api surface the checkout flow needs. */
|
|
37
|
+
export type CheckoutClient = Pick<FitoApiClient, "getCase" | "meWithRefresh">;
|
|
38
|
+
|
|
39
|
+
export interface RunCheckoutOptions {
|
|
40
|
+
/** The backend case id (a UUID) — the `<id>` from the case's `/cases/<id>` URL. */
|
|
41
|
+
caseId: string;
|
|
42
|
+
/** `--dir`: the target directory; defaults to `~/.fito/authoring/<case-id>`. */
|
|
43
|
+
dir?: string;
|
|
44
|
+
home?: string;
|
|
45
|
+
client?: CheckoutClient;
|
|
46
|
+
exec?: Executor;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface RunCheckoutResult {
|
|
50
|
+
caseId: string;
|
|
51
|
+
title: string | null;
|
|
52
|
+
/** The currently published SemVer (`GET /cases/{id}`), e.g. `1.1.0`. */
|
|
53
|
+
version: string;
|
|
54
|
+
versionRef: string;
|
|
55
|
+
/** The current version's ADR-009 chain note — null on an initial version. */
|
|
56
|
+
changeDescription: string | null;
|
|
57
|
+
repositoryUrl: string;
|
|
58
|
+
workDir: string;
|
|
59
|
+
/** Always `main` — the development branch, never the frozen ref. */
|
|
60
|
+
branch: string;
|
|
61
|
+
/** The authenticated gh login, when the ownership check could run. */
|
|
62
|
+
ghLogin?: string;
|
|
63
|
+
/** Set when the gh login does not own the case repo (or ownership could not be verified) — warn, never refuse. */
|
|
64
|
+
ownershipWarning?: string;
|
|
65
|
+
/** Set when the cloned `.case/` tree does not read cleanly — the checkout stays usable. */
|
|
66
|
+
structuralWarning?: string;
|
|
67
|
+
/** The cloned tree's parsed manifest, when it reads cleanly. */
|
|
68
|
+
manifest?: CaseManifest;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `git clone --branch main <url> <dir>` — the direct authoring clone. The explicit `--branch main`
|
|
73
|
+
* is the Task 9.7 contract (the publish flow lands every case repo's development branch as `main`);
|
|
74
|
+
* a repo somehow missing it fails loudly here instead of landing on an arbitrary default branch.
|
|
75
|
+
*/
|
|
76
|
+
export function gitCloneMainCommand(repoUrl: string, targetDir: string): ShellCommand {
|
|
77
|
+
return { command: "git", args: ["clone", "--branch", "main", repoUrl, targetDir] };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Fetch case → status gate → guard the target dir → direct clone of main → ownership check → orient. */
|
|
81
|
+
export async function runCheckout(options: RunCheckoutOptions): Promise<RunCheckoutResult> {
|
|
82
|
+
const home = options.home ?? os.homedir();
|
|
83
|
+
const client = options.client ?? createFitoApiClient();
|
|
84
|
+
const exec = options.exec ?? (await import("../../shared/shell-exec/exec.ts")).shellExec;
|
|
85
|
+
|
|
86
|
+
// Best-effort session (the open.ts enrollment pattern): a published checkout needs no login,
|
|
87
|
+
// but with one the backend serves the owner's own DRAFT (getCase's optional bearer, Task 9.7).
|
|
88
|
+
let accessToken: string | undefined;
|
|
89
|
+
try {
|
|
90
|
+
accessToken = (await resolveFitoSession(client, home)).tokens.accessToken;
|
|
91
|
+
} catch {
|
|
92
|
+
accessToken = undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const detail = await fetchDetail(client, options.caseId, accessToken);
|
|
96
|
+
gateStatus(detail, "checkout");
|
|
97
|
+
if (detail.gitPlatform !== "GITHUB") {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`case git platform ${detail.gitPlatform} is not supported — non-GitHub platforms are deferred to post-MVP`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const repo = parseGithubHttpsUrl(detail.repositoryUrl);
|
|
103
|
+
if (repo === null) {
|
|
104
|
+
throw new Error(`the registered repository URL is not an https github.com URL: ${detail.repositoryUrl}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const targetDir = options.dir ? path.resolve(options.dir) : path.join(home, ".fito", "authoring", options.caseId);
|
|
108
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`A directory already exists and is not empty:\n ${targetDir}\n` +
|
|
111
|
+
`If it is your earlier authoring checkout, keep working there. Otherwise move or remove it,\n` +
|
|
112
|
+
`or pass --dir <path> to clone elsewhere — Fito will not overwrite it.`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
mkdirSync(path.dirname(targetDir), { recursive: true });
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await exec(gitCloneMainCommand(detail.repositoryUrl, targetDir), { cwd: path.dirname(targetDir) });
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
121
|
+
// The one clone failure with a Fito-specific story (F15): a repo carrying only frozen refs.
|
|
122
|
+
if (/remote branch main not found/i.test(reason)) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`The case repository has no \`main\` development branch:\n ${detail.repositoryUrl}\n` +
|
|
125
|
+
`Every editable case needs one — the Fito publish flow creates it, so this repo was likely\n` +
|
|
126
|
+
`published outside that flow (frozen version refs only). Push a \`main\` branch to the repo\n` +
|
|
127
|
+
`(e.g. from the \`${detail.versionRef}\` tip), then re-run.`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Ownership is advisory (Task 9.7: warn, do not refuse): editing locally is always fine, and a
|
|
134
|
+
// non-owner push fails on its own later — this just says so before the author invests the work.
|
|
135
|
+
let ghLogin: string | undefined;
|
|
136
|
+
let ownershipWarning: string | undefined;
|
|
137
|
+
try {
|
|
138
|
+
const login = (await exec(ghCurrentLoginCommand(), { cwd: targetDir })).trim();
|
|
139
|
+
// An empty login is "unverifiable", not "a mismatch with nobody" — route it to the catch.
|
|
140
|
+
if (login.length === 0) {
|
|
141
|
+
throw new Error("gh returned an empty login");
|
|
142
|
+
}
|
|
143
|
+
ghLogin = login;
|
|
144
|
+
if (ghLogin.toLowerCase() !== repo.owner.toLowerCase()) {
|
|
145
|
+
// Informational, not an alarm (F10): the owner-string compare cannot see org write
|
|
146
|
+
// access, so an org member/admin publishing for their org is already covered.
|
|
147
|
+
ownershipWarning =
|
|
148
|
+
`Your gh account (\`${ghLogin}\`) is not \`${repo.owner}\`, which owns ${repo.owner}/${repo.repo}.\n` +
|
|
149
|
+
` Editing locally is fine. Publishing needs write access to the case repo — an org\n` +
|
|
150
|
+
` member or admin publishing for their org already has it; otherwise publish with\n` +
|
|
151
|
+
` an account that does.`;
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
155
|
+
ownershipWarning =
|
|
156
|
+
`Could not verify repo ownership (${reason.trimEnd()})\n` +
|
|
157
|
+
` Continuing — the version-publish push will need a gh login with write access to ${repo.owner}/${repo.repo}.`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// The .case/ summary is read from the tree just produced; a tree that doesn't read cleanly is a
|
|
161
|
+
// warning, not a failure — the checkout is on disk and the validator names what to fix.
|
|
162
|
+
let manifest: CaseManifest | undefined;
|
|
163
|
+
let structuralWarning: string | undefined;
|
|
164
|
+
try {
|
|
165
|
+
const loaded = loadCaseDir(targetDir);
|
|
166
|
+
manifest = manifestSchema.parse(loaded.content.manifest);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
169
|
+
structuralWarning =
|
|
170
|
+
`The checked-out .case/ tree does not read cleanly (${reason.trimEnd()})\n` +
|
|
171
|
+
` Run the validator before editing further: node validate.js ${targetDir}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
caseId: options.caseId,
|
|
176
|
+
title: detail.title,
|
|
177
|
+
version: detail.version,
|
|
178
|
+
versionRef: detail.versionRef,
|
|
179
|
+
changeDescription: detail.changeDescription,
|
|
180
|
+
repositoryUrl: detail.repositoryUrl,
|
|
181
|
+
workDir: targetDir,
|
|
182
|
+
branch: "main",
|
|
183
|
+
...(ghLogin === undefined ? {} : { ghLogin }),
|
|
184
|
+
...(ownershipWarning === undefined ? {} : { ownershipWarning }),
|
|
185
|
+
...(structuralWarning === undefined ? {} : { structuralWarning }),
|
|
186
|
+
...(manifest === undefined ? {} : { manifest }),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Fetch the detail, mapping API errors to author-facing messages (the case-detail.ts parity). */
|
|
191
|
+
async function fetchDetail(client: CheckoutClient, caseId: string, accessToken: string | undefined): Promise<CaseDetail> {
|
|
192
|
+
try {
|
|
193
|
+
return await client.getCase(caseId, accessToken);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (error instanceof FitoApiError && error.status === 404) {
|
|
196
|
+
// An unauthenticated read cannot see anyone's draft — say so instead of a dead end.
|
|
197
|
+
const draftHint =
|
|
198
|
+
accessToken === undefined
|
|
199
|
+
? `\n(A draft case is visible only to its logged-in owner — if this is your draft, run /fito-login and re-run.)`
|
|
200
|
+
: "";
|
|
201
|
+
throw new Error(`No case found for id "${caseId}".${draftHint}`);
|
|
202
|
+
}
|
|
203
|
+
if (error instanceof FitoApiError) {
|
|
204
|
+
throw new Error(`Could not fetch case "${caseId}" (${error.status}): ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The orientation brief `main` prints and `/fito-case-edit` relays: the facts, then the ADR-009 update rules. */
|
|
211
|
+
export function renderOrientation(result: RunCheckoutResult): string {
|
|
212
|
+
const manifestLine =
|
|
213
|
+
result.manifest === undefined
|
|
214
|
+
? []
|
|
215
|
+
: [
|
|
216
|
+
` type: ${result.manifest.type} · ~${result.manifest.estimated_duration_minutes} min · ` +
|
|
217
|
+
`${result.manifest.language} · tags: ${result.manifest.tags.join(", ")}`,
|
|
218
|
+
];
|
|
219
|
+
return [
|
|
220
|
+
`Case: ${result.title ?? "(untitled)"} (${result.caseId})`,
|
|
221
|
+
...manifestLine,
|
|
222
|
+
` currently published: ${result.version} (${result.versionRef})`,
|
|
223
|
+
result.changeDescription === null
|
|
224
|
+
? ` last change: — (initial version — no change description yet)`
|
|
225
|
+
: ` last change: ${result.changeDescription}`,
|
|
226
|
+
``,
|
|
227
|
+
`Update rules — the reference set is frozen:`,
|
|
228
|
+
` - A correction that changes the knowledge references is a new case — design it with`,
|
|
229
|
+
` /fito-case-design and deprecate this one.`,
|
|
230
|
+
` - A same-reference perfection is a versioned publish: edit on main, re-validate, publish vX.Y.Z.`,
|
|
231
|
+
` - Published refs (vX.Y.Z and case/solution-vX.Y.Z) are never rewritten.`,
|
|
232
|
+
].join("\n");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const USAGE = "usage: node checkout.js <case-id> [--dir <target>]";
|
|
236
|
+
|
|
237
|
+
/** Parse the checkout CLI args (`argv` minus the node/script prefix): the case id plus an optional target dir. */
|
|
238
|
+
export function parseCheckoutArgs(args: string[]): { caseId: string; dir: string | undefined } {
|
|
239
|
+
const [caseId, ...rest] = args;
|
|
240
|
+
if (!caseId || caseId.startsWith("--")) {
|
|
241
|
+
throw new Error(USAGE);
|
|
242
|
+
}
|
|
243
|
+
if (rest.length === 0) return { caseId, dir: undefined };
|
|
244
|
+
if (rest.length === 2 && rest[0] === "--dir" && !rest[1].startsWith("--")) {
|
|
245
|
+
return { caseId, dir: rest[1] };
|
|
246
|
+
}
|
|
247
|
+
throw new Error(USAGE);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function main(): Promise<void> {
|
|
251
|
+
let parsed: { caseId: string; dir: string | undefined };
|
|
252
|
+
try {
|
|
253
|
+
parsed = parseCheckoutArgs(process.argv.slice(2));
|
|
254
|
+
} catch (error) {
|
|
255
|
+
// Usage errors exit 2, real failures 1 — the publish.ts CLI convention.
|
|
256
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
257
|
+
process.exitCode = 2;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const result = await runCheckout({ caseId: parsed.caseId, dir: parsed.dir });
|
|
261
|
+
console.log(`✓ Cloned ${result.repositoryUrl} (no fork — this is the case repo itself).`);
|
|
262
|
+
console.log(`✓ Authoring checkout at:\n ${result.workDir}\n on branch 'main' — the development branch, not the frozen ref.`);
|
|
263
|
+
console.log("");
|
|
264
|
+
console.log(renderOrientation(result));
|
|
265
|
+
if (result.ownershipWarning) {
|
|
266
|
+
console.error(`⚠ ${result.ownershipWarning}`);
|
|
267
|
+
}
|
|
268
|
+
if (result.structuralWarning) {
|
|
269
|
+
console.error(`⚠ ${result.structuralWarning}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Only auto-invoke the CLI when run directly (`node checkout.js …`), not when imported (e.g. by tests). */
|
|
274
|
+
const entry = process.argv[1];
|
|
275
|
+
const isMainModule = !!entry && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
276
|
+
if (isMainModule) {
|
|
277
|
+
main().catch((error: unknown) => {
|
|
278
|
+
console.error(`✗ ${error instanceof Error ? error.message : String(error)}`);
|
|
279
|
+
process.exitCode = 1;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the publish flow's GitHub / git command surface (Task 9.3). Like the
|
|
3
|
+
* case-runner's `github.ts`, they build **`{command, args}`** values the orchestration spawns
|
|
4
|
+
* through an injectable executor — no shell strings, so nothing is shell-interpolated.
|
|
5
|
+
*
|
|
6
|
+
* Two publish-flow decisions live here: pushes go to an **explicit URL** (never a named remote —
|
|
7
|
+
* a reused project's `origin` is the author's own repo and must not be touched), and the author's
|
|
8
|
+
* current branch lands on the case repo as the canonical **`main`** whatever its local name, so
|
|
9
|
+
* every case repo looks identical to `/fito-case-edit` and the case-runner.
|
|
10
|
+
*/
|
|
11
|
+
/** A GitHub owner or repo segment: word chars, dots and dashes — enough to reject slashes/spaces. */
|
|
12
|
+
const REPO_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
13
|
+
/**
|
|
14
|
+
* Parse the `--repo` argument: `owner/name` (owner may be an org) or a bare `name`, whose owner
|
|
15
|
+
* the default chain fills (`FITO_PUBLISH_GITHUB_OWNER` env, else the authenticated `gh` login).
|
|
16
|
+
*/
|
|
17
|
+
export function parseRepoArg(arg) {
|
|
18
|
+
const parts = arg.split("/");
|
|
19
|
+
if (parts.length > 2 || !parts.every((p) => REPO_SEGMENT.test(p))) {
|
|
20
|
+
throw new Error(`--repo must be <owner>/<name> or a bare <name>, got: "${arg}"`);
|
|
21
|
+
}
|
|
22
|
+
if (parts.length === 2) {
|
|
23
|
+
return { owner: parts[0], name: parts[1] };
|
|
24
|
+
}
|
|
25
|
+
return { owner: undefined, name: parts[0] };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The https URL of the case repo — what `POST /cases` registers and every learner clone uses.
|
|
29
|
+
* Always https (the backend reachability ping rejects ssh remotes, lesson 46), no `.git` suffix.
|
|
30
|
+
*/
|
|
31
|
+
export function caseRepoHttpsUrl(owner, name) {
|
|
32
|
+
return `https://github.com/${owner}/${name}`;
|
|
33
|
+
}
|
|
34
|
+
/** `gh auth status` — the upfront readiness check (gh installed + authenticated). */
|
|
35
|
+
export function ghAuthStatusCommand() {
|
|
36
|
+
return { command: "gh", args: ["auth", "status"] };
|
|
37
|
+
}
|
|
38
|
+
/** `gh api user --jq .login` — the authenticated gh login (default repo owner + the identity warning). */
|
|
39
|
+
export function ghCurrentLoginCommand() {
|
|
40
|
+
return { command: "gh", args: ["api", "user", "--jq", ".login"] };
|
|
41
|
+
}
|
|
42
|
+
/** `gh repo view <slug> --json name` — the existence probe; a re-run must never create a duplicate repo. */
|
|
43
|
+
export function ghRepoViewCommand(slug) {
|
|
44
|
+
return { command: "gh", args: ["repo", "view", slug, "--json", "name"] };
|
|
45
|
+
}
|
|
46
|
+
/** `gh repo create <slug> --public --description <text>` — create the case repo (MVP is public-only), titled for its storefront; no clone, no push. */
|
|
47
|
+
export function ghRepoCreateCommand(slug, description) {
|
|
48
|
+
return { command: "gh", args: ["repo", "create", slug, "--public", "--description", description] };
|
|
49
|
+
}
|
|
50
|
+
/** `git status --porcelain` — the clean-tree guard: what was validated must be exactly what is pushed. */
|
|
51
|
+
export function gitStatusPorcelainCommand() {
|
|
52
|
+
return { command: "git", args: ["status", "--porcelain"] };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The authoring-harness paths a case working tree legitimately carries, each written **into the case
|
|
56
|
+
* dir** by a designed Fito workflow, none of them ever a case artifact, and none of them avoidable on
|
|
57
|
+
* the route the author is defaulted onto. That last criterion read *"impossible to relocate"* until
|
|
58
|
+
* F31: `.pi/` **can** be relocated, so the bar is now the default route rather than impossibility, and
|
|
59
|
+
* the member admitted under the weaker form says so in its own bullet.
|
|
60
|
+
*
|
|
61
|
+
* Membership is the bar: `.gitignore` is rejected for all three (it would ship a Fito-authoring entry
|
|
62
|
+
* into the learner-facing repo) and so is `.git/info/exclude` (per-clone — it breaks on a machine
|
|
63
|
+
* switch or a second author's `/fito-case-edit` re-clone), which leaves this gate as the one place
|
|
64
|
+
* that can know.
|
|
65
|
+
*
|
|
66
|
+
* - **`.pi-subagents/`** — the **legacy** pi-subagents debug run-store (F23). Every
|
|
67
|
+
* `/fito-case-plan-source` run spawns the `fito-case-source-planner` subagent with the case dir as
|
|
68
|
+
* cwd, and pi-subagents wrote its transcripts there with no config knob to relocate it (read from
|
|
69
|
+
* v0.35.1, the pin shipped until 2026-08-15). The shipped **0.50.0** writes to `.pi/subagents`
|
|
70
|
+
* instead, which `AUTHORING_HARNESS_PATHS` already covers via its `.pi/` entry — so both eras stay
|
|
71
|
+
* filtered and this entry is **kept for authors on an older copy**, not left behind.
|
|
72
|
+
*
|
|
73
|
+
* **Open: the "no config knob" half of this bullet is doubtful on 0.50.0** — see PLAN Open
|
|
74
|
+
* Question 12. That release exposes an `artifactDir` preference (`project` / `session` / `temp`,
|
|
75
|
+
* named in upstream's own packaging warning at `src/shared/artifacts.ts:125`), and Fito sets it
|
|
76
|
+
* nowhere, so what puts the run-store in the case dir is no longer established. **This changes
|
|
77
|
+
* nothing here**: the membership question is whether the path lands on the author's default route,
|
|
78
|
+
* which F23 observed directly and 9b.16 already reworded the bar around. Settle the reason before
|
|
79
|
+
* citing it as precedent for admitting a *new* member.
|
|
80
|
+
* - **`output/`** — the knowledge pipeline's stage workspace (F30). Every step writes its stage to
|
|
81
|
+
* `./output/…` relative to **CWD** — `/fito-fetch-urls-content` and `fito-source-ingestion` into
|
|
82
|
+
* `1-ingest/`, `/fito-identify-*` into `2-identify/`, `/fito-generate-*` into `3-generate/`, which
|
|
83
|
+
* is also where `/fito-push-knowledge` reads its payloads from — and `/fito-identify-*` **offers**
|
|
84
|
+
* `--source .` when the CWD holds `.case/manifest.yaml` and the authoring-context check returns
|
|
85
|
+
* *authoring*, so mining a case's own source is an offered workflow, not misuse, and it necessarily
|
|
86
|
+
* lands `output/` in the case tree. Unlike the run-store it could not be relocated even in
|
|
87
|
+
* principle: the stage convention is shared by every step and is the reuse point ADR-012
|
|
88
|
+
* Decision 3 depends on.
|
|
89
|
+
* - **`.pi/`** — the pi project directory (F31). One writer now: `pi install -l <path>` run from
|
|
90
|
+
* **inside the case dir** writes `<caseDir>/.pi/settings.json`. *(Until 2026-09-17 a second
|
|
91
|
+
* writer chained onto it — `fito-startup.ts` walked up for an existing `.pi/`, found the one the
|
|
92
|
+
* install had just made, and synced the worker personas into `<caseDir>/.pi/agents/`. That sync
|
|
93
|
+
* is gone; personas are read from the package itself, so the directory holds settings alone. The
|
|
94
|
+
* path stays on this list because the install still creates it.)* **Not a pre-release artifact:** Fito
|
|
95
|
+
* ships via `npx skills add`, whose default scope is **project** (`-g` is opt-in) and whose pi
|
|
96
|
+
* project dir is `.pi/skills/` — a case checkout is a project dir, so the default install lands it
|
|
97
|
+
* in every author's case tree. **Admitted on weaker ground than its siblings, deliberately:** they
|
|
98
|
+
* cannot be relocated even in principle, whereas this one can (`-g`, or installing from a parent
|
|
99
|
+
* dir). It is tolerated because preventing it means a behavioural instruction fighting the tool's
|
|
100
|
+
* default on every install — the shape Task 9b.13 rejected in favour of a mechanical guard — not
|
|
101
|
+
* because relocation is impossible.
|
|
102
|
+
*
|
|
103
|
+
* Git collapses any of these untracked dirs into a single `?? <path>` porcelain line.
|
|
104
|
+
*/
|
|
105
|
+
const AUTHORING_HARNESS_PATHS = [".pi-subagents/", "output/", ".pi/"];
|
|
106
|
+
/**
|
|
107
|
+
* Filter `git status --porcelain` output down to the changes the clean-tree gate must still refuse,
|
|
108
|
+
* dropping only an **untracked** `AUTHORING_HARNESS_PATHS` member so publish is not blocked on pure
|
|
109
|
+
* authoring-harness noise (F23, F30, F31). A porcelain line is `XY<space>path`; a line is dropped iff its
|
|
110
|
+
* status is `??` (untracked) **and** its path is under one of those paths. A **tracked** member (a
|
|
111
|
+
* stray `git add -A` stages each file with status `A `, not `??`) and every other change are kept, so
|
|
112
|
+
* real dirt still blocks — the asymmetry matters because the publish pushes `HEAD` to `main` *and* to
|
|
113
|
+
* the frozen `vX.Y.Z` branch and tag, whose refs are immutable once published.
|
|
114
|
+
*
|
|
115
|
+
* The match is **start-anchored on a path that ends in `/`**, which makes it precise in both
|
|
116
|
+
* directions: `--porcelain` prints paths relative to the **repository root** even when git runs from
|
|
117
|
+
* a subdirectory (unlike the short format's CWD-relative default), so only the case-root workspace
|
|
118
|
+
* matches — a `src/output/` is some build's and still blocks, as do a neighbouring `output-notes/`
|
|
119
|
+
* and a plain file named `output`. The slash carries the most weight for `.pi/`, whose bare form
|
|
120
|
+
* would prefix-match the whole `.pi*` dotfile space (`.pilot-notes/`, `.pi-cache`); with it, only
|
|
121
|
+
* the pi project dir matches and a nested `src/.pi/` still blocks.
|
|
122
|
+
*
|
|
123
|
+
* Returns the surviving porcelain lines joined by newlines (no trailing newline; empty when nothing
|
|
124
|
+
* gates) — the porcelain status field legitimately leads with a space (` M`), so the result is
|
|
125
|
+
* deliberately not trimmed.
|
|
126
|
+
*/
|
|
127
|
+
export function withoutAuthoringHarnessPaths(porcelain) {
|
|
128
|
+
return porcelain
|
|
129
|
+
.split("\n")
|
|
130
|
+
.filter((line) => {
|
|
131
|
+
if (line.length === 0)
|
|
132
|
+
return false;
|
|
133
|
+
const status = line.slice(0, 2);
|
|
134
|
+
const path = line.slice(3);
|
|
135
|
+
const isUntrackedHarnessPath = status === "??" && AUTHORING_HARNESS_PATHS.some((harnessPath) => path.startsWith(harnessPath));
|
|
136
|
+
return !isUntrackedHarnessPath;
|
|
137
|
+
})
|
|
138
|
+
.join("\n");
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* `git branch --list <branch>` — probe whether the local solution branch exists (empty stdout =
|
|
142
|
+
* missing). Preferred over `rev-parse --verify` because it exits 0 either way, so the throwing
|
|
143
|
+
* executor doesn't conflate "missing branch" with a real git failure.
|
|
144
|
+
*/
|
|
145
|
+
export function gitListLocalBranchCommand(branch) {
|
|
146
|
+
return { command: "git", args: ["branch", "--list", branch] };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `git diff --name-only <solutionBranch> HEAD -- .case` — the `.case/` parity probe (Task 9a.7):
|
|
150
|
+
* non-empty stdout = the solution branch's `.case/` diverged from the canonical branch's (F9 —
|
|
151
|
+
* plan-source finalizes `artifacts.yaml` on `main` after the solution branch was cut). Exits 0
|
|
152
|
+
* either way, so the throwing executor doesn't conflate "divergent" with a real git failure.
|
|
153
|
+
*/
|
|
154
|
+
export function gitCaseParityDiffCommand(solutionBranch) {
|
|
155
|
+
return { command: "git", args: ["diff", "--name-only", solutionBranch, "HEAD", "--", ".case"] };
|
|
156
|
+
}
|
|
157
|
+
/** `git rev-parse --abbrev-ref HEAD` — the author's current branch: the reconcile's restore source and return point. */
|
|
158
|
+
export function gitCurrentBranchCommand() {
|
|
159
|
+
return { command: "git", args: ["rev-parse", "--abbrev-ref", "HEAD"] };
|
|
160
|
+
}
|
|
161
|
+
/** `git checkout <ref>` — switch branches during the reconcile (the case-runner's convention). */
|
|
162
|
+
export function gitCheckoutCommand(ref) {
|
|
163
|
+
return { command: "git", args: ["checkout", ref] };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* `git restore --source <ref> --staged --worktree -- .case` — replace `.case/` wholesale from the
|
|
167
|
+
* canonical branch: unlike `git checkout <ref> -- path`, `git restore` also DELETES tracked paths
|
|
168
|
+
* absent in the source, and the pathspec keeps everything outside `.case/` untouched.
|
|
169
|
+
*/
|
|
170
|
+
export function gitRestoreCaseDirCommand(sourceRef) {
|
|
171
|
+
return { command: "git", args: ["restore", "--source", sourceRef, "--staged", "--worktree", "--", ".case"] };
|
|
172
|
+
}
|
|
173
|
+
/** `git commit -m …` — the reconcile commit (the restore staged its changes, so no `git add`). */
|
|
174
|
+
export function gitCommitCaseParityCommand() {
|
|
175
|
+
return {
|
|
176
|
+
command: "git",
|
|
177
|
+
args: ["commit", "-m", "chore: sync .case/ with main — the case description is branch-invariant"],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The one-shot push of every case ref to the repo URL: the current branch as the canonical
|
|
182
|
+
* `main`, plus the frozen `vX.Y.Z` **branch and tag** (a case repo carries both, which is why
|
|
183
|
+
* every version ref is an explicit refspec — lesson 46) and the `case/solution-vX.Y.Z` exemplar
|
|
184
|
+
* branch. The version refs are `+`-forced so a fix-and-retry can re-cut them: safe pre-publish,
|
|
185
|
+
* and the published-guard stops any post-publish re-run before this command (published refs are
|
|
186
|
+
* immutable — SPEC "Never" boundary).
|
|
187
|
+
*/
|
|
188
|
+
export function gitPushCaseRefsCommand(repoUrl, versionRef, solutionBranch) {
|
|
189
|
+
return {
|
|
190
|
+
command: "git",
|
|
191
|
+
args: [
|
|
192
|
+
"push",
|
|
193
|
+
repoUrl,
|
|
194
|
+
"HEAD:refs/heads/main",
|
|
195
|
+
`+HEAD:refs/heads/${versionRef}`,
|
|
196
|
+
`+HEAD:refs/tags/${versionRef}`,
|
|
197
|
+
`+refs/heads/${solutionBranch}:refs/heads/${solutionBranch}`,
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* `git fetch origin --tags` — the post-publish refresh of the author's **own** bookkeeping (F58).
|
|
203
|
+
* Because the push above goes to an explicit URL and never through a named remote, git updates no
|
|
204
|
+
* remote-tracking ref from it: `git status` reports a false *ahead*, the new tag is absent, and
|
|
205
|
+
* `origin/vX.Y.Z` does not exist locally. A fetch clears all of that **without breaking the rule
|
|
206
|
+
* the push exists to keep** — it reads from the remote and writes only local `refs/remotes/*` and
|
|
207
|
+
* tags, so it neither pushes through `origin` nor edits remote config.
|
|
208
|
+
*
|
|
209
|
+
* `--tags` is **belt-and-braces, not load-bearing** — measured, not assumed (2026-08-27): a bare
|
|
210
|
+
* `git fetch origin` against a real stale checkout brought `v1.2.0` too, because git's default
|
|
211
|
+
* tag auto-following already fetches a tag pointing into the history it fetched, and a case repo's
|
|
212
|
+
* `vX.Y.Z` tag and `main` name the same commit. `--tags` is kept because it also covers a tag that
|
|
213
|
+
* points *outside* that history, and because it is the command the failure warning tells the author
|
|
214
|
+
* to run — the two must not drift apart.
|
|
215
|
+
*/
|
|
216
|
+
export function gitFetchOriginTagsCommand() {
|
|
217
|
+
return { command: "git", args: ["fetch", "origin", "--tags"] };
|
|
218
|
+
}
|