@mairwunnx/ctxray 0.0.0-stage → 0.1.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 (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +160 -2
  3. package/bin/ctxray.js +2 -0
  4. package/index.js +1 -0
  5. package/package.json +41 -4
  6. package/types/app/globals.d.ts +3 -0
  7. package/types/app/public-api.d.ts +3 -0
  8. package/types/entities/harness/adapters.d.ts +12 -0
  9. package/types/entities/harness/capability.d.ts +2 -0
  10. package/types/entities/harness/capture/canary.d.ts +5 -0
  11. package/types/entities/harness/capture/copy.d.ts +3 -0
  12. package/types/entities/harness/capture/isolate.d.ts +16 -0
  13. package/types/entities/harness/capture/loadout.d.ts +19 -0
  14. package/types/entities/harness/capture/mcp.d.ts +15 -0
  15. package/types/entities/harness/capture/model.d.ts +44 -0
  16. package/types/entities/harness/capture/session.d.ts +54 -0
  17. package/types/entities/harness/capture/user-scope.d.ts +12 -0
  18. package/types/entities/harness/claude-code/transcript.d.ts +8 -0
  19. package/types/entities/harness/index.d.ts +22 -0
  20. package/types/entities/harness/inventory.d.ts +54 -0
  21. package/types/entities/harness/layers/dead-rules.d.ts +3 -0
  22. package/types/entities/harness/layers/files.d.ts +8 -0
  23. package/types/entities/harness/layers/lint-config.d.ts +9 -0
  24. package/types/entities/harness/layers/lint.d.ts +5 -0
  25. package/types/entities/harness/layers/policy.d.ts +16 -0
  26. package/types/entities/harness/layers/reach.d.ts +7 -0
  27. package/types/entities/harness/profile.d.ts +22 -0
  28. package/types/entities/harness/profiles.d.ts +3 -0
  29. package/types/entities/harness/project.d.ts +26 -0
  30. package/types/entities/harness/revision.d.ts +11 -0
  31. package/types/entities/harness/static-loadout.d.ts +42 -0
  32. package/types/entities/harness-cache/dirs.d.ts +7 -0
  33. package/types/entities/harness-cache/failure.d.ts +7 -0
  34. package/types/entities/harness-cache/index.d.ts +11 -0
  35. package/types/entities/harness-cache/install.d.ts +35 -0
  36. package/types/entities/harness-cache/inventory.d.ts +15 -0
  37. package/types/entities/harness-cache/npmrc.d.ts +9 -0
  38. package/types/entities/harness-cache/pack.d.ts +8 -0
  39. package/types/entities/harness-cache/progress-view.d.ts +5 -0
  40. package/types/entities/harness-cache/provisioning.d.ts +38 -0
  41. package/types/entities/harness-cache/recipes.d.ts +18 -0
  42. package/types/entities/harness-cache/registry.d.ts +20 -0
  43. package/types/entities/harness-cache/resolve.d.ts +4 -0
  44. package/types/entities/loadout/diff.d.ts +21 -0
  45. package/types/entities/loadout/index.d.ts +1 -0
  46. package/types/entities/proxy/ask.d.ts +9 -0
  47. package/types/entities/proxy/cassette.d.ts +20 -0
  48. package/types/entities/proxy/conversation.d.ts +10 -0
  49. package/types/entities/proxy/credentials.d.ts +4 -0
  50. package/types/entities/proxy/egress.d.ts +6 -0
  51. package/types/entities/proxy/exact/attribute.d.ts +19 -0
  52. package/types/entities/proxy/exact/cache.d.ts +7 -0
  53. package/types/entities/proxy/exact/counter.d.ts +17 -0
  54. package/types/entities/proxy/exact/endpoints.d.ts +14 -0
  55. package/types/entities/proxy/exact/index.d.ts +3 -0
  56. package/types/entities/proxy/forward.d.ts +16 -0
  57. package/types/entities/proxy/index.d.ts +15 -0
  58. package/types/entities/proxy/mcp-forward.d.ts +6 -0
  59. package/types/entities/proxy/model.d.ts +16 -0
  60. package/types/entities/proxy/prices.d.ts +10 -0
  61. package/types/entities/proxy/protocols/calls.d.ts +6 -0
  62. package/types/entities/proxy/protocols/index.d.ts +6 -0
  63. package/types/entities/proxy/protocols/kit.d.ts +7 -0
  64. package/types/entities/proxy/protocols/sse.d.ts +8 -0
  65. package/types/entities/proxy/relay.d.ts +13 -0
  66. package/types/entities/proxy/server.d.ts +17 -0
  67. package/types/entities/proxy/trace.d.ts +7 -0
  68. package/types/entities/proxy/usage.d.ts +10 -0
  69. package/types/entities/user-config/config.d.ts +32 -0
  70. package/types/entities/user-config/define.d.ts +2 -0
  71. package/types/entities/user-config/index.d.ts +8 -0
  72. package/types/entities/user-config/load.d.ts +15 -0
  73. package/types/entities/user-config/merge.d.ts +3 -0
  74. package/types/entities/user-config/network.d.ts +12 -0
  75. package/types/entities/user-config/option.d.ts +2 -0
  76. package/types/entities/user-config/problem.d.ts +13 -0
  77. package/types/entities/user-config/read.d.ts +2 -0
  78. package/types/features/test-run/api/baseline-command.d.ts +10 -0
  79. package/types/features/test-run/api/command.d.ts +15 -0
  80. package/types/features/test-run/baseline.action.d.ts +11 -0
  81. package/types/features/test-run/index.d.ts +11 -0
  82. package/types/features/test-run/lib/attempt.d.ts +31 -0
  83. package/types/features/test-run/lib/backend.d.ts +39 -0
  84. package/types/features/test-run/lib/base.d.ts +10 -0
  85. package/types/features/test-run/lib/binaries.d.ts +11 -0
  86. package/types/features/test-run/lib/capture.d.ts +37 -0
  87. package/types/features/test-run/lib/captured.d.ts +47 -0
  88. package/types/features/test-run/lib/cassettes.d.ts +15 -0
  89. package/types/features/test-run/lib/corpus.d.ts +5 -0
  90. package/types/features/test-run/lib/coverage.d.ts +15 -0
  91. package/types/features/test-run/lib/dsl.d.ts +31 -0
  92. package/types/features/test-run/lib/evals.d.ts +26 -0
  93. package/types/features/test-run/lib/expect.d.ts +43 -0
  94. package/types/features/test-run/lib/failure.d.ts +15 -0
  95. package/types/features/test-run/lib/loadout.d.ts +37 -0
  96. package/types/features/test-run/lib/model.d.ts +63 -0
  97. package/types/features/test-run/lib/rules.d.ts +32 -0
  98. package/types/features/test-run/lib/run.d.ts +44 -0
  99. package/types/features/test-run/lib/runs.d.ts +25 -0
  100. package/types/features/test-run/lib/scope.d.ts +39 -0
  101. package/types/features/test-run/lib/selection.d.ts +24 -0
  102. package/types/features/test-run/lib/session.d.ts +19 -0
  103. package/types/features/test-run/lib/snapshot.d.ts +46 -0
  104. package/types/features/test-run/lib/spend.d.ts +14 -0
  105. package/types/features/test-run/lib/workspace.d.ts +3 -0
  106. package/types/features/test-run/starting-loadout.action.d.ts +8 -0
  107. package/types/features/test-run/test-run.action.d.ts +51 -0
  108. package/types/shared/cli/command.d.ts +19 -0
  109. package/types/shared/cli/index.d.ts +2 -0
  110. package/types/shared/cli/parse.d.ts +14 -0
  111. package/types/shared/codeowners/codeowners.d.ts +5 -0
  112. package/types/shared/codeowners/index.d.ts +1 -0
  113. package/types/shared/contract/activation.d.ts +8 -0
  114. package/types/shared/contract/config.d.ts +373 -0
  115. package/types/shared/contract/exit-code.d.ts +10 -0
  116. package/types/shared/contract/harness.d.ts +31 -0
  117. package/types/shared/contract/index.d.ts +15 -0
  118. package/types/shared/contract/inspection.d.ts +327 -0
  119. package/types/shared/contract/json-schema.d.ts +1572 -0
  120. package/types/shared/contract/limits.d.ts +58 -0
  121. package/types/shared/contract/lint.d.ts +272 -0
  122. package/types/shared/contract/loadout.d.ts +195 -0
  123. package/types/shared/contract/lockfile.d.ts +48 -0
  124. package/types/shared/contract/report.d.ts +1635 -0
  125. package/types/shared/contract/result.d.ts +27 -0
  126. package/types/shared/contract/session.d.ts +230 -0
  127. package/types/shared/contract/tests.d.ts +625 -0
  128. package/types/shared/contract/trace.d.ts +42 -0
  129. package/types/shared/i18n/catalog-type.d.ts +4 -0
  130. package/types/shared/i18n/catalog.d.ts +7 -0
  131. package/types/shared/i18n/format.d.ts +7 -0
  132. package/types/shared/i18n/index.d.ts +5 -0
  133. package/types/shared/i18n/locales/en/index.d.ts +637 -0
  134. package/types/shared/i18n/locales/index.d.ts +3 -0
  135. package/types/shared/i18n/resolve-locale.d.ts +9 -0
  136. package/types/shared/i18n/translate.d.ts +5 -0
  137. package/types/shared/infra/env.d.ts +3 -0
  138. package/types/shared/infra/file-lock.d.ts +6 -0
  139. package/types/shared/infra/http.d.ts +7 -0
  140. package/types/shared/infra/index.d.ts +5 -0
  141. package/types/shared/infra/parallel.d.ts +2 -0
  142. package/types/shared/infra/platform.d.ts +9 -0
  143. package/types/shared/mcp-shim/index.d.ts +2 -0
  144. package/types/shared/mcp-shim/read.d.ts +18 -0
  145. package/types/shared/mcp-shim/shim.d.ts +15 -0
  146. package/types/shared/redact/index.d.ts +2 -0
  147. package/types/shared/redact/patterns.d.ts +14 -0
  148. package/types/shared/redact/redact.d.ts +6 -0
  149. package/types/shared/render/choose.d.ts +9 -0
  150. package/types/shared/render/index.d.ts +5 -0
  151. package/types/shared/render/layout.d.ts +7 -0
  152. package/types/shared/render/plain.d.ts +2 -0
  153. package/types/shared/render/renderer.d.ts +10 -0
  154. package/types/shared/render/view.d.ts +8 -0
  155. package/types/shared/stats/index.d.ts +1 -0
  156. package/types/shared/stats/wilson.d.ts +20 -0
  157. package/types/shared/tokens/calibration/calibration.d.ts +25 -0
  158. package/types/shared/tokens/calibration/classify.d.ts +3 -0
  159. package/types/shared/tokens/calibration/index.d.ts +9 -0
  160. package/types/shared/tokens/count.d.ts +10 -0
  161. package/types/shared/tokens/index.d.ts +2 -0
@@ -0,0 +1,17 @@
1
+ import type { Egress } from "#shared/infra/index.js";
2
+ import { type McpMessage } from "./mcp-forward.js";
3
+ import type { Handler } from "./model.js";
4
+ export type ProxyServer = {
5
+ url: string;
6
+ open: (handler: Handler) => {
7
+ id: string;
8
+ baseUrl: string;
9
+ close: () => void;
10
+ };
11
+ openMcp: (target: string, egress: Egress, onMessage: (line: McpMessage) => void) => {
12
+ url: string;
13
+ close: () => void;
14
+ };
15
+ stop: () => Promise<void>;
16
+ };
17
+ export declare const startProxy: () => ProxyServer;
@@ -0,0 +1,7 @@
1
+ import type { Redactor } from "#shared/redact/index.js";
2
+ import type { Exchange } from "./model.js";
3
+ export type TraceWriter = {
4
+ write: (exchange: Exchange) => void;
5
+ flush: () => Promise<void>;
6
+ };
7
+ export declare const createTraceWriter: (file: string, redactor: Redactor) => TraceWriter;
@@ -0,0 +1,10 @@
1
+ import type { Protocol } from "./model.js";
2
+ export type Usage = {
3
+ input: number;
4
+ cacheRead: number;
5
+ cacheWrite: number;
6
+ output: number;
7
+ };
8
+ export declare const NO_USAGE: Usage;
9
+ export declare const addUsage: (a: Usage, b: Usage) => Usage;
10
+ export declare const usageOf: (protocol: Protocol, text: string) => Usage;
@@ -0,0 +1,32 @@
1
+ import { type Backend, type Budget, type HarnessId, type HarnessSettings, type LimitsInput, type LintConfig, type Network, type Policy, type Price, type ResolvedLimits, type UserConfig } from "#shared/contract/index.js";
2
+ import { type Env } from "#shared/infra/index.js";
3
+ export type Config = {
4
+ readonly files: readonly string[];
5
+ readonly harnesses: Partial<Record<HarnessId, HarnessSettings>>;
6
+ readonly backends: Readonly<Record<string, Backend>>;
7
+ readonly upstream: string | undefined;
8
+ readonly offline: boolean;
9
+ readonly network: Network;
10
+ readonly budget: Budget;
11
+ readonly activate: {
12
+ readonly min: number;
13
+ readonly max: number;
14
+ readonly runs: number;
15
+ };
16
+ readonly prices: Readonly<Record<string, Price>>;
17
+ readonly exactTokens: boolean;
18
+ readonly ignoreHarnessDifferences: boolean;
19
+ readonly policies: readonly Policy[];
20
+ readonly redact: {
21
+ readonly patterns: readonly RegExp[];
22
+ };
23
+ readonly limits: ResolvedLimits;
24
+ readonly limitsInput: LimitsInput | undefined;
25
+ readonly lint: LintConfig;
26
+ readonly reporters: readonly string[] | undefined;
27
+ readonly lang: string;
28
+ readonly reportLangs: readonly string[] | undefined;
29
+ readonly reportDir: string;
30
+ };
31
+ export declare const finalizeConfig: (merged: UserConfig, env: Env, files: readonly string[]) => Config;
32
+ export declare const DEFAULT_CONFIG: Config;
@@ -0,0 +1,2 @@
1
+ import type { UserConfigInput } from "#shared/contract/index.js";
2
+ export declare const defineConfig: (config: UserConfigInput) => UserConfigInput;
@@ -0,0 +1,8 @@
1
+ export { type Config, DEFAULT_CONFIG, finalizeConfig } from "./config.js";
2
+ export { defineConfig } from "./define.js";
3
+ export { type ConfigLoader, createConfigLoader, type LoadResult } from "./load.js";
4
+ export { mergeConfigs } from "./merge.js";
5
+ export { egressOf, type NetworkSettings, resolveNetwork } from "./network.js";
6
+ export { CONFIG_OPTION } from "./option.js";
7
+ export type { ConfigProblem } from "./problem.js";
8
+ export { CONFIG_FILES } from "./read.js";
@@ -0,0 +1,15 @@
1
+ import { type Env } from "#shared/infra/index.js";
2
+ import { type Config } from "./config.js";
3
+ import { type ConfigProblem } from "./problem.js";
4
+ export type LoadResult = {
5
+ ok: true;
6
+ config: Config;
7
+ } | {
8
+ ok: false;
9
+ problems: readonly ConfigProblem[];
10
+ };
11
+ export type ConfigLoader = (path: string | undefined, lang: string) => Promise<LoadResult>;
12
+ export declare function createConfigLoader(cwd: string, env: Env): ConfigLoader;
13
+ export declare namespace createConfigLoader {
14
+ var inject: readonly ["cwd", "env"];
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { UserConfig } from "#shared/contract/index.js";
2
+ export declare const deepMerge: (base: unknown, override: unknown) => unknown;
3
+ export declare const mergeConfigs: (base: UserConfig, override: UserConfig) => UserConfig;
@@ -0,0 +1,12 @@
1
+ import type { Egress, Env } from "#shared/infra/index.js";
2
+ import type { Config } from "./config.js";
3
+ export type NetworkSettings = {
4
+ readonly httpsProxy: string | undefined;
5
+ readonly httpProxy: string | undefined;
6
+ readonly noProxy: readonly string[];
7
+ readonly caFiles: readonly string[];
8
+ readonly systemCa: boolean;
9
+ readonly offline: boolean;
10
+ };
11
+ export declare const resolveNetwork: (config: Config, env: Env) => NetworkSettings;
12
+ export declare const egressOf: (network: NetworkSettings) => Promise<Egress>;
@@ -0,0 +1,2 @@
1
+ import type { OptionSpec } from "#shared/cli/index.js";
2
+ export declare const CONFIG_OPTION: OptionSpec;
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ import type { MessageKey, Params } from "#shared/i18n/index.js";
3
+ export type ConfigProblem = {
4
+ readonly key: MessageKey;
5
+ readonly params: Params;
6
+ };
7
+ export declare class ConfigFailure extends Error {
8
+ readonly problems: readonly ConfigProblem[];
9
+ constructor(problems: readonly ConfigProblem[]);
10
+ }
11
+ export declare const fail: (key: MessageKey, params: Params) => never;
12
+ export declare const zodErrors: (lang: string) => z.core.$ZodErrorMap<z.core.$ZodIssue>;
13
+ export declare const issueProblem: (issue: z.core.$ZodIssue, file: string) => ConfigProblem;
@@ -0,0 +1,2 @@
1
+ export declare const CONFIG_FILES: readonly ["ctxray.config.ts", "ctxray.config.jsonc", "ctxray.config.json"];
2
+ export declare const readConfigFile: (file: string) => Promise<unknown>;
@@ -0,0 +1,10 @@
1
+ import { type Config } from "#entities/user-config/index.js";
2
+ import type { CommandSpec, Handler } from "#shared/cli/index.js";
3
+ import type { Translate } from "#shared/i18n/index.js";
4
+ import { type Renderer } from "#shared/render/index.js";
5
+ import type { BaselineAction } from "../baseline.action.js";
6
+ export declare const baselineSpec: CommandSpec;
7
+ export declare function createBaselineCommand(baseline: BaselineAction, t: Translate, renderer: Renderer, config: Config): Handler;
8
+ export declare namespace createBaselineCommand {
9
+ var inject: readonly ["baselineAction", "t", "renderer", "config"];
10
+ }
@@ -0,0 +1,15 @@
1
+ import { type Config } from "#entities/user-config/index.js";
2
+ import type { CommandSpec, Handler } from "#shared/cli/index.js";
3
+ import type { Translate } from "#shared/i18n/index.js";
4
+ import type { Env } from "#shared/infra/index.js";
5
+ import { type Renderer } from "#shared/render/index.js";
6
+ import type { TestRunAction } from "../test-run.action.js";
7
+ export declare const testSpec: CommandSpec;
8
+ export type RunSettings = {
9
+ readonly lang: string;
10
+ readonly ci: boolean;
11
+ };
12
+ export declare function createTestCommand(testRun: TestRunAction, t: Translate, renderer: Renderer, config: Config, env: Env, version: string, settings: RunSettings): Handler;
13
+ export declare namespace createTestCommand {
14
+ var inject: readonly ["testRunAction", "t", "renderer", "config", "env", "version", "settings"];
15
+ }
@@ -0,0 +1,11 @@
1
+ import type { Config } from "#entities/user-config/index.js";
2
+ import type { HarnessId } from "#shared/contract/index.js";
3
+ export type BaselineResult = {
4
+ file: string;
5
+ count: number;
6
+ };
7
+ export declare function createBaselineAction(config: Config, cwd: string): (harnesses: readonly HarnessId[]) => Promise<BaselineResult>;
8
+ export declare namespace createBaselineAction {
9
+ var inject: readonly ["config", "cwd"];
10
+ }
11
+ export type BaselineAction = ReturnType<typeof createBaselineAction>;
@@ -0,0 +1,11 @@
1
+ export { baselineSpec, createBaselineCommand } from "./api/baseline-command.js";
2
+ export { createTestCommand, testSpec } from "./api/command.js";
3
+ export { type BaselineAction, createBaselineAction } from "./baseline.action.js";
4
+ export { corpus } from "./lib/corpus.js";
5
+ export { suite, test } from "./lib/dsl.js";
6
+ export { expect } from "./lib/expect.js";
7
+ export type { ResolvedLoadout, ResolveRequest } from "./lib/loadout.js";
8
+ export type { SuiteOptions, TestOptions } from "./lib/model.js";
9
+ export { discover, type Rule, type RuleSelector, type RuleSet } from "./lib/rules.js";
10
+ export { createStartingLoadout, type StartingLoadout } from "./starting-loadout.action.js";
11
+ export { createTestRunAction, type TestRunAction } from "./test-run.action.js";
@@ -0,0 +1,31 @@
1
+ import type { Finding, Problem } from "#entities/harness/index.js";
2
+ import type { TestStatus } from "#shared/contract/index.js";
3
+ import type { MessageKey, Params } from "#shared/i18n/index.js";
4
+ import { type FailureLine } from "./failure.js";
5
+ export type Failure = {
6
+ kind: "check";
7
+ key: MessageKey;
8
+ params: Params;
9
+ lines: readonly FailureLine[];
10
+ } | {
11
+ kind: "error";
12
+ message: string;
13
+ where: string | undefined;
14
+ } | {
15
+ kind: "problems";
16
+ problems: readonly Problem[];
17
+ } | {
18
+ kind: "findings";
19
+ findings: readonly Finding[];
20
+ };
21
+ export declare const toFailure: (error: unknown) => Failure;
22
+ export declare const DEFAULT_TIMEOUT = 30000;
23
+ export type Outcome = {
24
+ status: TestStatus;
25
+ failure?: Failure;
26
+ attempts: number;
27
+ };
28
+ export declare const attempt: (run: () => unknown, { retries, timeout }?: {
29
+ retries?: number | undefined;
30
+ timeout?: number | undefined;
31
+ }) => Promise<Outcome>;
@@ -0,0 +1,39 @@
1
+ import { type Miss } from "#entities/proxy/index.js";
2
+ import type { HarnessId } from "#shared/contract/index.js";
3
+ import type { Egress, Env } from "#shared/infra/index.js";
4
+ import type { RelaySpec } from "./capture.js";
5
+ import type { Cassettes } from "./cassettes.js";
6
+ import type { Spend } from "./spend.js";
7
+ export type BackendDeps = {
8
+ kind: "real" | "replay";
9
+ record: boolean;
10
+ upstream: string | undefined;
11
+ env: Env;
12
+ egress: () => Promise<Egress>;
13
+ cassettes: Cassettes;
14
+ spend: Spend;
15
+ clean: (text: string) => string;
16
+ };
17
+ export type TapeKey = {
18
+ file: string;
19
+ harness: HarnessId;
20
+ key: string;
21
+ };
22
+ export type SampleBackend = {
23
+ spec: RelaySpec;
24
+ done: (ran: {
25
+ version: string;
26
+ model: string;
27
+ }) => Promise<void>;
28
+ misses: () => readonly Miss[];
29
+ recorded: () => Promise<{
30
+ version: string;
31
+ model: string;
32
+ } | undefined>;
33
+ };
34
+ export declare const createBackend: (deps: BackendDeps) => {
35
+ kind: "real" | "replay";
36
+ sample: (tape: TapeKey, maxTurns: number) => Promise<SampleBackend>;
37
+ spent: () => boolean;
38
+ };
39
+ export type Backend = ReturnType<typeof createBackend>;
@@ -0,0 +1,10 @@
1
+ import { type LoadoutDiff } from "#entities/loadout/index.js";
2
+ import type { HarnessId } from "#shared/contract/index.js";
3
+ export type BaseDiff = {
4
+ ref: string;
5
+ diffs: {
6
+ harness: HarnessId;
7
+ diff: LoadoutDiff;
8
+ }[];
9
+ };
10
+ export declare const diffAgainst: (root: string, ref: string, harnesses: readonly HarnessId[]) => Promise<BaseDiff>;
@@ -0,0 +1,11 @@
1
+ import { type Progress } from "#entities/harness-cache/index.js";
2
+ import { type Config } from "#entities/user-config/index.js";
3
+ import type { HarnessId } from "#shared/contract/index.js";
4
+ import type { Env } from "#shared/infra/index.js";
5
+ export type BinaryOptions = {
6
+ frozen: boolean;
7
+ install: boolean;
8
+ onInstall: (harness: HarnessId, progress: Progress) => void;
9
+ };
10
+ export declare const createBinaries: (config: Config, env: Env, cwd: string, options: BinaryOptions) => (harness: HarnessId) => Promise<string | undefined>;
11
+ export type Binaries = ReturnType<typeof createBinaries>;
@@ -0,0 +1,37 @@
1
+ import { type CaptureAdapter, type HarnessSession } from "#entities/harness/index.js";
2
+ import { type ExactCounter, type Handler, type Relay } from "#entities/proxy/index.js";
3
+ import { type Config } from "#entities/user-config/index.js";
4
+ import type { Env } from "#shared/infra/index.js";
5
+ import type { Binaries } from "./binaries.js";
6
+ import type { CellScope } from "./scope.js";
7
+ export type CaptureDeps = {
8
+ config: Config;
9
+ env: Env;
10
+ self: readonly string[];
11
+ binaries: Binaries;
12
+ };
13
+ export type RelaySpec = {
14
+ inner: (work: () => readonly string[]) => Handler;
15
+ maxTurns: number;
16
+ refuse?: () => string | undefined;
17
+ };
18
+ export type OpenRequest = {
19
+ cwd: string;
20
+ prompt: string;
21
+ relay?: RelaySpec | undefined;
22
+ };
23
+ export type OpenSession = {
24
+ harness: HarnessSession;
25
+ adapter: CaptureAdapter;
26
+ model: string;
27
+ trace: string;
28
+ relay: Relay | undefined;
29
+ exact: ExactCounter | undefined;
30
+ egress: () => readonly string[];
31
+ close: () => Promise<void>;
32
+ };
33
+ export declare const createCapture: ({ config, env, self, binaries }: CaptureDeps) => {
34
+ open: (scope: CellScope, { cwd, prompt, relay: spec }: OpenRequest) => Promise<OpenSession>;
35
+ stop: (keepTraces: boolean) => Promise<void>;
36
+ };
37
+ export type Capture = ReturnType<typeof createCapture>;
@@ -0,0 +1,47 @@
1
+ import type { StaticLoadout } from "#entities/harness/index.js";
2
+ import type { CommandEntry, Component, Exchange, HarnessId, LoadoutSnapshot, McpServer, McpTool, RuleEntry, SkillEntry, SystemSection } from "#shared/contract/index.js";
3
+ import { type EntryList } from "./loadout.js";
4
+ export type CapturedLoadout = {
5
+ harness: HarnessId;
6
+ version: string;
7
+ model: string | undefined;
8
+ system: EntryList<SystemSection & {
9
+ name: string;
10
+ }>;
11
+ rules: EntryList<RuleEntry>;
12
+ skills: {
13
+ listed: EntryList<SkillEntry>;
14
+ loaded: EntryList<SkillEntry>;
15
+ };
16
+ mcp: {
17
+ servers: EntryList<McpServer>;
18
+ tools: EntryList<McpTool>;
19
+ };
20
+ commands: EntryList<CommandEntry>;
21
+ duplicates: readonly {
22
+ path: string;
23
+ sameAs?: string | undefined;
24
+ }[];
25
+ tokens: {
26
+ total: number;
27
+ byComponent: Partial<Record<Component, number>>;
28
+ byMcpServer: (server: string) => number;
29
+ exact: boolean;
30
+ method: string;
31
+ framing: number | undefined;
32
+ };
33
+ };
34
+ export type CapturedRequest = {
35
+ kind: "request";
36
+ index: number;
37
+ loadout: CapturedLoadout;
38
+ added: {
39
+ rules: readonly string[];
40
+ skills: readonly string[];
41
+ };
42
+ predicted: StaticLoadout;
43
+ raw: Exchange;
44
+ snapshot: LoadoutSnapshot;
45
+ };
46
+ export declare const toCaptured: (full: LoadoutSnapshot) => CapturedLoadout;
47
+ export declare const isRequest: (value: unknown) => value is CapturedRequest;
@@ -0,0 +1,15 @@
1
+ import { type TapeEntry } from "#entities/proxy/index.js";
2
+ import type { HarnessId } from "#shared/contract/index.js";
3
+ export declare const CASSETTE_VERSION = 1;
4
+ export type Tape = {
5
+ version: string;
6
+ model: string;
7
+ entries: TapeEntry[];
8
+ };
9
+ export declare const cassettePath: (file: string, harness: HarnessId) => string;
10
+ export declare const createCassettes: () => {
11
+ get: (file: string, harness: HarnessId, key: string) => Promise<Tape | undefined>;
12
+ put: (file: string, harness: HarnessId, key: string, tape: Tape) => Promise<void>;
13
+ save: () => Promise<number>;
14
+ };
15
+ export type Cassettes = ReturnType<typeof createCassettes>;
@@ -0,0 +1,5 @@
1
+ export type Corpus = {
2
+ readonly positive: readonly string[];
3
+ readonly negative: readonly string[];
4
+ };
5
+ export declare const corpus: (path: string) => Corpus;
@@ -0,0 +1,15 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ import type { CellResult } from "./run.js";
3
+ import type { Workspace } from "./scope.js";
4
+ export type Coverage = {
5
+ harness: HarnessId;
6
+ kinds: {
7
+ activation: string;
8
+ total: number;
9
+ tested: number;
10
+ }[];
11
+ untested: string[];
12
+ dead: string[];
13
+ noPrompts: string[];
14
+ };
15
+ export declare const coverageOf: (repository: Workspace, harnesses: readonly HarnessId[], seen: (harness: HarnessId) => ReadonlySet<string>, results: readonly CellResult[]) => Promise<Coverage[]>;
@@ -0,0 +1,31 @@
1
+ import { type ContextOf, type Kind, type SuiteOptions, type TestDefinition, type TestOptions } from "./model.js";
2
+ import { type Rule, type RuleSet } from "./rules.js";
3
+ type Frame = {
4
+ name: string;
5
+ fixture: string | undefined;
6
+ };
7
+ export type Collector = {
8
+ file: string;
9
+ frames: Frame[];
10
+ tests: TestDefinition[];
11
+ pending: Promise<unknown>[];
12
+ };
13
+ export declare const collecting: () => Collector;
14
+ export declare const withCollector: (collector: Collector, load: () => Promise<unknown>) => Promise<void>;
15
+ export declare const suite: (name: string, ...args: [body: () => void] | [options: SuiteOptions, body: () => void]) => void;
16
+ export declare const formatName: (template: string, item: Readonly<Record<string, unknown>>) => string;
17
+ type Define<C> = {
18
+ (name: string, body: (context: C) => unknown): void;
19
+ (name: string, options: TestOptions, body: (context: C) => unknown): void;
20
+ };
21
+ type Each<C> = {
22
+ (rules: RuleSet): Define<C & {
23
+ rule: Rule;
24
+ }>;
25
+ <Item extends Readonly<Record<string, unknown>>>(items: readonly Item[]): Define<C & Item>;
26
+ };
27
+ export type TestKind<C> = Define<C> & {
28
+ each: Each<C>;
29
+ };
30
+ export declare const test: { [K in Kind]: TestKind<ContextOf<K>>; };
31
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { Config } from "#entities/user-config/index.js";
2
+ import { type Failure } from "./attempt.js";
3
+ import type { Backend } from "./backend.js";
4
+ import type { Capture } from "./capture.js";
5
+ import type { TestDefinition } from "./model.js";
6
+ import { type Run } from "./runs.js";
7
+ import type { CellScope } from "./scope.js";
8
+ export type EvalContext = {
9
+ capture: Capture;
10
+ backend: Backend;
11
+ concurrency: number;
12
+ activate: Config["activate"];
13
+ };
14
+ export declare const DEFAULT_TURNS: {
15
+ readonly activate: 2;
16
+ readonly scenario: 30;
17
+ };
18
+ export declare const SAMPLE_TIMEOUT = 300000;
19
+ export declare const collectRuns: (definition: TestDefinition, key: string, scope: CellScope, context: EvalContext) => Promise<import("./runs.js").Runs>;
20
+ export declare class FailedWith extends Error {
21
+ readonly failure: Failure;
22
+ constructor(failure: Failure);
23
+ }
24
+ export declare const checkBroken: (runs: readonly Run[]) => void;
25
+ export declare const judgeScenario: (runs: readonly Run[], scope: CellScope, min: number | undefined, check: (run: Run) => Promise<void>) => Promise<void>;
26
+ export declare const settle: (scope: CellScope) => void;
@@ -0,0 +1,43 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ declare const matchers: (actual: unknown, negated: boolean) => {
3
+ toLoadRule: (rule: import("./rules.js").Rule | string) => void;
4
+ toAgreeWithResolver: () => void;
5
+ skill: (name: string) => {
6
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
7
+ not: {
8
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
9
+ };
10
+ };
11
+ rule: (path: string) => {
12
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
13
+ not: {
14
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
15
+ };
16
+ };
17
+ anyOf: (set: import("./rules.js").RuleSet | readonly string[]) => {
18
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
19
+ not: {
20
+ toActivate: (threshold?: import("../../../shared/stats/wilson.js").Threshold) => void;
21
+ };
22
+ };
23
+ toBe: (expected: unknown) => void;
24
+ toEqual: (expected: unknown) => void;
25
+ toBeDefined: () => void;
26
+ toBeUndefined: () => void;
27
+ toBeLessThan: (limit: number) => void;
28
+ toBeLessThanOrEqual: (limit: number) => void;
29
+ toBeGreaterThan: (limit: number) => void;
30
+ toBeGreaterThanOrEqual: (limit: number) => void;
31
+ toHaveLength: (length: number) => void;
32
+ toMatch: (pattern: RegExp | string) => void;
33
+ toInclude: (expected: unknown) => void;
34
+ toMatchLoadoutSnapshot: () => void;
35
+ };
36
+ type Matchers = ReturnType<typeof matchers> & {
37
+ not: ReturnType<typeof matchers>;
38
+ };
39
+ declare const on: (harnesses: HarnessId | readonly HarnessId[], body: () => unknown) => unknown;
40
+ export declare const expect: ((actual: unknown) => Matchers) & {
41
+ on: typeof on;
42
+ };
43
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type MessageKey, type Params } from "#shared/i18n/index.js";
2
+ export type FailureLine = {
3
+ label: MessageKey;
4
+ value: string;
5
+ };
6
+ export declare class CheckFailure extends Error {
7
+ readonly key: MessageKey;
8
+ readonly params: Params;
9
+ readonly lines: readonly FailureLine[];
10
+ constructor(key: MessageKey, params?: Params, lines?: readonly FailureLine[]);
11
+ }
12
+ export declare class Inconclusive extends CheckFailure {
13
+ }
14
+ export declare const fail: (key: MessageKey, params?: Params, lines?: readonly FailureLine[]) => never;
15
+ export declare const show: (value: unknown) => string;
@@ -0,0 +1,37 @@
1
+ import type { CommandEntry, Component, HarnessId, McpServer, RuleEntry, SkillEntry } from "#shared/contract/index.js";
2
+ import type { CellScope } from "./scope.js";
3
+ export type ResolveRequest = {
4
+ cwd?: string;
5
+ files?: readonly string[];
6
+ };
7
+ export type EntryList<T> = T[] & {
8
+ get: (id: string) => T;
9
+ };
10
+ export type ResolvedLoadout = {
11
+ harness: HarnessId;
12
+ cwd: string;
13
+ files: readonly string[];
14
+ rules: EntryList<RuleEntry>;
15
+ skills: {
16
+ listed: EntryList<SkillEntry>;
17
+ loaded: EntryList<SkillEntry>;
18
+ };
19
+ mcp: {
20
+ servers: EntryList<McpServer>;
21
+ };
22
+ commands: EntryList<CommandEntry>;
23
+ tokens: {
24
+ known: number;
25
+ byComponent: Partial<Record<Component, number>>;
26
+ exact: false;
27
+ method: string;
28
+ };
29
+ };
30
+ type Entry = {
31
+ path?: string | undefined;
32
+ name?: string;
33
+ };
34
+ export declare const idOf: (entry: Entry) => string;
35
+ export declare const entryList: <T extends Entry>(entries: readonly T[], what: string) => EntryList<T>;
36
+ export declare const resolveIn: (scope: CellScope) => ({ cwd, files }?: ResolveRequest) => Promise<ResolvedLoadout>;
37
+ export {};
@@ -0,0 +1,63 @@
1
+ import type { Capability } from "#entities/harness/index.js";
2
+ import type { HarnessId } from "#shared/contract/index.js";
3
+ import type { CapturedLoadout } from "./captured.js";
4
+ import type { ResolvedLoadout, ResolveRequest } from "./loadout.js";
5
+ import type { RuleSet } from "./rules.js";
6
+ import type { Run, Runs } from "./runs.js";
7
+ import type { Session, SessionRequest } from "./session.js";
8
+ export declare const KIND_LAYERS: {
9
+ readonly resolve: "L3";
10
+ readonly assemble: "L4";
11
+ readonly wire: "L5";
12
+ readonly activate: "L6";
13
+ readonly scenario: "L7";
14
+ };
15
+ export type Kind = keyof typeof KIND_LAYERS;
16
+ export type TestOptions = {
17
+ requires?: readonly Capability[];
18
+ retries?: number;
19
+ timeout?: number;
20
+ cwd?: string;
21
+ prompt?: string;
22
+ positive?: readonly string[];
23
+ negative?: readonly string[];
24
+ samples?: number;
25
+ turns?: number;
26
+ min?: number;
27
+ };
28
+ export type SuiteOptions = {
29
+ fixture?: string;
30
+ };
31
+ export type BaseContext = {
32
+ harness: HarnessId;
33
+ };
34
+ export type ResolveContext = BaseContext & {
35
+ resolve: (request?: ResolveRequest) => Promise<ResolvedLoadout>;
36
+ };
37
+ export type AssembleContext = BaseContext & {
38
+ assemble: (request?: SessionRequest) => Promise<CapturedLoadout>;
39
+ };
40
+ export type WireContext = BaseContext & {
41
+ session: Session;
42
+ startSession: (request?: SessionRequest) => Session;
43
+ };
44
+ export type ActivateContext = BaseContext & {
45
+ runs: Runs;
46
+ };
47
+ export type ScenarioContext = BaseContext & {
48
+ run: Run;
49
+ };
50
+ export type ContextOf<K extends Kind> = K extends "resolve" ? ResolveContext : K extends "assemble" ? AssembleContext : K extends "wire" ? WireContext : K extends "activate" ? ActivateContext : ScenarioContext;
51
+ export type Body = (context: any) => unknown;
52
+ export type TestDefinition = {
53
+ file: string;
54
+ suites: readonly string[];
55
+ fixture: string | undefined;
56
+ name: string;
57
+ key: string;
58
+ kind: Kind;
59
+ options: TestOptions;
60
+ item?: Readonly<Record<string, unknown>>;
61
+ rules?: RuleSet;
62
+ body: Body;
63
+ };