@intentface/latch-agent-builder 0.9.1

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.
@@ -0,0 +1,58 @@
1
+ import type { AgentRecord } from "./record";
2
+ /**
3
+ * The extension seam.
4
+ *
5
+ * The builder core is agent CRUD + discovery + test_agent. Anything beyond
6
+ * that — evals, tool authoring, connections, memory schemas, whatever a host
7
+ * grows next — plugs in here instead of being compiled into the core, so hosts
8
+ * without the feature get a builder that simply never mentions it. An
9
+ * extension contributes:
10
+ *
11
+ * - tools: merged into the builder's toolset (name-collision =
12
+ * extension wins; keep names distinct).
13
+ * - promptSections: appended verbatim to the builder's instructions.
14
+ * - subagents: delegate agents (e.g. "eval-author"). Subagents run
15
+ * autonomously; if the host auto-approves subagent tools
16
+ * or the extension's flows must never mutate state, keep
17
+ * the subagent READ-ONLY — persisting writes belong on
18
+ * the builder where user approval gates them.
19
+ * - reservedNames: agent names save_agent must refuse to overwrite.
20
+ * - toolApproval: HITL policy for the extension's own tools.
21
+ * - validateSave: veto a save_agent record (return an error string).
22
+ * - decorate*Result: append guidance to save_agent / test_agent results —
23
+ * the model acts on tool results far more reliably than
24
+ * on distant prompt instructions (e.g. eval nudges).
25
+ */
26
+ type MaybePromise<T> = T | Promise<T>;
27
+ export interface AgentBuilderExtension<P> {
28
+ /** Short id for diagnostics (e.g. "evals", "tool-authoring"). */
29
+ name: string;
30
+ /** Extra tools bound to the chatting user's principal. */
31
+ tools?: (principal: P) => MaybePromise<Record<string, unknown>>;
32
+ /** Instruction fragments appended to the builder's system prompt. */
33
+ promptSections?: string[];
34
+ /** Extra delegate agents (see read-only note above). */
35
+ subagents?: string[];
36
+ /** Agent names the builder must not overwrite (e.g. the extension's own subagents). */
37
+ reservedNames?: string[];
38
+ /** Per-tool approval policy for the extension's tools (merged into the builder's). */
39
+ toolApproval?: Record<string, unknown>;
40
+ /**
41
+ * Declares that this extension understands `exec.authoredTools`. Without
42
+ * any such extension the core REJECTS a non-empty `authoredTools` (a clear
43
+ * error beats silently dropping capabilities).
44
+ */
45
+ handlesAuthoredTools?: boolean;
46
+ /**
47
+ * Veto a save: return an error string to reject (surfaced as the tool
48
+ * result), or undefined to pass. Receives the NORMALIZED record about to be
49
+ * persisted; runs after the core validations.
50
+ */
51
+ validateSave?: (principal: P, record: AgentRecord) => MaybePromise<string | undefined>;
52
+ /** Amend the save_agent success result (e.g. append an eval nudge to `note`). */
53
+ decorateSaveResult?: (principal: P, agentName: string, result: Record<string, unknown>) => MaybePromise<Record<string, unknown>>;
54
+ /** Amend the test_agent result the same way. */
55
+ decorateTestResult?: (principal: P, agentName: string, result: Record<string, unknown>) => MaybePromise<Record<string, unknown>>;
56
+ }
57
+ export {};
58
+ //# sourceMappingURL=extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAChE,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,uFAAuF;IACvF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,sFAAsF;IACtF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvF,iFAAiF;IACjF,kBAAkB,CAAC,EAAE,CACnB,SAAS,EAAE,CAAC,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,gDAAgD;IAChD,kBAAkB,CAAC,EAAE,CACnB,SAAS,EAAE,CAAC,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export { createAgentBuilder } from "./agent-builder";
2
+ export type { AgentBuilderConfig, AgentBuilderDeps, CapabilitySupport, ModelChoice, ConnectionChoice, } from "./agent-builder";
3
+ export type { AgentBuilderExtension } from "./extension";
4
+ export type { AgentBuilderStore } from "./store";
5
+ export { AgentRecordSchema, AgentExecSchema, AgentToolsSchema, AgentScopeSchema, AttachedEvalSchema, MemoryConfigSchema, MemoryScopeSchema, EffortSchema, normalizeAgentName, normalizeAgentRecord, parseAgentRecord, parseAgentRef, } from "./record";
6
+ export type { AgentRecord, AgentRecordInput, AgentScope, AttachedEval } from "./record";
7
+ export { sharedReadTools } from "./shared-read-tools";
8
+ export type { SharedReadDeps } from "./shared-read-tools";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createAgentBuilder } from "./agent-builder";
2
+ export { AgentRecordSchema, AgentExecSchema, AgentToolsSchema, AgentScopeSchema, AttachedEvalSchema, MemoryConfigSchema, MemoryScopeSchema, EffortSchema, normalizeAgentName, normalizeAgentRecord, parseAgentRecord, parseAgentRef, } from "./record";
3
+ export { sharedReadTools } from "./shared-read-tools";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAUrD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,230 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * THE agent record — one zod schema that every writer and reader derives from:
4
+ * the persisted shape (`AgentRecord`), the builder's `save_agent` input, a
5
+ * host's server-side validator, and a schema-driven editor form. Declared once
6
+ * so a field can't exist in one home and not another.
7
+ *
8
+ * Zod-only on purpose (no `ai`, no runtime imports) — safe to ship to a
9
+ * browser bundle via the `./record` subpath.
10
+ *
11
+ * Two kinds of rule live here:
12
+ * - shape + cross-field invariants that are TRUE FOR EVERY HOST (memory
13
+ * connection must be wired, org-shared memory needs an org agent, index
14
+ * schemas are outlines, …) → `AgentRecordSchema`.
15
+ * - canonicalization every writer must apply → `normalizeAgentRecord`.
16
+ * Host policy (reserved names, who may attach org tools, which capabilities
17
+ * exist) stays with the host / the builder's `CapabilitySupport`.
18
+ */
19
+ /** Where a record lives: the caller's personal scope or the shared org scope. */
20
+ export declare const AgentScopeSchema: z.ZodEnum<{
21
+ user: "user";
22
+ org: "org";
23
+ }>;
24
+ export type AgentScope = z.infer<typeof AgentScopeSchema>;
25
+ export declare const MemoryScopeSchema: z.ZodEnum<{
26
+ user: "user";
27
+ "agent-user": "agent-user";
28
+ "agent-org": "agent-org";
29
+ }>;
30
+ export declare const MemoryConfigSchema: z.ZodObject<{
31
+ scope: z.ZodEnum<{
32
+ user: "user";
33
+ "agent-user": "agent-user";
34
+ "agent-org": "agent-org";
35
+ }>;
36
+ connection: z.ZodString;
37
+ extractTo: z.ZodOptional<z.ZodArray<z.ZodEnum<{
38
+ user: "user";
39
+ "agent-user": "agent-user";
40
+ "agent-org": "agent-org";
41
+ }>>>;
42
+ schemas: z.ZodOptional<z.ZodObject<{
43
+ "agent-user": z.ZodOptional<z.ZodString>;
44
+ "agent-org": z.ZodOptional<z.ZodString>;
45
+ }, z.core.$strict>>;
46
+ extraction: z.ZodOptional<z.ZodObject<{
47
+ idleMinutes: z.ZodOptional<z.ZodNumber>;
48
+ }, z.core.$strip>>;
49
+ consolidation: z.ZodOptional<z.ZodObject<{
50
+ cooldownHours: z.ZodOptional<z.ZodNumber>;
51
+ }, z.core.$strip>>;
52
+ }, z.core.$strip>;
53
+ /**
54
+ * One judge rubric attached to an agent. `trigger` is a host-defined predicate
55
+ * tree (see the host's eval feature) — opaque here; the host narrows it.
56
+ */
57
+ export declare const AttachedEvalSchema: z.ZodObject<{
58
+ name: z.ZodString;
59
+ prompt: z.ZodString;
60
+ judgeModelId: z.ZodOptional<z.ZodString>;
61
+ scale: z.ZodDefault<z.ZodEnum<{
62
+ binary: "binary";
63
+ score: "score";
64
+ }>>;
65
+ enabled: z.ZodDefault<z.ZodBoolean>;
66
+ trigger: z.ZodOptional<z.ZodUnknown>;
67
+ context: z.ZodOptional<z.ZodEnum<{
68
+ turn: "turn";
69
+ chat: "chat";
70
+ loop: "loop";
71
+ }>>;
72
+ }, z.core.$strip>;
73
+ export type AttachedEval = z.infer<typeof AttachedEvalSchema>;
74
+ /** Per-tool selection over the connections' tools. */
75
+ export declare const AgentToolsSchema: z.ZodObject<{
76
+ enabled: z.ZodArray<z.ZodString>;
77
+ approval: z.ZodRecord<z.ZodString, z.ZodBoolean>;
78
+ descriptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
79
+ }, z.core.$strip>;
80
+ export declare const EffortSchema: z.ZodEnum<{
81
+ minimal: "minimal";
82
+ low: "low";
83
+ medium: "medium";
84
+ high: "high";
85
+ }>;
86
+ /** Code-execution + harness capabilities. Every flag is optional; absent = off. */
87
+ export declare const AgentExecSchema: z.ZodObject<{
88
+ sandbox: z.ZodOptional<z.ZodBoolean>;
89
+ provider: z.ZodOptional<z.ZodString>;
90
+ defaultTools: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
91
+ disableTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
92
+ providerWebTools: z.ZodOptional<z.ZodBoolean>;
93
+ renderTools: z.ZodOptional<z.ZodBoolean>;
94
+ authoredTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
95
+ preApprovedWrites: z.ZodOptional<z.ZodBoolean>;
96
+ effort: z.ZodOptional<z.ZodEnum<{
97
+ minimal: "minimal";
98
+ low: "low";
99
+ medium: "medium";
100
+ high: "high";
101
+ }>>;
102
+ memory: z.ZodOptional<z.ZodObject<{
103
+ scope: z.ZodEnum<{
104
+ user: "user";
105
+ "agent-user": "agent-user";
106
+ "agent-org": "agent-org";
107
+ }>;
108
+ connection: z.ZodString;
109
+ extractTo: z.ZodOptional<z.ZodArray<z.ZodEnum<{
110
+ user: "user";
111
+ "agent-user": "agent-user";
112
+ "agent-org": "agent-org";
113
+ }>>>;
114
+ schemas: z.ZodOptional<z.ZodObject<{
115
+ "agent-user": z.ZodOptional<z.ZodString>;
116
+ "agent-org": z.ZodOptional<z.ZodString>;
117
+ }, z.core.$strict>>;
118
+ extraction: z.ZodOptional<z.ZodObject<{
119
+ idleMinutes: z.ZodOptional<z.ZodNumber>;
120
+ }, z.core.$strip>>;
121
+ consolidation: z.ZodOptional<z.ZodObject<{
122
+ cooldownHours: z.ZodOptional<z.ZodNumber>;
123
+ }, z.core.$strip>>;
124
+ }, z.core.$strip>>;
125
+ }, z.core.$strip>;
126
+ export declare const AgentRecordSchema: z.ZodObject<{
127
+ name: z.ZodString;
128
+ title: z.ZodOptional<z.ZodString>;
129
+ description: z.ZodOptional<z.ZodString>;
130
+ modelId: z.ZodString;
131
+ instructions: z.ZodString;
132
+ connections: z.ZodDefault<z.ZodArray<z.ZodString>>;
133
+ maxSteps: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">]>>;
134
+ tools: z.ZodOptional<z.ZodObject<{
135
+ enabled: z.ZodArray<z.ZodString>;
136
+ approval: z.ZodRecord<z.ZodString, z.ZodBoolean>;
137
+ descriptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
138
+ }, z.core.$strip>>;
139
+ exec: z.ZodOptional<z.ZodObject<{
140
+ sandbox: z.ZodOptional<z.ZodBoolean>;
141
+ provider: z.ZodOptional<z.ZodString>;
142
+ defaultTools: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
143
+ disableTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
144
+ providerWebTools: z.ZodOptional<z.ZodBoolean>;
145
+ renderTools: z.ZodOptional<z.ZodBoolean>;
146
+ authoredTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
147
+ preApprovedWrites: z.ZodOptional<z.ZodBoolean>;
148
+ effort: z.ZodOptional<z.ZodEnum<{
149
+ minimal: "minimal";
150
+ low: "low";
151
+ medium: "medium";
152
+ high: "high";
153
+ }>>;
154
+ memory: z.ZodOptional<z.ZodObject<{
155
+ scope: z.ZodEnum<{
156
+ user: "user";
157
+ "agent-user": "agent-user";
158
+ "agent-org": "agent-org";
159
+ }>;
160
+ connection: z.ZodString;
161
+ extractTo: z.ZodOptional<z.ZodArray<z.ZodEnum<{
162
+ user: "user";
163
+ "agent-user": "agent-user";
164
+ "agent-org": "agent-org";
165
+ }>>>;
166
+ schemas: z.ZodOptional<z.ZodObject<{
167
+ "agent-user": z.ZodOptional<z.ZodString>;
168
+ "agent-org": z.ZodOptional<z.ZodString>;
169
+ }, z.core.$strict>>;
170
+ extraction: z.ZodOptional<z.ZodObject<{
171
+ idleMinutes: z.ZodOptional<z.ZodNumber>;
172
+ }, z.core.$strip>>;
173
+ consolidation: z.ZodOptional<z.ZodObject<{
174
+ cooldownHours: z.ZodOptional<z.ZodNumber>;
175
+ }, z.core.$strip>>;
176
+ }, z.core.$strip>>;
177
+ }, z.core.$strip>>;
178
+ subagents: z.ZodOptional<z.ZodArray<z.ZodString>>;
179
+ attachedEvals: z.ZodOptional<z.ZodArray<z.ZodObject<{
180
+ name: z.ZodString;
181
+ prompt: z.ZodString;
182
+ judgeModelId: z.ZodOptional<z.ZodString>;
183
+ scale: z.ZodDefault<z.ZodEnum<{
184
+ binary: "binary";
185
+ score: "score";
186
+ }>>;
187
+ enabled: z.ZodDefault<z.ZodBoolean>;
188
+ trigger: z.ZodOptional<z.ZodUnknown>;
189
+ context: z.ZodOptional<z.ZodEnum<{
190
+ turn: "turn";
191
+ chat: "chat";
192
+ loop: "loop";
193
+ }>>;
194
+ }, z.core.$strip>>>;
195
+ scope: z.ZodEnum<{
196
+ user: "user";
197
+ org: "org";
198
+ }>;
199
+ }, z.core.$strict>;
200
+ /** The persisted record — the schema's output type. */
201
+ export type AgentRecord = z.infer<typeof AgentRecordSchema>;
202
+ /** What a writer may pass in (defaults not yet applied). */
203
+ export type AgentRecordInput = z.input<typeof AgentRecordSchema>;
204
+ /**
205
+ * Canonical agent-name normalization — used by EVERY writer (host editors and
206
+ * the builder's save_agent) so the same intended name always maps to one
207
+ * record. Lowercased kebab, underscores allowed.
208
+ */
209
+ export declare const normalizeAgentName: (s: string) => string;
210
+ /**
211
+ * Channel bindings and run records pin an agent to one scope with an
212
+ * `org:`/`user:` prefix (stored names never contain `:` — normalizeAgentName
213
+ * strips it). Split a possibly-pinned reference.
214
+ */
215
+ export declare function parseAgentRef(ref: string): {
216
+ name: string;
217
+ scope?: AgentScope;
218
+ };
219
+ /**
220
+ * Canonicalize a validated record before persisting. Idempotent. Every writer
221
+ * runs this so the stored form is the same regardless of who wrote it:
222
+ * - name normalized; title/description trimmed (blank → absent)
223
+ * - `exec.memory.extractTo` = unique levels, primary first (absent when it
224
+ * would only repeat the primary); blank index schemas dropped
225
+ * - empty `exec` / `subagents` / `schemas` → absent, not `{}` / `[]`
226
+ */
227
+ export declare function normalizeAgentRecord(rec: AgentRecord): AgentRecord;
228
+ /** Parse + normalize in one step — what a server-side writer wants. Throws `ZodError` on invalid input. */
229
+ export declare function parseAgentRecord(input: unknown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AgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAAE,CAG/E;AAaD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CA4BlE;AAED,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAE5D"}
package/dist/record.js ADDED
@@ -0,0 +1,217 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * THE agent record — one zod schema that every writer and reader derives from:
4
+ * the persisted shape (`AgentRecord`), the builder's `save_agent` input, a
5
+ * host's server-side validator, and a schema-driven editor form. Declared once
6
+ * so a field can't exist in one home and not another.
7
+ *
8
+ * Zod-only on purpose (no `ai`, no runtime imports) — safe to ship to a
9
+ * browser bundle via the `./record` subpath.
10
+ *
11
+ * Two kinds of rule live here:
12
+ * - shape + cross-field invariants that are TRUE FOR EVERY HOST (memory
13
+ * connection must be wired, org-shared memory needs an org agent, index
14
+ * schemas are outlines, …) → `AgentRecordSchema`.
15
+ * - canonicalization every writer must apply → `normalizeAgentRecord`.
16
+ * Host policy (reserved names, who may attach org tools, which capabilities
17
+ * exist) stays with the host / the builder's `CapabilitySupport`.
18
+ */
19
+ /** Where a record lives: the caller's personal scope or the shared org scope. */
20
+ export const AgentScopeSchema = z.enum(["user", "org"]);
21
+ export const MemoryScopeSchema = z.enum(["agent-user", "agent-org", "user"]);
22
+ const MEMORY_LEVEL_DESCRIPTION = "'agent-user' = this agent's memory of each user (default choice); 'agent-org' = one shared memory for the whole org (requires the agent itself to have scope 'org'); 'user' = shared across all the user's agents.";
23
+ /**
24
+ * Markdown index-schema outline: at least one real level-2 heading (`## ` +
25
+ * text, CommonMark requires the space), or blank (dropped on normalize).
26
+ */
27
+ const isOutline = (s) => !s.trim() || /^[ \t]*##(?!#)[ \t]+\S/m.test(s);
28
+ const MemorySchemaText = z
29
+ .string()
30
+ .max(4000, "Memory schema is too long (max 4000 chars).")
31
+ .refine(isOutline, 'Memory schema needs at least one "## Section" heading — it is the index outline.');
32
+ export const MemoryConfigSchema = z.object({
33
+ scope: MemoryScopeSchema.describe(MEMORY_LEVEL_DESCRIPTION),
34
+ connection: z
35
+ .string()
36
+ .min(1)
37
+ .describe("Which of the agent's connections holds the memory files (must be in `connections`; typically 'loredex')."),
38
+ extractTo: z
39
+ .array(MemoryScopeSchema)
40
+ .optional()
41
+ .describe("EXTRA memory levels the background archivist also files facts into from the same conversations (the primary scope is always included). 'agent-org' here also requires the agent to have scope 'org'. Same connection for all levels."),
42
+ schemas: z
43
+ .strictObject({
44
+ "agent-user": MemorySchemaText.optional(),
45
+ "agent-org": MemorySchemaText.optional(),
46
+ })
47
+ .optional()
48
+ .describe("Markdown index-schema outlines per agent-held level ('## Section' headings + description bullets): what that level collects and how its MEMORY.md is organized. The shared 'user' level's schema is a workspace file, not agent config."),
49
+ extraction: z.object({ idleMinutes: z.number().int().positive().optional() }).optional(),
50
+ consolidation: z.object({ cooldownHours: z.number().positive().optional() }).optional(),
51
+ });
52
+ const _memoryConfigMatchesCore = true;
53
+ void _memoryConfigMatchesCore;
54
+ /**
55
+ * One judge rubric attached to an agent. `trigger` is a host-defined predicate
56
+ * tree (see the host's eval feature) — opaque here; the host narrows it.
57
+ */
58
+ export const AttachedEvalSchema = z.object({
59
+ name: z.string().min(1).describe("Kebab-case id — becomes the score name."),
60
+ prompt: z.string().max(1000).describe("The judging instructions: one observable quality of a good response."),
61
+ judgeModelId: z.string().optional().describe("Judge model override (default: the host judge model)."),
62
+ scale: z.enum(["binary", "score"]).default("binary").describe("binary → pass/fail; score → graded 0–1."),
63
+ enabled: z.boolean().default(true),
64
+ trigger: z.unknown().optional().describe("When the judge runs — host-defined predicate; absent → every completed turn."),
65
+ context: z.enum(["turn", "chat", "loop"]).optional().describe("What the judge sees: turn (default), chat, or loop."),
66
+ });
67
+ /** Per-tool selection over the connections' tools. */
68
+ export const AgentToolsSchema = z.object({
69
+ /** Namespaced tool names the model may call (empty → all). */
70
+ enabled: z.array(z.string()),
71
+ /** Per-tool override: true → require approval, false → waive it (overrides the connection default). */
72
+ approval: z.record(z.string(), z.boolean()),
73
+ /** Per-tool description overrides (by namespaced tool name). */
74
+ descriptions: z.record(z.string(), z.string()).optional(),
75
+ });
76
+ export const EffortSchema = z.enum(["minimal", "low", "medium", "high"]);
77
+ /** Code-execution + harness capabilities. Every flag is optional; absent = off. */
78
+ export const AgentExecSchema = z.object({
79
+ sandbox: z.boolean().optional().describe("Per-session workspace + file/shell tools (bash, read_file, …)."),
80
+ provider: z.string().optional().describe("Sandbox backend id (host-specific). Omit for the host default."),
81
+ defaultTools: z
82
+ .union([z.boolean(), z.array(z.string())])
83
+ .optional()
84
+ .describe("App harness tools (host-defined: e.g. web_fetch, askUser, scheduling). true = all of them, or a list of tool names."),
85
+ disableTools: z.array(z.string()).optional().describe("Harness tool names to opt out of."),
86
+ providerWebTools: z.boolean().optional().describe("Native provider web search/fetch (Anthropic/OpenAI/Google)."),
87
+ renderTools: z.boolean().optional().describe("Headless-browser fetch/render tool(s)."),
88
+ authoredTools: z
89
+ .array(z.string())
90
+ .optional()
91
+ .describe("Names of host-authored tools attached to this agent — only where the host offers tool authoring."),
92
+ preApprovedWrites: z
93
+ .boolean()
94
+ .optional()
95
+ .describe("Waive the per-call approval pause on this agent's WRITE tools — the save approval is the consent. ONLY for agents that must run unattended (schedules); requires defaultTools."),
96
+ effort: EffortSchema.optional().describe("Reasoning/thinking effort. Only set for a model where list_models shows reasoning=true."),
97
+ memory: MemoryConfigSchema.optional().describe("Persistent cross-session memory: the host archives durable facts from idle chats into the connection's workspace, injects a compiled index each turn, and adds memory_search/memory_save tools."),
98
+ });
99
+ // `strictObject`, not `object`: the pre-schema builder took `effort` and
100
+ // `authoredTools` at the TOP level. Zod strips unknown keys by default, so a
101
+ // writer still emitting that shape would save an agent silently missing its
102
+ // configuration. Rejecting is the honest outcome. (`exec` itself stays
103
+ // non-strict: a stored row carrying a retired flag such as `codeMode` is NOT
104
+ // rejected — the unknown key is stripped on parse and simply not written back.
105
+ // Nothing reads it anymore, so dropping it is the whole migration.)
106
+ export const AgentRecordSchema = z
107
+ .strictObject({
108
+ name: z.string().min(1).describe("Unique kebab-case id. Reusing an existing name UPDATES that agent."),
109
+ title: z.string().optional().describe("Short human label for the picker."),
110
+ description: z.string().optional().describe("One line on what the agent does."),
111
+ modelId: z.string().min(1).describe("Must be an id returned by list_models."),
112
+ instructions: z.string().min(1).describe("The system prompt — the heart of the agent. Be specific."),
113
+ connections: z.array(z.string()).default([]).describe("Connection names from list_connections."),
114
+ maxSteps: z
115
+ .union([z.number().int().min(1), z.literal("unlimited")])
116
+ .optional()
117
+ .describe("Tool-loop ceiling: a number caps steps; \"unlimited\" runs until done; omit for the default."),
118
+ tools: AgentToolsSchema.optional(),
119
+ exec: AgentExecSchema.optional(),
120
+ subagents: z.array(z.string()).optional().describe("Names of agents this one may delegate to."),
121
+ attachedEvals: z.array(AttachedEvalSchema).optional(),
122
+ scope: AgentScopeSchema.describe("'user' (personal) or 'org' (shared). Ask the user — never guess."),
123
+ })
124
+ .superRefine((rec, ctx) => {
125
+ if (!normalizeAgentName(rec.name)) {
126
+ ctx.addIssue({ code: "custom", path: ["name"], message: "invalid name" });
127
+ }
128
+ const mem = rec.exec?.memory;
129
+ if (!mem)
130
+ return;
131
+ // Memory files live in one of the agent's OWN connections. A dangling name
132
+ // would silently disable recall while looking configured.
133
+ if (!rec.connections.includes(mem.connection)) {
134
+ ctx.addIssue({
135
+ code: "custom",
136
+ path: ["exec", "memory", "connection"],
137
+ message: `Memory connection "${mem.connection}" must also be listed in the agent's connections.`,
138
+ });
139
+ }
140
+ // agent-org memory is keyed by agent name alone — restrict it to
141
+ // org-visible agents so same-named personal agents can't share a store.
142
+ // Applies to the primary scope AND every extraction level.
143
+ const levels = [mem.scope, ...(mem.extractTo ?? [])];
144
+ if (levels.includes("agent-org") && rec.scope !== "org") {
145
+ ctx.addIssue({
146
+ code: "custom",
147
+ path: ["exec", "memory", "scope"],
148
+ message: `Org-shared memory ('agent-org') requires scope: "org" on the agent itself.`,
149
+ });
150
+ }
151
+ });
152
+ /**
153
+ * Canonical agent-name normalization — used by EVERY writer (host editors and
154
+ * the builder's save_agent) so the same intended name always maps to one
155
+ * record. Lowercased kebab, underscores allowed.
156
+ */
157
+ export const normalizeAgentName = (s) => s.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[-_]+|[-_]+$/g, "");
158
+ /**
159
+ * Channel bindings and run records pin an agent to one scope with an
160
+ * `org:`/`user:` prefix (stored names never contain `:` — normalizeAgentName
161
+ * strips it). Split a possibly-pinned reference.
162
+ */
163
+ export function parseAgentRef(ref) {
164
+ const m = /^(org|user):(.+)$/.exec(ref);
165
+ return m ? { name: m[2], scope: m[1] } : { name: ref };
166
+ }
167
+ const blankToUndefined = (s) => {
168
+ const t = s?.trim();
169
+ return t ? t : undefined;
170
+ };
171
+ /** Drop `undefined` values; return undefined when nothing is left. */
172
+ function compact(obj) {
173
+ const out = Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
174
+ return Object.keys(out).length ? out : undefined;
175
+ }
176
+ /**
177
+ * Canonicalize a validated record before persisting. Idempotent. Every writer
178
+ * runs this so the stored form is the same regardless of who wrote it:
179
+ * - name normalized; title/description trimmed (blank → absent)
180
+ * - `exec.memory.extractTo` = unique levels, primary first (absent when it
181
+ * would only repeat the primary); blank index schemas dropped
182
+ * - empty `exec` / `subagents` / `schemas` → absent, not `{}` / `[]`
183
+ */
184
+ export function normalizeAgentRecord(rec) {
185
+ let exec = rec.exec ? { ...rec.exec } : undefined;
186
+ if (exec?.memory) {
187
+ const mem = { ...exec.memory };
188
+ const levels = [...new Set([mem.scope, ...(mem.extractTo ?? [])])];
189
+ mem.extractTo = levels.length > 1 ? levels : undefined;
190
+ if (mem.schemas) {
191
+ const kept = Object.fromEntries(Object.entries(mem.schemas).filter(([, s]) => s != null && s.trim()));
192
+ mem.schemas = Object.keys(kept).length ? kept : undefined;
193
+ }
194
+ exec.memory = compact(mem);
195
+ }
196
+ if (exec) {
197
+ if (exec.authoredTools && exec.authoredTools.length === 0)
198
+ exec.authoredTools = undefined;
199
+ if (exec.disableTools && exec.disableTools.length === 0)
200
+ exec.disableTools = undefined;
201
+ exec = compact(exec);
202
+ }
203
+ return {
204
+ ...rec,
205
+ name: normalizeAgentName(rec.name),
206
+ title: blankToUndefined(rec.title),
207
+ description: blankToUndefined(rec.description),
208
+ exec,
209
+ subagents: rec.subagents?.length ? rec.subagents : undefined,
210
+ attachedEvals: rec.attachedEvals?.length ? rec.attachedEvals : undefined,
211
+ };
212
+ }
213
+ /** Parse + normalize in one step — what a server-side writer wants. Throws `ZodError` on invalid input. */
214
+ export function parseAgentRecord(input) {
215
+ return normalizeAgentRecord(AgentRecordSchema.parse(input));
216
+ }
217
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;GAgBG;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAGxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7E,MAAM,wBAAwB,GAC5B,oNAAoN,CAAC;AAEvN;;;GAGG;AACH,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhF,MAAM,gBAAgB,GAAG,CAAC;KACvB,MAAM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AAI,CAAC,CAAC;IACvB,CAAC;IACD,OAAO;QACL,GAAG,GAAG;QACN,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC;QAClC,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC;QAClC,WAAW,EAAE,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC;QAC9C,IAAI;QACJ,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC5D,aAAa,EAAE,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;KACzE,CAAC;AACJ,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { AgentBuilderStore } from "./store";
2
+ /**
3
+ * Read-only discovery tools the builder shares with delegate agents (e.g. an
4
+ * eval author) — one implementation so the two can't drift. All are bound to
5
+ * the chatting user's principal; none mutate anything.
6
+ */
7
+ export interface SharedReadDeps<P> {
8
+ store: AgentBuilderStore<P>;
9
+ /** Enumerate the tools a set of connections exposes, for this caller. */
10
+ connectionTools: (principal: P, names: string[]) => Promise<{
11
+ name: string;
12
+ description: string;
13
+ }[]>;
14
+ }
15
+ export declare function sharedReadTools<P>(principal: P, deps: SharedReadDeps<P>): Record<string, unknown>;
16
+ //# sourceMappingURL=shared-read-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-read-tools.d.ts","sourceRoot":"","sources":["../src/shared-read-tools.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;GAIG;AAEH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC5B,yEAAyE;IACzE,eAAe,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;CACtG;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBjG"}
@@ -0,0 +1,28 @@
1
+ import { tool } from "ai";
2
+ import { z } from "zod";
3
+ export function sharedReadTools(principal, deps) {
4
+ return {
5
+ get_agent: tool({
6
+ description: "Get the full config of one of the user's agents (instructions, connections, exec capabilities).",
7
+ inputSchema: z.object({ name: z.string() }),
8
+ execute: async ({ name }) => {
9
+ // `getRecord` normalizes casing/spacing variants and honours an
10
+ // `org:`/`user:` pin; personal wins over org on a bare name.
11
+ const rec = await deps.store.getRecord(principal, name);
12
+ if (!rec)
13
+ return { error: `No editable agent named "${name}".` };
14
+ return rec;
15
+ },
16
+ }),
17
+ list_connection_tools: tool({
18
+ description: "Enumerate the tools a set of connections exposes (to understand their capabilities).",
19
+ inputSchema: z.object({ connections: z.array(z.string()) }),
20
+ execute: async ({ connections }) => {
21
+ if (connections.length === 0)
22
+ return [];
23
+ return deps.connectionTools(principal, connections);
24
+ },
25
+ }),
26
+ };
27
+ }
28
+ //# sourceMappingURL=shared-read-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-read-tools.js","sourceRoot":"","sources":["../src/shared-read-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB,MAAM,UAAU,eAAe,CAAI,SAAY,EAAE,IAAuB;IACtE,OAAO;QACL,SAAS,EAAE,IAAI,CAAC;YACd,WAAW,EAAE,iGAAiG;YAC9G,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;gBAC1B,gEAAgE;gBAChE,6DAA6D;gBAC7D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;gBACxD,IAAI,CAAC,GAAG;oBAAE,OAAO,EAAE,KAAK,EAAE,4BAA4B,IAAI,IAAI,EAAE,CAAC;gBACjE,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;QAEF,qBAAqB,EAAE,IAAI,CAAC;YAC1B,WAAW,EAAE,sFAAsF;YACnG,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;YAC3D,OAAO,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;gBACjC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;oBAAE,OAAO,EAAE,CAAC;gBACxC,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YACtD,CAAC;SACF,CAAC;KACH,CAAC;AACJ,CAAC"}