@aaac/runtime 0.1.55 → 0.2.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.
Files changed (71) hide show
  1. package/README.md +6 -11
  2. package/dist/adapters/adk-sdk.d.ts +3 -3
  3. package/dist/adapters/adk-sdk.js +6 -8
  4. package/dist/adapters/adk-sdk.js.map +1 -1
  5. package/dist/adapters/claude-agent-sdk.d.ts +3 -3
  6. package/dist/adapters/claude-agent-sdk.js +22 -23
  7. package/dist/adapters/claude-agent-sdk.js.map +1 -1
  8. package/dist/adapters/mock.d.ts +2 -3
  9. package/dist/adapters/openai-agents-sdk.d.ts +3 -3
  10. package/dist/adapters/openai-agents-sdk.js +6 -5
  11. package/dist/adapters/openai-agents-sdk.js.map +1 -1
  12. package/dist/chunk-2INQL5TG.js +298 -0
  13. package/dist/chunk-2INQL5TG.js.map +1 -0
  14. package/dist/chunk-3CLWG72V.js +47 -0
  15. package/dist/chunk-3CLWG72V.js.map +1 -0
  16. package/dist/chunk-3DDB34BU.js +237 -0
  17. package/dist/chunk-3DDB34BU.js.map +1 -0
  18. package/dist/chunk-ABXDSTUV.js +685 -0
  19. package/dist/chunk-ABXDSTUV.js.map +1 -0
  20. package/dist/{chunk-3H3PVPPF.js → chunk-F5R46S7I.js} +151 -204
  21. package/dist/chunk-F5R46S7I.js.map +1 -0
  22. package/dist/chunk-FKAI54OM.js +234 -0
  23. package/dist/chunk-FKAI54OM.js.map +1 -0
  24. package/dist/chunk-KTVMMG33.js +1111 -0
  25. package/dist/chunk-KTVMMG33.js.map +1 -0
  26. package/dist/chunk-MSVIEEGR.js +269 -0
  27. package/dist/chunk-MSVIEEGR.js.map +1 -0
  28. package/dist/chunk-VJXGCWSZ.js +36 -0
  29. package/dist/chunk-VJXGCWSZ.js.map +1 -0
  30. package/dist/claude-bundles/full.js +311 -309
  31. package/dist/claude-bundles/lean.js +6 -6
  32. package/dist/claude-bundles/prompt.js +17 -0
  33. package/dist/generator/index.d.ts +2 -2
  34. package/dist/generator/index.js +8 -7
  35. package/dist/guardrail-hooks-CB23nhZV.d.ts +202 -0
  36. package/dist/hook-protocol-CFnNudiV.d.ts +96 -0
  37. package/dist/hooks-lite-CoWWnCRH.d.ts +428 -0
  38. package/dist/index-BlSepCSZ.d.ts +296 -0
  39. package/dist/index.d.ts +785 -105
  40. package/dist/index.js +2189 -634
  41. package/dist/index.js.map +1 -1
  42. package/dist/lib/claude-native/hooks-lite.d.ts +3 -26
  43. package/dist/lib/claude-native/hooks-lite.js +18 -36
  44. package/dist/lib/claude-native/hooks-prompt.d.ts +5 -0
  45. package/dist/lib/claude-native/hooks-prompt.js +33 -0
  46. package/dist/lib/claude-native/hooks-prompt.js.map +1 -0
  47. package/dist/lib/claude-native/index.d.ts +56 -214
  48. package/dist/lib/claude-native/index.js +79 -280
  49. package/dist/lib/claude-native/index.js.map +1 -1
  50. package/dist/{navigation-context-D_E1NIUf.d.ts → navigation-context-B-RpUg3_.d.ts} +1 -1
  51. package/dist/navigation-index-prompt-CbrS5laO.d.ts +43 -0
  52. package/dist/{task-runner-DfIEorkU.d.ts → task-runner-GWoI7_71.d.ts} +100 -493
  53. package/dist/workspace-user-prompt-submit-D11Iu0zO.d.ts +269 -0
  54. package/package.json +15 -6
  55. package/dist/chunk-3H3PVPPF.js.map +0 -1
  56. package/dist/chunk-DBM5XN67.js +0 -354
  57. package/dist/chunk-DBM5XN67.js.map +0 -1
  58. package/dist/chunk-KXGUWBGK.js +0 -370
  59. package/dist/chunk-KXGUWBGK.js.map +0 -1
  60. package/dist/chunk-LDCQZPDG.js +0 -11
  61. package/dist/chunk-LDCQZPDG.js.map +0 -1
  62. package/dist/chunk-N4KNGDYY.js +0 -1963
  63. package/dist/chunk-N4KNGDYY.js.map +0 -1
  64. package/dist/chunk-NMX4C6LC.js +0 -332
  65. package/dist/chunk-NMX4C6LC.js.map +0 -1
  66. package/dist/chunk-QVH5KKBR.js +0 -374
  67. package/dist/chunk-QVH5KKBR.js.map +0 -1
  68. package/dist/context-DKkamYX_.d.ts +0 -31
  69. package/dist/guardrail-hooks-slK-z0Dz.d.ts +0 -83
  70. package/dist/index-LqEvaRk-.d.ts +0 -299
  71. package/dist/workspace-pre-tool-use-C6nidc0q.d.ts +0 -333
