nexus-agents 4.26.9 → 4.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/{chunk-O7LX6CCH.js → chunk-6OAWETHW.js} +2 -2
  2. package/dist/{chunk-YOGYNVAN.js → chunk-7V5V6H5C.js} +26 -24
  3. package/dist/{chunk-YOGYNVAN.js.map → chunk-7V5V6H5C.js.map} +1 -1
  4. package/dist/chunk-D2E5PC2V.js +7 -0
  5. package/dist/{chunk-VYZWF4DB.js → chunk-EGO754SU.js} +41 -18
  6. package/dist/{chunk-VYZWF4DB.js.map → chunk-EGO754SU.js.map} +1 -1
  7. package/dist/{chunk-FQQOROWP.js → chunk-LLJ65HUO.js} +2 -2
  8. package/dist/{chunk-DHYDTSS3.js → chunk-Q4T3UWOC.js} +2 -2
  9. package/dist/{chunk-MJQVSJZB.js → chunk-RV57MIQU.js} +1 -1
  10. package/dist/chunk-RV57MIQU.js.map +1 -0
  11. package/dist/{chunk-MQTXQPFN.js → chunk-VEFRTBUE.js} +3 -3
  12. package/dist/cli.js +22 -10
  13. package/dist/cli.js.map +1 -1
  14. package/dist/{consensus-vote-ZCZJS543.js → consensus-vote-YYHQHD7V.js} +5 -5
  15. package/dist/{improvement-review-GG7IIXBS.js → improvement-review-C74SDVTQ.js} +5 -5
  16. package/dist/index.d.ts +46 -0
  17. package/dist/index.js +9 -9
  18. package/dist/{issue-triage-N4ZYYJYR.js → issue-triage-BOGQS5GP.js} +3 -3
  19. package/dist/{setup-data-dir-CF5HCZ3V.js → setup-data-dir-YSN7UU3M.js} +3 -3
  20. package/package.json +1 -1
  21. package/dist/chunk-ARR4ZJVE.js +0 -7
  22. package/dist/chunk-MJQVSJZB.js.map +0 -1
  23. /package/dist/{chunk-O7LX6CCH.js.map → chunk-6OAWETHW.js.map} +0 -0
  24. /package/dist/{chunk-ARR4ZJVE.js.map → chunk-D2E5PC2V.js.map} +0 -0
  25. /package/dist/{chunk-FQQOROWP.js.map → chunk-LLJ65HUO.js.map} +0 -0
  26. /package/dist/{chunk-DHYDTSS3.js.map → chunk-Q4T3UWOC.js.map} +0 -0
  27. /package/dist/{chunk-MQTXQPFN.js.map → chunk-VEFRTBUE.js.map} +0 -0
  28. /package/dist/{consensus-vote-ZCZJS543.js.map → consensus-vote-YYHQHD7V.js.map} +0 -0
  29. /package/dist/{improvement-review-GG7IIXBS.js.map → improvement-review-C74SDVTQ.js.map} +0 -0
  30. /package/dist/{issue-triage-N4ZYYJYR.js.map → issue-triage-BOGQS5GP.js.map} +0 -0
  31. /package/dist/{setup-data-dir-CF5HCZ3V.js.map → setup-data-dir-YSN7UU3M.js.map} +0 -0
@@ -11,12 +11,12 @@ import {
11
11
  resetCorrelationTracker,
12
12
  runConsensusForGoal,
13
13
  unwrapVoteOrThrow
14
- } from "./chunk-O7LX6CCH.js";
14
+ } from "./chunk-6OAWETHW.js";
15
15
  import "./chunk-NAL4EHFM.js";
16
16
  import "./chunk-OQB3XC5O.js";
17
- import "./chunk-YOGYNVAN.js";
18
- import "./chunk-ARR4ZJVE.js";
19
- import "./chunk-MJQVSJZB.js";
17
+ import "./chunk-7V5V6H5C.js";
18
+ import "./chunk-D2E5PC2V.js";
19
+ import "./chunk-RV57MIQU.js";
20
20
  import "./chunk-N3SKF4YT.js";
21
21
  import "./chunk-PU2NTY6U.js";
22
22
  import "./chunk-6T3EPABN.js";
@@ -50,4 +50,4 @@ export {
50
50
  runConsensusForGoal,
51
51
  unwrapVoteOrThrow
52
52
  };
