@useavalon/caelence-agent 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -8
- package/desktop/src/api.ts +1 -0
- package/desktop/src/desktop-turn.ts +7 -0
- package/desktop/src/stream.ts +1 -0
- package/desktop/src/thought.test.ts +16 -0
- package/desktop/src/thought.ts +15 -4
- package/desktop/src/turn-verbs.ts +14 -0
- package/package.json +12 -4
- package/src/browser/browser-use.test.ts +54 -2
- package/src/browser/browser-use.ts +75 -3
- package/src/browser/own-chrome.test.ts +593 -0
- package/src/browser/own-chrome.ts +542 -0
- package/src/cli/tui-progress.ts +15 -3
- package/src/cli/tui.tsx +7 -0
- package/src/config.ts +31 -2
- package/src/core/approval.test.ts +126 -0
- package/src/core/approval.ts +17 -0
- package/src/core/events.ts +12 -1
- package/src/core/host-extensions.test.ts +605 -0
- package/src/core/mcp.ts +7 -0
- package/src/core/mode.ts +5 -0
- package/src/core/run-turn.test.ts +85 -0
- package/src/core/run-turn.ts +145 -28
- package/src/core/strands.test.ts +89 -0
- package/src/core/strands.ts +3 -1
- package/src/decisions/shortcuts.ts +5 -0
- package/src/desktop/bridge.ts +66 -12
- package/src/desktop/host.test.ts +244 -0
- package/src/desktop/host.ts +59 -0
- package/src/index.ts +122 -4
- package/src/memory/brief.ts +62 -0
- package/src/memory/embeddings.ts +104 -0
- package/src/memory/extract.ts +9 -8
- package/src/memory/layered.test.ts +202 -0
- package/src/memory/layered.ts +125 -0
- package/src/memory/memory-store.test.ts +299 -0
- package/src/memory/memory-store.ts +295 -0
- package/src/memory/store.ts +70 -20
- package/src/observability/langfuse.ts +9 -2
- package/src/observability/types.ts +5 -0
- package/src/runtime.ts +253 -53
- package/src/status/categories.ts +64 -0
- package/src/status/default-verbs.ts +190 -0
- package/src/status/status-verb-categories.json +6167 -0
- package/src/status/status-verbs.test.ts +209 -0
- package/src/status/status-verbs.ts +62 -0
- package/src/tools/background.test.ts +304 -0
- package/src/tools/background.ts +432 -0
- package/src/tools/memory.ts +94 -0
|
@@ -122,3 +122,129 @@ describe("exec approval", () => {
|
|
|
122
122
|
expect(input.path).toBe("/tmp/note.txt");
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
|
+
|
|
126
|
+
describe("promptOnly", () => {
|
|
127
|
+
const deletes = (req: { input: Record<string, unknown> }) =>
|
|
128
|
+
/\brm\b/.test(String(req.input.command ?? ""));
|
|
129
|
+
|
|
130
|
+
test("requests it rejects run without asking", async () => {
|
|
131
|
+
let asked = 0;
|
|
132
|
+
const gate = createExecApprovalGate({
|
|
133
|
+
policy: "prompt",
|
|
134
|
+
ask: async () => {
|
|
135
|
+
asked += 1;
|
|
136
|
+
return false;
|
|
137
|
+
},
|
|
138
|
+
promptOnly: deletes,
|
|
139
|
+
});
|
|
140
|
+
expect(
|
|
141
|
+
await gate.request({ callId: "1", toolName: "exec", input: { command: "bun test" } }),
|
|
142
|
+
).toBe(true);
|
|
143
|
+
expect(await gate.request({ callId: "2", toolName: "write_file", input: { path: "a" } })).toBe(
|
|
144
|
+
true,
|
|
145
|
+
);
|
|
146
|
+
expect(asked).toBe(0);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("requests it accepts still ask", async () => {
|
|
150
|
+
let asked = 0;
|
|
151
|
+
const gate = createExecApprovalGate({
|
|
152
|
+
policy: "prompt",
|
|
153
|
+
ask: async () => {
|
|
154
|
+
asked += 1;
|
|
155
|
+
return false;
|
|
156
|
+
},
|
|
157
|
+
promptOnly: deletes,
|
|
158
|
+
});
|
|
159
|
+
expect(
|
|
160
|
+
await gate.request({ callId: "3", toolName: "exec", input: { command: "rm -rf dist" } }),
|
|
161
|
+
).toBe(false);
|
|
162
|
+
expect(asked).toBe(1);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("the deny policy still refuses what it lets through", async () => {
|
|
166
|
+
const gate = createExecApprovalGate({ policy: "deny", promptOnly: deletes });
|
|
167
|
+
expect(await gate.request({ callId: "4", toolName: "exec", input: { command: "rm x" } })).toBe(
|
|
168
|
+
false,
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("confirm requests (a tool asked for a human on this call)", () => {
|
|
174
|
+
const confirmReq = {
|
|
175
|
+
callId: "c1",
|
|
176
|
+
toolName: "browser_click",
|
|
177
|
+
input: { element: "Post button" },
|
|
178
|
+
reason: "Click the Post button",
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
test("always ask, even under promptOnly, always-allow, and the auto policy", async () => {
|
|
182
|
+
for (const policy of ["prompt", "auto"] as const) {
|
|
183
|
+
let asked = 0;
|
|
184
|
+
let assisted = 0;
|
|
185
|
+
const gate = createExecApprovalGate({
|
|
186
|
+
policy,
|
|
187
|
+
alwaysAllow: new Set(["browser_click"]),
|
|
188
|
+
promptOnly: () => false,
|
|
189
|
+
assist: async () => {
|
|
190
|
+
assisted += 1;
|
|
191
|
+
return "allow";
|
|
192
|
+
},
|
|
193
|
+
ask: async () => {
|
|
194
|
+
asked += 1;
|
|
195
|
+
return false;
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
expect(await gate.request(confirmReq)).toBe(false);
|
|
199
|
+
expect(asked).toBe(1);
|
|
200
|
+
expect(assisted).toBe(0);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("the deny policy refuses without asking", async () => {
|
|
205
|
+
let asked = 0;
|
|
206
|
+
const gate = createExecApprovalGate({
|
|
207
|
+
policy: "deny",
|
|
208
|
+
ask: async () => {
|
|
209
|
+
asked += 1;
|
|
210
|
+
return true;
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
expect(await gate.request(confirmReq)).toBe(false);
|
|
214
|
+
expect(asked).toBe(0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("with nobody to ask, the answer is no", async () => {
|
|
218
|
+
const gate = createExecApprovalGate({ policy: "prompt" });
|
|
219
|
+
expect(await gate.request(confirmReq)).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("the reason reaches the approval card", async () => {
|
|
223
|
+
const events: unknown[] = [];
|
|
224
|
+
const gate = createExecApprovalGate({
|
|
225
|
+
policy: "prompt",
|
|
226
|
+
emit: (event) => events.push(event),
|
|
227
|
+
ask: async () => true,
|
|
228
|
+
});
|
|
229
|
+
expect(await gate.request(confirmReq)).toBe(true);
|
|
230
|
+
expect(events[0]).toMatchObject({
|
|
231
|
+
kind: "approval_request",
|
|
232
|
+
toolName: "browser_click",
|
|
233
|
+
reason: "Click the Post button",
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test("a yes covers one call only", async () => {
|
|
238
|
+
let asked = 0;
|
|
239
|
+
const gate = createExecApprovalGate({
|
|
240
|
+
policy: "prompt",
|
|
241
|
+
ask: async () => {
|
|
242
|
+
asked += 1;
|
|
243
|
+
return true;
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
await gate.request(confirmReq);
|
|
247
|
+
await gate.request({ ...confirmReq, callId: "c2" });
|
|
248
|
+
expect(asked).toBe(2);
|
|
249
|
+
});
|
|
250
|
+
});
|
package/src/core/approval.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface ApprovalRequest {
|
|
|
6
6
|
callId: string;
|
|
7
7
|
toolName: string;
|
|
8
8
|
input: Record<string, unknown>;
|
|
9
|
+
/** Why the tool asked for approval, in words the user can act on. Set by `confirm`. */
|
|
10
|
+
reason?: string;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export interface ApprovalGate {
|
|
@@ -72,6 +74,13 @@ export interface ExecApprovalGateDeps {
|
|
|
72
74
|
* prompt and can never deny. Must not throw; a throw or "ask" falls through to the prompt.
|
|
73
75
|
*/
|
|
74
76
|
assist?: (req: ApprovalRequest) => Promise<"allow" | "ask">;
|
|
77
|
+
/**
|
|
78
|
+
* When set, only requests this returns true for go through the normal approval path. Every
|
|
79
|
+
* other request runs without a prompt. Use it for a host that wants fewer prompts, such as
|
|
80
|
+
* asking only before deletions. The `deny` policy and the host denylist still apply to the
|
|
81
|
+
* requests it lets through.
|
|
82
|
+
*/
|
|
83
|
+
promptOnly?: (req: ApprovalRequest) => boolean;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
async function promptAsk(deps: ExecApprovalGateDeps, req: ApprovalRequest): Promise<boolean> {
|
|
@@ -80,6 +89,7 @@ async function promptAsk(deps: ExecApprovalGateDeps, req: ApprovalRequest): Prom
|
|
|
80
89
|
callId: req.callId,
|
|
81
90
|
toolName: req.toolName,
|
|
82
91
|
input: req.input,
|
|
92
|
+
...(req.reason ? { reason: req.reason } : {}),
|
|
83
93
|
});
|
|
84
94
|
if (!deps.ask) return false;
|
|
85
95
|
return deps.ask(req);
|
|
@@ -100,6 +110,13 @@ export function createExecApprovalGate(deps: ExecApprovalGateDeps): ApprovalGate
|
|
|
100
110
|
const always = deps.alwaysAllow ?? new Set<string>();
|
|
101
111
|
return {
|
|
102
112
|
async request(req) {
|
|
113
|
+
// A tool asked for a human on this call. Nothing else may answer for the user: not
|
|
114
|
+
// promptOnly, "always allow", the auto policy, or the decision-model assist.
|
|
115
|
+
if (req.reason) {
|
|
116
|
+
if (deps.policy === "deny") return false;
|
|
117
|
+
return promptAsk(deps, req);
|
|
118
|
+
}
|
|
119
|
+
if (deps.promptOnly && !deps.promptOnly(req)) return true;
|
|
103
120
|
if (isFileWriteTool(req.toolName) && deps.resolveUploadEdit) {
|
|
104
121
|
const path = typeof req.input.path === "string" ? req.input.path : "";
|
|
105
122
|
const hit = deps.resolveUploadEdit(path);
|
package/src/core/events.ts
CHANGED
|
@@ -15,8 +15,19 @@ export type AgentEvent =
|
|
|
15
15
|
output?: string;
|
|
16
16
|
error?: string;
|
|
17
17
|
}
|
|
18
|
-
| {
|
|
18
|
+
| {
|
|
19
|
+
kind: "approval_request";
|
|
20
|
+
callId: string;
|
|
21
|
+
toolName: string;
|
|
22
|
+
input: Record<string, unknown>;
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
19
25
|
| { kind: "session_meta"; sessionId: string; title: string }
|
|
26
|
+
/**
|
|
27
|
+
* Sent once at the start of a turn: the verbs a UI rotates through while the agent is thinking
|
|
28
|
+
* ("Pondering", "Brewing"). A UI that ignores it shows its own plain label.
|
|
29
|
+
*/
|
|
30
|
+
| { kind: "status"; verbs: string[] }
|
|
20
31
|
| {
|
|
21
32
|
kind: "usage";
|
|
22
33
|
promptTokens: number;
|