fito-tui 0.4.0 → 0.5.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/agents/fito-performance-reviewer.md +6 -5
- package/extensions/fito-startup.js +27 -3
- package/extensions/fito-startup.ts +39 -7
- package/package.json +3 -3
- package/prompts/fito-auth-refresh.md +1 -1
- package/prompts/fito-case-edit.md +2 -2
- package/prompts/fito-case-generate.md +1 -1
- package/prompts/fito-case-open.md +6 -5
- package/prompts/fito-create-or-update-competence.md +2 -2
- package/prompts/fito-create-or-update-technology.md +5 -5
- package/prompts/fito-delete-competence.md +2 -2
- package/prompts/fito-evaluate.md +30 -22
- package/prompts/fito-login.md +3 -3
- package/prompts/fito-logout.md +1 -1
- package/prompts/fito-publish-case.md +3 -3
- package/prompts/fito-push-knowledge.md +1 -1
- package/prompts/fito-submit.md +55 -36
- package/skills/fito-auth/SKILL.md +8 -7
- package/skills/fito-auth/browser.js +3 -2
- package/skills/fito-auth/browser.ts +3 -2
- package/skills/fito-auth/login.js +22 -6
- package/skills/fito-auth/login.ts +23 -6
- package/skills/fito-case-author/SKILL.md +4 -4
- package/skills/fito-case-author/checkout.js +22 -5
- package/skills/fito-case-author/checkout.ts +22 -5
- package/skills/fito-case-runner/SKILL.md +24 -7
- package/skills/fito-case-runner/github.js +20 -2
- package/skills/fito-case-runner/github.ts +21 -2
- package/skills/fito-case-runner/open.js +3 -3
- package/skills/fito-case-runner/open.ts +3 -3
- package/skills/fito-case-runner/runner.js +12 -1
- package/skills/fito-case-runner/runner.ts +15 -0
- package/skills/fito-case-runner/submit.js +1 -1
- package/skills/fito-case-runner/submit.ts +1 -1
- package/skills/fito-case-runner/temp-file.js +16 -0
- package/skills/fito-case-runner/temp-file.ts +17 -0
- package/skills/fito-competence-write/SKILL.md +3 -3
- package/skills/fito-competence-write/delete.js +1 -1
- package/skills/fito-competence-write/delete.ts +1 -1
- package/skills/fito-evaluator/SKILL.md +7 -6
- package/skills/fito-evaluator/criterion-exec.js +113 -17
- package/skills/fito-evaluator/criterion-exec.ts +110 -18
- package/skills/fito-evaluator/evaluate-automated.js +7 -3
- package/skills/fito-evaluator/evaluate-automated.ts +7 -3
- package/skills/fito-knowledge-push/SKILL.md +1 -1
- package/skills/fito-knowledge-push/push.js +8 -8
- package/skills/fito-knowledge-push/push.ts +8 -8
- package/skills/fito-source-ingestion/SKILL.md +4 -4
- package/skills/fito-technology-write/SKILL.md +2 -2
- package/skills/fito-technology-write/create.js +2 -2
- package/skills/fito-technology-write/create.ts +2 -2
|
@@ -76,9 +76,20 @@ export function forkCloneUrl(login: string, repo: string): string {
|
|
|
76
76
|
return `https://github.com/${login}/${repo}.git`;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* `git clone -c core.autocrlf=input -c core.longpaths=true <url> <dir>` — clone the fork into the
|
|
81
|
+
* explicit per-case working directory. Git for Windows checks files out with CRLF, which can break a
|
|
82
|
+
* case's shell script in a rubric command, and refuses a path over 260 characters (Phase 17a,
|
|
83
|
+
* finding 7 and N2). `input` checks out LF and stores a CRLF file as LF at commit; `longpaths` lifts
|
|
84
|
+
* the limit and means nothing elsewhere. `git clone -c` stores both keys in the new repository, so
|
|
85
|
+
* every later git command there keeps them. The author's clone carries the same two keys
|
|
86
|
+
* (`fito-case-author`'s `gitCloneMainCommand`).
|
|
87
|
+
*/
|
|
80
88
|
export function gitCloneCommand(cloneUrl: string, targetDir: string): ShellCommand {
|
|
81
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
command: "git",
|
|
91
|
+
args: ["clone", "-c", "core.autocrlf=input", "-c", "core.longpaths=true", cloneUrl, targetDir],
|
|
92
|
+
};
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
/**
|
|
@@ -167,6 +178,14 @@ export function isDivergedPush(message: string): boolean {
|
|
|
167
178
|
return /non-fast-forward|fetch first|! \[rejected\]/i.test(message);
|
|
168
179
|
}
|
|
169
180
|
|
|
181
|
+
/**
|
|
182
|
+
* `git status --porcelain` — the submit guard's view of what is not committed: changed files and
|
|
183
|
+
* new ones, but not what `.gitignore` lists. Every line blocks a submit (Task 17a.2).
|
|
184
|
+
*/
|
|
185
|
+
export function gitStatusPorcelainCommand(): ShellCommand {
|
|
186
|
+
return { command: "git", args: ["status", "--porcelain"] };
|
|
187
|
+
}
|
|
188
|
+
|
|
170
189
|
/** `git push -u origin <studentBranch>` — publish the student branch to the fork. */
|
|
171
190
|
export function gitPushCommand(studentBranch: string): ShellCommand {
|
|
172
191
|
return { command: "git", args: ["push", "-u", "origin", studentBranch] };
|
|
@@ -60,10 +60,10 @@ export async function runOpen(options) {
|
|
|
60
60
|
throw new Error(`Your fork already has a '${error.branch}' branch from a previous attempt on this case.\n` +
|
|
61
61
|
`Choose how to continue, then re-run with that choice:\n` +
|
|
62
62
|
` resume the previous attempt — keeps its commits and its open pull request:\n` +
|
|
63
|
-
` node open.js ${options.caseId} --resume\n` +
|
|
63
|
+
` node "open.js" ${options.caseId} --resume\n` +
|
|
64
64
|
` start over from the published case — deletes '${error.branch}' on your fork, ` +
|
|
65
65
|
`closing its pull request; that attempt's unmerged work is lost:\n` +
|
|
66
|
-
` node open.js ${options.caseId} --start-over`);
|
|
66
|
+
` node "open.js" ${options.caseId} --start-over`);
|
|
67
67
|
}
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
@@ -156,7 +156,7 @@ async function main() {
|
|
|
156
156
|
console.log(`✓ Started over — your fork's previous '${result.branch}' was deleted (its PR closed).`);
|
|
157
157
|
}
|
|
158
158
|
console.log(`✓ Case opened at:\n ${result.workDir}\n on branch '${result.branch}'.`);
|
|
159
|
-
console.log(` Make your changes there, then submit: node submit.js ${caseId}`);
|
|
159
|
+
console.log(` Make your changes there, then submit: node "submit.js" ${caseId}`);
|
|
160
160
|
if (result.deprecationWarning) {
|
|
161
161
|
console.error(`⚠ ${result.deprecationWarning}`);
|
|
162
162
|
}
|
|
@@ -106,10 +106,10 @@ export async function runOpen(options: RunOpenOptions): Promise<RunOpenResult> {
|
|
|
106
106
|
`Your fork already has a '${error.branch}' branch from a previous attempt on this case.\n` +
|
|
107
107
|
`Choose how to continue, then re-run with that choice:\n` +
|
|
108
108
|
` resume the previous attempt — keeps its commits and its open pull request:\n` +
|
|
109
|
-
` node open.js ${options.caseId} --resume\n` +
|
|
109
|
+
` node "open.js" ${options.caseId} --resume\n` +
|
|
110
110
|
` start over from the published case — deletes '${error.branch}' on your fork, ` +
|
|
111
111
|
`closing its pull request; that attempt's unmerged work is lost:\n` +
|
|
112
|
-
` node open.js ${options.caseId} --start-over`,
|
|
112
|
+
` node "open.js" ${options.caseId} --start-over`,
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
115
|
throw error;
|
|
@@ -221,7 +221,7 @@ async function main(): Promise<void> {
|
|
|
221
221
|
console.log(`✓ Started over — your fork's previous '${result.branch}' was deleted (its PR closed).`);
|
|
222
222
|
}
|
|
223
223
|
console.log(`✓ Case opened at:\n ${result.workDir}\n on branch '${result.branch}'.`);
|
|
224
|
-
console.log(` Make your changes there, then submit: node submit.js ${caseId}`);
|
|
224
|
+
console.log(` Make your changes there, then submit: node "submit.js" ${caseId}`);
|
|
225
225
|
if (result.deprecationWarning) {
|
|
226
226
|
console.error(`⚠ ${result.deprecationWarning}`);
|
|
227
227
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
|
-
import { assertGithubPlatform, forkCloneUrl, ghAuthStatusCommand, ghCurrentLoginCommand, ghForkCommand, ghPrCreateCommand, ghPrListCommand, gitAddUpstreamRemoteCommand, gitCheckoutRefCommand, gitCheckoutTrackCommand, gitCloneCommand, gitCreateBranchCommand, gitDeleteRemoteBranchCommand, gitFetchUpstreamRefCommand, gitListRemoteBranchCommand, gitPushCommand, isDivergedPush, parseExistingPrUrl, parseGithubRepo, repoSlug, } from "./github.js";
|
|
2
|
+
import { assertGithubPlatform, forkCloneUrl, ghAuthStatusCommand, ghCurrentLoginCommand, ghForkCommand, ghPrCreateCommand, ghPrListCommand, gitAddUpstreamRemoteCommand, gitCheckoutRefCommand, gitCheckoutTrackCommand, gitCloneCommand, gitCreateBranchCommand, gitDeleteRemoteBranchCommand, gitFetchUpstreamRefCommand, gitListRemoteBranchCommand, gitPushCommand, gitStatusPorcelainCommand, isDivergedPush, parseExistingPrUrl, parseGithubRepo, repoSlug, } from "./github.js";
|
|
3
3
|
import { formatValidationFailure } from "./report.js";
|
|
4
4
|
/** Upfront readiness: fail fast with an actionable message when `gh` is missing or unauthenticated. */
|
|
5
5
|
export async function ensureGhReady(exec, cwd) {
|
|
@@ -93,6 +93,17 @@ export async function submitSolution(options) {
|
|
|
93
93
|
const { pointer, targetDir, exec, readBranches, resolveLinkedGithubLogin, recordSubmission } = options;
|
|
94
94
|
assertGithubPlatform(pointer.gitPlatform);
|
|
95
95
|
const repo = parseGithubRepo(pointer.repositoryUrl);
|
|
96
|
+
// The push carries commits only, so work left uncommitted would be missing from the PR while the
|
|
97
|
+
// evaluation that follows scores the working tree as it stands (Task 17a.2). Every porcelain line
|
|
98
|
+
// blocks: on the learner's default route no tool writes into the checkout, unlike the author's
|
|
99
|
+
// case tree, whose publish gate exempts three such folders.
|
|
100
|
+
const uncommitted = (await exec(gitStatusPorcelainCommand(), { cwd: targetDir })).trimEnd();
|
|
101
|
+
if (uncommitted.length > 0) {
|
|
102
|
+
throw new Error(`Your checkout has changes that are not committed, so this submission would leave them out:\n` +
|
|
103
|
+
`${uncommitted}\n` +
|
|
104
|
+
`Nothing was pushed. Commit them on your working branch — or delete the ones that are not ` +
|
|
105
|
+
`part of your work — then submit again.`);
|
|
106
|
+
}
|
|
96
107
|
await ensureGhReady(exec, targetDir);
|
|
97
108
|
// The local gh account that will own the fork branch + the PR.
|
|
98
109
|
const login = (await exec(ghCurrentLoginCommand(), { cwd: targetDir })).trim();
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
gitFetchUpstreamRefCommand,
|
|
20
20
|
gitListRemoteBranchCommand,
|
|
21
21
|
gitPushCommand,
|
|
22
|
+
gitStatusPorcelainCommand,
|
|
22
23
|
isDivergedPush,
|
|
23
24
|
parseExistingPrUrl,
|
|
24
25
|
parseGithubRepo,
|
|
@@ -216,6 +217,20 @@ export async function submitSolution(options: SubmitSolutionOptions): Promise<Su
|
|
|
216
217
|
assertGithubPlatform(pointer.gitPlatform);
|
|
217
218
|
const repo = parseGithubRepo(pointer.repositoryUrl);
|
|
218
219
|
|
|
220
|
+
// The push carries commits only, so work left uncommitted would be missing from the PR while the
|
|
221
|
+
// evaluation that follows scores the working tree as it stands (Task 17a.2). Every porcelain line
|
|
222
|
+
// blocks: on the learner's default route no tool writes into the checkout, unlike the author's
|
|
223
|
+
// case tree, whose publish gate exempts three such folders.
|
|
224
|
+
const uncommitted = (await exec(gitStatusPorcelainCommand(), { cwd: targetDir })).trimEnd();
|
|
225
|
+
if (uncommitted.length > 0) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`Your checkout has changes that are not committed, so this submission would leave them out:\n` +
|
|
228
|
+
`${uncommitted}\n` +
|
|
229
|
+
`Nothing was pushed. Commit them on your working branch — or delete the ones that are not ` +
|
|
230
|
+
`part of your work — then submit again.`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
219
234
|
await ensureGhReady(exec, targetDir);
|
|
220
235
|
|
|
221
236
|
// The local gh account that will own the fork branch + the PR.
|
|
@@ -24,7 +24,7 @@ export async function runSubmit(options) {
|
|
|
24
24
|
const detail = await fetchCaseDetail(client, options.caseId);
|
|
25
25
|
const targetDir = caseWorkDir(options.caseId, home);
|
|
26
26
|
if (!existsSync(targetDir)) {
|
|
27
|
-
throw new Error(`No open case at:\n ${targetDir}\nRun open first: node open.js ${options.caseId}`);
|
|
27
|
+
throw new Error(`No open case at:\n ${targetDir}\nRun open first: node "open.js" ${options.caseId}`);
|
|
28
28
|
}
|
|
29
29
|
// The version pin comes from the local tree, not the case detail: after a case update the
|
|
30
30
|
// backend serves the *current* version, while the learner solved this checkout's version.
|
|
@@ -41,7 +41,7 @@ export async function runSubmit(options: RunSubmitOptions): Promise<SubmitSoluti
|
|
|
41
41
|
const targetDir = caseWorkDir(options.caseId, home);
|
|
42
42
|
|
|
43
43
|
if (!existsSync(targetDir)) {
|
|
44
|
-
throw new Error(`No open case at:\n ${targetDir}\nRun open first: node open.js ${options.caseId}`);
|
|
44
|
+
throw new Error(`No open case at:\n ${targetDir}\nRun open first: node "open.js" ${options.caseId}`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// The version pin comes from the local tree, not the case detail: after a case update the
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node temp-file.js` — make a new folder under the system temp folder and print the path of a file
|
|
3
|
+
* in it (Task 17a.2). `/fito-submit` and `/fito-evaluate` write a JSON file there, for
|
|
4
|
+
* `submit-evaluation.js`, `score-quiz-mc.js` or `submit-quiz-result.js` to read.
|
|
5
|
+
*
|
|
6
|
+
* It replaces `$(mktemp)`, which on Windows names two different files: Git Bash makes `/tmp/tmp.X`
|
|
7
|
+
* in the user's `Temp` folder, while Node and pi's `write` tool read `/tmp` as `C:\tmp`. The path is
|
|
8
|
+
* printed with `/`, which Git Bash, Node and pi's file tools all accept, so a model copying it into
|
|
9
|
+
* a command or a tool call has no `\` to lose or to escape. The folder stays behind, as a `mktemp`
|
|
10
|
+
* file did.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdtempSync } from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), "fito-"));
|
|
16
|
+
console.log(path.join(dir, "data.json").split(path.sep).join("/"));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `node temp-file.js` — make a new folder under the system temp folder and print the path of a file
|
|
3
|
+
* in it (Task 17a.2). `/fito-submit` and `/fito-evaluate` write a JSON file there, for
|
|
4
|
+
* `submit-evaluation.js`, `score-quiz-mc.js` or `submit-quiz-result.js` to read.
|
|
5
|
+
*
|
|
6
|
+
* It replaces `$(mktemp)`, which on Windows names two different files: Git Bash makes `/tmp/tmp.X`
|
|
7
|
+
* in the user's `Temp` folder, while Node and pi's `write` tool read `/tmp` as `C:\tmp`. The path is
|
|
8
|
+
* printed with `/`, which Git Bash, Node and pi's file tools all accept, so a model copying it into
|
|
9
|
+
* a command or a tool call has no `\` to lose or to escape. The folder stays behind, as a `mktemp`
|
|
10
|
+
* file did.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdtempSync } from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
|
|
16
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), "fito-"));
|
|
17
|
+
console.log(path.join(dir, "data.json").split(path.sep).join("/"));
|
|
@@ -30,7 +30,7 @@ itself.
|
|
|
30
30
|
## Create the competence
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
node <fito-competence-write skill dir>/create.js <payload-file>
|
|
33
|
+
node "<fito-competence-write skill dir>/create.js" "<payload-file>"
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
POSTs the payload to `POST /competences`. The author becomes the competence's owner.
|
|
@@ -60,7 +60,7 @@ seen the id — an edit or a delete addresses the competence by it.
|
|
|
60
60
|
## Edit the name or the description
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
node <fito-competence-write skill dir>/update.js <competence-id> <payload-file> [--name] [--description]
|
|
63
|
+
node "<fito-competence-write skill dir>/update.js" <competence-id> "<payload-file>" [--name] [--description]
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
PATCHes `/competences/{id}`, in place: the competence keeps its id, its elements and its learners'
|
|
@@ -94,7 +94,7 @@ on a no-axis run.
|
|
|
94
94
|
## Delete the competence and everything beneath it
|
|
95
95
|
|
|
96
96
|
```bash
|
|
97
|
-
node <fito-competence-write skill dir>/delete.js <competence-id> [--confirm]
|
|
97
|
+
node "<fito-competence-write skill dir>/delete.js" <competence-id> [--confirm]
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
Without `--confirm` nothing is deleted. The script reads the competence and prints what a delete would
|
|
@@ -74,7 +74,7 @@ export function describeStopped(result) {
|
|
|
74
74
|
describeWhatGoes(result),
|
|
75
75
|
"",
|
|
76
76
|
"Nothing has been deleted. A delete needs the author's explicit confirmation:",
|
|
77
|
-
` node delete.js ${result.competence.id} --confirm`,
|
|
77
|
+
` node "delete.js" ${result.competence.id} --confirm`,
|
|
78
78
|
].join("\n");
|
|
79
79
|
}
|
|
80
80
|
/** The success line: the competence deleted, and how much went with it. */
|
|
@@ -105,7 +105,7 @@ export function describeStopped(result: DeleteResult): string {
|
|
|
105
105
|
describeWhatGoes(result),
|
|
106
106
|
"",
|
|
107
107
|
"Nothing has been deleted. A delete needs the author's explicit confirmation:",
|
|
108
|
-
` node delete.js ${result.competence.id} --confirm`,
|
|
108
|
+
` node "delete.js" ${result.competence.id} --confirm`,
|
|
109
109
|
].join("\n");
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -27,11 +27,12 @@ writes — so it always agrees with where the learner is working.
|
|
|
27
27
|
## Run the evaluation
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
node <fito-evaluator skill dir>/evaluate-automated.js <case-id>
|
|
30
|
+
node "<fito-evaluator skill dir>/evaluate-automated.js" <case-id>
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Loads the checkout's `rubric.yaml` and prints one **evaluation report** the reviewer
|
|
34
|
-
scores,
|
|
34
|
+
scores. Its first line, `Case checkout: <path>`, is the checkout's absolute path. Then
|
|
35
|
+
come up to three parts:
|
|
35
36
|
|
|
36
37
|
- **Automated criteria** — runs each `evaluation_method.type: automated` `command`
|
|
37
38
|
via `sh -c` in the checkout (a non-zero exit is **evidence**, not a failure):
|
|
@@ -53,10 +54,10 @@ This runs the case author's commands on the learner's machine and checkout — t
|
|
|
53
54
|
same trust boundary as the learner working in the repo (Architecture Decision #4).
|
|
54
55
|
It writes nothing to the backend and never reads `.case/solution/`.
|
|
55
56
|
|
|
56
|
-
**Done when** it prints the report. Hand that report **and the checkout path**
|
|
57
|
-
|
|
58
|
-
`subagent` tool) to assign the 0–3 scores: it judges the automated/gate evidence
|
|
59
|
-
the report and reads the learner's artifacts + git diff from the checkout for the
|
|
57
|
+
**Done when** it prints the report. Hand that report **and the checkout path** (its
|
|
58
|
+
first line, exactly as printed) to the `fito-performance-reviewer` **subagent** (via
|
|
59
|
+
the `subagent` tool) to assign the 0–3 scores: it judges the automated/gate evidence
|
|
60
|
+
from the report and reads the learner's artifacts + git diff from the checkout for the
|
|
60
61
|
`ai`/`hybrid` criteria. If the report has no scorable criteria, there is nothing to
|
|
61
62
|
score.
|
|
62
63
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
2
4
|
import { promisify } from "node:util";
|
|
3
5
|
/**
|
|
4
6
|
* The real executor for automated rubric criteria (Task 6.1): runs each criterion's free-form
|
|
@@ -18,7 +20,7 @@ const MAX_BUFFER = 16 * 1024 * 1024;
|
|
|
18
20
|
* Default per-command time budget; a command still running after this is terminated and scored as
|
|
19
21
|
* evidence.
|
|
20
22
|
*
|
|
21
|
-
* **Deliberately generous, because a timeout is scored as a failure** (see the `
|
|
23
|
+
* **Deliberately generous, because a timeout is scored as a failure** (see the `timedOut` branch
|
|
22
24
|
* below) and that score reaches the learner's competence profile through `/fito-submit`. A command
|
|
23
25
|
* that is merely *slow* is indistinguishable here from one that is *hung*, so the budget has to
|
|
24
26
|
* clear the slow case by a wide margin: a first `./gradlew test` on a cold cache downloads
|
|
@@ -34,31 +36,125 @@ const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
|
|
|
34
36
|
const TIMEOUT_EXIT_CODE = 124;
|
|
35
37
|
export const shellExec = async (command, options) => {
|
|
36
38
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
// Fito's own output limit and timer, not `execFile`'s `maxBuffer` and `timeout`: those end the
|
|
40
|
+
// `sh` alone, and the programs it started kept running (Phase 17a, finding 14).
|
|
41
|
+
const run = execFileAsync("sh", ["-c", command], {
|
|
42
|
+
cwd: options.cwd,
|
|
43
|
+
encoding: "utf8",
|
|
44
|
+
maxBuffer: Infinity,
|
|
45
|
+
});
|
|
46
|
+
const stop = () => {
|
|
47
|
+
endProcessTree(run.child);
|
|
48
|
+
// As `execFile`'s own limits do: a program that still holds the output open must not hold the
|
|
49
|
+
// result back.
|
|
50
|
+
run.child.stdout?.destroy();
|
|
51
|
+
run.child.stderr?.destroy();
|
|
52
|
+
};
|
|
53
|
+
let overflow;
|
|
54
|
+
for (const stream of [run.child.stdout, run.child.stderr]) {
|
|
55
|
+
let bytes = 0;
|
|
56
|
+
stream?.on("data", (chunk) => {
|
|
57
|
+
bytes += Buffer.byteLength(chunk);
|
|
58
|
+
if (bytes > MAX_BUFFER && overflow === undefined) {
|
|
59
|
+
overflow = new Error(`\`${command}\` produced more than ${MAX_BUFFER} bytes of output`);
|
|
60
|
+
stop();
|
|
61
|
+
}
|
|
43
62
|
});
|
|
63
|
+
}
|
|
64
|
+
let timedOut = false;
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
timedOut = true;
|
|
67
|
+
stop();
|
|
68
|
+
}, timeoutMs);
|
|
69
|
+
try {
|
|
70
|
+
const { stdout, stderr } = await run;
|
|
71
|
+
// A command can exit 0 right as its output passes the limit.
|
|
72
|
+
if (overflow !== undefined)
|
|
73
|
+
throw overflow;
|
|
44
74
|
return { stdout: String(stdout), stderr: String(stderr), exitCode: 0 };
|
|
45
75
|
}
|
|
46
76
|
catch (error) {
|
|
77
|
+
if (overflow !== undefined)
|
|
78
|
+
throw overflow;
|
|
47
79
|
const e = error;
|
|
80
|
+
if (timedOut) {
|
|
81
|
+
// Terminated by the timeout — report it as evidence so it scores like a failure, not an
|
|
82
|
+
// abort. Checked first: `taskkill` ends the `sh` with exit code 1.
|
|
83
|
+
const note = `[fito] command timed out after ${timeoutMs}ms and was terminated`;
|
|
84
|
+
const stderr = e.stderr ? `${String(e.stderr)}\n${note}` : note;
|
|
85
|
+
return { stdout: String(e.stdout ?? ""), stderr, exitCode: TIMEOUT_EXIT_CODE };
|
|
86
|
+
}
|
|
48
87
|
if (typeof e.code === "number") {
|
|
49
88
|
// The command ran and exited non-zero — capture its output as evidence, don't throw.
|
|
50
89
|
return { stdout: String(e.stdout ?? ""), stderr: String(e.stderr ?? ""), exitCode: e.code };
|
|
51
90
|
}
|
|
52
|
-
if (e.code === "
|
|
53
|
-
|
|
91
|
+
if (e.code === "ENOENT") {
|
|
92
|
+
// No `sh` on `PATH`: a missing `cwd` gives the same error, and `runEvaluate` checks the
|
|
93
|
+
// checkout before any command runs. Windows has no `sh` of its own (Phase 17a, finding 3).
|
|
94
|
+
throw new Error(`Could not run \`${command}\`: Fito scores a rubric command with \`sh\`, and none was found. ` +
|
|
95
|
+
"On Windows, `sh` comes with Git for Windows, in Git Bash: https://git-scm.com/download/win");
|
|
54
96
|
}
|
|
55
|
-
|
|
56
|
-
// Terminated by the timeout — report it as evidence so it scores like a failure, not an abort.
|
|
57
|
-
const note = `[fito] command timed out after ${timeoutMs}ms and was terminated`;
|
|
58
|
-
const stderr = e.stderr ? `${String(e.stderr)}\n${note}` : note;
|
|
59
|
-
return { stdout: String(e.stdout ?? ""), stderr, exitCode: TIMEOUT_EXIT_CODE };
|
|
60
|
-
}
|
|
61
|
-
// Could not run the command at all (e.g. missing sh).
|
|
97
|
+
// Could not run the command at all, for a reason other than a missing `sh`.
|
|
62
98
|
throw new Error(`Failed to run \`${command}\`: ${e.message ?? "unknown error"}`);
|
|
63
99
|
}
|
|
100
|
+
finally {
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
}
|
|
64
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* Ends the `sh` and every program below it. On Windows, `taskkill /T` follows the parent chain — pi
|
|
106
|
+
* runs it the same way, from `System32`, so `PATH` does not matter. On Linux each process of the tree
|
|
107
|
+
* is killed, found in `/proc`.
|
|
108
|
+
*
|
|
109
|
+
* The command stays in the process group of pi's `bash`, which pi kills on Esc, at its `bash` tool's
|
|
110
|
+
* timeout and when it quits; a group of its own would put it out of reach of all three (author's
|
|
111
|
+
* choice, 2026-10-22, measured on Linux). The cost: a program whose parent has already ended belongs
|
|
112
|
+
* to `init` and is not found, and with no `/proc` (macOS) only the `sh` is killed.
|
|
113
|
+
*/
|
|
114
|
+
function endProcessTree(child) {
|
|
115
|
+
if (child.pid === undefined)
|
|
116
|
+
return;
|
|
117
|
+
if (process.platform === "win32") {
|
|
118
|
+
const taskkill = path.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "taskkill.exe");
|
|
119
|
+
spawn(taskkill, ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true }).on("error", () => child.kill());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const pid of processTree(child.pid)) {
|
|
123
|
+
try {
|
|
124
|
+
process.kill(pid, "SIGKILL");
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// It ended on its own in the meantime.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** `root` and the pid of every process below it, from each process's parent in `/proc`; `[root]` with no `/proc`. */
|
|
132
|
+
function processTree(root) {
|
|
133
|
+
let entries;
|
|
134
|
+
try {
|
|
135
|
+
entries = fs.readdirSync("/proc");
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return [root];
|
|
139
|
+
}
|
|
140
|
+
const parentOf = new Map();
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
if (!/^\d+$/.test(entry))
|
|
143
|
+
continue;
|
|
144
|
+
try {
|
|
145
|
+
// `<pid> (<name>) <state> <ppid> …` — a name can hold spaces and `)`, so read after the last `)`.
|
|
146
|
+
const stat = fs.readFileSync(`/proc/${entry}/stat`, "utf8");
|
|
147
|
+
parentOf.set(Number(entry), Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]));
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// The process ended while the table was read.
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const tree = [root];
|
|
154
|
+
for (let i = 0; i < tree.length; i++) {
|
|
155
|
+
for (const [pid, parent] of parentOf)
|
|
156
|
+
if (parent === tree[i])
|
|
157
|
+
tree.push(pid);
|
|
158
|
+
}
|
|
159
|
+
return tree;
|
|
160
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
1
|
+
import { type ChildProcess, execFile, spawn } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
2
4
|
import { promisify } from "node:util";
|
|
3
5
|
|
|
4
6
|
import type { AutomatedExecutor, CommandResult } from "./evaluate.ts";
|
|
@@ -21,7 +23,7 @@ const MAX_BUFFER = 16 * 1024 * 1024;
|
|
|
21
23
|
* Default per-command time budget; a command still running after this is terminated and scored as
|
|
22
24
|
* evidence.
|
|
23
25
|
*
|
|
24
|
-
* **Deliberately generous, because a timeout is scored as a failure** (see the `
|
|
26
|
+
* **Deliberately generous, because a timeout is scored as a failure** (see the `timedOut` branch
|
|
25
27
|
* below) and that score reaches the learner's competence profile through `/fito-submit`. A command
|
|
26
28
|
* that is merely *slow* is indistinguishable here from one that is *hung*, so the budget has to
|
|
27
29
|
* clear the slow case by a wide margin: a first `./gradlew test` on a cold cache downloads
|
|
@@ -38,36 +40,126 @@ const TIMEOUT_EXIT_CODE = 124;
|
|
|
38
40
|
|
|
39
41
|
export const shellExec: AutomatedExecutor = async (command, options): Promise<CommandResult> => {
|
|
40
42
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// Fito's own output limit and timer, not `execFile`'s `maxBuffer` and `timeout`: those end the
|
|
44
|
+
// `sh` alone, and the programs it started kept running (Phase 17a, finding 14).
|
|
45
|
+
const run = execFileAsync("sh", ["-c", command], {
|
|
46
|
+
cwd: options.cwd,
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
maxBuffer: Infinity,
|
|
49
|
+
});
|
|
50
|
+
const stop = (): void => {
|
|
51
|
+
endProcessTree(run.child);
|
|
52
|
+
// As `execFile`'s own limits do: a program that still holds the output open must not hold the
|
|
53
|
+
// result back.
|
|
54
|
+
run.child.stdout?.destroy();
|
|
55
|
+
run.child.stderr?.destroy();
|
|
56
|
+
};
|
|
57
|
+
let overflow: Error | undefined;
|
|
58
|
+
for (const stream of [run.child.stdout, run.child.stderr]) {
|
|
59
|
+
let bytes = 0;
|
|
60
|
+
stream?.on("data", (chunk: string) => {
|
|
61
|
+
bytes += Buffer.byteLength(chunk);
|
|
62
|
+
if (bytes > MAX_BUFFER && overflow === undefined) {
|
|
63
|
+
overflow = new Error(`\`${command}\` produced more than ${MAX_BUFFER} bytes of output`);
|
|
64
|
+
stop();
|
|
65
|
+
}
|
|
47
66
|
});
|
|
67
|
+
}
|
|
68
|
+
let timedOut = false;
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
timedOut = true;
|
|
71
|
+
stop();
|
|
72
|
+
}, timeoutMs);
|
|
73
|
+
try {
|
|
74
|
+
const { stdout, stderr } = await run;
|
|
75
|
+
// A command can exit 0 right as its output passes the limit.
|
|
76
|
+
if (overflow !== undefined) throw overflow;
|
|
48
77
|
return { stdout: String(stdout), stderr: String(stderr), exitCode: 0 };
|
|
49
78
|
} catch (error) {
|
|
79
|
+
if (overflow !== undefined) throw overflow;
|
|
50
80
|
const e = error as {
|
|
51
81
|
code?: number | string;
|
|
52
|
-
killed?: boolean;
|
|
53
82
|
stdout?: string;
|
|
54
83
|
stderr?: string;
|
|
55
84
|
message?: string;
|
|
56
85
|
};
|
|
86
|
+
if (timedOut) {
|
|
87
|
+
// Terminated by the timeout — report it as evidence so it scores like a failure, not an
|
|
88
|
+
// abort. Checked first: `taskkill` ends the `sh` with exit code 1.
|
|
89
|
+
const note = `[fito] command timed out after ${timeoutMs}ms and was terminated`;
|
|
90
|
+
const stderr = e.stderr ? `${String(e.stderr)}\n${note}` : note;
|
|
91
|
+
return { stdout: String(e.stdout ?? ""), stderr, exitCode: TIMEOUT_EXIT_CODE };
|
|
92
|
+
}
|
|
57
93
|
if (typeof e.code === "number") {
|
|
58
94
|
// The command ran and exited non-zero — capture its output as evidence, don't throw.
|
|
59
95
|
return { stdout: String(e.stdout ?? ""), stderr: String(e.stderr ?? ""), exitCode: e.code };
|
|
60
96
|
}
|
|
61
|
-
if (e.code === "
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return { stdout: String(e.stdout ?? ""), stderr, exitCode: TIMEOUT_EXIT_CODE };
|
|
97
|
+
if (e.code === "ENOENT") {
|
|
98
|
+
// No `sh` on `PATH`: a missing `cwd` gives the same error, and `runEvaluate` checks the
|
|
99
|
+
// checkout before any command runs. Windows has no `sh` of its own (Phase 17a, finding 3).
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Could not run \`${command}\`: Fito scores a rubric command with \`sh\`, and none was found. ` +
|
|
102
|
+
"On Windows, `sh` comes with Git for Windows, in Git Bash: https://git-scm.com/download/win",
|
|
103
|
+
);
|
|
69
104
|
}
|
|
70
|
-
// Could not run the command at all
|
|
105
|
+
// Could not run the command at all, for a reason other than a missing `sh`.
|
|
71
106
|
throw new Error(`Failed to run \`${command}\`: ${e.message ?? "unknown error"}`);
|
|
107
|
+
} finally {
|
|
108
|
+
clearTimeout(timer);
|
|
72
109
|
}
|
|
73
110
|
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Ends the `sh` and every program below it. On Windows, `taskkill /T` follows the parent chain — pi
|
|
114
|
+
* runs it the same way, from `System32`, so `PATH` does not matter. On Linux each process of the tree
|
|
115
|
+
* is killed, found in `/proc`.
|
|
116
|
+
*
|
|
117
|
+
* The command stays in the process group of pi's `bash`, which pi kills on Esc, at its `bash` tool's
|
|
118
|
+
* timeout and when it quits; a group of its own would put it out of reach of all three (author's
|
|
119
|
+
* choice, 2026-10-22, measured on Linux). The cost: a program whose parent has already ended belongs
|
|
120
|
+
* to `init` and is not found, and with no `/proc` (macOS) only the `sh` is killed.
|
|
121
|
+
*/
|
|
122
|
+
function endProcessTree(child: ChildProcess): void {
|
|
123
|
+
if (child.pid === undefined) return;
|
|
124
|
+
if (process.platform === "win32") {
|
|
125
|
+
const taskkill = path.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "taskkill.exe");
|
|
126
|
+
spawn(taskkill, ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true }).on(
|
|
127
|
+
"error",
|
|
128
|
+
() => child.kill(),
|
|
129
|
+
);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const pid of processTree(child.pid)) {
|
|
133
|
+
try {
|
|
134
|
+
process.kill(pid, "SIGKILL");
|
|
135
|
+
} catch {
|
|
136
|
+
// It ended on its own in the meantime.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** `root` and the pid of every process below it, from each process's parent in `/proc`; `[root]` with no `/proc`. */
|
|
142
|
+
function processTree(root: number): number[] {
|
|
143
|
+
let entries: string[];
|
|
144
|
+
try {
|
|
145
|
+
entries = fs.readdirSync("/proc");
|
|
146
|
+
} catch {
|
|
147
|
+
return [root];
|
|
148
|
+
}
|
|
149
|
+
const parentOf = new Map<number, number>();
|
|
150
|
+
for (const entry of entries) {
|
|
151
|
+
if (!/^\d+$/.test(entry)) continue;
|
|
152
|
+
try {
|
|
153
|
+
// `<pid> (<name>) <state> <ppid> …` — a name can hold spaces and `)`, so read after the last `)`.
|
|
154
|
+
const stat = fs.readFileSync(`/proc/${entry}/stat`, "utf8");
|
|
155
|
+
parentOf.set(Number(entry), Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]));
|
|
156
|
+
} catch {
|
|
157
|
+
// The process ended while the table was read.
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const tree = [root];
|
|
161
|
+
for (let i = 0; i < tree.length; i++) {
|
|
162
|
+
for (const [pid, parent] of parentOf) if (parent === tree[i]) tree.push(pid);
|
|
163
|
+
}
|
|
164
|
+
return tree;
|
|
165
|
+
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* `node evaluate-automated.js <case-id>` — the `fito-performance-reviewer` automated-criteria
|
|
3
3
|
* entrypoint (Task 6.1). Resolves the learner's per-case checkout (`~/.fito/cases/<case-id>/`, the
|
|
4
4
|
* same location `/fito-case-open` writes), loads its `rubric.yaml`, runs every `automated` criterion's
|
|
5
|
-
* command, and prints the captured-evidence report
|
|
6
|
-
* the report to the reviewer subagent for scoring.
|
|
5
|
+
* command, and prints the captured-evidence report, headed by the checkout's absolute path. The
|
|
6
|
+
* `/fito-evaluate` prompt runs this, then hands the report to the reviewer subagent for scoring.
|
|
7
7
|
*
|
|
8
8
|
* `runEvaluate` is the testable core (deps injectable); `main` is the thin CLI wrapper (argv + real
|
|
9
9
|
* deps + printing). It performs no submission and writes nothing to the backend — evaluation on submit
|
|
@@ -33,7 +33,11 @@ export async function runEvaluate(options) {
|
|
|
33
33
|
// Hybrid gates run deterministically here (inheriting the 5-min timeout); the pass/fail judgment
|
|
34
34
|
// against `passingCondition` and the AI fallback are the reviewer subagent's job (Task 6.2).
|
|
35
35
|
const hybridRuns = await evaluateHybridGates(selectHybridCriteria(rubric), exec, dir, options.onProgress);
|
|
36
|
-
|
|
36
|
+
const report = renderReport(runs, selectSkippedCriteria(rubric), selectAICriteria(rubric), hybridRuns);
|
|
37
|
+
// The reviewer and the prompt's later steps use this path as printed (Task 17a.2): a
|
|
38
|
+
// `~/.fito/cases/<id>/` would be read from `HOME` by Git Bash and from `USERPROFILE` by Node, and
|
|
39
|
+
// with `/` a model copying the path into a tool call has no `\` to escape.
|
|
40
|
+
return `Case checkout: ${dir.split(path.sep).join("/")}\n\n${report}`;
|
|
37
41
|
}
|
|
38
42
|
async function main() {
|
|
39
43
|
const caseId = process.argv[2];
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* `node evaluate-automated.js <case-id>` — the `fito-performance-reviewer` automated-criteria
|
|
3
3
|
* entrypoint (Task 6.1). Resolves the learner's per-case checkout (`~/.fito/cases/<case-id>/`, the
|
|
4
4
|
* same location `/fito-case-open` writes), loads its `rubric.yaml`, runs every `automated` criterion's
|
|
5
|
-
* command, and prints the captured-evidence report
|
|
6
|
-
* the report to the reviewer subagent for scoring.
|
|
5
|
+
* command, and prints the captured-evidence report, headed by the checkout's absolute path. The
|
|
6
|
+
* `/fito-evaluate` prompt runs this, then hands the report to the reviewer subagent for scoring.
|
|
7
7
|
*
|
|
8
8
|
* `runEvaluate` is the testable core (deps injectable); `main` is the thin CLI wrapper (argv + real
|
|
9
9
|
* deps + printing). It performs no submission and writes nothing to the backend — evaluation on submit
|
|
@@ -58,7 +58,11 @@ export async function runEvaluate(options: RunEvaluateOptions): Promise<string>
|
|
|
58
58
|
// Hybrid gates run deterministically here (inheriting the 5-min timeout); the pass/fail judgment
|
|
59
59
|
// against `passingCondition` and the AI fallback are the reviewer subagent's job (Task 6.2).
|
|
60
60
|
const hybridRuns = await evaluateHybridGates(selectHybridCriteria(rubric), exec, dir, options.onProgress);
|
|
61
|
-
|
|
61
|
+
const report = renderReport(runs, selectSkippedCriteria(rubric), selectAICriteria(rubric), hybridRuns);
|
|
62
|
+
// The reviewer and the prompt's later steps use this path as printed (Task 17a.2): a
|
|
63
|
+
// `~/.fito/cases/<id>/` would be read from `HOME` by Git Bash and from `USERPROFILE` by Node, and
|
|
64
|
+
// with `/` a model copying the path into a tool call has no `\` to escape.
|
|
65
|
+
return `Case checkout: ${dir.split(path.sep).join("/")}\n\n${report}`;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
async function main(): Promise<void> {
|