53
- //# sourceMappingURL=consensus-vote-ZCZJS543.js.map
53
+ //# sourceMappingURL=consensus-vote-YYHQHD7V.js.map
@@ -11,10 +11,10 @@ import {
11
11
  loadSelfEvalSignals,
12
12
  registerImprovementReviewTool,
13
13
  runImprovementReview
14
- } from "./chunk-DHYDTSS3.js";
15
- import "./chunk-YOGYNVAN.js";
16
- import "./chunk-ARR4ZJVE.js";
17
- import "./chunk-MJQVSJZB.js";
14
+ } from "./chunk-Q4T3UWOC.js";
15
+ import "./chunk-7V5V6H5C.js";
16
+ import "./chunk-D2E5PC2V.js";
17
+ import "./chunk-RV57MIQU.js";
18
18
  import "./chunk-6Q4XUAE5.js";
19
19
  import "./chunk-GBHJ37V3.js";
20
20
  import "./chunk-OGHEKPLD.js";
@@ -33,4 +33,4 @@ export {
33
33
  registerImprovementReviewTool,
34
34
  runImprovementReview
35
35
  };
36
- //# sourceMappingURL=improvement-review-GG7IIXBS.js.map
36
+ //# sourceMappingURL=improvement-review-C74SDVTQ.js.map
package/dist/index.d.ts CHANGED
@@ -21293,7 +21293,38 @@ interface DryRunResult {
21293
21293
  * Dependencies required by the run_workflow tool.
21294
21294
  */
21295
21295
  interface RunWorkflowDeps extends BaseMcpToolDeps {
21296
+ /**
21297
+ * Engine used to ENUMERATE and load templates — `listTemplates`,
21298
+ * `getTemplateByName`, `loadTemplate`. Never used to execute.
21299
+ *
21300
+ * Listing needs no model adapter, so this engine is constructible on a fresh
21301
+ * install with no credentials. That is the capability split #5116 turns on:
21302
+ * enumerating workflows and running them have different prerequisites.
21303
+ */
21296
21304
  workflowEngine: IWorkflowEngine;
21305
+ /**
21306
+ * Resolves the engine that actually EXECUTES, at call time (#5116).
21307
+ *
21308
+ * A THUNK rather than a value because constructing an executing engine throws
21309
+ * `WorkflowExecutionUnavailableError` under the #507 fail-safe when nothing
21310
+ * can execute for real — doing that eagerly at tool registration killed the
21311
+ * whole server, all 47 tools, over one unconfigured adapter.
21312
+ *
21313
+ * OPTIONAL rather than required, by unanimous panel decision. It was briefly
21314
+ * required, which is how all eight internal call sites were enumerated by the
21315
+ * compiler — that value is already banked. Keeping it required would make
21316
+ * this a breaking change to a publicly exported type (`exports/mcp.ts`) and
21317
+ * gate a p1 correctness fix behind a major version.
21318
+ *
21319
+ * Defaulting to `workflowEngine` is semantically correct for an external
21320
+ * caller, not merely compile-compatible: their single engine genuinely serves
21321
+ * both listing and execution, so the fallback preserves exactly what they had.
21322
+ * The residual hazard — a future INTERNAL call site omitting this and
21323
+ * executing against a listing engine — is covered two ways: a test asserting
21324
+ * the production registration supplies it, and the listing engine failing
21325
+ * closed rather than returning a fabricated success.
21326
+ */
21327
+ resolveExecutionEngine?: (() => IWorkflowEngine) | undefined;
21297
21328
  /** MCP notifier for client-visible logging (Issue #974) */
21298
21329
  notifier?: IMcpNotifier | undefined;
21299
21330
  }
@@ -30690,6 +30721,21 @@ interface ClawGuardViolationEvent extends AuditEventBase {
30690
30721
  readonly mode: string;
30691
30722
  /** Request ID of the offending tool call, for correlation. */
30692
30723
  readonly requestId: string;
30724
+ /**
30725
+ * Which rule produced the verdict (#5106) — `unbypassable:tool`,
30726
+ * `unbypassable:path`, `allowedTools`, `allowedTools:confirm_risky`.
30727
+ *
30728
+ * A first-class field rather than prose inside `warning`, because `warning`
30729
+ * is truncated at 500 chars and a long attacker-selectable `path` argument
30730
+ * pushes the rule off the end. A chain reader must be able to tell an
30731
+ * unbypassable denylist hit from an allowlist miss without parsing a string
30732
+ * that may have been cut mid-word.
30733
+ *
30734
+ * Absent for verdicts that carry no rule (an audit-mode allowlist
30735
+ * observation), which is why it is optional rather than defaulted — there is
30736
+ * no rule to name, and inventing one would misreport.
30737
+ */
30738
+ readonly matchedRule?: string;
30693
30739
  }
30694
30740
  /** Graph execution lifecycle event (Issue #839). */
30695
30741
  interface GraphExecutionAuditEvent extends AuditEventBase {
package/dist/index.js CHANGED
@@ -553,7 +553,7 @@ import {
553
553
  withLogging,
554
554
  withRetry,
555
555
  withRetryWrapper
556
- } from "./chunk-VYZWF4DB.js";
556
+ } from "./chunk-EGO754SU.js";
557
557
  import {
558
558
  FALLBACK_SCANNER_DATA,
559
559
  buildPlanFromAnalysis,
@@ -574,7 +574,7 @@ import {
574
574
  connectTransport,
575
575
  createServer,
576
576
  startStdioServer
577
- } from "./chunk-MQTXQPFN.js";
577
+ } from "./chunk-VEFRTBUE.js";
578
578
  import {
579
579
  OPENAI_MODELS,
580
580
  OPENAI_MODEL_ALIASES,
@@ -632,7 +632,7 @@ import {
632
632
  generateProposalId,
633
633
  parseAgentPairKey,
634
634
  registerConsensusVoteTool
635
- } from "./chunk-O7LX6CCH.js";
635
+ } from "./chunk-6OAWETHW.js";
636
636
  import "./chunk-NAL4EHFM.js";
637
637
  import {
638
638
  allOf
@@ -660,7 +660,7 @@ import {
660
660
  requiresHumanApproval,
661
661
  validateAgentAction,
662
662
  validateCorroboration
663
- } from "./chunk-FQQOROWP.js";
663
+ } from "./chunk-LLJ65HUO.js";
664
664
  import {
665
665
  GitHubProvider,
666
666
  ScmError
@@ -683,7 +683,7 @@ import {
683
683
  import {
684
684
  ImprovementReviewInputSchema,
685
685
  registerImprovementReviewTool
686
- } from "./chunk-DHYDTSS3.js";
686
+ } from "./chunk-Q4T3UWOC.js";
687
687
  import {
688
688
  AgentPerformanceSchema,
689
689
  ConsensusAlgorithmSchema,
@@ -719,10 +719,10 @@ import {
719
719
  toolSuccess,
720
720
  toolSuccessStructured,
721
721
  validateToolInput
722
- } from "./chunk-YOGYNVAN.js";
722
+ } from "./chunk-7V5V6H5C.js";
723
723
  import {
724
724
  VERSION
725
- } from "./chunk-ARR4ZJVE.js";
725
+ } from "./chunk-D2E5PC2V.js";
726
726
  import {
727
727
  AuditTrail,
728
728
  MAX_STRIPPED_ELEMENTS_PER_EVENT,
@@ -734,7 +734,7 @@ import {
734
734
  emitReputationEvent,
735
735
  emitSanitizationEvent,
736
736
  emitTrustEvent
737
- } from "./chunk-MJQVSJZB.js";
737
+ } from "./chunk-RV57MIQU.js";
738
738
  import {
739
739
  UnifiedAdapterRegistry,
740
740
  createUnifiedRegistry,
@@ -4729,7 +4729,7 @@ function buildVotingInput(plan, config) {
4729
4729
  }
4730
4730
  async function executeSingleVote(plan, config, log) {
4731
4731
  try {
4732
- const { executeVoting } = await import("./consensus-vote-ZCZJS543.js");
4732
+ const { executeVoting } = await import("./consensus-vote-YYHQHD7V.js");
4733
4733
  const input = buildVotingInput(plan, config);
4734
4734
  const result = await executeVoting(input, log);
4735
4735
  return parseVotingResult(result);
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  IssueTriage,
3
3
  createIssueTriage
4
- } from "./chunk-FQQOROWP.js";
4
+ } from "./chunk-LLJ65HUO.js";
5
5
  import "./chunk-PSZVTY77.js";
6
6
  import "./chunk-UBWHBW7S.js";
7
- import "./chunk-MJQVSJZB.js";
7
+ import "./chunk-RV57MIQU.js";
8
8
  import "./chunk-V353Q4L7.js";
9
9
  import "./chunk-6Q4XUAE5.js";
10
10
  import "./chunk-GBHJ37V3.js";
@@ -14,4 +14,4 @@ export {
14
14
  IssueTriage,
15
15
  createIssueTriage
16
16
  };
17
- //# sourceMappingURL=issue-triage-N4ZYYJYR.js.map
17
+ //# sourceMappingURL=issue-triage-BOGQS5GP.js.map
@@ -2,11 +2,11 @@ import {
2
2
  NEXUS_DATA_DIR,
3
3
  describeDataDirFix,
4
4
  initDataDirectories
5
- } from "./chunk-MQTXQPFN.js";
5
+ } from "./chunk-VEFRTBUE.js";
6
6
  import "./chunk-VCM2NHH7.js";
7
7
  import "./chunk-NAL4EHFM.js";
8
8
  import "./chunk-OQB3XC5O.js";
9
- import "./chunk-ARR4ZJVE.js";
9
+ import "./chunk-D2E5PC2V.js";
10
10
  import "./chunk-6T3EPABN.js";
11
11
  import "./chunk-IED5SFCF.js";
12
12
  import "./chunk-QUVWKVKU.js";
@@ -26,4 +26,4 @@ export {
26
26
  describeDataDirFix,
27
27
  initDataDirectories
28
28
  };
29
- //# sourceMappingURL=setup-data-dir-CF5HCZ3V.js.map
29
+ //# sourceMappingURL=setup-data-dir-YSN7UU3M.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-agents",
3
- "version": "4.26.9",
3
+ "version": "4.28.0",
4
4
  "description": "Governance substrate for AI coding agents — adversarial PR review, drift-detected rules, tamper-evident audit, and closed-loop outcome routing for Claude, Codex, Gemini, and OpenCode",
5
5
  "mcpName": "io.github.nexus-substrate/nexus-agents",
6
6
  "license": "MIT",
@@ -1,7 +0,0 @@
1
- // src/version.ts
2
- var VERSION = true ? "4.26.9" : "dev";
3
-
4
- export {
5
- VERSION
6
- };
7
- //# sourceMappingURL=chunk-ARR4ZJVE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/security/audit-trail.ts"],"sourcesContent":["/**\n * nexus-agents/security - Audit Trail\n *\n * Machine-readable JSON audit events for security pipeline decisions.\n * Every trust classification, policy gate decision, corroboration check,\n * and reputation assessment is recorded as a structured event.\n *\n * Satisfies CLAUDE.md requirement: \"Every action on untrusted input must\n * log: trust tier, sources cited, policy gate decision, stripped content.\"\n *\n * @module security/audit-trail\n * (Source: Issue #832 — Security audit trail)\n */\n\nimport { getTimeProvider } from '../core/index.js';\nimport type { TrustTier } from './trust-types.js';\nimport type { AgentActionType } from './action-schema.js';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Maximum stored events before oldest are evicted. */\nconst MAX_EVENTS = 10_000;\n\n/**\n * Discriminated union of audit event types.\n * Each event captures a single security pipeline decision.\n */\nexport type AuditEvent =\n | TrustClassificationEvent\n | PolicyGateEvent\n | CorroborationEvent\n | ReputationEvent\n | SanitizationEvent\n | GraphExecutionAuditEvent\n | ClawGuardViolationEvent;\n\n/** Base fields shared by all audit events. */\ninterface AuditEventBase {\n readonly id: string;\n readonly timestamp: string;\n readonly component: string;\n}\n\n/** Trust classification decision. */\nexport interface TrustClassificationEvent extends AuditEventBase {\n readonly type: 'trust_classification';\n readonly username: string;\n readonly assignedTier: TrustTier;\n readonly userRole: string;\n readonly isAllowlisted: boolean;\n readonly wasDowngraded: boolean;\n readonly reason: string;\n}\n\n/** Policy gate evaluation result. */\nexport interface PolicyGateEvent extends AuditEventBase {\n readonly type: 'policy_gate';\n /**\n * The agent action evaluated, for the security policy-gate path\n * (security/policy-gate.ts). Optional because the PIPELINE policy path\n * (pipeline/policy-evaluator.ts → #3710) records stage-boundary policy\n * decisions that have no `AgentAction` — they carry {@link stageType} +\n * {@link mode} + {@link ruleIds} instead. Security emitters always set it.\n */\n readonly actionType?: AgentActionType;\n readonly allowed: boolean;\n readonly requiresApproval: boolean;\n readonly inputTrustTier: TrustTier;\n readonly violationRules: readonly string[];\n /**\n * Pipeline-policy fields (#3710). Carried for the dev-pipeline\n * consensus→execute seam so the DURABLE record can distinguish soak (`warn`)\n * from enforce (`block`) and which rules/stage fired — without these the\n * persisted event is useless to the tune/readiness loop. Absent for the\n * security policy-gate path.\n */\n /** Enforcement mode the decision was made under: `warn` (soak) or `block` (enforce). */\n readonly mode?: 'off' | 'warn' | 'block';\n /** IDs of the policy rules that fired (mirrors `violationRules` for the pipeline path). */\n readonly ruleIds?: readonly string[];\n /** Type of the stage the gate guarded (e.g. `execute`). */\n readonly stageType?: string;\n /**\n * #3727: discriminates a per-EVALUATION SUMMARY record (`'summary'` — emitted\n * once per pipeline policy evaluation INCLUDING clean ones, the DENOMINATOR for\n * the would-block rate) from a per-VIOLATION record (`'violation'` — the\n * existing #3710 per-violation records). Absent for the security policy-gate\n * path. Denominator = count(recordKind==='summary'); numerator = summaries with\n * `violationCount > 0`. Scope the #3710 count-parity assertion to `'violation'`.\n */\n readonly recordKind?: 'summary' | 'violation';\n /** #3727: number of violations in THIS evaluation (set on the summary record). */\n readonly violationCount?: number;\n}\n\n/** Corroboration validation result. */\nexport interface CorroborationEvent extends AuditEventBase {\n readonly type: 'corroboration';\n readonly actionType: AgentActionType;\n readonly satisfied: boolean;\n readonly sourceCount: number;\n readonly missingRequirements: readonly string[];\n}\n\n/** Reputation assessment result. */\nexport interface ReputationEvent extends AuditEventBase {\n readonly type: 'reputation';\n readonly username: string;\n readonly reputationScore: number;\n readonly isSuspicious: boolean;\n readonly effectiveTier: TrustTier;\n readonly signalCount: number;\n}\n\n/** Summary of a single element stripped during sanitization. */\nexport interface StrippedElementSummary {\n /** Truncated tag text (≤30 chars + '...' from the sanitizer). */\n readonly tag: string;\n /** Reason the element was removed (e.g. 'Trail of Bits injection vector'). */\n readonly reason: string;\n}\n\n/** Max stripped-element details retained per sanitization event. */\nexport const MAX_STRIPPED_ELEMENTS_PER_EVENT = 20;\n\n/** Input sanitization result. */\nexport interface SanitizationEvent extends AuditEventBase {\n readonly type: 'sanitization';\n readonly source: string;\n readonly wasModified: boolean;\n readonly strippedCount: number;\n readonly injectionFlagCount: number;\n /**\n * Per-element tag/reason details, truncated to at most\n * MAX_STRIPPED_ELEMENTS_PER_EVENT entries. Required by CLAUDE.md's\n * Untrusted Input Policy: \"Log stripped elements for audit trail.\"\n */\n readonly strippedElements: readonly StrippedElementSummary[];\n}\n\n/**\n * ClawGuard AUDIT-mode violation (#4097). Records a tool call that VIOLATED the\n * derived access policy but was ALLOWED to proceed because the policy is in\n * `audit` mode (log-and-allow). Persisting these is what lets the audit→enforce\n * graduation loop size the real violation rate from durable telemetry rather\n * than ephemeral logs.\n */\nexport interface ClawGuardViolationEvent extends AuditEventBase {\n readonly type: 'clawguard_violation';\n /** The tool whose call violated the policy. */\n readonly toolName: string;\n /** Human-readable warning from the access decision (may be truncated). */\n readonly warning: string;\n /** Source of the derived policy (`llm` / `fallback-keyword` / `bypass`). */\n readonly policySource: string;\n /** Policy mode under which the violation was allowed (e.g. `audit`). */\n readonly mode: string;\n /** Request ID of the offending tool call, for correlation. */\n readonly requestId: string;\n}\n\n/** Graph execution lifecycle event (Issue #839). */\nexport interface GraphExecutionAuditEvent extends AuditEventBase {\n readonly type: 'graph_execution';\n readonly graphEvent: string;\n readonly nodeId?: string;\n readonly stepNumber: number;\n readonly detail: string;\n}\n\n/**\n * Query filter for retrieving audit events.\n *\n * The post-mortem dimensions (#3197) — `actionType`, `actor`, `violationRule`\n * — NARROW to events that actually carry the field (events lacking it are\n * excluded), unlike `trustTier`'s legacy keep-non-applicable behavior. Only\n * dimensions backed by a real event field are offered: `resource` and\n * `policyName` from the original ask were dropped because no AuditEvent\n * records them (a filter with no backing field would be dead config); the\n * policy-rule intent is served by `violationRule` (PolicyGateEvent's\n * `violationRules`).\n */\nexport interface AuditQuery {\n readonly type?: AuditEvent['type'];\n readonly since?: string;\n readonly until?: string;\n readonly trustTier?: TrustTier;\n /** Match PolicyGate/Corroboration events by their `actionType`. */\n readonly actionType?: AgentActionType;\n /** Match Trust/Reputation events by `username` (the acting/assessed user). */\n readonly actor?: string;\n /** Match PolicyGate events whose `violationRules` include this rule name. */\n readonly violationRule?: string;\n readonly limit?: number;\n}\n\n// ============================================================================\n// AuditTrail\n// ============================================================================\n\n/**\n * Append-only audit trail for security pipeline decisions.\n * Events are bounded by MAX_EVENTS to prevent unbounded growth.\n */\n/**\n * Optional durable sink: receives every fully-formed event appended to the\n * trail, so security decisions can be mirrored to a persistent, hash-chained\n * store (see security/audit-bridge.ts). Default-off — when absent, the trail\n * behaves exactly as before (#3291).\n */\nexport type DurableAuditSink = (event: AuditEvent) => void;\n\nexport class AuditTrail {\n private events: AuditEvent[] = [];\n private nextId = 1;\n\n constructor(private readonly durableSink?: DurableAuditSink) {}\n\n /** Appends an event to the trail. Returns the assigned event ID. */\n append(event: Omit<AuditEvent, 'id' | 'timestamp'>): string {\n const id = `audit-${String(this.nextId++)}`;\n const fullEvent = {\n ...event,\n id,\n timestamp: getTimeProvider().nowIso(),\n } as AuditEvent;\n\n this.events.push(fullEvent);\n this.enforceLimit();\n\n // Mirror to the durable store when wired (#3291). Best-effort: a sink\n // failure must never break the in-memory security pipeline.\n if (this.durableSink !== undefined) {\n try {\n this.durableSink(fullEvent);\n } catch {\n // Sink implementations already swallow+log; this is belt-and-suspenders.\n }\n }\n\n return id;\n }\n\n /** Queries events matching the given filter. */\n query(filter: AuditQuery = {}): readonly AuditEvent[] {\n let results = this.events as readonly AuditEvent[];\n\n if (filter.type !== undefined) {\n results = results.filter((e) => e.type === filter.type);\n }\n\n if (filter.since !== undefined) {\n results = filterSince(results, filter.since);\n }\n\n if (filter.until !== undefined) {\n results = filterUntil(results, filter.until);\n }\n\n if (filter.trustTier !== undefined) {\n results = filterByTrustTier(results, filter.trustTier);\n }\n\n if (filter.actionType !== undefined) {\n results = filterByActionType(results, filter.actionType);\n }\n\n if (filter.actor !== undefined) {\n results = filterByActor(results, filter.actor);\n }\n\n if (filter.violationRule !== undefined) {\n results = filterByViolationRule(results, filter.violationRule);\n }\n\n const limit = filter.limit ?? results.length;\n return results.slice(-limit);\n }\n\n /** Returns the total number of events. */\n get size(): number {\n return this.events.length;\n }\n\n /** Clears all events. */\n clear(): void {\n this.events = [];\n }\n\n /** Enforces MAX_EVENTS bound. */\n private enforceLimit(): void {\n if (this.events.length > MAX_EVENTS) {\n this.events = this.events.slice(-MAX_EVENTS);\n }\n }\n}\n\n// ============================================================================\n// Filter Helpers\n// ============================================================================\n\nfunction filterSince(events: readonly AuditEvent[], since: string): readonly AuditEvent[] {\n const sinceTime = new Date(since).getTime();\n return events.filter((e) => new Date(e.timestamp).getTime() >= sinceTime);\n}\n\nfunction filterUntil(events: readonly AuditEvent[], until: string): readonly AuditEvent[] {\n const untilTime = new Date(until).getTime();\n return events.filter((e) => new Date(e.timestamp).getTime() <= untilTime);\n}\n\nfunction filterByTrustTier(events: readonly AuditEvent[], tier: TrustTier): readonly AuditEvent[] {\n return events.filter((e) => {\n if (e.type === 'trust_classification') return e.assignedTier === tier;\n if (e.type === 'policy_gate') return e.inputTrustTier === tier;\n if (e.type === 'reputation') return e.effectiveTier === tier;\n return true;\n });\n}\n\n/**\n * Narrow to events carrying the given `actionType` (#3197). Only PolicyGate and\n * Corroboration events have one; all others are excluded.\n */\nfunction filterByActionType(\n events: readonly AuditEvent[],\n actionType: AgentActionType\n): readonly AuditEvent[] {\n return events.filter(\n (e) => (e.type === 'policy_gate' || e.type === 'corroboration') && e.actionType === actionType\n );\n}\n\n/**\n * Narrow to events for the given actor (#3197), matched on `username`. Only\n * Trust-classification and Reputation events carry a username; others are\n * excluded so an actor filter never returns unrelated rows.\n */\nfunction filterByActor(events: readonly AuditEvent[], actor: string): readonly AuditEvent[] {\n return events.filter(\n (e) => (e.type === 'trust_classification' || e.type === 'reputation') && e.username === actor\n );\n}\n\n/**\n * Narrow to PolicyGate events whose `violationRules` include the given rule\n * name (#3197) — the security post-mortem \"who tripped rule X\" query.\n */\nfunction filterByViolationRule(events: readonly AuditEvent[], rule: string): readonly AuditEvent[] {\n return events.filter((e) => e.type === 'policy_gate' && e.violationRules.includes(rule));\n}\n\n// ============================================================================\n// Convenience Emitters\n// ============================================================================\n\n/**\n * Records a trust classification decision.\n */\nexport function emitTrustEvent(\n trail: AuditTrail,\n data: Omit<TrustClassificationEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'trust_classification',\n component: 'trust-classifier',\n ...data,\n });\n}\n\n/**\n * Records a policy gate evaluation.\n */\nexport function emitPolicyEvent(\n trail: AuditTrail,\n data: Omit<PolicyGateEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'policy_gate',\n component: 'policy-gate',\n ...data,\n });\n}\n\n/**\n * Records a PIPELINE-policy gate decision (#3710) — the dev-pipeline\n * consensus→execute seam. Distinct from {@link emitPolicyEvent} (the security\n * policy-gate path with an `AgentAction`): this carries `mode`/`ruleIds`/\n * `stageType` so the durable record distinguishes soak(warn) from enforce(block)\n * and is usable by the tune/readiness loop. ONE append per call.\n */\nexport function emitPipelinePolicyEvent(\n trail: AuditTrail,\n data: Omit<PolicyGateEvent, 'id' | 'timestamp' | 'type' | 'component' | 'actionType'>\n): string {\n return trail.append({\n type: 'policy_gate',\n component: 'pipeline-policy-evaluator',\n ...data,\n });\n}\n\n/** The pipeline-policy would-block rate over a window (#3727). */\nexport interface PolicyWouldBlockRate {\n /** Total pipeline-policy evaluations (the denominator — summary records). */\n readonly evaluations: number;\n /** Evaluations that had ≥1 violation (what enforce mode WOULD block). */\n readonly wouldBlock: number;\n /** `wouldBlock / evaluations`; 0 when there are no evaluations. */\n readonly rate: number;\n}\n\n/**\n * Compute the pipeline-policy would-block RATE from durable audit events (#3727)\n * — the read-side of the per-evaluation summary records, and the signal the\n * #3769-enforce soak-readiness gate needs. Denominator = per-evaluation SUMMARY\n * records (`recordKind === 'summary'`); numerator = summaries with\n * `violationCount > 0` (the would-block fraction, independent of warn/block mode).\n * Per-violation records (`recordKind === 'violation'`) are intentionally NOT\n * counted — counting them would double-count and break the denominator.\n */\nexport function computePolicyWouldBlockRate(events: readonly AuditEvent[]): PolicyWouldBlockRate {\n let evaluations = 0;\n let wouldBlock = 0;\n for (const e of events) {\n if (e.type !== 'policy_gate' || e.recordKind !== 'summary') continue;\n evaluations += 1;\n if ((e.violationCount ?? 0) > 0) wouldBlock += 1;\n }\n return { evaluations, wouldBlock, rate: evaluations > 0 ? wouldBlock / evaluations : 0 };\n}\n\n/**\n * Records a corroboration validation.\n */\nexport function emitCorroborationEvent(\n trail: AuditTrail,\n data: Omit<CorroborationEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'corroboration',\n component: 'corroboration-validator',\n ...data,\n });\n}\n\n/**\n * Records a reputation assessment.\n */\nexport function emitReputationEvent(\n trail: AuditTrail,\n data: Omit<ReputationEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'reputation',\n component: 'reputation-model',\n ...data,\n });\n}\n\n/**\n * Records an input sanitization result.\n */\nexport function emitSanitizationEvent(\n trail: AuditTrail,\n data: Omit<SanitizationEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'sanitization',\n component: 'input-sanitizer',\n ...data,\n });\n}\n\n/**\n * Records a graph execution lifecycle event.\n */\nexport function emitGraphExecutionEvent(\n trail: AuditTrail,\n data: Omit<GraphExecutionAuditEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'graph_execution',\n component: 'graph-executor',\n ...data,\n });\n}\n\n/**\n * Records a ClawGuard AUDIT-mode violation (#4097) — a policy-violating tool\n * call that was log-and-allowed because the policy is in `audit` mode. ONE\n * append per call; mirrors to the durable sink when the trail is wired.\n */\nexport function emitClawGuardViolation(\n trail: AuditTrail,\n data: Omit<ClawGuardViolationEvent, 'id' | 'timestamp' | 'type' | 'component'>\n): string {\n return trail.append({\n type: 'clawguard_violation',\n component: 'clawguard-audit',\n ...data,\n });\n}\n\n/**\n * Creates an onEvent callback that bridges graph events to the audit trail.\n * Pass the returned function as `onEvent` in GraphExecuteOptions.\n *\n * @example\n * const trail = createAuditTrail();\n * await executeGraph(graph, inputs, { onEvent: createGraphAuditBridge(trail) });\n */\nexport function createGraphAuditBridge(\n trail: AuditTrail\n): (event: { readonly type: string; readonly [key: string]: unknown }) => void {\n return (event) => {\n const nodeId = typeof event['nodeId'] === 'string' ? event['nodeId'] : undefined;\n const stepNumber = typeof event['stepNumber'] === 'number' ? event['stepNumber'] : 0;\n emitGraphExecutionEvent(trail, {\n graphEvent: event.type,\n ...(nodeId !== undefined ? { nodeId } : {}),\n stepNumber,\n detail: formatGraphEventDetail(event),\n });\n };\n}\n\n/** Formats a brief detail string from a graph event. */\nfunction formatGraphEventDetail(event: {\n readonly type: string;\n readonly [key: string]: unknown;\n}): string {\n switch (event.type) {\n case 'node_started':\n return `Node ${String(event['nodeId'])} starting`;\n case 'node_completed':\n return `Node ${String(event['nodeId'])} completed in ${String(event['durationMs'])}ms`;\n case 'node_error':\n return `Node ${String(event['nodeId'])} failed: ${String(event['error'])}`;\n case 'state_updated':\n return `State updated: ${String(event['updatedKeys'])}`;\n case 'step_completed':\n return `Step ${String(event['stepNumber'])}: ${String(event['nodesExecuted'])} nodes`;\n case 'execution_complete':\n return `Complete: ${String(event['totalSteps'])} steps, ${String(event['durationMs'])}ms`;\n default:\n return event.type;\n }\n}\n\n/**\n * Creates a new AuditTrail instance. Pass a {@link DurableAuditSink} (e.g. from\n * `createDurableAuditSink(auditLogger)`) to mirror appended security decisions\n * to a durable, hash-chained store (#3291). Default: in-memory only.\n */\nexport function createAuditTrail(durableSink?: DurableAuditSink): AuditTrail {\n return new AuditTrail(durableSink);\n}\n"],"m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