@cargo-ai/cli 1.0.77 → 1.0.80

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 (73) hide show
  1. package/README.md +12 -0
  2. package/build/commands/ai/chat.d.ts.map +1 -1
  3. package/build/commands/ai/chat.js +6 -0
  4. package/build/commands/ai/message.d.ts.map +1 -1
  5. package/build/commands/ai/message.js +10 -0
  6. package/build/commands/ai/release.d.ts.map +1 -1
  7. package/build/commands/ai/release.js +29 -2
  8. package/build/commands/ask/argvFlags.d.ts +18 -0
  9. package/build/commands/ask/argvFlags.d.ts.map +1 -0
  10. package/build/commands/ask/argvFlags.js +46 -0
  11. package/build/commands/ask/artifacts.d.ts +2 -0
  12. package/build/commands/ask/artifacts.d.ts.map +1 -0
  13. package/build/commands/ask/artifacts.js +100 -0
  14. package/build/commands/ask/binding.d.ts +13 -0
  15. package/build/commands/ask/binding.d.ts.map +1 -0
  16. package/build/commands/ask/binding.js +19 -0
  17. package/build/commands/ask/claudeConfig.d.ts +23 -0
  18. package/build/commands/ask/claudeConfig.d.ts.map +1 -0
  19. package/build/commands/ask/claudeConfig.js +33 -0
  20. package/build/commands/ask/completer.d.ts +48 -0
  21. package/build/commands/ask/completer.d.ts.map +1 -0
  22. package/build/commands/ask/completer.js +217 -0
  23. package/build/commands/ask/history.d.ts +32 -0
  24. package/build/commands/ask/history.d.ts.map +1 -0
  25. package/build/commands/ask/history.js +122 -0
  26. package/build/commands/ask/index.d.ts +14 -0
  27. package/build/commands/ask/index.d.ts.map +1 -0
  28. package/build/commands/ask/index.js +111 -0
  29. package/build/commands/ask/localHarness.d.ts +225 -0
  30. package/build/commands/ask/localHarness.d.ts.map +1 -0
  31. package/build/commands/ask/localHarness.js +1074 -0
  32. package/build/commands/ask/messageStream.d.ts +33 -0
  33. package/build/commands/ask/messageStream.d.ts.map +1 -0
  34. package/build/commands/ask/messageStream.js +114 -0
  35. package/build/commands/ask/persist.d.ts +5 -0
  36. package/build/commands/ask/persist.d.ts.map +1 -0
  37. package/build/commands/ask/persist.js +31 -0
  38. package/build/commands/ask/pnpmShim.d.ts +20 -0
  39. package/build/commands/ask/pnpmShim.d.ts.map +1 -0
  40. package/build/commands/ask/pnpmShim.js +39 -0
  41. package/build/commands/ask/prompt.d.ts +20 -0
  42. package/build/commands/ask/prompt.d.ts.map +1 -0
  43. package/build/commands/ask/prompt.js +228 -0
  44. package/build/commands/ask/rewriteChatFlag.d.ts +9 -0
  45. package/build/commands/ask/rewriteChatFlag.d.ts.map +1 -0
  46. package/build/commands/ask/rewriteChatFlag.js +26 -0
  47. package/build/commands/ask/session.d.ts +94 -0
  48. package/build/commands/ask/session.d.ts.map +1 -0
  49. package/build/commands/ask/session.js +965 -0
  50. package/build/commands/ask/slash.d.ts +20 -0
  51. package/build/commands/ask/slash.d.ts.map +1 -0
  52. package/build/commands/ask/slash.js +73 -0
  53. package/build/commands/ask/state.d.ts +9 -0
  54. package/build/commands/ask/state.d.ts.map +1 -0
  55. package/build/commands/ask/state.js +18 -0
  56. package/build/commands/bookDemo.d.ts +14 -0
  57. package/build/commands/bookDemo.d.ts.map +1 -0
  58. package/build/commands/bookDemo.js +100 -0
  59. package/build/commands/runHandler.d.ts +9 -1
  60. package/build/commands/runHandler.d.ts.map +1 -1
  61. package/build/commands/runHandler.js +16 -1
  62. package/build/index.js +56 -18
  63. package/build/paletteLayout.d.ts +6 -1
  64. package/build/paletteLayout.d.ts.map +1 -1
  65. package/build/paletteLayout.js +35 -9
  66. package/build/utils/cdkState.d.ts +17 -4
  67. package/build/utils/cdkState.d.ts.map +1 -1
  68. package/build/utils/cdkState.js +26 -4
  69. package/build/utils/loadCompiledAgent.d.ts.map +1 -1
  70. package/build/utils/loadCompiledAgent.js +51 -11
  71. package/build/utils/prompt.d.ts.map +1 -1
  72. package/build/utils/prompt.js +4 -1
  73. package/package.json +8 -4
