@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,9 @@
1
+ import type { HarnessId, LimitsInput, LintConfig, LintRule, ResolvedLimits } from "#shared/contract/index.js";
2
+ import type { MessageKey } from "#shared/i18n/index.js";
3
+ import type { Problem } from "../inventory.js";
4
+ import type { Project } from "../project.js";
5
+ export declare const ruleOf: (key: MessageKey) => LintRule | undefined;
6
+ export type PathsOf = (path: string) => readonly string[];
7
+ export declare const projectPaths: (root: string) => PathsOf;
8
+ export declare const limitsFor: (lint: LintConfig, base: LimitsInput | undefined, harness: HarnessId, pathsOf?: PathsOf) => (path: string) => ResolvedLimits;
9
+ export declare const applyLintConfig: (problems: readonly Problem[], project: Project, lint: LintConfig, harness: HarnessId, pathsOf?: PathsOf) => Promise<Problem[]>;
@@ -0,0 +1,5 @@
1
+ import { type ResolvedLimits } from "#shared/contract/index.js";
2
+ import { type Inventory, type Problem } from "../inventory.js";
3
+ import { type Project } from "../project.js";
4
+ export type LimitsOf = (path: string) => ResolvedLimits;
5
+ export declare const lint: (project: Project, inventory: Inventory, limitsOf?: LimitsOf) => Promise<Problem[]>;
@@ -0,0 +1,16 @@
1
+ import type { Policy } from "#shared/contract/index.js";
2
+ import type { MessageKey } from "#shared/i18n/index.js";
3
+ import type { Project } from "../project.js";
4
+ import type { StaticLoadout } from "../static-loadout.js";
5
+ export type Finding = {
6
+ key: MessageKey;
7
+ params: Readonly<Record<string, string | number>>;
8
+ };
9
+ export type PolicyOutcome = {
10
+ id: string;
11
+ severity: "error" | "warning";
12
+ status: "passed" | "failed" | "skipped";
13
+ failures: Finding[];
14
+ skipped: Finding[];
15
+ };
16
+ export declare const checkPolicies: (policies: readonly Policy[], project: Project, loadout: StaticLoadout) => Promise<PolicyOutcome[]>;
@@ -0,0 +1,7 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ import { type Inventory, type Problem } from "../inventory.js";
3
+ import { type Project } from "../project.js";
4
+ export type ReachOptions = {
5
+ differences: boolean;
6
+ };
7
+ export declare const checkReach: (project: Project, inventories: Partial<Record<HarnessId, Inventory>>, { differences }?: ReachOptions) => Promise<Partial<Record<HarnessId, Problem[]>>>;
@@ -0,0 +1,22 @@
1
+ import type { CaptureMode, HarnessId } from "#shared/contract/index.js";
2
+ import type { Capability } from "./capability.js";
3
+ export type HarnessProfile = {
4
+ id: HarnessId;
5
+ title: string;
6
+ modes: readonly CaptureMode[];
7
+ experimentalModes: readonly CaptureMode[];
8
+ capabilities: readonly Capability[];
9
+ twin?: HarnessId;
10
+ };
11
+ export type Requirement = {
12
+ requires: readonly Capability[];
13
+ mode: CaptureMode;
14
+ experimental: boolean;
15
+ };
16
+ export type Support = {
17
+ supported: true;
18
+ } | {
19
+ supported: false;
20
+ missing: string[];
21
+ };
22
+ export declare const checkSupport: (profile: HarnessProfile, need: Requirement) => Support;
@@ -0,0 +1,3 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ import type { HarnessProfile } from "./profile.js";
3
+ export declare const PROFILES: Record<HarnessId, HarnessProfile>;
@@ -0,0 +1,26 @@
1
+ export type Project = {
2
+ root: string;
3
+ files: readonly string[];
4
+ dirs: readonly string[];
5
+ read: (path: string) => Promise<string | undefined>;
6
+ readAll: (paths: readonly string[]) => Promise<(string | undefined)[]>;
7
+ exists: (path: string) => Promise<boolean>;
8
+ };
9
+ export declare const findRoot: (dir: string) => Promise<{
10
+ root: string;
11
+ dir: string;
12
+ }>;
13
+ export declare const parentDirs: (path: string) => string[];
14
+ export declare const openProject: (root: string) => Promise<Project>;
15
+ export declare const joinPath: (dir: string, path: string) => string;
16
+ export declare const dirOf: (path: string) => string;
17
+ export declare const isInside: (path: string, dir: string) => boolean;
18
+ export declare const isWithin: (dir: string, ancestor: string) => boolean;
19
+ export declare const chainTo: (cwd: string) => string[];
20
+ export declare const matchingGlob: (globs: readonly string[], dir: string, file: string) => string | undefined;
21
+ export type MatchedFile = {
22
+ path: string;
23
+ match: RegExpExecArray;
24
+ text: string;
25
+ };
26
+ export declare const readMatching: (project: Project, pattern: RegExp) => Promise<MatchedFile[]>;
@@ -0,0 +1,11 @@
1
+ import type { LoadoutPieces } from "#shared/contract/index.js";
2
+ import type { StaticLoadout } from "./static-loadout.js";
3
+ export declare class UnknownRevision extends Error {
4
+ }
5
+ export type Revision = {
6
+ dir: string;
7
+ commit: string;
8
+ remove: () => Promise<void>;
9
+ };
10
+ export declare const checkoutRevision: (root: string, ref: string) => Promise<Revision>;
11
+ export declare const staticPieces: (loadout: StaticLoadout) => LoadoutPieces;
@@ -0,0 +1,42 @@
1
+ import type { Activation, CommandEntry, Component, HarnessId, McpServer, McpTool, RuleEntry, SkillEntry } from "#shared/contract/index.js";
2
+ import { type ModelFamily, type TokenCounter } from "#shared/tokens/index.js";
3
+ export type Scope = {
4
+ cwd: string;
5
+ files: readonly string[];
6
+ };
7
+ export type StaticLoadout = {
8
+ harness: HarnessId;
9
+ cwd: string;
10
+ rules: RuleEntry[];
11
+ skills: {
12
+ listed: SkillEntry[];
13
+ loaded: SkillEntry[];
14
+ };
15
+ mcp: {
16
+ servers: McpServer[];
17
+ tools: McpTool[];
18
+ };
19
+ commands: CommandEntry[];
20
+ tokens: {
21
+ byComponent: Partial<Record<Component, number>>;
22
+ exact: false;
23
+ method: string;
24
+ calibration?: "none";
25
+ };
26
+ };
27
+ export declare const listingLine: (name: string, description: string) => string;
28
+ export declare const familyOf: (harness: HarnessId) => ModelFamily;
29
+ export declare const tokenCounterOf: (harness: HarnessId) => TokenCounter;
30
+ export declare const createRules: (counter: TokenCounter) => {
31
+ rules: {
32
+ path: string;
33
+ activation: "always" | "intent" | "manual" | "path";
34
+ reason: string;
35
+ tokens: number;
36
+ }[];
37
+ add: (path: string, activation: Activation, reason: string, text: string) => void;
38
+ };
39
+ type Parts = Omit<StaticLoadout, "tokens">;
40
+ type Calibration = Pick<StaticLoadout["tokens"], "calibration">;
41
+ export declare const withTokens: (parts: Parts, commandLines: readonly string[], calibration?: Calibration, counter?: TokenCounter) => StaticLoadout;
42
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Env } from "#shared/infra/index.js";
2
+ export type CacheDirs = {
3
+ readonly write: string | undefined;
4
+ readonly all: readonly string[];
5
+ };
6
+ export declare const defaultCacheDir: (env: Env, os?: string, home?: string) => string;
7
+ export declare const resolveCacheDirs: (env: Env) => Promise<CacheDirs>;
@@ -0,0 +1,7 @@
1
+ import { type MessageKey, type Params } from "#shared/i18n/index.js";
2
+ export declare class ProvisionFailure extends Error {
3
+ readonly key: MessageKey;
4
+ readonly params: Params;
5
+ constructor(key: MessageKey, params?: Params);
6
+ }
7
+ export declare const fail: (key: MessageKey, params?: Params) => never;
@@ -0,0 +1,11 @@
1
+ export { type CacheDirs, defaultCacheDir, resolveCacheDirs } from "./dirs.js";
2
+ export { ProvisionFailure } from "./failure.js";
3
+ export { createHarnessCache, entryPath, type HarnessCache, type Installed, type Progress, type TarballSource, } from "./install.js";
4
+ export { type CachedBuild, listCache, type PruneOptions, pruneCache } from "./inventory.js";
5
+ export { DEFAULT_REGISTRY, type RegistrySetup, readRegistrySetup } from "./npmrc.js";
6
+ export { archiveSource, packHarnesses, registrySource } from "./pack.js";
7
+ export { progressView } from "./progress-view.js";
8
+ export { type Located, type LocateOptions, locateHarness, openProvisioning, type Provisioning, type ProvisioningOptions, } from "./provisioning.js";
9
+ export { RECIPES } from "./recipes.js";
10
+ export { createRegistry, type Registry } from "./registry.js";
11
+ export { maxSatisfying, resolveHarness } from "./resolve.js";
@@ -0,0 +1,35 @@
1
+ import type { HarnessId, LockedPackage, RegistryHarness } from "#shared/contract/index.js";
2
+ import { type Platform } from "#shared/infra/index.js";
3
+ import type { CacheDirs } from "./dirs.js";
4
+ export declare const MANIFEST = "ctxray-install.json";
5
+ export type Manifest = {
6
+ harness: HarnessId;
7
+ version: string;
8
+ platform: string;
9
+ package: string;
10
+ integrity: string;
11
+ bin: string;
12
+ };
13
+ export type Installed = Manifest & {
14
+ dir: string;
15
+ binary: string;
16
+ shared: boolean;
17
+ fresh?: boolean;
18
+ };
19
+ export type Progress = {
20
+ phase: "waiting";
21
+ } | {
22
+ phase: "download";
23
+ done: number;
24
+ total: number | undefined;
25
+ } | {
26
+ phase: "unpack";
27
+ };
28
+ export type TarballSource = (build: LockedPackage, onBytes: (done: number, total: number | undefined) => void) => AsyncIterable<Uint8Array>;
29
+ export declare const entryPath: (harness: HarnessId, version: string, platform: string, integrity: string) => string;
30
+ export declare const readManifest: (dir: string) => Promise<Manifest | undefined>;
31
+ export declare const createHarnessCache: (dirs: CacheDirs) => {
32
+ find: (harness: HarnessId, locked: RegistryHarness, platform: Platform) => Promise<Installed | undefined>;
33
+ install: (harness: HarnessId, locked: RegistryHarness, platform: Platform, source: TarballSource, onProgress?: (progress: Progress) => void) => Promise<Installed>;
34
+ };
35
+ export type HarnessCache = ReturnType<typeof createHarnessCache>;
@@ -0,0 +1,15 @@
1
+ import type { CacheDirs } from "./dirs.js";
2
+ import { type Manifest } from "./install.js";
3
+ export type CachedBuild = Manifest & {
4
+ dir: string;
5
+ size: number;
6
+ lastUsed: Date;
7
+ shared: boolean;
8
+ };
9
+ export declare const listCache: (dirs: CacheDirs) => Promise<CachedBuild[]>;
10
+ export type PruneOptions = {
11
+ keep: (build: CachedBuild) => boolean;
12
+ olderThan: number;
13
+ now?: number;
14
+ };
15
+ export declare const pruneCache: (dirs: CacheDirs, { keep, olderThan, now }: PruneOptions) => Promise<CachedBuild[]>;
@@ -0,0 +1,9 @@
1
+ import type { Env } from "#shared/infra/index.js";
2
+ export declare const DEFAULT_REGISTRY = "https://registry.npmjs.org/";
3
+ export type RegistrySetup = {
4
+ readonly registryOf: (name: string) => string;
5
+ readonly authOf: (url: string) => string | undefined;
6
+ readonly ca: readonly string[];
7
+ };
8
+ export declare const parseNpmrc: (text: string, env: Env) => Map<string, string[]>;
9
+ export declare const readRegistrySetup: (project: string, env: Env, configured: string | undefined, home?: string) => Promise<RegistrySetup>;
@@ -0,0 +1,8 @@
1
+ import type { LockedPackage, Lockfile } from "#shared/contract/index.js";
2
+ import type { TarballSource } from "./install.js";
3
+ import type { Registry } from "./registry.js";
4
+ export declare const tarballName: (build: LockedPackage) => string;
5
+ export declare const isDownload: (build: LockedPackage) => boolean;
6
+ export declare const registrySource: (registry: Registry) => TarballSource;
7
+ export declare const packHarnesses: (lock: Lockfile, platforms: readonly string[], source: TarballSource) => Promise<Record<string, string | Uint8Array<ArrayBufferLike>>>;
8
+ export declare const archiveSource: (path: string) => Promise<TarballSource>;
@@ -0,0 +1,5 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ import type { Translate } from "#shared/i18n/index.js";
3
+ import { type View } from "#shared/render/index.js";
4
+ import type { Progress } from "./install.js";
5
+ export declare const progressView: (harness: HarnessId, progress: Progress, t: Translate) => View;
@@ -0,0 +1,38 @@
1
+ import type { HarnessId, LockedHarness } from "#shared/contract/index.js";
2
+ import { type Egress, type Env, type Platform } from "#shared/infra/index.js";
3
+ import { type Installed, type Progress, type TarballSource } from "./install.js";
4
+ import { type Registry } from "./registry.js";
5
+ export type ProvisioningOptions = {
6
+ project: string;
7
+ env: Env;
8
+ registry: string | undefined;
9
+ egress: Egress;
10
+ offline: boolean;
11
+ platform?: Platform;
12
+ };
13
+ export declare const openProvisioning: ({ project, env, registry, egress, offline, platform }: ProvisioningOptions) => Promise<{
14
+ dirs: import("./dirs.js").CacheDirs;
15
+ cache: {
16
+ find: (harness: HarnessId, locked: import("#shared/contract/index.js").RegistryHarness, platform: Platform) => Promise<Installed | undefined>;
17
+ install: (harness: HarnessId, locked: import("#shared/contract/index.js").RegistryHarness, platform: Platform, source: TarballSource, onProgress?: (progress: Progress) => void) => Promise<Installed>;
18
+ };
19
+ platform: Platform;
20
+ registry: () => Promise<Registry>;
21
+ source: () => Promise<TarballSource>;
22
+ }>;
23
+ export type Provisioning = Awaited<ReturnType<typeof openProvisioning>>;
24
+ export type Located = {
25
+ binary: string;
26
+ from: "path" | "cache" | "install";
27
+ installed?: Installed;
28
+ };
29
+ export type LocateOptions = {
30
+ harness: HarnessId;
31
+ locked: LockedHarness | undefined;
32
+ system: boolean;
33
+ binary: string;
34
+ path: string;
35
+ install: boolean;
36
+ onProgress?: (progress: Progress) => void;
37
+ };
38
+ export declare const locateHarness: (provisioning: Provisioning, options: LocateOptions) => Promise<Located | undefined>;
@@ -0,0 +1,18 @@
1
+ import type { HarnessId } from "#shared/contract/index.js";
2
+ import type { Platform } from "#shared/infra/index.js";
3
+ export type Recipe = {
4
+ readonly package: string;
5
+ readonly tag: string;
6
+ readonly build: (version: string, platform: Platform) => string | undefined;
7
+ readonly bin: (dir: string, platform: Platform) => Promise<string>;
8
+ readonly root?: string;
9
+ readonly download?: {
10
+ readonly latest: (text: (url: string) => Promise<string | undefined>) => Promise<string | undefined>;
11
+ readonly checksum: (url: string) => string;
12
+ };
13
+ };
14
+ export declare const RECIPES: Partial<Record<HarnessId, Recipe>>;
15
+ export declare const splitSpec: (spec: string) => {
16
+ name: string;
17
+ version: string;
18
+ };
@@ -0,0 +1,20 @@
1
+ import { type Egress } from "#shared/infra/index.js";
2
+ import type { RegistrySetup } from "./npmrc.js";
3
+ export type Dist = {
4
+ tarball: string;
5
+ integrity: string;
6
+ };
7
+ export type Packument = {
8
+ "dist-tags": Record<string, string>;
9
+ versions: Record<string, {
10
+ dist: Dist;
11
+ }>;
12
+ };
13
+ export type Download = (done: number, total: number | undefined) => void;
14
+ export type Registry = {
15
+ packument: (name: string) => Promise<Packument>;
16
+ dist: (name: string, version: string) => Promise<Dist | undefined>;
17
+ download: (url: string, onBytes?: Download) => AsyncIterable<Uint8Array>;
18
+ text: (url: string) => Promise<string | undefined>;
19
+ };
20
+ export declare const createRegistry: (setup: RegistrySetup, egress: Egress, offline?: boolean) => Registry;
@@ -0,0 +1,4 @@
1
+ import type { HarnessId, RegistryHarness } from "#shared/contract/index.js";
2
+ import type { Registry } from "./registry.js";
3
+ export declare const maxSatisfying: (versions: readonly string[], range: string) => string | undefined;
4
+ export declare const resolveHarness: (registry: Registry, harness: HarnessId, range: string | undefined) => Promise<RegistryHarness>;
@@ -0,0 +1,21 @@
1
+ import type { Component, LoadoutPieces, LoadoutSnapshot } from "#shared/contract/index.js";
2
+ export type LoadoutChange = {
3
+ component: Component;
4
+ id: string;
5
+ before: number | undefined;
6
+ after: number | undefined;
7
+ };
8
+ export type LoadoutDiff = {
9
+ total: {
10
+ before: number;
11
+ after: number;
12
+ };
13
+ byComponent: Partial<Record<Component, {
14
+ before: number;
15
+ after: number;
16
+ }>>;
17
+ changes: LoadoutChange[];
18
+ };
19
+ export declare const piecesOfSnapshot: (loadout: LoadoutSnapshot) => LoadoutPieces;
20
+ export declare const diffLoadouts: (before: LoadoutSnapshot, after: LoadoutSnapshot) => LoadoutDiff;
21
+ export declare const diffPieces: (before: LoadoutPieces, after: LoadoutPieces) => LoadoutDiff;
@@ -0,0 +1 @@
1
+ export { diffLoadouts, diffPieces, type LoadoutChange, type LoadoutDiff, piecesOfSnapshot } from "./diff.js";
@@ -0,0 +1,9 @@
1
+ import { type Egress, type Env } from "#shared/infra/index.js";
2
+ import type { Protocol } from "./model.js";
3
+ export declare const protocolOfModel: (model: string) => Protocol;
4
+ export type AskDeps = {
5
+ upstream: string | undefined;
6
+ egress: Egress;
7
+ env: Env;
8
+ };
9
+ export declare const askModel: ({ upstream, egress, env }: AskDeps, model: string, prompt: string) => Promise<string>;
@@ -0,0 +1,20 @@
1
+ import type { Answer } from "./forward.js";
2
+ import type { Exchange, Handler } from "./model.js";
3
+ export type TapeEntry = {
4
+ path: string;
5
+ position?: number | undefined;
6
+ status: number;
7
+ contentType: string;
8
+ body: string;
9
+ };
10
+ export declare const WORK = "<work>";
11
+ export declare const createRecorder: (dirs: () => readonly string[], clean?: (text: string) => string) => {
12
+ onExchange: (exchange: Exchange) => void;
13
+ onAnswer: (exchange: Exchange, answer: Answer) => void;
14
+ tape: () => Promise<TapeEntry[]>;
15
+ };
16
+ export type Miss = {
17
+ path: string;
18
+ position: number | undefined;
19
+ };
20
+ export declare const createPlayer: (tape: readonly TapeEntry[], work: () => string, onMiss: (miss: Miss) => void) => Handler;
@@ -0,0 +1,10 @@
1
+ import type { Exchange, Handler, Step } from "./model.js";
2
+ export type Conversation = {
3
+ handler: Handler;
4
+ turns: () => readonly Exchange[];
5
+ sideCalls: () => readonly Exchange[];
6
+ turn: (position: number) => Promise<Exchange>;
7
+ answer: (position: number, step: Step) => void;
8
+ finish: (step: Step) => void;
9
+ };
10
+ export declare const createConversation: (onExchange?: (exchange: Exchange) => void) => Conversation;
@@ -0,0 +1,4 @@
1
+ import type { Env } from "#shared/infra/index.js";
2
+ import type { Protocol } from "./model.js";
3
+ export declare const CREDENTIAL_HEADERS: string[];
4
+ export declare const credentialsFor: (protocol: Protocol, env: Env, betas?: string | null) => Record<string, string>;
@@ -0,0 +1,6 @@
1
+ export type EgressGuard = {
2
+ url: string;
3
+ attempts: () => readonly string[];
4
+ stop: () => Promise<void>;
5
+ };
6
+ export declare const startEgressGuard: () => Promise<EgressGuard>;
@@ -0,0 +1,19 @@
1
+ import type { Json, Protocol } from "../model.js";
2
+ import type { ExactCounter } from "./counter.js";
3
+ export type Piece = {
4
+ component: string;
5
+ id: string;
6
+ text: string;
7
+ };
8
+ export type LocalSummary = {
9
+ byComponent: Readonly<Record<string, number | undefined>>;
10
+ byMcpServer: Readonly<Record<string, number>>;
11
+ };
12
+ export type ExactSummary = {
13
+ total: number;
14
+ byComponent: Record<string, number>;
15
+ byMcpServer: Record<string, number>;
16
+ framing: number;
17
+ method: string;
18
+ };
19
+ export declare const exactSummary: (counter: ExactCounter, protocol: Protocol, model: string, body: Json, pieces: readonly Piece[], local: LocalSummary) => Promise<ExactSummary | undefined>;
@@ -0,0 +1,7 @@
1
+ export type CountCache = {
2
+ get: (key: string) => number | undefined;
3
+ set: (key: string, tokens: number) => void;
4
+ close: () => void;
5
+ };
6
+ export declare const openCountCache: (file: string, now?: () => number) => CountCache;
7
+ export declare const memoryCountCache: () => CountCache;
@@ -0,0 +1,17 @@
1
+ import { type Egress, type Env } from "#shared/infra/index.js";
2
+ import type { Json, Protocol } from "../model.js";
3
+ import type { CountCache } from "./cache.js";
4
+ import { type Endpoint } from "./endpoints.js";
5
+ export type ExactCounter = {
6
+ endpoint: (protocol: Protocol) => Endpoint | undefined;
7
+ count: (protocol: Protocol, model: string, body: Json) => Promise<number>;
8
+ };
9
+ export type CounterDeps = {
10
+ upstream: string | undefined;
11
+ egress: Egress;
12
+ env: Env;
13
+ cache: CountCache;
14
+ };
15
+ export declare class CountFailure extends Error {
16
+ }
17
+ export declare const createExactCounter: ({ upstream, egress, env, cache }: CounterDeps) => ExactCounter;
@@ -0,0 +1,14 @@
1
+ import type { Json, Protocol } from "../model.js";
2
+ export type Endpoint = {
3
+ method: string;
4
+ path: (model: string) => string;
5
+ request: (body: Json, model: string) => Json;
6
+ read: (answer: Json) => number | undefined;
7
+ headers?: Record<string, string>;
8
+ minimal: (model: string) => Json;
9
+ withSystem: (body: Json, text: string) => Json;
10
+ withTools: (body: Json, tools: readonly Json[]) => Json;
11
+ toolsOf: (body: Json) => Json[];
12
+ probe: Json;
13
+ };
14
+ export declare const ENDPOINTS: Partial<Record<Protocol, Endpoint>>;
@@ -0,0 +1,3 @@
1
+ export { type ExactSummary, exactSummary, type LocalSummary, type Piece } from "./attribute.js";
2
+ export { type CountCache, memoryCountCache, openCountCache } from "./cache.js";
3
+ export { CountFailure, createExactCounter, type ExactCounter } from "./counter.js";
@@ -0,0 +1,16 @@
1
+ import { type Egress } from "#shared/infra/index.js";
2
+ import type { Exchange, Handler, Protocol } from "./model.js";
3
+ export declare const PROVIDERS: Record<Protocol, string>;
4
+ export type Answer = {
5
+ status: number;
6
+ contentType: string;
7
+ text: string;
8
+ };
9
+ export type ForwardOptions = {
10
+ upstream: string | undefined;
11
+ egress: Egress;
12
+ headers?: Record<string, string> | ((protocol: Protocol, sent: Headers) => Record<string, string>);
13
+ onExchange?: (exchange: Exchange) => void;
14
+ onAnswer?: (exchange: Exchange, answer: Answer) => void;
15
+ };
16
+ export declare const createForward: ({ upstream, egress, headers, onExchange, onAnswer, }: ForwardOptions) => Handler;
@@ -0,0 +1,15 @@
1
+ export { type AskDeps, askModel, protocolOfModel } from "./ask.js";
2
+ export { createPlayer, createRecorder, type Miss, type TapeEntry, WORK } from "./cassette.js";
3
+ export { type Conversation, createConversation } from "./conversation.js";
4
+ export { CREDENTIAL_HEADERS, credentialsFor } from "./credentials.js";
5
+ export { type EgressGuard, startEgressGuard } from "./egress.js";
6
+ export { CountFailure, createExactCounter, type ExactCounter, exactSummary, memoryCountCache, openCountCache, type Piece, } from "./exact/index.js";
7
+ export { type Answer, createForward, type ForwardOptions, PROVIDERS } from "./forward.js";
8
+ export type { McpMessage } from "./mcp-forward.js";
9
+ export type { Exchange, Handler, Incoming, Json, Protocol, Step, ToolCall } from "./model.js";
10
+ export { costOf, PRICES, type Price, priceOf } from "./prices.js";
11
+ export { callsOf, KITS, type MadeCall } from "./protocols/index.js";
12
+ export { createRelay, type Relay } from "./relay.js";
13
+ export { type ProxyServer, startProxy } from "./server.js";
14
+ export { createTraceWriter, type TraceWriter } from "./trace.js";
15
+ export { addUsage, NO_USAGE, type Usage, usageOf } from "./usage.js";
@@ -0,0 +1,6 @@
1
+ import { type Egress } from "#shared/infra/index.js";
2
+ export type McpMessage = {
3
+ from: "client" | "server";
4
+ message: unknown;
5
+ };
6
+ export declare const forwardMcp: (target: string, egress: Egress, onMessage: (line: McpMessage) => void) => (request: Request, subpath: string) => Promise<Response>;
@@ -0,0 +1,16 @@
1
+ import type { Exchange, Json, Protocol, Step, ToolCall } from "#shared/contract/index.js";
2
+ export type { Exchange, Json, Protocol, Step, ToolCall };
3
+ export type Route = "turn" | "count" | "models" | "analytics" | "unknown";
4
+ export type Incoming = {
5
+ session: string;
6
+ protocol: Protocol;
7
+ route: Route;
8
+ stream: boolean;
9
+ path: string;
10
+ search: string;
11
+ method: string;
12
+ headers: Headers;
13
+ body: Json;
14
+ model: string | undefined;
15
+ };
16
+ export type Handler = (incoming: Incoming) => Promise<Response>;
@@ -0,0 +1,10 @@
1
+ import type { Usage } from "./usage.js";
2
+ export type Price = {
3
+ input: number;
4
+ output: number;
5
+ cacheRead?: number | undefined;
6
+ cacheWrite?: number | undefined;
7
+ };
8
+ export declare const PRICES: Readonly<Record<string, Price>>;
9
+ export declare const priceOf: (model: string, own?: Readonly<Record<string, Price>>) => Price | undefined;
10
+ export declare const costOf: (usage: Usage, price: Price | undefined) => number | undefined;
@@ -0,0 +1,6 @@
1
+ import type { Json, Protocol } from "../model.js";
2
+ export type MadeCall = {
3
+ name: string;
4
+ input: unknown;
5
+ };
6
+ export declare const callsOf: (protocol: Protocol, body: Json) => MadeCall[];
@@ -0,0 +1,6 @@
1
+ import type { Protocol } from "../model.js";
2
+ import type { Kit } from "./kit.js";
3
+ export declare const KITS: Record<Protocol, Kit>;
4
+ export { callsOf, type MadeCall } from "./calls.js";
5
+ export type { Kit } from "./kit.js";
6
+ export { roughTokens } from "./sse.js";
@@ -0,0 +1,7 @@
1
+ import type { Json, Step } from "../model.js";
2
+ export type Kit = {
3
+ position: (body: Json) => number;
4
+ hasTools: (body: Json) => boolean;
5
+ reply: (step: Step, body: Json, stream: boolean) => Response;
6
+ error: (status: number, message: string) => Response;
7
+ };
@@ -0,0 +1,8 @@
1
+ export type Event = {
2
+ event?: string;
3
+ data: unknown;
4
+ };
5
+ export declare const sseResponse: (events: readonly Event[], headers?: Record<string, string>) => Response;
6
+ export declare const roughTokens: (value: unknown) => number;
7
+ export declare const newId: (prefix: string) => string;
8
+ export declare const chunks: (text: string, size: number) => string[];
@@ -0,0 +1,13 @@
1
+ import type { Exchange, Handler } from "./model.js";
2
+ export type RelayOptions = {
3
+ maxTurns: number;
4
+ onExchange?: (exchange: Exchange) => void;
5
+ refuse?: () => string | undefined;
6
+ };
7
+ export type Relay = {
8
+ handler: Handler;
9
+ turn: (position: number) => Promise<Exchange>;
10
+ turns: () => readonly Exchange[];
11
+ cut: () => boolean;
12
+ };
13
+ export declare const createRelay: (inner: Handler, { maxTurns, onExchange, refuse }: RelayOptions) => Relay;