@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.
- package/README.md +201 -0
- package/bin/harness.ts +10 -0
- package/package.json +75 -0
- package/skills/copy-editor/SKILL.md +74 -0
- package/skills/copy-editor/references/anti-slop.md +62 -0
- package/skills/copy-editor/references/ui-states.md +46 -0
- package/skills/copy-editor/scripts/lint-copy.py +78 -0
- package/skills/copy-harry-dry/SKILL.md +120 -0
- package/skills/copy-rmbc/SKILL.md +97 -0
- package/skills/copywriting/SKILL.md +73 -0
- package/skills/impeccable/SKILL.md +133 -0
- package/skills/impeccable/references/visual-slop.md +36 -0
- package/src/cli/main.test.ts +36 -0
- package/src/cli/main.ts +384 -0
- package/src/cli/media-models.ts +82 -0
- package/src/cli/models.ts +43 -0
- package/src/cli/openrouter-live.test.ts +35 -0
- package/src/cli/openrouter-live.ts +72 -0
- package/src/cli/openrouter-modality.test.ts +25 -0
- package/src/cli/openrouter-modality.ts +83 -0
- package/src/cli/picker.test.ts +53 -0
- package/src/cli/picker.ts +48 -0
- package/src/cli/plain-text.ts +15 -0
- package/src/cli/slash-dispatch.test.ts +213 -0
- package/src/cli/slash-dispatch.ts +298 -0
- package/src/cli/slash.test.ts +113 -0
- package/src/cli/slash.ts +119 -0
- package/src/cli/theme.test.ts +10 -0
- package/src/cli/theme.ts +44 -0
- package/src/cli/tui-layout.test.ts +33 -0
- package/src/cli/tui-layout.ts +33 -0
- package/src/cli/tui-screen.test.ts +33 -0
- package/src/cli/tui-screen.ts +13 -0
- package/src/cli/tui.tsx +735 -0
- package/src/config.ts +86 -0
- package/src/core/approval.test.ts +60 -0
- package/src/core/approval.ts +83 -0
- package/src/core/auto-router.test.ts +31 -0
- package/src/core/auto-router.ts +66 -0
- package/src/core/errors.ts +67 -0
- package/src/core/events.ts +85 -0
- package/src/core/hooks.test.ts +66 -0
- package/src/core/hooks.ts +94 -0
- package/src/core/ids.ts +6 -0
- package/src/core/instructions.test.ts +49 -0
- package/src/core/instructions.ts +44 -0
- package/src/core/logger.ts +45 -0
- package/src/core/mcp.ts +191 -0
- package/src/core/mode.test.ts +63 -0
- package/src/core/mode.ts +60 -0
- package/src/core/run-turn.test.ts +339 -0
- package/src/core/run-turn.ts +487 -0
- package/src/core/session.test.ts +203 -0
- package/src/core/session.ts +349 -0
- package/src/core/stdio-mcp.ts +143 -0
- package/src/core/strands.ts +262 -0
- package/src/core/usage.test.ts +69 -0
- package/src/core/usage.ts +171 -0
- package/src/desktop/bridge.test.ts +331 -0
- package/src/desktop/bridge.ts +729 -0
- package/src/desktop/open-local.test.ts +40 -0
- package/src/desktop/open-local.ts +52 -0
- package/src/desktop/preview-cache.test.ts +36 -0
- package/src/desktop/preview-cache.ts +63 -0
- package/src/desktop/secrets.test.ts +44 -0
- package/src/desktop/secrets.ts +60 -0
- package/src/evals/runner.test.ts +43 -0
- package/src/evals/runner.ts +225 -0
- package/src/index.ts +132 -0
- package/src/init.test.ts +54 -0
- package/src/init.ts +117 -0
- package/src/integrations/catalog-data.json +424 -0
- package/src/integrations/catalog.ts +81 -0
- package/src/integrations/connect.ts +231 -0
- package/src/integrations/integrations.test.ts +329 -0
- package/src/integrations/marks/airtable.svg +1 -0
- package/src/integrations/marks/algolia-mcp.svg +1 -0
- package/src/integrations/marks/canva.jpg +0 -0
- package/src/integrations/marks/cloudflare-mcp.svg +1 -0
- package/src/integrations/marks/contentful-mcp.svg +1 -0
- package/src/integrations/marks/craft.png +0 -0
- package/src/integrations/marks/dinero.png +0 -0
- package/src/integrations/marks/figma.svg +1 -0
- package/src/integrations/marks/gitlab.svg +1 -0
- package/src/integrations/marks/google-calendar.svg +1 -0
- package/src/integrations/marks/google-docs.svg +1 -0
- package/src/integrations/marks/google-drive.svg +1 -0
- package/src/integrations/marks/google-gmail.svg +1 -0
- package/src/integrations/marks/google-sheets.svg +1 -0
- package/src/integrations/marks/google-slides.svg +1 -0
- package/src/integrations/marks/granola.png +0 -0
- package/src/integrations/marks/jira.svg +1 -0
- package/src/integrations/marks/linear.svg +1 -0
- package/src/integrations/marks/microsoft-365.svg +7 -0
- package/src/integrations/marks/miro.svg +1 -0
- package/src/integrations/marks/mixpanel-mcp.svg +1 -0
- package/src/integrations/marks/monday.png +0 -0
- package/src/integrations/marks/mux-mcp.png +0 -0
- package/src/integrations/marks/neon-mcp.svg +1 -0
- package/src/integrations/marks/notion.svg +1 -0
- package/src/integrations/marks/paddle-mcp.svg +1 -0
- package/src/integrations/marks/posthog-mcp.svg +1 -0
- package/src/integrations/marks/prismic-mcp.svg +1 -0
- package/src/integrations/marks/replicate-mcp.svg +1 -0
- package/src/integrations/marks/resend-mcp.svg +1 -0
- package/src/integrations/marks/sanity-mcp.svg +1 -0
- package/src/integrations/marks/sceneplane.png +0 -0
- package/src/integrations/marks/sentry-mcp.svg +1 -0
- package/src/integrations/marks/stripe-mcp.svg +1 -0
- package/src/integrations/marks/supabase-mcp.svg +1 -0
- package/src/integrations/marks/upstash-mcp.svg +1 -0
- package/src/integrations/marks/vercel.svg +1 -0
- package/src/integrations/marks/webflow.svg +1 -0
- package/src/integrations/mcp-oauth.test.ts +39 -0
- package/src/integrations/mcp-oauth.ts +330 -0
- package/src/integrations/oauth-clients.test.ts +77 -0
- package/src/integrations/oauth-clients.ts +127 -0
- package/src/integrations/oauth.ts +145 -0
- package/src/integrations/remote-mcp.ts +307 -0
- package/src/integrations/store.ts +149 -0
- package/src/media/openrouter-generate.test.ts +80 -0
- package/src/media/openrouter-generate.ts +178 -0
- package/src/media/prefs.ts +54 -0
- package/src/observability/categories.ts +41 -0
- package/src/observability/create.test.ts +56 -0
- package/src/observability/create.ts +45 -0
- package/src/observability/experiments.ts +113 -0
- package/src/observability/fake.ts +191 -0
- package/src/observability/index.ts +57 -0
- package/src/observability/judges.ts +91 -0
- package/src/observability/langfuse.ts +275 -0
- package/src/observability/noop.ts +33 -0
- package/src/observability/observability.test.ts +113 -0
- package/src/observability/prompts.ts +98 -0
- package/src/observability/regression-items.ts +158 -0
- package/src/observability/sanitize.test.ts +26 -0
- package/src/observability/sanitize.ts +57 -0
- package/src/observability/types.ts +122 -0
- package/src/observability/version.ts +41 -0
- package/src/product.ts +2 -0
- package/src/runtime.test.ts +98 -0
- package/src/runtime.ts +438 -0
- package/src/skills/author-skill.ts +49 -0
- package/src/skills/create-skill.test.ts +108 -0
- package/src/skills/create-skill.ts +70 -0
- package/src/skills/loader.test.ts +122 -0
- package/src/skills/loader.ts +162 -0
- package/src/skills/registry.test.ts +190 -0
- package/src/skills/registry.ts +402 -0
- package/src/skills/skill-command.ts +53 -0
- package/src/skills/user-dir.ts +8 -0
- package/src/tools/git.test.ts +71 -0
- package/src/tools/git.ts +126 -0
- package/src/tools/local.ts +258 -0
- package/src/tools/paths.test.ts +24 -0
- package/src/tools/paths.ts +39 -0
- package/src/tools/read-skill.ts +43 -0
- package/src/tools/subagent.test.ts +77 -0
- package/src/tools/subagent.ts +74 -0
- package/src/tools/todo.test.ts +25 -0
- package/src/tools/todo.ts +70 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { ExperimentItem } from "./experiments.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Seed cases for `website-generation-regression`. Expected output is
|
|
5
|
+
* characteristics only — no invented metrics or sample copy.
|
|
6
|
+
*/
|
|
7
|
+
export const WEBSITE_GENERATION_REGRESSION: ExperimentItem[] = [
|
|
8
|
+
{
|
|
9
|
+
id: "saas-landing",
|
|
10
|
+
input: {
|
|
11
|
+
brief:
|
|
12
|
+
"SaaS landing page for a project-management tool used by small agencies. Spec, pricing, FAQ.",
|
|
13
|
+
},
|
|
14
|
+
metadata: { siteType: "saas" },
|
|
15
|
+
expectedOutput: { characteristics: ["pricing", "faq", "responsive"] },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "restaurant",
|
|
19
|
+
input: {
|
|
20
|
+
brief: "Restaurant website with menu, hours, reservation form, and a location block.",
|
|
21
|
+
},
|
|
22
|
+
metadata: { siteType: "restaurant" },
|
|
23
|
+
expectedOutput: { characteristics: ["menu", "hours", "responsive"] },
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "portfolio",
|
|
27
|
+
input: { brief: "Portfolio for a photographer. Work grid, about, contact. No testimonials." },
|
|
28
|
+
metadata: { siteType: "portfolio" },
|
|
29
|
+
expectedOutput: { characteristics: ["work", "contact"] },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "agency",
|
|
33
|
+
input: {
|
|
34
|
+
brief: "Design agency site. Services, selected work, contact. Sentence-case headings.",
|
|
35
|
+
},
|
|
36
|
+
metadata: { siteType: "agency" },
|
|
37
|
+
expectedOutput: { characteristics: ["services", "work", "contact"] },
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "ecommerce",
|
|
41
|
+
input: {
|
|
42
|
+
brief:
|
|
43
|
+
"Small ecommerce store for ceramic tableware. Catalog, product page, cart, shipping FAQ.",
|
|
44
|
+
},
|
|
45
|
+
metadata: { siteType: "ecommerce" },
|
|
46
|
+
expectedOutput: { characteristics: ["catalog", "product", "faq"] },
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "blog",
|
|
50
|
+
input: { brief: "Independent magazine. Issue index, article layout, about the editors." },
|
|
51
|
+
metadata: { siteType: "blog" },
|
|
52
|
+
expectedOutput: { characteristics: ["index", "article"] },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "dashboard-marketing",
|
|
56
|
+
input: { brief: "Marketing site for a B2B analytics dashboard product. Not the app itself." },
|
|
57
|
+
metadata: { siteType: "saas" },
|
|
58
|
+
expectedOutput: { characteristics: ["landing", "pricing"] },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "ai-startup",
|
|
62
|
+
input: {
|
|
63
|
+
brief:
|
|
64
|
+
"Dark premium landing page for an AI infrastructure company with pricing, integrations, FAQ and responsive mobile design. Do not invent testimonials.",
|
|
65
|
+
},
|
|
66
|
+
metadata: { siteType: "saas", difficulty: "hard" },
|
|
67
|
+
expectedOutput: { characteristics: ["dark", "pricing", "integrations", "faq", "responsive"] },
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "developer-tool",
|
|
71
|
+
input: {
|
|
72
|
+
brief: "Docs-first site for a CLI. Install, commands, changelog. Mono for commands only.",
|
|
73
|
+
},
|
|
74
|
+
metadata: { siteType: "docs" },
|
|
75
|
+
expectedOutput: { characteristics: ["install", "commands"] },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "personal",
|
|
79
|
+
input: { brief: "Personal site for a journalist. Bio, selected articles, email." },
|
|
80
|
+
metadata: { siteType: "personal" },
|
|
81
|
+
expectedOutput: { characteristics: ["bio", "articles", "contact"] },
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "docs-product",
|
|
85
|
+
input: {
|
|
86
|
+
brief: "Product documentation home with getting started, API reference, and changelog.",
|
|
87
|
+
},
|
|
88
|
+
metadata: { siteType: "docs" },
|
|
89
|
+
expectedOutput: { characteristics: ["getting-started", "api"] },
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "nonprofit",
|
|
93
|
+
input: {
|
|
94
|
+
brief: "Nonprofit campaign site. Mission, programs, donate. No invented impact numbers.",
|
|
95
|
+
},
|
|
96
|
+
metadata: { siteType: "nonprofit" },
|
|
97
|
+
expectedOutput: { characteristics: ["mission", "donate"] },
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "law-firm",
|
|
101
|
+
input: { brief: "Law firm site. Practice areas, people, contact. Conservative layout." },
|
|
102
|
+
metadata: { siteType: "professional" },
|
|
103
|
+
expectedOutput: { characteristics: ["practice-areas", "people", "contact"] },
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "clinic",
|
|
107
|
+
input: {
|
|
108
|
+
brief: "Dental clinic. Services, hours, new-patient form. Facts only from the brief.",
|
|
109
|
+
},
|
|
110
|
+
metadata: { siteType: "health" },
|
|
111
|
+
expectedOutput: { characteristics: ["services", "hours", "form"] },
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "hotel",
|
|
115
|
+
input: { brief: "Boutique hotel. Rooms, location, booking enquiry. No invented star ratings." },
|
|
116
|
+
metadata: { siteType: "hospitality" },
|
|
117
|
+
expectedOutput: { characteristics: ["rooms", "location"] },
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "education",
|
|
121
|
+
input: { brief: "Independent school. Admissions, calendar, faculty. No invented test scores." },
|
|
122
|
+
metadata: { siteType: "education" },
|
|
123
|
+
expectedOutput: { characteristics: ["admissions", "calendar"] },
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "marketplace",
|
|
127
|
+
input: { brief: "Two-sided marketplace landing: for buyers, for sellers, pricing, FAQ." },
|
|
128
|
+
metadata: { siteType: "marketplace" },
|
|
129
|
+
expectedOutput: { characteristics: ["buyers", "sellers", "pricing", "faq"] },
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "mobile-first",
|
|
133
|
+
input: {
|
|
134
|
+
brief:
|
|
135
|
+
"Mobile-first landing for a local courier. Quote form above the fold on a 390px viewport.",
|
|
136
|
+
},
|
|
137
|
+
metadata: { siteType: "services", difficulty: "hard" },
|
|
138
|
+
expectedOutput: { characteristics: ["form", "responsive"] },
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "multilingual-ready",
|
|
142
|
+
input: {
|
|
143
|
+
brief:
|
|
144
|
+
"Studio site with a language switcher for English and Danish. Same structure both languages.",
|
|
145
|
+
},
|
|
146
|
+
metadata: { siteType: "studio" },
|
|
147
|
+
expectedOutput: { characteristics: ["language-switcher"] },
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "empty-proof",
|
|
151
|
+
input: {
|
|
152
|
+
brief:
|
|
153
|
+
"New bakery with no reviews yet. Menu, hours, address. Do not invent testimonials or ratings.",
|
|
154
|
+
},
|
|
155
|
+
metadata: { siteType: "restaurant", difficulty: "hard" },
|
|
156
|
+
expectedOutput: { characteristics: ["menu", "hours", "no-testimonials"] },
|
|
157
|
+
},
|
|
158
|
+
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { sanitize } from "./sanitize.ts";
|
|
3
|
+
|
|
4
|
+
describe("sanitize", () => {
|
|
5
|
+
test("redacts secret keys and bearer tokens", () => {
|
|
6
|
+
const out = sanitize({
|
|
7
|
+
authorization: "Bearer abc",
|
|
8
|
+
apiKey: "sk-secret",
|
|
9
|
+
nested: { password: "hunter2", note: "ok" },
|
|
10
|
+
header: "Bearer supersecret",
|
|
11
|
+
DATABASE_URL: "postgres://user:pass@host/db",
|
|
12
|
+
}) as Record<string, unknown>;
|
|
13
|
+
expect(out.authorization).toBe("[redacted]");
|
|
14
|
+
expect(out.apiKey).toBe("[redacted]");
|
|
15
|
+
expect((out.nested as Record<string, unknown>).password).toBe("[redacted]");
|
|
16
|
+
expect((out.nested as Record<string, unknown>).note).toBe("ok");
|
|
17
|
+
expect(out.header).toBe("[redacted]");
|
|
18
|
+
expect(out.DATABASE_URL).toBe("[redacted]");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("truncates long strings", () => {
|
|
22
|
+
const out = sanitize("x".repeat(9000)) as string;
|
|
23
|
+
expect(out.endsWith("…")).toBe(true);
|
|
24
|
+
expect(out.length).toBeLessThan(9005);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const SENSITIVE_KEY =
|
|
2
|
+
/^(authorization|cookie|set-cookie|x-api-key|api[_-]?key|secret|passwd|password|token|access[_-]?token|refresh[_-]?token|private[_-]?key|database[_-]?url|connection[_-]?string|credit[_-]?card|card[_-]?number|cvv|cvc|ssn|stripe[_-]?key)$/i;
|
|
3
|
+
|
|
4
|
+
const SENSITIVE_VALUE =
|
|
5
|
+
/(sk-[a-zA-Z0-9_-]{8,}|pk_(live|test)_[a-zA-Z0-9]+|Bearer\s+\S+|postgres(ql)?:\/\/\S+|mysql:\/\/\S+|mongodb(\+srv)?:\/\/\S+)/i;
|
|
6
|
+
|
|
7
|
+
const REDACTED = "[redacted]";
|
|
8
|
+
const MAX_STRING = 8_000;
|
|
9
|
+
const MAX_ARRAY = 40;
|
|
10
|
+
const MAX_KEYS = 80;
|
|
11
|
+
const MAX_DEPTH = 6;
|
|
12
|
+
|
|
13
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
14
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function redactString(value: string): string {
|
|
18
|
+
const trimmed = value.length > MAX_STRING ? `${value.slice(0, MAX_STRING)}…` : value;
|
|
19
|
+
return SENSITIVE_VALUE.test(trimmed) ? REDACTED : trimmed;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function walk(value: unknown, depth: number): unknown {
|
|
23
|
+
if (value == null) return value;
|
|
24
|
+
if (typeof value === "string") return redactString(value);
|
|
25
|
+
if (typeof value === "number" || typeof value === "boolean") return value;
|
|
26
|
+
if (typeof value === "bigint") return value.toString();
|
|
27
|
+
if (typeof value !== "object") return String(value);
|
|
28
|
+
if (depth >= MAX_DEPTH) return "[truncated]";
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
return value.slice(0, MAX_ARRAY).map((item) => walk(item, depth + 1));
|
|
31
|
+
}
|
|
32
|
+
if (!isPlainObject(value)) return String(value);
|
|
33
|
+
const out: Record<string, unknown> = {};
|
|
34
|
+
let count = 0;
|
|
35
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
36
|
+
if (count >= MAX_KEYS) {
|
|
37
|
+
out._truncated = true;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
count += 1;
|
|
41
|
+
if (SENSITIVE_KEY.test(key)) {
|
|
42
|
+
out[key] = REDACTED;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
out[key] = walk(nested, depth + 1);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Strip secrets and cap payload size before sending to an observability backend. */
|
|
51
|
+
export function sanitize(value: unknown): unknown {
|
|
52
|
+
try {
|
|
53
|
+
return walk(value, 0);
|
|
54
|
+
} catch {
|
|
55
|
+
return "[unserializable]";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor-neutral AI observability. Langfuse is one adapter; hosts may no-op.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface SpanFields {
|
|
6
|
+
input?: unknown;
|
|
7
|
+
output?: unknown;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
level?: "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
|
|
10
|
+
statusMessage?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface GenerationFields extends SpanFields {
|
|
14
|
+
model?: string;
|
|
15
|
+
usage?: {
|
|
16
|
+
promptTokens?: number;
|
|
17
|
+
completionTokens?: number;
|
|
18
|
+
totalTokens?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SpanHandle {
|
|
23
|
+
readonly traceId?: string;
|
|
24
|
+
update(fields: SpanFields): void;
|
|
25
|
+
end(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GenerationHandle extends SpanHandle {
|
|
29
|
+
update(fields: GenerationFields): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TurnOptions {
|
|
33
|
+
name: string;
|
|
34
|
+
input?: unknown;
|
|
35
|
+
userId?: string;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
tags?: string[];
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface SpanOptions {
|
|
42
|
+
input?: unknown;
|
|
43
|
+
metadata?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface GenerationOptions extends SpanOptions {
|
|
47
|
+
model?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ScoreInput {
|
|
51
|
+
name: string;
|
|
52
|
+
value: number;
|
|
53
|
+
comment?: string;
|
|
54
|
+
traceId?: string;
|
|
55
|
+
dataType?: "NUMERIC" | "BOOLEAN" | "CATEGORICAL";
|
|
56
|
+
stringValue?: string;
|
|
57
|
+
metadata?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface EventInput {
|
|
61
|
+
input?: unknown;
|
|
62
|
+
metadata?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Thin observability seam. Implementations must never throw into the agent loop.
|
|
67
|
+
*/
|
|
68
|
+
export interface Observability {
|
|
69
|
+
readonly enabled: boolean;
|
|
70
|
+
startTurn<T>(options: TurnOptions, fn: (span: SpanHandle) => Promise<T>): Promise<T>;
|
|
71
|
+
startSpan<T>(
|
|
72
|
+
name: string,
|
|
73
|
+
fn: (span: SpanHandle) => Promise<T>,
|
|
74
|
+
options?: SpanOptions,
|
|
75
|
+
): Promise<T>;
|
|
76
|
+
generation<T>(
|
|
77
|
+
name: string,
|
|
78
|
+
fn: (span: GenerationHandle) => Promise<T>,
|
|
79
|
+
options?: GenerationOptions,
|
|
80
|
+
): Promise<T>;
|
|
81
|
+
tool<T>(name: string, fn: (span: SpanHandle) => Promise<T>, options?: SpanOptions): Promise<T>;
|
|
82
|
+
score(input: ScoreInput): void;
|
|
83
|
+
event(name: string, input?: EventInput): void;
|
|
84
|
+
currentTraceId(): string | undefined;
|
|
85
|
+
flush(): Promise<void>;
|
|
86
|
+
shutdown(): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface CreateObservabilityOptions {
|
|
90
|
+
/** Override auto-detect. `false` always no-ops. `true` still no-ops without keys. */
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
agentVersion?: string;
|
|
93
|
+
environment?: string;
|
|
94
|
+
env?: Record<string, string | undefined>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const FEEDBACK_CATEGORIES = [
|
|
98
|
+
"design",
|
|
99
|
+
"layout",
|
|
100
|
+
"content",
|
|
101
|
+
"code",
|
|
102
|
+
"mobile",
|
|
103
|
+
"didn't follow instructions",
|
|
104
|
+
"other",
|
|
105
|
+
] as const;
|
|
106
|
+
|
|
107
|
+
export type FeedbackCategory = (typeof FEEDBACK_CATEGORIES)[number];
|
|
108
|
+
|
|
109
|
+
export const FAILURE_CATEGORIES = [
|
|
110
|
+
"PLANNING_ERROR",
|
|
111
|
+
"CODE_GENERATION_ERROR",
|
|
112
|
+
"BUILD_ERROR",
|
|
113
|
+
"RUNTIME_ERROR",
|
|
114
|
+
"DESIGN_ERROR",
|
|
115
|
+
"RESPONSIVE_ERROR",
|
|
116
|
+
"TOOL_ERROR",
|
|
117
|
+
"MODEL_ERROR",
|
|
118
|
+
"TIMEOUT",
|
|
119
|
+
"USER_REQUIREMENT_MISMATCH",
|
|
120
|
+
] as const;
|
|
121
|
+
|
|
122
|
+
export type FailureCategory = (typeof FAILURE_CATEGORIES)[number];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
function readPackageVersion(fromFile: string): string | undefined {
|
|
6
|
+
try {
|
|
7
|
+
const dir = dirname(fromFile);
|
|
8
|
+
for (const candidate of [join(dir, "package.json"), join(dir, "..", "..", "package.json")]) {
|
|
9
|
+
try {
|
|
10
|
+
const raw = readFileSync(candidate, "utf8");
|
|
11
|
+
const parsed = JSON.parse(raw) as { version?: unknown; name?: unknown };
|
|
12
|
+
if (typeof parsed.version === "string" && parsed.version.trim())
|
|
13
|
+
return parsed.version.trim();
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Explicit `CAELENCE_AGENT_VERSION` wins. Otherwise the nearest package version
|
|
24
|
+
* (passed in by the host) or this harness package version.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveAgentVersion(fallback?: string, env = process.env): string {
|
|
27
|
+
const fromEnv = env.CAELENCE_AGENT_VERSION?.trim();
|
|
28
|
+
if (fromEnv) return fromEnv;
|
|
29
|
+
if (fallback?.trim()) return fallback.trim();
|
|
30
|
+
return readPackageVersion(fileURLToPath(import.meta.url)) ?? "0.0.0";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resolveEnvironment(env = process.env): string {
|
|
34
|
+
return env.LANGFUSE_TRACING_ENVIRONMENT?.trim() || env.NODE_ENV?.trim() || "development";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function langfuseKeysPresent(
|
|
38
|
+
env: Record<string, string | undefined> = process.env,
|
|
39
|
+
): boolean {
|
|
40
|
+
return Boolean(env.LANGFUSE_SECRET_KEY?.trim() && env.LANGFUSE_PUBLIC_KEY?.trim());
|
|
41
|
+
}
|
package/src/product.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtemp, rm } 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
|
+
|
|
11
|
+
const fakeProvider: MainModelProvider = {
|
|
12
|
+
kind: "fake",
|
|
13
|
+
modelId: "fake",
|
|
14
|
+
async *stream() {
|
|
15
|
+
yield { type: "done" };
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("createHarness modes", () => {
|
|
20
|
+
test("ask mode does not expose write_file or exec", async () => {
|
|
21
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-runtime-"));
|
|
22
|
+
try {
|
|
23
|
+
let names: string[] = [];
|
|
24
|
+
const constructAgent: ConstructAgent = (input) => {
|
|
25
|
+
names = input.tools.map((tool) => tool.name);
|
|
26
|
+
return {
|
|
27
|
+
async run(_message, emit) {
|
|
28
|
+
emit({ kind: "text_delta", text: "ok" });
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const harness = await createHarness({
|
|
33
|
+
cwd,
|
|
34
|
+
config: { ...DEFAULT_CONFIG, mode: "ask" },
|
|
35
|
+
provider: fakeProvider,
|
|
36
|
+
constructAgent,
|
|
37
|
+
observability: noopObservability,
|
|
38
|
+
});
|
|
39
|
+
expect(harness.mode).toBe("ask");
|
|
40
|
+
await harness.runTurn("inspect", () => undefined);
|
|
41
|
+
expect(names).toContain("read_file");
|
|
42
|
+
expect(names).toContain("git_status");
|
|
43
|
+
expect(names).not.toContain("write_file");
|
|
44
|
+
expect(names).not.toContain("exec");
|
|
45
|
+
expect(names).not.toContain("git_commit");
|
|
46
|
+
expect(names).not.toContain("todo_write");
|
|
47
|
+
expect(names).not.toContain("task");
|
|
48
|
+
|
|
49
|
+
harness.setMode("plan");
|
|
50
|
+
await harness.runTurn("plan it", () => undefined);
|
|
51
|
+
expect(names).toContain("todo_write");
|
|
52
|
+
expect(names).not.toContain("write_file");
|
|
53
|
+
|
|
54
|
+
harness.setMode("agent");
|
|
55
|
+
await harness.runTurn("implement", () => undefined);
|
|
56
|
+
expect(names).toContain("write_file");
|
|
57
|
+
expect(names).toContain("git_commit");
|
|
58
|
+
expect(names).toContain("task");
|
|
59
|
+
harness.close();
|
|
60
|
+
} finally {
|
|
61
|
+
await rm(cwd, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("accumulates usage on the runtime", async () => {
|
|
66
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-spend-"));
|
|
67
|
+
try {
|
|
68
|
+
const provider: MainModelProvider = {
|
|
69
|
+
kind: "fake",
|
|
70
|
+
modelId: "fake",
|
|
71
|
+
async *stream() {
|
|
72
|
+
yield { type: "done" };
|
|
73
|
+
},
|
|
74
|
+
takeUsage() {
|
|
75
|
+
return { promptTokens: 3, completionTokens: 1, totalTokens: 4 };
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const harness = await createHarness({
|
|
79
|
+
cwd,
|
|
80
|
+
config: DEFAULT_CONFIG,
|
|
81
|
+
provider,
|
|
82
|
+
constructAgent: () => ({
|
|
83
|
+
async run(_message, emit) {
|
|
84
|
+
emit({ kind: "text_delta", text: "ok" });
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
observability: noopObservability,
|
|
88
|
+
});
|
|
89
|
+
const events: AgentEvent["kind"][] = [];
|
|
90
|
+
await harness.runTurn("hi", (event) => events.push(event.kind));
|
|
91
|
+
expect(events).toContain("usage");
|
|
92
|
+
expect(harness.spend).toEqual({ promptTokens: 3, completionTokens: 1, totalTokens: 4 });
|
|
93
|
+
harness.close();
|
|
94
|
+
} finally {
|
|
95
|
+
await rm(cwd, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|