@@ -0,0 +1,225 @@
1
+ import type { Api } from "../../api.js";
2
+ /**
3
+ * Always-on local-copy rails, plus CDK rails only when `dir` is a CDK project.
4
+ * Exported for tests.
5
+ */
6
+ export declare function localHarnessInstructions(dir: string): string;
7
+ /** Exported for tests. */
8
+ export declare function localHarnessSkills(dir: string): Array<{
9
+ name: string;
10
+ description: string;
11
+ content: string;
12
+ }>;
13
+ /**
14
+ * A built-in tool Claude Code wants to run that `permissionMode` does not
15
+ * auto-approve (anything that writes or shells out under `allow-reads`).
16
+ */
17
+ export type LocalToolApproval = {
18
+ approvalId: string;
19
+ toolCallId: string;
20
+ toolName: string;
21
+ /** Compact one-line rendering of the tool input, for the prompt. */
22
+ summary: string;
23
+ input: unknown;
24
+ };
25
+ /** A tool starting or finishing, so the caller can show what is happening. */
26
+ export type LocalToolActivity = {
27
+ kind: "start";
28
+ toolName: string;
29
+ summary: string;
30
+ } | {
31
+ kind: "end";
32
+ toolName: string;
33
+ isError: boolean;
34
+ };
35
+ export type LocalStreamHandlers = {
36
+ onTextDelta?: (delta: string) => void;
37
+ /**
38
+ * Decide whether the tool may run. Omitted (`--print`, non-interactive)
39
+ * means deny — the turn continues and the model reports what it could not
40
+ * do rather than silently running commands on the user's machine.
41
+ */
42
+ onApproval?: (approval: LocalToolApproval) => Promise<boolean>;
43
+ onActivity?: (activity: LocalToolActivity) => void;
44
+ /** Path of a file the turn wrote or edited, as the tool named it. */
45
+ onFileTouched?: (path: string) => void;
46
+ /** Something worth saying that is not part of the reply. */
47
+ onNotice?: (message: string) => void;
48
+ };
49
+ export type LocalStreamOptions = LocalStreamHandlers & {
50
+ /** Aborts the turn; the harness interrupts Claude Code gracefully. */
51
+ abortSignal?: AbortSignal;
52
+ };
53
+ /**
54
+ * What one turn spent upstream, summed over the streams a suspended turn is
55
+ * made of. `costUsd` is Claude Code's own accounting; the API prices it into
56
+ * credits so the CLI never states a credit count itself.
57
+ */
58
+ export type LocalTurnUsage = {
59
+ costUsd: number;
60
+ totalTokens: number;
61
+ inputTokens: number;
62
+ outputTokens: number;
63
+ cacheReadTokens: number;
64
+ cacheWriteTokens: number;
65
+ reasoningTokens: number;
66
+ };
67
+ /**
68
+ * Text and usage of a turn in progress, owned by the caller rather than by
69
+ * `runPromptTurn`: a cancelled or failed turn still spent those tokens, and
70
+ * they have to reach the API anyway.
71
+ */
72
+ export type LocalTurnAccumulator = {
73
+ chunks: string[];
74
+ usage: LocalTurnUsage;
75
+ };
76
+ /** Exported for tests. */
77
+ export declare function createTurnAccumulator(): LocalTurnAccumulator;
78
+ export type LocalHarnessHandle = {
79
+ streamPrompt: (question: string, options?: LocalStreamOptions) => Promise<string>;
80
+ /**
81
+ * When a turn last reached Anthropic, or undefined if none has. The proxy
82
+ * token re-arms on every call it makes, so this — not the mint time — is
83
+ * what its real expiry runs from.
84
+ */
85
+ proxyLastUsedAtMs: () => number | undefined;
86
+ /** Stops Claude Code and its bridge; the session is not resumable. */
87
+ close: () => Promise<void>;
88
+ };
89
+ /**
90
+ * The workspace half of local Ask: the hosted Cargo MCP server, reached
91
+ * through this CLI's own `mcp` bridge.
92
+ *
93
+ * Going through the bridge rather than configuring the HTTP endpoint directly
94
+ * is what keeps a long chat working — the bridge rebuilds the `Authorization`
95
+ * header per request from the same credentials every other command uses, so an
96
+ * OAuth session that expires mid-session renews instead of 401ing. `CARGO_BASE_URL`
97
+ * is pinned so the bridge cannot end up on a different API than this session.
98
+ *
99
+ * Everything the workspace can do arrives this way: actions, runs, models and
100
+ * SQL, the context, usage. That includes `execute_action`, which spends credits
101
+ * and writes to connected systems — see the approval note on
102
+ * `isAutoApproved`.
103
+ */
104
+ /**
105
+ * What Claude Code mounts this server as, and so the `mcp__<server>__` prefix
106
+ * its tools carry. Read by `isAutoApproved`, which trusts this server and no
107
+ * other — see the note there.
108
+ *
109
+ * Exported for tests.
110
+ */
111
+ export declare const CARGO_MCP_SERVER_NAME = "cargo";
112
+ type WorkspaceLayout = {
113
+ sandboxCwd: string;
114
+ /** `undefined` leaves the harness its per-session default. */
115
+ workDir: string | undefined;
116
+ };
117
+ /**
118
+ * Where to root the sandbox, and which directory inside it the session works in.
119
+ *
120
+ * The harness gives every session a work directory under the sandbox root and
121
+ * starts Claude Code there — `cwd: workdir` in the bridge — and it refuses to
122
+ * use the root itself. Rooted at the project, that means the agent begins in an
123
+ * empty `claude-code-<sessionId>` directory one level below the working copy it
124
+ * was asked about. Rooting at the project's parent instead makes the session
125
+ * work directory *be* the project, so the agent starts where the user is, and
126
+ * the harness's own artifacts land beside the project rather than in it.
127
+ *
128
+ * Falls back to the project when the parent cannot serve — a project at a
129
+ * filesystem root has no usable name, and a parent we cannot write to would
130
+ * fail the session at startup. The per-session directory returns in that case,
131
+ * and `pruneHarnessArtifacts` sweeps it once it is cold.
132
+ */
133
+ export declare function resolveWorkspaceLayout(dir: string): WorkspaceLayout;
134
+ export declare function createLocalHarness(input: {
135
+ api: Api;
136
+ /**
137
+ * Cargo API origin (`config.baseUrl`). The Anthropic proxy is mounted on
138
+ * the API as `/sandbox/anthropic` — same host the backend uses via
139
+ * `config.app.url` (which is the API URL, not the web app).
140
+ */
141
+ apiBaseUrl: string;
142
+ dir: string;
143
+ chatUuid: string;
144
+ agentUuid?: string;
145
+ proxyToken: string;
146
+ /**
147
+ * Earlier turns of this chat, from `loadChatHistoryPreamble`. The session is
148
+ * always new, so this is the only thing that carries a `--continue` chat
149
+ * across CLI runs.
150
+ */
151
+ history?: string;
152
+ /**
153
+ * The id the caller claimed the chat with. Sent with the ingest so recording
154
+ * a turn releases this session's claim and not one taken after it.
155
+ */
156
+ turnOwnerId?: string;
157
+ }): Promise<LocalHarnessHandle>;
158
+ export type StreamLike = {
159
+ fullStream: AsyncIterable<unknown>;
160
+ text: PromiseLike<string>;
161
+ };
162
+ type ApprovalContinuation = {
163
+ approvalResponse: {
164
+ type: "tool-approval-response";
165
+ approvalId: string;
166
+ approved: boolean;
167
+ reason?: string;
168
+ };
169
+ toolCall: {
170
+ type: "tool-call";
171
+ toolCallId: string;
172
+ toolName: string;
173
+ input: unknown;
174
+ };
175
+ };
176
+ /** The two harness calls a turn needs. Split out so tests can fake them. */
177
+ export type TurnDriver = {
178
+ start: () => Promise<StreamLike>;
179
+ continueWithApprovals: (continuations: readonly ApprovalContinuation[]) => Promise<StreamLike>;
180
+ };
181
+ /**
182
+ * Run one turn to completion, answering approval requests along the way.
183
+ *
184
+ * A turn suspends whenever Claude Code wants a tool `permissionMode` does not
185
+ * cover: the stream ends with the approvals still pending, and the turn only
186
+ * finishes once decisions are fed back in. Exported for tests.
187
+ */
188
+ export declare function runPromptTurn(input: {
189
+ driver: TurnDriver;
190
+ handlers: LocalStreamHandlers | undefined;
191
+ accumulator?: LocalTurnAccumulator;
192
+ /**
193
+ * Filled with approvals the harness asked about and drained as each is
194
+ * answered, so a turn that ends mid-question leaves the unanswered ones
195
+ * behind for the caller to deny.
196
+ */
197
+ unanswered?: LocalToolApproval[];
198
+ /** Overridden by tests; `Infinity` waits forever. */
199
+ stallTimeoutMs?: number;
200
+ }): Promise<string>;
201
+ /**
202
+ * The previous turn could not be wound down, so this session cannot take
203
+ * another prompt. Raised rather than pressed on with: the harness would either
204
+ * refuse the prompt itself or run it alongside the turn we failed to finish.
205
+ *
206
+ * The caller's recovery is to replace the session — nothing about a wedged
207
+ * runtime gets better by asking it again.
208
+ */
209
+ export declare class HarnessTurnStuck extends Error {
210
+ constructor();
211
+ }
212
+ /**
213
+ * Wait for `work`, but give up after `timeoutMs` rather than blocking a
214
+ * teardown forever. Resolves either way; the caller has already decided that
215
+ * an unfinished result is better than waiting.
216
+ *
217
+ * Exported for tests.
218
+ */
219
+ export declare function settleWithin(work: Promise<unknown>, timeoutMs: number): Promise<void>;
220
+ /** Exported for tests. */
221
+ export declare function isAutoApproved(toolName: string): boolean;
222
+ /** Exported for tests. */
223
+ export declare function isAlwaysDenied(toolName: string): boolean;
224
+ export {};
225
+ //# sourceMappingURL=localHarness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localHarness.d.ts","sourceRoot":"","sources":["../../../src/commands/ask/localHarness.ts"],"names":[],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