agent-contracts-runtime 0.36.17 → 0.36.18
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/cli-contract.yaml +1 -1
- package/dist/adapters/claude-agent-sdk.d.ts +2 -0
- package/dist/adapters/claude-agent-sdk.js +21 -7
- package/dist/adapters/claude-agent-sdk.js.map +1 -1
- package/dist/adapters/mock.js +3 -37
- package/dist/adapters/mock.js.map +1 -1
- package/dist/agent-runtime.bundle.mjs +221 -219
- package/dist/agent-runtime.bundle.mjs.map +4 -4
- package/dist/{bound-resolver-I7WLYGC6.js → bound-resolver-RPJYAOCW.js} +4 -4
- package/dist/{chunk-S7MTKPBF.js → chunk-CFOEW6XJ.js} +4 -25
- package/dist/chunk-CFOEW6XJ.js.map +1 -0
- package/dist/chunk-KB4VDAAQ.js +740 -0
- package/dist/chunk-KB4VDAAQ.js.map +1 -0
- package/dist/chunk-L5OAGF7D.js +42 -0
- package/dist/chunk-L5OAGF7D.js.map +1 -0
- package/dist/{chunk-VKCNOSMQ.js → chunk-UHHKLLA3.js} +68 -57
- package/dist/chunk-UHHKLLA3.js.map +1 -0
- package/dist/cli/index.js +29 -40
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.js +2 -2
- package/dist/{guardrail-hooks-CFd3a8tQ.d.ts → guardrail-hooks-BiLI9u9-.d.ts} +12 -6
- package/dist/index.d.ts +12 -5
- package/dist/index.js +10 -12
- package/dist/{task-runner-DJW49UGZ.d.ts → task-runner-Ba4kLv7O.d.ts} +2 -0
- package/docs/cli-reference.md +1 -1
- package/package.json +1 -1
- package/dist/chunk-2E2LWE6C.js +0 -171
- package/dist/chunk-2E2LWE6C.js.map +0 -1
- package/dist/chunk-D2QTXQB2.js +0 -266
- package/dist/chunk-D2QTXQB2.js.map +0 -1
- package/dist/chunk-KKJW4TE5.js +0 -302
- package/dist/chunk-KKJW4TE5.js.map +0 -1
- package/dist/chunk-S7MTKPBF.js.map +0 -1
- package/dist/chunk-VKCNOSMQ.js.map +0 -1
- package/dist/dsl-context-LACANPO4.js +0 -13
- package/dist/dsl-context-LACANPO4.js.map +0 -1
- /package/dist/{bound-resolver-I7WLYGC6.js.map → bound-resolver-RPJYAOCW.js.map} +0 -0
package/dist/generator/index.js
CHANGED
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
generate,
|
|
6
6
|
loadConfig,
|
|
7
7
|
loadProjectConfig
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-CFOEW6XJ.js";
|
|
9
9
|
import {
|
|
10
10
|
buildContractContext,
|
|
11
11
|
buildGuardrailContext
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-KB4VDAAQ.js";
|
|
13
13
|
export {
|
|
14
14
|
DEFAULT_CONFIG_PATH,
|
|
15
15
|
ProjectConfigSchema,
|
|
@@ -46,13 +46,18 @@ interface GuardrailHooks {
|
|
|
46
46
|
beforeShellExecution: (input: {
|
|
47
47
|
command?: string;
|
|
48
48
|
}) => HookResponse;
|
|
49
|
+
/**
|
|
50
|
+
* `root` is the directory the rule patterns are written against (the agent's
|
|
51
|
+
* working directory); it defaults to process.cwd().
|
|
52
|
+
*/
|
|
49
53
|
preToolUse: (input: {
|
|
50
54
|
tool_name?: string;
|
|
51
55
|
tool_input?: {
|
|
52
56
|
file_path?: string;
|
|
53
57
|
path?: string;
|
|
58
|
+
content?: string;
|
|
54
59
|
};
|
|
55
|
-
}) => HookResponse;
|
|
60
|
+
}, root?: string) => HookResponse;
|
|
56
61
|
afterFileEdit: (input: {
|
|
57
62
|
file_path?: string;
|
|
58
63
|
content?: string;
|
|
@@ -70,15 +75,16 @@ declare function hasBlockingViolation(results: GuardrailCheckResult[]): boolean;
|
|
|
70
75
|
* plus a generic runChecks() for programmatic use.
|
|
71
76
|
*/
|
|
72
77
|
declare function createGuardrailHooks(checks: GuardrailCheckFunctions): GuardrailHooks;
|
|
73
|
-
/**
|
|
74
|
-
* Create SDK hook functions from embedded guardrail rule data.
|
|
75
|
-
*/
|
|
76
78
|
/**
|
|
77
79
|
* Create SDK hooks scoped to a single agent from a per-agent guardrail map.
|
|
78
|
-
*
|
|
80
|
+
* An agent without rules in the map gets hooks that evaluate plugin guardrails only.
|
|
79
81
|
*/
|
|
80
82
|
declare function createGuardrailHooksForAgent(agentId: string, perAgent: Map<string, GuardrailRuleData>): GuardrailHooks;
|
|
81
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Create SDK hook functions from embedded guardrail rule data. Without rules
|
|
85
|
+
* the hooks still evaluate the plugin-registered guardrails.
|
|
86
|
+
*/
|
|
87
|
+
declare function createGuardrailHooksFromRules(rules: GuardrailRuleData | undefined): GuardrailHooks;
|
|
82
88
|
|
|
83
89
|
export { createGuardrailHooks as f, createGuardrailHooksForAgent as g, createGuardrailHooksFromRules as h, getBlockingViolations as i, getWarnings as j, hasBlockingViolation as k };
|
|
84
90
|
export type { GuardrailHooks as G, HookContext as H, GuardrailRuleData as a, GuardrailCheckFunctions as b, GuardrailCheckResult as c, GuardrailRule as d, HookResponse as e };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { S as SdkAdapter, T as TaskOutcome, b as TaskContractLike, c as AgentContractLike, d as TaskContext, P as PromptBuilderOptions, e as TaskRunResult } from './task-runner-
|
|
2
|
-
export { A as AdapterSendOptions, a as AgentExecutionRequest, f as AgentProgressEvent, C as CacheConfig, g as CandidateAgent, I as InMemoryStore, M as MemoryRef, h as MemoryStore, R as RetryDecision, i as SplitPrompt, j as TaskRunOptions, k as buildCandidateAgents, l as buildRetryFollowUp, m as buildSplitTaskPrompt, n as buildTaskPrompt, o as extractStructuredResult, r as renderAgentSystemPrompt, p as runTask, z as zodSchemaToPromptDescription, q as zodSchemaToYamlExample } from './task-runner-
|
|
1
|
+
import { S as SdkAdapter, T as TaskOutcome, b as TaskContractLike, c as AgentContractLike, d as TaskContext, P as PromptBuilderOptions, e as TaskRunResult } from './task-runner-Ba4kLv7O.js';
|
|
2
|
+
export { A as AdapterSendOptions, a as AgentExecutionRequest, f as AgentProgressEvent, C as CacheConfig, g as CandidateAgent, I as InMemoryStore, M as MemoryRef, h as MemoryStore, R as RetryDecision, i as SplitPrompt, j as TaskRunOptions, k as buildCandidateAgents, l as buildRetryFollowUp, m as buildSplitTaskPrompt, n as buildTaskPrompt, o as extractStructuredResult, r as renderAgentSystemPrompt, p as runTask, z as zodSchemaToPromptDescription, q as zodSchemaToYamlExample } from './task-runner-Ba4kLv7O.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { a as GuardrailRuleData, G as GuardrailHooks } from './guardrail-hooks-
|
|
5
|
-
export { b as GuardrailCheckFunctions, c as GuardrailCheckResult, d as GuardrailRule, H as HookContext, e as HookResponse, f as createGuardrailHooks, g as createGuardrailHooksForAgent, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-
|
|
4
|
+
import { a as GuardrailRuleData, G as GuardrailHooks } from './guardrail-hooks-BiLI9u9-.js';
|
|
5
|
+
export { b as GuardrailCheckFunctions, c as GuardrailCheckResult, d as GuardrailRule, H as HookContext, e as HookResponse, f as createGuardrailHooks, g as createGuardrailHooksForAgent, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-BiLI9u9-.js';
|
|
6
6
|
import { G as GuardrailContext } from './context-BEisfYPn.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -118,6 +118,10 @@ interface WorkflowRunOptions {
|
|
|
118
118
|
progressOutput?: {
|
|
119
119
|
write(chunk: string): unknown;
|
|
120
120
|
};
|
|
121
|
+
/** Run every step with read-only tools. */
|
|
122
|
+
readonly?: boolean;
|
|
123
|
+
/** Simulate the workflow with the mock adapter instead of the given adapter. */
|
|
124
|
+
dryRun?: boolean;
|
|
121
125
|
}
|
|
122
126
|
/** Typed handoff envelope for workflow input. */
|
|
123
127
|
interface HandoffInput<TType extends string = string, TPayload = unknown> {
|
|
@@ -319,7 +323,10 @@ interface ResolvedComponent {
|
|
|
319
323
|
}>;
|
|
320
324
|
}
|
|
321
325
|
/**
|
|
322
|
-
* Effective guardrail IDs for an agent: entity-side bindings ∪ scope-side
|
|
326
|
+
* Effective guardrail IDs for an agent: entity-side bindings ∪ scope-side
|
|
327
|
+
* bindings ∪ the guardrails attributed to no agent. A guardrail without
|
|
328
|
+
* `scope.agents` that no `agents[].guardrails` references applies to every
|
|
329
|
+
* agent run in-process, as it does on every other route.
|
|
323
330
|
*/
|
|
324
331
|
declare function getEffectiveGuardrailIds(dsl: Record<string, unknown>, agentId: string): Set<string>;
|
|
325
332
|
declare function guardrailContextToRuleData(ctx: GuardrailContext, effectiveIds?: Set<string>): GuardrailRuleData;
|
package/dist/index.js
CHANGED
|
@@ -29,25 +29,23 @@ import {
|
|
|
29
29
|
runWorkflow,
|
|
30
30
|
zodSchemaToPromptDescription,
|
|
31
31
|
zodSchemaToYamlExample
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import
|
|
34
|
-
createModelResolver
|
|
35
|
-
} from "./chunk-AWBHN3LI.js";
|
|
32
|
+
} from "./chunk-UHHKLLA3.js";
|
|
33
|
+
import "./chunk-L5OAGF7D.js";
|
|
36
34
|
import {
|
|
37
35
|
BoundResolver,
|
|
38
|
-
buildPerAgentGuardrails,
|
|
39
|
-
getEffectiveGuardrailIds,
|
|
40
|
-
getGuardrailRulesForAgent,
|
|
41
|
-
guardrailContextToRuleData
|
|
42
|
-
} from "./chunk-2E2LWE6C.js";
|
|
43
|
-
import "./chunk-KKJW4TE5.js";
|
|
44
|
-
import {
|
|
45
36
|
DslValidationError,
|
|
46
37
|
buildGuardrailRulesFromDsl,
|
|
38
|
+
buildPerAgentGuardrails,
|
|
47
39
|
buildRegistriesFromDsl,
|
|
40
|
+
getEffectiveGuardrailIds,
|
|
41
|
+
getGuardrailRulesForAgent,
|
|
42
|
+
guardrailContextToRuleData,
|
|
48
43
|
jsonSchemaToZod,
|
|
49
44
|
loadDslContext
|
|
50
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-KB4VDAAQ.js";
|
|
46
|
+
import {
|
|
47
|
+
createModelResolver
|
|
48
|
+
} from "./chunk-AWBHN3LI.js";
|
|
51
49
|
export {
|
|
52
50
|
BoundResolver,
|
|
53
51
|
DslValidationError,
|
|
@@ -345,6 +345,8 @@ interface TaskRunOptions {
|
|
|
345
345
|
progressOutput?: {
|
|
346
346
|
write(chunk: string): unknown;
|
|
347
347
|
};
|
|
348
|
+
/** Run the task with read-only tools even when the agent is read-write. */
|
|
349
|
+
readonly?: boolean;
|
|
348
350
|
}
|
|
349
351
|
interface TaskRunResult {
|
|
350
352
|
outcome: TaskOutcome;
|
package/docs/cli-reference.md
CHANGED
package/package.json
CHANGED
package/dist/chunk-2E2LWE6C.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildGuardrailContext
|
|
3
|
-
} from "./chunk-KKJW4TE5.js";
|
|
4
|
-
import {
|
|
5
|
-
buildRegistriesFromDsl
|
|
6
|
-
} from "./chunk-D2QTXQB2.js";
|
|
7
|
-
|
|
8
|
-
// src/lib/bound-resolver.ts
|
|
9
|
-
import { readFile } from "fs/promises";
|
|
10
|
-
import YAML from "yaml";
|
|
11
|
-
function getEffectiveGuardrailIds(dsl, agentId) {
|
|
12
|
-
const ids = /* @__PURE__ */ new Set();
|
|
13
|
-
const agents = dsl.agents ?? {};
|
|
14
|
-
const agent = agents[agentId];
|
|
15
|
-
if (agent) {
|
|
16
|
-
for (const ref of agent.guardrails ?? []) {
|
|
17
|
-
ids.add(ref);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const guardrails = dsl.guardrails ?? {};
|
|
21
|
-
for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
|
|
22
|
-
if (guardrail.scope?.agents?.includes(agentId)) {
|
|
23
|
-
ids.add(guardrailId);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return ids;
|
|
27
|
-
}
|
|
28
|
-
function guardrailCheckToCommandRule(c) {
|
|
29
|
-
return {
|
|
30
|
-
guardrail_id: c.guardrail_id,
|
|
31
|
-
pattern: c.pattern,
|
|
32
|
-
action: c.action,
|
|
33
|
-
message: c.message
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function guardrailCheckToFileRule(c) {
|
|
37
|
-
return {
|
|
38
|
-
guardrail_id: c.guardrail_id,
|
|
39
|
-
pattern: c.pattern,
|
|
40
|
-
action: c.action,
|
|
41
|
-
message: c.message,
|
|
42
|
-
...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function guardrailCheckToContentRule(c) {
|
|
46
|
-
return {
|
|
47
|
-
guardrail_id: c.guardrail_id,
|
|
48
|
-
pattern: c.pattern,
|
|
49
|
-
action: c.action,
|
|
50
|
-
message: c.message,
|
|
51
|
-
...c.file_glob ? { file_glob: c.file_glob } : {},
|
|
52
|
-
...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function guardrailContextToRuleData(ctx, effectiveIds) {
|
|
56
|
-
const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
|
|
57
|
-
return {
|
|
58
|
-
commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
|
|
59
|
-
fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
|
|
60
|
-
contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function buildPerAgentGuardrails(dsl, guardrailCtx) {
|
|
64
|
-
const perAgent = /* @__PURE__ */ new Map();
|
|
65
|
-
const agents = dsl.agents ?? {};
|
|
66
|
-
for (const agentId of Object.keys(agents)) {
|
|
67
|
-
const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
|
|
68
|
-
const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
|
|
69
|
-
if (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) {
|
|
70
|
-
perAgent.set(agentId, rules);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return perAgent;
|
|
74
|
-
}
|
|
75
|
-
function hasGuardrailRules(rules) {
|
|
76
|
-
return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
|
|
77
|
-
}
|
|
78
|
-
var BoundResolver = class {
|
|
79
|
-
cache = /* @__PURE__ */ new Map();
|
|
80
|
-
/**
|
|
81
|
-
* Resolve binding + policy in one pass. Results are cached by component id.
|
|
82
|
-
*/
|
|
83
|
-
async resolve(opts) {
|
|
84
|
-
const cached = this.cache.get(opts.id);
|
|
85
|
-
if (cached) return cached;
|
|
86
|
-
const diagnostics = [];
|
|
87
|
-
let dsl;
|
|
88
|
-
if (opts.embeddedDsl) {
|
|
89
|
-
dsl = opts.embeddedDsl;
|
|
90
|
-
} else if (opts.dslPath) {
|
|
91
|
-
const { resolve: resolveDsl } = await import("agent-contracts");
|
|
92
|
-
const result = await resolveDsl(opts.dslPath);
|
|
93
|
-
dsl = result.data;
|
|
94
|
-
} else {
|
|
95
|
-
throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
|
|
96
|
-
}
|
|
97
|
-
if (opts.artifactBinding) {
|
|
98
|
-
const { resolveBound } = await import("agent-contracts");
|
|
99
|
-
const boundResult = await resolveBound(dsl, {
|
|
100
|
-
artifactBinding: opts.artifactBinding,
|
|
101
|
-
paths: opts.paths
|
|
102
|
-
});
|
|
103
|
-
dsl = boundResult.data;
|
|
104
|
-
for (const d of boundResult.diagnostics) {
|
|
105
|
-
diagnostics.push({
|
|
106
|
-
path: d.rule,
|
|
107
|
-
message: d.message,
|
|
108
|
-
severity: d.severity
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
let guardrailCtx = {
|
|
113
|
-
commandChecks: [],
|
|
114
|
-
fileChecks: [],
|
|
115
|
-
contentChecks: [],
|
|
116
|
-
allChecks: [],
|
|
117
|
-
hasGuardrails: false
|
|
118
|
-
};
|
|
119
|
-
if (opts.bindingPaths && opts.bindingPaths.length > 0) {
|
|
120
|
-
for (const bindingPath of opts.bindingPaths) {
|
|
121
|
-
const raw = await readFile(bindingPath, "utf8");
|
|
122
|
-
const binding = YAML.parse(raw);
|
|
123
|
-
guardrailCtx = buildGuardrailContext(
|
|
124
|
-
dsl,
|
|
125
|
-
binding,
|
|
126
|
-
opts.activeGuardrailPolicy
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
|
|
131
|
-
const component = {
|
|
132
|
-
id: opts.id,
|
|
133
|
-
dsl,
|
|
134
|
-
registries: buildRegistriesFromDsl(dsl),
|
|
135
|
-
guardrails: { perAgent },
|
|
136
|
-
diagnostics
|
|
137
|
-
};
|
|
138
|
-
this.cache.set(opts.id, component);
|
|
139
|
-
return component;
|
|
140
|
-
}
|
|
141
|
-
/** Clear cached components (e.g. for testing). */
|
|
142
|
-
clearCache() {
|
|
143
|
-
this.cache.clear();
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
function getGuardrailRulesForAgent(component, agentId, fallbackDsl) {
|
|
147
|
-
const perAgent = component.guardrails.perAgent.get(agentId);
|
|
148
|
-
if (perAgent && hasGuardrailRules(perAgent)) {
|
|
149
|
-
return perAgent;
|
|
150
|
-
}
|
|
151
|
-
if (fallbackDsl) {
|
|
152
|
-
const raw = fallbackDsl._guardrailRules;
|
|
153
|
-
if (raw) {
|
|
154
|
-
return {
|
|
155
|
-
commandRules: raw.commandRules ?? [],
|
|
156
|
-
fileRules: raw.fileRules ?? [],
|
|
157
|
-
contentRules: raw.contentRules ?? []
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return void 0;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export {
|
|
165
|
-
getEffectiveGuardrailIds,
|
|
166
|
-
guardrailContextToRuleData,
|
|
167
|
-
buildPerAgentGuardrails,
|
|
168
|
-
BoundResolver,
|
|
169
|
-
getGuardrailRulesForAgent
|
|
170
|
-
};
|
|
171
|
-
//# sourceMappingURL=chunk-2E2LWE6C.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/bound-resolver.ts"],"sourcesContent":["/**\n * BoundResolver — runtime binding + policy resolution with per-agent isolation.\n *\n * Resolves artifact binding and guardrail/policy in one pass at runtime,\n * producing a per-agent scoped ResolvedComponent. Reuses existing\n * resolveBound(), buildGuardrailContext(), and agent scope resolution.\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport YAML from \"yaml\";\nimport { buildGuardrailContext, type GuardrailCheckEntry, type GuardrailContext } from \"../generator/context.js\";\nimport { buildRegistriesFromDsl } from \"./dsl-context.js\";\nimport type { GuardrailRuleData } from \"./guardrail-hooks.js\";\nimport type { WorkflowRegistries } from \"./workflow-runner.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface ArtifactBindingConfig {\n source: string;\n mappings?: Record<string, string>;\n}\n\nexport interface BoundResolveOptions {\n /** Component identifier — used for cache keying. */\n id: string;\n /** Pre-resolved DSL (e.g. embedded from codegen). */\n embeddedDsl?: Record<string, unknown>;\n /** Path to DSL file — resolved via agent-contracts when no embeddedDsl. */\n dslPath?: string;\n /** Paths to software binding YAML files (guardrail_impl, etc.). */\n bindingPaths?: string[];\n /** Active guardrail policy name from DSL guardrail_policies. */\n activeGuardrailPolicy?: string;\n /** Artifact binding config — resolved via agent-contracts resolveBound(). */\n artifactBinding?: ArtifactBindingConfig;\n /** Path substitutions for artifact binding. */\n paths?: Record<string, string>;\n}\n\nexport interface ResolvedComponent {\n id: string;\n dsl: Record<string, unknown>;\n registries: WorkflowRegistries;\n guardrails: {\n perAgent: Map<string, GuardrailRuleData>;\n };\n diagnostics: Array<{ path?: string; message: string; severity?: string }>;\n}\n\n// ---------------------------------------------------------------------------\n// Guardrail scope helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Effective guardrail IDs for an agent: entity-side bindings ∪ scope-side bindings.\n */\nexport function getEffectiveGuardrailIds(\n dsl: Record<string, unknown>,\n agentId: string,\n): Set<string> {\n const ids = new Set<string>();\n\n const agents = (dsl.agents ?? {}) as Record<string, Record<string, unknown>>;\n const agent = agents[agentId];\n if (agent) {\n for (const ref of (agent.guardrails as string[]) ?? []) {\n ids.add(ref);\n }\n }\n\n const guardrails = (dsl.guardrails ?? {}) as Record<\n string,\n { scope?: { agents?: string[] } }\n >;\n for (const [guardrailId, guardrail] of Object.entries(guardrails)) {\n if (guardrail.scope?.agents?.includes(agentId)) {\n ids.add(guardrailId);\n }\n }\n\n return ids;\n}\n\nfunction guardrailCheckToCommandRule(c: GuardrailCheckEntry) {\n return {\n guardrail_id: c.guardrail_id,\n pattern: c.pattern,\n action: c.action as GuardrailRuleData[\"commandRules\"][number][\"action\"],\n message: c.message,\n };\n}\n\nfunction guardrailCheckToFileRule(c: GuardrailCheckEntry) {\n return {\n guardrail_id: c.guardrail_id,\n pattern: c.pattern,\n action: c.action as GuardrailRuleData[\"fileRules\"][number][\"action\"],\n message: c.message,\n ...(c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}),\n };\n}\n\nfunction guardrailCheckToContentRule(c: GuardrailCheckEntry) {\n return {\n guardrail_id: c.guardrail_id,\n pattern: c.pattern,\n action: c.action as GuardrailRuleData[\"contentRules\"][number][\"action\"],\n message: c.message,\n ...(c.file_glob ? { file_glob: c.file_glob } : {}),\n ...(c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}),\n };\n}\n\nexport function guardrailContextToRuleData(\n ctx: GuardrailContext,\n effectiveIds?: Set<string>,\n): GuardrailRuleData {\n const filter = (checks: GuardrailCheckEntry[]) =>\n effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;\n\n return {\n commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),\n fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),\n contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule),\n };\n}\n\nexport function buildPerAgentGuardrails(\n dsl: Record<string, unknown>,\n guardrailCtx: GuardrailContext,\n): Map<string, GuardrailRuleData> {\n const perAgent = new Map<string, GuardrailRuleData>();\n const agents = (dsl.agents ?? {}) as Record<string, unknown>;\n\n for (const agentId of Object.keys(agents)) {\n const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);\n const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);\n if (\n rules.commandRules.length > 0 ||\n rules.fileRules.length > 0 ||\n rules.contentRules.length > 0\n ) {\n perAgent.set(agentId, rules);\n }\n }\n\n return perAgent;\n}\n\nfunction hasGuardrailRules(rules: GuardrailRuleData): boolean {\n return (\n rules.commandRules.length > 0 ||\n rules.fileRules.length > 0 ||\n rules.contentRules.length > 0\n );\n}\n\n// ---------------------------------------------------------------------------\n// BoundResolver\n// ---------------------------------------------------------------------------\n\nexport class BoundResolver {\n private readonly cache = new Map<string, ResolvedComponent>();\n\n /**\n * Resolve binding + policy in one pass. Results are cached by component id.\n */\n async resolve(opts: BoundResolveOptions): Promise<ResolvedComponent> {\n const cached = this.cache.get(opts.id);\n if (cached) return cached;\n\n const diagnostics: ResolvedComponent[\"diagnostics\"] = [];\n let dsl: Record<string, unknown>;\n\n if (opts.embeddedDsl) {\n dsl = opts.embeddedDsl;\n } else if (opts.dslPath) {\n const { resolve: resolveDsl } = await import(\"agent-contracts\");\n const result = await resolveDsl(opts.dslPath);\n dsl = result.data;\n } else {\n throw new Error(\"BoundResolver.resolve requires embeddedDsl or dslPath\");\n }\n\n // Artifact binding (resolveBound)\n if (opts.artifactBinding) {\n const { resolveBound } = await import(\"agent-contracts\");\n const boundResult = await resolveBound(dsl, {\n artifactBinding: opts.artifactBinding,\n paths: opts.paths,\n });\n dsl = boundResult.data;\n for (const d of boundResult.diagnostics) {\n diagnostics.push({\n path: d.rule,\n message: d.message,\n severity: d.severity,\n });\n }\n }\n\n // Guardrail + policy from bindings\n let guardrailCtx: GuardrailContext = {\n commandChecks: [],\n fileChecks: [],\n contentChecks: [],\n allChecks: [],\n hasGuardrails: false,\n };\n\n if (opts.bindingPaths && opts.bindingPaths.length > 0) {\n for (const bindingPath of opts.bindingPaths) {\n const raw = await readFile(bindingPath, \"utf8\");\n const binding = YAML.parse(raw) as Record<string, unknown>;\n guardrailCtx = buildGuardrailContext(\n dsl,\n binding,\n opts.activeGuardrailPolicy,\n );\n }\n }\n\n const perAgent = guardrailCtx.hasGuardrails\n ? buildPerAgentGuardrails(dsl, guardrailCtx)\n : new Map<string, GuardrailRuleData>();\n\n const component: ResolvedComponent = {\n id: opts.id,\n dsl,\n registries: buildRegistriesFromDsl(dsl),\n guardrails: { perAgent },\n diagnostics,\n };\n\n this.cache.set(opts.id, component);\n return component;\n }\n\n /** Clear cached components (e.g. for testing). */\n clearCache(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Get guardrail rules for a specific agent from a ResolvedComponent.\n * Falls back to embedded _guardrailRules when no per-agent rules exist.\n */\nexport function getGuardrailRulesForAgent(\n component: ResolvedComponent,\n agentId: string,\n fallbackDsl?: Record<string, unknown>,\n): GuardrailRuleData | undefined {\n const perAgent = component.guardrails.perAgent.get(agentId);\n if (perAgent && hasGuardrailRules(perAgent)) {\n return perAgent;\n }\n\n if (fallbackDsl) {\n const raw = fallbackDsl._guardrailRules as Record<string, unknown> | undefined;\n if (raw) {\n return {\n commandRules: (raw.commandRules as GuardrailRuleData[\"commandRules\"]) ?? [],\n fileRules: (raw.fileRules as GuardrailRuleData[\"fileRules\"]) ?? [],\n contentRules: (raw.contentRules as GuardrailRuleData[\"contentRules\"]) ?? [],\n };\n }\n }\n\n return undefined;\n}\n"],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aAAa;AACf,UAAM,MAAM,YAAY;AACxB,QAAI,KAAK;AACP,aAAO;AAAA,QACL,cAAe,IAAI,gBAAsD,CAAC;AAAA,QAC1E,WAAY,IAAI,aAAgD,CAAC;AAAA,QACjE,cAAe,IAAI,gBAAsD,CAAC;AAAA,MAC5E;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/chunk-D2QTXQB2.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
// src/lib/dsl-context.ts
|
|
2
|
-
import { readFile } from "fs/promises";
|
|
3
|
-
import YAML from "yaml";
|
|
4
|
-
|
|
5
|
-
// src/lib/schema-converter.ts
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
function applyStringValidations(schema, def) {
|
|
8
|
-
let s = schema;
|
|
9
|
-
if (typeof def.minLength === "number") s = s.min(def.minLength);
|
|
10
|
-
if (typeof def.maxLength === "number") s = s.max(def.maxLength);
|
|
11
|
-
if (typeof def.pattern === "string") s = s.regex(new RegExp(def.pattern));
|
|
12
|
-
return s;
|
|
13
|
-
}
|
|
14
|
-
function applyNumberValidations(schema, def, isInteger) {
|
|
15
|
-
let n = schema;
|
|
16
|
-
if (isInteger) n = n.int();
|
|
17
|
-
if (typeof def.minimum === "number") n = n.min(def.minimum);
|
|
18
|
-
if (typeof def.maximum === "number") n = n.max(def.maximum);
|
|
19
|
-
return n;
|
|
20
|
-
}
|
|
21
|
-
function applyArrayValidations(schema, def) {
|
|
22
|
-
let a = schema;
|
|
23
|
-
if (typeof def.minItems === "number") a = a.min(def.minItems);
|
|
24
|
-
if (typeof def.maxItems === "number") a = a.max(def.maxItems);
|
|
25
|
-
return a;
|
|
26
|
-
}
|
|
27
|
-
function jsonSchemaToZod(schema) {
|
|
28
|
-
if (!schema || typeof schema !== "object") return z.unknown();
|
|
29
|
-
if (schema.enum) {
|
|
30
|
-
const vals = schema.enum;
|
|
31
|
-
if (vals.length === 0) return z.unknown();
|
|
32
|
-
return z.enum(vals);
|
|
33
|
-
}
|
|
34
|
-
if (schema.const !== void 0) {
|
|
35
|
-
const val = schema.const;
|
|
36
|
-
if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") {
|
|
37
|
-
return z.literal(val);
|
|
38
|
-
}
|
|
39
|
-
return z.unknown();
|
|
40
|
-
}
|
|
41
|
-
const type = schema.type;
|
|
42
|
-
if (type === "string") return applyStringValidations(z.string(), schema);
|
|
43
|
-
if (type === "integer") return applyNumberValidations(z.number(), schema, true);
|
|
44
|
-
if (type === "number") return applyNumberValidations(z.number(), schema, false);
|
|
45
|
-
if (type === "boolean") return z.boolean();
|
|
46
|
-
if (type === "array") {
|
|
47
|
-
const items = schema.items;
|
|
48
|
-
const inner = items ? jsonSchemaToZod(items) : z.unknown();
|
|
49
|
-
return applyArrayValidations(z.array(inner), schema);
|
|
50
|
-
}
|
|
51
|
-
if (type === "object") {
|
|
52
|
-
const props = schema.properties;
|
|
53
|
-
if (!props) return z.record(z.string(), z.unknown());
|
|
54
|
-
const required = new Set(schema.required ?? []);
|
|
55
|
-
const shape = {};
|
|
56
|
-
for (const [key, val] of Object.entries(props)) {
|
|
57
|
-
const fieldSchema = jsonSchemaToZod(val);
|
|
58
|
-
shape[key] = required.has(key) ? fieldSchema : fieldSchema.optional();
|
|
59
|
-
}
|
|
60
|
-
return z.object(shape).passthrough();
|
|
61
|
-
}
|
|
62
|
-
if (schema.allOf) {
|
|
63
|
-
const parts = schema.allOf.map(jsonSchemaToZod);
|
|
64
|
-
if (parts.length === 0) return z.unknown();
|
|
65
|
-
if (parts.length === 1) return parts[0];
|
|
66
|
-
let merged = parts[0];
|
|
67
|
-
for (let i = 1; i < parts.length; i++) {
|
|
68
|
-
const part = parts[i];
|
|
69
|
-
if (merged instanceof z.ZodObject && part instanceof z.ZodObject) {
|
|
70
|
-
merged = merged.merge(part);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return merged;
|
|
74
|
-
}
|
|
75
|
-
return z.unknown();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// src/lib/dsl-context.ts
|
|
79
|
-
var DslValidationError = class extends Error {
|
|
80
|
-
missing;
|
|
81
|
-
constructor(missing) {
|
|
82
|
-
super(
|
|
83
|
-
"Required entities missing after DSL merge:\n" + missing.map((m) => ` - ${m}`).join("\n")
|
|
84
|
-
);
|
|
85
|
-
this.name = "DslValidationError";
|
|
86
|
-
this.missing = missing;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
function buildAgentRegistry(agents) {
|
|
90
|
-
const registry = {};
|
|
91
|
-
for (const [id, agent] of Object.entries(agents)) {
|
|
92
|
-
const rawMode = agent.mode ?? "read-only";
|
|
93
|
-
const mode = rawMode === "read-write" ? "read-write" : "read-only";
|
|
94
|
-
registry[id] = {
|
|
95
|
-
id,
|
|
96
|
-
role_name: agent.role_name ?? id,
|
|
97
|
-
purpose: agent.purpose ?? "",
|
|
98
|
-
mode,
|
|
99
|
-
responsibilities: agent.responsibilities ?? [],
|
|
100
|
-
constraints: agent.constraints ?? [],
|
|
101
|
-
rules: agent.rules ?? [],
|
|
102
|
-
can_invoke_agents: agent.can_invoke_agents ?? void 0,
|
|
103
|
-
can_execute_tools: agent.can_execute_tools ?? void 0
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return registry;
|
|
107
|
-
}
|
|
108
|
-
function buildTaskRegistry(tasks) {
|
|
109
|
-
const registry = {};
|
|
110
|
-
for (const [id, task] of Object.entries(tasks)) {
|
|
111
|
-
registry[id] = {
|
|
112
|
-
id,
|
|
113
|
-
description: task.description ?? "",
|
|
114
|
-
target_agent: task.target_agent ?? "",
|
|
115
|
-
result_handoff: task.result_handoff ?? "",
|
|
116
|
-
completion_criteria: task.completion_criteria ?? [],
|
|
117
|
-
model_class: task.model_class
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return registry;
|
|
121
|
-
}
|
|
122
|
-
function buildWorkflowStep(step) {
|
|
123
|
-
if (step.type === "gate") {
|
|
124
|
-
return {
|
|
125
|
-
type: "gate",
|
|
126
|
-
gate_kind: step.gate_kind ?? "",
|
|
127
|
-
description: step.description ?? "",
|
|
128
|
-
depends_on: step.depends_on
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
type: "delegate",
|
|
133
|
-
task: step.task ?? "",
|
|
134
|
-
from_agent: step.from_agent ?? "",
|
|
135
|
-
description: step.description ?? "",
|
|
136
|
-
optional: step.optional ?? false,
|
|
137
|
-
max_retries: step.max_retries ?? 0,
|
|
138
|
-
max_follow_ups: step.max_follow_ups,
|
|
139
|
-
depends_on: step.depends_on,
|
|
140
|
-
retry: step.retry
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function buildWorkflowRegistry(workflows) {
|
|
144
|
-
const registry = {};
|
|
145
|
-
for (const [id, wf] of Object.entries(workflows)) {
|
|
146
|
-
const steps = (wf.steps ?? []).map(buildWorkflowStep);
|
|
147
|
-
registry[id] = { id, description: wf.description ?? "", steps };
|
|
148
|
-
}
|
|
149
|
-
return registry;
|
|
150
|
-
}
|
|
151
|
-
function buildHandoffSchemas(handoffTypes) {
|
|
152
|
-
const schemas = {};
|
|
153
|
-
for (const [id, ht] of Object.entries(handoffTypes)) {
|
|
154
|
-
const schema = ht.schema;
|
|
155
|
-
if (schema) {
|
|
156
|
-
schemas[id] = jsonSchemaToZod(schema);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return schemas;
|
|
160
|
-
}
|
|
161
|
-
function buildGuardrailRulesFromDsl(dsl) {
|
|
162
|
-
const raw = dsl._guardrailRules;
|
|
163
|
-
if (!raw) return void 0;
|
|
164
|
-
return {
|
|
165
|
-
commandRules: raw.commandRules ?? [],
|
|
166
|
-
fileRules: raw.fileRules ?? [],
|
|
167
|
-
contentRules: raw.contentRules ?? []
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function buildRegistriesFromDsl(dsl) {
|
|
171
|
-
const agents = dsl.agents ?? {};
|
|
172
|
-
const tasks = dsl.tasks ?? {};
|
|
173
|
-
const workflows = dsl.workflow ?? {};
|
|
174
|
-
const handoffTypes = dsl.handoff_types ?? {};
|
|
175
|
-
return {
|
|
176
|
-
agentRegistry: buildAgentRegistry(agents),
|
|
177
|
-
taskRegistry: buildTaskRegistry(tasks),
|
|
178
|
-
workflowRegistry: buildWorkflowRegistry(workflows),
|
|
179
|
-
handoffSchemas: buildHandoffSchemas(handoffTypes)
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function validateRequiredEntities(dsl, required) {
|
|
183
|
-
const missing = [];
|
|
184
|
-
const workflows = dsl.workflow ?? {};
|
|
185
|
-
const tasks = dsl.tasks ?? {};
|
|
186
|
-
const handoffTypes = dsl.handoff_types ?? {};
|
|
187
|
-
if (required.workflows) {
|
|
188
|
-
for (const wfId of required.workflows) {
|
|
189
|
-
if (!(wfId in workflows)) {
|
|
190
|
-
missing.push(`workflow "${wfId}" is required by the CLI but not found in the resolved DSL`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (required.tasks) {
|
|
195
|
-
for (const taskId of required.tasks) {
|
|
196
|
-
if (!(taskId in tasks)) {
|
|
197
|
-
missing.push(`task "${taskId}" is required by the CLI but not found in the resolved DSL`);
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const task = tasks[taskId];
|
|
201
|
-
const invHandoff = task.invocation_handoff;
|
|
202
|
-
const resHandoff = task.result_handoff;
|
|
203
|
-
if (invHandoff && !(invHandoff in handoffTypes)) {
|
|
204
|
-
missing.push(`handoff_type "${invHandoff}" (invocation_handoff of task "${taskId}") not found`);
|
|
205
|
-
}
|
|
206
|
-
if (resHandoff && !(resHandoff in handoffTypes)) {
|
|
207
|
-
missing.push(`handoff_type "${resHandoff}" (result_handoff of task "${taskId}") not found`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (required.workflows) {
|
|
212
|
-
for (const wfId of required.workflows) {
|
|
213
|
-
if (!(wfId in workflows)) continue;
|
|
214
|
-
const wf = workflows[wfId];
|
|
215
|
-
const steps = wf.steps ?? [];
|
|
216
|
-
for (const step of steps) {
|
|
217
|
-
if (step.type !== "delegate") continue;
|
|
218
|
-
const taskId = step.task;
|
|
219
|
-
if (taskId && taskId in tasks) {
|
|
220
|
-
const task = tasks[taskId];
|
|
221
|
-
const resHandoff = task.result_handoff;
|
|
222
|
-
if (resHandoff && !(resHandoff in handoffTypes)) {
|
|
223
|
-
missing.push(`handoff_type "${resHandoff}" (result of task "${taskId}" in workflow "${wfId}") not found`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (missing.length > 0) {
|
|
230
|
-
throw new DslValidationError(missing);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async function loadDslContext(options) {
|
|
234
|
-
let dsl;
|
|
235
|
-
if (options.projectDslPath) {
|
|
236
|
-
const { resolve: resolveDsl, mergeDsl, expandDefaults } = await import("agent-contracts");
|
|
237
|
-
const raw = await readFile(options.projectDslPath, "utf8");
|
|
238
|
-
const projectData = YAML.parse(raw);
|
|
239
|
-
if (projectData.extends === "/$embedded/") {
|
|
240
|
-
const { extends: _extends, ...projectOverrides } = projectData;
|
|
241
|
-
const merged = mergeDsl(options.embeddedDsl, projectOverrides);
|
|
242
|
-
dsl = expandDefaults(merged);
|
|
243
|
-
} else {
|
|
244
|
-
const projectResult = await resolveDsl(options.projectDslPath);
|
|
245
|
-
const merged = mergeDsl(options.embeddedDsl, projectResult.data);
|
|
246
|
-
dsl = expandDefaults(merged);
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
dsl = options.embeddedDsl;
|
|
250
|
-
}
|
|
251
|
-
if (options.requiredEntities) {
|
|
252
|
-
validateRequiredEntities(dsl, options.requiredEntities);
|
|
253
|
-
}
|
|
254
|
-
const registries = buildRegistriesFromDsl(dsl);
|
|
255
|
-
const guardrailRules = buildGuardrailRulesFromDsl(dsl);
|
|
256
|
-
return { registries, dsl, guardrailRules };
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export {
|
|
260
|
-
jsonSchemaToZod,
|
|
261
|
-
DslValidationError,
|
|
262
|
-
buildGuardrailRulesFromDsl,
|
|
263
|
-
buildRegistriesFromDsl,
|
|
264
|
-
loadDslContext
|
|
265
|
-
};
|
|
266
|
-
//# sourceMappingURL=chunk-D2QTXQB2.js.map
|