@@ -0,0 +1,685 @@
1
+ import {
2
+ jsonSchemaToZod
3
+ } from "./chunk-ET6TGQRT.js";
4
+ import {
5
+ PROJECT_CONFIG_FILENAME,
6
+ buildGuardrailContext,
7
+ loadProjectConfig
8
+ } from "./chunk-F5R46S7I.js";
9
+
10
+ // src/lib/artifact-resolver.ts
11
+ import { readFile } from "fs/promises";
12
+ import YAML from "yaml";
13
+ async function loadArtifactRegistry(source) {
14
+ let content;
15
+ try {
16
+ content = await readFile(source, "utf8");
17
+ } catch {
18
+ throw new Error(
19
+ `Failed to read artifact registry: ${source} (declared by the project manifest's \`artifacts:\`).`
20
+ );
21
+ }
22
+ let parsed;
23
+ try {
24
+ parsed = YAML.parse(content);
25
+ } catch (err) {
26
+ throw new Error(
27
+ `Invalid YAML in artifact registry ${source}: ${err.message}`
28
+ );
29
+ }
30
+ const document = typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
31
+ const artifacts = document?.artifacts;
32
+ if (artifacts && typeof artifacts === "object" && !Array.isArray(artifacts)) {
33
+ return artifacts;
34
+ }
35
+ return {};
36
+ }
37
+ async function resolveArtifacts(options) {
38
+ if (!options.artifactBinding) {
39
+ return { dsl: options.dsl, diagnostics: [] };
40
+ }
41
+ const { resolveArtifactBinding } = await import("agent-contracts");
42
+ const registry = await loadArtifactRegistry(options.artifactBinding.source);
43
+ const dslArtifacts = options.dsl.artifacts ?? {};
44
+ const mappings = options.artifactBinding.mappings;
45
+ const claimed = new Set(
46
+ Object.keys(dslArtifacts).map((id) => mappings?.[id] ?? id)
47
+ );
48
+ const composed = Object.keys(registry).filter(
49
+ (id) => !claimed.has(id) && !(id in dslArtifacts)
50
+ );
51
+ const bound = resolveArtifactBinding(
52
+ {
53
+ ...Object.fromEntries(composed.map((id) => [id, {}])),
54
+ ...dslArtifacts
55
+ },
56
+ { artifacts: registry },
57
+ mappings,
58
+ options.paths
59
+ );
60
+ return {
61
+ dsl: { ...options.dsl, artifacts: bound.artifacts },
62
+ diagnostics: bound.diagnostics.map((d) => ({
63
+ path: d.rule,
64
+ message: d.message,
65
+ severity: d.severity
66
+ }))
67
+ };
68
+ }
69
+
70
+ // src/lib/dsl-context.ts
71
+ import { readFile as readFile2 } from "fs/promises";
72
+ import YAML2 from "yaml";
73
+ import {
74
+ expandDslSection
75
+ } from "@aaac/contracts";
76
+ var DslValidationError = class extends Error {
77
+ missing;
78
+ constructor(missing) {
79
+ super(
80
+ "Required entities missing after DSL merge:\n" + missing.map((m) => ` - ${m}`).join("\n")
81
+ );
82
+ this.name = "DslValidationError";
83
+ this.missing = missing;
84
+ }
85
+ };
86
+ function buildAgentRegistry(dsl) {
87
+ const agents = dsl.agents ?? {};
88
+ const registry = {};
89
+ for (const [id, agent] of Object.entries(agents)) {
90
+ const rawMode = agent.mode ?? "read-only";
91
+ const mode = rawMode === "read-write" ? "read-write" : "read-only";
92
+ const authority = agent["x-authority"];
93
+ registry[id] = {
94
+ id,
95
+ role_name: agent.role_name ?? id,
96
+ purpose: agent.purpose ?? "",
97
+ mode,
98
+ responsibilities: agent.responsibilities ?? [],
99
+ constraints: agent.constraints ?? [],
100
+ rules: agent.rules ?? [],
101
+ can_invoke_agents: agent.can_invoke_agents ?? void 0,
102
+ can_execute_tools: agent.can_execute_tools ?? void 0,
103
+ dispatch_only: agent.dispatch_only ?? void 0,
104
+ can_read_artifacts: agent.can_read_artifacts ?? [],
105
+ can_write_artifacts: agent.can_write_artifacts ?? [],
106
+ can_return_handoffs: agent.can_return_handoffs ?? [],
107
+ can_perform_validations: agent.can_perform_validations ?? [],
108
+ anti_patterns: agent.anti_patterns ?? [],
109
+ escalation_criteria: agent.escalation_criteria ?? [],
110
+ authority,
111
+ audit_checklist: agent["x-audit-checklist"] ?? [],
112
+ sections: (agent.sections ?? []).map((section) => expandDslSection(section, dsl)).filter((section) => section !== void 0)
113
+ };
114
+ }
115
+ return registry;
116
+ }
117
+ function buildTaskRegistry(tasks) {
118
+ const registry = {};
119
+ for (const [id, task] of Object.entries(tasks)) {
120
+ registry[id] = {
121
+ id,
122
+ description: task.description ?? "",
123
+ target_agent: task.target_agent ?? "",
124
+ result_handoff: task.result_handoff ?? "",
125
+ completion_criteria: task.completion_criteria ?? [],
126
+ model_class: task.model_class
127
+ };
128
+ }
129
+ return registry;
130
+ }
131
+ function buildWorkflowStep(step) {
132
+ if (step.type === "gate") {
133
+ return {
134
+ type: "gate",
135
+ gate_kind: step.gate_kind ?? "",
136
+ description: step.description ?? "",
137
+ depends_on: step.depends_on
138
+ };
139
+ }
140
+ if (step.type === "evaluate") {
141
+ return {
142
+ type: "evaluate",
143
+ task: step.task ?? "",
144
+ from_agent: step.from_agent ?? "",
145
+ evaluator_agent: step.evaluator_agent,
146
+ description: step.description,
147
+ loop_to: step.loop_to ?? "",
148
+ max_iterations: step.max_iterations ?? 1,
149
+ inject_as: step.inject_as,
150
+ on_exhausted: step.on_exhausted,
151
+ depends_on: step.depends_on
152
+ };
153
+ }
154
+ return {
155
+ type: "delegate",
156
+ task: step.task ?? "",
157
+ from_agent: step.from_agent ?? "",
158
+ description: step.description ?? "",
159
+ optional: step["x-optional"] ?? false,
160
+ max_retries: step.max_retries ?? 0,
161
+ max_follow_ups: step.max_follow_ups,
162
+ depends_on: step.depends_on,
163
+ instruction: step["x-instruction"],
164
+ receives: step["x-receives"],
165
+ retry: step.retry
166
+ };
167
+ }
168
+ function buildWorkflowRegistry(workflows) {
169
+ const registry = {};
170
+ for (const [id, wf] of Object.entries(workflows)) {
171
+ const steps = (wf.steps ?? []).map(buildWorkflowStep);
172
+ registry[id] = { id, description: wf.description ?? "", steps };
173
+ }
174
+ return registry;
175
+ }
176
+ function buildHandoffSchemas(handoffTypes) {
177
+ const schemas = {};
178
+ for (const [id, ht] of Object.entries(handoffTypes)) {
179
+ const schema = ht.schema;
180
+ if (schema) {
181
+ schemas[id] = jsonSchemaToZod(schema);
182
+ }
183
+ }
184
+ return schemas;
185
+ }
186
+ function buildRegistriesFromDsl(dsl) {
187
+ const tasks = dsl.tasks ?? {};
188
+ const workflows = dsl.workflow ?? {};
189
+ const handoffTypes = dsl.handoff_types ?? {};
190
+ return {
191
+ agentRegistry: buildAgentRegistry(dsl),
192
+ taskRegistry: buildTaskRegistry(tasks),
193
+ workflowRegistry: buildWorkflowRegistry(workflows),
194
+ handoffSchemas: buildHandoffSchemas(handoffTypes)
195
+ };
196
+ }
197
+ function validateRequiredEntities(dsl, required) {
198
+ const missing = [];
199
+ const workflows = dsl.workflow ?? {};
200
+ const tasks = dsl.tasks ?? {};
201
+ const handoffTypes = dsl.handoff_types ?? {};
202
+ if (required.workflows) {
203
+ for (const wfId of required.workflows) {
204
+ if (!(wfId in workflows)) {
205
+ missing.push(`workflow "${wfId}" is required by the CLI but not found in the resolved DSL`);
206
+ }
207
+ }
208
+ }
209
+ if (required.tasks) {
210
+ for (const taskId of required.tasks) {
211
+ if (!(taskId in tasks)) {
212
+ missing.push(`task "${taskId}" is required by the CLI but not found in the resolved DSL`);
213
+ continue;
214
+ }
215
+ const task = tasks[taskId];
216
+ const invHandoff = task.invocation_handoff;
217
+ const resHandoff = task.result_handoff;
218
+ if (invHandoff && !(invHandoff in handoffTypes)) {
219
+ missing.push(`handoff_type "${invHandoff}" (invocation_handoff of task "${taskId}") not found`);
220
+ }
221
+ if (resHandoff && !(resHandoff in handoffTypes)) {
222
+ missing.push(`handoff_type "${resHandoff}" (result_handoff of task "${taskId}") not found`);
223
+ }
224
+ }
225
+ }
226
+ if (required.workflows) {
227
+ for (const wfId of required.workflows) {
228
+ if (!(wfId in workflows)) continue;
229
+ const wf = workflows[wfId];
230
+ const steps = wf.steps ?? [];
231
+ for (const step of steps) {
232
+ if (step.type !== "delegate") continue;
233
+ const taskId = step.task;
234
+ if (taskId && taskId in tasks) {
235
+ const task = tasks[taskId];
236
+ const resHandoff = task.result_handoff;
237
+ if (resHandoff && !(resHandoff in handoffTypes)) {
238
+ missing.push(`handoff_type "${resHandoff}" (result of task "${taskId}" in workflow "${wfId}") not found`);
239
+ }
240
+ }
241
+ }
242
+ }
243
+ }
244
+ if (missing.length > 0) {
245
+ throw new DslValidationError(missing);
246
+ }
247
+ }
248
+ async function loadDslContext(options) {
249
+ let dsl;
250
+ if (options.projectDslPath) {
251
+ const { resolve: resolveDsl, mergeDsl, expandDefaults } = await import("agent-contracts");
252
+ const raw = await readFile2(options.projectDslPath, "utf8");
253
+ const document = YAML2.parse(raw);
254
+ if (typeof document !== "object" || document === null || Array.isArray(document)) {
255
+ throw new Error(`${options.projectDslPath} is not a DSL document (expected a YAML mapping)`);
256
+ }
257
+ const projectData = document;
258
+ if (projectData.extends === "/$embedded/") {
259
+ const { extends: _extends, ...projectOverrides } = projectData;
260
+ const merged = mergeDsl(options.embeddedDsl, projectOverrides);
261
+ dsl = expandDefaults(merged);
262
+ } else {
263
+ const projectResult = await resolveDsl(options.projectDslPath);
264
+ const merged = mergeDsl(options.embeddedDsl, projectResult.data);
265
+ dsl = expandDefaults(merged);
266
+ }
267
+ } else {
268
+ dsl = options.embeddedDsl;
269
+ }
270
+ if (options.requiredEntities) {
271
+ validateRequiredEntities(dsl, options.requiredEntities);
272
+ }
273
+ const registries = buildRegistriesFromDsl(dsl);
274
+ return { registries, dsl };
275
+ }
276
+
277
+ // src/lib/bound-resolver.ts
278
+ import { readFile as readFile3 } from "fs/promises";
279
+ import { dirname, resolve as resolvePath } from "path";
280
+ import { parseComponentFile } from "@aaac/contracts";
281
+ import YAML3 from "yaml";
282
+ function getEffectiveGuardrailIds(dsl, agentId) {
283
+ const ids = /* @__PURE__ */ new Set();
284
+ const agents = dsl.agents ?? {};
285
+ const agent = agents[agentId];
286
+ if (agent) {
287
+ for (const ref of agent.guardrails ?? []) {
288
+ ids.add(ref);
289
+ }
290
+ }
291
+ const guardrails = dsl.guardrails ?? {};
292
+ for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
293
+ if (guardrail.scope?.agents?.includes(agentId)) {
294
+ ids.add(guardrailId);
295
+ }
296
+ }
297
+ return ids;
298
+ }
299
+ function guardrailCheckToCommandRule(c) {
300
+ return {
301
+ guardrail_id: c.guardrail_id,
302
+ pattern: c.pattern,
303
+ action: c.action,
304
+ message: c.message
305
+ };
306
+ }
307
+ function guardrailCheckToFileRule(c) {
308
+ return {
309
+ guardrail_id: c.guardrail_id,
310
+ pattern: c.pattern,
311
+ action: c.action,
312
+ message: c.message,
313
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
314
+ };
315
+ }
316
+ function guardrailCheckToContentRule(c) {
317
+ return {
318
+ guardrail_id: c.guardrail_id,
319
+ pattern: c.pattern,
320
+ action: c.action,
321
+ message: c.message,
322
+ ...c.file_glob ? { file_glob: c.file_glob } : {},
323
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
324
+ };
325
+ }
326
+ function guardrailContextToRuleData(ctx, effectiveIds) {
327
+ const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
328
+ return {
329
+ commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
330
+ fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
331
+ contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
332
+ };
333
+ }
334
+ function buildPerAgentGuardrails(dsl, guardrailCtx) {
335
+ const perAgent = /* @__PURE__ */ new Map();
336
+ const agents = dsl.agents ?? {};
337
+ for (const agentId of Object.keys(agents)) {
338
+ const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
339
+ const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
340
+ if (hasGuardrailRules(rules)) {
341
+ perAgent.set(agentId, rules);
342
+ }
343
+ }
344
+ return perAgent;
345
+ }
346
+ var EMPTY_GUARDRAIL_CONTEXT = {
347
+ commandChecks: [],
348
+ fileChecks: [],
349
+ contentChecks: [],
350
+ allChecks: [],
351
+ hasGuardrails: false,
352
+ diagnostics: []
353
+ };
354
+ async function resolveGuardrailContext(dsl, bindingPaths, activeGuardrailPolicy, options) {
355
+ if (!bindingPaths || bindingPaths.length === 0) {
356
+ return EMPTY_GUARDRAIL_CONTEXT;
357
+ }
358
+ const merged = {
359
+ commandChecks: [],
360
+ fileChecks: [],
361
+ contentChecks: [],
362
+ allChecks: [],
363
+ hasGuardrails: false,
364
+ diagnostics: []
365
+ };
366
+ const seenDiagnostics = /* @__PURE__ */ new Set();
367
+ for (const bindingPath of bindingPaths) {
368
+ let raw;
369
+ try {
370
+ raw = await readFile3(bindingPath, "utf8");
371
+ } catch (err) {
372
+ if (options?.skipMissing && err.code === "ENOENT") continue;
373
+ throw err;
374
+ }
375
+ const document = YAML3.parse(raw);
376
+ if (typeof document !== "object" || document === null || Array.isArray(document)) {
377
+ throw new Error(`${bindingPath} is not a binding document (expected a YAML mapping)`);
378
+ }
379
+ const binding = document;
380
+ const ctx = buildGuardrailContext(dsl, binding, activeGuardrailPolicy);
381
+ merged.commandChecks.push(...ctx.commandChecks);
382
+ merged.fileChecks.push(...ctx.fileChecks);
383
+ merged.contentChecks.push(...ctx.contentChecks);
384
+ merged.allChecks.push(...ctx.allChecks);
385
+ merged.hasGuardrails = merged.hasGuardrails || ctx.hasGuardrails;
386
+ for (const diagnostic of ctx.diagnostics) {
387
+ const key = `${diagnostic.path} :: ${diagnostic.message}`;
388
+ if (seenDiagnostics.has(key)) continue;
389
+ seenDiagnostics.add(key);
390
+ merged.diagnostics.push(diagnostic);
391
+ }
392
+ }
393
+ return merged;
394
+ }
395
+ function hasGuardrailRules(rules) {
396
+ return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
397
+ }
398
+ async function readComponentId(componentPath, toolchainId) {
399
+ try {
400
+ return (await parseComponentFile(componentPath)).info.id;
401
+ } catch (err) {
402
+ throw new Error(
403
+ `Toolchain "${toolchainId}" declares component_contract "${componentPath}", which cannot be read as a component contract: ${err.message}`,
404
+ { cause: err }
405
+ );
406
+ }
407
+ }
408
+ function mergeDerivedWithAgentTools(derivedTools, agentToolIds, allToolchains) {
409
+ const merged = /* @__PURE__ */ new Map();
410
+ for (const tc of derivedTools) {
411
+ merged.set(tc.id, tc);
412
+ }
413
+ for (const toolId of agentToolIds) {
414
+ if (!merged.has(toolId)) {
415
+ if (allToolchains[toolId]) {
416
+ merged.set(toolId, { ...allToolchains[toolId], source: "merged" });
417
+ }
418
+ } else {
419
+ const existing = merged.get(toolId);
420
+ merged.set(toolId, { ...existing, source: "merged" });
421
+ }
422
+ }
423
+ return Array.from(merged.values());
424
+ }
425
+ function deriveToolchainsForAgents(dsl, toolchains) {
426
+ const result = /* @__PURE__ */ new Map();
427
+ const agents = dsl.agents ?? {};
428
+ for (const [agentId, agent] of Object.entries(agents)) {
429
+ const derivedTools = [];
430
+ const canReadArtifacts = agent.can_read_artifacts ?? [];
431
+ const canWriteArtifacts = agent.can_write_artifacts ?? [];
432
+ const agentArtifacts = agent.artifacts;
433
+ const readArtifacts = /* @__PURE__ */ new Set([
434
+ ...canReadArtifacts,
435
+ ...agentArtifacts?.consumes ?? []
436
+ ]);
437
+ const writeArtifacts = /* @__PURE__ */ new Set([
438
+ ...canWriteArtifacts,
439
+ ...agentArtifacts?.produces ?? []
440
+ ]);
441
+ for (const tc of Object.values(toolchains)) {
442
+ let matched = false;
443
+ for (const artifactId of tc.artifacts.consumes) {
444
+ if (readArtifacts.has(artifactId) || writeArtifacts.has(artifactId)) {
445
+ matched = true;
446
+ break;
447
+ }
448
+ }
449
+ if (!matched) {
450
+ for (const artifactId of tc.artifacts.produces) {
451
+ if (writeArtifacts.has(artifactId)) {
452
+ matched = true;
453
+ break;
454
+ }
455
+ }
456
+ }
457
+ if (matched) {
458
+ derivedTools.push(tc);
459
+ }
460
+ }
461
+ if (derivedTools.length > 0) {
462
+ const agentTools = agent.can_execute_tools ?? [];
463
+ const mergedTools = mergeDerivedWithAgentTools(
464
+ derivedTools,
465
+ agentTools,
466
+ toolchains
467
+ );
468
+ result.set(agentId, mergedTools);
469
+ }
470
+ }
471
+ return result;
472
+ }
473
+ var BoundResolver = class {
474
+ cache = /* @__PURE__ */ new Map();
475
+ /**
476
+ * Resolve binding + policy in one pass. Results are cached by component id.
477
+ */
478
+ async resolve(opts) {
479
+ const cached = this.cache.get(opts.id);
480
+ if (cached) return cached;
481
+ const diagnostics = [];
482
+ let dsl;
483
+ if (opts.embeddedDsl) {
484
+ dsl = opts.embeddedDsl;
485
+ } else if (opts.dslPath) {
486
+ const { resolve: resolveDsl } = await import("agent-contracts");
487
+ const result = await resolveDsl(opts.dslPath);
488
+ dsl = result.data;
489
+ } else {
490
+ throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
491
+ }
492
+ if (opts.artifactBinding) {
493
+ const bound = await resolveArtifacts({
494
+ dsl,
495
+ artifactBinding: opts.artifactBinding,
496
+ paths: opts.paths
497
+ });
498
+ dsl = bound.dsl;
499
+ diagnostics.push(...bound.diagnostics);
500
+ }
501
+ let guardrailCtx;
502
+ guardrailCtx = await resolveGuardrailContext(
503
+ dsl,
504
+ opts.bindingPaths,
505
+ opts.activeGuardrailPolicy
506
+ );
507
+ diagnostics.push(...guardrailCtx.diagnostics);
508
+ const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
509
+ let toolchains;
510
+ let toolchainsByAgent;
511
+ if (opts.toolchainContractsPath) {
512
+ const toolchainPkg = "@aaac/toolchain";
513
+ const mod = await import(
514
+ /* webpackIgnore: true */
515
+ toolchainPkg
516
+ );
517
+ const tcDoc = await mod.loadToolchainContracts(opts.toolchainContractsPath);
518
+ const toolchainDir = dirname(resolvePath(opts.toolchainContractsPath));
519
+ toolchains = {};
520
+ for (const [id, tc] of Object.entries(tcDoc.toolchains)) {
521
+ toolchains[id] = {
522
+ id,
523
+ kind: tc.kind,
524
+ description: tc.description,
525
+ module: tc.module,
526
+ command: tc.command,
527
+ cli_contract: tc.cli_contract,
528
+ component_contract: tc.component_contract,
529
+ ...tc.component_contract ? {
530
+ componentId: await readComponentId(
531
+ resolvePath(toolchainDir, tc.component_contract),
532
+ id
533
+ )
534
+ } : {},
535
+ artifacts: {
536
+ consumes: [...tc.artifacts.consumes],
537
+ produces: [...tc.artifacts.produces]
538
+ },
539
+ operations: tc.operations ? [...tc.operations] : void 0,
540
+ source: "toolchain-contracts"
541
+ };
542
+ }
543
+ toolchainsByAgent = deriveToolchainsForAgents(dsl, toolchains);
544
+ }
545
+ const component = {
546
+ id: opts.id,
547
+ dsl,
548
+ registries: buildRegistriesFromDsl(dsl),
549
+ guardrails: { perAgent },
550
+ diagnostics,
551
+ ...toolchains ? { toolchains } : {},
552
+ ...toolchainsByAgent ? { toolchainsByAgent } : {}
553
+ };
554
+ this.cache.set(opts.id, component);
555
+ return component;
556
+ }
557
+ /** Clear cached components (e.g. for testing). */
558
+ clearCache() {
559
+ this.cache.clear();
560
+ }
561
+ };
562
+ function getGuardrailRulesForAgent(component, agentId) {
563
+ const perAgent = component.guardrails.perAgent.get(agentId);
564
+ return perAgent && hasGuardrailRules(perAgent) ? perAgent : void 0;
565
+ }
566
+
567
+ // src/lib/navigation-context.ts
568
+ async function resolveNavigationDsl(options) {
569
+ if (options.embeddedDsl != null) {
570
+ if (options.projectDslPath) {
571
+ const ctx = await loadDslContext({
572
+ embeddedDsl: options.embeddedDsl,
573
+ projectDslPath: options.projectDslPath
574
+ });
575
+ return ctx.dsl;
576
+ }
577
+ return options.embeddedDsl;
578
+ }
579
+ if (options.projectDslPath) {
580
+ const { resolve: resolve2 } = await import("agent-contracts");
581
+ const result = await resolve2(options.projectDslPath);
582
+ return result.data;
583
+ }
584
+ throw new Error("resolveNavigationDsl requires embeddedDsl or projectDslPath");
585
+ }
586
+ async function buildNavigationContext(options) {
587
+ const diagnostics = [];
588
+ let dsl = await resolveNavigationDsl(options);
589
+ if (options.artifactBinding) {
590
+ const bound = await resolveArtifacts({
591
+ dsl,
592
+ artifactBinding: options.artifactBinding,
593
+ paths: options.paths
594
+ });
595
+ dsl = bound.dsl;
596
+ diagnostics.push(...bound.diagnostics);
597
+ }
598
+ const { validateSchema, buildNavigationIndex } = await import("agent-contracts");
599
+ const validation = validateSchema(dsl);
600
+ const schemaDiagnostics = validation.diagnostics.map((d) => ({
601
+ path: d.path,
602
+ message: d.message,
603
+ severity: d.severity ?? "error"
604
+ }));
605
+ diagnostics.push(...schemaDiagnostics);
606
+ if (!validation.data) {
607
+ throw new Error(
608
+ [
609
+ "DSL schema validation failed \u2014 a navigation index cannot be built from it:",
610
+ ...schemaDiagnostics.map((d) => ` - [${d.severity}] ${d.path}: ${d.message}`)
611
+ ].join("\n")
612
+ );
613
+ }
614
+ const navigationIndex = buildNavigationIndex(validation.data);
615
+ const guardrailCtx = await resolveGuardrailContext(
616
+ dsl,
617
+ options.bindingPaths,
618
+ options.activeGuardrailPolicy
619
+ );
620
+ diagnostics.push(...guardrailCtx.diagnostics);
621
+ const guardrailRules = guardrailCtx.hasGuardrails ? guardrailContextToRuleData(guardrailCtx) : void 0;
622
+ return { dsl, navigationIndex, guardrailRules, diagnostics };
623
+ }
624
+
625
+ // src/lib/claude-native/navigation-sources.ts
626
+ import { existsSync } from "fs";
627
+ import { resolve } from "path";
628
+ async function resolveNavigationSources(options) {
629
+ const manifestPath = resolve(options.projectRoot, PROJECT_CONFIG_FILENAME);
630
+ if (!existsSync(manifestPath)) {
631
+ const projectDslPath2 = resolve(options.projectRoot, options.dslPath);
632
+ const isSource = options.embeddedDsl === void 0 || existsSync(projectDslPath2);
633
+ return {
634
+ navigationOptions: {
635
+ ...isSource ? { projectDslPath: projectDslPath2 } : {},
636
+ embeddedDsl: options.embeddedDsl
637
+ },
638
+ // Both paths are watched even when neither exists yet: the manifest is the
639
+ // file that DECIDES the rest of this set, and the conventional DSL path
640
+ // becomes an overlay the moment it appears. `computeCurrentHash` records an
641
+ // absent file as `missing:<path>`, so the hash changes when either is
642
+ // created.
643
+ sourceFiles: [manifestPath, projectDslPath2]
644
+ };
645
+ }
646
+ const config = await loadProjectConfig(manifestPath);
647
+ const sourceFiles = [manifestPath];
648
+ const projectDslPath = config.dslDeclared ? config.dslPath : void 0;
649
+ if (projectDslPath) {
650
+ sourceFiles.push(projectDslPath);
651
+ }
652
+ if (config.artifactsPath) {
653
+ sourceFiles.push(config.artifactsPath);
654
+ }
655
+ sourceFiles.push(...config.bindingPaths);
656
+ return {
657
+ navigationOptions: {
658
+ ...projectDslPath ? { projectDslPath } : {},
659
+ embeddedDsl: options.embeddedDsl,
660
+ ...config.artifactsPath ? { artifactBinding: { source: config.artifactsPath } } : {},
661
+ bindingPaths: config.bindingPaths,
662
+ ...config.active_guardrail_policy ? { activeGuardrailPolicy: config.active_guardrail_policy } : {}
663
+ },
664
+ sourceFiles
665
+ };
666
+ }
667
+
668
+ export {
669
+ resolveArtifacts,
670
+ DslValidationError,
671
+ buildAgentRegistry,
672
+ buildRegistriesFromDsl,
673
+ loadDslContext,
674
+ getEffectiveGuardrailIds,
675
+ guardrailContextToRuleData,
676
+ buildPerAgentGuardrails,
677
+ resolveGuardrailContext,
678
+ deriveToolchainsForAgents,
679
+ BoundResolver,
680
+ getGuardrailRulesForAgent,
681
+ resolveNavigationDsl,
682
+ buildNavigationContext,
683
+ resolveNavigationSources
684
+ };
685
+ //# sourceMappingURL=chunk-ABXDSTUV.js.map