@useavalon/caelence-agent 0.1.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.
Files changed (161) hide show
  1. package/README.md +201 -0
  2. package/bin/harness.ts +10 -0
  3. package/package.json +75 -0
  4. package/skills/copy-editor/SKILL.md +74 -0
  5. package/skills/copy-editor/references/anti-slop.md +62 -0
  6. package/skills/copy-editor/references/ui-states.md +46 -0
  7. package/skills/copy-editor/scripts/lint-copy.py +78 -0
  8. package/skills/copy-harry-dry/SKILL.md +120 -0
  9. package/skills/copy-rmbc/SKILL.md +97 -0
  10. package/skills/copywriting/SKILL.md +73 -0
  11. package/skills/impeccable/SKILL.md +133 -0
  12. package/skills/impeccable/references/visual-slop.md +36 -0
  13. package/src/cli/main.test.ts +36 -0
  14. package/src/cli/main.ts +384 -0
  15. package/src/cli/media-models.ts +82 -0
  16. package/src/cli/models.ts +43 -0
  17. package/src/cli/openrouter-live.test.ts +35 -0
  18. package/src/cli/openrouter-live.ts +72 -0
  19. package/src/cli/openrouter-modality.test.ts +25 -0
  20. package/src/cli/openrouter-modality.ts +83 -0
  21. package/src/cli/picker.test.ts +53 -0
  22. package/src/cli/picker.ts +48 -0
  23. package/src/cli/plain-text.ts +15 -0
  24. package/src/cli/slash-dispatch.test.ts +213 -0
  25. package/src/cli/slash-dispatch.ts +298 -0
  26. package/src/cli/slash.test.ts +113 -0
  27. package/src/cli/slash.ts +119 -0
  28. package/src/cli/theme.test.ts +10 -0
  29. package/src/cli/theme.ts +44 -0
  30. package/src/cli/tui-layout.test.ts +33 -0
  31. package/src/cli/tui-layout.ts +33 -0
  32. package/src/cli/tui-screen.test.ts +33 -0
  33. package/src/cli/tui-screen.ts +13 -0
  34. package/src/cli/tui.tsx +735 -0
  35. package/src/config.ts +86 -0
  36. package/src/core/approval.test.ts +60 -0
  37. package/src/core/approval.ts +83 -0
  38. package/src/core/auto-router.test.ts +31 -0
  39. package/src/core/auto-router.ts +66 -0
  40. package/src/core/errors.ts +67 -0
  41. package/src/core/events.ts +85 -0
  42. package/src/core/hooks.test.ts +66 -0
  43. package/src/core/hooks.ts +94 -0
  44. package/src/core/ids.ts +6 -0
  45. package/src/core/instructions.test.ts +49 -0
  46. package/src/core/instructions.ts +44 -0
  47. package/src/core/logger.ts +45 -0
  48. package/src/core/mcp.ts +191 -0
  49. package/src/core/mode.test.ts +63 -0
  50. package/src/core/mode.ts +60 -0
  51. package/src/core/run-turn.test.ts +339 -0
  52. package/src/core/run-turn.ts +487 -0
  53. package/src/core/session.test.ts +203 -0
  54. package/src/core/session.ts +349 -0
  55. package/src/core/stdio-mcp.ts +143 -0
  56. package/src/core/strands.ts +262 -0
  57. package/src/core/usage.test.ts +69 -0
  58. package/src/core/usage.ts +171 -0
  59. package/src/desktop/bridge.test.ts +331 -0
  60. package/src/desktop/bridge.ts +729 -0
  61. package/src/desktop/open-local.test.ts +40 -0
  62. package/src/desktop/open-local.ts +52 -0
  63. package/src/desktop/preview-cache.test.ts +36 -0
  64. package/src/desktop/preview-cache.ts +63 -0
  65. package/src/desktop/secrets.test.ts +44 -0
  66. package/src/desktop/secrets.ts +60 -0
  67. package/src/evals/runner.test.ts +43 -0
  68. package/src/evals/runner.ts +225 -0
  69. package/src/index.ts +132 -0
  70. package/src/init.test.ts +54 -0
  71. package/src/init.ts +117 -0
  72. package/src/integrations/catalog-data.json +424 -0
  73. package/src/integrations/catalog.ts +81 -0
  74. package/src/integrations/connect.ts +231 -0
  75. package/src/integrations/integrations.test.ts +329 -0
  76. package/src/integrations/marks/airtable.svg +1 -0
  77. package/src/integrations/marks/algolia-mcp.svg +1 -0
  78. package/src/integrations/marks/canva.jpg +0 -0
  79. package/src/integrations/marks/cloudflare-mcp.svg +1 -0
  80. package/src/integrations/marks/contentful-mcp.svg +1 -0
  81. package/src/integrations/marks/craft.png +0 -0
  82. package/src/integrations/marks/dinero.png +0 -0
  83. package/src/integrations/marks/figma.svg +1 -0
  84. package/src/integrations/marks/gitlab.svg +1 -0
  85. package/src/integrations/marks/google-calendar.svg +1 -0
  86. package/src/integrations/marks/google-docs.svg +1 -0
  87. package/src/integrations/marks/google-drive.svg +1 -0
  88. package/src/integrations/marks/google-gmail.svg +1 -0
  89. package/src/integrations/marks/google-sheets.svg +1 -0
  90. package/src/integrations/marks/google-slides.svg +1 -0
  91. package/src/integrations/marks/granola.png +0 -0
  92. package/src/integrations/marks/jira.svg +1 -0
  93. package/src/integrations/marks/linear.svg +1 -0
  94. package/src/integrations/marks/microsoft-365.svg +7 -0
  95. package/src/integrations/marks/miro.svg +1 -0
  96. package/src/integrations/marks/mixpanel-mcp.svg +1 -0
  97. package/src/integrations/marks/monday.png +0 -0
  98. package/src/integrations/marks/mux-mcp.png +0 -0
  99. package/src/integrations/marks/neon-mcp.svg +1 -0
  100. package/src/integrations/marks/notion.svg +1 -0
  101. package/src/integrations/marks/paddle-mcp.svg +1 -0
  102. package/src/integrations/marks/posthog-mcp.svg +1 -0
  103. package/src/integrations/marks/prismic-mcp.svg +1 -0
  104. package/src/integrations/marks/replicate-mcp.svg +1 -0
  105. package/src/integrations/marks/resend-mcp.svg +1 -0
  106. package/src/integrations/marks/sanity-mcp.svg +1 -0
  107. package/src/integrations/marks/sceneplane.png +0 -0
  108. package/src/integrations/marks/sentry-mcp.svg +1 -0
  109. package/src/integrations/marks/stripe-mcp.svg +1 -0
  110. package/src/integrations/marks/supabase-mcp.svg +1 -0
  111. package/src/integrations/marks/upstash-mcp.svg +1 -0
  112. package/src/integrations/marks/vercel.svg +1 -0
  113. package/src/integrations/marks/webflow.svg +1 -0
  114. package/src/integrations/mcp-oauth.test.ts +39 -0
  115. package/src/integrations/mcp-oauth.ts +330 -0
  116. package/src/integrations/oauth-clients.test.ts +77 -0
  117. package/src/integrations/oauth-clients.ts +127 -0
  118. package/src/integrations/oauth.ts +145 -0
  119. package/src/integrations/remote-mcp.ts +307 -0
  120. package/src/integrations/store.ts +149 -0
  121. package/src/media/openrouter-generate.test.ts +80 -0
  122. package/src/media/openrouter-generate.ts +178 -0
  123. package/src/media/prefs.ts +54 -0
  124. package/src/observability/categories.ts +41 -0
  125. package/src/observability/create.test.ts +56 -0
  126. package/src/observability/create.ts +45 -0
  127. package/src/observability/experiments.ts +113 -0
  128. package/src/observability/fake.ts +191 -0
  129. package/src/observability/index.ts +57 -0
  130. package/src/observability/judges.ts +91 -0
  131. package/src/observability/langfuse.ts +275 -0
  132. package/src/observability/noop.ts +33 -0
  133. package/src/observability/observability.test.ts +113 -0
  134. package/src/observability/prompts.ts +98 -0
  135. package/src/observability/regression-items.ts +158 -0
  136. package/src/observability/sanitize.test.ts +26 -0
  137. package/src/observability/sanitize.ts +57 -0
  138. package/src/observability/types.ts +122 -0
  139. package/src/observability/version.ts +41 -0
  140. package/src/product.ts +2 -0
  141. package/src/runtime.test.ts +98 -0
  142. package/src/runtime.ts +438 -0
  143. package/src/skills/author-skill.ts +49 -0
  144. package/src/skills/create-skill.test.ts +108 -0
  145. package/src/skills/create-skill.ts +70 -0
  146. package/src/skills/loader.test.ts +122 -0
  147. package/src/skills/loader.ts +162 -0
  148. package/src/skills/registry.test.ts +190 -0
  149. package/src/skills/registry.ts +402 -0
  150. package/src/skills/skill-command.ts +53 -0
  151. package/src/skills/user-dir.ts +8 -0
  152. package/src/tools/git.test.ts +71 -0
  153. package/src/tools/git.ts +126 -0
  154. package/src/tools/local.ts +258 -0
  155. package/src/tools/paths.test.ts +24 -0
  156. package/src/tools/paths.ts +39 -0
  157. package/src/tools/read-skill.ts +43 -0
  158. package/src/tools/subagent.test.ts +77 -0
  159. package/src/tools/subagent.ts +74 -0
  160. package/src/tools/todo.test.ts +25 -0
  161. package/src/tools/todo.ts +70 -0
