@cruxy/cli 1.0.2 → 1.0.4

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 (245) hide show
  1. package/dist/agent/loop.js +3 -0
  2. package/dist/agent/session.js +2 -1
  3. package/dist/theme/tokens.js +3 -0
  4. package/dist/usage/collect.js +41 -2
  5. package/dist/usage/index.js +1 -1
  6. package/dist/usage/summary.js +19 -0
  7. package/dist/usage/types.js +9 -0
  8. package/package.json +1 -1
  9. package/dist/agent/budget.d.ts +0 -52
  10. package/dist/agent/index.d.ts +0 -3
  11. package/dist/agent/loop.d.ts +0 -159
  12. package/dist/agent/prompts.d.ts +0 -69
  13. package/dist/agent/session.d.ts +0 -212
  14. package/dist/approval/classify.d.ts +0 -18
  15. package/dist/approval/index.d.ts +0 -6
  16. package/dist/approval/mutex.d.ts +0 -45
  17. package/dist/approval/policy.d.ts +0 -43
  18. package/dist/approval/prompt.d.ts +0 -48
  19. package/dist/approval/service.d.ts +0 -36
  20. package/dist/approval/types.d.ts +0 -82
  21. package/dist/brand/index.d.ts +0 -1
  22. package/dist/brand/voice.d.ts +0 -94
  23. package/dist/checkpoint/capture.d.ts +0 -17
  24. package/dist/checkpoint/gate-hook.d.ts +0 -28
  25. package/dist/checkpoint/gate.d.ts +0 -71
  26. package/dist/checkpoint/git-store.d.ts +0 -61
  27. package/dist/checkpoint/index.d.ts +0 -10
  28. package/dist/checkpoint/restore.d.ts +0 -23
  29. package/dist/checkpoint/service.d.ts +0 -89
  30. package/dist/checkpoint/set-rollback.d.ts +0 -51
  31. package/dist/checkpoint/set.d.ts +0 -44
  32. package/dist/checkpoint/shadow-store.d.ts +0 -23
  33. package/dist/checkpoint/types.d.ts +0 -164
  34. package/dist/cli/commands/checkpoint.d.ts +0 -7
  35. package/dist/cli/commands/config.d.ts +0 -2
  36. package/dist/cli/commands/hooks.d.ts +0 -8
  37. package/dist/cli/commands/index.d.ts +0 -7
  38. package/dist/cli/commands/init.d.ts +0 -7
  39. package/dist/cli/commands/login.d.ts +0 -8
  40. package/dist/cli/commands/mcp.d.ts +0 -9
  41. package/dist/cli/commands/memory.d.ts +0 -8
  42. package/dist/cli/commands/pr.d.ts +0 -8
  43. package/dist/cli/commands/rollback.d.ts +0 -18
  44. package/dist/cli/commands/run.d.ts +0 -2
  45. package/dist/cli/commands/skills.d.ts +0 -8
  46. package/dist/cli/commands/test.d.ts +0 -9
  47. package/dist/cli/commands/usage.d.ts +0 -9
  48. package/dist/cli/onboard.d.ts +0 -25
  49. package/dist/cli/program.d.ts +0 -2
  50. package/dist/cli/repl.d.ts +0 -27
  51. package/dist/cli/session-factory.d.ts +0 -42
  52. package/dist/cli/stream-print.d.ts +0 -14
  53. package/dist/components/autocomplete.d.ts +0 -32
  54. package/dist/components/frame.d.ts +0 -28
  55. package/dist/components/fuzzy.d.ts +0 -61
  56. package/dist/components/index.d.ts +0 -6
  57. package/dist/components/input.d.ts +0 -78
  58. package/dist/components/keys.d.ts +0 -48
  59. package/dist/components/select.d.ts +0 -28
  60. package/dist/config/credentials.d.ts +0 -18
  61. package/dist/config/index.d.ts +0 -5
  62. package/dist/config/manager.d.ts +0 -39
  63. package/dist/config/owner-only.d.ts +0 -19
  64. package/dist/config/paths.d.ts +0 -9
  65. package/dist/config/project.d.ts +0 -10
  66. package/dist/config/schema.d.ts +0 -2143
  67. package/dist/constants.d.ts +0 -65
  68. package/dist/errors/boundary.d.ts +0 -43
  69. package/dist/errors/constructors.d.ts +0 -411
  70. package/dist/errors/format.d.ts +0 -31
  71. package/dist/errors/index.d.ts +0 -4
  72. package/dist/errors/types.d.ts +0 -270
  73. package/dist/hooks/config.d.ts +0 -21
  74. package/dist/hooks/index.d.ts +0 -7
  75. package/dist/hooks/router.d.ts +0 -58
  76. package/dist/hooks/runner.d.ts +0 -88
  77. package/dist/hooks/service.d.ts +0 -38
  78. package/dist/hooks/slash.d.ts +0 -48
  79. package/dist/hooks/trust.d.ts +0 -46
  80. package/dist/hooks/types.d.ts +0 -147
  81. package/dist/index.d.ts +0 -2
  82. package/dist/indexing/chunker.d.ts +0 -28
  83. package/dist/indexing/embedder.d.ts +0 -98
  84. package/dist/indexing/index.d.ts +0 -9
  85. package/dist/indexing/indexer.d.ts +0 -45
  86. package/dist/indexing/retriever.d.ts +0 -61
  87. package/dist/indexing/service.d.ts +0 -49
  88. package/dist/indexing/store.d.ts +0 -103
  89. package/dist/indexing/types.d.ts +0 -78
  90. package/dist/indexing/util.d.ts +0 -34
  91. package/dist/indexing/walker.d.ts +0 -53
  92. package/dist/jobs/approval-queue.d.ts +0 -85
  93. package/dist/jobs/dispatch-tool.d.ts +0 -34
  94. package/dist/jobs/index.d.ts +0 -6
  95. package/dist/jobs/log-buffer.d.ts +0 -31
  96. package/dist/jobs/log-renderer.d.ts +0 -32
  97. package/dist/jobs/manager.d.ts +0 -139
  98. package/dist/jobs/types.d.ts +0 -81
  99. package/dist/lsp/client.d.ts +0 -25
  100. package/dist/lsp/index.d.ts +0 -8
  101. package/dist/lsp/pool.d.ts +0 -48
  102. package/dist/lsp/registry.d.ts +0 -38
  103. package/dist/lsp/server.d.ts +0 -48
  104. package/dist/lsp/service.d.ts +0 -44
  105. package/dist/lsp/tools/common.d.ts +0 -50
  106. package/dist/lsp/tools/find-definition.d.ts +0 -23
  107. package/dist/lsp/tools/find-references.d.ts +0 -23
  108. package/dist/lsp/tools/get-diagnostics.d.ts +0 -17
  109. package/dist/lsp/tools/hover.d.ts +0 -23
  110. package/dist/lsp/tools/index.d.ts +0 -4
  111. package/dist/lsp/transport.d.ts +0 -39
  112. package/dist/lsp/types.d.ts +0 -107
  113. package/dist/mcp/adapter.d.ts +0 -44
  114. package/dist/mcp/bounds.d.ts +0 -35
  115. package/dist/mcp/client.d.ts +0 -19
  116. package/dist/mcp/demarcate.d.ts +0 -12
  117. package/dist/mcp/http-transport.d.ts +0 -89
  118. package/dist/mcp/index.d.ts +0 -12
  119. package/dist/mcp/service.d.ts +0 -71
  120. package/dist/mcp/sibling-banner.d.ts +0 -25
  121. package/dist/mcp/transport.d.ts +0 -30
  122. package/dist/mcp/trust-gate.d.ts +0 -59
  123. package/dist/mcp/trust.d.ts +0 -62
  124. package/dist/mcp/types.d.ts +0 -62
  125. package/dist/mcp/url-guard.d.ts +0 -48
  126. package/dist/memory/index.d.ts +0 -7
  127. package/dist/memory/recall.d.ts +0 -56
  128. package/dist/memory/remember-tool.d.ts +0 -28
  129. package/dist/memory/secrets.d.ts +0 -29
  130. package/dist/memory/service.d.ts +0 -92
  131. package/dist/memory/store.d.ts +0 -32
  132. package/dist/memory/trust.d.ts +0 -52
  133. package/dist/memory/types.d.ts +0 -101
  134. package/dist/net/ip-guard.d.ts +0 -55
  135. package/dist/onboarding/detect.d.ts +0 -26
  136. package/dist/onboarding/flow.d.ts +0 -28
  137. package/dist/onboarding/index.d.ts +0 -5
  138. package/dist/onboarding/io.d.ts +0 -9
  139. package/dist/onboarding/steps.d.ts +0 -17
  140. package/dist/onboarding/types.d.ts +0 -81
  141. package/dist/plan/approve.d.ts +0 -16
  142. package/dist/plan/execute.d.ts +0 -28
  143. package/dist/plan/index.d.ts +0 -7
  144. package/dist/plan/policy.d.ts +0 -26
  145. package/dist/plan/render.d.ts +0 -5
  146. package/dist/plan/service.d.ts +0 -58
  147. package/dist/plan/submit-plan.d.ts +0 -33
  148. package/dist/plan/types.d.ts +0 -60
  149. package/dist/render/capabilities.d.ts +0 -31
  150. package/dist/render/diff.d.ts +0 -18
  151. package/dist/render/highlight.d.ts +0 -47
  152. package/dist/render/index.d.ts +0 -22
  153. package/dist/render/layout.d.ts +0 -59
  154. package/dist/render/motion.d.ts +0 -76
  155. package/dist/render/plain-renderer.d.ts +0 -39
  156. package/dist/render/resize.d.ts +0 -36
  157. package/dist/render/screen-reader-renderer.d.ts +0 -45
  158. package/dist/render/state.d.ts +0 -49
  159. package/dist/render/tty-renderer.d.ts +0 -106
  160. package/dist/render/types.d.ts +0 -201
  161. package/dist/routing/index.d.ts +0 -2
  162. package/dist/routing/resolve.d.ts +0 -17
  163. package/dist/routing/router.d.ts +0 -47
  164. package/dist/routing/types.d.ts +0 -42
  165. package/dist/sandbox/detect.d.ts +0 -22
  166. package/dist/sandbox/docker-runtime.d.ts +0 -32
  167. package/dist/sandbox/index.d.ts +0 -7
  168. package/dist/sandbox/policy.d.ts +0 -26
  169. package/dist/sandbox/service.d.ts +0 -64
  170. package/dist/sandbox/types.d.ts +0 -123
  171. package/dist/skills/index.d.ts +0 -4
  172. package/dist/skills/loader.d.ts +0 -43
  173. package/dist/skills/parser.d.ts +0 -31
  174. package/dist/skills/service.d.ts +0 -41
  175. package/dist/skills/types.d.ts +0 -94
  176. package/dist/subagent/index.d.ts +0 -5
  177. package/dist/subagent/orchestrator.d.ts +0 -169
  178. package/dist/subagent/registry-scope.d.ts +0 -41
  179. package/dist/subagent/semaphore.d.ts +0 -56
  180. package/dist/subagent/spawn-tool.d.ts +0 -86
  181. package/dist/subagent/types.d.ts +0 -65
  182. package/dist/testing/detect.d.ts +0 -3
  183. package/dist/testing/index.d.ts +0 -5
  184. package/dist/testing/parse.d.ts +0 -33
  185. package/dist/testing/run-tests-tool.d.ts +0 -64
  186. package/dist/testing/runner.d.ts +0 -26
  187. package/dist/testing/sandbox-runner.d.ts +0 -16
  188. package/dist/testing/types.d.ts +0 -66
  189. package/dist/theme/index.d.ts +0 -2
  190. package/dist/theme/resolve.d.ts +0 -43
  191. package/dist/theme/tokens.d.ts +0 -119
  192. package/dist/tools/create-pull-request.d.ts +0 -27
  193. package/dist/tools/file/apply-patch.d.ts +0 -94
  194. package/dist/tools/file/edit-file.d.ts +0 -12
  195. package/dist/tools/file/glob.d.ts +0 -17
  196. package/dist/tools/file/grep-files.d.ts +0 -43
  197. package/dist/tools/file/index.d.ts +0 -7
  198. package/dist/tools/file/match.d.ts +0 -43
  199. package/dist/tools/file/paths.d.ts +0 -160
  200. package/dist/tools/file/read-file.d.ts +0 -8
  201. package/dist/tools/file/write-file.d.ts +0 -10
  202. package/dist/tools/git-status.d.ts +0 -15
  203. package/dist/tools/index.d.ts +0 -9
  204. package/dist/tools/list-files.d.ts +0 -13
  205. package/dist/tools/list-skills.d.ts +0 -9
  206. package/dist/tools/load-skill.d.ts +0 -21
  207. package/dist/tools/registry.d.ts +0 -23
  208. package/dist/tools/search-codebase.d.ts +0 -35
  209. package/dist/tools/shell/exec.d.ts +0 -53
  210. package/dist/tools/shell/index.d.ts +0 -1
  211. package/dist/tools/shell/resolve-shell.d.ts +0 -81
  212. package/dist/tools/shell/run-command.d.ts +0 -14
  213. package/dist/tools/types.d.ts +0 -257
  214. package/dist/usage/collect.d.ts +0 -40
  215. package/dist/usage/cost.d.ts +0 -19
  216. package/dist/usage/index.d.ts +0 -15
  217. package/dist/usage/store.d.ts +0 -37
  218. package/dist/usage/summary.d.ts +0 -32
  219. package/dist/usage/types.d.ts +0 -220
  220. package/dist/utils/child-tree.d.ts +0 -33
  221. package/dist/utils/git.d.ts +0 -17
  222. package/dist/utils/logger.d.ts +0 -18
  223. package/dist/utils/process-tree.d.ts +0 -16
  224. package/dist/vcs/auth.d.ts +0 -22
  225. package/dist/vcs/generate.d.ts +0 -74
  226. package/dist/vcs/git.d.ts +0 -60
  227. package/dist/vcs/github.d.ts +0 -50
  228. package/dist/vcs/guidance.d.ts +0 -20
  229. package/dist/vcs/index.d.ts +0 -7
  230. package/dist/vcs/service.d.ts +0 -61
  231. package/dist/vcs/types.d.ts +0 -73
  232. package/dist/web/demarcate.d.ts +0 -13
  233. package/dist/web/fetch.d.ts +0 -11
  234. package/dist/web/index.d.ts +0 -7
  235. package/dist/web/provider.d.ts +0 -29
  236. package/dist/web/search.d.ts +0 -17
  237. package/dist/web/ssrf.d.ts +0 -41
  238. package/dist/web/tools.d.ts +0 -20
  239. package/dist/web/types.d.ts +0 -64
  240. package/dist/workspace/add-root.d.ts +0 -27
  241. package/dist/workspace/index.d.ts +0 -6
  242. package/dist/workspace/resolve.d.ts +0 -54
  243. package/dist/workspace/select.d.ts +0 -41
  244. package/dist/workspace/types.d.ts +0 -30
  245. package/dist/workspace/workspace.d.ts +0 -61
