@hassangameryt/freeflow 0.8.0 → 0.9.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/plugins/marketplace.json +2 -2
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +3 -3
- package/.cursor-plugin/plugin.json +1 -1
- package/README.md +96 -149
- package/capabilities/cognitive-routing/SKILL.md +21 -129
- package/capabilities/cognitive-routing/references/coordinator.md +163 -0
- package/capabilities/cognitive-routing/references/worker.md +38 -0
- package/capabilities/compaction/SKILL.md +3 -3
- package/capabilities/compaction/references/summary-format.md +26 -15
- package/capabilities/messaging/SKILL.md +49 -0
- package/capabilities/task-memory/SKILL.md +87 -0
- package/command-surface.json +6 -54
- package/gemini-extension.json +1 -1
- package/hooks/claude/hooks.json +13 -3
- package/hooks/codex/hooks.json +2 -1
- package/hooks/shared/runtime-context.mjs +69 -77
- package/package.json +25 -8
- package/pi-extension/dist/ask-user/ask.js +108 -0
- package/pi-extension/dist/ask-user/form.js +250 -0
- package/pi-extension/dist/ask-user/questions.js +66 -0
- package/pi-extension/dist/ask-user/tool.js +124 -0
- package/pi-extension/dist/cognitive-routing/assembler.js +35 -11
- package/pi-extension/dist/cognitive-routing/bootstrap.js +90 -0
- package/pi-extension/dist/cognitive-routing/config.js +3 -4
- package/pi-extension/dist/cognitive-routing/event-store.js +4 -1
- package/pi-extension/dist/cognitive-routing/gate.js +20 -5
- package/pi-extension/dist/cognitive-routing/handlers.js +15 -13
- package/pi-extension/dist/cognitive-routing/model-control.js +17 -8
- package/pi-extension/dist/cognitive-routing/projection.js +23 -6
- package/pi-extension/dist/cognitive-routing/provenance.js +3 -1
- package/pi-extension/dist/cognitive-routing/render.js +15 -15
- package/pi-extension/dist/cognitive-routing/runtime.js +4 -2
- package/pi-extension/dist/cognitive-routing/schemas.js +4 -4
- package/pi-extension/dist/cognitive-routing/session.js +3 -1
- package/pi-extension/dist/cognitive-routing/sources.js +29 -4
- package/pi-extension/dist/cognitive-routing/state.js +18 -8
- package/pi-extension/dist/cognitive-routing/status.js +4 -3
- package/pi-extension/dist/cognitive-routing/tools.js +29 -15
- package/pi-extension/dist/cognitive-routing/types.js +10 -1
- package/pi-extension/dist/compaction/carry.js +36 -22
- package/pi-extension/dist/compaction/config.js +4 -2
- package/pi-extension/dist/compaction/controller.js +52 -29
- package/pi-extension/dist/compaction/harness.js +19 -3
- package/pi-extension/dist/compaction/results.js +14 -13
- package/pi-extension/dist/compaction/tool.js +6 -6
- package/pi-extension/dist/host/catalog.js +20 -35
- package/pi-extension/dist/host/config-validation.js +233 -0
- package/pi-extension/dist/host/config.js +78 -91
- package/pi-extension/dist/host/inbound.js +142 -0
- package/pi-extension/dist/host/projection-tags.js +1 -1
- package/pi-extension/dist/host/prompts.js +24 -13
- package/pi-extension/dist/host/read-only-session.js +6 -1
- package/pi-extension/dist/host/request-history.js +7 -3
- package/pi-extension/dist/host/rows.js +25 -0
- package/pi-extension/dist/host/runtime-state.js +17 -2
- package/pi-extension/dist/host/section-keeper.js +85 -0
- package/pi-extension/dist/host/settings/freeflow-command.js +846 -93
- package/pi-extension/dist/host/settings/settings-view.js +27 -8
- package/pi-extension/dist/host/status.js +19 -5
- package/pi-extension/dist/index.js +638 -72
- package/pi-extension/dist/messaging/config.js +27 -0
- package/pi-extension/dist/messaging/messaging.js +398 -0
- package/pi-extension/dist/messaging/registry.js +57 -0
- package/pi-extension/dist/messaging/render.js +90 -0
- package/pi-extension/dist/messaging/tools.js +109 -0
- package/pi-extension/dist/messaging/transport.js +101 -0
- package/pi-extension/dist/provider-support/cache/keepalive.js +16 -4
- package/pi-extension/dist/task-memory/config.js +49 -0
- package/pi-extension/dist/task-memory/registry.js +119 -0
- package/pi-extension/dist/task-memory/render.js +107 -0
- package/pi-extension/dist/task-memory/runtime.js +994 -0
- package/pi-extension/dist/task-memory/tool.js +233 -0
- package/pi-extension/dist/tool-execution/apply-patch/tool.js +1 -1
- package/pi-extension/dist/tool-execution/background.js +220 -28
- package/pi-extension/dist/tool-execution/config.js +14 -3
- package/pi-extension/dist/tool-execution/file-tracking.js +24 -4
- package/pi-extension/dist/tool-execution/guidance-notices.js +124 -0
- package/pi-extension/dist/tool-execution/skill-reads.js +143 -0
- package/pi-extension/dist/tool-execution/tools.js +2 -2
- package/runtime/prompts/cognitive-routing.md +4 -4
- package/runtime/prompts/core.md +24 -14
- package/runtime/prompts/interaction-contract.md +7 -4
- package/runtime/prompts/tool-execution.md +3 -16
- package/runtime/prompts/working-method.md +16 -99
- package/skills/deliver-work/SKILL.md +76 -0
- package/skills/deliver-work/references/branch-closeout.md +134 -0
- package/skills/deliver-work/references/commit.md +83 -0
- package/skills/deliver-work/references/launch.md +94 -0
- package/skills/deliver-work/references/release.md +85 -0
- package/skills/deliver-work/scripts/commit-state.mjs +139 -0
- package/skills/deliver-work/scripts/delivery-state.mjs +107 -0
- package/skills/deliver-work/scripts/lib/git-state.mjs +178 -0
- package/skills/deliver-work/scripts/push-route.mjs +122 -0
- package/skills/deliver-work/scripts/release-preflight.mjs +177 -0
- package/skills/discuss-work/SKILL.md +148 -0
- package/skills/{discuss → discuss-work}/references/discussion-continuity.md +10 -27
- package/skills/discuss-work/references/learning-action.md +36 -0
- package/skills/discuss-work/scripts/choices.mjs +101 -0
- package/skills/discuss-work/scripts/lib/choices.mjs +159 -0
- package/skills/evaluate-behavior/SKILL.md +107 -0
- package/skills/evaluate-behavior/references/authoring.md +381 -0
- package/skills/evaluate-behavior/references/coding-tasks.md +145 -0
- package/skills/evaluate-behavior/references/conversations-pipelines-judges.md +177 -0
- package/skills/evaluate-behavior/references/design-and-measurement.md +273 -0
- package/skills/evaluate-behavior/references/running-and-evidence.md +245 -0
- package/skills/evaluate-behavior/scripts/claude-guard.mjs +76 -0
- package/skills/evaluate-behavior/scripts/guard-rules.mjs +309 -0
- package/skills/evaluate-behavior/scripts/lib/agreement.mjs +90 -0
- package/skills/evaluate-behavior/scripts/lib/arms.mjs +55 -0
- package/skills/evaluate-behavior/scripts/lib/budget.mjs +87 -0
- package/skills/evaluate-behavior/scripts/lib/build-source.mjs +287 -0
- package/skills/evaluate-behavior/scripts/lib/clear.mjs +74 -0
- package/skills/evaluate-behavior/scripts/lib/container.mjs +395 -0
- package/skills/evaluate-behavior/scripts/lib/decision.mjs +418 -0
- package/skills/evaluate-behavior/scripts/lib/definitions.mjs +1072 -0
- package/skills/evaluate-behavior/scripts/lib/freeflow.mjs +103 -0
- package/skills/evaluate-behavior/scripts/lib/grade-command.mjs +591 -0
- package/skills/evaluate-behavior/scripts/lib/grade-comparison.mjs +90 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-interaction.mjs +19 -18
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-support.mjs +32 -5
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-workspace.mjs +28 -12
- package/skills/evaluate-behavior/scripts/lib/grade.mjs +101 -0
- package/skills/evaluate-behavior/scripts/lib/hooks.mjs +98 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/confinement.mjs +196 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/constraints.mjs +111 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/index.mjs +48 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/isolation.mjs +74 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/launch.mjs +123 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/model-call.mjs +73 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/recorder.mjs +178 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/session.mjs +494 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/skills.mjs +81 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/index.mjs +31 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/names.mjs +3 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/confinement.mjs +173 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/host.mjs +148 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/index.mjs +70 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/isolation.mjs +81 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/model-call.mjs +79 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/process.mjs +241 -0
- package/skills/{evaluate-skill/scripts/lib → evaluate-behavior/scripts/lib/hosts/pi}/rpc.mjs +144 -26
- package/skills/evaluate-behavior/scripts/lib/identity.mjs +82 -0
- package/skills/evaluate-behavior/scripts/lib/judge.mjs +688 -0
- package/skills/evaluate-behavior/scripts/lib/metrics.mjs +332 -0
- package/skills/evaluate-behavior/scripts/lib/model-call.mjs +17 -0
- package/skills/evaluate-behavior/scripts/lib/participants.mjs +616 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/process.mjs +22 -0
- package/skills/evaluate-behavior/scripts/lib/queue.mjs +54 -0
- package/skills/evaluate-behavior/scripts/lib/reference.mjs +343 -0
- package/skills/evaluate-behavior/scripts/lib/reuse.mjs +277 -0
- package/skills/evaluate-behavior/scripts/lib/review.mjs +933 -0
- package/skills/evaluate-behavior/scripts/lib/runner.mjs +732 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/sandbox.mjs +119 -14
- package/skills/evaluate-behavior/scripts/lib/scan-shell.mjs +457 -0
- package/skills/evaluate-behavior/scripts/lib/scan.mjs +479 -0
- package/skills/evaluate-behavior/scripts/lib/seal.mjs +91 -0
- package/skills/evaluate-behavior/scripts/lib/shell.mjs +560 -0
- package/skills/evaluate-behavior/scripts/lib/source-override.mjs +64 -0
- package/skills/evaluate-behavior/scripts/lib/subject-file.mjs +88 -0
- package/skills/{evaluate-skill/scripts/lib/pi.mjs → evaluate-behavior/scripts/lib/subject.mjs} +235 -265
- package/skills/evaluate-behavior/scripts/lib/task-copy.mjs +124 -0
- package/skills/evaluate-behavior/scripts/lib/trials.mjs +524 -0
- package/skills/evaluate-behavior/scripts/lib/validity.mjs +68 -0
- package/skills/evaluate-behavior/scripts/lib/view-html.mjs +454 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/view.mjs +159 -18
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-command-tool.mjs +21 -6
- package/skills/evaluate-behavior/scripts/pi-container-route.mjs +23 -0
- package/skills/evaluate-behavior/scripts/pi-guard.mjs +77 -0
- package/skills/evaluate-behavior/scripts/pi-login-refresh.mjs +31 -0
- package/skills/evaluate-behavior/scripts/skill-eval.mjs +586 -0
- package/skills/execute-work/SKILL.md +96 -104
- package/skills/execute-work/references/code-practices.md +27 -51
- package/skills/execute-work/references/design.md +271 -0
- package/skills/execute-work/references/diagnose.md +117 -0
- package/skills/execute-work/references/migration.md +108 -0
- package/skills/execute-work/references/simplify.md +65 -0
- package/skills/execute-work/scripts/self-review.mjs +422 -0
- package/skills/execute-work/scripts/touch-map.mjs +290 -0
- package/skills/review-work/SKILL.md +89 -65
- package/skills/review-work/references/adjudication.md +94 -0
- package/skills/review-work/references/artifact.md +198 -0
- package/skills/review-work/references/evals-and-judges.md +66 -0
- package/skills/review-work/references/work.md +177 -0
- package/skills/review-work/scripts/check-brief.mjs +128 -0
- package/skills/review-work/scripts/review-packet.mjs +233 -0
- package/skills/setup-freeflow/SKILL.md +68 -17
- package/skills/track-work/SKILL.md +52 -20
- package/skills/track-work/references/handoff.md +190 -0
- package/skills/track-work/references/projects.md +51 -0
- package/skills/track-work/references/working-record-format.md +36 -18
- package/skills/track-work/scripts/lib/document.mjs +17 -13
- package/skills/track-work/scripts/lib/format.mjs +2 -0
- package/skills/track-work/scripts/lib/recover.mjs +254 -0
- package/skills/track-work/scripts/lib/registry.mjs +656 -0
- package/skills/track-work/scripts/lib/search.mjs +40 -0
- package/skills/track-work/scripts/lib/store.mjs +46 -15
- package/skills/track-work/scripts/lib/views.mjs +50 -1
- package/skills/track-work/scripts/working-record.mjs +232 -13
- package/skills/verify-work/SKILL.md +45 -37
- package/skills/verify-work/references/feature-map.md +120 -0
- package/skills/verify-work/references/runtime-evidence.md +203 -0
- package/skills/verify-work/references/test-design.md +25 -6
- package/skills/verify-work/scripts/test-changes.mjs +246 -0
- package/skills/write-docs/SKILL.md +113 -25
- package/skills/write-docs/references/documentation-shapes.md +68 -3
- package/skills/write-docs/references/spec-and-plan-shapes.md +308 -0
- package/skills/write-docs/scripts/artifact-check.mjs +148 -0
- package/skills/write-docs/scripts/docs-check.mjs +96 -6
- package/skills/write-docs/scripts/plan-lint.mjs +123 -0
- package/skills/write-skill/SKILL.md +92 -52
- package/skills/write-skill/references/activation-and-wording.md +143 -0
- package/skills/write-skill/references/placement-and-dependencies.md +154 -0
- package/skills/write-skill/scripts/lib/compare.mjs +701 -0
- package/skills/write-skill/scripts/lib/skill-author.mjs +197 -3
- package/skills/write-skill/scripts/skill-author.mjs +51 -8
- package/capabilities/cognitive-routing/references/both-mode.md +0 -36
- package/capabilities/cognitive-routing/references/executor-mode.md +0 -48
- package/capabilities/cognitive-routing/references/helper-mode.md +0 -47
- package/plugin.json +0 -33
- package/skills/action-selection/SKILL.md +0 -92
- package/skills/action-selection/references/trajectory-stalls.md +0 -73
- package/skills/bypass/SKILL.md +0 -153
- package/skills/commit-work/SKILL.md +0 -93
- package/skills/commit-work/references/git-state-edges.md +0 -94
- package/skills/commit-work/references/simple-push.md +0 -94
- package/skills/commit-work/references/staging-decisions.md +0 -106
- package/skills/decision-gate/SKILL.md +0 -87
- package/skills/design-for-depth/SKILL.md +0 -108
- package/skills/design-for-depth/references/design-pressure-signals.md +0 -84
- package/skills/design-for-depth/references/implementation-decisions.md +0 -76
- package/skills/design-for-depth/references/interface-design-loop.md +0 -105
- package/skills/design-for-depth/references/module-and-dependency-design.md +0 -117
- package/skills/design-for-depth/references/state-and-failure-boundaries.md +0 -125
- package/skills/diagnose-failure/SKILL.md +0 -140
- package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +0 -50
- package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +0 -51
- package/skills/discuss/SKILL.md +0 -140
- package/skills/evaluate-skill/SKILL.md +0 -188
- package/skills/evaluate-skill/references/evaluation-definition-schema.md +0 -415
- package/skills/evaluate-skill/references/evaluation-design.md +0 -112
- package/skills/evaluate-skill/references/execution-and-evidence.md +0 -111
- package/skills/evaluate-skill/references/review-and-revision.md +0 -94
- package/skills/evaluate-skill/scripts/lib/definitions.mjs +0 -448
- package/skills/evaluate-skill/scripts/lib/grade-comparison.mjs +0 -60
- package/skills/evaluate-skill/scripts/lib/grade.mjs +0 -64
- package/skills/evaluate-skill/scripts/lib/review.mjs +0 -196
- package/skills/evaluate-skill/scripts/lib/runner.mjs +0 -405
- package/skills/evaluate-skill/scripts/lib/trials.mjs +0 -103
- package/skills/evaluate-skill/scripts/pi-guard.mjs +0 -181
- package/skills/evaluate-skill/scripts/skill-eval.mjs +0 -182
- package/skills/execute-work/references/execute-work-edges.md +0 -78
- package/skills/finish-branch/SKILL.md +0 -117
- package/skills/finish-branch/references/integration-options.md +0 -80
- package/skills/handoff/SKILL.md +0 -82
- package/skills/handoff/references/handoff-templates.md +0 -150
- package/skills/launch-work/SKILL.md +0 -116
- package/skills/launch-work/references/launch-readiness.md +0 -85
- package/skills/migration-work/SKILL.md +0 -115
- package/skills/migration-work/references/migration-lifecycle.md +0 -82
- package/skills/release-work/SKILL.md +0 -118
- package/skills/release-work/references/release-evidence.md +0 -78
- package/skills/review-artifact/SKILL.md +0 -143
- package/skills/review-artifact/references/adjudicate-artifact-review.md +0 -101
- package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +0 -159
- package/skills/review-work/references/adjudicate-work-review.md +0 -97
- package/skills/review-work/references/independent-work-reviewer-contract.md +0 -139
- package/skills/review-work/references/security-risk-lens.md +0 -67
- package/skills/setup-freeflow/references/activation-contract.md +0 -103
- package/skills/setup-freeflow/references/host-setup.md +0 -67
- package/skills/simplify-code/SKILL.md +0 -85
- package/skills/simplify-code/references/simplification-patterns.md +0 -70
- package/skills/verify-work/references/browser-runtime-evidence.md +0 -51
- package/skills/verify-work/references/integration-evidence.md +0 -49
- package/skills/verify-work/references/performance-evidence.md +0 -59
- package/skills/workflow/SKILL.md +0 -171
- package/skills/workflow/references/domain-skill-composition.md +0 -45
- package/skills/write-plan/SKILL.md +0 -92
- package/skills/write-plan/references/plan-shapes.md +0 -156
- package/skills/write-skill/references/activation-boundaries.md +0 -106
- package/skills/write-skill/references/agent-first-instructions.md +0 -133
- package/skills/write-skill/references/progressive-disclosure.md +0 -129
- package/skills/write-skill/references/skill-dependency-graphs.md +0 -192
- package/skills/write-spec/SKILL.md +0 -85
- package/skills/write-spec/references/artifact-standards.md +0 -86
- package/skills/write-spec/references/decision-records.md +0 -80
- package/skills/write-spec/references/spec-shapes.md +0 -143
- /package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/evidence.mjs +0 -0
- /package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-observer.mjs +0 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { ARM_NAME, comparisonArms, storedArms } from "./arms.mjs";
|
|
5
|
+
import { renderClaim, trialCounts } from "./decision.mjs";
|
|
6
|
+
import { judgedAggregateLines, judgedLines } from "./judge.mjs";
|
|
7
|
+
import { aggregateMetricsLines, runMetricsLines } from "./metrics.mjs";
|
|
8
|
+
import { participantLines } from "./participants.mjs";
|
|
9
|
+
import { readClearances } from "./scan.mjs";
|
|
10
|
+
|
|
5
11
|
const DEFAULT_SELECTORS = /** @type {{group: string | null, variant: string | null}} */ ({
|
|
6
12
|
group: null,
|
|
7
13
|
variant: null,
|
|
@@ -20,8 +26,12 @@ class ViewError extends Error {
|
|
|
20
26
|
* @param {{root?: string}} [options]
|
|
21
27
|
*/
|
|
22
28
|
|
|
23
|
-
export async function renderResult(
|
|
24
|
-
|
|
29
|
+
export async function renderResult(
|
|
30
|
+
target,
|
|
31
|
+
selectors = DEFAULT_SELECTORS,
|
|
32
|
+
{ root = process.cwd(), results = null } = {},
|
|
33
|
+
) {
|
|
34
|
+
const resultDirectory = await resolveResult(target, root, results);
|
|
25
35
|
const aggregateFile = path.join(resultDirectory, "aggregate.json");
|
|
26
36
|
if (await stat(aggregateFile).catch(() => null)) {
|
|
27
37
|
if (selectors.group !== null || selectors.variant !== null) {
|
|
@@ -42,11 +52,31 @@ export async function renderResult(target, selectors = DEFAULT_SELECTORS, { root
|
|
|
42
52
|
: groups.filter((group) => group.position === position);
|
|
43
53
|
if (groups.length === 0) throw new ViewError(`Unknown group selector: ${selectors.group}`);
|
|
44
54
|
}
|
|
45
|
-
if (selectors.variant !== null && !
|
|
46
|
-
throw new ViewError("variant must be baseline or candidate");
|
|
55
|
+
if (selectors.variant !== null && !ARM_NAME.test(selectors.variant)) {
|
|
56
|
+
throw new ViewError("variant must be an arm name, such as baseline or candidate");
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
const lines = [`Result ${summary.id} [${summary.state}]`, `Path: ${escapeCell(resultDirectory)}`];
|
|
60
|
+
// This invocation's own spend; in a trial, the budget's total is the whole run's so far.
|
|
61
|
+
if (summary.cost) {
|
|
62
|
+
const unmeasured = summary.cost.unmeasured ? [`unmeasured=${summary.cost.unmeasured}`] : [];
|
|
63
|
+
lines.push(
|
|
64
|
+
compactRow("cost", [
|
|
65
|
+
`spent=${formatNumber(summary.cost.spent)}`,
|
|
66
|
+
`subjects=${summary.cost.subjects}`,
|
|
67
|
+
...unmeasured,
|
|
68
|
+
]),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (summary.budget) {
|
|
72
|
+
lines.push(
|
|
73
|
+
compactRow("budget", [
|
|
74
|
+
`max-cost=${formatNumber(summary.budget.maxCost)}`,
|
|
75
|
+
`run-total=${formatNumber(summary.budget.runTotal ?? summary.budget.spent)}`,
|
|
76
|
+
`exhausted=${summary.budget.exhausted}`,
|
|
77
|
+
]),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
50
80
|
for (const group of groups) {
|
|
51
81
|
lines.push("", ...(await renderGroup(resultDirectory, group, selectors.variant)));
|
|
52
82
|
}
|
|
@@ -58,12 +88,18 @@ async function renderGroup(resultDirectory, group, selectedVariant) {
|
|
|
58
88
|
const definition = await readJson(path.join(groupDirectory, "definition.json"), `definition for ${group.id}`);
|
|
59
89
|
const gradeFile = path.join(groupDirectory, group.artifacts?.grade ?? "deterministic-grade.json");
|
|
60
90
|
const grade = await readJson(gradeFile, `grade for ${group.id}`);
|
|
61
|
-
const
|
|
91
|
+
const arms = storedArms(group, definition);
|
|
92
|
+
if (selectedVariant !== null && !arms.includes(selectedVariant)) {
|
|
93
|
+
throw new ViewError(`variant ${selectedVariant} is not an arm of group ${group.id}`);
|
|
94
|
+
}
|
|
95
|
+
const variants = selectedVariant === null ? arms : [selectedVariant];
|
|
62
96
|
const lines = [`Group ${group.id} [${group.state}] type=${definition.type}`];
|
|
63
97
|
|
|
64
98
|
appendSharedEvidence(lines, definition);
|
|
65
99
|
appendGradeEvidence(lines, grade, group, definition, selectedVariant);
|
|
66
|
-
await appendAdvisoryReview(lines, groupDirectory,
|
|
100
|
+
await appendAdvisoryReview(lines, groupDirectory, variants);
|
|
101
|
+
lines.push(...(await judgedLines(groupDirectory, variants)));
|
|
102
|
+
lines.push(...(await participantLines(groupDirectory, variants)));
|
|
67
103
|
for (const variant of variants) {
|
|
68
104
|
await appendVariantEvidence(lines, resultDirectory, groupDirectory, group.id, variant);
|
|
69
105
|
}
|
|
@@ -130,13 +166,26 @@ function appendGradeEvidence(lines, grade, group, definition, selectedVariant) {
|
|
|
130
166
|
if (selectedVariant === null && Array.isArray(grade.comparisons) && grade.comparisons.length > 0) {
|
|
131
167
|
lines.push("Comparisons:");
|
|
132
168
|
for (const comparison of grade.comparisons) {
|
|
169
|
+
if (comparison.arms === undefined) {
|
|
170
|
+
lines.push(
|
|
171
|
+
compactRow("comparison", [
|
|
172
|
+
comparison.id,
|
|
173
|
+
comparison.kind,
|
|
174
|
+
comparison.transition,
|
|
175
|
+
`baseline=${comparison.baseline.check}:${comparison.baseline.state}`,
|
|
176
|
+
`candidate=${comparison.candidate.check}:${comparison.candidate.state}`,
|
|
177
|
+
]),
|
|
178
|
+
);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
// Each non-reference arm's transition from the reference, then every arm's check and state.
|
|
182
|
+
const { arms, transitions } = comparisonArms(comparison);
|
|
133
183
|
lines.push(
|
|
134
184
|
compactRow("comparison", [
|
|
135
185
|
comparison.id,
|
|
136
186
|
comparison.kind,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
`candidate=${comparison.candidate.check}:${comparison.candidate.state}`,
|
|
187
|
+
...Object.entries(transitions).map(([arm, transition]) => `${arm}:${transition}`),
|
|
188
|
+
...Object.entries(arms).map(([arm, outcome]) => `${arm}=${outcome?.check}:${outcome?.state}`),
|
|
140
189
|
]),
|
|
141
190
|
);
|
|
142
191
|
}
|
|
@@ -144,12 +193,11 @@ function appendGradeEvidence(lines, grade, group, definition, selectedVariant) {
|
|
|
144
193
|
}
|
|
145
194
|
|
|
146
195
|
// Advisory answers stay visually separate from deterministic grades; they are not canonical evidence.
|
|
147
|
-
async function appendAdvisoryReview(lines, groupDirectory,
|
|
196
|
+
async function appendAdvisoryReview(lines, groupDirectory, variants) {
|
|
148
197
|
const file = path.join(groupDirectory, "semantic-grade.json");
|
|
149
198
|
if (!(await stat(file).catch(() => null))) return;
|
|
150
199
|
const review = await readJson(file, "advisory review");
|
|
151
200
|
lines.push(`Advisory review [${review.state}] model=${review.model} (not canonical evidence)`);
|
|
152
|
-
const variants = selectedVariant === null ? VARIANTS : [selectedVariant];
|
|
153
201
|
for (const [index, answer] of (review.answers ?? []).entries()) {
|
|
154
202
|
lines.push(
|
|
155
203
|
compactRow("review", [
|
|
@@ -159,12 +207,26 @@ async function appendAdvisoryReview(lines, groupDirectory, selectedVariant) {
|
|
|
159
207
|
]),
|
|
160
208
|
);
|
|
161
209
|
}
|
|
210
|
+
if (review.subject?.familyRelation) lines.push(compactRow("judge", [`family=${review.subject.familyRelation}`]));
|
|
211
|
+
if (review.swap?.agreement) {
|
|
212
|
+
const { agreed, questions } = review.swap.agreement;
|
|
213
|
+
lines.push(compactRow("judge", [`order swap agreed on ${agreed}/${questions}`]));
|
|
214
|
+
const byArm = Object.entries(review.swap.agreement.arms ?? {});
|
|
215
|
+
if (byArm.length > 0) {
|
|
216
|
+
lines.push(
|
|
217
|
+
compactRow("judge", [
|
|
218
|
+
`order swap agreed per arm: ${byArm.map(([arm, counts]) => `${arm}=${counts.agreed}/${counts.questions}`).join(" ")}`,
|
|
219
|
+
]),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const gap of review.contractGaps ?? []) lines.push(compactRow("judge", [`contract gap: ${gap}`]));
|
|
162
224
|
for (const error of review.errors ?? []) lines.push(compactRow("error", ["review", error]));
|
|
163
225
|
}
|
|
164
226
|
|
|
165
227
|
function renderAggregate(resultDirectory, aggregate) {
|
|
166
228
|
const lines = [
|
|
167
|
-
`Aggregate ${aggregate.id} [${aggregate.state}] trials=${aggregate
|
|
229
|
+
`Aggregate ${aggregate.id} [${aggregate.state}] trials=${trialCounts(aggregate)}`,
|
|
168
230
|
`Path: ${escapeCell(resultDirectory)}`,
|
|
169
231
|
];
|
|
170
232
|
if (aggregate.budget) {
|
|
@@ -176,10 +238,36 @@ function renderAggregate(resultDirectory, aggregate) {
|
|
|
176
238
|
]),
|
|
177
239
|
);
|
|
178
240
|
}
|
|
179
|
-
for (const
|
|
241
|
+
for (const entry of aggregate.held ?? []) {
|
|
242
|
+
lines.push(compactRow("held", [entry.trial, entry.group, entry.arm, `flags=${entry.flags.join(",")}`]));
|
|
243
|
+
}
|
|
244
|
+
for (const trial of aggregate.trials) {
|
|
245
|
+
lines.push(
|
|
246
|
+
compactRow("trial", [
|
|
247
|
+
trial.id,
|
|
248
|
+
trial.state,
|
|
249
|
+
...(trial.cost === undefined ? [] : [`cost=${formatNumber(trial.cost)}`]),
|
|
250
|
+
]),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
lines.push(...renderClaim(aggregate));
|
|
180
254
|
for (const group of aggregate.groups) {
|
|
181
|
-
|
|
255
|
+
const unreadable = group.unreadableGrades ? ` unreadable-grades=${group.unreadableGrades}` : "";
|
|
256
|
+
const gradeErrors = group.gradeErrors ? ` grade-errors=${group.gradeErrors}` : "";
|
|
257
|
+
lines.push("", `Group ${group.id} trials=${group.trials}${unreadable}${gradeErrors}`);
|
|
258
|
+
for (const [variant, states] of Object.entries(group.runStates ?? {})) {
|
|
259
|
+
const notComplete = Object.entries(states).filter(([state]) => state !== "complete");
|
|
260
|
+
if (notComplete.length > 0) {
|
|
261
|
+
lines.push(
|
|
262
|
+
compactRow("runs", [variant, ...Object.entries(states).map(([state, count]) => `${state}=${count}`)]),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
182
266
|
for (const comparison of group.comparisons) {
|
|
267
|
+
if (comparison.arms !== undefined) {
|
|
268
|
+
appendArmComparison(lines, comparison);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
183
271
|
lines.push(
|
|
184
272
|
compactRow("comparison", [
|
|
185
273
|
comparison.id,
|
|
@@ -189,14 +277,56 @@ function renderAggregate(resultDirectory, aggregate) {
|
|
|
189
277
|
...Object.entries(comparison.transitions).map(([transition, count]) => `${transition}=${count}`),
|
|
190
278
|
]),
|
|
191
279
|
);
|
|
280
|
+
if (comparison.pairs) {
|
|
281
|
+
const pairs = Object.entries(comparison.pairs).filter(([, count]) => count > 0);
|
|
282
|
+
lines.push(
|
|
283
|
+
compactRow("comparison", [
|
|
284
|
+
comparison.id,
|
|
285
|
+
`pairs: ${pairs.map(([pair, count]) => `${pair}=${count}`).join(" ")}`,
|
|
286
|
+
]),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
192
289
|
}
|
|
193
290
|
for (const check of group.checks) {
|
|
194
|
-
|
|
291
|
+
const counts =
|
|
292
|
+
typeof check.passAll === "boolean"
|
|
293
|
+
? [
|
|
294
|
+
`pass=${passRate(check)}`,
|
|
295
|
+
`fail=${check.fail}`,
|
|
296
|
+
`unavailable=${check.unavailable}`,
|
|
297
|
+
`pass^${check.trials}=${check.passAll ? "yes" : "no"}`,
|
|
298
|
+
]
|
|
299
|
+
: [`pass=${passRate(check)}`];
|
|
300
|
+
lines.push(compactRow("check", [check.id, check.variant, check.kind, ...counts]));
|
|
195
301
|
}
|
|
302
|
+
lines.push(...aggregateMetricsLines(group.metrics));
|
|
303
|
+
lines.push(...judgedAggregateLines(group.judged));
|
|
196
304
|
}
|
|
197
305
|
return `${lines.join("\n")}\n`;
|
|
198
306
|
}
|
|
199
307
|
|
|
308
|
+
/** An arm-keyed aggregate comparison: every arm's pass rate, then each arm's transitions and pairs against the reference. */
|
|
309
|
+
function appendArmComparison(lines, comparison) {
|
|
310
|
+
lines.push(
|
|
311
|
+
compactRow("comparison", [
|
|
312
|
+
comparison.id,
|
|
313
|
+
comparison.kind,
|
|
314
|
+
...Object.entries(comparison.arms).map(([arm, counts]) => `${arm}=${passRate(counts)}`),
|
|
315
|
+
]),
|
|
316
|
+
);
|
|
317
|
+
for (const [arm, versus] of Object.entries(comparison.outcomes ?? {})) {
|
|
318
|
+
const pairs = Object.entries(versus.pairs ?? {}).filter(([, count]) => count > 0);
|
|
319
|
+
lines.push(
|
|
320
|
+
compactRow("comparison", [
|
|
321
|
+
comparison.id,
|
|
322
|
+
`${arm} against ${comparison.reference}`,
|
|
323
|
+
...Object.entries(versus.transitions ?? {}).map(([transition, count]) => `${transition}=${count}`),
|
|
324
|
+
`pairs: ${pairs.map(([pair, count]) => `${pair}=${count}`).join(" ")}`,
|
|
325
|
+
]),
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
200
330
|
function passRate(counts) {
|
|
201
331
|
return `${counts.pass}/${counts.pass + counts.fail + counts.unavailable}`;
|
|
202
332
|
}
|
|
@@ -231,6 +361,12 @@ async function appendVariantEvidence(lines, resultDirectory, groupDirectory, gro
|
|
|
231
361
|
lines.push("", `${title(variant)} [${run.state}]`);
|
|
232
362
|
appendRunEvidence(lines, run);
|
|
233
363
|
const variantDirectory = path.dirname(runFile);
|
|
364
|
+
// Transcript-scan flags, each with whether a person cleared it and why; an uncleared one holds the run.
|
|
365
|
+
const cleared = new Map((await readClearances(variantDirectory)).map((entry) => [entry.flag, entry.reason]));
|
|
366
|
+
for (const flag of run.postRun?.scan?.flags ?? []) {
|
|
367
|
+
const status = cleared.has(flag.id) ? `cleared: ${cleared.get(flag.id)}` : "not cleared";
|
|
368
|
+
lines.push(compactRow(" flag", [flag.id, flag.detail, status]));
|
|
369
|
+
}
|
|
234
370
|
const artifacts = [["run", relativeArtifact(resultDirectory, runFile)]];
|
|
235
371
|
if (typeof run.workspace === "string") {
|
|
236
372
|
artifacts.push(["workspace", relativeArtifact(resultDirectory, run.workspace)]);
|
|
@@ -251,9 +387,13 @@ async function appendVariantEvidence(lines, resultDirectory, groupDirectory, gro
|
|
|
251
387
|
);
|
|
252
388
|
}
|
|
253
389
|
|
|
254
|
-
|
|
390
|
+
/** A result or aggregate directory: an explicit path, or a stored ID under `results` (default `<root>/.skill-eval/runs`). */
|
|
391
|
+
export async function resolveResult(target, root, results = null) {
|
|
255
392
|
const explicit = path.resolve(root, target);
|
|
256
|
-
const stored = path.join(
|
|
393
|
+
const stored = path.join(
|
|
394
|
+
results === null ? path.join(root, ".skill-eval", "runs") : path.resolve(root, results),
|
|
395
|
+
target,
|
|
396
|
+
);
|
|
257
397
|
const isPath = path.isAbsolute(target) || target.includes("/") || target.includes("\\") || target.startsWith(".");
|
|
258
398
|
const candidates = isPath ? [explicit] : [stored, explicit];
|
|
259
399
|
for (const candidate of candidates) {
|
|
@@ -325,6 +465,7 @@ function appendRunEvidence(lines, run) {
|
|
|
325
465
|
if (typeof run.usage.cost?.total === "number") usage.push(`cost=${formatNumber(run.usage.cost.total)}`);
|
|
326
466
|
lines.push(compactRow(" usage", usage));
|
|
327
467
|
}
|
|
468
|
+
lines.push(...runMetricsLines(run));
|
|
328
469
|
if (run.process?.assistantError) lines.push(` assistant-error: ${run.process.assistantError}`);
|
|
329
470
|
if (run.process?.terminationReason) {
|
|
330
471
|
lines.push(` termination: ${run.process.terminationReason}`);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
|
|
3
|
+
import { containerExecArgv, dockerClientEnvironment, parseContainerTarget } from "./lib/container.mjs";
|
|
3
4
|
import { COMMAND_TOOL } from "./lib/definitions.mjs";
|
|
5
|
+
import { LOGIN_VARIABLES } from "./lib/hosts/claude-code/isolation.mjs";
|
|
4
6
|
|
|
5
7
|
const DEFAULT_TIMEOUT_MS = 120 * 1000;
|
|
6
8
|
const OUTPUT_LIMIT_BYTES = 32 * 1024;
|
|
@@ -12,8 +14,16 @@ function parseCommands(value) {
|
|
|
12
14
|
return parsed;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
// A declared command runs the workspace's own code, so it gets neither the evaluator's control variables nor a
|
|
18
|
+
// pointer to the login: Pi's agent directory, which holds the copied provider login, and any login variable. On the
|
|
19
|
+
// host this keeps the login out of easy reach, not out of reach (the run's network "host"); in a container the
|
|
20
|
+
// command gets none of this environment at all.
|
|
21
|
+
const WITHHELD = new Set(["PI_CODING_AGENT_DIR", ...LOGIN_VARIABLES]);
|
|
22
|
+
|
|
15
23
|
function commandEnvironment() {
|
|
16
|
-
return Object.fromEntries(
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
Object.entries(process.env).filter(([key]) => !key.startsWith("SKILL_EVAL_") && !WITHHELD.has(key)),
|
|
26
|
+
);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
function captureStream(stream) {
|
|
@@ -44,13 +54,16 @@ function signalGroup(child, signal) {
|
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
// Runs one author-declared argv in the workspace
|
|
48
|
-
|
|
57
|
+
// Runs one author-declared argv in the workspace, or, in a container environment, through `docker exec` in the
|
|
58
|
+
// subject's container, where bash runs too, so both use the image's toolchain. A nonzero exit or timeout is
|
|
59
|
+
// ordinary evidence, not a tool error.
|
|
60
|
+
function runCommand(command, cwd, signal, container) {
|
|
49
61
|
const timeoutMs = command.timeout_ms ?? DEFAULT_TIMEOUT_MS;
|
|
62
|
+
const argv = container === null ? command.argv : containerExecArgv(container, command.argv);
|
|
50
63
|
return new Promise((resolve, reject) => {
|
|
51
|
-
const child = spawn(
|
|
64
|
+
const child = spawn(argv[0], argv.slice(1), {
|
|
52
65
|
cwd,
|
|
53
|
-
env: commandEnvironment(),
|
|
66
|
+
env: container === null ? commandEnvironment() : dockerClientEnvironment(),
|
|
54
67
|
shell: false,
|
|
55
68
|
detached: process.platform !== "win32",
|
|
56
69
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -94,6 +107,8 @@ export default function registerCommandTool(pi) {
|
|
|
94
107
|
const workspace = process.env.SKILL_EVAL_WRITABLE_ROOT;
|
|
95
108
|
if (!workspace) throw new Error("SKILL_EVAL_WRITABLE_ROOT is required");
|
|
96
109
|
const byId = new Map(commands.map((command) => [command.id, command]));
|
|
110
|
+
// Set by the evaluator only for a container environment; the guard routes bash by the same value.
|
|
111
|
+
const container = parseContainerTarget(process.env.SKILL_EVAL_CONTAINER);
|
|
97
112
|
|
|
98
113
|
pi.registerTool({
|
|
99
114
|
name: COMMAND_TOOL,
|
|
@@ -113,7 +128,7 @@ export default function registerCommandTool(pi) {
|
|
|
113
128
|
async execute(_toolCallId, input, signal) {
|
|
114
129
|
const command = byId.get(input?.command);
|
|
115
130
|
if (!command) throw new Error(`Command is not declared for this evaluation: ${String(input?.command)}`);
|
|
116
|
-
const result = await runCommand(command, workspace, signal);
|
|
131
|
+
const result = await runCommand(command, workspace, signal, container);
|
|
117
132
|
const status = result.timedOut
|
|
118
133
|
? `timed out after ${result.timeoutMs} ms`
|
|
119
134
|
: `exit code: ${result.exitCode ?? `signal ${result.signal}`}`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Pi's last extension in a subject with a container environment: it moves each shell tool's command (bash, and
|
|
2
|
+
// Freeflow's bash_background and monitor) into the subject's container. The guard (pi-guard.mjs, loaded first) has
|
|
3
|
+
// already decided the call; this runs after every other extension's tool_call handler, so those handlers see the
|
|
4
|
+
// command the model wrote, and only then does it become the docker client command Pi's shell runs. Pi runs every
|
|
5
|
+
// handler in load order and stops only on a refusal, so a call that runs has passed through here. The guard refuses
|
|
6
|
+
// container shell calls when this extension is not loaded.
|
|
7
|
+
|
|
8
|
+
import { CONTAINER_ROUTE, decideToolCall, guardState, SHELL_TOOLS } from "./guard-rules.mjs";
|
|
9
|
+
|
|
10
|
+
export default function registerSkillEvalContainerRoute(pi) {
|
|
11
|
+
const state = guardState(process.env);
|
|
12
|
+
globalThis[CONTAINER_ROUTE] = true;
|
|
13
|
+
pi.on("tool_call", (event, ctx) => {
|
|
14
|
+
if (!SHELL_TOOLS.has(event.toolName)) return undefined;
|
|
15
|
+
const decision = decideToolCall(state, event.toolName, event.input, ctx.cwd, process.env);
|
|
16
|
+
if (decision?.block) return decision;
|
|
17
|
+
if (decision?.command === undefined) {
|
|
18
|
+
return { block: true, reason: `${event.toolName} has no container to run in for this evaluation` };
|
|
19
|
+
}
|
|
20
|
+
event.input.command = decision.command;
|
|
21
|
+
return undefined;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTAINER_ROUTE,
|
|
3
|
+
decideToolCall,
|
|
4
|
+
escapeXml,
|
|
5
|
+
guardState,
|
|
6
|
+
loadDeclaredContext,
|
|
7
|
+
renderDeclaredContext,
|
|
8
|
+
} from "./guard-rules.mjs";
|
|
9
|
+
|
|
10
|
+
function buildSubjectSystemPrompt(options, declaredContext) {
|
|
11
|
+
const tools = options.selectedTools ?? [];
|
|
12
|
+
const toolLines = tools.map((tool) => `- ${tool}: ${options.toolSnippets?.[tool] ?? "Declared evaluation tool"}`);
|
|
13
|
+
const lines = [
|
|
14
|
+
"You are an expert coding assistant operating inside pi, a coding agent harness.",
|
|
15
|
+
"Help the user with the task using only the tools and resources listed below.",
|
|
16
|
+
"",
|
|
17
|
+
"Available tools:",
|
|
18
|
+
...(toolLines.length > 0 ? toolLines : ["(none)"]),
|
|
19
|
+
"",
|
|
20
|
+
"Guidelines:",
|
|
21
|
+
"- Use read to load a skill's SKILL.md when the task matches its description.",
|
|
22
|
+
"- Resolve relative skill resources from the skill directory.",
|
|
23
|
+
"- Be concise in your response.",
|
|
24
|
+
];
|
|
25
|
+
const skills = (options.skills ?? []).filter((skill) => !skill.disableModelInvocation);
|
|
26
|
+
if (skills.length > 0) {
|
|
27
|
+
lines.push("", "<available_skills>");
|
|
28
|
+
for (const skill of skills) {
|
|
29
|
+
lines.push(
|
|
30
|
+
" <skill>",
|
|
31
|
+
` <name>${escapeXml(skill.name)}</name>`,
|
|
32
|
+
` <description>${escapeXml(skill.description)}</description>`,
|
|
33
|
+
` <location>${escapeXml(skill.filePath)}</location>`,
|
|
34
|
+
" </skill>",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
lines.push("</available_skills>");
|
|
38
|
+
}
|
|
39
|
+
if (declaredContext.length > 0) lines.push("", renderDeclaredContext(declaredContext));
|
|
40
|
+
lines.push(`Current working directory: ${options.cwd}`);
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// "isolated" replaces the host prompt with an evaluator-owned one; "host" keeps the host's own prompt
|
|
45
|
+
// (and anything declared extensions compose onto it) so evidence reflects the production prompt.
|
|
46
|
+
function beforeAgentStartHandler(promptMode, declaredContext) {
|
|
47
|
+
if (promptMode === "isolated") {
|
|
48
|
+
return (event) => ({ systemPrompt: buildSubjectSystemPrompt(event.systemPromptOptions, declaredContext) });
|
|
49
|
+
}
|
|
50
|
+
return (event) =>
|
|
51
|
+
declaredContext.length === 0
|
|
52
|
+
? undefined
|
|
53
|
+
: { systemPrompt: `${event.systemPrompt}\n\n${renderDeclaredContext(declaredContext)}` };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default function registerSkillEvalGuard(pi) {
|
|
57
|
+
const state = guardState(process.env);
|
|
58
|
+
const declaredContext = loadDeclaredContext(process.env.SKILL_EVAL_CONTEXT_MANIFEST);
|
|
59
|
+
const promptMode = process.env.SKILL_EVAL_PROMPT_MODE || "isolated";
|
|
60
|
+
if (promptMode !== "isolated" && promptMode !== "host") {
|
|
61
|
+
throw new Error(`SKILL_EVAL_PROMPT_MODE must be isolated or host: ${promptMode}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
pi.on("before_agent_start", beforeAgentStartHandler(promptMode, declaredContext));
|
|
65
|
+
|
|
66
|
+
pi.on("tool_call", (event, ctx) => {
|
|
67
|
+
const decision = decideToolCall(state, event.toolName, event.input, ctx.cwd, process.env);
|
|
68
|
+
if (decision?.command === undefined) return decision;
|
|
69
|
+
// A shell tool's command runs in the subject's container. The route extension, loaded after every other one,
|
|
70
|
+
// rewrites it there, so extensions that read the command (Freeflow refuses a trailing `&` in bash) see the one
|
|
71
|
+
// the model wrote. Without the route nothing would move it into the container, so the call is refused.
|
|
72
|
+
if (globalThis[CONTAINER_ROUTE] !== true) {
|
|
73
|
+
return { block: true, reason: "the evaluator's container route is not loaded, so this command cannot run" };
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Asks the installed Pi to make one provider's stored OAuth login valid for at least the given minutes,
|
|
4
|
+
// refreshing it if needed. Pi does the refresh itself, under its own lock on auth.json, exactly as it does in
|
|
5
|
+
// ordinary use. Usage: pi-login-refresh.mjs <auth.json path> <provider> <minutes>
|
|
6
|
+
// Prints the login's new expiry as epoch milliseconds.
|
|
7
|
+
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { realpathSync } from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
|
|
13
|
+
const [authPath, provider, minutes] = process.argv.slice(2);
|
|
14
|
+
if (!authPath || !provider || !/^\d+$/.test(minutes ?? "")) {
|
|
15
|
+
process.stderr.write("usage: pi-login-refresh.mjs <auth.json path> <provider> <minutes>\n");
|
|
16
|
+
process.exit(2);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The installed Pi's package root, found from the `pi` command so the refresh uses the same Pi the runs use.
|
|
20
|
+
const binary = realpathSync(execFileSync("which", ["pi"], { encoding: "utf8" }).trim());
|
|
21
|
+
let packageRoot = path.dirname(binary);
|
|
22
|
+
while (path.basename(packageRoot) !== "pi-coding-agent" && packageRoot !== path.dirname(packageRoot)) {
|
|
23
|
+
packageRoot = path.dirname(packageRoot);
|
|
24
|
+
}
|
|
25
|
+
const { ModelRuntime } = await import(pathToFileURL(path.join(packageRoot, "dist", "index.js")).href);
|
|
26
|
+
const runtime = await ModelRuntime.create({ authPath });
|
|
27
|
+
await runtime.getAuth(provider, { minOAuthValidityMs: Number(minutes) * 60_000 });
|
|
28
|
+
|
|
29
|
+
const { readFileSync } = await import("node:fs");
|
|
30
|
+
const stored = JSON.parse(readFileSync(authPath, "utf8"))[provider];
|
|
31
|
+
process.stdout.write(`${stored?.expires ?? ""}\n`);
|