@@ -0,0 +1,331 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { DEFAULT_CONFIG } from "../config.ts";
6
+ import type { AgentEvent, MainModelProvider } from "../core/events.ts";
7
+ import type { ConstructAgent } from "../core/strands.ts";
8
+ import { noopObservability } from "../observability/noop.ts";
9
+ import { createHarness } from "../runtime.ts";
10
+ import { startDesktopBridge } from "./bridge.ts";
11
+
12
+ const fakeProvider: MainModelProvider = {
13
+ kind: "fake",
14
+ modelId: "fake",
15
+ async *stream() {
16
+ yield { type: "text_delta", text: "hello from the desk" };
17
+ yield { type: "done" };
18
+ },
19
+ };
20
+
21
+ async function withBridge(
22
+ openUrl?: (url: string) => void,
23
+ openPath?: (path: string, reveal: boolean) => void,
24
+ ) {
25
+ const cwd = await mkdtemp(join(tmpdir(), "harness-desk-"));
26
+ const prevHome = process.env.HARNESS_HOME;
27
+ process.env.HARNESS_HOME = join(cwd, "home");
28
+ const constructAgent: ConstructAgent = () => ({
29
+ async run(_message, emit) {
30
+ emit({ kind: "text_delta", text: "hello from the desk" } satisfies AgentEvent);
31
+ emit({ kind: "completion" });
32
+ },
33
+ });
34
+ const harness = await createHarness({
35
+ cwd,
36
+ config: { ...DEFAULT_CONFIG, name: "desk" },
37
+ provider: fakeProvider,
38
+ constructAgent,
39
+ observability: noopObservability,
40
+ });
41
+ const { ready, stop } = await startDesktopBridge({
42
+ cwd,
43
+ harness,
44
+ token: "test-token",
45
+ openUrl,
46
+ openPath,
47
+ });
48
+ const headers = { authorization: "Bearer test-token", "content-type": "application/json" };
49
+ return {
50
+ ready,
51
+ headers,
52
+ async close() {
53
+ await stop();
54
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
55
+ else process.env.HARNESS_HOME = prevHome;
56
+ await rm(cwd, { recursive: true, force: true });
57
+ },
58
+ };
59
+ }
60
+
61
+ describe("desktop bridge", () => {
62
+ test("rejects a missing token", async () => {
63
+ const ctx = await withBridge();
64
+ try {
65
+ const res = await fetch(`${ctx.ready.url}/state`);
66
+ expect(res.status).toBe(401);
67
+ } finally {
68
+ await ctx.close();
69
+ }
70
+ });
71
+
72
+ test("returns state and streams a turn", async () => {
73
+ const ctx = await withBridge();
74
+ try {
75
+ const state = await fetch(`${ctx.ready.url}/state`, { headers: ctx.headers });
76
+ expect(state.ok).toBe(true);
77
+ const body = (await state.json()) as { name: string };
78
+ expect(body.name).toBe("desk");
79
+
80
+ const turn = await fetch(`${ctx.ready.url}/turn`, {
81
+ method: "POST",
82
+ headers: ctx.headers,
83
+ body: JSON.stringify({ message: "hi" }),
84
+ });
85
+ expect(turn.ok).toBe(true);
86
+ expect(turn.headers.get("content-type")).toContain("text/event-stream");
87
+ const text = await turn.text();
88
+ expect(text).toContain("hello from the desk");
89
+ expect(text).toContain("completion");
90
+ } finally {
91
+ await ctx.close();
92
+ }
93
+ });
94
+
95
+ test("transcribe rejects an empty recording", async () => {
96
+ const ctx = await withBridge();
97
+ try {
98
+ const res = await fetch(`${ctx.ready.url}/transcribe`, {
99
+ method: "POST",
100
+ headers: ctx.headers,
101
+ body: JSON.stringify({ data: "", format: "webm" }),
102
+ });
103
+ expect(res.status).toBe(400);
104
+ } finally {
105
+ await ctx.close();
106
+ }
107
+ });
108
+
109
+ test("settings reports and stores an api key without echoing it", async () => {
110
+ const home = await mkdtemp(join(tmpdir(), "harness-settings-"));
111
+ const prevHome = process.env.HARNESS_HOME;
112
+ const prevKey = process.env.OPENROUTER_API_KEY;
113
+ delete process.env.OPENROUTER_API_KEY;
114
+ process.env.HARNESS_HOME = home;
115
+ const ctx = await withBridge();
116
+ try {
117
+ const before = await fetch(`${ctx.ready.url}/settings`, { headers: ctx.headers });
118
+ const empty = (await before.json()) as { hasApiKey: boolean; apiKeyHint: string };
119
+ expect(empty.hasApiKey).toBe(false);
120
+
121
+ const saved = await fetch(`${ctx.ready.url}/settings`, {
122
+ method: "POST",
123
+ headers: ctx.headers,
124
+ body: JSON.stringify({ apiKey: "sk-or-v1-secretkey" }),
125
+ });
126
+ const body = (await saved.json()) as { hasApiKey: boolean; apiKeyHint: string };
127
+ expect(body.hasApiKey).toBe(true);
128
+ expect(body.apiKeyHint).toBe("••••tkey");
129
+ expect(JSON.stringify(body)).not.toContain("sk-or-v1-secretkey");
130
+ } finally {
131
+ await ctx.close();
132
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
133
+ else process.env.HARNESS_HOME = prevHome;
134
+ if (prevKey === undefined) delete process.env.OPENROUTER_API_KEY;
135
+ else process.env.OPENROUTER_API_KEY = prevKey;
136
+ await rm(home, { recursive: true, force: true });
137
+ }
138
+ });
139
+
140
+ test("settings stores a Google OAuth client without echoing the secret", async () => {
141
+ const home = await mkdtemp(join(tmpdir(), "harness-google-oauth-"));
142
+ const prevHome = process.env.HARNESS_HOME;
143
+ process.env.HARNESS_HOME = home;
144
+ const ctx = await withBridge();
145
+ try {
146
+ const saved = await fetch(`${ctx.ready.url}/settings`, {
147
+ method: "POST",
148
+ headers: ctx.headers,
149
+ body: JSON.stringify({
150
+ googleClientId: "abc.apps.googleusercontent.com",
151
+ googleClientSecret: "gsecret-value",
152
+ }),
153
+ });
154
+ const body = (await saved.json()) as {
155
+ hasGoogleOAuth: boolean;
156
+ googleOAuthHint: string;
157
+ };
158
+ expect(body.hasGoogleOAuth).toBe(true);
159
+ expect(body.googleOAuthHint).toBe("••••.com");
160
+ expect(JSON.stringify(body)).not.toContain("gsecret-value");
161
+ } finally {
162
+ await ctx.close();
163
+ if (prevHome === undefined) delete process.env.HARNESS_HOME;
164
+ else process.env.HARNESS_HOME = prevHome;
165
+ await rm(home, { recursive: true, force: true });
166
+ }
167
+ });
168
+
169
+ test("slash help stays off the model", async () => {
170
+ const ctx = await withBridge();
171
+ try {
172
+ const res = await fetch(`${ctx.ready.url}/turn`, {
173
+ method: "POST",
174
+ headers: ctx.headers,
175
+ body: JSON.stringify({ message: "/help" }),
176
+ });
177
+ const body = (await res.json()) as { outcome: { kind: string; text?: string } };
178
+ expect(body.outcome.kind).toBe("text");
179
+ expect(body.outcome.text).toContain("/resume");
180
+ } finally {
181
+ await ctx.close();
182
+ }
183
+ });
184
+
185
+ test("lists MCP integrations without tokens", async () => {
186
+ const ctx = await withBridge();
187
+ try {
188
+ const res = await fetch(`${ctx.ready.url}/integrations`, { headers: ctx.headers });
189
+ expect(res.ok).toBe(true);
190
+ const body = (await res.json()) as {
191
+ items: Array<{ id: string; label: string; connected: boolean }>;
192
+ };
193
+ expect(body.items.some((item) => item.id === "linear" && item.label === "Linear")).toBe(true);
194
+ expect(body.items.every((item) => item.connected === false)).toBe(true);
195
+ expect(JSON.stringify(body)).not.toContain("accessToken");
196
+ } finally {
197
+ await ctx.close();
198
+ }
199
+ });
200
+
201
+ test("opens http links and rejects other schemes", async () => {
202
+ const opened: string[] = [];
203
+ const ctx = await withBridge((url) => opened.push(url));
204
+ try {
205
+ const ok = await fetch(`${ctx.ready.url}/open`, {
206
+ method: "POST",
207
+ headers: ctx.headers,
208
+ body: JSON.stringify({ url: "https://www.canva.com/d/abc" }),
209
+ });
210
+ expect(ok.ok).toBe(true);
211
+ expect(opened).toEqual(["https://www.canva.com/d/abc"]);
212
+
213
+ const bad = await fetch(`${ctx.ready.url}/open`, {
214
+ method: "POST",
215
+ headers: ctx.headers,
216
+ body: JSON.stringify({ url: "javascript:alert(1)" }),
217
+ });
218
+ expect(bad.status).toBe(400);
219
+ expect(opened).toHaveLength(1);
220
+ } finally {
221
+ await ctx.close();
222
+ }
223
+ });
224
+
225
+ test("opens a local path", async () => {
226
+ const opened: Array<{ path: string; reveal: boolean }> = [];
227
+ const ctx = await withBridge(undefined, (path, reveal) => opened.push({ path, reveal }));
228
+ try {
229
+ const file = join(tmpdir(), `harness-open-file-${Date.now()}.txt`);
230
+ await writeFile(file, "ok");
231
+ try {
232
+ const ok = await fetch(`${ctx.ready.url}/open-path`, {
233
+ method: "POST",
234
+ headers: ctx.headers,
235
+ body: JSON.stringify({ path: file, reveal: true }),
236
+ });
237
+ expect(ok.ok).toBe(true);
238
+ expect(opened).toEqual([{ path: file, reveal: true }]);
239
+ } finally {
240
+ await rm(file, { force: true });
241
+ }
242
+ } finally {
243
+ await ctx.close();
244
+ }
245
+ });
246
+
247
+ test("rejects a missing local path", async () => {
248
+ const ctx = await withBridge();
249
+ try {
250
+ const missing = await fetch(`${ctx.ready.url}/open-path`, {
251
+ method: "POST",
252
+ headers: ctx.headers,
253
+ body: JSON.stringify({ path: "/no/such/caelence-file.txt" }),
254
+ });
255
+ expect(missing.status).toBe(400);
256
+ const body = (await missing.json()) as { error?: string };
257
+ expect(body.error).toBe("File is missing.");
258
+ } finally {
259
+ await ctx.close();
260
+ }
261
+ });
262
+
263
+ test("embed rejects local and non-http urls", async () => {
264
+ const ctx = await withBridge();
265
+ try {
266
+ const local = await fetch(`${ctx.ready.url}/embed`, {
267
+ method: "POST",
268
+ headers: ctx.headers,
269
+ body: JSON.stringify({ url: "http://127.0.0.1/secret" }),
270
+ });
271
+ expect(local.status).toBe(400);
272
+ const bad = await fetch(`${ctx.ready.url}/embed`, {
273
+ method: "POST",
274
+ headers: ctx.headers,
275
+ body: JSON.stringify({ url: "javascript:alert(1)" }),
276
+ });
277
+ expect(bad.status).toBe(400);
278
+ } finally {
279
+ await ctx.close();
280
+ }
281
+ });
282
+
283
+ test("renames and deletes a session", async () => {
284
+ const ctx = await withBridge();
285
+ try {
286
+ const turn = await fetch(`${ctx.ready.url}/turn`, {
287
+ method: "POST",
288
+ headers: ctx.headers,
289
+ body: JSON.stringify({ message: "hello world" }),
290
+ });
291
+ expect(turn.ok).toBe(true);
292
+ await turn.text();
293
+ const listed = await fetch(`${ctx.ready.url}/sessions`, { headers: ctx.headers });
294
+ const before = (await listed.json()) as { items: Array<{ id: string; label: string }> };
295
+ expect(before.items).toHaveLength(1);
296
+ const id = before.items[0]?.id ?? "";
297
+ expect(id).toBeTruthy();
298
+
299
+ const empty = await fetch(`${ctx.ready.url}/session`, {
300
+ method: "POST",
301
+ headers: ctx.headers,
302
+ body: JSON.stringify({ id, title: " " }),
303
+ });
304
+ expect(empty.status).toBe(400);
305
+
306
+ const renamed = await fetch(`${ctx.ready.url}/session`, {
307
+ method: "POST",
308
+ headers: ctx.headers,
309
+ body: JSON.stringify({ id, title: " Billing copy " }),
310
+ });
311
+ const renamedBody = (await renamed.json()) as { title: string };
312
+ expect(renamedBody.title).toBe("Billing copy");
313
+ const afterRename = await fetch(`${ctx.ready.url}/sessions`, { headers: ctx.headers });
314
+ const renamedList = (await afterRename.json()) as { items: Array<{ label: string }> };
315
+ expect(renamedList.items[0]?.label).toBe("Billing copy");
316
+
317
+ const deleted = await fetch(`${ctx.ready.url}/session`, {
318
+ method: "POST",
319
+ headers: ctx.headers,
320
+ body: JSON.stringify({ id, delete: true }),
321
+ });
322
+ const deletedBody = (await deleted.json()) as { cleared: boolean };
323
+ expect(deletedBody.cleared).toBe(true);
324
+ const afterDelete = await fetch(`${ctx.ready.url}/sessions`, { headers: ctx.headers });
325
+ const emptyList = (await afterDelete.json()) as { items: unknown[] };
326
+ expect(emptyList.items).toEqual([]);
327
+ } finally {
328
+ await ctx.close();
329
+ }
330
+ });
331
+ });