@absolutejs/agent-trust 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AbsoluteJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @absolutejs/agent-trust
2
+
3
+ Provider-neutral provenance and taint tracking for agents. Every value carries
4
+ its purpose, authority, source, digest/proof, taints, parent digests, and
5
+ evidence-bearing transformations.
6
+
7
+ The central security rule is structural: external content is data, never an
8
+ instruction merely because it contains imperative language. `compileAgentContext`
9
+ returns separate instruction and data segments instead of interpolating tool,
10
+ web, file, or memory content into a privileged prompt. Sink policies then fail
11
+ closed before instructions or actions cross a trust boundary.
12
+
13
+ Taints propagate through derived model output. A sanitizer may remove named
14
+ taints only while recording evidence and a new digest; there is no implicit
15
+ "trusted because the model said so" conversion. Proof verification is injected,
16
+ so signed discovery descriptors, DSSE, JWTs, or provider KMS can share the same
17
+ contract.
@@ -0,0 +1,18 @@
1
+ import type { TrustedAgentValue } from "./types";
2
+ export type AgentContextSegment = {
3
+ channel: "instructions" | "data";
4
+ content: string;
5
+ metadata: {
6
+ authority: string;
7
+ source: string;
8
+ digest?: string;
9
+ taints: string[];
10
+ };
11
+ };
12
+ /**
13
+ * Produces structured segments so providers can map trusted instructions and
14
+ * untrusted data to separate message/content channels. It never concatenates
15
+ * external data into an instruction string.
16
+ */
17
+ export declare const compileAgentContext: (values: readonly TrustedAgentValue[]) => AgentContextSegment[];
18
+ export declare const detectPromptInjection: <Value>(input: TrustedAgentValue<Value>, detector: (value: Value) => boolean | Promise<boolean>) => Promise<TrustedAgentValue<Value>>;
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./trust";
3
+ export * from "./context";
package/dist/index.js ADDED
@@ -0,0 +1,111 @@
1
+ // @bun
2
+ // src/trust.ts
3
+ var unique = (values) => [...new Set(values)];
4
+ var encoder = new TextEncoder;
5
+ var stable = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
6
+ var digestAgentValue = async (value) => `sha256:${Buffer.from(await crypto.subtle.digest("SHA-256", encoder.encode(stable(value)))).toString("hex")}`;
7
+ var trustAgentValue = (value, labels) => ({
8
+ value,
9
+ purpose: labels.purpose,
10
+ authority: labels.authority,
11
+ provenance: structuredClone(labels.provenance),
12
+ taints: unique(labels.taints ?? []),
13
+ transformations: []
14
+ });
15
+ var deriveAgentValue = (value, parents, input) => ({
16
+ value,
17
+ purpose: input.purpose,
18
+ authority: input.authority ?? (parents.every((parent) => parent.authority === parents[0]?.authority) ? parents[0]?.authority ?? "model" : "model"),
19
+ taints: unique(parents.flatMap((parent) => parent.taints).concat("model-generated")),
20
+ provenance: {
21
+ ...input.provenance,
22
+ parentDigests: parents.flatMap((parent) => parent.provenance.digest ? [parent.provenance.digest] : [])
23
+ },
24
+ transformations: [
25
+ ...parents.flatMap((parent) => parent.transformations),
26
+ input.transformation
27
+ ]
28
+ });
29
+ var withAgentValueDigest = async (input) => ({
30
+ ...structuredClone(input),
31
+ provenance: {
32
+ ...input.provenance,
33
+ digest: await digestAgentValue(input.value)
34
+ }
35
+ });
36
+ var sanitizeAgentValue = async (input, sanitizer, at = new Date().toISOString()) => {
37
+ const result = await sanitizer.run(input.value);
38
+ if (result.evidence === undefined)
39
+ throw new Error("Sanitizer must return evidence");
40
+ return {
41
+ ...structuredClone(input),
42
+ value: result.value,
43
+ taints: input.taints.filter((taint) => !sanitizer.removes.includes(taint)),
44
+ transformations: [
45
+ ...input.transformations,
46
+ { id: sanitizer.id, at, evidence: result.evidence }
47
+ ],
48
+ provenance: {
49
+ ...input.provenance,
50
+ digest: await digestAgentValue(result.value),
51
+ parentDigests: unique([
52
+ ...input.provenance.parentDigests ?? [],
53
+ ...input.provenance.digest ? [input.provenance.digest] : []
54
+ ])
55
+ }
56
+ };
57
+ };
58
+ var enforceAgentTrustPolicy = async (input, policy, verifyProof) => {
59
+ if (!policy.allowedPurposes.includes(input.purpose))
60
+ throw new Error(`Purpose ${input.purpose} is denied at ${policy.sink}`);
61
+ if (policy.allowedAuthorities && !policy.allowedAuthorities.includes(input.authority))
62
+ throw new Error(`Authority ${input.authority} is denied at ${policy.sink}`);
63
+ const denied = input.taints.find((taint) => policy.deniedTaints?.includes(taint));
64
+ if (denied)
65
+ throw new Error(`Taint ${denied} is denied at ${policy.sink}`);
66
+ if (policy.requireDigest && !input.provenance.digest)
67
+ throw new Error(`A provenance digest is required at ${policy.sink}`);
68
+ if (policy.requireVerifiedProof && (!verifyProof || !await verifyProof(input.provenance)))
69
+ throw new Error(`Verified provenance is required at ${policy.sink}`);
70
+ };
71
+ var AGENT_INSTRUCTION_POLICY = {
72
+ sink: "agent.instructions",
73
+ allowedPurposes: ["instruction"],
74
+ allowedAuthorities: ["system", "developer", "user", "delegated"],
75
+ deniedTaints: ["external", "unverified", "prompt-injection-suspected"]
76
+ };
77
+ var AGENT_ACTION_POLICY = {
78
+ sink: "agent.actions",
79
+ allowedPurposes: ["data", "tool-output", "memory"],
80
+ deniedTaints: ["secret", "prompt-injection-suspected", "executable"],
81
+ requireDigest: true
82
+ };
83
+ // src/context.ts
84
+ var compileAgentContext = (values) => values.map((item) => ({
85
+ channel: item.purpose === "instruction" ? "instructions" : "data",
86
+ content: typeof item.value === "string" ? item.value : JSON.stringify(item.value),
87
+ metadata: {
88
+ authority: item.authority,
89
+ source: item.provenance.source,
90
+ digest: item.provenance.digest,
91
+ taints: [...item.taints]
92
+ }
93
+ }));
94
+ var detectPromptInjection = async (input, detector) => await detector(input.value) ? {
95
+ ...structuredClone(input),
96
+ taints: [
97
+ ...new Set([...input.taints, "prompt-injection-suspected"])
98
+ ]
99
+ } : structuredClone(input);
100
+ export {
101
+ withAgentValueDigest,
102
+ trustAgentValue,
103
+ sanitizeAgentValue,
104
+ enforceAgentTrustPolicy,
105
+ digestAgentValue,
106
+ detectPromptInjection,
107
+ deriveAgentValue,
108
+ compileAgentContext,
109
+ AGENT_INSTRUCTION_POLICY,
110
+ AGENT_ACTION_POLICY
111
+ };
@@ -0,0 +1 @@
1
+ export declare const manifest: import("@absolutejs/manifest").PackageManifest<unknown, never>;
@@ -0,0 +1,23 @@
1
+ // @bun
2
+ // src/manifest.ts
3
+ import { defineManifest } from "@absolutejs/manifest";
4
+ import { Type } from "@sinclair/typebox";
5
+ var manifest = defineManifest()({
6
+ contract: 2,
7
+ identity: {
8
+ name: "@absolutejs/agent-trust",
9
+ category: "security",
10
+ tagline: "Keep agent instructions authoritative and external data untrusted.",
11
+ description: "Provider-neutral provenance envelopes, taint propagation, explicit instruction/data channels, evidence-bearing sanitizers, and fail-closed sink policies for AI agents.",
12
+ docsUrl: "https://github.com/absolutejs/agent-trust",
13
+ accent: "#f59e0b"
14
+ },
15
+ settings: Type.Object({}),
16
+ slots: {},
17
+ implements: [],
18
+ tools: {},
19
+ wiring: []
20
+ });
21
+ export {
22
+ manifest
23
+ };
@@ -0,0 +1,19 @@
1
+ {
2
+ "contract": 2,
3
+ "identity": {
4
+ "name": "@absolutejs/agent-trust",
5
+ "category": "security",
6
+ "tagline": "Keep agent instructions authoritative and external data untrusted.",
7
+ "description": "Provider-neutral provenance envelopes, taint propagation, explicit instruction/data channels, evidence-bearing sanitizers, and fail-closed sink policies for AI agents.",
8
+ "docsUrl": "https://github.com/absolutejs/agent-trust",
9
+ "accent": "#f59e0b"
10
+ },
11
+ "settings": {
12
+ "type": "object",
13
+ "properties": {}
14
+ },
15
+ "slots": {},
16
+ "implements": [],
17
+ "wiring": [],
18
+ "tools": {}
19
+ }
@@ -0,0 +1,33 @@
1
+ import type { AgentAuthority, AgentContentPurpose, AgentProofVerifier, AgentProvenance, AgentTaint, AgentTrustSinkPolicy, TrustedAgentValue } from "./types";
2
+ export declare const digestAgentValue: (value: unknown) => Promise<string>;
3
+ export declare const trustAgentValue: <Value>(value: Value, labels: {
4
+ purpose: AgentContentPurpose;
5
+ authority: AgentAuthority;
6
+ provenance: AgentProvenance;
7
+ taints?: AgentTaint[];
8
+ }) => TrustedAgentValue<Value>;
9
+ export declare const deriveAgentValue: <Value>(value: Value, parents: readonly TrustedAgentValue[], input: {
10
+ purpose: AgentContentPurpose;
11
+ authority?: AgentAuthority;
12
+ transformation: {
13
+ id: string;
14
+ at: string;
15
+ evidence?: unknown;
16
+ };
17
+ provenance: Omit<AgentProvenance, "parentDigests">;
18
+ }) => TrustedAgentValue<Value>;
19
+ export declare const withAgentValueDigest: <Value>(input: TrustedAgentValue<Value>) => Promise<TrustedAgentValue<Value>>;
20
+ export declare const sanitizeAgentValue: <Value>(input: TrustedAgentValue<Value>, sanitizer: {
21
+ id: string;
22
+ removes: AgentTaint[];
23
+ run(value: Value): Promise<{
24
+ value: Value;
25
+ evidence: unknown;
26
+ }> | {
27
+ value: Value;
28
+ evidence: unknown;
29
+ };
30
+ }, at?: string) => Promise<TrustedAgentValue<Value>>;
31
+ export declare const enforceAgentTrustPolicy: (input: TrustedAgentValue, policy: AgentTrustSinkPolicy, verifyProof?: AgentProofVerifier) => Promise<void>;
32
+ export declare const AGENT_INSTRUCTION_POLICY: AgentTrustSinkPolicy;
33
+ export declare const AGENT_ACTION_POLICY: AgentTrustSinkPolicy;
@@ -0,0 +1,33 @@
1
+ export type AgentAuthority = "system" | "developer" | "user" | "delegated" | "tool" | "external" | "model";
2
+ export type AgentContentPurpose = "instruction" | "data" | "tool-output" | "memory" | "credential";
3
+ export type AgentTaint = "external" | "user-controlled" | "model-generated" | "unverified" | "personal" | "secret" | "financial" | "executable" | "prompt-injection-suspected";
4
+ export type AgentProvenance = {
5
+ source: string;
6
+ sourceType: "user" | "agent" | "tool" | "web" | "file" | "memory" | "system";
7
+ producer?: string;
8
+ retrievedAt: string;
9
+ digest?: string;
10
+ parentDigests?: string[];
11
+ proof?: unknown;
12
+ };
13
+ export type TrustedAgentValue<Value = unknown> = {
14
+ value: Value;
15
+ purpose: AgentContentPurpose;
16
+ authority: AgentAuthority;
17
+ taints: AgentTaint[];
18
+ provenance: AgentProvenance;
19
+ transformations: Array<{
20
+ id: string;
21
+ at: string;
22
+ evidence?: unknown;
23
+ }>;
24
+ };
25
+ export type AgentTrustSinkPolicy = {
26
+ sink: string;
27
+ allowedPurposes: AgentContentPurpose[];
28
+ allowedAuthorities?: AgentAuthority[];
29
+ deniedTaints?: AgentTaint[];
30
+ requireDigest?: boolean;
31
+ requireVerifiedProof?: boolean;
32
+ };
33
+ export type AgentProofVerifier = (provenance: AgentProvenance) => boolean | Promise<boolean>;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@absolutejs/agent-trust",
3
+ "version": "0.1.0",
4
+ "description": "Provider-neutral provenance, taint propagation, instruction/data separation, and sink policy enforcement for AI agents.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/absolutejs/agent-trust.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "absolutejs": {
17
+ "manifestContract": 2
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./manifest": {
25
+ "types": "./dist/manifest.d.ts",
26
+ "import": "./dist/manifest.js"
27
+ },
28
+ "./manifest.json": "./dist/manifest.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "format": "prettier --write \"./**/*.{ts,json,md,yml}\"",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "bun test",
39
+ "build": "rm -rf dist && bun build src/index.ts src/manifest.ts --outdir dist --target=bun --external @absolutejs/manifest --external @sinclair/typebox && tsc -p tsconfig.build.json && absolute-manifest emit",
40
+ "check:package": "bun run typecheck && bun run test && bun run build"
41
+ },
42
+ "dependencies": {
43
+ "@absolutejs/manifest": "^0.2.0",
44
+ "@sinclair/typebox": "^0.34.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/bun": "^1.3.14",
48
+ "prettier": "3.5.3",
49
+ "typescript": "5.8.3"
50
+ }
51
+ }