@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,257 +0,0 @@
1
- import type { z, ZodTypeAny } from "zod";
2
- import type { CruxyConfig } from "../config/index.js";
3
- import type { ApprovalDecision } from "../approval/types.js";
4
- import type { SandboxService } from "../sandbox/index.js";
5
- import type { Workspace } from "../workspace/index.js";
6
- import type { logger } from "../utils/logger.js";
7
- /** The leveled logger instance shared across the CLI. */
8
- type Logger = typeof logger;
9
- /**
10
- * The outcome of a tool run. Tools never throw across this boundary — failures
11
- * are reported as `{ ok: false }` so the agent loop can feed the error back to
12
- * the model instead of crashing.
13
- */
14
- export type ToolResult = {
15
- ok: true;
16
- output: string;
17
- } | {
18
- ok: false;
19
- error: string;
20
- };
21
- /**
22
- * One file's worth of change inside an `apply_patch` preview. Paths are
23
- * project-relative (the tool relativizes them for display).
24
- */
25
- export type PatchFilePreview = {
26
- op: "update";
27
- path: string;
28
- hunks: {
29
- oldStr: string;
30
- newStr: string;
31
- }[];
32
- } | {
33
- op: "create";
34
- path: string;
35
- lines: string[];
36
- omittedLines: number;
37
- } | {
38
- op: "delete";
39
- path: string;
40
- };
41
- /**
42
- * An optional preview of exactly what a mutating action will change, threaded
43
- * from the tool into `ctx.approve` so the prompt can show it before the user
44
- * decides. The tool fills this in from data it has already computed.
45
- */
46
- export type ActionPreview =
47
- /** The exact strings `edit_file` is about to swap. */
48
- {
49
- type: "edit";
50
- oldStr: string;
51
- newStr: string;
52
- }
53
- /**
54
- * What `write_file` will write: whether the path already exists (overwrite vs
55
- * create) and the first lines of the new content, pre-capped by the tool.
56
- */
57
- | {
58
- type: "write";
59
- exists: boolean;
60
- lines: string[];
61
- omittedLines: number;
62
- }
63
- /** The full set of file changes `apply_patch` will make, for a combined diff. */
64
- | {
65
- type: "patch";
66
- files: PatchFilePreview[];
67
- }
68
- /**
69
- * The whole publish plan for a `vcs` action (C.15): the feature branch, the
70
- * conventional commit, and the PR title/body — shown as one block so the user
71
- * approves the entire branch → commit → push → open-PR sequence at once. C.26
72
- * Step 4 adds `target` (the resolved `host/owner/repo` the PR will open against)
73
- * so the human sees the real API destination — not just the root name — before
74
- * approving (⚖︎JC-4); it is re-resolved and re-checked immediately before the API
75
- * call, so what is shown here is what the guard holds them to.
76
- */
77
- | {
78
- type: "pr";
79
- branch: string;
80
- base: string;
81
- commitSubject: string;
82
- commitBody: string;
83
- prTitle: string;
84
- prBody: string;
85
- /** The resolved forge target parsed from `origin` at approval time. */
86
- target: {
87
- host: string;
88
- owner: string;
89
- repo: string;
90
- };
91
- }
92
- /**
93
- * The full blast radius of a checkpoint restore (C.32): every file rollback
94
- * will recreate/revert/delete (as patch-style entries), plus the paths that
95
- * changed since the checkpoint by something *other* than the tracked run —
96
- * shown before the diff so the collapse cap can never hide them. Rollback
97
- * covers working-tree files only; commits/pushes/PRs made during the run are
98
- * out of scope (stated in the rendered note).
99
- */
100
- | {
101
- type: "rollback";
102
- checkpointId: string;
103
- createdAt: string;
104
- runSummary: string;
105
- files: PatchFilePreview[];
106
- externalPaths: string[];
107
- /** The run executed shell commands, so per-file attribution is impossible. */
108
- attributionUnknown: boolean;
109
- }
110
- /**
111
- * A multi-root rollback set (C.26 step 3): one combined preview grouped by root,
112
- * each root carrying its own file diffs and external-change warnings, so a single
113
- * U.3 approval covers restoring every touched root of a run at once (⚖︎JC-ι). One
114
- * `roots` entry per member of the run's `CheckpointSet`.
115
- */
116
- | {
117
- type: "rollback-set";
118
- runId: string;
119
- createdAt: string;
120
- runSummary: string;
121
- roots: {
122
- rootName: string;
123
- checkpointId: string;
124
- files: PatchFilePreview[];
125
- externalPaths: string[];
126
- attributionUnknown: boolean;
127
- }[];
128
- };
129
- /**
130
- * A side-effecting action a tool wants to take, passed to `ctx.approve`. The
131
- * `kind` set grows as more mutating tools land; it drives the permission prompt.
132
- */
133
- export interface ApproveAction {
134
- /** The category of side effect being requested. */
135
- kind: "write" | "edit" | "shell" | "patch" | "vcs" | "rollback" | "test" | "mcp";
136
- /** Absolute resolved path the action targets (write/edit). */
137
- path?: string;
138
- /** The command to run (shell / test). */
139
- command?: string;
140
- /** MCP tool call (C.27): the server id and the tool name being invoked. The
141
- * gate keys a session grant on this exact pair, so approving one MCP tool never
142
- * covers another — and a server can never mark its own tool low-risk. */
143
- server?: string;
144
- tool?: string;
145
- /**
146
- * The declared workspace root this action acts in (C.26). `vcs` sets it to the
147
- * root a pull request was selected for (C.26 Step 4): it may be non-primary, and
148
- * the checkpoint gate attributes the vcs checkpoint to exactly this root. `shell`/
149
- * `test` still set it to the primary as an attribution seam — their non-primary
150
- * support is Step 5 (JC-β residual), so the gate hard-attributes them to the
151
- * primary regardless of this value. File actions carry their root in the resolved
152
- * absolute `path`/preview instead, so they leave this unset.
153
- */
154
- root?: string;
155
- /** Exact-change preview rendered above the prompt (write/edit/patch/vcs/rollback). */
156
- preview?: ActionPreview;
157
- }
158
- /**
159
- * Ambient capabilities handed to every tool at execution time. Tools run on the
160
- * user's machine, so this is the only sanctioned door to the filesystem root
161
- * (`cwd`), configuration, logging, and the permission gate.
162
- */
163
- export interface ToolContext {
164
- /** Absolute path the tool should treat as its working root. */
165
- cwd: string;
166
- /**
167
- * The declared workspace root set for this session (C.26). Path-taking tools
168
- * resolve *through* this rather than through `cwd`, so a multi-root session
169
- * confines each call to the one root it selects. **Required** (C.26 Step 6): a
170
- * construction site that fails to thread it is a *compile error*, not a runtime
171
- * primary-default — closing the omission hole the old optional field left. The
172
- * runtime always sets it; a single-root caller builds one with `sessionWorkspace`.
173
- * (The type catches *omission*; it cannot catch a *fabricated* workspace threaded
174
- * through — the `no-split-brain` grep guard covers that. See its header.) `cwd`
175
- * remains equal to `workspace.primary().absPath`.
176
- */
177
- workspace: Workspace;
178
- /** Fully-resolved CLI configuration. */
179
- config: CruxyConfig;
180
- /** Shared leveled logger (diagnostics to stderr, `print` to stdout). */
181
- logger: Logger;
182
- /**
183
- * The approval gate every side-effecting tool funnels through, **before** any
184
- * mutation. Returns a decision: `{allow:true}` to proceed, or `{allow:false,
185
- * feedback?}` (a clean rejection whose feedback is surfaced to the agent).
186
- * Backed by the risk-tiered `ApprovalService` (see src/approval); it may
187
- * *throw* `CRUXY_E_APPROVAL_REQUIRED` when it can't ask (non-interactive),
188
- * which propagates to the boundary rather than being swallowed. Read-only
189
- * tools never call this.
190
- */
191
- requestApproval(action: ApproveAction): Promise<ApprovalDecision>;
192
- /**
193
- * Whether per-root checkpointing is active for this session (C.26 step 3). It is
194
- * the single fact that lifts the JC-1 non-primary-write refusal: a write to a
195
- * non-primary root is permitted **iff** this is true, because a true value means
196
- * a per-root checkpoint gate is wired that captures the write (get-or-creates the
197
- * root's service and snapshots it) before it reaches disk. False/absent → a
198
- * non-primary write is still refused with `CRUXY_E_MULTIROOT_WRITE_DEFERRED`, so
199
- * a checkpoints-disabled session never widens un-restorable writes to siblings.
200
- * Set together with `requestApproval` (the gate), so permit and capture are one
201
- * decision — never lift-then-verify.
202
- */
203
- checkpointsActive?: boolean;
204
- /**
205
- * Isolation substrate for the shell + test tools (C.16). Present ONLY when
206
- * the sandbox is enabled; when set, `run_command`/`run_tests` execute the
207
- * approved command inside the container and NEVER on the host. Its mere
208
- * presence is the switch — there is no host fallback once it is set (an
209
- * unavailable runtime fails loud at construction, before this is ever
210
- * populated). Absent → host execution, unchanged.
211
- */
212
- sandbox?: SandboxService;
213
- /**
214
- * Cooperative cancellation for in-flight tool work (C.33). Set on a subagent's
215
- * ctx when it runs inside a parallel fan-out: when a fatal sibling failure or
216
- * Ctrl-C aborts the batch, this signal fires, and a long-running `run_command`
217
- * kills its whole process tree instead of leaving it orphaned — the C.12/C.16
218
- * kill-tree discipline extended to N concurrent children. Absent → no external
219
- * cancellation (the tool's own timeout still applies), unchanged behaviour.
220
- */
221
- signal?: AbortSignal;
222
- }
223
- /**
224
- * The one interface every tool implements. `parameters` is a zod schema; it both
225
- * validates the model's arguments and (via the registry) becomes the wire-format
226
- * JSON Schema advertised to the provider.
227
- */
228
- export interface Tool<Schema extends ZodTypeAny = ZodTypeAny> {
229
- /** Unique, snake_case identifier the model uses to call the tool. */
230
- name: string;
231
- /** One-line description shown to the model. */
232
- description: string;
233
- /** Zod schema for the tool's input arguments. */
234
- parameters: Schema;
235
- /**
236
- * An optional pre-rendered JSON Schema to advertise to the provider *verbatim*
237
- * instead of deriving one from {@link parameters}. Used only by proxied tools
238
- * whose schema originates elsewhere and cannot be reconstructed from zod — the
239
- * MCP adapter (C.27) sets this to a server's own (bounds-capped) input schema
240
- * while keeping a permissive `parameters` for local validation. Built-in tools
241
- * leave it unset and are advertised from their zod schema as before.
242
- */
243
- rawInputSchema?: Record<string, unknown>;
244
- /**
245
- * Optional per-turn lifecycle hook (C.13). {@link Session.send} calls it on
246
- * every tool in the session registry at the start of each user turn, before the
247
- * model runs. A tool that carries per-episode state — e.g. `run_tests`' consecutive-
248
- * failure breaker — resets it here so a fresh instruction starts clean, while that
249
- * state still latches across the many model iterations *within* one turn. Tools
250
- * with no per-turn state omit it (a subagent/one-shot run is a single episode, so
251
- * a missing hook simply means the state lives for that whole run).
252
- */
253
- onTurnStart?(): void;
254
- /** Run the tool against validated `input` and the ambient `ctx`. */
255
- execute(input: z.infer<Schema>, ctx: ToolContext): Promise<ToolResult>;
256
- }
257
- export {};
@@ -1,40 +0,0 @@
1
- import type { Usage } from "@cruxy/sdk";
2
- import type { UsageRecord } from "./types.js";
3
- /**
4
- * Usage collection (C.22). Accumulates per-request usage exactly as the agent
5
- * loop reports it — one {@link UsageEntry} per completed model request — and
6
- * emits a {@link UsageRecord} for the run.
7
- *
8
- * The one honesty invariant: `usage: undefined` (the loop's signal that the
9
- * provider returned NO usage event for a request) is recorded as `undefined`
10
- * token counts — the honest "unknown". A provider-reported `0` arrives as a real
11
- * `Usage` and is stored as `0`. Nothing is estimated, re-tokenized, or
12
- * zero-filled, and this module makes ZERO network calls.
13
- */
14
- /** What the loop hands over for one completed request. */
15
- export interface RequestUsage {
16
- /** The routing tier (C.30) the request ran on, if routing was active. */
17
- tier?: string;
18
- /**
19
- * The provider's usage for THIS request, or `undefined` when the provider
20
- * emitted no usage event (⇒ tokens are unknown, not zero).
21
- */
22
- usage?: Usage;
23
- }
24
- /** Wall clock as an injectable seam so tests are deterministic. */
25
- export type Clock = () => string;
26
- export declare class UsageCollector {
27
- private readonly now;
28
- private readonly entries;
29
- constructor(now?: Clock);
30
- /**
31
- * Record one completed request. When `req.usage` is absent the entry's token
32
- * counts stay `undefined` — the provider reported nothing, so we assert
33
- * nothing. A real reported `0` is preserved as `0`.
34
- */
35
- record(req: RequestUsage): void;
36
- /** How many requests have been recorded so far. */
37
- get count(): number;
38
- /** Snapshot the collected entries into a persistable {@link UsageRecord}. */
39
- toRecord(runId: string, sessionId: string | undefined, startedAt: string): UsageRecord;
40
- }
@@ -1,19 +0,0 @@
1
- import type { PriceTable, TierPrice } from "./types.js";
2
- /**
3
- * Token → cost mapping (C.22). The whole discipline lives in one rule: a cost is
4
- * produced ONLY when the tier has a configured price AND at least one token side
5
- * is known. Otherwise the result is `undefined` — cost is omitted, tokens are
6
- * still shown, and NO dollar figure is ever fabricated. Prices are per MILLION
7
- * tokens (see {@link TierPrice}). Keyed by tier only (U.8 gag). No network.
8
- */
9
- /** The configured price for a tier, or `undefined` when the tier is unpriced. */
10
- export declare function priceForTier(tier: string, prices: PriceTable): TierPrice | undefined;
11
- /**
12
- * Compute the cost of a tier's usage, or `undefined` when it cannot be stated
13
- * honestly:
14
- * - no configured price for the tier → `undefined` (cost omitted).
15
- * - both token counts unknown → `undefined` (nothing real to price).
16
- * A known side is priced; an unknown side contributes nothing (never a
17
- * fabricated 0-token charge). tokens/1e6 × price, summed.
18
- */
19
- export declare function costFor(tier: string, inputTokens: number | undefined, outputTokens: number | undefined, prices: PriceTable): number | undefined;
@@ -1,15 +0,0 @@
1
- /**
2
- * Usage telemetry + cost tracking (C.22) — LOCAL usage accounting only.
3
- *
4
- * NO-PHONE-HOME GUARANTEE: nothing here transmits anything. This module reads
5
- * and writes ONE local file under `~/.cruxy/usage` and renders to the terminal;
6
- * it imports no provider, no transport, and makes no `fetch`/HTTP call. The
7
- * `@cruxy/sdk` import below is a TYPE-only import (`Usage`), erased at build. A
8
- * future opt-in remote report would be a new, clearly-named seam — this build
9
- * ships nothing that sends. Asserted by the runtime + static no-phone-home tests.
10
- */
11
- export * from "./types.js";
12
- export { UsageCollector, type RequestUsage, type Clock } from "./collect.js";
13
- export { costFor, priceForTier } from "./cost.js";
14
- export { loadUsage, appendRun, usageStorePath } from "./store.js";
15
- export { summarizeRuns, renderSummary, formatCost, type SummarizeOptions, } from "./summary.js";
@@ -1,37 +0,0 @@
1
- import { CruxyError } from "../errors/index.js";
2
- import { type UsageFile, type UsageRecord } from "./types.js";
3
- /**
4
- * The usage store (C.22): a single JSON file under `~/.cruxy/usage`, holding a
5
- * bounded, newest-last list of run records. Pure DATA — parsed with the strict
6
- * schema, NEVER eval'd — and written `0600` (personal accounting). This module
7
- * touches only the local filesystem; it makes ZERO network calls.
8
- *
9
- * Reads are non-fatal by contract: a missing file is empty (not an error); a
10
- * corrupt/unreadable one yields an empty result plus a coded
11
- * {@link usageRead} error the caller can surface and SKIP — a broken usage file
12
- * never crashes a run.
13
- */
14
- /** `~/.cruxy/usage/runs.json` — the single usage store file. */
15
- export declare function usageStorePath(): string;
16
- /**
17
- * Load and validate the store. Never throws. A missing file → empty, no error.
18
- * Invalid JSON or a schema mismatch → empty + a `CRUXY_E_USAGE_READ` error
19
- * (skip, don't crash). The raw text is parsed with `JSON.parse` only — a store
20
- * file is never executed, so a hand-edited file cannot run code.
21
- */
22
- export declare function loadUsage(file?: string): {
23
- data: UsageFile;
24
- error?: CruxyError;
25
- };
26
- /**
27
- * Append one run's usage, pruning oldest-first to the last `retention` runs.
28
- * Never throws — any failure (a corrupt existing file that cannot be safely
29
- * appended to, or a write error) is returned as a coded error for the caller to
30
- * downgrade to a warning, so persistence never takes a run down with it.
31
- */
32
- export declare function appendRun(record: UsageRecord, opts?: {
33
- retention: number;
34
- file?: string;
35
- }): {
36
- error?: CruxyError;
37
- };
@@ -1,32 +0,0 @@
1
- import type { Theme } from "../theme/index.js";
2
- import type { PriceTable, UsageRecord, UsageSummary } from "./types.js";
3
- /**
4
- * Usage aggregation + rendering (C.22). Aggregation sums only KNOWN token
5
- * counts and counts the requests that reported none separately, so a total is
6
- * never inflated by a fabricated zero — and the renderer ALWAYS surfaces that
7
- * count, so a total can never be misread as complete while requests are silently
8
- * excluded. Costs appear only for priced tiers. Only tier names ever reach the
9
- * output (U.8 gag). Pure — no I/O, no network.
10
- */
11
- export interface SummarizeOptions {
12
- prices: PriceTable;
13
- /** Currency label to prefix costs; "" when the user configured none. */
14
- currency: string;
15
- }
16
- /** Aggregate one or more run records into a {@link UsageSummary}. */
17
- export declare function summarizeRuns(runs: readonly UsageRecord[], opts: SummarizeOptions): UsageSummary;
18
- /**
19
- * Format a cost figure honestly: enough precision for small per-run costs,
20
- * trailing zeros trimmed. Prefixed by the currency label only when one is set
21
- * (never an assumed symbol). Callers pass a cost only when it was actually
22
- * computed (priced + known tokens).
23
- */
24
- export declare function formatCost(n: number, currency: string): string;
25
- /**
26
- * Render a {@link UsageSummary} to a single themed line. Honors the theme
27
- * end-to-end: NO_COLOR yields zero ANSI (identity stylers), and screen-reader
28
- * mode swaps the arrow glyphs for words. The count of requests that reported no
29
- * usage is ALWAYS shown when non-zero, so the total is never mistaken for a
30
- * complete accounting.
31
- */
32
- export declare function renderSummary(summary: UsageSummary, t: Theme): string;
@@ -1,220 +0,0 @@
1
- import { z } from "zod";
2
- import { MODEL_TIERS } from "../brand/voice.js";
3
- /**
4
- * Usage telemetry + cost tracking (C.22): types for LOCAL, honest usage
5
- * accounting. Every number here is a real figure the provider reported — a token
6
- * count is present only when the provider returned usage for that request, and
7
- * `undefined` (never `0`) when it did not. Nothing in this module is ever
8
- * transmitted anywhere (see the module barrel's no-phone-home note).
9
- */
10
- /** Bump when the on-disk usage file shape changes (enables future migration). */
11
- export declare const USAGE_FILE_VERSION: 1;
12
- /**
13
- * One model request's usage. A request that reported no usage keeps
14
- * `inputTokens`/`outputTokens` as `undefined` — the honest "unknown", never
15
- * zero-filled or re-tokenized. A provider-reported `0` is stored as `0` (a real
16
- * count), so the two cases stay distinguishable downstream.
17
- */
18
- export declare const UsageEntrySchema: z.ZodObject<{
19
- /** The routing tier (C.30) this request ran on; absent when routing is inert. */
20
- tier: z.ZodOptional<z.ZodString>;
21
- /** Provider-reported prompt tokens; `undefined` ⇔ no usage was reported. */
22
- inputTokens: z.ZodOptional<z.ZodNumber>;
23
- /** Provider-reported completion tokens; `undefined` ⇔ no usage was reported. */
24
- outputTokens: z.ZodOptional<z.ZodNumber>;
25
- /** ISO-8601 timestamp the request completed. */
26
- at: z.ZodString;
27
- }, "strict", z.ZodTypeAny, {
28
- at: string;
29
- tier?: string | undefined;
30
- inputTokens?: number | undefined;
31
- outputTokens?: number | undefined;
32
- }, {
33
- at: string;
34
- tier?: string | undefined;
35
- inputTokens?: number | undefined;
36
- outputTokens?: number | undefined;
37
- }>;
38
- export type UsageEntry = z.infer<typeof UsageEntrySchema>;
39
- /** One run's usage: an ordered list of per-request entries. */
40
- export declare const UsageRecordSchema: z.ZodObject<{
41
- /** Unique id for this run (one `session.send`). */
42
- runId: z.ZodString;
43
- /** Groups runs of one interactive session, so `--session` aggregates them. */
44
- sessionId: z.ZodOptional<z.ZodString>;
45
- /** ISO-8601 timestamp the run started. */
46
- startedAt: z.ZodString;
47
- entries: z.ZodArray<z.ZodObject<{
48
- /** The routing tier (C.30) this request ran on; absent when routing is inert. */
49
- tier: z.ZodOptional<z.ZodString>;
50
- /** Provider-reported prompt tokens; `undefined` ⇔ no usage was reported. */
51
- inputTokens: z.ZodOptional<z.ZodNumber>;
52
- /** Provider-reported completion tokens; `undefined` ⇔ no usage was reported. */
53
- outputTokens: z.ZodOptional<z.ZodNumber>;
54
- /** ISO-8601 timestamp the request completed. */
55
- at: z.ZodString;
56
- }, "strict", z.ZodTypeAny, {
57
- at: string;
58
- tier?: string | undefined;
59
- inputTokens?: number | undefined;
60
- outputTokens?: number | undefined;
61
- }, {
62
- at: string;
63
- tier?: string | undefined;
64
- inputTokens?: number | undefined;
65
- outputTokens?: number | undefined;
66
- }>, "many">;
67
- }, "strict", z.ZodTypeAny, {
68
- entries: {
69
- at: string;
70
- tier?: string | undefined;
71
- inputTokens?: number | undefined;
72
- outputTokens?: number | undefined;
73
- }[];
74
- runId: string;
75
- startedAt: string;
76
- sessionId?: string | undefined;
77
- }, {
78
- entries: {
79
- at: string;
80
- tier?: string | undefined;
81
- inputTokens?: number | undefined;
82
- outputTokens?: number | undefined;
83
- }[];
84
- runId: string;
85
- startedAt: string;
86
- sessionId?: string | undefined;
87
- }>;
88
- export type UsageRecord = z.infer<typeof UsageRecordSchema>;
89
- /** The persisted store: a bounded, newest-last list of run records. */
90
- export declare const UsageFileSchema: z.ZodObject<{
91
- version: z.ZodLiteral<1>;
92
- runs: z.ZodArray<z.ZodObject<{
93
- /** Unique id for this run (one `session.send`). */
94
- runId: z.ZodString;
95
- /** Groups runs of one interactive session, so `--session` aggregates them. */
96
- sessionId: z.ZodOptional<z.ZodString>;
97
- /** ISO-8601 timestamp the run started. */
98
- startedAt: z.ZodString;
99
- entries: z.ZodArray<z.ZodObject<{
100
- /** The routing tier (C.30) this request ran on; absent when routing is inert. */
101
- tier: z.ZodOptional<z.ZodString>;
102
- /** Provider-reported prompt tokens; `undefined` ⇔ no usage was reported. */
103
- inputTokens: z.ZodOptional<z.ZodNumber>;
104
- /** Provider-reported completion tokens; `undefined` ⇔ no usage was reported. */
105
- outputTokens: z.ZodOptional<z.ZodNumber>;
106
- /** ISO-8601 timestamp the request completed. */
107
- at: z.ZodString;
108
- }, "strict", z.ZodTypeAny, {
109
- at: string;
110
- tier?: string | undefined;
111
- inputTokens?: number | undefined;
112
- outputTokens?: number | undefined;
113
- }, {
114
- at: string;
115
- tier?: string | undefined;
116
- inputTokens?: number | undefined;
117
- outputTokens?: number | undefined;
118
- }>, "many">;
119
- }, "strict", z.ZodTypeAny, {
120
- entries: {
121
- at: string;
122
- tier?: string | undefined;
123
- inputTokens?: number | undefined;
124
- outputTokens?: number | undefined;
125
- }[];
126
- runId: string;
127
- startedAt: string;
128
- sessionId?: string | undefined;
129
- }, {
130
- entries: {
131
- at: string;
132
- tier?: string | undefined;
133
- inputTokens?: number | undefined;
134
- outputTokens?: number | undefined;
135
- }[];
136
- runId: string;
137
- startedAt: string;
138
- sessionId?: string | undefined;
139
- }>, "many">;
140
- }, "strict", z.ZodTypeAny, {
141
- version: 1;
142
- runs: {
143
- entries: {
144
- at: string;
145
- tier?: string | undefined;
146
- inputTokens?: number | undefined;
147
- outputTokens?: number | undefined;
148
- }[];
149
- runId: string;
150
- startedAt: string;
151
- sessionId?: string | undefined;
152
- }[];
153
- }, {
154
- version: 1;
155
- runs: {
156
- entries: {
157
- at: string;
158
- tier?: string | undefined;
159
- inputTokens?: number | undefined;
160
- outputTokens?: number | undefined;
161
- }[];
162
- runId: string;
163
- startedAt: string;
164
- sessionId?: string | undefined;
165
- }[];
166
- }>;
167
- export type UsageFile = z.infer<typeof UsageFileSchema>;
168
- /**
169
- * A per-tier price, in the user's own currency, PER MILLION TOKENS. Chosen over
170
- * per-token so prices read the way LLM pricing is quoted and don't lose
171
- * precision to tiny floats. Configured by the user under `usage.prices.<tier>`;
172
- * cruxy ships NO prices (a bundled table would imply upstream identities and go
173
- * stale) — with none configured, cost is omitted entirely.
174
- */
175
- export interface TierPrice {
176
- /** Price per 1,000,000 input tokens. */
177
- input: number;
178
- /** Price per 1,000,000 output tokens. */
179
- output: number;
180
- }
181
- /**
182
- * Prices keyed by TIER ONLY (kavi/vaani/mira) — the type literally cannot name
183
- * an upstream model, so the U.8 gag holds by construction. Partial: any tier may
184
- * be unpriced (its cost is then omitted, tokens still shown).
185
- */
186
- export type PriceTable = Partial<Record<(typeof MODEL_TIERS)[number], TierPrice>>;
187
- /** Aggregated usage for one tier across the summarized runs. */
188
- export interface TierUsage {
189
- tier: string;
190
- /** Sum of KNOWN input tokens; `undefined` if no request on this tier reported usage. */
191
- inputTokens?: number;
192
- /** Sum of KNOWN output tokens; `undefined` if none reported. */
193
- outputTokens?: number;
194
- /** Requests attributed to this tier. */
195
- requests: number;
196
- /** How many of those reported no usage (surfaced, never silently dropped). */
197
- requestsWithoutUsage: number;
198
- /** Cost, ONLY when this tier is priced AND has known tokens; else omitted. */
199
- cost?: number;
200
- }
201
- /** The aggregate over one or more runs — what the summary renderer consumes. */
202
- export interface UsageSummary {
203
- perTier: TierUsage[];
204
- /** Sum of KNOWN input tokens across all runs; `undefined` if none known. */
205
- totalInputTokens?: number;
206
- /** Sum of KNOWN output tokens across all runs; `undefined` if none known. */
207
- totalOutputTokens?: number;
208
- /** Sum of per-tier costs; `undefined` unless ≥1 tier was priced. */
209
- totalCost?: number;
210
- /** True iff at least one tier had a configured price (cost is shown). */
211
- priced: boolean;
212
- /** Currency label to prefix costs with; "" when the user configured none. */
213
- currency: string;
214
- /** Total requests across all runs that reported no usage (rendered visibly). */
215
- requestsWithoutUsage: number;
216
- /** Total requests across all runs. */
217
- requests: number;
218
- /** How many runs were aggregated. */
219
- runCount: number;
220
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * The process-EXIT backstop for long-lived child trees (C.12 LSP servers, C.27
3
- * MCP servers). The platform-aware spawn/kill primitives themselves now live in
4
- * {@link ./process-tree.js} — {@link killTree} is re-exported here unchanged so
5
- * existing LSP/MCP importers keep their import path, and so this backstop and
6
- * those transports reap trees the SAME way on every platform (negative-PID
7
- * `SIGKILL` on POSIX, `taskkill /T /F` on win32 — no more orphaned grandchildren
8
- * on Windows).
9
- *
10
- * A per-session graceful shutdown covers the normal path, but a hard exit
11
- * (Ctrl-C, an uncaught throw) would otherwise orphan these trees. So every live
12
- * child's pid is tracked in one process-wide set and force-killed on teardown.
13
- * Handlers are installed ONCE, lazily, on the first registration — so unit tests
14
- * that never spawn a real process never install them.
15
- *
16
- * This module is deliberately transport-agnostic: LSP (Content-Length framing)
17
- * and MCP (newline-delimited JSON) share the SAME backstop, so `killTrackedTrees`
18
- * on exit reaps both and there is a single source of truth for "no orphans".
19
- */
20
- import { killTree } from "./process-tree.js";
21
- export { killTree };
22
- /**
23
- * Force-kill the process group of every tracked-but-not-yet-shut-down child,
24
- * then forget them. This is exactly what the `exit`/`SIGINT`/`SIGTERM`/`SIGHUP`
25
- * handlers run — the last line against orphaned server trees on a hard exit.
26
- * Exported so it is directly testable without raising real process signals.
27
- * Idempotent: a second call is a no-op.
28
- */
29
- export declare function killTrackedTrees(): void;
30
- /** Number of child trees currently tracked by the exit backstop (for tests). */
31
- export declare function trackedTreeCount(): number;
32
- /** Track a live child for the exit backstop; returns a deregister callback. */
33
- export declare function registerForCleanup(pid: number | undefined): () => void;
@@ -1,17 +0,0 @@
1
- /**
2
- * Branch name plus the raw `git status --porcelain` text for `cwd`, or `null`
3
- * when it isn't a git repository (or git is unavailable). Backs the `git_status`
4
- * tool, which surfaces the porcelain output to the model.
5
- */
6
- export declare function getGitStatus(cwd: string): {
7
- branch: string;
8
- status: string;
9
- } | null;
10
- /**
11
- * Compact git context for the system prompt: current branch and whether the
12
- * working tree has uncommitted changes. `null` when not a repo / git missing.
13
- */
14
- export declare function getGitInfo(cwd: string): {
15
- branch: string;
16
- dirty: boolean;
17
- } | null;