crewhaus 0.1.8 → 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.
Files changed (136) hide show
  1. package/README.md +10 -3
  2. package/dist/advice-apply.d.ts +182 -0
  3. package/dist/advice-apply.js +286 -0
  4. package/dist/advise-rules.d.ts +348 -0
  5. package/dist/advise-rules.js +905 -0
  6. package/dist/alert-sink.d.ts +48 -0
  7. package/dist/alert-sink.js +86 -0
  8. package/dist/approval-gate.d.ts +127 -0
  9. package/dist/approval-gate.js +254 -0
  10. package/dist/audit-verify.d.ts +69 -0
  11. package/dist/audit-verify.js +97 -0
  12. package/dist/autodistill.d.ts +113 -0
  13. package/dist/autodistill.js +256 -0
  14. package/dist/channel-provision.d.ts +360 -0
  15. package/dist/channel-provision.js +881 -0
  16. package/dist/ci-scaffold.d.ts +31 -0
  17. package/dist/ci-scaffold.js +343 -0
  18. package/dist/compile-check.d.ts +90 -0
  19. package/dist/compile-check.js +285 -0
  20. package/dist/compliance-schedule.d.ts +35 -0
  21. package/dist/compliance-schedule.js +36 -0
  22. package/dist/context-pressure.d.ts +80 -0
  23. package/dist/context-pressure.js +166 -0
  24. package/dist/dataset-mine.d.ts +172 -0
  25. package/dist/dataset-mine.js +403 -0
  26. package/dist/datasets.d.ts +124 -0
  27. package/dist/datasets.js +260 -0
  28. package/dist/deploy-canary.d.ts +83 -0
  29. package/dist/deploy-canary.js +87 -0
  30. package/dist/doctor-checks.d.ts +33 -0
  31. package/dist/doctor-checks.js +92 -0
  32. package/dist/doctor-detect.d.ts +108 -0
  33. package/dist/doctor-detect.js +214 -0
  34. package/dist/doctor-fix.d.ts +81 -0
  35. package/dist/doctor-fix.js +164 -0
  36. package/dist/egress-triage.d.ts +121 -0
  37. package/dist/egress-triage.js +261 -0
  38. package/dist/eval-bridge.d.ts +114 -0
  39. package/dist/eval-bridge.js +158 -0
  40. package/dist/eval-coverage.d.ts +140 -0
  41. package/dist/eval-coverage.js +428 -0
  42. package/dist/eval-history.d.ts +48 -0
  43. package/dist/eval-history.js +157 -0
  44. package/dist/eval-matrix.d.ts +80 -0
  45. package/dist/eval-matrix.js +182 -0
  46. package/dist/eval-sentinel.d.ts +65 -0
  47. package/dist/eval-sentinel.js +132 -0
  48. package/dist/faq.d.ts +68 -0
  49. package/dist/faq.js +168 -0
  50. package/dist/feedback.d.ts +9 -2
  51. package/dist/feedback.js +17 -7
  52. package/dist/fewshot.d.ts +83 -0
  53. package/dist/fewshot.js +158 -0
  54. package/dist/fleet.d.ts +207 -0
  55. package/dist/fleet.js +488 -0
  56. package/dist/flywheel.d.ts +193 -0
  57. package/dist/flywheel.js +519 -0
  58. package/dist/graders-suggest.d.ts +186 -0
  59. package/dist/graders-suggest.js +658 -0
  60. package/dist/incident.d.ts +99 -0
  61. package/dist/incident.js +217 -0
  62. package/dist/index.d.ts +9 -1
  63. package/dist/index.js +11601 -964
  64. package/dist/init-interactive.d.ts +105 -0
  65. package/dist/init-interactive.js +208 -0
  66. package/dist/intents.d.ts +105 -0
  67. package/dist/intents.js +292 -0
  68. package/dist/judge-calibrate.d.ts +137 -0
  69. package/dist/judge-calibrate.js +247 -0
  70. package/dist/justification-calibrate.d.ts +150 -0
  71. package/dist/justification-calibrate.js +262 -0
  72. package/dist/justification-gate.d.ts +27 -6
  73. package/dist/justification-gate.js +30 -6
  74. package/dist/knowledge-sync.d.ts +179 -0
  75. package/dist/knowledge-sync.js +551 -0
  76. package/dist/lessons.d.ts +87 -0
  77. package/dist/lessons.js +207 -0
  78. package/dist/lint.d.ts +127 -0
  79. package/dist/lint.js +226 -0
  80. package/dist/loadtest.d.ts +114 -0
  81. package/dist/loadtest.js +196 -0
  82. package/dist/marketplace-cli.d.ts +110 -0
  83. package/dist/marketplace-cli.js +250 -0
  84. package/dist/mcp-doctor.d.ts +121 -0
  85. package/dist/mcp-doctor.js +249 -0
  86. package/dist/model-scan.d.ts +116 -0
  87. package/dist/model-scan.js +226 -0
  88. package/dist/onchain-tune.d.ts +164 -0
  89. package/dist/onchain-tune.js +346 -0
  90. package/dist/permissions-suggest.d.ts +126 -0
  91. package/dist/permissions-suggest.js +333 -0
  92. package/dist/pii-tune.d.ts +107 -0
  93. package/dist/pii-tune.js +122 -0
  94. package/dist/propose.d.ts +117 -0
  95. package/dist/propose.js +184 -0
  96. package/dist/refresh-goldens.d.ts +82 -0
  97. package/dist/refresh-goldens.js +221 -0
  98. package/dist/regression-pin.d.ts +160 -0
  99. package/dist/regression-pin.js +281 -0
  100. package/dist/retention.d.ts +193 -0
  101. package/dist/retention.js +607 -0
  102. package/dist/retire.d.ts +118 -0
  103. package/dist/retire.js +291 -0
  104. package/dist/right-size.d.ts +100 -0
  105. package/dist/right-size.js +123 -0
  106. package/dist/scaffold-evals.d.ts +138 -0
  107. package/dist/scaffold-evals.js +410 -0
  108. package/dist/scope-audit-drift.d.ts +139 -0
  109. package/dist/scope-audit-drift.js +260 -0
  110. package/dist/security-corpus.d.ts +237 -0
  111. package/dist/security-corpus.js +516 -0
  112. package/dist/security-digest.d.ts +173 -0
  113. package/dist/security-digest.js +650 -0
  114. package/dist/sessions-index.d.ts +27 -0
  115. package/dist/sessions-index.js +51 -0
  116. package/dist/slo-doctor.d.ts +67 -0
  117. package/dist/slo-doctor.js +119 -0
  118. package/dist/slo-sink.d.ts +96 -0
  119. package/dist/slo-sink.js +107 -0
  120. package/dist/spec-changelog.d.ts +102 -0
  121. package/dist/spec-changelog.js +237 -0
  122. package/dist/state-backup.d.ts +223 -0
  123. package/dist/state-backup.js +648 -0
  124. package/dist/tools-cli.d.ts +170 -0
  125. package/dist/tools-cli.js +298 -0
  126. package/dist/triage.d.ts +202 -0
  127. package/dist/triage.js +403 -0
  128. package/dist/upgrade.d.ts +57 -0
  129. package/dist/upgrade.js +113 -0
  130. package/dist/version.d.ts +6 -0
  131. package/dist/version.js +27 -0
  132. package/dist/voice-eval.d.ts +138 -0
  133. package/dist/voice-eval.js +309 -0
  134. package/dist/watch.d.ts +58 -0
  135. package/dist/watch.js +97 -0
  136. package/package.json +89 -65
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Item 4 — `crewhaus graders suggest`: draft grader suites from the failure
3
+ * rationale that already accumulates on disk, instead of hand-authoring
4
+ * gotcha-prone graders.yaml files from scratch.
5
+ *
6
+ * Evidence sources (all read-side, none mutated):
7
+ * - Per-sample grader rationale from recent eval run dirs (the grades.json
8
+ * the runner persists next to results.json), located via the item-3
9
+ * run-history index for the cwd spec.
10
+ * - Judge criterionScores where present in grades.json (GradeResult carries
11
+ * no structured output today, so this is a defensive parse that lights up
12
+ * as soon as a judge grader persists them).
13
+ * - User feedback comments (`extractFeedbackRecords` rows) — down-rated
14
+ * comments join the failure evidence; up-rated turns join the pass
15
+ * exemplars.
16
+ *
17
+ * Pipeline: failure texts cluster into themes DETERMINISTICALLY (normalized
18
+ * token overlap — no model call needed to cluster); each theme then gets a
19
+ * deterministic draft grader (tool_call_sequence / json_path / regex /
20
+ * contains, in that priority order) derived from the observed up-rated
21
+ * outputs; with `--model`/credentials one complete llm_judge rubric (all
22
+ * five anchors) is additionally drafted from real good/bad exemplars — the
23
+ * model call itself lives in the CLI entry file, this module owns the pure
24
+ * prompt builder + response parser.
25
+ *
26
+ * The output is a REVIEW file (never auto-applied) whose header documents
27
+ * the hard-AND collapse: `crewhaus eval` combines stacked graders with
28
+ * eval-grader's `all(...)` (min-score, every-grader-must-pass), so the file
29
+ * tells the user to adopt ONE grader rather than the whole stack.
30
+ *
31
+ * Kept in a side-effect-free module (the CLI entry file runs an argv switch
32
+ * on import) mirroring `feedback.ts` / `triage.ts`.
33
+ */
34
+ import type { LoadedRun } from "@crewhaus/eval-report";
35
+ import { type FeedbackRecord, type GraderSpecObject, type GradersConfigObject, type SessionTurn } from "./feedback";
36
+ /** Thrown on malformed flags / unusable evidence. The CLI entry file routes
37
+ * it through `die()`; tests assert on `.message`. */
38
+ export declare class GradersSuggestError extends Error {
39
+ readonly name = "GradersSuggestError";
40
+ }
41
+ /** How many recent runs (for the cwd spec) feed the suggestion by default. */
42
+ export declare const DEFAULT_SUGGEST_RUNS = 10;
43
+ /** Default output path for the review file. */
44
+ export declare const DEFAULT_SUGGESTED_GRADERS_FILE = "graders-suggested.yaml";
45
+ /** One-liner printed by `crewhaus distill` when it falls back to the floor
46
+ * grader (see {@link isFloorGraderConfig}). */
47
+ export declare const FLOOR_GRADER_HINT = "hint: draft sharper graders from recent eval failures and ratings with `crewhaus graders suggest`";
48
+ /** True when a synthesized config is exactly the non-empty-answer floor
49
+ * grader `synthesizeGraders` emits when the ratings carry no signal — the
50
+ * trigger for the {@link FLOOR_GRADER_HINT} suggestion hook. */
51
+ export declare function isFloorGraderConfig(config: GradersConfigObject): boolean;
52
+ export type RunsSelector = {
53
+ kind: "dir";
54
+ dir: string;
55
+ } | {
56
+ kind: "last";
57
+ n: number;
58
+ };
59
+ /** Parse `--runs`: `last:N` / `last N` selects the N most recent indexed
60
+ * runs; anything else is a run directory path. */
61
+ export declare function parseRunsFlag(value: string): RunsSelector;
62
+ /** One failing grader verdict (or down-rated comment), joined to its sample. */
63
+ export type FailureEvidence = {
64
+ readonly sampleId: string;
65
+ /** runId, or "feedback" for rating comments. */
66
+ readonly runId: string;
67
+ /** Grader name, `<grader>:criterion`, or "user_feedback". */
68
+ readonly source: string;
69
+ /** Cleaned rationale/comment text — the clustering signal. */
70
+ readonly text: string;
71
+ /** The failing output, when known (discriminative-token drafting). */
72
+ readonly output?: string;
73
+ };
74
+ /** One up-rated output — a passing eval sample or a thumbs-up turn. */
75
+ export type PassExemplar = {
76
+ readonly sampleId: string;
77
+ readonly runId: string;
78
+ readonly output: string;
79
+ readonly toolNames: ReadonlyArray<string>;
80
+ };
81
+ export type SuggestEvidence = {
82
+ readonly failures: ReadonlyArray<FailureEvidence>;
83
+ readonly passes: ReadonlyArray<PassExemplar>;
84
+ };
85
+ /** Mirror of eval-runner's per-sample dir sanitizer — the key LoadedRun's
86
+ * perSample map uses. Keep in sync with run-sample.ts. */
87
+ export declare function sanitizeSampleId(id: string): string;
88
+ /** Unique tool names (first-seen order) from a per-sample events.jsonl —
89
+ * `tool_call_end` trace events carry the runtime tool name. Tolerant of
90
+ * torn/corrupt lines. */
91
+ export declare function toolNamesFromEventsJsonl(text: string): string[];
92
+ /**
93
+ * Strip runner/judge boilerplate from a grader rationale so clustering sees
94
+ * the substance: the `[name: ✗]` combinator markers, the `judge=N (need
95
+ * ≥M):` prefix. Infra noise ("grader threw: …", "agent invocation error:
96
+ * …") returns "" — an outage is not a failure theme.
97
+ */
98
+ export declare function cleanRationale(rationale: string): string;
99
+ /** Defensive parse of a raw grades.json for judge criterionScores (not part
100
+ * of GradeResult today — see the module doc). Criteria scored ≤ 2 of 5
101
+ * become failure evidence in their own right. */
102
+ export declare function criterionEvidence(gradesText: string, sampleId: string, runId: string): FailureEvidence[];
103
+ /**
104
+ * Extract failure evidence + pass exemplars from one loaded eval run.
105
+ * Samples are visited in sampleId order (determinism), errored/grader-threw
106
+ * samples are skipped wholesale (infra noise, not a failure theme — the
107
+ * same posture as triage's pin guards).
108
+ */
109
+ export declare function evidenceFromRun(run: LoadedRun): SuggestEvidence;
110
+ /**
111
+ * Fold user ratings into the evidence: down-rated comments become failure
112
+ * evidence, up-rated turns become pass exemplars (their outputs + observed
113
+ * tool names). Positive comments are returned separately — they season the
114
+ * llm_judge rubric prompt, not the clustering.
115
+ */
116
+ export declare function evidenceFromFeedback(turns: ReadonlyArray<SessionTurn>, records: ReadonlyArray<FeedbackRecord>, minScore: number): SuggestEvidence & {
117
+ positiveComments: string[];
118
+ };
119
+ /** Normalized token list for one evidence text: lowercase, alphanumeric,
120
+ * length ≥ 3, non-stopword, unique, in first-seen order. */
121
+ export declare function normalizeEvidenceTokens(text: string): string[];
122
+ export type FailureTheme = {
123
+ /** Top tokens joined — the human handle for the theme. */
124
+ readonly label: string;
125
+ readonly tokens: ReadonlyArray<string>;
126
+ readonly items: ReadonlyArray<FailureEvidence>;
127
+ readonly sampleIds: ReadonlyArray<string>;
128
+ readonly runIds: ReadonlyArray<string>;
129
+ readonly sources: ReadonlyArray<string>;
130
+ };
131
+ /**
132
+ * Deterministic greedy clustering by normalized token overlap — no model
133
+ * call. Items are visited in a stable sort order (runId, sampleId, source,
134
+ * text) and joined to the best existing cluster when the Jaccard overlap
135
+ * with its SEED item's tokens reaches `threshold` (seed comparison keeps a
136
+ * cluster from drifting as it grows); otherwise they seed a new cluster.
137
+ * Themes come back largest-first, labelled by their most frequent tokens.
138
+ */
139
+ export declare function clusterFailures(items: ReadonlyArray<FailureEvidence>, opts?: {
140
+ threshold?: number;
141
+ }): FailureTheme[];
142
+ export type SuggestedGrader = {
143
+ readonly spec: GraderSpecObject;
144
+ /** Comment lines (without the leading `# `) citing the evidence. */
145
+ readonly evidence: ReadonlyArray<string>;
146
+ };
147
+ export type DraftResult = {
148
+ readonly suggestions: ReadonlyArray<SuggestedGrader>;
149
+ /** Themes no deterministic grader could be drafted for. */
150
+ readonly undrafted: ReadonlyArray<FailureTheme>;
151
+ };
152
+ /**
153
+ * Draft one deterministic grader per failure theme from the observed
154
+ * up-rated outputs, in priority order: tool_call_sequence (theme mentions
155
+ * tools + passes share tools) → json_path (all pass outputs are JSON
156
+ * objects with a common key) → regex (shared output prefix) → contains
157
+ * (discriminative pass token). Themes with no deterministic signal come
158
+ * back in `undrafted` so the review file can note them.
159
+ */
160
+ export declare function draftGradersForThemes(themes: ReadonlyArray<FailureTheme>, passes: ReadonlyArray<PassExemplar>): DraftResult;
161
+ /** System block for the one-shot rubric drafting call. */
162
+ export declare const RUBRIC_SUGGESTION_SYSTEM = "You design eval rubrics for AI agent harnesses. You will receive real GOOD exemplars (outputs users or graders rated up), real BAD evidence (grader rationales / user complaints), and the clustered failure themes. Write one llm_judge rubric criterion that separates the good from the bad.\n\nHard rules:\n- Output exactly one JSON object: {\"name\": \"...\", \"description\": \"...\", \"anchors\": {\"1\": \"...\", \"2\": \"...\", \"3\": \"...\", \"4\": \"...\", \"5\": \"...\"}, \"passing_score\": 3}. No text outside the JSON.\n- \"name\" is a short snake_case identifier.\n- The five anchors must be concrete, observable behaviors grounded in the exemplars \u2014 1 is the worst observed failure mode, 5 is the best observed behavior.\n- Do not quote any exemplar verbatim for more than a short phrase.";
163
+ /** The user message for the rubric call: clipped good/bad exemplars + the
164
+ * deterministic theme labels. */
165
+ export declare function buildRubricSuggestionPrompt(goodOutputs: ReadonlyArray<string>, badEvidence: ReadonlyArray<FailureEvidence>, themes: ReadonlyArray<FailureTheme>): string;
166
+ /**
167
+ * Tolerant parse of the rubric response into a complete single-criterion
168
+ * `llm_judge` GraderSpecObject (all five anchors required). Returns
169
+ * undefined on ANY shape failure — the caller keeps the deterministic
170
+ * suggestions and notes the skipped rubric.
171
+ */
172
+ export declare function parseRubricSuggestion(raw: string, model?: string): GraderSpecObject | undefined;
173
+ export type RenderSuggestionsOptions = {
174
+ readonly specName?: string;
175
+ readonly runsSeen: number;
176
+ readonly failureCount: number;
177
+ readonly feedbackCount: number;
178
+ readonly undraftedLabels: ReadonlyArray<string>;
179
+ };
180
+ /**
181
+ * Render the review file: a hard-AND-aware header, then a valid graders.yaml
182
+ * (parseable by `parseGradersConfig`, so a reviewed grader can be copied —
183
+ * or the file trimmed to one grader and used directly), with each grader
184
+ * preceded by a `# evidence:` comment citing what it was drafted from.
185
+ */
186
+ export declare function renderSuggestedGradersYaml(suggestions: ReadonlyArray<SuggestedGrader>, opts: RenderSuggestionsOptions): string;