@cruxy/cli 1.0.3 → 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 (238) hide show
  1. package/package.json +1 -1
  2. package/dist/agent/budget.d.ts +0 -52
  3. package/dist/agent/index.d.ts +0 -3
  4. package/dist/agent/loop.d.ts +0 -159
  5. package/dist/agent/prompts.d.ts +0 -69
  6. package/dist/agent/session.d.ts +0 -212
  7. package/dist/approval/classify.d.ts +0 -18
  8. package/dist/approval/index.d.ts +0 -6
  9. package/dist/approval/mutex.d.ts +0 -45
  10. package/dist/approval/policy.d.ts +0 -43
  11. package/dist/approval/prompt.d.ts +0 -48
  12. package/dist/approval/service.d.ts +0 -36
  13. package/dist/approval/types.d.ts +0 -82
  14. package/dist/brand/index.d.ts +0 -1
  15. package/dist/brand/voice.d.ts +0 -94
  16. package/dist/checkpoint/capture.d.ts +0 -17
  17. package/dist/checkpoint/gate-hook.d.ts +0 -28
  18. package/dist/checkpoint/gate.d.ts +0 -71
  19. package/dist/checkpoint/git-store.d.ts +0 -61
  20. package/dist/checkpoint/index.d.ts +0 -10
  21. package/dist/checkpoint/restore.d.ts +0 -23
  22. package/dist/checkpoint/service.d.ts +0 -89
  23. package/dist/checkpoint/set-rollback.d.ts +0 -51
  24. package/dist/checkpoint/set.d.ts +0 -44
  25. package/dist/checkpoint/shadow-store.d.ts +0 -23
  26. package/dist/checkpoint/types.d.ts +0 -164
  27. package/dist/cli/commands/checkpoint.d.ts +0 -7
  28. package/dist/cli/commands/config.d.ts +0 -2
  29. package/dist/cli/commands/hooks.d.ts +0 -8
  30. package/dist/cli/commands/index.d.ts +0 -7
  31. package/dist/cli/commands/init.d.ts +0 -7
  32. package/dist/cli/commands/login.d.ts +0 -8
  33. package/dist/cli/commands/mcp.d.ts +0 -9
  34. package/dist/cli/commands/memory.d.ts +0 -8
  35. package/dist/cli/commands/pr.d.ts +0 -8
  36. package/dist/cli/commands/rollback.d.ts +0 -18
  37. package/dist/cli/commands/run.d.ts +0 -2
  38. package/dist/cli/commands/skills.d.ts +0 -8
  39. package/dist/cli/commands/test.d.ts +0 -9
  40. package/dist/cli/commands/usage.d.ts +0 -9
  41. package/dist/cli/onboard.d.ts +0 -25
  42. package/dist/cli/program.d.ts +0 -2
  43. package/dist/cli/repl.d.ts +0 -27
  44. package/dist/cli/session-factory.d.ts +0 -42
  45. package/dist/cli/stream-print.d.ts +0 -14
  46. package/dist/components/autocomplete.d.ts +0 -32
  47. package/dist/components/frame.d.ts +0 -28
  48. package/dist/components/fuzzy.d.ts +0 -61
  49. package/dist/components/index.d.ts +0 -6
  50. package/dist/components/input.d.ts +0 -78
  51. package/dist/components/keys.d.ts +0 -48
  52. package/dist/components/select.d.ts +0 -28
  53. package/dist/config/credentials.d.ts +0 -18
  54. package/dist/config/index.d.ts +0 -5
  55. package/dist/config/manager.d.ts +0 -39
  56. package/dist/config/owner-only.d.ts +0 -19
  57. package/dist/config/paths.d.ts +0 -9
  58. package/dist/config/project.d.ts +0 -10
  59. package/dist/config/schema.d.ts +0 -2143
  60. package/dist/constants.d.ts +0 -65
  61. package/dist/errors/boundary.d.ts +0 -43
  62. package/dist/errors/constructors.d.ts +0 -411
  63. package/dist/errors/format.d.ts +0 -31
  64. package/dist/errors/index.d.ts +0 -4
  65. package/dist/errors/types.d.ts +0 -270
  66. package/dist/hooks/config.d.ts +0 -21
  67. package/dist/hooks/index.d.ts +0 -7
  68. package/dist/hooks/router.d.ts +0 -58
  69. package/dist/hooks/runner.d.ts +0 -88
  70. package/dist/hooks/service.d.ts +0 -38
  71. package/dist/hooks/slash.d.ts +0 -48
  72. package/dist/hooks/trust.d.ts +0 -46
  73. package/dist/hooks/types.d.ts +0 -147
  74. package/dist/index.d.ts +0 -2
  75. package/dist/indexing/chunker.d.ts +0 -28
  76. package/dist/indexing/embedder.d.ts +0 -98
  77. package/dist/indexing/index.d.ts +0 -9
  78. package/dist/indexing/indexer.d.ts +0 -45
  79. package/dist/indexing/retriever.d.ts +0 -61
  80. package/dist/indexing/service.d.ts +0 -49
  81. package/dist/indexing/store.d.ts +0 -103
  82. package/dist/indexing/types.d.ts +0 -78
  83. package/dist/indexing/util.d.ts +0 -34
  84. package/dist/indexing/walker.d.ts +0 -53
  85. package/dist/jobs/approval-queue.d.ts +0 -85
  86. package/dist/jobs/dispatch-tool.d.ts +0 -34
  87. package/dist/jobs/index.d.ts +0 -6
  88. package/dist/jobs/log-buffer.d.ts +0 -31
  89. package/dist/jobs/log-renderer.d.ts +0 -32
  90. package/dist/jobs/manager.d.ts +0 -139
  91. package/dist/jobs/types.d.ts +0 -81
  92. package/dist/lsp/client.d.ts +0 -25
  93. package/dist/lsp/index.d.ts +0 -8
  94. package/dist/lsp/pool.d.ts +0 -48
  95. package/dist/lsp/registry.d.ts +0 -38
  96. package/dist/lsp/server.d.ts +0 -48
  97. package/dist/lsp/service.d.ts +0 -44
  98. package/dist/lsp/tools/common.d.ts +0 -50
  99. package/dist/lsp/tools/find-definition.d.ts +0 -23
  100. package/dist/lsp/tools/find-references.d.ts +0 -23
  101. package/dist/lsp/tools/get-diagnostics.d.ts +0 -17
  102. package/dist/lsp/tools/hover.d.ts +0 -23
  103. package/dist/lsp/tools/index.d.ts +0 -4
  104. package/dist/lsp/transport.d.ts +0 -39
  105. package/dist/lsp/types.d.ts +0 -107
  106. package/dist/mcp/adapter.d.ts +0 -44
  107. package/dist/mcp/bounds.d.ts +0 -35
  108. package/dist/mcp/client.d.ts +0 -19
  109. package/dist/mcp/demarcate.d.ts +0 -12
  110. package/dist/mcp/http-transport.d.ts +0 -89
  111. package/dist/mcp/index.d.ts +0 -12
  112. package/dist/mcp/service.d.ts +0 -71
  113. package/dist/mcp/sibling-banner.d.ts +0 -25
  114. package/dist/mcp/transport.d.ts +0 -30
  115. package/dist/mcp/trust-gate.d.ts +0 -59
  116. package/dist/mcp/trust.d.ts +0 -62
  117. package/dist/mcp/types.d.ts +0 -62
  118. package/dist/mcp/url-guard.d.ts +0 -48
  119. package/dist/memory/index.d.ts +0 -7
  120. package/dist/memory/recall.d.ts +0 -56
  121. package/dist/memory/remember-tool.d.ts +0 -28
  122. package/dist/memory/secrets.d.ts +0 -29
  123. package/dist/memory/service.d.ts +0 -92
  124. package/dist/memory/store.d.ts +0 -32
  125. package/dist/memory/trust.d.ts +0 -52
  126. package/dist/memory/types.d.ts +0 -101
  127. package/dist/net/ip-guard.d.ts +0 -55
  128. package/dist/onboarding/detect.d.ts +0 -26
  129. package/dist/onboarding/flow.d.ts +0 -28
  130. package/dist/onboarding/index.d.ts +0 -5
  131. package/dist/onboarding/io.d.ts +0 -9
  132. package/dist/onboarding/steps.d.ts +0 -17
  133. package/dist/onboarding/types.d.ts +0 -81
  134. package/dist/plan/approve.d.ts +0 -16
  135. package/dist/plan/execute.d.ts +0 -28
  136. package/dist/plan/index.d.ts +0 -7
  137. package/dist/plan/policy.d.ts +0 -26
  138. package/dist/plan/render.d.ts +0 -5
  139. package/dist/plan/service.d.ts +0 -58
  140. package/dist/plan/submit-plan.d.ts +0 -33
  141. package/dist/plan/types.d.ts +0 -60
  142. package/dist/render/capabilities.d.ts +0 -31
  143. package/dist/render/diff.d.ts +0 -18
  144. package/dist/render/highlight.d.ts +0 -47
  145. package/dist/render/index.d.ts +0 -22
  146. package/dist/render/layout.d.ts +0 -59
  147. package/dist/render/motion.d.ts +0 -76
  148. package/dist/render/plain-renderer.d.ts +0 -39
  149. package/dist/render/resize.d.ts +0 -36
  150. package/dist/render/screen-reader-renderer.d.ts +0 -45
  151. package/dist/render/state.d.ts +0 -49
  152. package/dist/render/tty-renderer.d.ts +0 -106
  153. package/dist/render/types.d.ts +0 -201
  154. package/dist/routing/index.d.ts +0 -2
  155. package/dist/routing/resolve.d.ts +0 -17
  156. package/dist/routing/router.d.ts +0 -47
  157. package/dist/routing/types.d.ts +0 -42
  158. package/dist/sandbox/detect.d.ts +0 -22
  159. package/dist/sandbox/docker-runtime.d.ts +0 -32
  160. package/dist/sandbox/index.d.ts +0 -7
  161. package/dist/sandbox/policy.d.ts +0 -26
  162. package/dist/sandbox/service.d.ts +0 -64
  163. package/dist/sandbox/types.d.ts +0 -123
  164. package/dist/skills/index.d.ts +0 -4
  165. package/dist/skills/loader.d.ts +0 -43
  166. package/dist/skills/parser.d.ts +0 -31
  167. package/dist/skills/service.d.ts +0 -41
  168. package/dist/skills/types.d.ts +0 -94
  169. package/dist/subagent/index.d.ts +0 -5
  170. package/dist/subagent/orchestrator.d.ts +0 -169
  171. package/dist/subagent/registry-scope.d.ts +0 -41
  172. package/dist/subagent/semaphore.d.ts +0 -56
  173. package/dist/subagent/spawn-tool.d.ts +0 -86
  174. package/dist/subagent/types.d.ts +0 -65
  175. package/dist/testing/detect.d.ts +0 -3
  176. package/dist/testing/index.d.ts +0 -5
  177. package/dist/testing/parse.d.ts +0 -33
  178. package/dist/testing/run-tests-tool.d.ts +0 -64
  179. package/dist/testing/runner.d.ts +0 -26
  180. package/dist/testing/sandbox-runner.d.ts +0 -16
  181. package/dist/testing/types.d.ts +0 -66
  182. package/dist/theme/index.d.ts +0 -2
  183. package/dist/theme/resolve.d.ts +0 -43
  184. package/dist/theme/tokens.d.ts +0 -125
  185. package/dist/tools/create-pull-request.d.ts +0 -27
  186. package/dist/tools/file/apply-patch.d.ts +0 -94
  187. package/dist/tools/file/edit-file.d.ts +0 -12
  188. package/dist/tools/file/glob.d.ts +0 -17
  189. package/dist/tools/file/grep-files.d.ts +0 -43
  190. package/dist/tools/file/index.d.ts +0 -7
  191. package/dist/tools/file/match.d.ts +0 -43
  192. package/dist/tools/file/paths.d.ts +0 -160
  193. package/dist/tools/file/read-file.d.ts +0 -8
  194. package/dist/tools/file/write-file.d.ts +0 -10
  195. package/dist/tools/git-status.d.ts +0 -15
  196. package/dist/tools/index.d.ts +0 -9
  197. package/dist/tools/list-files.d.ts +0 -13
  198. package/dist/tools/list-skills.d.ts +0 -9
  199. package/dist/tools/load-skill.d.ts +0 -21
  200. package/dist/tools/registry.d.ts +0 -23
  201. package/dist/tools/search-codebase.d.ts +0 -35
  202. package/dist/tools/shell/exec.d.ts +0 -53
  203. package/dist/tools/shell/index.d.ts +0 -1
  204. package/dist/tools/shell/resolve-shell.d.ts +0 -81
  205. package/dist/tools/shell/run-command.d.ts +0 -14
  206. package/dist/tools/types.d.ts +0 -257
  207. package/dist/usage/collect.d.ts +0 -53
  208. package/dist/usage/cost.d.ts +0 -19
  209. package/dist/usage/index.d.ts +0 -15
  210. package/dist/usage/store.d.ts +0 -37
  211. package/dist/usage/summary.d.ts +0 -32
  212. package/dist/usage/types.d.ts +0 -283
  213. package/dist/utils/child-tree.d.ts +0 -33
  214. package/dist/utils/git.d.ts +0 -17
  215. package/dist/utils/logger.d.ts +0 -18
  216. package/dist/utils/process-tree.d.ts +0 -16
  217. package/dist/vcs/auth.d.ts +0 -22
  218. package/dist/vcs/generate.d.ts +0 -74
  219. package/dist/vcs/git.d.ts +0 -60
  220. package/dist/vcs/github.d.ts +0 -50
  221. package/dist/vcs/guidance.d.ts +0 -20
  222. package/dist/vcs/index.d.ts +0 -7
  223. package/dist/vcs/service.d.ts +0 -61
  224. package/dist/vcs/types.d.ts +0 -73
  225. package/dist/web/demarcate.d.ts +0 -13
  226. package/dist/web/fetch.d.ts +0 -11
  227. package/dist/web/index.d.ts +0 -7
  228. package/dist/web/provider.d.ts +0 -29
  229. package/dist/web/search.d.ts +0 -17
  230. package/dist/web/ssrf.d.ts +0 -41
  231. package/dist/web/tools.d.ts +0 -20
  232. package/dist/web/types.d.ts +0 -64
  233. package/dist/workspace/add-root.d.ts +0 -27
  234. package/dist/workspace/index.d.ts +0 -6
  235. package/dist/workspace/resolve.d.ts +0 -54
  236. package/dist/workspace/select.d.ts +0 -41
  237. package/dist/workspace/types.d.ts +0 -30
  238. 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,53 +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
