@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,3 @@
1
+ import type { Catalog } from "../catalog-type.js";
2
+ export declare const CATALOGS: Readonly<Record<string, Catalog>>;
3
+ export declare const DEFAULT_LANG = "en";
@@ -0,0 +1,9 @@
1
+ export type LocaleSources = {
2
+ flag?: string | undefined;
3
+ env: Readonly<Record<string, string | undefined>>;
4
+ config?: string | undefined;
5
+ windowsUiLocale?: string | undefined;
6
+ intlLocale?: string | undefined;
7
+ };
8
+ export declare const languageOf: (value: string | undefined) => string | undefined;
9
+ export declare const resolveLocale: (sources: LocaleSources, supported: readonly string[]) => string;
@@ -0,0 +1,5 @@
1
+ import type { Catalog, MessageKey } from "./catalog-type.js";
2
+ export type Params = Readonly<Record<string, string | number | readonly string[]>>;
3
+ export type Translate = (key: MessageKey, params?: Params) => string;
4
+ export type OnMissing = (key: string, lang: string) => void;
5
+ export declare const createTranslator: (lang: string, catalogs?: Readonly<Record<string, Catalog>>, onMissing?: OnMissing) => Translate;
@@ -0,0 +1,3 @@
1
+ export type Env = Readonly<Record<string, string | undefined>>;
2
+ export declare const isOn: (value: string | undefined) => boolean;
3
+ export declare const isCi: (env: Env) => boolean;
@@ -0,0 +1,6 @@
1
+ export type LockOptions = {
2
+ stale?: number;
3
+ poll?: number;
4
+ onWait?: () => void;
5
+ };
6
+ export declare const withFileLock: <T>(path: string, work: () => Promise<T>, options?: LockOptions) => Promise<T>;
@@ -0,0 +1,7 @@
1
+ export type Egress = {
2
+ proxy: string | undefined;
3
+ noProxy: readonly string[];
4
+ ca: readonly string[];
5
+ };
6
+ export declare const DIRECT: Egress;
7
+ export declare const fetchThrough: (url: URL, init: RequestInit, egress: Egress) => Promise<Response>;
@@ -0,0 +1,5 @@
1
+ export { type Env, isCi, isOn } from "./env.js";
2
+ export { type LockOptions, withFileLock } from "./file-lock.js";
3
+ export { DIRECT, type Egress, fetchThrough } from "./http.js";
4
+ export { allInOrder, inParallel } from "./parallel.js";
5
+ export { currentPlatform, PLATFORMS, type Platform, parsePlatform, platformKey } from "./platform.js";
@@ -0,0 +1,2 @@
1
+ export declare const inParallel: <Item, Result>(items: Iterable<Item>, task: (item: Item, index: number) => Promise<Result>) => Promise<Result[]>;
2
+ export declare const allInOrder: <Result>(promises: readonly Promise<Result>[]) => Promise<Result[]>;
@@ -0,0 +1,9 @@
1
+ export type Platform = {
2
+ readonly os: string;
3
+ readonly arch: string;
4
+ readonly libc?: "glibc" | "musl";
5
+ };
6
+ export declare const platformKey: ({ os, arch, libc }: Platform) => string;
7
+ export declare const parsePlatform: (key: string) => Platform | undefined;
8
+ export declare const PLATFORMS: readonly Platform[];
9
+ export declare const currentPlatform: () => Platform;
@@ -0,0 +1,2 @@
1
+ export { type McpToolSchema, readShimLog, type ServerRecord } from "./read.js";
2
+ export { runMcpShim, type ShimConfig, type ShimLine } from "./shim.js";
@@ -0,0 +1,18 @@
1
+ export type McpToolSchema = {
2
+ name: string;
3
+ description?: string;
4
+ inputSchema?: unknown;
5
+ };
6
+ export type ServerRecord = {
7
+ info: {
8
+ name: string;
9
+ version: string;
10
+ } | undefined;
11
+ instructions: string | undefined;
12
+ tools: McpToolSchema[];
13
+ calls: {
14
+ name: string;
15
+ arguments: unknown;
16
+ }[];
17
+ };
18
+ export declare const readShimLog: (text: string) => ServerRecord;
@@ -0,0 +1,15 @@
1
+ export type ShimConfig = {
2
+ log: string;
3
+ env: Record<string, string>;
4
+ unset: string[];
5
+ patterns: {
6
+ source: string;
7
+ flags: string;
8
+ }[];
9
+ };
10
+ export type ShimLine = {
11
+ at: number;
12
+ from: "client" | "server";
13
+ message: unknown;
14
+ };
15
+ export declare const runMcpShim: (args: readonly string[]) => Promise<number>;
@@ -0,0 +1,2 @@
1
+ export { BUILTIN_PATTERNS, type Pattern } from "./patterns.js";
2
+ export { createRedactor, marker, type Redactor } from "./redact.js";
@@ -0,0 +1,14 @@
1
+ export type Found = {
2
+ match: string;
3
+ groups: readonly (string | undefined)[];
4
+ offset: number;
5
+ text: string;
6
+ };
7
+ export type Pattern = {
8
+ id: string;
9
+ regex: RegExp;
10
+ accept?: (match: string) => boolean;
11
+ keywords?: readonly string[];
12
+ secret?: (found: Found) => string | undefined;
13
+ };
14
+ export declare const BUILTIN_PATTERNS: readonly Pattern[];
@@ -0,0 +1,6 @@
1
+ export type Redactor = {
2
+ text: (value: string) => string;
3
+ value: <T>(value: T) => T;
4
+ };
5
+ export declare const marker: (id: string) => string;
6
+ export declare const createRedactor: (extra?: readonly RegExp[]) => Redactor;
@@ -0,0 +1,9 @@
1
+ import type { Env } from "#shared/infra/index.js";
2
+ export type RendererKind = "ink" | "plain";
3
+ export type Terminal = {
4
+ tty: boolean;
5
+ ci: boolean;
6
+ plain: boolean;
7
+ env: Env;
8
+ };
9
+ export declare const chooseRenderer: ({ tty, ci, plain, env }: Terminal) => RendererKind;
@@ -0,0 +1,5 @@
1
+ export { chooseRenderer, type RendererKind, type Terminal } from "./choose.js";
2
+ export { type ColumnsOptions, columns, widthOf } from "./layout.js";
3
+ export { toPlain } from "./plain.js";
4
+ export { createPlainRenderer, createRenderer, type Renderer } from "./renderer.js";
5
+ export { type Line, type Span, span, type Tone, type View } from "./view.js";
@@ -0,0 +1,7 @@
1
+ import { type Span, type View } from "./view.js";
2
+ export declare const widthOf: (text: string) => number;
3
+ export type ColumnsOptions = {
4
+ indent?: number;
5
+ gap?: number;
6
+ };
7
+ export declare const columns: (rows: readonly (readonly Span[])[], { indent, gap }?: ColumnsOptions) => View;
@@ -0,0 +1,2 @@
1
+ import type { View } from "./view.js";
2
+ export declare const toPlain: (view: View) => string;
@@ -0,0 +1,10 @@
1
+ import type { RendererKind } from "./choose.js";
2
+ import type { View } from "./view.js";
3
+ export type Renderer = {
4
+ print: (view: View) => void;
5
+ live: (view: View | undefined) => void;
6
+ keys: (onKey: ((key: string) => void) | undefined) => void;
7
+ close: () => Promise<void>;
8
+ };
9
+ export declare const createPlainRenderer: (write: (text: string) => void) => Renderer;
10
+ export declare const createRenderer: (kind: RendererKind, stdout: NodeJS.WriteStream) => Promise<Renderer>;
@@ -0,0 +1,8 @@
1
+ export type Tone = "plain" | "strong" | "accent" | "success" | "failure" | "warning" | "muted";
2
+ export type Span = {
3
+ readonly text: string;
4
+ readonly tone: Tone;
5
+ };
6
+ export type Line = readonly Span[];
7
+ export type View = readonly Line[];
8
+ export declare const span: (text: string, tone?: Tone) => Span;
@@ -0,0 +1 @@
1
+ export { fewestToProve, type Interval, type Judgement, judge, type Threshold, type Verdict, wilson, } from "./wilson.js";
@@ -0,0 +1,20 @@
1
+ export type Interval = {
2
+ rate: number;
3
+ low: number;
4
+ high: number;
5
+ };
6
+ export declare const wilson: (successes: number, samples: number) => Interval;
7
+ export type Threshold = {
8
+ min: number;
9
+ } | {
10
+ max: number;
11
+ };
12
+ export type Verdict = "passed" | "failed" | "inconclusive";
13
+ export type Judgement = Interval & {
14
+ successes: number;
15
+ samples: number;
16
+ verdict: Verdict;
17
+ needed?: number;
18
+ };
19
+ export declare const judge: (successes: number, samples: number, threshold: Threshold) => Judgement;
20
+ export declare const fewestToProve: (threshold: Threshold) => number;
@@ -0,0 +1,25 @@
1
+ import type { TokenCounter } from "../count.js";
2
+ import { type ContentClass } from "./classify.js";
3
+ export type ClassFactor = {
4
+ factor: number;
5
+ low: number;
6
+ high: number;
7
+ pieces: number;
8
+ };
9
+ export type Calibration = {
10
+ status: "unmeasured";
11
+ } | {
12
+ status: "measured";
13
+ provider: string;
14
+ model: string;
15
+ date: string;
16
+ ctxray: string;
17
+ classes: Record<ContentClass, ClassFactor>;
18
+ };
19
+ export type Measured = {
20
+ class: ContentClass;
21
+ local: number;
22
+ exact: number;
23
+ };
24
+ export declare const factorsOf: (measured: readonly Measured[]) => Record<ContentClass, ClassFactor>;
25
+ export declare const calibratedCounter: (base: TokenCounter, calibration: Calibration) => TokenCounter | undefined;
@@ -0,0 +1,3 @@
1
+ export declare const CONTENT_CLASSES: readonly ["prose", "nonLatin", "code", "json", "metadata"];
2
+ export type ContentClass = (typeof CONTENT_CLASSES)[number];
3
+ export declare const classify: (text: string) => ContentClass;
@@ -0,0 +1,9 @@
1
+ import type { Calibration } from "./calibration.js";
2
+ import type { ContentClass } from "./classify.js";
3
+ export { type Calibration, type ClassFactor, calibratedCounter, factorsOf, type Measured } from "./calibration.js";
4
+ export { CONTENT_CLASSES, type ContentClass, classify } from "./classify.js";
5
+ export declare const CORPUS: {
6
+ class: ContentClass;
7
+ text: string;
8
+ }[];
9
+ export declare const ANTHROPIC_CALIBRATION: Calibration;
@@ -0,0 +1,10 @@
1
+ export declare const LOCAL_METHOD = "local:o200k_base";
2
+ export declare const GEMMA_METHOD = "local:gemma4";
3
+ export declare const countTokens: (text: string) => number;
4
+ export type TokenCounter = {
5
+ method: string;
6
+ count: (text: string) => number;
7
+ };
8
+ export type ModelFamily = "google" | "anthropic" | "other";
9
+ export declare const isCalibrated: (family: ModelFamily) => boolean;
10
+ export declare const counterFor: (family: ModelFamily) => TokenCounter;
@@ -0,0 +1,2 @@
1
+ export { ANTHROPIC_CALIBRATION, type Calibration, CONTENT_CLASSES, CORPUS, type ContentClass, classify, factorsOf, } from "./calibration/index.js";
2
+ export { counterFor, countTokens, GEMMA_METHOD, isCalibrated, LOCAL_METHOD, type ModelFamily, type TokenCounter, } from "./count.js";