@looprun-ai/core 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/LICENSE +202 -0
- package/dist/guards.d.ts +76 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +407 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/model-params.d.ts +16 -0
- package/dist/model-params.d.ts.map +1 -0
- package/dist/model-params.js +27 -0
- package/dist/model-params.js.map +1 -0
- package/dist/rules.d.ts +76 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +11 -0
- package/dist/rules.js.map +1 -0
- package/dist/runtime/ledger.d.ts +28 -0
- package/dist/runtime/ledger.d.ts.map +1 -0
- package/dist/runtime/ledger.js +50 -0
- package/dist/runtime/ledger.js.map +1 -0
- package/dist/runtime/terminal.d.ts +18 -0
- package/dist/runtime/terminal.d.ts.map +1 -0
- package/dist/runtime/terminal.js +50 -0
- package/dist/runtime/terminal.js.map +1 -0
- package/dist/runtime/turn.d.ts +38 -0
- package/dist/runtime/turn.d.ts.map +1 -0
- package/dist/runtime/turn.js +127 -0
- package/dist/runtime/turn.js.map +1 -0
- package/dist/runtime/types.d.ts +55 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +5 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/spec.d.ts +147 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +168 -0
- package/dist/spec.js.map +1 -0
- package/dist/trunk.d.ts +35 -0
- package/dist/trunk.d.ts.map +1 -0
- package/dist/trunk.js +98 -0
- package/dist/trunk.js.map +1 -0
- package/dist/validate.d.ts +15 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +36 -0
- package/dist/validate.js.map +1 -0
- package/package.json +49 -0
package/dist/spec.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @looprun-ai/core — the AgentSpec INTERFACE + class hierarchy (framework-free).
|
|
3
|
+
*
|
|
4
|
+
* The ruleset IS the spec (no compile step). A backend (e.g. @looprun-ai/mastra) consumes this
|
|
5
|
+
* interface directly, mapping each hook to a framework primitive:
|
|
6
|
+
* onInput → an input processor (abort ⇒ turn refused, no LLM call)
|
|
7
|
+
* preTool → a `beforeToolCall` veto ({ proceed:false, output: correction })
|
|
8
|
+
* postTool → recorded via `afterToolCall`
|
|
9
|
+
* onReply → runtime finalization (bounded no-tools redrive; exhaustion ⇒ a deterministic
|
|
10
|
+
* guard-authored closure)
|
|
11
|
+
* controls → maxSteps (stop condition) · terminal (reply-only policy) · directives · escalate ·
|
|
12
|
+
* exhaustionReply
|
|
13
|
+
*
|
|
14
|
+
* Layer hierarchy (guards installed by the constructor, layer-tagged and addressable):
|
|
15
|
+
* AgentSpecMinimal — invariants EVERY agent carries: noDuplicateCall (preTool) + emptyReply (onReply).
|
|
16
|
+
* AgentSpecBase — Minimal + the destructive-safety protocol on `destructiveTools`:
|
|
17
|
+
* confirmFirst + destructiveThrottle.
|
|
18
|
+
* AgentSpecFull — Base + the schema-auto layer (argRequired/argFormat from tool JSON schemas).
|
|
19
|
+
* resolveBindings sorts each hook agent → full → base → minimal so an agent correction wins.
|
|
20
|
+
*/
|
|
21
|
+
import { argFormat, argRequired, confirmFirst, destructiveThrottle, emptyReply, noDuplicateCall } from './guards.js';
|
|
22
|
+
const TERMINAL_TOOLS = ['replyToUser', 'askUser'];
|
|
23
|
+
const LAYER_ORDER = { agent: 0, full: 1, base: 2, minimal: 3 };
|
|
24
|
+
export function resolveBindings(bindings, tool) {
|
|
25
|
+
return (bindings ?? [])
|
|
26
|
+
.filter((b) => !b.disabled && (tool === undefined || b.target === 'any' || b.target.includes(tool)))
|
|
27
|
+
.sort((a, b) => LAYER_ORDER[a.layer] - LAYER_ORDER[b.layer]);
|
|
28
|
+
}
|
|
29
|
+
export function resolveGuards(bindings, tool) {
|
|
30
|
+
return resolveBindings(bindings, tool).map((b) => b.guard);
|
|
31
|
+
}
|
|
32
|
+
export function resolveMutators(bindings) {
|
|
33
|
+
return (bindings ?? [])
|
|
34
|
+
.filter((b) => !b.disabled)
|
|
35
|
+
.sort((a, b) => LAYER_ORDER[a.layer] - LAYER_ORDER[b.layer])
|
|
36
|
+
.map((b) => b.mutator);
|
|
37
|
+
}
|
|
38
|
+
export class AgentSpecMinimal {
|
|
39
|
+
id;
|
|
40
|
+
mode;
|
|
41
|
+
persona;
|
|
42
|
+
surface;
|
|
43
|
+
flow;
|
|
44
|
+
guards;
|
|
45
|
+
controls;
|
|
46
|
+
behavior;
|
|
47
|
+
theme;
|
|
48
|
+
destructiveTools;
|
|
49
|
+
toolSchemas;
|
|
50
|
+
seq = 0;
|
|
51
|
+
constructor(cfg) {
|
|
52
|
+
const terminals = cfg.tools.filter((t) => TERMINAL_TOOLS.includes(t));
|
|
53
|
+
if (terminals.length) {
|
|
54
|
+
throw new Error(`AgentSpec "${cfg.id}": terminal tools are runtime-owned and may not be in tools (found: ${terminals.join(', ')}).`);
|
|
55
|
+
}
|
|
56
|
+
if (!cfg.persona?.trim()) {
|
|
57
|
+
throw new Error(`AgentSpec "${cfg.id}": a non-empty per-agent persona is required — persona lives in the spec, never a shared theme (persona-on-spec law).`);
|
|
58
|
+
}
|
|
59
|
+
this.id = cfg.id;
|
|
60
|
+
this.mode = cfg.mode;
|
|
61
|
+
this.persona = cfg.persona;
|
|
62
|
+
// DESIGN RULE: every agent renders its OWN scoped prompt — no shared/global persona trunk.
|
|
63
|
+
this.surface = {
|
|
64
|
+
tools: [...cfg.tools],
|
|
65
|
+
// Theme-agnostic rendering: a spec never bakes theme strings into its prompt. If it ships no
|
|
66
|
+
// own renderer, the RUNTIME renders the scoped trunk with the theme (renderScopedSpecTrunk) —
|
|
67
|
+
// so the trunk carries ONLY what the spec/theme declare, and the domain skin stays outside
|
|
68
|
+
// the AgentSpec. `theme` here is a REFERENCE for DX, not content.
|
|
69
|
+
systemPrompt: cfg.systemPrompt,
|
|
70
|
+
};
|
|
71
|
+
this.flow = [...(cfg.flow ?? [])];
|
|
72
|
+
this.guards = { onInput: [], preTool: [], postTool: [], onReply: [], onReplyMutate: [] };
|
|
73
|
+
this.controls = {
|
|
74
|
+
...(cfg.maxSteps != null ? { maxSteps: cfg.maxSteps } : {}),
|
|
75
|
+
...(cfg.redrives != null ? { redrives: cfg.redrives } : {}),
|
|
76
|
+
...(cfg.terminal ? { terminal: cfg.terminal } : {}),
|
|
77
|
+
...(cfg.directives?.length ? { directives: [...cfg.directives] } : {}),
|
|
78
|
+
...(cfg.escalate ? { escalate: cfg.escalate } : {}),
|
|
79
|
+
...(cfg.exhaustionReply ? { exhaustionReply: cfg.exhaustionReply } : {}),
|
|
80
|
+
};
|
|
81
|
+
this.behavior = [...(cfg.behavior ?? [])];
|
|
82
|
+
if (cfg.theme)
|
|
83
|
+
this.theme = cfg.theme;
|
|
84
|
+
this.destructiveTools = [...(cfg.destructiveTools ?? [])];
|
|
85
|
+
this.toolSchemas = cfg.toolSchemas ?? {};
|
|
86
|
+
this.installMinimal();
|
|
87
|
+
}
|
|
88
|
+
installMinimal() {
|
|
89
|
+
this.addGuard('preTool', 'any', noDuplicateCall(), { layer: 'minimal', id: 'minimal:noDuplicateCall' });
|
|
90
|
+
this.addGuard('onReply', 'any', emptyReply(), { layer: 'minimal', id: 'minimal:emptyReply' });
|
|
91
|
+
}
|
|
92
|
+
addGuard(hook, target, guard, opts) {
|
|
93
|
+
if (hook === 'preTool' && (guard.dim === 'behavior' || guard.dim === 'output')) {
|
|
94
|
+
throw new Error(`AgentSpec "${this.id}": a '${guard.dim}'-dim guard (${guard.kind}) cannot be a preTool gate — use onReply/postTool.`);
|
|
95
|
+
}
|
|
96
|
+
const id = opts?.id ?? `${opts?.layer ?? 'agent'}:${guard.kind}#${++this.seq}`;
|
|
97
|
+
const all = [...this.guards.onInput, ...this.guards.preTool, ...this.guards.postTool, ...this.guards.onReply];
|
|
98
|
+
if (all.some((b) => b.id === id))
|
|
99
|
+
throw new Error(`AgentSpec guard id "${id}" already exists`);
|
|
100
|
+
this.guards[hook].push({ id, target, guard, layer: opts?.layer ?? 'agent', disabled: false });
|
|
101
|
+
return id;
|
|
102
|
+
}
|
|
103
|
+
addReplyCheck(guard, opts) {
|
|
104
|
+
return this.addGuard('onReply', 'any', guard, opts);
|
|
105
|
+
}
|
|
106
|
+
addMutator(mutator, opts) {
|
|
107
|
+
const id = opts?.id ?? `${opts?.layer ?? 'agent'}:${mutator.kind}#${++this.seq}`;
|
|
108
|
+
const list = (this.guards.onReplyMutate ??= []);
|
|
109
|
+
if (list.some((b) => b.id === id))
|
|
110
|
+
throw new Error(`AgentSpec mutator id "${id}" already exists`);
|
|
111
|
+
list.push({ id, mutator, layer: opts?.layer ?? 'agent', disabled: false });
|
|
112
|
+
return id;
|
|
113
|
+
}
|
|
114
|
+
get isPureGuardSet() {
|
|
115
|
+
const all = [...this.guards.onInput, ...this.guards.preTool, ...this.guards.postTool, ...this.guards.onReply];
|
|
116
|
+
return !all.some((b) => b.guard.kind.startsWith('llm:'));
|
|
117
|
+
}
|
|
118
|
+
addBehavior(line) {
|
|
119
|
+
this.behavior.push(line);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
addFlow(edge) {
|
|
123
|
+
this.flow.push(edge);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export class AgentSpecBase extends AgentSpecMinimal {
|
|
128
|
+
constructor(cfg) {
|
|
129
|
+
super(cfg);
|
|
130
|
+
this.installBase();
|
|
131
|
+
}
|
|
132
|
+
installBase() {
|
|
133
|
+
const destructive = this.destructiveTools;
|
|
134
|
+
if (!destructive.length)
|
|
135
|
+
return;
|
|
136
|
+
const missing = destructive.filter((t) => !this.surface.tools.includes(t));
|
|
137
|
+
if (missing.length) {
|
|
138
|
+
throw new Error(`AgentSpec "${this.id}": destructiveTools not in the tool surface: ${missing.join(', ')}.`);
|
|
139
|
+
}
|
|
140
|
+
this.addGuard('preTool', destructive, confirmFirst(), { layer: 'base', id: 'base:confirmFirst' });
|
|
141
|
+
this.addGuard('preTool', destructive, destructiveThrottle(destructive), { layer: 'base', id: 'base:destructiveThrottle' });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export class AgentSpecFull extends AgentSpecBase {
|
|
145
|
+
constructor(cfg) {
|
|
146
|
+
super(cfg);
|
|
147
|
+
this.installFull();
|
|
148
|
+
}
|
|
149
|
+
installFull() {
|
|
150
|
+
for (const tool of this.surface.tools) {
|
|
151
|
+
const s = this.toolSchemas[tool];
|
|
152
|
+
if (!s)
|
|
153
|
+
continue;
|
|
154
|
+
for (const field of s.required ?? []) {
|
|
155
|
+
this.addGuard('preTool', [tool], argRequired(field), { layer: 'full', id: `full:argRequired:${tool}.${field}` });
|
|
156
|
+
}
|
|
157
|
+
for (const [field, prop] of Object.entries(s.properties ?? {})) {
|
|
158
|
+
if (!prop.pattern)
|
|
159
|
+
continue;
|
|
160
|
+
try {
|
|
161
|
+
this.addGuard('preTool', [tool], argFormat(field, prop.pattern), { layer: 'full', id: `full:argFormat:${tool}.${field}` });
|
|
162
|
+
}
|
|
163
|
+
catch { /* a malformed pattern degrades one guard, not the import */ }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=spec.js.map
|
package/dist/spec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../src/spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAgFrH,MAAM,cAAc,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;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|
package/dist/trunk.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgentSpec } from './spec.js';
|
|
2
|
+
import type { AgentWorld } from './rules.js';
|
|
3
|
+
/** The DOMAIN skin: the business-COMMON strings NOT derived from any single AgentSpec. Ideally
|
|
4
|
+
* GENERATED by the agentspec skill from the business docs. Carries NO per-agent persona — that
|
|
5
|
+
* lives on `spec.persona` (persona-on-spec law). */
|
|
6
|
+
export interface TrunkTheme {
|
|
7
|
+
/** The business VOICE paragraph — the trunk's opening. BYTE-IDENTICAL across every agent of the
|
|
8
|
+
* domain (trunk-static law: shared/static head, per-agent divergence as late as possible) and
|
|
9
|
+
* case-invariant (no volatile world state — cacheable prefix). */
|
|
10
|
+
voice: string;
|
|
11
|
+
/** The volatile account/brand-state block — rendered by the runtime onto the USER MESSAGE tail. */
|
|
12
|
+
stateBlock(world: AgentWorld): string;
|
|
13
|
+
/** The always-render "## Core rules (NEVER violate)" invariants. */
|
|
14
|
+
coreInvariants: string[];
|
|
15
|
+
/** The final "## Output language (ABSOLUTE)" clause. */
|
|
16
|
+
languageClause: string;
|
|
17
|
+
/** Deterministic honest-abstain closure (verified observations only). */
|
|
18
|
+
exhaustionReply?: (world: AgentWorld, okTools: string[], produced: string[], violations: string[]) => string;
|
|
19
|
+
}
|
|
20
|
+
/** Linearize producer→consumer edges into an ordered node path (agent flows form simple chains). */
|
|
21
|
+
export declare function chainOrder(edges: {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
}[]): string[];
|
|
25
|
+
/**
|
|
26
|
+
* The SCOPED spec trunk — the BYTE-STABLE system prompt: the theme's shared VOICE (byte-identical
|
|
27
|
+
* across the domain's agents — trunk-static law) + the theme's core invariants + the spec's Flow /
|
|
28
|
+
* Tool rules / Governance / Behavior (the spec's per-agent persona/role line renders as the FIRST
|
|
29
|
+
* Behavior bullet — per-agent divergence as late as possible) + the theme's language clause.
|
|
30
|
+
* NO account/brand state (that rides the user message tail — state-in-tail). `_uploads` is accepted
|
|
31
|
+
* for signature compatibility but not rendered (upload labels also ride the user message).
|
|
32
|
+
* The theme resolves host-injected first, then `spec.theme`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function renderScopedSpecTrunk(_world: AgentWorld, spec: AgentSpec, _uploads?: readonly string[], theme?: TrunkTheme): string;
|
|
35
|
+
//# sourceMappingURL=trunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trunk.d.ts","sourceRoot":"","sources":["../src/trunk.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;qDAEqD;AACrD,MAAM,WAAW,UAAU;IACzB;;uEAEmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,mGAAmG;IACnG,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;IACtC,oEAAoE;IACpE,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,wDAAwD;IACxD,cAAc,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CAC9G;AAED,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,MAAM,EAAE,CAkB1E;AA4BD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,EACf,QAAQ,GAAE,SAAS,MAAM,EAAO,EAChC,KAAK,CAAC,EAAE,UAAU,GACjB,MAAM,CA0BR"}
|
package/dist/trunk.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @looprun-ai/core — the DOMAIN-NEUTRAL trunk renderer + the `TrunkTheme` interface.
|
|
3
|
+
*
|
|
4
|
+
* This file contains ZERO business content — it is pure assembly machinery. Every business string
|
|
5
|
+
* comes from a GENERATED artifact with exactly one owner: the AgentSpec (persona / Flow / Tool rules /
|
|
6
|
+
* Governance / Behavior — per-agent) or the domain `TrunkTheme` (voice / core invariants / language /
|
|
7
|
+
* state-render mapping — common to a business's agents). The per-agent persona (role line,
|
|
8
|
+
* persona-on-spec law) lives on `spec.persona` and renders as the FIRST Behavior bullet; the shared
|
|
9
|
+
* business `voice` lives on the theme and opens the trunk — byte-identical across the domain's agents
|
|
10
|
+
* (trunk-static law: maximal shared prefix, per-agent divergence as late as possible).
|
|
11
|
+
*
|
|
12
|
+
* State-in-tail: `renderScopedSpecTrunk` renders ONLY case-invariant content, so the assembled
|
|
13
|
+
* system prompt is BYTE-STABLE across cases/turns of an agent (→ cacheable prefix). The volatile
|
|
14
|
+
* account/brand STATE (`theme.stateBlock`) is NOT rendered here — the runtime rides it on the USER
|
|
15
|
+
* MESSAGE tail (like upload labels), keeping the stable prefix intact. For that to hold, a spec's
|
|
16
|
+
* `persona` MUST be case-invariant (do not interpolate volatile world state into it).
|
|
17
|
+
*/
|
|
18
|
+
import { resolveBindings } from './spec.js';
|
|
19
|
+
/** Linearize producer→consumer edges into an ordered node path (agent flows form simple chains). */
|
|
20
|
+
export function chainOrder(edges) {
|
|
21
|
+
if (!edges.length)
|
|
22
|
+
return [];
|
|
23
|
+
const succ = new Map();
|
|
24
|
+
const hasPred = new Set();
|
|
25
|
+
for (const e of edges) {
|
|
26
|
+
succ.set(e.from, e.to);
|
|
27
|
+
hasPred.add(e.to);
|
|
28
|
+
}
|
|
29
|
+
const start = edges.map((e) => e.from).find((n) => !hasPred.has(n)) ?? edges[0].from;
|
|
30
|
+
const order = [];
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
let cur = start;
|
|
33
|
+
while (cur && !seen.has(cur)) {
|
|
34
|
+
order.push(cur);
|
|
35
|
+
seen.add(cur);
|
|
36
|
+
cur = succ.get(cur);
|
|
37
|
+
}
|
|
38
|
+
return order;
|
|
39
|
+
}
|
|
40
|
+
function ruleSections(spec) {
|
|
41
|
+
const pre = resolveBindings(spec.guards.preTool);
|
|
42
|
+
const post = resolveBindings(spec.guards.postTool);
|
|
43
|
+
const all = [...pre, ...post];
|
|
44
|
+
const globals = all.filter((b) => b.target === 'any');
|
|
45
|
+
const globalSection = globals.length
|
|
46
|
+
? `## Global tool rules\n${globals.map((b) => `- ${b.guard.prose()}.`).join('\n')}`
|
|
47
|
+
: null;
|
|
48
|
+
const lines = [];
|
|
49
|
+
for (const tool of spec.surface.tools) {
|
|
50
|
+
const scoped = all.filter((b) => b.target !== 'any' && b.target.includes(tool));
|
|
51
|
+
if (scoped.length)
|
|
52
|
+
lines.push(`- **${tool}**: ${scoped.map((b) => b.guard.prose()).join('; ')}.`);
|
|
53
|
+
}
|
|
54
|
+
const toolSection = lines.length ? `## Tool rules\n${lines.join('\n')}` : null;
|
|
55
|
+
return { globalSection, toolSection };
|
|
56
|
+
}
|
|
57
|
+
function governanceSection(spec, heading) {
|
|
58
|
+
const directives = spec.controls.directives ?? [];
|
|
59
|
+
if (!directives.length)
|
|
60
|
+
return null;
|
|
61
|
+
return `${heading}\n${directives.map((d) => `- IF ${d.cond} → ${d.directive}`).join('\n')}`;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The SCOPED spec trunk — the BYTE-STABLE system prompt: the theme's shared VOICE (byte-identical
|
|
65
|
+
* across the domain's agents — trunk-static law) + the theme's core invariants + the spec's Flow /
|
|
66
|
+
* Tool rules / Governance / Behavior (the spec's per-agent persona/role line renders as the FIRST
|
|
67
|
+
* Behavior bullet — per-agent divergence as late as possible) + the theme's language clause.
|
|
68
|
+
* NO account/brand state (that rides the user message tail — state-in-tail). `_uploads` is accepted
|
|
69
|
+
* for signature compatibility but not rendered (upload labels also ride the user message).
|
|
70
|
+
* The theme resolves host-injected first, then `spec.theme`.
|
|
71
|
+
*/
|
|
72
|
+
export function renderScopedSpecTrunk(_world, spec, _uploads = [], theme) {
|
|
73
|
+
const t = theme ?? spec.theme;
|
|
74
|
+
if (!t)
|
|
75
|
+
throw new Error('renderScopedSpecTrunk: a TrunkTheme is required (pass one, or set spec.theme).');
|
|
76
|
+
const parts = [
|
|
77
|
+
t.voice,
|
|
78
|
+
`## Core rules (NEVER violate)\n${t.coreInvariants.map((r) => `- ${r}`).join('\n')}`,
|
|
79
|
+
];
|
|
80
|
+
const order = chainOrder(spec.flow);
|
|
81
|
+
if (order.length)
|
|
82
|
+
parts.push(`## Flow (call the tools in THIS order — do not skip a step)\n${order.join(' → ')}`);
|
|
83
|
+
const { globalSection, toolSection } = ruleSections(spec);
|
|
84
|
+
if (globalSection)
|
|
85
|
+
parts.push(globalSection);
|
|
86
|
+
if (toolSection)
|
|
87
|
+
parts.push(toolSection);
|
|
88
|
+
const gov = governanceSection(spec, '## Governance (deterministic — evaluate against the account state below)');
|
|
89
|
+
if (gov)
|
|
90
|
+
parts.push(gov);
|
|
91
|
+
// The per-agent persona (role line) leads the Behavior list — the LAST section before language,
|
|
92
|
+
// so agents of a domain share the maximal static prefix (trunk-static law).
|
|
93
|
+
const behaviorLines = [spec.persona, ...spec.behavior];
|
|
94
|
+
parts.push(`## Behavior\n${behaviorLines.map((b) => `- ${b}`).join('\n')}`);
|
|
95
|
+
parts.push(t.languageClause);
|
|
96
|
+
return parts.join('\n\n');
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=trunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trunk.js","sourceRoot":"","sources":["../src/trunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAsB5C,oGAAoG;AACpG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G;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzB,gGAAgG;IAChG,4EAA4E;IAC5E,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvD,KAAK,CAAC,IAAI,CAAC,gBAAgB,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE5E,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @looprun-ai/core — spec validation (the library-side spec laws).
|
|
3
|
+
*
|
|
4
|
+
* `validateSpec` returns warnings instead of throwing: a host decides strictness (LoopRunAgent's
|
|
5
|
+
* `strict: true` throws on any warning). Hard invariants (terminal tools in the surface, empty
|
|
6
|
+
* persona) already throw in the AgentSpec constructor.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentSpec } from './spec.js';
|
|
9
|
+
export declare const MAX_TOOL_SURFACE = 15;
|
|
10
|
+
export interface SpecWarning {
|
|
11
|
+
code: 'tool-surface-over-15' | 'empty-behavior' | 'duplicate-tools' | 'flow-tool-missing';
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function validateSpec(spec: AgentSpec): SpecWarning[];
|
|
15
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,mBAAmB,CAAC;IAC1F,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,EAAE,CAuC3D"}
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const MAX_TOOL_SURFACE = 15;
|
|
2
|
+
export function validateSpec(spec) {
|
|
3
|
+
const warnings = [];
|
|
4
|
+
if (spec.surface.tools.length > MAX_TOOL_SURFACE) {
|
|
5
|
+
warnings.push({
|
|
6
|
+
code: 'tool-surface-over-15',
|
|
7
|
+
message: `AgentSpec "${spec.id}": ${spec.surface.tools.length} tools exceed the ≤${MAX_TOOL_SURFACE} surface law — ` +
|
|
8
|
+
'split the agent by TOOL-NEED (never by user intent).',
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
const dups = spec.surface.tools.filter((t) => (seen.has(t) ? true : (seen.add(t), false)));
|
|
13
|
+
if (dups.length) {
|
|
14
|
+
warnings.push({
|
|
15
|
+
code: 'duplicate-tools',
|
|
16
|
+
message: `AgentSpec "${spec.id}": duplicate tools in the surface: ${[...new Set(dups)].join(', ')}.`,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!spec.behavior.length) {
|
|
20
|
+
warnings.push({
|
|
21
|
+
code: 'empty-behavior',
|
|
22
|
+
message: `AgentSpec "${spec.id}": no behavior bullets — the persona alone rarely covers the agent's jobs.`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const surface = new Set(spec.surface.tools);
|
|
26
|
+
const flowTools = spec.flow.flatMap((e) => [e.from, e.to]);
|
|
27
|
+
const missing = [...new Set(flowTools.filter((t) => !surface.has(t)))];
|
|
28
|
+
if (missing.length) {
|
|
29
|
+
warnings.push({
|
|
30
|
+
code: 'flow-tool-missing',
|
|
31
|
+
message: `AgentSpec "${spec.id}": flow references tools outside the surface: ${missing.join(', ')}.`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return warnings;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAOnC,MAAM,UAAU,YAAY,CAAC,IAAe;IAC1C,MAAM,QAAQ,GAAkB,EAAE,CAAC;IAEnC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,gBAAgB,EAAE,CAAC;QACjD,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,sBAAsB;YAC5B,OAAO,EACL,cAAc,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,sBAAsB,gBAAgB,iBAAiB;gBAC3G,sDAAsD;SACzD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3F,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,cAAc,IAAI,CAAC,EAAE,sCAAsC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACrG,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC1B,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,cAAc,IAAI,CAAC,EAAE,4EAA4E;SAC3G,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,cAAc,IAAI,CAAC,EAAE,iDAAiD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACrG,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@looprun-ai/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "looprun core: the AgentSpec governance layer for LLM agents — typed deterministic guards (prose+check pairing), the byte-stable scoped trunk renderer, and the backend-agnostic governed-turn machine. Framework-free: zero runtime dependencies; backends (@looprun-ai/mastra, …) supply the loop.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ai",
|
|
8
|
+
"agents",
|
|
9
|
+
"llm",
|
|
10
|
+
"governance",
|
|
11
|
+
"guardrails",
|
|
12
|
+
"agentspec",
|
|
13
|
+
"deterministic",
|
|
14
|
+
"guards"
|
|
15
|
+
],
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"author": "LoopRun Team",
|
|
18
|
+
"homepage": "https://looprun.ai",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/looprun-ai/looprun.git",
|
|
22
|
+
"directory": "packages/core"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/looprun-ai/looprun/issues"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.0.0",
|
|
41
|
+
"typescript": "^5.7.0",
|
|
42
|
+
"vitest": "^2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -p tsconfig.build.json",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
49
|
+
}
|