@axtary/policy 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -2
- package/dist/acs.d.ts +103 -0
- package/dist/acs.d.ts.map +1 -0
- package/dist/acs.js +207 -0
- package/dist/acs.js.map +1 -0
- package/dist/index.d.ts +208 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1033 -162
- package/dist/index.js.map +1 -1
- package/dist/parity.d.ts +150 -0
- package/dist/parity.d.ts.map +1 -0
- package/dist/parity.js +348 -0
- package/dist/parity.js.map +1 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -12,9 +12,23 @@ npm install @axtary/policy
|
|
|
12
12
|
|
|
13
13
|
- Evaluates normalized Axtary actions against a local policy config.
|
|
14
14
|
- Returns `allow`, `deny`, or `step_up` decisions.
|
|
15
|
-
-
|
|
15
|
+
- Supports named multi-rule policies with wildcard tool/resource/actor matchers,
|
|
16
|
+
deny-overrides precedence, and default-deny.
|
|
17
|
+
- Attaches enforceable obligations: narrowed TTL, approver roles, blocked paths,
|
|
18
|
+
UTC time windows, and per-process rate windows.
|
|
19
|
+
- Ships guardrails for GitHub PRs/reviews/checks and content reads/writes,
|
|
20
|
+
Slack posts (channel allowlists + external-recipient step-up), Linear/Jira
|
|
21
|
+
issue actions, Postgres scoped SELECT analysis (write statements denied
|
|
22
|
+
before execution), Google Drive file reads, and MCP tool calls pinned by
|
|
23
|
+
definition hash (same-name definition drift denies).
|
|
16
24
|
- Maps the same normalized action into Cedar-style principal/action/resource/context.
|
|
17
|
-
- Exposes OPA/Rego-compatible input JSON
|
|
25
|
+
- Exposes OPA/Rego-compatible input JSON, with an executable `--parity` harness
|
|
26
|
+
that fails on any cross-engine disagreement.
|
|
27
|
+
- Exposes a thin Agent Control-style `pre_tool_call` / `post_tool_call` shim
|
|
28
|
+
that maps tool-call snapshots into normalized Axtary actions and fails closed
|
|
29
|
+
on malformed envelopes.
|
|
30
|
+
- Emits an offline AgentCore Cedar-shaped Gateway authorization request mapping
|
|
31
|
+
for parity fixtures. This is an export shape, not a live AWS deployment.
|
|
18
32
|
|
|
19
33
|
## Quickstart
|
|
20
34
|
|
|
@@ -32,8 +46,76 @@ console.log(decision.decision, decision.reasons);
|
|
|
32
46
|
console.log(explainPolicyDecision(decision).summary);
|
|
33
47
|
```
|
|
34
48
|
|
|
49
|
+
## Multi-rule policies
|
|
50
|
+
|
|
51
|
+
`axtary.yml` may define a top-level `policies:` block. When `rules` is empty,
|
|
52
|
+
the existing provider guardrail preset remains active for compatibility.
|
|
53
|
+
When one or more rules are present, only the explicit rules apply and unmatched
|
|
54
|
+
actions deny.
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
policies:
|
|
58
|
+
defaultDecision: deny
|
|
59
|
+
rules:
|
|
60
|
+
- id: review-repo-writes
|
|
61
|
+
match:
|
|
62
|
+
tools: github.contents.write
|
|
63
|
+
resources: repo:company/*
|
|
64
|
+
actors:
|
|
65
|
+
runtimes: [codex-*, claude-*]
|
|
66
|
+
effect: step_up
|
|
67
|
+
reason: repository_write_requires_review
|
|
68
|
+
obligations:
|
|
69
|
+
expiresInSeconds: 60
|
|
70
|
+
requiredApproverRoles: [security-reviewer]
|
|
71
|
+
blockedPathPrefixes: [.env, secrets/]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
All matching rules are evaluated. `deny` outranks `step_up`, which outranks
|
|
75
|
+
`allow`; obligations are merged toward the narrower result. Use
|
|
76
|
+
`simulatePolicy` for the complete match/mismatch trace.
|
|
77
|
+
|
|
35
78
|
## Design Notes
|
|
36
79
|
|
|
37
80
|
The normalized action schema from `@axtary/actionpass` remains the source of truth. Policy evaluation is deterministic and fail-closed for unknown protected tools.
|
|
38
81
|
|
|
82
|
+
## Deterministic provenance guard
|
|
83
|
+
|
|
84
|
+
Set `policy.provenance.enabled: true` to require authority-stamped lineage for
|
|
85
|
+
covered outbound/content fields. Missing or unknown lineage denies with
|
|
86
|
+
`provenance_unknown_egress`. Untrusted document/tool-output lineage steps up
|
|
87
|
+
with `provenance_untrusted_egress` by default, or can be configured to deny.
|
|
88
|
+
The guard runs after the underlying native, Cedar, or Rego decision and can
|
|
89
|
+
only preserve or restrict it—never turn a deny into an allow.
|
|
90
|
+
|
|
91
|
+
Coverage is intentionally explicit (`PROVENANCE_COVERAGE`) rather than generic
|
|
92
|
+
DLP or semantic prompt-injection detection.
|
|
93
|
+
|
|
39
94
|
This package stays format-agnostic. `@axtary/config` loads YAML and passes the parsed policy object into this evaluator so the same deterministic decision path can be used by tests, the local proxy, and future MCP wrappers.
|
|
95
|
+
|
|
96
|
+
## Standards adapters
|
|
97
|
+
|
|
98
|
+
The ACS shim lives at `@axtary/policy/acs`:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import {
|
|
102
|
+
createAxtaryAcsManifest,
|
|
103
|
+
evaluateAcsIntervention,
|
|
104
|
+
} from "@axtary/policy/acs";
|
|
105
|
+
|
|
106
|
+
const manifest = createAxtaryAcsManifest();
|
|
107
|
+
const result = evaluateAcsIntervention({
|
|
108
|
+
manifest,
|
|
109
|
+
interventionPoint: "pre_tool_call",
|
|
110
|
+
snapshot,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`allow` maps to `allow`, `step_up` maps to `escalate`, and `deny` maps to
|
|
115
|
+
`deny`. Invalid manifests or malformed snapshots return deny-style
|
|
116
|
+
`runtime_error:*` reasons.
|
|
117
|
+
|
|
118
|
+
AgentCore/Cedar export helpers live at `@axtary/policy/parity` and are also
|
|
119
|
+
included in `axtary test-policy --parity --json`. They emit Cedar-shaped
|
|
120
|
+
Gateway requests with Axtary action and payload hashes, but do not claim live
|
|
121
|
+
AWS AgentCore enforcement.
|
package/dist/acs.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type JsonValue, type NormalizedAction, type PolicyDecision } from "@axtary/actionpass";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type PolicyConfigPatch } from "./index.js";
|
|
4
|
+
export declare const AXTARY_ACS_MANIFEST_VERSION = "axtary.acs_manifest.v0";
|
|
5
|
+
export declare const AXTARY_ACS_SNAPSHOT_VERSION = "axtary.acs_snapshot.v0";
|
|
6
|
+
export type AcsInterventionPoint = "pre_tool_call" | "post_tool_call";
|
|
7
|
+
export type AcsVerdict = "allow" | "warn" | "deny" | "escalate" | "transform";
|
|
8
|
+
export declare const AcsPolicySchema: z.ZodObject<{
|
|
9
|
+
type: z.ZodEnum<{
|
|
10
|
+
custom: "custom";
|
|
11
|
+
cedar: "cedar";
|
|
12
|
+
rego: "rego";
|
|
13
|
+
test: "test";
|
|
14
|
+
}>;
|
|
15
|
+
adapter: z.ZodOptional<z.ZodString>;
|
|
16
|
+
source: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
export declare const AcsInterventionConfigSchema: z.ZodObject<{
|
|
19
|
+
policy: z.ZodString;
|
|
20
|
+
policy_target: z.ZodString;
|
|
21
|
+
policy_target_kind: z.ZodOptional<z.ZodString>;
|
|
22
|
+
tool_name_from: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export declare const AcsManifestSchema: z.ZodObject<{
|
|
25
|
+
agent_control_specification_version: z.ZodString;
|
|
26
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
27
|
+
policies: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
28
|
+
type: z.ZodEnum<{
|
|
29
|
+
custom: "custom";
|
|
30
|
+
cedar: "cedar";
|
|
31
|
+
rego: "rego";
|
|
32
|
+
test: "test";
|
|
33
|
+
}>;
|
|
34
|
+
adapter: z.ZodOptional<z.ZodString>;
|
|
35
|
+
source: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
intervention_points: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
38
|
+
policy: z.ZodString;
|
|
39
|
+
policy_target: z.ZodString;
|
|
40
|
+
policy_target_kind: z.ZodOptional<z.ZodString>;
|
|
41
|
+
tool_name_from: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, z.core.$strict>>;
|
|
43
|
+
tools: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>>;
|
|
44
|
+
annotators: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>>;
|
|
45
|
+
approval: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
export type AcsManifest = z.infer<typeof AcsManifestSchema>;
|
|
48
|
+
export declare const AcsToolCallSnapshotSchema: z.ZodObject<{
|
|
49
|
+
schemaVersion: z.ZodOptional<z.ZodLiteral<"axtary.acs_snapshot.v0">>;
|
|
50
|
+
actor: z.ZodObject<{
|
|
51
|
+
agentId: z.ZodString;
|
|
52
|
+
humanOwner: z.ZodString;
|
|
53
|
+
runtime: z.ZodString;
|
|
54
|
+
tenant: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
intent: z.ZodObject<{
|
|
57
|
+
taskId: z.ZodString;
|
|
58
|
+
declaredGoal: z.ZodString;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
tool_call: z.ZodObject<{
|
|
61
|
+
tool: z.ZodString;
|
|
62
|
+
resource: z.ZodString;
|
|
63
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
64
|
+
toolDefinition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
tool_result: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
status: z.ZodEnum<{
|
|
68
|
+
error: "error";
|
|
69
|
+
ok: "ok";
|
|
70
|
+
}>;
|
|
71
|
+
outputHash: z.ZodOptional<z.ZodString>;
|
|
72
|
+
errorReason: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
}, z.core.$strict>;
|
|
75
|
+
export type AcsToolCallSnapshot = z.infer<typeof AcsToolCallSnapshotSchema>;
|
|
76
|
+
export type AcsEvaluationResult = {
|
|
77
|
+
schemaVersion: "axtary.acs_evaluation.v0";
|
|
78
|
+
interventionPoint: AcsInterventionPoint;
|
|
79
|
+
verdict: AcsVerdict;
|
|
80
|
+
reason: string;
|
|
81
|
+
reasons: string[];
|
|
82
|
+
policyTargetKind: string;
|
|
83
|
+
normalizedAction?: NormalizedAction;
|
|
84
|
+
policyDecision?: PolicyDecision;
|
|
85
|
+
evidence: {
|
|
86
|
+
adapter: "axtary.policy";
|
|
87
|
+
actionHash?: string;
|
|
88
|
+
payloadHash?: string;
|
|
89
|
+
resultHash?: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export declare function createAxtaryAcsManifest(input?: {
|
|
93
|
+
version?: string;
|
|
94
|
+
name?: string;
|
|
95
|
+
}): AcsManifest;
|
|
96
|
+
export declare function actionFromAcsToolCallSnapshot(snapshotInput: unknown): NormalizedAction;
|
|
97
|
+
export declare function evaluateAcsIntervention(input: {
|
|
98
|
+
manifest: unknown;
|
|
99
|
+
interventionPoint: AcsInterventionPoint;
|
|
100
|
+
snapshot: unknown;
|
|
101
|
+
config?: PolicyConfigPatch;
|
|
102
|
+
}): AcsEvaluationResult;
|
|
103
|
+
//# sourceMappingURL=acs.d.ts.map
|
|
@@ -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IAChC,QAAQ,EAAE;QACR,OAAO,EAAE,eAAe,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,KAAK,GAAE;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACV,GAAG,WAAW,CA8BnB;AAED,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,OAAO,GACrB,gBAAgB,CAelB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,oBAAoB,CAAC;IACxC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B,GAAG,mBAAmB,CA+CtB"}
|
package/dist/acs.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { hashAction, hashPayload, NormalizedActionSchema, } from "@axtary/actionpass";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { evaluatePolicy, } from "./index.js";
|
|
4
|
+
export const AXTARY_ACS_MANIFEST_VERSION = "axtary.acs_manifest.v0";
|
|
5
|
+
export const AXTARY_ACS_SNAPSHOT_VERSION = "axtary.acs_snapshot.v0";
|
|
6
|
+
const JsonValueSchema = z.lazy(() => z.union([
|
|
7
|
+
z.string(),
|
|
8
|
+
z.number(),
|
|
9
|
+
z.boolean(),
|
|
10
|
+
z.null(),
|
|
11
|
+
z.array(JsonValueSchema),
|
|
12
|
+
z.record(z.string(), JsonValueSchema),
|
|
13
|
+
]));
|
|
14
|
+
export const AcsPolicySchema = z
|
|
15
|
+
.object({
|
|
16
|
+
type: z.enum(["custom", "cedar", "rego", "test"]),
|
|
17
|
+
adapter: z.string().min(1).optional(),
|
|
18
|
+
source: z.string().min(1).optional(),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
export const AcsInterventionConfigSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
policy: z.string().min(1),
|
|
24
|
+
policy_target: z.string().min(1),
|
|
25
|
+
policy_target_kind: z.string().min(1).optional(),
|
|
26
|
+
tool_name_from: z.string().min(1).optional(),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
export const AcsManifestSchema = z
|
|
30
|
+
.object({
|
|
31
|
+
agent_control_specification_version: z.string().min(1),
|
|
32
|
+
metadata: z.record(z.string(), JsonValueSchema).optional(),
|
|
33
|
+
policies: z.record(z.string(), AcsPolicySchema),
|
|
34
|
+
intervention_points: z.record(z.string(), AcsInterventionConfigSchema),
|
|
35
|
+
tools: z.record(z.string(), z.record(z.string(), JsonValueSchema)).optional(),
|
|
36
|
+
annotators: z.record(z.string(), z.record(z.string(), JsonValueSchema)).optional(),
|
|
37
|
+
approval: z.record(z.string(), JsonValueSchema).optional(),
|
|
38
|
+
})
|
|
39
|
+
.strict()
|
|
40
|
+
.superRefine((manifest, ctx) => {
|
|
41
|
+
if (Object.keys(manifest.policies).length === 0) {
|
|
42
|
+
ctx.addIssue({
|
|
43
|
+
code: "custom",
|
|
44
|
+
message: "policies_required",
|
|
45
|
+
path: ["policies"],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (Object.keys(manifest.intervention_points).length === 0) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: "custom",
|
|
51
|
+
message: "intervention_points_required",
|
|
52
|
+
path: ["intervention_points"],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for (const [name, config] of Object.entries(manifest.intervention_points)) {
|
|
56
|
+
if (!["pre_tool_call", "post_tool_call"].includes(name)) {
|
|
57
|
+
ctx.addIssue({
|
|
58
|
+
code: "custom",
|
|
59
|
+
message: `unsupported_intervention_point:${name}`,
|
|
60
|
+
path: ["intervention_points", name],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (!manifest.policies[config.policy]) {
|
|
64
|
+
ctx.addIssue({
|
|
65
|
+
code: "custom",
|
|
66
|
+
message: `undefined_policy:${config.policy}`,
|
|
67
|
+
path: ["intervention_points", name, "policy"],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
export const AcsToolCallSnapshotSchema = z
|
|
73
|
+
.object({
|
|
74
|
+
schemaVersion: z.literal(AXTARY_ACS_SNAPSHOT_VERSION).optional(),
|
|
75
|
+
actor: z.object({
|
|
76
|
+
agentId: z.string().min(1),
|
|
77
|
+
humanOwner: z.string().min(1),
|
|
78
|
+
runtime: z.string().min(1),
|
|
79
|
+
tenant: z.string().min(1).optional(),
|
|
80
|
+
}),
|
|
81
|
+
intent: z.object({
|
|
82
|
+
taskId: z.string().min(1),
|
|
83
|
+
declaredGoal: z.string().min(1),
|
|
84
|
+
}),
|
|
85
|
+
tool_call: z.object({
|
|
86
|
+
tool: z.string().min(1),
|
|
87
|
+
resource: z.string().min(1),
|
|
88
|
+
arguments: z.record(z.string(), JsonValueSchema).default({}),
|
|
89
|
+
toolDefinition: z.record(z.string(), JsonValueSchema).optional(),
|
|
90
|
+
}),
|
|
91
|
+
tool_result: z
|
|
92
|
+
.object({
|
|
93
|
+
status: z.enum(["ok", "error"]),
|
|
94
|
+
outputHash: z.string().min(1).optional(),
|
|
95
|
+
errorReason: z.string().min(1).optional(),
|
|
96
|
+
})
|
|
97
|
+
.optional(),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
export function createAxtaryAcsManifest(input = {}) {
|
|
101
|
+
return AcsManifestSchema.parse({
|
|
102
|
+
agent_control_specification_version: input.version ?? "0.3.1-beta",
|
|
103
|
+
metadata: {
|
|
104
|
+
schemaVersion: AXTARY_ACS_MANIFEST_VERSION,
|
|
105
|
+
name: input.name ?? "Axtary ActionPass enforcement",
|
|
106
|
+
note: "Thin ACS shim: pre_tool_call maps into Axtary normalized actions; the host/proxy enforces the returned verdict.",
|
|
107
|
+
},
|
|
108
|
+
policies: {
|
|
109
|
+
axtary_actionpass: {
|
|
110
|
+
type: "custom",
|
|
111
|
+
adapter: "axtary.policy",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
intervention_points: {
|
|
115
|
+
pre_tool_call: {
|
|
116
|
+
policy: "axtary_actionpass",
|
|
117
|
+
policy_target: "$.tool_call",
|
|
118
|
+
policy_target_kind: "axtary.normalized_action",
|
|
119
|
+
tool_name_from: "$.tool_call.tool",
|
|
120
|
+
},
|
|
121
|
+
post_tool_call: {
|
|
122
|
+
policy: "axtary_actionpass",
|
|
123
|
+
policy_target: "$.tool_result",
|
|
124
|
+
policy_target_kind: "axtary.tool_result",
|
|
125
|
+
tool_name_from: "$.tool_call.tool",
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
export function actionFromAcsToolCallSnapshot(snapshotInput) {
|
|
131
|
+
const snapshot = AcsToolCallSnapshotSchema.parse(snapshotInput);
|
|
132
|
+
return NormalizedActionSchema.parse({
|
|
133
|
+
schemaVersion: "axtary.action.v0",
|
|
134
|
+
actor: snapshot.actor,
|
|
135
|
+
intent: snapshot.intent,
|
|
136
|
+
capability: {
|
|
137
|
+
tool: snapshot.tool_call.tool,
|
|
138
|
+
resource: snapshot.tool_call.resource,
|
|
139
|
+
payload: snapshot.tool_call.arguments,
|
|
140
|
+
},
|
|
141
|
+
...(snapshot.tool_call.toolDefinition
|
|
142
|
+
? { toolDefinition: snapshot.tool_call.toolDefinition }
|
|
143
|
+
: {}),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export function evaluateAcsIntervention(input) {
|
|
147
|
+
const manifest = AcsManifestSchema.safeParse(input.manifest);
|
|
148
|
+
if (!manifest.success) {
|
|
149
|
+
return acsRuntimeDeny(input.interventionPoint, "runtime_error:manifest_invalid");
|
|
150
|
+
}
|
|
151
|
+
const point = manifest.data.intervention_points[input.interventionPoint];
|
|
152
|
+
if (!point) {
|
|
153
|
+
return acsRuntimeDeny(input.interventionPoint, "runtime_error:intervention_point_unknown");
|
|
154
|
+
}
|
|
155
|
+
let action;
|
|
156
|
+
try {
|
|
157
|
+
action = actionFromAcsToolCallSnapshot(input.snapshot);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return acsRuntimeDeny(input.interventionPoint, "runtime_error:request_invalid");
|
|
161
|
+
}
|
|
162
|
+
const decision = evaluatePolicy(action, input.config);
|
|
163
|
+
const payloadHash = hashPayload(action.capability.payload);
|
|
164
|
+
const verdict = decisionToAcsVerdict(decision.decision);
|
|
165
|
+
const primaryReason = decision.reasons[0] ?? "policy_default_deny";
|
|
166
|
+
const snapshot = AcsToolCallSnapshotSchema.parse(input.snapshot);
|
|
167
|
+
return {
|
|
168
|
+
schemaVersion: "axtary.acs_evaluation.v0",
|
|
169
|
+
interventionPoint: input.interventionPoint,
|
|
170
|
+
verdict,
|
|
171
|
+
reason: primaryReason,
|
|
172
|
+
reasons: decision.reasons,
|
|
173
|
+
policyTargetKind: point.policy_target_kind ??
|
|
174
|
+
(input.interventionPoint === "pre_tool_call"
|
|
175
|
+
? "axtary.normalized_action"
|
|
176
|
+
: "axtary.tool_result"),
|
|
177
|
+
normalizedAction: action,
|
|
178
|
+
policyDecision: decision,
|
|
179
|
+
evidence: {
|
|
180
|
+
adapter: "axtary.policy",
|
|
181
|
+
actionHash: hashAction(action),
|
|
182
|
+
payloadHash,
|
|
183
|
+
resultHash: snapshot.tool_result?.outputHash,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function decisionToAcsVerdict(decision) {
|
|
188
|
+
if (decision === "allow")
|
|
189
|
+
return "allow";
|
|
190
|
+
if (decision === "step_up")
|
|
191
|
+
return "escalate";
|
|
192
|
+
return "deny";
|
|
193
|
+
}
|
|
194
|
+
function acsRuntimeDeny(interventionPoint, reason) {
|
|
195
|
+
return {
|
|
196
|
+
schemaVersion: "axtary.acs_evaluation.v0",
|
|
197
|
+
interventionPoint,
|
|
198
|
+
verdict: "deny",
|
|
199
|
+
reason,
|
|
200
|
+
reasons: [reason],
|
|
201
|
+
policyTargetKind: "axtary.runtime_error",
|
|
202
|
+
evidence: {
|
|
203
|
+
adapter: "axtary.policy",
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=acs.js.map
|
package/dist/acs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acs.js","sourceRoot":"","sources":["../src/acs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,sBAAsB,GAIvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AAKpE,MAAM,eAAe,GAAyB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACxD,CAAC,CAAC,KAAK,CAAC;IACN,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,OAAO,EAAE;IACX,CAAC,CAAC,IAAI,EAAE;IACR,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;IACxB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC;CACtC,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC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