@@ -1,44 +0,0 @@
1
- import type { CruxyConfig } from "../config/index.js";
2
- import type { BinaryPresent, LspDiagnostic, LspHover, LspLocation, TransportFactory } from "./types.js";
3
- /** Logger surface the service reports through (matches the indexing service). */
4
- interface ServiceLogger {
5
- debug(message: string): void;
6
- info(message: string): void;
7
- warn(message: string): void;
8
- }
9
- /**
10
- * A ready-to-use LSP facade for one project root (C.12): it owns the registry,
11
- * pool, and client, exposes the four normalized queries, and shuts the whole
12
- * server pool down on `close()`. Build one with {@link getLspService}, cached
13
- * per cwd so servers are spawned at most once per project per process.
14
- */
15
- export interface LspService {
16
- definition(file: string, line: number, col: number): Promise<LspLocation[]>;
17
- references(file: string, line: number, col: number): Promise<LspLocation[]>;
18
- hover(file: string, line: number, col: number): Promise<LspHover | null>;
19
- diagnostics(file: string): Promise<LspDiagnostic[]>;
20
- /** Shut down every managed server (session end / process teardown). */
21
- close(): Promise<void>;
22
- }
23
- /**
24
- * Explicit dependency overrides, for tests only. Production callers (the LSP
25
- * tools) never pass these, so they always go through the real stdio transport
26
- * and PATH-based binary detection.
27
- */
28
- export interface LspServiceDeps {
29
- /** Substitute the JSON-RPC transport (a fake stdio peer — no real binary). */
30
- transportFactory?: TransportFactory;
31
- /** Substitute PATH-based binary detection (force present/absent). */
32
- binaryPresent?: BinaryPresent;
33
- /** Substitute the idle clock. */
34
- now?: () => number;
35
- }
36
- /**
37
- * Get (or build) the {@link LspService} for a project root, cached per resolved
38
- * cwd so the pool is created at most once per process. No server spawns until
39
- * the first query. `deps` is for explicit test injection only.
40
- */
41
- export declare function getLspService(cwd: string, config: CruxyConfig, logger: ServiceLogger, deps?: LspServiceDeps): LspService;
42
- /** Drop all cached services (shutting them down). For tests and process teardown. */
43
- export declare function resetLspServices(): Promise<void>;
44
- export {};
@@ -1,50 +0,0 @@
1
- import type { ToolContext, ToolResult } from "../../tools/types.js";
2
- import type { DeclaredRoot } from "../../workspace/index.js";
3
- import { type LspService } from "../service.js";
4
- import type { LspLocation } from "../types.js";
5
- /**
6
- * The root a query ran against, threaded to the tool so it can label locations by
7
- * their source root and — for references — name the per-root limitation (C.26).
8
- */
9
- export interface LspRootContext {
10
- /** The declared root whose language-server pool answered the query. */
11
- root: DeclaredRoot;
12
- /** Whether this is a genuine multi-root session (labels render only then). */
13
- isMultiRoot: boolean;
14
- }
15
- /**
16
- * The shared spine of every LSP tool (C.12): enforce the master switch, resolve
17
- * the target file to the ONE declared root that contains it, prove it exists, get
18
- * THAT root's language-server pool, and run `query`. Read-only throughout — no
19
- * `ctx.requestApproval`, so these bypass the U.3 gate exactly like `search_codebase`
20
- * and `grep_files`.
21
- *
22
- * Multi-repo (C.26, Funnel A→pool): the file is resolved through the shared
23
- * `resolveToolPath`, so it commits to exactly one root, and the pool is keyed by
24
- * THAT root's `absPath` (`getLspService` caches per resolved cwd → a per-root map
25
- * for free). A file in root B is answered by B's server, never A's — the
26
- * `(file → root)` selection and the `(root → pool)` key are the same value.
27
- *
28
- * Errors are surfaced as `{ ok:false }` text the agent can act on: a coded LSP
29
- * failure (no server / timeout / crash) is rendered WITH its next step, so the
30
- * agent can reroute (e.g. to grep) or the user can install the server. A genuine
31
- * empty answer never reaches here as an error — `query` returns it as `ok:true`.
32
- */
33
- export declare function runLspTool(ctx: ToolContext, file: string, query: (service: LspService, absFile: string, rc: LspRootContext) => Promise<ToolResult>): Promise<ToolResult>;
34
- /**
35
- * A note stating that a per-root language server only sees its own root, so
36
- * references/definitions in sibling roots are NOT searched (⚖︎JC-7) — returned only
37
- * in a multi-root session, so a references list is never read as complete when it
38
- * silently could not span roots. Empty string in single-root (byte-identical).
39
- */
40
- export declare function crossRootNote(rc: LspRootContext): string;
41
- /**
42
- * Render up to `max` locations as `path:line:col-endLine:endCol`, one per line,
43
- * with a trailing "N more" note when capped — the same bounded-honest pattern as
44
- * grep_files and search_codebase (never silently drop the overflow). In a
45
- * multi-root session each path is labelled `‹root› ▸ path` (the query ran against
46
- * one root, so every location carries that root's label).
47
- */
48
- export declare function formatLocations(locations: LspLocation[], max: number, rc: LspRootContext): string;
49
- /** Relative label for a validated absolute path, for tool messages. */
50
- export declare function relLabel(cwd: string, absFile: string): string;
@@ -1,23 +0,0 @@
1
- import { z } from "zod";
2
- import type { Tool } from "../../tools/types.js";
3
- declare const parameters: z.ZodObject<{
4
- file: z.ZodString;
5
- line: z.ZodNumber;
6
- column: z.ZodNumber;
7
- }, "strip", z.ZodTypeAny, {
8
- file: string;
9
- line: number;
10
- column: number;
11
- }, {
12
- file: string;
13
- line: number;
14
- column: number;
15
- }>;
16
- /**
17
- * LSP go-to-definition (C.12). Read-only — no approval, like search_codebase.
18
- * Returns the definition site(s) as `path:line:col-endLine:endCol`. A missing
19
- * language server is a coded, actionable error (distinct from "no definition
20
- * found", which is an honest empty result).
21
- */
22
- export declare const findDefinitionTool: Tool<typeof parameters>;
23
- export {};
@@ -1,23 +0,0 @@
1
- import { z } from "zod";
2
- import type { Tool } from "../../tools/types.js";
3
- declare const parameters: z.ZodObject<{
4
- file: z.ZodString;
5
- line: z.ZodNumber;
6
- column: z.ZodNumber;
7
- }, "strip", z.ZodTypeAny, {
8
- file: string;
9
- line: number;
10
- column: number;
11
- }, {
12
- file: string;
13
- line: number;
14
- column: number;
15
- }>;
16
- /**
17
- * LSP find-references (C.12). Read-only — no approval. Returns every use of the
18
- * symbol (declaration included) as `path:line:col-endLine:endCol`, capped to
19
- * `lsp.maxResults` with an "N more" note so a hot symbol can't flood the output.
20
- * A missing server is a coded error, distinct from an honest "no references".
21
- */
22
- export declare const findReferencesTool: Tool<typeof parameters>;
23
- export {};
@@ -1,17 +0,0 @@
1
- import { z } from "zod";
2
- import type { Tool } from "../../tools/types.js";
3
- declare const parameters: z.ZodObject<{
4
- file: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- file: string;
7
- }, {
8
- file: string;
9
- }>;
10
- /**
11
- * LSP diagnostics (C.12): the language server's errors/warnings for a file.
12
- * Read-only — no approval. Returns each diagnostic as
13
- * `severity path:line:col message [source]`, capped to `lsp.maxResults`. A
14
- * missing server is a coded error; a clean file is an honest empty result.
15
- */
16
- export declare const getDiagnosticsTool: Tool<typeof parameters>;
17
- export {};
@@ -1,23 +0,0 @@
1
- import { z } from "zod";
2
- import type { Tool } from "../../tools/types.js";
3
- declare const parameters: z.ZodObject<{
4
- file: z.ZodString;
5
- line: z.ZodNumber;
6
- column: z.ZodNumber;
7
- }, "strip", z.ZodTypeAny, {
8
- file: string;
9
- line: number;
10
- column: number;
11
- }, {
12
- file: string;
13
- line: number;
14
- column: number;
15
- }>;
16
- /**
17
- * LSP hover (C.12): type signature / documentation for the symbol at a position.
18
- * Read-only — no approval. Returns the server's hover text (markup flattened to
19
- * plain text). A missing server is a coded error; a symbol with no hover info is
20
- * an honest empty result.
21
- */
22
- export declare const hoverTool: Tool<typeof parameters>;
23
- export {};
@@ -1,4 +0,0 @@
1
- export { findDefinitionTool } from "./find-definition.js";
2
- export { findReferencesTool } from "./find-references.js";
3
- export { getDiagnosticsTool } from "./get-diagnostics.js";
4
- export { hoverTool } from "./hover.js";
@@ -1,39 +0,0 @@
1
- import { killTree, killTrackedTrees, trackedTreeCount } from "../utils/child-tree.js";
2
- import type { LspTransport, ServerSpec } from "./types.js";
3
- export { killTree };
4
- /** @deprecated Use the shared backstop; kept for LSP tests. */
5
- export declare const killTrackedServers: typeof killTrackedTrees;
6
- /** @deprecated Use the shared backstop; kept for LSP tests. */
7
- export declare const trackedServerCount: typeof trackedTreeCount;
8
- export declare class StdioTransport implements LspTransport {
9
- private readonly child;
10
- private nextId;
11
- private readonly pending;
12
- private readonly notificationHandlers;
13
- private crashHandler;
14
- /** stdout parse buffer (header + body may arrive across chunks). */
15
- private buffer;
16
- private disposed;
17
- /** Deregisters this process from the process-exit kill-tree backstop. */
18
- private readonly unregisterCleanup;
19
- constructor(spec: ServerSpec, root: string);
20
- request(method: string, params: unknown, timeoutMs: number): Promise<unknown>;
21
- notify(method: string, params: unknown): void;
22
- onNotification(method: string, handler: (params: unknown) => void): void;
23
- onCrash(handler: (info: {
24
- code: number | null;
25
- signal: string | null;
26
- }) => void): void;
27
- dispose(force?: boolean): Promise<void>;
28
- private send;
29
- private onStdout;
30
- private dispatch;
31
- private onExit;
32
- private onSpawnError;
33
- }
34
- /** A per-request timeout, distinguishable from an ordinary LSP error response. */
35
- export declare class TransportTimeoutError extends Error {
36
- readonly method: string;
37
- readonly timeoutMs: number;
38
- constructor(method: string, timeoutMs: number);
39
- }
@@ -1,107 +0,0 @@
1
- import type { LspConfig } from "../config/index.js";
2
- /**
3
- * Per-language LSP integration (C.12) — the shared vocabulary. Results here are
4
- * NORMALIZED (1-based lines/columns, project-relative paths, plain severities):
5
- * the LSP wire format's 0-based positions and `file://` URIs are converted at
6
- * the edge (`server.ts`) so nothing downstream speaks raw LSP.
7
- */
8
- export type { LspConfig };
9
- /**
10
- * A source range, normalized to 1-based lines and columns (LSP is 0-based; we
11
- * add 1 at the boundary). `path` is project-relative for display.
12
- */
13
- export interface LspLocation {
14
- /** Project-relative file path. */
15
- path: string;
16
- /** 1-based start line. */
17
- startLine: number;
18
- /** 1-based start column. */
19
- startCol: number;
20
- /** 1-based end line. */
21
- endLine: number;
22
- /** 1-based end column. */
23
- endCol: number;
24
- }
25
- /** A normalized diagnostic (severity mapped off the LSP 1–4 integer scale). */
26
- export interface LspDiagnostic {
27
- /** Project-relative file path. */
28
- path: string;
29
- /** Where the diagnostic applies (1-based). */
30
- range: LspLocation;
31
- severity: "error" | "warning" | "info" | "hint";
32
- message: string;
33
- /** The producing tool, when the server reports it (e.g. "tsc", "gopls"). */
34
- source?: string;
35
- }
36
- /** A normalized hover result — markdown/markup flattened to plain text. */
37
- export interface LspHover {
38
- contents: string;
39
- /** The symbol range the hover describes, when the server reports it. */
40
- range?: LspLocation;
41
- }
42
- /**
43
- * A single, initialized language server (≈ one live child process). Queries are
44
- * absolute-path in / normalized-out; the client relativizes paths against the
45
- * workspace root. A method resolving to `[]`/`null` is an honest "no result" —
46
- * unavailability is signalled by a thrown coded error from the pool, never here.
47
- */
48
- export interface LanguageServer {
49
- readonly language: string;
50
- /** True until the process exits (crash detection flips this to false). */
51
- readonly alive: boolean;
52
- definition(file: string, line: number, col: number): Promise<LspLocation[]>;
53
- references(file: string, line: number, col: number): Promise<LspLocation[]>;
54
- diagnostics(file: string): Promise<LspDiagnostic[]>;
55
- hover(file: string, line: number, col: number): Promise<LspHover | null>;
56
- /** LSP `shutdown` → `exit`, then force-kill the process group after a grace. */
57
- shutdown(force?: boolean): Promise<void>;
58
- }
59
- /** How to launch one language's server, resolved from config ∪ the default table. */
60
- export interface ServerSpec {
61
- language: string;
62
- /** Executable name or absolute path. */
63
- command: string;
64
- /** Argument vector (e.g. `["--stdio"]`). */
65
- args: string[];
66
- /** Concrete install instruction, surfaced when the binary is missing. */
67
- installHint?: string;
68
- }
69
- /**
70
- * The registry's answer for a language. Availability is EXPLICIT: an
71
- * unavailable server carries the reason so the caller raises a coded,
72
- * actionable error rather than silently returning nothing.
73
- */
74
- export type ServerResolution = {
75
- available: true;
76
- spec: ServerSpec;
77
- } | {
78
- available: false;
79
- language: string;
80
- spec: ServerSpec | null;
81
- reason: "no-spec" | "binary-missing";
82
- };
83
- /**
84
- * The one seam tests replace: a live JSON-RPC peer over the server's stdio. A
85
- * fake implementation lets the whole stack run with NO real language-server
86
- * binary (mirroring `RecordingRuntime` for the sandbox).
87
- */
88
- export interface LspTransport {
89
- /** Send a request and await its response, rejecting after `timeoutMs`. */
90
- request(method: string, params: unknown, timeoutMs: number): Promise<unknown>;
91
- /** Fire-and-forget notification (no response expected). */
92
- notify(method: string, params: unknown): void;
93
- /** Register a handler for a server→client notification (e.g. diagnostics). */
94
- onNotification(method: string, handler: (params: unknown) => void): void;
95
- /** Register a one-shot crash callback (process exited unexpectedly). */
96
- onCrash(handler: (info: {
97
- code: number | null;
98
- signal: string | null;
99
- }) => void): void;
100
- /** LSP graceful path already sent by the caller; drop the transport,
101
- * force-killing the process group after the grace when `force` is set. */
102
- dispose(force?: boolean): Promise<void>;
103
- }
104
- /** Builds a transport for a resolved spec, rooted at `root`. Injectable in tests. */
105
- export type TransportFactory = (spec: ServerSpec, root: string) => LspTransport;
106
- /** Predicate: is `command` runnable (on PATH, or an existing executable path)? */
107
- export type BinaryPresent = (command: string) => boolean;
@@ -1,44 +0,0 @@
1
- import type { Tool } from "../tools/types.js";
2
- import { type McpBounds } from "./bounds.js";
3
- import type { McpCallResult, RawMcpTool } from "./types.js";
4
- /**
5
- * THE SINGLE SEAM (C.27). `mcpToolsFrom` is the ONE and ONLY place an MCP server
6
- * becomes an agent {@link Tool}. Nothing else in the codebase constructs an
7
- * MCP-backed tool, so every security property is enforced here, by construction:
8
- *
9
- * - GATE. Every produced tool's `execute` calls `ctx.requestApproval({kind:"mcp",
10
- * …})` BEFORE it ever calls the server. A rejection returns the feedback as the
11
- * tool result and `tools/call` never fires. The action is classified
12
- * `destructive` and the classifier never reads the server's `readOnlyHint`
13
- * (which this adapter deliberately does not even forward) — a server cannot
14
- * self-declare its tool safe. A session grant is keyed on the exact server+tool
15
- * pair, so approving one tool never covers another.
16
- * - DEMARCATE + GAG. Both the advertised description and every result are wrapped
17
- * as untrusted external data with upstream model names scrubbed
18
- * ({@link demarcateDescription} / {@link demarcateResult}) — the model never
19
- * sees a raw, un-boxed description or result.
20
- * - BOUNDS. The server's tool list is capped in count and per-tool size
21
- * ({@link boundToolList}); overflow is truncated with a visible note, never a
22
- * silent drop or an unbounded context blow-up.
23
- * - NON-PERSISTENCE. `execute` returns a plain {@link ToolResult}; it writes to
24
- * no store. Results live only in the in-memory conversation (asserted by test).
25
- *
26
- * Trust is enforced UPSTREAM (the service never calls this until the server is
27
- * trusted), so reaching this function already means "the user accepted running
28
- * this server's code unsandboxed".
29
- */
30
- export interface McpToolSource {
31
- /** The configured server id (the tool-name prefix and gate key). */
32
- server: string;
33
- /** Tools exactly as the server advertised them (untrusted). */
34
- tools: readonly RawMcpTool[];
35
- /** Invoke a tool on the server by its ORIGINAL name. Adapter-internal only. */
36
- call(toolName: string, args: unknown): Promise<McpCallResult>;
37
- /** Size/count caps for the advertised list. */
38
- bounds: McpBounds;
39
- /** Where the visible "N tools dropped" note is surfaced. */
40
- logger?: {
41
- warn(message: string): void;
42
- };
43
- }
44
- export declare function mcpToolsFrom(source: McpToolSource): Tool[];
@@ -1,35 +0,0 @@
1
- import type { RawMcpTool } from "./types.js";
2
- /**
3
- * Tool-list bounds (C.27). A malicious or buggy MCP server can advertise
4
- * thousands of tools with enormous descriptions and schemas — a context-budget
5
- * DoS. So the list a server returns is bounded exactly like `find_references`'
6
- * output: capped in count and per-tool size, and every truncation is surfaced as
7
- * a VISIBLE note (never a silent drop, never an unbounded blow-up). The caps are
8
- * config-driven (`mcp.maxToolsPerServer` / `maxDescriptionChars` / `maxSchemaBytes`).
9
- */
10
- export interface McpBounds {
11
- maxTools: number;
12
- maxDescriptionChars: number;
13
- maxSchemaBytes: number;
14
- }
15
- /** A single tool after bounding, carrying any truncation notes for the model. */
16
- export interface BoundedTool {
17
- name: string;
18
- description: string;
19
- inputSchema: Record<string, unknown>;
20
- /** Human notes about what was truncated on THIS tool (surfaced as data). */
21
- notes: string[];
22
- }
23
- export interface BoundedToolList {
24
- tools: BoundedTool[];
25
- /** How many tools were dropped because the server exceeded the count cap. */
26
- droppedCount: number;
27
- }
28
- /**
29
- * Apply the bounds to a raw `tools/list`. Over the count cap → keep the first N
30
- * (by advertised order) and report `droppedCount`. Per tool: an over-long
31
- * description is truncated with a marker; an over-size input schema is replaced
32
- * with a permissive `object` schema and a note (we never forward an unbounded
33
- * schema, but we also never claim the args are constrained when we dropped it).
34
- */
35
- export declare function boundToolList(tools: readonly RawMcpTool[], bounds: McpBounds): BoundedToolList;
@@ -1,19 +0,0 @@
1
- import type { McpCallResult, McpTransport, RawMcpTool } from "./types.js";
2
- export interface McpClientTimeouts {
3
- /** `initialize` + `tools/list` budget (connect-time). */
4
- startupTimeout: number;
5
- /** Per `tools/call` budget. */
6
- requestTimeout: number;
7
- }
8
- export declare class McpClient {
9
- private readonly transport;
10
- private readonly timeouts;
11
- constructor(transport: McpTransport, timeouts: McpClientTimeouts);
12
- /** Perform the MCP handshake: `initialize`, then the `initialized` notice. */
13
- initialize(): Promise<void>;
14
- /** List the server's tools. Malformed entries are dropped, not thrown on. */
15
- listTools(): Promise<RawMcpTool[]>;
16
- /** Call one tool. Normalizes content to flat text + the server's error flag. */
17
- callTool(name: string, args: unknown): Promise<McpCallResult>;
18
- dispose(force?: boolean): Promise<void>;
19
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Wrap a server-advertised tool description as untrusted data for the model. The
3
- * description is one of MCP's most direct injection surfaces (it is fed to the
4
- * model as the tool's own `description`), so it gets the same envelope as results.
5
- */
6
- export declare function demarcateDescription(server: string, tool: string, rawDescription: string): string;
7
- /**
8
- * Wrap a tool-call result as untrusted data for the model. Same discipline as
9
- * the description: the result is external content that may attempt injection, so
10
- * it is scrubbed, fence-neutralized, and clearly boxed as data.
11
- */
12
- export declare function demarcateResult(server: string, tool: string, rawResult: string): string;
@@ -1,89 +0,0 @@
1
- import { fetch as undiciFetch } from "undici";
2
- import type { McpTransport } from "./types.js";
3
- /**
4
- * JSON-RPC 2.0 over MCP's Streamable HTTP transport (C.27b) — the network sibling
5
- * of {@link ../mcp/transport McpStdioTransport}. It satisfies the SAME
6
- * {@link McpTransport} seam, so `McpClient`, the single adapter (`mcpToolsFrom`),
7
- * bounds, demarcation, gating, and non-persistence are all inherited UNCHANGED —
8
- * every C.27 security property holds over the wire by construction, and all the
9
- * network-specific hardening lives here, below the seam.
10
- *
11
- * Trust boundary (this is a remote endpoint, not a local process):
12
- * - PINNED CONNECTIONS. The connection is pinned (undici `Agent` + {@link pinnedLookup})
13
- * to the exact address set the SSRF guard already validated at trust time. The
14
- * transport itself does NO DNS resolution — it dials only the passed addresses,
15
- * so a DNS rebind cannot flip check→connect. The Host header / TLS SNI still
16
- * carry the original hostname, so certificate hostname validation is unaffected.
17
- * - HTTPS + CERT VALIDATION. TLS validation is undici's default and is NEVER
18
- * disabled — there is deliberately no skip-verify path (JC-E). `https` vs
19
- * loopback-`http` is enforced upstream by the url-guard.
20
- * - NO REDIRECTS. `maxRedirections: 0` and a manual 3xx check: an MCP RPC endpoint
21
- * has no legitimate reason to redirect, so a redirect is REFUSED (never re-pinned
22
- * and followed to a new, unvalidated host).
23
- * - NO SOCKET BEFORE TRUST (JC-C). The constructor opens no socket and resolves no
24
- * DNS; the first network I/O is the `initialize` POST, which the service issues
25
- * only after the trust gate passes.
26
- *
27
- * Inbound posture mirrors stdio: cruxy advertises NO capabilities (no sampling, no
28
- * roots, no elicitation), so it never solicits server→client requests; any that
29
- * arrive on a response stream are ignored, never acted on. This is a deliberate
30
- * SUBSET of Streamable HTTP — no standalone GET listening stream and no SSE
31
- * resumption — sufficient for request/response tool use and easy to reason about.
32
- */
33
- export interface McpHttpSpec {
34
- /** The server endpoint (already scheme/SSRF-validated by the url-guard). */
35
- url: string;
36
- /** Pre-validated address set to pin the connection to (never re-resolved here). */
37
- addresses: string[];
38
- /** `initialize` + `tools/list` budget, ms. */
39
- connectTimeout: number;
40
- /** Per `tools/call` budget, ms. */
41
- requestTimeout: number;
42
- /**
43
- * Resolved auth headers (C.27c), attached to every request to THIS pinned,
44
- * https endpoint (never on a redirect target, never over http). Empty/absent for
45
- * an unauthenticated server. Reserved framing headers here are ignored — a
46
- * credential can never rewrite content-type/accept/session framing.
47
- */
48
- authHeaders?: Record<string, string>;
49
- }
50
- /**
51
- * The endpoint rejected our credential (401/403) — C.27c. A DISTINCT type so the
52
- * service maps it to `CRUXY_E_MCP_AUTH` ("credential rejected") rather than the
53
- * generic connect failure. Carries only the status; the token never touches it.
54
- */
55
- export declare class McpHttpAuthError extends Error {
56
- readonly status: number;
57
- constructor(status: number);
58
- }
59
- /** Minimal fetch surface we depend on (injectable for tests). */
60
- type FetchLike = typeof undiciFetch;
61
- export declare class McpHttpTransport implements McpTransport {
62
- private readonly url;
63
- private readonly connectTimeout;
64
- private readonly requestTimeout;
65
- private readonly dispatcher;
66
- private readonly fetchImpl;
67
- /** Sanitized auth headers, sent ONLY over https to this pinned endpoint. */
68
- private readonly authHeaders;
69
- private nextId;
70
- private disposed;
71
- /** Streamable HTTP session id, captured from the `initialize` response. */
72
- private sessionId;
73
- private crashHandler;
74
- /** In-flight request aborts, so `dispose()` can cancel them. */
75
- private readonly inflight;
76
- constructor(spec: McpHttpSpec, fetchImpl?: FetchLike);
77
- /** Whether the `initialize` handshake budget or the per-call budget applies. */
78
- private budgetFor;
79
- request(method: string, params: unknown, timeoutMs: number): Promise<unknown>;
80
- notify(method: string, params: unknown): void;
81
- onCrash(handler: (info: {
82
- code: number | null;
83
- signal: string | null;
84
- }) => void): void;
85
- dispose(): Promise<void>;
86
- /** POST one framed JSON-RPC message; refuse redirects; reject non-2xx. */
87
- private post;
88
- }
89
- export {};
@@ -1,12 +0,0 @@
1
- export type { McpTrust, McpTransport, RawMcpTool, McpCallResult, } from "./types.js";
2
- export { mcpTrustPath, fingerprintMcpServers, isMcpTrusted, endpointsMatch, fileMcpTrustStore, memoryMcpTrustStore, type McpTrustStore, } from "./trust.js";
3
- export { ensureMcpTrust, type EnsureMcpTrustDeps, type EnsureMcpTrustResult, type McpTrustIO, type McpTrustOutcome, } from "./trust-gate.js";
4
- export { validateMcpUrl, resolveMcpEndpoints, type ValidatedMcpUrl, } from "./url-guard.js";
5
- export { McpHttpTransport, McpHttpAuthError, type McpHttpSpec, } from "./http-transport.js";
6
- export { demarcateDescription, demarcateResult } from "./demarcate.js";
7
- export { boundToolList, type McpBounds, type BoundedTool, type BoundedToolList, } from "./bounds.js";
8
- export { McpStdioTransport, type McpSpawnSpec } from "./transport.js";
9
- export { McpClient, type McpClientTimeouts } from "./client.js";
10
- export { mcpToolsFrom, type McpToolSource } from "./adapter.js";
11
- export { deferredSiblingServers, type DeferredSiblingServer, } from "./sibling-banner.js";
12
- export { connectMcpTools, resetMcpServices, liveMcpConnectionCount, type ConnectMcpToolsParams, type ConnectMcpToolsResult, type McpServiceDeps, } from "./service.js";
@@ -1,71 +0,0 @@
1
- import type { CruxyConfig, McpServerConfig } from "../config/index.js";
2
- import type { HostResolver } from "../net/ip-guard.js";
3
- import type { Tool } from "../tools/types.js";
4
- import { type McpTrustStore } from "./trust.js";
5
- import { type McpTrustIO } from "./trust-gate.js";
6
- import type { McpTransport } from "./types.js";
7
- /**
8
- * The session-facing MCP entry point (C.27). `connectMcpTools` is what a session
9
- * calls at start to (1) honor the master switch, (2) enforce the connect-time
10
- * trust gate, and (3) connect every trusted server and return its gated tools —
11
- * all produced through the single adapter seam. Connections are tracked so
12
- * {@link resetMcpServices} can shut them down at session end (the shared
13
- * child-tree exit backstop is the fail-safe for a hard kill).
14
- *
15
- * Off-by-default is enforced first: when `mcp.enabled` is false, this returns no
16
- * tools without ever reading trust, spawning a process, or touching a server.
17
- */
18
- interface ServiceLogger {
19
- debug(message: string): void;
20
- info(message: string): void;
21
- warn(message: string): void;
22
- }
23
- /** Explicit dependency overrides, for tests only. Production passes none. */
24
- export interface McpServiceDeps {
25
- /** Substitute the transport (a fake peer — no real server binary/socket). */
26
- transportFactory?: (server: string, cfg: McpServerConfig, root: string,
27
- /** Pre-validated, pinned address set (url servers only). */
28
- addresses: string[],
29
- /** Resolved auth headers (url servers only; C.27c). */
30
- authHeaders?: Record<string, string>) => McpTransport;
31
- /** Substitute the trust store. */
32
- trustStore?: McpTrustStore;
33
- /** ISO-timestamp source for a recorded trust decision. */
34
- now?: () => string;
35
- /** DNS resolver for the trust gate's url-endpoint capture + SSRF guard. */
36
- resolveHost?: HostResolver;
37
- }
38
- export interface ConnectMcpToolsParams {
39
- cwd: string;
40
- config: CruxyConfig;
41
- logger: ServiceLogger;
42
- /** Whether cruxy can prompt for trust (stdin is a TTY). */
43
- interactive: boolean;
44
- /** Prompt I/O for the trust disclosure (required to prompt when interactive). */
45
- io?: McpTrustIO;
46
- deps?: McpServiceDeps;
47
- }
48
- export interface ConnectMcpToolsResult {
49
- /** The gated MCP tools to register (empty when disabled / untrusted-declined). */
50
- tools: Tool[];
51
- }
52
- export declare function connectMcpTools(params: ConnectMcpToolsParams): Promise<ConnectMcpToolsResult>;
53
- /**
54
- * Resolve the auth headers to send to a `url` server (C.27c), or `undefined` for
55
- * an unauthenticated/stdio server. Two sources, both user-owned and outside the
56
- * repo: a `credentialRef` looked up SOLELY in `~/.cruxy/credentials.json` (never
57
- * the env, never any config file), and raw `headers` (accepted only from
58
- * user-scope config — the loader already rejected them from project scope). A
59
- * named credential with no stored token throws {@link mcpAuth} (missing) so a
60
- * dangling reference fails cleanly rather than connecting unauthenticated.
61
- */
62
- export declare function resolveMcpAuthHeaders(server: string, cfg: McpServerConfig, read?: (ref: string) => string | undefined): Record<string, string> | undefined;
63
- /**
64
- * Dispose every live MCP connection (session end / process teardown). Mirrors
65
- * `resetLspServices`; the shared child-tree exit backstop reaps anything a hard
66
- * kill skips. Idempotent.
67
- */
68
- export declare function resetMcpServices(): Promise<void>;
69
- /** Number of live MCP connections (for tests). */
70
- export declare function liveMcpConnectionCount(): number;
71
- export {};
@@ -1,25 +0,0 @@
1
- import type { Workspace } from "../workspace/index.js";
2
- /**
3
- * MCP is PRIMARY-ROOT ONLY this release (JC-D). Two roots each declaring a
4
- * `github` server would collide on the wire-name `mcp__github__<tool>` (the
5
- * adapter derives it from the server id with no root component), so sibling-root
6
- * servers are NOT registered. They are also NOT silently dropped: each one is
7
- * named individually in the startup banner (server + which root declared it), so
8
- * the deferral is explicit. Root-qualified wire-names are a separate follow-up.
9
- */
10
- export interface DeferredSiblingServer {
11
- /** The declared server id (the would-be `mcp__<server>__*` prefix). */
12
- server: string;
13
- /** The declaring non-primary root's name. */
14
- root: string;
15
- }
16
- /**
17
- * Enumerate the MCP servers declared by each NON-primary root's own project
18
- * config — the set deferred this release. Pure over an injectable reader so the
19
- * naming is unit-testable without touching disk. Reads each sibling's OWN
20
- * declaration (not the merged/global set), so a sibling's `github` is named even
21
- * when the primary also declares one (the exact collision we're deferring).
22
- */
23
- export declare function deferredSiblingServers(workspace: Workspace, opts?: {
24
- declaredServersFor?: (absPath: string) => string[];
25
- }): DeferredSiblingServer[];