- /**
15
- * Fold a streamed {@link Usage} event's cache counters into an accumulator.
16
- *
17
- * Phase-A prompt caching (Anthropic dev path only) reports `cache_read_*` /
18
- * `cache_creation_*` ONCE per request but echoes the same value on both the
19
- * `message_start` and terminal `message_delta` usage events — so we ASSIGN
20
- * (never `+=`) to avoid double-counting within a request. `undefined` is left
21
- * untouched: a provider that doesn't cache (the cruxy gateway, OpenAI-compat)
22
- * never sets these, so the accumulator's fields stay `undefined` — the honest
23
- * "unknown", never a fabricated `0`. A real reported `0` (cache in play, no read
24
- * this request) is captured as `0`.
25
- */
26
- export declare function accumulateCacheTokens(acc: Usage, ev: Usage): void;
27
- /** What the loop hands over for one completed request. */
28
- export interface RequestUsage {
29
- /** The routing tier (C.30) the request ran on, if routing was active. */
30
- tier?: string;
31
- /**
32
- * The provider's usage for THIS request, or `undefined` when the provider
33
- * emitted no usage event (⇒ tokens are unknown, not zero).
34
- */
35
- usage?: Usage;
36
- }
37
- /** Wall clock as an injectable seam so tests are deterministic. */
38
- export type Clock = () => string;
39
- export declare class UsageCollector {
40
- private readonly now;
41
- private readonly entries;
42
- constructor(now?: Clock);
43
- /**
44
- * Record one completed request. When `req.usage` is absent the entry's token
45
- * counts stay `undefined` — the provider reported nothing, so we assert
46
- * nothing. A real reported `0` is preserved as `0`.
47
- */
48
- record(req: RequestUsage): void;
49
- /** How many requests have been recorded so far. */
50
- get count(): number;
51
- /** Snapshot the collected entries into a persistable {@link UsageRecord}. */
52
- toRecord(runId: string, sessionId: string | undefined, startedAt: string): UsageRecord;
53
- }
@@ -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, accumulateCacheTokens, 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;