@aaac/runtime 0.1.13 → 0.1.15
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/dist/adapters/adk-sdk.d.ts +1 -1
- package/dist/adapters/claude-agent-sdk.d.ts +1 -1
- package/dist/adapters/mock.d.ts +1 -1
- package/dist/adapters/openai-agents-sdk.d.ts +1 -1
- package/dist/index.d.ts +97 -3
- package/dist/index.js +256 -2
- package/dist/index.js.map +1 -1
- package/dist/{task-runner-3MPh_dn7.d.ts → task-runner-DUyztyo3.d.ts} +16 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-
|
|
1
|
+
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-DUyztyo3.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '../context-DKkamYX_.js';
|
|
4
4
|
import '@aaac/observability';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-
|
|
1
|
+
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-DUyztyo3.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '../context-DKkamYX_.js';
|
|
4
4
|
import '@aaac/observability';
|
package/dist/adapters/mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SdkAdapter, A as AdapterSendOptions, M as MemoryRef } from '../task-runner-
|
|
1
|
+
import { S as SdkAdapter, A as AdapterSendOptions, M as MemoryRef } from '../task-runner-DUyztyo3.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '../context-DKkamYX_.js';
|
|
4
4
|
import '@aaac/observability';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-
|
|
1
|
+
import { S as SdkAdapter, G as GuardrailHooks, C as CacheConfig, A as AdapterSendOptions, a as AgentExecutionRequest, M as MemoryRef } from '../task-runner-DUyztyo3.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '../context-DKkamYX_.js';
|
|
4
4
|
import '@aaac/observability';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as ObserverEmitFn, T as TaskContext, b as TaskOutcome, c as AgentContractLike, d as TaskContractLike, P as PromptBuilderOptions, W as WorkflowResult, S as SdkAdapter, e as WorkflowRegistries, H as HandoffInput, f as StepCompleteEvent, g as StepResult, D as DelegateStep, h as GuardrailRuleData, i as MemoryStore, M as MemoryRef, L as LibraryToolRegistry, G as GuardrailHooks, R as ResolvedComponent, j as ArtifactBindingConfig, k as TaskRunResult, l as ResolvedToolchain, m as LibraryToolDefinition } from './task-runner-
|
|
2
|
-
export {
|
|
1
|
+
import { O as ObserverEmitFn, T as TaskContext, b as TaskOutcome, c as AgentContractLike, d as TaskContractLike, P as PromptBuilderOptions, W as WorkflowResult, S as SdkAdapter, e as WorkflowRegistries, H as HandoffInput, f as StepCompleteEvent, g as StepResult, D as DelegateStep, h as GuardrailRuleData, i as MemoryStore, M as MemoryRef, L as LibraryToolRegistry, G as GuardrailHooks, R as ResolvedComponent, j as ArtifactBindingConfig, k as TaskRunResult, l as ResolvedToolchain, m as LibraryToolDefinition, n as HookResponse, o as GuardrailCheckResult } from './task-runner-DUyztyo3.js';
|
|
2
|
+
export { p as AdapterOrFactory, A as AdapterSendOptions, a as AgentExecutionRequest, q as AgentProgressEvent, B as BoundResolveOptions, r as BoundResolver, C as CacheConfig, s as CandidateAgent, t as ConvergenceEnvelope, u as ConvergenceEnvelopePayload, E as EnvelopeParams, v as EvaluateStep, w as GateStep, x as GuardrailCheckFunctions, y as GuardrailRule, z as HookContext, I as InMemoryStore, F as ModelAwareSdkAdapterFactory, J as ModelClass, K as ModelMappingConfig, N as ModelResolver, Q as ModelResolverOptions, U as ReceiveSpec, V as ResolvedModel, X as RetryDecision, Y as SdkAdapterFactory, Z as SplitPrompt, _ as TaskRunOptions, $ as WorkflowContractLike, a0 as WorkflowInvocation, a1 as WorkflowRunOptions, a2 as WorkflowStep, a3 as buildCandidateAgents, a4 as buildGateEvaluationPrompt, a5 as buildPerAgentGuardrails, a6 as buildRetryFollowUp, a7 as buildSplitTaskPrompt, a8 as buildTaskPrompt, a9 as createExecutionEnvelope, aa as createGuardrailHooks, ab as createGuardrailHooksForAgent, ac as createGuardrailHooksFromRules, ad as createLibraryToolRegistry, ae as createModelResolver, af as deriveToolchainsForAgents, ag as emitIterationClose, ah as emitIterationMetric, ai as emitIterationOpen, aj as emitSessionClose, ak as emitSessionOpen, al as emitSubagentClose, am as emitSubagentOpen, an as emitToolchainClose, ao as emitToolchainOpen, ap as extractStructuredResult, aq as getBlockingViolations, ar as getEffectiveGuardrailIds, as as getGuardrailRulesForAgent, at as getWarnings, au as guardrailContextToRuleData, av as hasBlockingViolation, aw as parseGateEvaluationResponse, ax as renderAgentSystemPrompt, ay as runTask, az as runWorkflow, aA as zodSchemaToPromptDescription, aB as zodSchemaToYamlExample } from './task-runner-DUyztyo3.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { OperationIR, ComponentIR } from '@aaac/contracts';
|
|
5
5
|
import { ResolvedConfig } from './generator/index.js';
|
|
@@ -651,6 +651,100 @@ interface ArtifactResolveResult {
|
|
|
651
651
|
}
|
|
652
652
|
declare function resolveArtifacts(options: ArtifactResolveOptions): Promise<ArtifactResolveResult>;
|
|
653
653
|
|
|
654
|
+
/**
|
|
655
|
+
* Guard CLI commands — evaluate/list/status for guardrail enforcement.
|
|
656
|
+
*
|
|
657
|
+
* These functions back the `guard evaluate`, `guard list`, and `guard status`
|
|
658
|
+
* sub-commands that are auto-injected by @aaac/contracts cli-generator
|
|
659
|
+
* whenever `governance.guardrails: true` is declared in component.yaml.
|
|
660
|
+
*
|
|
661
|
+
* exit code contract (evaluate):
|
|
662
|
+
* 0 = allowed / pass / warn
|
|
663
|
+
* 2 = denied (permission === "deny")
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
interface EvaluateGuardrailOptions {
|
|
667
|
+
/** Raw JSON string read from stdin (HookContext format). */
|
|
668
|
+
hookJson: string;
|
|
669
|
+
/** Component agent-contracts DSL (contains guardrails + guardrail_policies). */
|
|
670
|
+
dsl: Record<string, unknown>;
|
|
671
|
+
/** Paths to software binding YAML files (contain guardrail_impl matchers). */
|
|
672
|
+
bindingPaths: string[];
|
|
673
|
+
/** Active guardrail policy name (from project.yaml active_guardrail_policy). */
|
|
674
|
+
activeGuardrailPolicy?: string;
|
|
675
|
+
}
|
|
676
|
+
interface EvaluateGuardrailResult {
|
|
677
|
+
/** HookResponse to write to stdout. */
|
|
678
|
+
response: HookResponse;
|
|
679
|
+
/**
|
|
680
|
+
* CLI exit code.
|
|
681
|
+
* 0 = allowed (pass or warn)
|
|
682
|
+
* 2 = denied (permission === "deny")
|
|
683
|
+
*/
|
|
684
|
+
exitCode: 0 | 2;
|
|
685
|
+
/** All check results from all matchers. */
|
|
686
|
+
checks: GuardrailCheckResult[];
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Evaluate a guardrail hook from a JSON string (typically stdin).
|
|
690
|
+
*
|
|
691
|
+
* Detects the hook type from which fields are present in the input:
|
|
692
|
+
* - `command` → beforeShellExecution
|
|
693
|
+
* - `tool_name` / `tool_input` → preToolUse
|
|
694
|
+
* - `file_path` (without command) → afterFileEdit
|
|
695
|
+
*/
|
|
696
|
+
declare function evaluateGuardrail(opts: EvaluateGuardrailOptions): Promise<EvaluateGuardrailResult>;
|
|
697
|
+
interface ListGuardrailsOptions {
|
|
698
|
+
/** Component agent-contracts DSL. */
|
|
699
|
+
dsl: Record<string, unknown>;
|
|
700
|
+
/** Paths to software binding YAML files. */
|
|
701
|
+
bindingPaths: string[];
|
|
702
|
+
/** Active guardrail policy name. */
|
|
703
|
+
activeGuardrailPolicy?: string;
|
|
704
|
+
}
|
|
705
|
+
interface GuardrailListEntry {
|
|
706
|
+
guardrail_id: string;
|
|
707
|
+
description: string;
|
|
708
|
+
matcher_type: string;
|
|
709
|
+
action: string;
|
|
710
|
+
severity: string;
|
|
711
|
+
pattern: string;
|
|
712
|
+
}
|
|
713
|
+
interface ListGuardrailsResult {
|
|
714
|
+
policy: string | undefined;
|
|
715
|
+
entries: GuardrailListEntry[];
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* List all active guardrails and their enforcement settings.
|
|
719
|
+
*
|
|
720
|
+
* Reads DSL + binding files and builds the guardrail context for the active
|
|
721
|
+
* policy, returning a flat list of guardrail_id / matcher_type / action /
|
|
722
|
+
* severity rows for display.
|
|
723
|
+
*/
|
|
724
|
+
declare function listGuardrails(opts: ListGuardrailsOptions): Promise<ListGuardrailsResult>;
|
|
725
|
+
interface GuardStatusOptions {
|
|
726
|
+
/** Base directory for agent logs (defaults to ".agent-logs"). */
|
|
727
|
+
baseDir?: string;
|
|
728
|
+
/** Maximum number of recent run events to return (defaults to 10). */
|
|
729
|
+
limit?: number;
|
|
730
|
+
}
|
|
731
|
+
interface GuardStatusResult {
|
|
732
|
+
hasHistory: boolean;
|
|
733
|
+
message: string;
|
|
734
|
+
/** Recent run log events (operation_start/end, etc.). */
|
|
735
|
+
recentEvents: unknown[];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Show recent guardrail evaluation summary.
|
|
739
|
+
*
|
|
740
|
+
* Phase 1 limitation: RunLogEvent does not yet include a `guardrail_evaluate`
|
|
741
|
+
* event type, so this command reports general run history from .agent-logs/runs/.
|
|
742
|
+
* Guard-specific event tracking will be added in a future phase.
|
|
743
|
+
*
|
|
744
|
+
* Gracefully returns "no evaluation history" when .agent-logs/ does not exist.
|
|
745
|
+
*/
|
|
746
|
+
declare function guardStatus(opts?: GuardStatusOptions): Promise<GuardStatusResult>;
|
|
747
|
+
|
|
654
748
|
/**
|
|
655
749
|
* @aaac/runtime — public API
|
|
656
750
|
*
|
|
@@ -659,4 +753,4 @@ declare function resolveArtifacts(options: ArtifactResolveOptions): Promise<Arti
|
|
|
659
753
|
/** Package version string. */
|
|
660
754
|
declare const version: string;
|
|
661
755
|
|
|
662
|
-
export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime, AgentContractLike, AgentLogWriter, type AgentLogWriterOptions, type AgentPlugin, ArtifactBindingConfig, type ArtifactResolveOptions, type ArtifactResolveResult, type ComponentScope, type CreateAdapterOptions, type CreateComponentScopeOptions, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, GuardrailHooks, type GuardrailResult, GuardrailRuleData, HandoffInput, LibraryToolDefinition, LibraryToolRegistry, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type RequiredEntities, type ResolvedAdapterSelection, ResolvedComponent, ResolvedToolchain, type RunLogEvent, type Runtime, type RuntimeBinding, type RuntimeConfig, SdkAdapter, type SdkFunctionTool, StepCompleteEvent, StepResult, TaskContext, TaskContractLike, type TaskHookContext, TaskOutcome, TaskRunResult, WorkflowBuilder, type WorkflowHookContext, WorkflowRegistries, WorkflowResult, buildGuardrailRulesFromDsl, buildNavigationContext, buildRegistriesFromDsl, buildSdkFunctionTools, createAdapter, createComponentScope, createProgressSink, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, executeTask, executeWorkflow, findProjectConfig, jsonSchemaToZod, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, pluginRegistry, resolveArtifacts, version };
|
|
756
|
+
export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime, AgentContractLike, AgentLogWriter, type AgentLogWriterOptions, type AgentPlugin, ArtifactBindingConfig, type ArtifactResolveOptions, type ArtifactResolveResult, type ComponentScope, type CreateAdapterOptions, type CreateComponentScopeOptions, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type EvaluateGuardrailOptions, type EvaluateGuardrailResult, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, type GuardStatusOptions, type GuardStatusResult, GuardrailCheckResult, GuardrailHooks, type GuardrailListEntry, type GuardrailResult, GuardrailRuleData, HandoffInput, HookResponse, LibraryToolDefinition, LibraryToolRegistry, type ListGuardrailsOptions, type ListGuardrailsResult, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type RequiredEntities, type ResolvedAdapterSelection, ResolvedComponent, ResolvedToolchain, type RunLogEvent, type Runtime, type RuntimeBinding, type RuntimeConfig, SdkAdapter, type SdkFunctionTool, StepCompleteEvent, StepResult, TaskContext, TaskContractLike, type TaskHookContext, TaskOutcome, TaskRunResult, WorkflowBuilder, type WorkflowHookContext, WorkflowRegistries, WorkflowResult, buildGuardrailRulesFromDsl, buildNavigationContext, buildRegistriesFromDsl, buildSdkFunctionTools, createAdapter, createComponentScope, createProgressSink, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, evaluateGuardrail, executeTask, executeWorkflow, findProjectConfig, guardStatus, jsonSchemaToZod, listGuardrails, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, pluginRegistry, resolveArtifacts, version };
|
package/dist/index.js
CHANGED
|
@@ -214,6 +214,59 @@ function emitSubagentClose(observer, spanId, envelope, durationMs, status, agent
|
|
|
214
214
|
}
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
function emitIterationOpen(observer, parentSpanId, evaluateTaskId, loopTo, iterationNumber, maxIterations) {
|
|
218
|
+
if (!observer) return void 0;
|
|
219
|
+
const spanId = generateId();
|
|
220
|
+
observer({
|
|
221
|
+
source: "aaac-runtime",
|
|
222
|
+
eventType: "evaluate.iteration",
|
|
223
|
+
lifecycle: "open",
|
|
224
|
+
spanId,
|
|
225
|
+
parentSpanId,
|
|
226
|
+
attributes: attrs({
|
|
227
|
+
axis: "agent",
|
|
228
|
+
"evaluate.task": evaluateTaskId,
|
|
229
|
+
"evaluate.loop_to": loopTo,
|
|
230
|
+
"evaluate.iteration": iterationNumber,
|
|
231
|
+
"evaluate.max_iterations": maxIterations
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
return spanId;
|
|
235
|
+
}
|
|
236
|
+
function emitIterationClose(observer, spanId, evaluateTaskId, iterationNumber, verdict, durationMs, feedbackInjected) {
|
|
237
|
+
if (!observer) return;
|
|
238
|
+
observer({
|
|
239
|
+
source: "aaac-runtime",
|
|
240
|
+
eventType: "evaluate.iteration",
|
|
241
|
+
lifecycle: "close",
|
|
242
|
+
spanId,
|
|
243
|
+
attributes: attrs({
|
|
244
|
+
axis: "agent",
|
|
245
|
+
"evaluate.task": evaluateTaskId,
|
|
246
|
+
"evaluate.iteration": iterationNumber,
|
|
247
|
+
"evaluate.verdict": verdict,
|
|
248
|
+
"evaluate.duration_ms": durationMs,
|
|
249
|
+
"evaluate.feedback_injected": feedbackInjected
|
|
250
|
+
})
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function emitIterationMetric(observer, parentSpanId, evaluateTaskId, totalIterations, terminalOutcome) {
|
|
254
|
+
if (!observer) return;
|
|
255
|
+
const spanId = generateId();
|
|
256
|
+
observer({
|
|
257
|
+
source: "aaac-runtime",
|
|
258
|
+
eventType: "evaluate.metric",
|
|
259
|
+
lifecycle: "instant",
|
|
260
|
+
spanId,
|
|
261
|
+
parentSpanId,
|
|
262
|
+
attributes: attrs({
|
|
263
|
+
axis: "agent",
|
|
264
|
+
"evaluate.task": evaluateTaskId,
|
|
265
|
+
"evaluate.total_iterations": totalIterations,
|
|
266
|
+
"evaluate.terminal_outcome": terminalOutcome
|
|
267
|
+
})
|
|
268
|
+
});
|
|
269
|
+
}
|
|
217
270
|
function emitToolchainOpen(observer, parentSpanId, toolchainId, operation, artifactIds, componentId) {
|
|
218
271
|
if (!observer) return void 0;
|
|
219
272
|
const spanId = generateId();
|
|
@@ -975,6 +1028,7 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
975
1028
|
const stepOutputs = new Array(workflow.steps.length).fill(void 0);
|
|
976
1029
|
let abortResult;
|
|
977
1030
|
const evaluateExecCount = /* @__PURE__ */ new Map();
|
|
1031
|
+
const iterationSpanIds = /* @__PURE__ */ new Map();
|
|
978
1032
|
const loopInjectedVars = {};
|
|
979
1033
|
function extractPath(obj, path) {
|
|
980
1034
|
const cleanPath = path.startsWith("$.") ? path.slice(2) : path;
|
|
@@ -1016,6 +1070,18 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
1016
1070
|
}
|
|
1017
1071
|
if (step.type === "evaluate") {
|
|
1018
1072
|
const evaluateStep = step;
|
|
1073
|
+
const iterationNumber = (evaluateExecCount.get(i) ?? 0) + 1;
|
|
1074
|
+
const iterationSpanId = emitIterationOpen(
|
|
1075
|
+
options.observer,
|
|
1076
|
+
sessionSpanId,
|
|
1077
|
+
evaluateStep.task,
|
|
1078
|
+
evaluateStep.loop_to,
|
|
1079
|
+
iterationNumber,
|
|
1080
|
+
evaluateStep.max_iterations
|
|
1081
|
+
);
|
|
1082
|
+
if (iterationSpanId) {
|
|
1083
|
+
iterationSpanIds.set(i, iterationSpanId);
|
|
1084
|
+
}
|
|
1019
1085
|
const effectiveVariables = mergeVariables(options.variables, loopInjectedVars);
|
|
1020
1086
|
const context2 = {
|
|
1021
1087
|
user_request: evaluateStep.description ?? options.user_request,
|
|
@@ -1031,7 +1097,7 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
1031
1097
|
handoffSchemas: registries?.handoffSchemas,
|
|
1032
1098
|
progressOutput: options.progressOutput,
|
|
1033
1099
|
observer: options.observer,
|
|
1034
|
-
parentSpanId: sessionSpanId
|
|
1100
|
+
parentSpanId: iterationSpanId ?? sessionSpanId
|
|
1035
1101
|
});
|
|
1036
1102
|
return {
|
|
1037
1103
|
step_index: i,
|
|
@@ -1147,7 +1213,29 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
1147
1213
|
const data = result.outcome.status === "success" ? result.outcome.data : void 0;
|
|
1148
1214
|
const verdict = typeof data?.verdict === "string" ? data.verdict : "fail";
|
|
1149
1215
|
const execCount = (evaluateExecCount.get(i) ?? 0) + 1;
|
|
1216
|
+
const currentIterationSpanId = iterationSpanIds.get(i);
|
|
1217
|
+
if (currentIterationSpanId) {
|
|
1218
|
+
const willLoopBack = verdict !== "pass" && execCount < evaluateStep.max_iterations;
|
|
1219
|
+
const feedbackInjected = willLoopBack && !!evaluateStep.inject_as;
|
|
1220
|
+
emitIterationClose(
|
|
1221
|
+
options.observer,
|
|
1222
|
+
currentIterationSpanId,
|
|
1223
|
+
evaluateStep.task,
|
|
1224
|
+
execCount,
|
|
1225
|
+
verdict,
|
|
1226
|
+
result.elapsed_ms,
|
|
1227
|
+
feedbackInjected
|
|
1228
|
+
);
|
|
1229
|
+
iterationSpanIds.delete(i);
|
|
1230
|
+
}
|
|
1150
1231
|
if (verdict === "pass") {
|
|
1232
|
+
emitIterationMetric(
|
|
1233
|
+
options.observer,
|
|
1234
|
+
sessionSpanId,
|
|
1235
|
+
evaluateStep.task,
|
|
1236
|
+
execCount,
|
|
1237
|
+
"pass"
|
|
1238
|
+
);
|
|
1151
1239
|
stepResults[i] = result;
|
|
1152
1240
|
completed.add(i);
|
|
1153
1241
|
emitStepEvent(options, workflow.id, i, step, result);
|
|
@@ -1186,7 +1274,15 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
1186
1274
|
evaluateExecCount.set(i, execCount);
|
|
1187
1275
|
stepResults[i] = result;
|
|
1188
1276
|
completed.add(i);
|
|
1189
|
-
|
|
1277
|
+
const exhaustedPolicy = evaluateStep.on_exhausted ?? "escalate";
|
|
1278
|
+
emitIterationMetric(
|
|
1279
|
+
options.observer,
|
|
1280
|
+
sessionSpanId,
|
|
1281
|
+
evaluateStep.task,
|
|
1282
|
+
execCount,
|
|
1283
|
+
`exhausted-${exhaustedPolicy}`
|
|
1284
|
+
);
|
|
1285
|
+
switch (exhaustedPolicy) {
|
|
1190
1286
|
case "abort":
|
|
1191
1287
|
abortResult = {
|
|
1192
1288
|
workflow_id: workflow.id,
|
|
@@ -2906,6 +3002,158 @@ async function resolveArtifacts(options) {
|
|
|
2906
3002
|
};
|
|
2907
3003
|
}
|
|
2908
3004
|
|
|
3005
|
+
// src/lib/guard-commands.ts
|
|
3006
|
+
import { readFile as readFile6, readdir as readdir3 } from "fs/promises";
|
|
3007
|
+
import YAML4 from "yaml";
|
|
3008
|
+
async function evaluateGuardrail(opts) {
|
|
3009
|
+
let hookInput;
|
|
3010
|
+
try {
|
|
3011
|
+
hookInput = JSON.parse(opts.hookJson);
|
|
3012
|
+
} catch (cause) {
|
|
3013
|
+
throw new Error(
|
|
3014
|
+
`Invalid hook JSON: input must be valid JSON. ${cause.message}`
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
let guardrailCtx = {
|
|
3018
|
+
commandChecks: [],
|
|
3019
|
+
fileChecks: [],
|
|
3020
|
+
contentChecks: [],
|
|
3021
|
+
allChecks: [],
|
|
3022
|
+
hasGuardrails: false
|
|
3023
|
+
};
|
|
3024
|
+
for (const bindingPath of opts.bindingPaths) {
|
|
3025
|
+
let raw;
|
|
3026
|
+
try {
|
|
3027
|
+
raw = await readFile6(bindingPath, "utf8");
|
|
3028
|
+
} catch (err) {
|
|
3029
|
+
const code = err.code;
|
|
3030
|
+
if (code === "ENOENT") continue;
|
|
3031
|
+
throw err;
|
|
3032
|
+
}
|
|
3033
|
+
const binding = YAML4.parse(raw);
|
|
3034
|
+
guardrailCtx = buildGuardrailContext(
|
|
3035
|
+
opts.dsl,
|
|
3036
|
+
binding,
|
|
3037
|
+
opts.activeGuardrailPolicy
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
const ruleData = guardrailContextToRuleData(guardrailCtx);
|
|
3041
|
+
const hooks = createGuardrailHooksFromRules(ruleData);
|
|
3042
|
+
const command = hookInput.command;
|
|
3043
|
+
const toolName = hookInput.tool_name;
|
|
3044
|
+
const toolInput = hookInput.tool_input;
|
|
3045
|
+
const filePath = hookInput.file_path;
|
|
3046
|
+
const content = hookInput.content;
|
|
3047
|
+
let response = {};
|
|
3048
|
+
let checks = [];
|
|
3049
|
+
if (command !== void 0) {
|
|
3050
|
+
response = hooks.beforeShellExecution({ command });
|
|
3051
|
+
checks = hooks.runChecks({ command });
|
|
3052
|
+
} else if (toolName !== void 0 || toolInput !== void 0) {
|
|
3053
|
+
response = hooks.preToolUse({ tool_name: toolName, tool_input: toolInput });
|
|
3054
|
+
const checkFilePath = toolInput?.file_path ?? toolInput?.path ?? "";
|
|
3055
|
+
if (checkFilePath) {
|
|
3056
|
+
checks = hooks.runChecks({ filePath: checkFilePath });
|
|
3057
|
+
}
|
|
3058
|
+
} else if (filePath !== void 0) {
|
|
3059
|
+
response = hooks.afterFileEdit({ file_path: filePath, content });
|
|
3060
|
+
checks = hooks.runChecks({ filePath, content });
|
|
3061
|
+
}
|
|
3062
|
+
const exitCode = response.permission === "deny" ? 2 : 0;
|
|
3063
|
+
return { response, exitCode, checks };
|
|
3064
|
+
}
|
|
3065
|
+
async function listGuardrails(opts) {
|
|
3066
|
+
let guardrailCtx = {
|
|
3067
|
+
commandChecks: [],
|
|
3068
|
+
fileChecks: [],
|
|
3069
|
+
contentChecks: [],
|
|
3070
|
+
allChecks: [],
|
|
3071
|
+
hasGuardrails: false
|
|
3072
|
+
};
|
|
3073
|
+
for (const bindingPath of opts.bindingPaths) {
|
|
3074
|
+
let raw;
|
|
3075
|
+
try {
|
|
3076
|
+
raw = await readFile6(bindingPath, "utf8");
|
|
3077
|
+
} catch (err) {
|
|
3078
|
+
const code = err.code;
|
|
3079
|
+
if (code === "ENOENT") continue;
|
|
3080
|
+
throw err;
|
|
3081
|
+
}
|
|
3082
|
+
const binding = YAML4.parse(raw);
|
|
3083
|
+
guardrailCtx = buildGuardrailContext(
|
|
3084
|
+
opts.dsl,
|
|
3085
|
+
binding,
|
|
3086
|
+
opts.activeGuardrailPolicy
|
|
3087
|
+
);
|
|
3088
|
+
}
|
|
3089
|
+
const entries = guardrailCtx.allChecks.map(
|
|
3090
|
+
(c) => ({
|
|
3091
|
+
guardrail_id: c.guardrail_id,
|
|
3092
|
+
description: c.description,
|
|
3093
|
+
matcher_type: c.matcher_type,
|
|
3094
|
+
action: c.action,
|
|
3095
|
+
severity: c.severity,
|
|
3096
|
+
pattern: c.pattern
|
|
3097
|
+
})
|
|
3098
|
+
);
|
|
3099
|
+
return {
|
|
3100
|
+
policy: opts.activeGuardrailPolicy,
|
|
3101
|
+
entries
|
|
3102
|
+
};
|
|
3103
|
+
}
|
|
3104
|
+
async function guardStatus(opts = {}) {
|
|
3105
|
+
const baseDir = opts.baseDir ?? ".agent-logs";
|
|
3106
|
+
const runsDir = `${baseDir}/runs`;
|
|
3107
|
+
const limit = opts.limit ?? 10;
|
|
3108
|
+
let files = [];
|
|
3109
|
+
try {
|
|
3110
|
+
files = await readdir3(runsDir);
|
|
3111
|
+
} catch (err) {
|
|
3112
|
+
const code = err.code;
|
|
3113
|
+
if (code === "ENOENT") {
|
|
3114
|
+
return {
|
|
3115
|
+
hasHistory: false,
|
|
3116
|
+
message: "No evaluation history. Note: guardrail_evaluate event type is not yet tracked in Phase 1.",
|
|
3117
|
+
recentEvents: []
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
throw err;
|
|
3121
|
+
}
|
|
3122
|
+
const jsonlFiles = files.filter((f) => f.endsWith(".jsonl")).sort().reverse().slice(0, limit);
|
|
3123
|
+
if (jsonlFiles.length === 0) {
|
|
3124
|
+
return {
|
|
3125
|
+
hasHistory: false,
|
|
3126
|
+
message: "No evaluation history.",
|
|
3127
|
+
recentEvents: []
|
|
3128
|
+
};
|
|
3129
|
+
}
|
|
3130
|
+
const recentEvents = [];
|
|
3131
|
+
for (const file of jsonlFiles) {
|
|
3132
|
+
const filePath = `${runsDir}/${file}`;
|
|
3133
|
+
let raw;
|
|
3134
|
+
try {
|
|
3135
|
+
raw = await readFile6(filePath, "utf8");
|
|
3136
|
+
} catch {
|
|
3137
|
+
continue;
|
|
3138
|
+
}
|
|
3139
|
+
const events = raw.split("\n").filter((line) => line.trim().length > 0).map((line) => {
|
|
3140
|
+
try {
|
|
3141
|
+
return JSON.parse(line);
|
|
3142
|
+
} catch {
|
|
3143
|
+
return null;
|
|
3144
|
+
}
|
|
3145
|
+
}).filter(Boolean);
|
|
3146
|
+
recentEvents.push(...events);
|
|
3147
|
+
if (recentEvents.length >= limit) break;
|
|
3148
|
+
}
|
|
3149
|
+
const count = recentEvents.length;
|
|
3150
|
+
return {
|
|
3151
|
+
hasHistory: count > 0,
|
|
3152
|
+
message: count > 0 ? `${count} recent run event(s) found. Note: guardrail_evaluate events are not yet tracked in Phase 1.` : "No evaluation history.",
|
|
3153
|
+
recentEvents: recentEvents.slice(0, limit)
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
|
|
2909
3157
|
// src/index.ts
|
|
2910
3158
|
var require2 = createRequire(import.meta.url);
|
|
2911
3159
|
var pkg = require2("../package.json");
|
|
@@ -2942,6 +3190,9 @@ export {
|
|
|
2942
3190
|
createRuntime,
|
|
2943
3191
|
createRuntimeBinding,
|
|
2944
3192
|
deriveToolchainsForAgents,
|
|
3193
|
+
emitIterationClose,
|
|
3194
|
+
emitIterationMetric,
|
|
3195
|
+
emitIterationOpen,
|
|
2945
3196
|
emitProcessEdit,
|
|
2946
3197
|
emitProcessTaskClose,
|
|
2947
3198
|
emitProcessTaskOpen,
|
|
@@ -2953,6 +3204,7 @@ export {
|
|
|
2953
3204
|
emitSubagentOpen,
|
|
2954
3205
|
emitToolchainClose,
|
|
2955
3206
|
emitToolchainOpen,
|
|
3207
|
+
evaluateGuardrail,
|
|
2956
3208
|
executeTask,
|
|
2957
3209
|
executeWorkflow,
|
|
2958
3210
|
extractStructuredResult,
|
|
@@ -2961,9 +3213,11 @@ export {
|
|
|
2961
3213
|
getEffectiveGuardrailIds,
|
|
2962
3214
|
getGuardrailRulesForAgent,
|
|
2963
3215
|
getWarnings,
|
|
3216
|
+
guardStatus,
|
|
2964
3217
|
guardrailContextToRuleData,
|
|
2965
3218
|
hasBlockingViolation,
|
|
2966
3219
|
jsonSchemaToZod,
|
|
3220
|
+
listGuardrails,
|
|
2967
3221
|
loadDslContext,
|
|
2968
3222
|
loadPlugins,
|
|
2969
3223
|
loadPluginsFromDirectory,
|