@ai-pip/core 0.1.8 → 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/CHANGELOG.md +157 -2
- package/README.md +351 -11
- package/dist/AAL/constants.d.ts +15 -0
- package/dist/AAL/constants.d.ts.map +1 -0
- package/dist/AAL/constants.js +20 -0
- package/dist/AAL/constants.js.map +1 -0
- package/dist/AAL/index.d.ts +29 -0
- package/dist/AAL/index.d.ts.map +1 -0
- package/dist/AAL/index.js +30 -0
- package/dist/AAL/index.js.map +1 -0
- package/dist/AAL/lineage/buildAALLineage.d.ts +22 -0
- package/dist/AAL/lineage/buildAALLineage.d.ts.map +1 -0
- package/dist/AAL/lineage/buildAALLineage.js +26 -0
- package/dist/AAL/lineage/buildAALLineage.js.map +1 -0
- package/dist/AAL/lineage/index.d.ts +5 -0
- package/dist/AAL/lineage/index.d.ts.map +1 -0
- package/dist/AAL/lineage/index.js +5 -0
- package/dist/AAL/lineage/index.js.map +1 -0
- package/dist/AAL/process/applyRemovalPlan.d.ts +21 -0
- package/dist/AAL/process/applyRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/applyRemovalPlan.js +150 -0
- package/dist/AAL/process/applyRemovalPlan.js.map +1 -0
- package/dist/AAL/process/buildDecisionReason.d.ts +36 -0
- package/dist/AAL/process/buildDecisionReason.d.ts.map +1 -0
- package/dist/AAL/process/buildDecisionReason.js +70 -0
- package/dist/AAL/process/buildDecisionReason.js.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts +39 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.js +104 -0
- package/dist/AAL/process/buildRemovalPlan.js.map +1 -0
- package/dist/AAL/process/index.d.ts +10 -0
- package/dist/AAL/process/index.d.ts.map +1 -0
- package/dist/AAL/process/index.js +8 -0
- package/dist/AAL/process/index.js.map +1 -0
- package/dist/AAL/process/resolveAgentAction.d.ts +31 -0
- package/dist/AAL/process/resolveAgentAction.d.ts.map +1 -0
- package/dist/AAL/process/resolveAgentAction.js +67 -0
- package/dist/AAL/process/resolveAgentAction.js.map +1 -0
- package/dist/AAL/types.d.ts +108 -0
- package/dist/AAL/types.d.ts.map +1 -0
- package/dist/AAL/types.js +2 -0
- package/dist/AAL/types.js.map +1 -0
- package/dist/{isl → AAL}/value-objects/AnomalyScore.d.ts +2 -1
- package/dist/AAL/value-objects/AnomalyScore.d.ts.map +1 -0
- package/dist/{isl → AAL}/value-objects/AnomalyScore.js.map +1 -1
- package/dist/{isl → AAL}/value-objects/PolicyRule.d.ts.map +1 -1
- package/dist/{isl → AAL}/value-objects/PolicyRule.js.map +1 -1
- package/dist/AAL/value-objects/index.d.ts +5 -0
- package/dist/AAL/value-objects/index.d.ts.map +1 -0
- package/dist/AAL/value-objects/index.js +3 -0
- package/dist/AAL/value-objects/index.js.map +1 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/isl/detect/detect.d.ts +39 -0
- package/dist/isl/detect/detect.d.ts.map +1 -0
- package/dist/isl/detect/detect.js +369 -0
- package/dist/isl/detect/detect.js.map +1 -0
- package/dist/isl/detect/index.d.ts +6 -0
- package/dist/isl/detect/index.d.ts.map +1 -0
- package/dist/isl/detect/index.js +5 -0
- package/dist/isl/detect/index.js.map +1 -0
- package/dist/isl/index.d.ts +22 -6
- package/dist/isl/index.d.ts.map +1 -1
- package/dist/isl/index.js +20 -5
- package/dist/isl/index.js.map +1 -1
- package/dist/isl/lineage/buildISLLineage.d.ts +22 -0
- package/dist/isl/lineage/buildISLLineage.d.ts.map +1 -0
- package/dist/isl/lineage/buildISLLineage.js +26 -0
- package/dist/isl/lineage/buildISLLineage.js.map +1 -0
- package/dist/isl/lineage/index.d.ts +5 -0
- package/dist/isl/lineage/index.d.ts.map +1 -0
- package/dist/isl/lineage/index.js +5 -0
- package/dist/isl/lineage/index.js.map +1 -0
- package/dist/isl/process/buildISLResult.d.ts +24 -0
- package/dist/isl/process/buildISLResult.d.ts.map +1 -0
- package/dist/isl/process/buildISLResult.js +38 -0
- package/dist/isl/process/buildISLResult.js.map +1 -0
- package/dist/isl/process/emitSignal.d.ts +32 -0
- package/dist/isl/process/emitSignal.d.ts.map +1 -0
- package/dist/isl/process/emitSignal.js +41 -0
- package/dist/isl/process/emitSignal.js.map +1 -0
- package/dist/isl/process/index.d.ts +7 -0
- package/dist/isl/process/index.d.ts.map +1 -0
- package/dist/isl/process/index.js +6 -0
- package/dist/isl/process/index.js.map +1 -0
- package/dist/isl/riskScore/calculators.d.ts +19 -0
- package/dist/isl/riskScore/calculators.d.ts.map +1 -0
- package/dist/isl/riskScore/calculators.js +50 -0
- package/dist/isl/riskScore/calculators.js.map +1 -0
- package/dist/isl/riskScore/index.d.ts +14 -0
- package/dist/isl/riskScore/index.d.ts.map +1 -0
- package/dist/isl/riskScore/index.js +26 -0
- package/dist/isl/riskScore/index.js.map +1 -0
- package/dist/isl/riskScore/types.d.ts +20 -0
- package/dist/isl/riskScore/types.d.ts.map +1 -0
- package/dist/isl/riskScore/types.js +12 -0
- package/dist/isl/riskScore/types.js.map +1 -0
- package/dist/isl/sanitize.d.ts +13 -6
- package/dist/isl/sanitize.d.ts.map +1 -1
- package/dist/isl/sanitize.js +34 -40
- package/dist/isl/sanitize.js.map +1 -1
- package/dist/isl/signals.d.ts +113 -0
- package/dist/isl/signals.d.ts.map +1 -0
- package/dist/isl/signals.js +94 -0
- package/dist/isl/signals.js.map +1 -0
- package/dist/isl/types.d.ts +4 -48
- package/dist/isl/types.d.ts.map +1 -1
- package/dist/isl/types.js +1 -1
- package/dist/isl/value-objects/Pattern.d.ts +21 -0
- package/dist/isl/value-objects/Pattern.d.ts.map +1 -1
- package/dist/isl/value-objects/Pattern.js +36 -0
- package/dist/isl/value-objects/Pattern.js.map +1 -1
- package/dist/isl/value-objects/PiDetection.d.ts +2 -1
- package/dist/isl/value-objects/PiDetection.d.ts.map +1 -1
- package/dist/isl/value-objects/PiDetectionResult.d.ts +2 -3
- package/dist/isl/value-objects/PiDetectionResult.d.ts.map +1 -1
- package/dist/isl/value-objects/PiDetectionResult.js +1 -27
- package/dist/isl/value-objects/PiDetectionResult.js.map +1 -1
- package/dist/isl/value-objects/RiskScore.d.ts +70 -0
- package/dist/isl/value-objects/RiskScore.d.ts.map +1 -0
- package/dist/isl/value-objects/RiskScore.js +85 -0
- package/dist/isl/value-objects/RiskScore.js.map +1 -0
- package/dist/isl/value-objects/index.d.ts +4 -4
- package/dist/isl/value-objects/index.d.ts.map +1 -1
- package/dist/isl/value-objects/index.js +2 -4
- package/dist/isl/value-objects/index.js.map +1 -1
- package/dist/shared/audit.d.ts +250 -0
- package/dist/shared/audit.d.ts.map +1 -0
- package/dist/shared/audit.js +455 -0
- package/dist/shared/audit.js.map +1 -0
- package/dist/shared/index.d.ts +5 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +5 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/types.d.ts +36 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +2 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +12 -3
- package/dist/isl/value-objects/AnomalyScore.d.ts.map +0 -1
- /package/dist/{isl → AAL}/value-objects/AnomalyScore.js +0 -0
- /package/dist/{isl → AAL}/value-objects/PolicyRule.d.ts +0 -0
- /package/dist/{isl → AAL}/value-objects/PolicyRule.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,116 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - (unreleased)
|
|
11
|
+
|
|
12
|
+
### ✨ Added
|
|
13
|
+
|
|
14
|
+
- **ISL – Threat detection**
|
|
15
|
+
- `detectThreats(content, options?)`: pure, deterministic function returning `readonly PiDetection[]`.
|
|
16
|
+
- Default patterns for known attack surfaces (prompt-injection, jailbreak, role hijacking, script_like, hidden_text); expanded set (~287 patterns).
|
|
17
|
+
- Integration in `sanitize`: each segment may carry `piDetection` (`PiDetectionResult`).
|
|
18
|
+
- Option `SanitizeOptions.detectThreatsOptions` for custom patterns or limits (`patterns`, `maxTotal`, `maxPerPattern`).
|
|
19
|
+
- `getDefaultThreatPatterns()`: returns the default set (cached, frozen).
|
|
20
|
+
- `THREAT_TYPES` and type `ThreatType` for deterministic taxonomy.
|
|
21
|
+
|
|
22
|
+
- **ISL – Risk score strategies**
|
|
23
|
+
- Enum `RiskScoreStrategy`: `MAX_CONFIDENCE`, `SEVERITY_PLUS_VOLUME`, `WEIGHTED_BY_TYPE`.
|
|
24
|
+
- Pure calculators: `maxConfidenceCalculator`, `severityPlusVolumeCalculator`, `weightedByTypeCalculator`, `defaultWeightedByTypeCalculator`.
|
|
25
|
+
- `getCalculator(strategy, typeWeights?)`: returns the registered calculator for the strategy.
|
|
26
|
+
- Strategy fixed at `emitSignal`; reflected in `ISLSignal.metadata.strategy` for audit.
|
|
27
|
+
|
|
28
|
+
- **emitSignal – Risk score options**
|
|
29
|
+
- `EmitSignalOptions`: `timestamp?`, `riskScore?: { strategy, typeWeights? }`.
|
|
30
|
+
- Default: `RiskScoreStrategy.MAX_CONFIDENCE`.
|
|
31
|
+
- Backward compatibility: `emitSignal(islResult, timestamp)` still supported.
|
|
32
|
+
|
|
33
|
+
- **ISLSignal – Strategy metadata**
|
|
34
|
+
- `ISLSignal.metadata?: { strategy: RiskScoreStrategy }` for traceability.
|
|
35
|
+
- `createISLSignal(..., metadata?)` accepts optional fourth argument `metadata`.
|
|
36
|
+
|
|
37
|
+
- **AAL – Actionable removal plan**
|
|
38
|
+
- `buildRemovalPlanFromResult(islResult, policy)`: builds `RemovalPlan` from `ISLResult` with `segmentId` per instruction.
|
|
39
|
+
- `applyRemovalPlan(islResult, plan)`: pure function that removes malicious ranges from each segment's `sanitizedContent`; clamps ranges to content; merges overlapping and adjacent ranges (gap only punctuation/whitespace); returns new `ISLResult`.
|
|
40
|
+
- `RemovedInstruction.segmentId?`: optional, present when the plan is built from `ISLResult`.
|
|
41
|
+
- Guards in `resolveAgentAction`, `resolveAgentActionWithScore`, `buildDecisionReason`, `buildRemovalPlan`, and `buildRemovalPlanFromResult` for safe handling of detections and signals.
|
|
42
|
+
|
|
43
|
+
- **AAL – Resolve action with score**
|
|
44
|
+
- `resolveAgentActionWithScore(islSignal, policy)`: returns `{ action, anomalyScore }` for SDK/audit use.
|
|
45
|
+
|
|
46
|
+
- **AAL – Colors for UI/audit**
|
|
47
|
+
- `ACTION_DISPLAY_COLORS` and `getActionDisplayColor(action)` for ALLOW/WARN/BLOCK.
|
|
48
|
+
|
|
49
|
+
- **Shared – Audit improvements (run id, JSON, logs, full pipeline)**
|
|
50
|
+
- **Run identifier**: `createAuditRunId()` generates a unique run id; full-pipeline formatters accept `options.runId` and `options.generatedAt` for correlation across reports and logs.
|
|
51
|
+
- **Full pipeline audit**: `formatPipelineAuditFull(csl, isl, signal, aalReason, removalPlan?, cpe?, options?)` builds a single report (CSL → ISL → Signal → AAL → optional CPE) with run id and generated-at timestamp; lineage preserved in each section.
|
|
52
|
+
- **formatPipelineAudit** extended: `options.includeSignalAndAAL`, `options.signal`, `options.aalReason`, `options.removalPlan` to include ISL Signal and AAL sections in the pipeline report.
|
|
53
|
+
- **JSON variant**: `buildFullAuditPayload(csl, isl, signal, reason, options?)` returns a JSON-serializable object (runId, generatedAt, summary, sections with lineage). `formatPipelineAuditAsJson(...)` returns the JSON string; `options.compact: true` for one-line output (logs, SIEM).
|
|
54
|
+
- **Audit for logs**: `buildAuditLogEntry(signal, reason, options?)` returns a compact summary (runId, generatedAtIso, action, riskScore, hasThreats, detectionCount) for one-line logging.
|
|
55
|
+
- Types: `AuditRunInfo`, `AuditLogSummary`, `FullPipelineAuditOptions`, `PipelineAuditJsonOptions`.
|
|
56
|
+
|
|
57
|
+
### 🔄 Changed
|
|
58
|
+
|
|
59
|
+
- **sanitize (ISL)**: optional second argument `SanitizeOptions`; uses `detectThreats` per segment and assigns `piDetection` when detections exist; option `detectThreatsOptions` for patterns or limits.
|
|
60
|
+
- **emitSignal (ISL)**: second argument may be `EmitSignalOptions` (object) or `number` (timestamp); computes risk score with configured strategy; includes `metadata.strategy` on the signal.
|
|
61
|
+
- **RemovedInstruction (AAL)**: `type` is now `string` (any `pattern_type`); added `segmentId?: string`.
|
|
62
|
+
|
|
63
|
+
### 📚 Documentation
|
|
64
|
+
|
|
65
|
+
- **FEATURE.md**: per-version detail of new and modified features; table of methods/APIs changed in 0.3.0 with description of each change.
|
|
66
|
+
- **README.md**: audit section updated with run id, full pipeline (formatPipelineAuditFull), JSON variant (buildFullAuditPayload, formatPipelineAuditAsJson), and audit for logs (buildAuditLogEntry); examples for full report and compact log entry.
|
|
67
|
+
|
|
68
|
+
### 📎 More information
|
|
69
|
+
|
|
70
|
+
For specific method signatures and API changes in 0.3.0, see **[FEATURE.md](./FEATURE.md)**.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## [0.2.0] - 2026-01-26
|
|
75
|
+
|
|
76
|
+
### ♻️ Architectural Refactor - ISL / AAL Separation
|
|
77
|
+
|
|
78
|
+
- Refactored ISL (Instruction Sanitization Layer) to be strictly pure and semantic
|
|
79
|
+
- Removed all decision-making logic from ISL:
|
|
80
|
+
- No Blocking
|
|
81
|
+
- No allowing
|
|
82
|
+
- No warnings
|
|
83
|
+
- No instruction removal
|
|
84
|
+
- ISL is now responsible for:
|
|
85
|
+
- Malicious pattern detection (prompt injection, jailbreak, role hijacking, ...)
|
|
86
|
+
- Risk scoring (RiskScore)
|
|
87
|
+
- Content sanitization
|
|
88
|
+
- Signal emission and lineage preservation
|
|
89
|
+
|
|
90
|
+
- Introduced AAL (Agent Action Lock) as a distinct hybrid layer:
|
|
91
|
+
- Consume ISL signal (RiskScore, detection)
|
|
92
|
+
- Applies configurable policies (ALLOW / WARN / BLOCK)
|
|
93
|
+
- Decides whether to remove malicious instructions
|
|
94
|
+
- Ensures only sanitized content reaches the LLM
|
|
95
|
+
- Designed as a core-defined contract, implemented at the SDK level
|
|
96
|
+
|
|
97
|
+
- **Shared audit utilities**: Pure functions for ordered, human-readable audit output (`formatCSLForAudit`, `formatISLForAudit`, `formatISLSignalForAudit`, `formatAALForAudit`, `formatCPEForAudit`, `formatPipelineAudit`) for compliance and debugging
|
|
98
|
+
|
|
99
|
+
- **Package**: Version set to 0.2.0; AAL export path corrected (`./aal` → `./dist/AAL/`)
|
|
100
|
+
|
|
101
|
+
### 📚 Documentation
|
|
102
|
+
|
|
103
|
+
- README.md updated to clarify the new ISL / AAL responsibility split; architecture and layer sections in English
|
|
104
|
+
- **Use cases** section added with scenarios (secure chat, policy moderation, audit, DOM/API/SYSTEM sources, lineage)
|
|
105
|
+
- Examples for policy-based moderation (ISL + AAL) and audit report using shared formatters
|
|
106
|
+
- Audit and pretty-print utilities documented (formatCSLForAudit, formatISLForAudit, formatISLSignalForAudit, formatAALForAudit, formatCPEForAudit, formatPipelineAudit)
|
|
107
|
+
|
|
108
|
+
### 🧪 Testing
|
|
109
|
+
|
|
110
|
+
- Added unit tests for CSL (segment, classify), ISL (signals, emitSignal, buildISLResult, RiskScore), AAL (resolveAgentAction, buildDecisionReason, buildRemovalPlan, buildAALLineage, AnomalyScore, PolicyRule), CPE (envelope), and shared (audit formatters)
|
|
111
|
+
- Integration tests updated for ISL Signal → AAL flow; all test messages in English
|
|
112
|
+
- Coverage target met: **92%+** statements for CSL, ISL, AAL, CPE, and shared layers
|
|
113
|
+
|
|
114
|
+
### ⚠️ Breaking Semantic Change
|
|
115
|
+
|
|
116
|
+
- Although public APIs remain mostly stable, ISL behavior has changed semantically
|
|
117
|
+
- Consumers must no longer expect ISL to perform actions or remove instructions
|
|
118
|
+
- Decision logic must be handled by AAL or the SDK
|
|
119
|
+
|
|
10
120
|
## [0.1.8] - 2026-01-04
|
|
11
121
|
|
|
12
122
|
### 🐛 Critical Fixes - Origin Classification
|
|
@@ -92,6 +202,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
92
202
|
|
|
93
203
|
## [0.1.7] - 2026-01-04
|
|
94
204
|
|
|
205
|
+
### ⚠️ DEPRECATED
|
|
206
|
+
|
|
207
|
+
**Deprecation reason**: This version has incorrect source classification that doesn't match the AI-PIP protocol specification. The trust level assignments for sources (UI, DOM, API, SYSTEM) are incorrect, which can lead to improper sanitization levels and security vulnerabilities.
|
|
208
|
+
|
|
209
|
+
**Known issues**:
|
|
210
|
+
- Incorrect source-to-trust-level mapping (UI classified as TC instead of STC, DOM as STC instead of UC, API as UC instead of STC)
|
|
211
|
+
- Inconsistent behavior with AI-PIP protocol specification
|
|
212
|
+
- Tests and documentation don't match actual implementation
|
|
213
|
+
- Potential security risks due to incorrect sanitization levels
|
|
214
|
+
|
|
215
|
+
**Recommendation**: Update to `0.1.8` or higher, which fixes all classification issues and aligns with the AI-PIP protocol specification.
|
|
216
|
+
|
|
95
217
|
### 🐛 Critical Fixes
|
|
96
218
|
|
|
97
219
|
#### Type Resolution Fix
|
|
@@ -103,7 +225,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
103
225
|
|
|
104
226
|
**Problem**: When importing types from `@ai-pip/core` in SDK projects, TypeScript could not resolve nested type properties:
|
|
105
227
|
- `this.data.trust.value` appeared as `any` instead of `TrustLevelType`
|
|
106
|
-
- No
|
|
228
|
+
- No autocomplete for nested properties
|
|
107
229
|
- Type inference failed for complex types
|
|
108
230
|
|
|
109
231
|
**Root Cause**: Incompatibility between `moduleResolution: "bundler"` (used in `@ai-pip-core`) and `moduleResolution: "nodenext"` (used in SDK projects). TypeScript couldn't follow the chain of type imports correctly.
|
|
@@ -115,7 +237,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
115
237
|
|
|
116
238
|
**Impact**:
|
|
117
239
|
- ✅ Nested types now resolve correctly
|
|
118
|
-
- ✅
|
|
240
|
+
- ✅ Autocomplete works for all type properties
|
|
119
241
|
- ✅ Type inference works correctly in consuming projects
|
|
120
242
|
- ✅ Better compatibility with Node.js ESM module resolution
|
|
121
243
|
|
|
@@ -145,6 +267,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
145
267
|
|
|
146
268
|
## [0.1.6] - 2025-12-28
|
|
147
269
|
|
|
270
|
+
### ⚠️ DEPRECATED
|
|
271
|
+
|
|
272
|
+
**Deprecation reason**: This version has incorrect source classification that doesn't match the AI-PIP protocol specification. The trust level assignments for sources are incorrect, which can lead to improper sanitization levels and security vulnerabilities.
|
|
273
|
+
|
|
274
|
+
**Known issues**:
|
|
275
|
+
- Incorrect source-to-trust-level mapping
|
|
276
|
+
- Inconsistent behavior with AI-PIP protocol specification
|
|
277
|
+
- Potential security risks due to incorrect sanitization levels
|
|
278
|
+
|
|
279
|
+
**Recommendation**: Update to `0.1.8` or higher, which fixes all classification issues and aligns with the AI-PIP protocol specification.
|
|
280
|
+
|
|
148
281
|
### 📚 Documentation Improvements
|
|
149
282
|
- **Centralized documentation**: Moved all protocol documentation to `ai-pip-docs` repository
|
|
150
283
|
- **Updated README**: Added comprehensive links to centralized documentation
|
|
@@ -158,6 +291,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
158
291
|
|
|
159
292
|
## [0.1.5] - 2025-12-28
|
|
160
293
|
|
|
294
|
+
### ⚠️ DEPRECATED
|
|
295
|
+
|
|
296
|
+
**Deprecation reason**: This version has incorrect source classification that doesn't match the AI-PIP protocol specification. The trust level assignments for sources are incorrect, which can lead to improper sanitization levels and security vulnerabilities.
|
|
297
|
+
|
|
298
|
+
**Known issues**:
|
|
299
|
+
- Incorrect source-to-trust-level mapping
|
|
300
|
+
- Inconsistent behavior with AI-PIP protocol specification
|
|
301
|
+
- Potential security risks due to incorrect sanitization levels
|
|
302
|
+
|
|
303
|
+
**Recommendation**: Update to `0.1.8` or higher, which fixes all classification issues and aligns with the AI-PIP protocol specification.
|
|
304
|
+
|
|
161
305
|
### 📚 Documentation Improvements
|
|
162
306
|
- **Updated README**: Added links to whitepaper, roadmap, and complete layer documentation
|
|
163
307
|
- **Updated Roadmap**: Added SDK-browser in Phase 4, updated Phase 1 status to 100% completed
|
|
@@ -176,6 +320,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
176
320
|
|
|
177
321
|
## [0.1.3] - 2025-12-28
|
|
178
322
|
|
|
323
|
+
### ⚠️ DEPRECATED
|
|
324
|
+
|
|
325
|
+
**Deprecation reason**: This version has incorrect source classification that doesn't match the AI-PIP protocol specification. The trust level assignments for sources are incorrect, which can lead to improper sanitization levels and security vulnerabilities.
|
|
326
|
+
|
|
327
|
+
**Known issues**:
|
|
328
|
+
- Incorrect source-to-trust-level mapping
|
|
329
|
+
- Inconsistent behavior with AI-PIP protocol specification
|
|
330
|
+
- Potential security risks due to incorrect sanitization levels
|
|
331
|
+
|
|
332
|
+
**Recommendation**: Update to `0.1.8` or higher, which fixes all classification issues and aligns with the AI-PIP protocol specification.
|
|
333
|
+
|
|
179
334
|
### ✨ New Features
|
|
180
335
|
- **JavaScript compilation**: The package now compiles to JavaScript (`dist/`) for better compatibility
|
|
181
336
|
- **Type declaration files**: `.d.ts` files are generated for full TypeScript support
|
package/README.md
CHANGED
|
@@ -25,6 +25,9 @@ This package contains the **core** implementation of the protocol, which include
|
|
|
25
25
|
- [Complete Example (Layer-Specific Imports)](#complete-example-layer-specific-imports)
|
|
26
26
|
- [Example with additional functions](#example-with-additional-functions)
|
|
27
27
|
- [Example: Multi-Layer Lineage and Audit Trail](#example-multi-layer-lineage-and-audit-trail)
|
|
28
|
+
- [Example: ISL Signal and AAL Integration](#example-isl-signal-aal)
|
|
29
|
+
- [Example: Audit and pretty-print utilities](#example-audit-utilities)
|
|
30
|
+
- [Use cases](#use-cases)
|
|
28
31
|
- [Examples by Content Source](#examples-by-content-source)
|
|
29
32
|
- [DOM Source (HTML Content)](#example-dom-source-html-content)
|
|
30
33
|
- [UI Source (User Input)](#example-ui-source-user-input)
|
|
@@ -32,6 +35,7 @@ This package contains the **core** implementation of the protocol, which include
|
|
|
32
35
|
- [API Source (External Data)](#example-api-source-external-data)
|
|
33
36
|
- [Documentation](#documentation)
|
|
34
37
|
- [Testing](#testing)
|
|
38
|
+
- [Coverage](#coverage)
|
|
35
39
|
- [Development](#development)
|
|
36
40
|
- [Requirements](#requirements)
|
|
37
41
|
- [License](#license)
|
|
@@ -40,25 +44,77 @@ This package contains the **core** implementation of the protocol, which include
|
|
|
40
44
|
- [Import Strategies](#import-strategies)
|
|
41
45
|
- [Official SDK](#official-sdk)
|
|
42
46
|
- [CHANGELOG](#changelog)
|
|
43
|
-
|
|
47
|
+
- [FEATURES](#features)
|
|
44
48
|
<a id="architecture"></a>
|
|
45
49
|
## 🏗️ Architecture
|
|
46
50
|
|
|
47
|
-
The AI-PIP protocol is composed of the following layers:
|
|
51
|
+
The AI-PIP protocol is composed of the following layers with clear separation of responsibilities:
|
|
48
52
|
|
|
49
53
|
### ✅ Implemented Layers
|
|
50
54
|
|
|
51
55
|
- **CSL (Context Segmentation Layer)**: Segments and classifies content according to its origin
|
|
52
|
-
- **ISL (Instruction Sanitization Layer)**:
|
|
56
|
+
- **ISL (Instruction Sanitization Layer)**: Detects malicious patterns (`detectThreats`, ~287 default patterns), scores risk (configurable strategies), and sanitizes content. Each segment may carry `piDetection` (`PiDetectionResult`). Optional `SanitizeOptions.detectThreatsOptions` for custom patterns or limits. Emits signals (ISLSignal) for other layers to consume.
|
|
57
|
+
- **AAL (Agent Action Lock)**: Hybrid layer that consumes ISL signals and applies configurable policies (ALLOW/WARN/BLOCK). Core-defined contract, SDK-implemented.
|
|
53
58
|
- **CPE (Cryptographic Prompt Envelope)**: Generates cryptographic envelope with HMAC-SHA256 signature
|
|
54
59
|
|
|
55
60
|
### 🔧 Shared Features
|
|
56
61
|
|
|
57
62
|
- **Shared**: Shared functions and global incremental lineage (not a layer, but features shared between layers)
|
|
58
63
|
|
|
64
|
+
### 🏛️ Architectural Principles
|
|
65
|
+
|
|
66
|
+
#### Layer Separation and Signals
|
|
67
|
+
|
|
68
|
+
**Fundamental rule**: A layer must never consume another layer's internal "result". It consumes a signal.
|
|
69
|
+
|
|
70
|
+
- **ISLResult**: Internal result of the ISL pipeline (segments, lineage, full metadata)
|
|
71
|
+
- Intended for: debugging, reporter, internal traceability
|
|
72
|
+
- **ISLSignal**: Semantic contract between layers (risk scores, detections, security signals)
|
|
73
|
+
- Intended for: AAL, SDK, Engine
|
|
74
|
+
- Does not expose ISL internals
|
|
75
|
+
|
|
76
|
+
**Processing flow:**
|
|
77
|
+
```
|
|
78
|
+
ISL.process()
|
|
79
|
+
→ ISLResult (internal)
|
|
80
|
+
→ ISLSignal (external)
|
|
81
|
+
→ AAL consumes ISLSignal (not ISLResult)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Layer Organization
|
|
85
|
+
|
|
86
|
+
Each layer follows a consistent structure:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
Layer/
|
|
90
|
+
├─ exceptions/ → what is invalid
|
|
91
|
+
├─ value-objects/ → what it is
|
|
92
|
+
├─ process/ → how it transforms
|
|
93
|
+
├─ lineage/ → what happened
|
|
94
|
+
├─ types.ts
|
|
95
|
+
└─ index.ts
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Benefits:**
|
|
99
|
+
- ✅ No layer overlap
|
|
100
|
+
- ✅ Clear separation of responsibilities
|
|
101
|
+
- ✅ Core scales better
|
|
102
|
+
- ✅ Clear separation between internals and semantic contracts
|
|
103
|
+
|
|
59
104
|
### 📝 Note on AAL and Model Gateway
|
|
60
105
|
|
|
61
|
-
**AAL (Agent Action Lock)**
|
|
106
|
+
**AAL (Agent Action Lock)** is a hybrid layer defined in the semantic core but implemented at the SDK level. The core provides:
|
|
107
|
+
- Value objects (AnomalyScore, AgentPolicy, PolicyRule)
|
|
108
|
+
- Semantic contracts and types
|
|
109
|
+
- Pure functions for decision logic
|
|
110
|
+
|
|
111
|
+
The SDK implements:
|
|
112
|
+
- Operational decision execution
|
|
113
|
+
- Policy enforcement
|
|
114
|
+
- Instruction removal
|
|
115
|
+
- Side effects and state management
|
|
116
|
+
|
|
117
|
+
**Model Gateway** is a pure SDK component for routing and managing AI model interactions.
|
|
62
118
|
|
|
63
119
|
<a id="installation"></a>
|
|
64
120
|
## 📦 Installation
|
|
@@ -97,8 +153,12 @@ import { segment, classifySource, createTrustLevel } from '@ai-pip/core/csl'
|
|
|
97
153
|
import type { CSLResult, CSLSegment, TrustLevel } from '@ai-pip/core/csl'
|
|
98
154
|
|
|
99
155
|
// Import from ISL (Instruction Sanitization Layer)
|
|
100
|
-
import { sanitize } from '@ai-pip/core/isl'
|
|
101
|
-
import type { ISLResult, ISLSegment } from '@ai-pip/core/isl'
|
|
156
|
+
import { sanitize, createISLSignal, detectThreats, getDefaultThreatPatterns } from '@ai-pip/core/isl'
|
|
157
|
+
import type { ISLResult, ISLSegment, ISLSignal, DetectThreatsOptions } from '@ai-pip/core/isl'
|
|
158
|
+
|
|
159
|
+
// Import from AAL (Agent Action Lock)
|
|
160
|
+
import { createAnomalyScore, resolveAgentAction, resolveAgentActionWithScore, buildRemovalPlanFromResult, applyRemovalPlan } from '@ai-pip/core/aal'
|
|
161
|
+
import type { AnomalyScore, AgentPolicy } from '@ai-pip/core/aal'
|
|
102
162
|
|
|
103
163
|
// Import from CPE (Cryptographic Prompt Envelope)
|
|
104
164
|
import { envelope, createNonce, createMetadata } from '@ai-pip/core/cpe'
|
|
@@ -139,7 +199,7 @@ This example demonstrates the complete AI-PIP processing pipeline:
|
|
|
139
199
|
|
|
140
200
|
1. **CSL (Context Segmentation Layer)**: The `segment()` function takes user input and segments it into semantic chunks. Each segment is classified by its origin (`source: 'UI'`), which determines its trust level. The result contains multiple segments, each with its own trust classification and lineage tracking.
|
|
141
201
|
|
|
142
|
-
2. **ISL (Instruction Sanitization Layer)**: The `sanitize()` function processes the segmented content and applies sanitization based on each segment's trust level. Trusted content (TC) receives minimal sanitization, semi-trusted (STC) gets moderate sanitization, and untrusted content (UC) receives aggressive sanitization to remove potential prompt injection attempts.
|
|
202
|
+
2. **ISL (Instruction Sanitization Layer)**: The `sanitize()` function processes the segmented content and applies sanitization based on each segment's trust level. Trusted content (TC) receives minimal sanitization, semi-trusted (STC) gets moderate sanitization, and untrusted content (UC) receives aggressive sanitization to remove potential prompt injection attempts. ISL runs `detectThreats` per segment (default ~287 patterns; optional `SanitizeOptions.detectThreatsOptions` for custom patterns or limits) and attaches `piDetection` (`PiDetectionResult`) to segments with detections. It emits signals (ISLSignal) that can be consumed by AAL for policy-based decisions.
|
|
143
203
|
|
|
144
204
|
3. **CPE (Cryptographic Prompt Envelope)**: The `envelope()` function creates a cryptographic wrapper around the sanitized content. It generates a unique nonce, timestamp, and HMAC-SHA256 signature to ensure the integrity and authenticity of the processed prompt. The resulting envelope can be safely sent to an AI model with cryptographic proof that the content hasn't been tampered with.
|
|
145
205
|
|
|
@@ -194,7 +254,7 @@ This example shows the same processing pipeline but using layer-specific imports
|
|
|
194
254
|
|
|
195
255
|
2. **Content Segmentation**: The `segment()` function breaks down the input into semantic segments. Each segment inherits the trust classification from its source, allowing different parts of the content to be processed according to their trustworthiness.
|
|
196
256
|
|
|
197
|
-
3. **Content Sanitization**: The `sanitize()` function applies security measures based on each segment's trust level. This step removes or neutralizes potential prompt injection attempts, especially in untrusted content segments.
|
|
257
|
+
3. **Content Sanitization**: The `sanitize()` function applies security measures based on each segment's trust level and runs threat detection per segment (each segment may have `piDetection`). This step removes or neutralizes potential prompt injection attempts, especially in untrusted content segments.
|
|
198
258
|
|
|
199
259
|
4. **Nonce Generation**: `createNonce()` generates a unique random value that prevents replay attacks. This nonce is included in the cryptographic envelope to ensure each processed prompt is unique.
|
|
200
260
|
|
|
@@ -529,6 +589,276 @@ const cpeResult = envelope(islResult, 'your-secret-key')
|
|
|
529
589
|
- Enhanced pattern matching and anomaly detection
|
|
530
590
|
- Production-ready implementations with comprehensive security features
|
|
531
591
|
- and more...
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
<a id="example-isl-signal-aal"></a>
|
|
596
|
+
### Example: ISL Signal and AAL Integration
|
|
597
|
+
|
|
598
|
+
**How signals work:** ISL produces an internal result (`ISLResult`). You call `emitSignal(islResult)` to obtain an `ISLSignal` (risk score, detections, `hasThreats`). AAL consumes only this signal via `resolveAgentAction(islSignal, policy)` and never sees `ISLResult`. Minimal flow:
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
const islResult = sanitize(cslResult) // ISL internal result
|
|
602
|
+
const islSignal = emitSignal(islResult) // External signal for other layers
|
|
603
|
+
const action = resolveAgentAction(islSignal, policy) // AAL consumes signal → 'ALLOW' | 'WARN' | 'BLOCK'
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Full example below demonstrates the signal-based communication between ISL and AAL layers, following the architectural principle that layers should consume signals, not internal results:
|
|
607
|
+
|
|
608
|
+
```typescript
|
|
609
|
+
import {
|
|
610
|
+
segment,
|
|
611
|
+
sanitize,
|
|
612
|
+
emitSignal,
|
|
613
|
+
resolveAgentAction,
|
|
614
|
+
buildDecisionReason,
|
|
615
|
+
buildRemovalPlan,
|
|
616
|
+
buildRemovalPlanFromResult,
|
|
617
|
+
applyRemovalPlan
|
|
618
|
+
} from '@ai-pip/core'
|
|
619
|
+
import type { ISLSignal, AgentPolicy } from '@ai-pip/core'
|
|
620
|
+
|
|
621
|
+
// 1. Segment content (CSL)
|
|
622
|
+
const cslResult = segment({
|
|
623
|
+
content: 'User input with potential injection',
|
|
624
|
+
source: 'UI',
|
|
625
|
+
metadata: {}
|
|
626
|
+
})
|
|
627
|
+
|
|
628
|
+
// 2. Sanitize content (ISL) - produces internal result; segments may have piDetection
|
|
629
|
+
const islResult = sanitize(cslResult)
|
|
630
|
+
|
|
631
|
+
// 3. Emit signal from ISL result - external contract
|
|
632
|
+
const islSignal: ISLSignal = emitSignal(islResult)
|
|
633
|
+
|
|
634
|
+
// 4. Define agent policy
|
|
635
|
+
const policy: AgentPolicy = {
|
|
636
|
+
thresholds: {
|
|
637
|
+
warn: 0.3,
|
|
638
|
+
block: 0.7
|
|
639
|
+
},
|
|
640
|
+
removal: {
|
|
641
|
+
enabled: true
|
|
642
|
+
},
|
|
643
|
+
mode: 'balanced'
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// 5. AAL consumes ISLSignal (not ISLResult) and resolves action
|
|
647
|
+
const action = resolveAgentAction(islSignal, policy)
|
|
648
|
+
console.log('Agent action:', action) // 'ALLOW', 'WARN', or 'BLOCK'
|
|
649
|
+
|
|
650
|
+
// 6. Build decision reason for audit
|
|
651
|
+
const reason = buildDecisionReason(action, islSignal, policy)
|
|
652
|
+
console.log('Decision reason:', reason.reason)
|
|
653
|
+
|
|
654
|
+
// 7. Build removal plan from signal (descriptive) or from result (actionable)
|
|
655
|
+
const removalPlan = buildRemovalPlan(islSignal, policy)
|
|
656
|
+
if (removalPlan.shouldRemove) {
|
|
657
|
+
const planFromResult = buildRemovalPlanFromResult(islResult, policy)
|
|
658
|
+
const cleanedResult = applyRemovalPlan(islResult, planFromResult)
|
|
659
|
+
console.log(`Removed ${planFromResult.instructionsToRemove.length} instruction(s); use cleanedResult for LLM`)
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
**What this example demonstrates:**
|
|
664
|
+
|
|
665
|
+
1. **Signal-Based Communication**: ISL emits `ISLSignal` (external contract) instead of exposing `ISLResult` (internal). This maintains layer separation.
|
|
666
|
+
|
|
667
|
+
2. **AAL Decision Making**: AAL consumes the signal and applies configurable policies to determine actions (ALLOW/WARN/BLOCK).
|
|
668
|
+
|
|
669
|
+
3. **Separation of Concerns**:
|
|
670
|
+
- ISL: Detects threats, scores risk, sanitizes content
|
|
671
|
+
- AAL: Evaluates signals, applies policies, builds removal plans
|
|
672
|
+
- SDK: Executes actions, removes instructions, manages state
|
|
673
|
+
|
|
674
|
+
4. **Architectural Benefits**:
|
|
675
|
+
- ✅ No layer coupling (AAL doesn't know ISL internals)
|
|
676
|
+
- ✅ Clear contracts between layers
|
|
677
|
+
- ✅ Easy to test and maintain
|
|
678
|
+
- ✅ Scalable architecture
|
|
679
|
+
|
|
680
|
+
**Key Principle**: A layer should never consume the internal "result" of another layer. It consumes a signal.
|
|
681
|
+
|
|
682
|
+
#### Risk score strategies (ISL)
|
|
683
|
+
|
|
684
|
+
The risk score on the signal is derived from aggregated detections using a **strategy** chosen at emit time. Only registered strategies are allowed (auditability and reproducibility).
|
|
685
|
+
|
|
686
|
+
| Strategy | Description | When to use |
|
|
687
|
+
|----------|-------------|-------------|
|
|
688
|
+
| **MAX_CONFIDENCE** (default) | Single highest confidence among detections. | Simple, conservative; good default. |
|
|
689
|
+
| **SEVERITY_PLUS_VOLUME** | Highest confidence plus a small bump per extra detection (volume). | When multiple detections should raise risk. |
|
|
690
|
+
| **WEIGHTED_BY_TYPE** | Weight by pattern type (e.g. jailbreak vs prompt-injection). | When some threat types should count more. |
|
|
691
|
+
|
|
692
|
+
```typescript
|
|
693
|
+
import { emitSignal, RiskScoreStrategy } from '@ai-pip/core/isl'
|
|
694
|
+
|
|
695
|
+
// Default: MAX_CONFIDENCE
|
|
696
|
+
const signal = emitSignal(islResult)
|
|
697
|
+
|
|
698
|
+
// Explicit strategy
|
|
699
|
+
const signalSev = emitSignal(islResult, {
|
|
700
|
+
riskScore: { strategy: RiskScoreStrategy.SEVERITY_PLUS_VOLUME }
|
|
701
|
+
})
|
|
702
|
+
|
|
703
|
+
// WEIGHTED_BY_TYPE with custom weights
|
|
704
|
+
const signalWeighted = emitSignal(islResult, {
|
|
705
|
+
riskScore: {
|
|
706
|
+
strategy: RiskScoreStrategy.WEIGHTED_BY_TYPE,
|
|
707
|
+
typeWeights: { 'prompt-injection': 1.2, jailbreak: 1 }
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
The strategy used is stored in **`signal.metadata.strategy`** for auditability. For full API and formulas, see the [ISL layer documentation](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/ISL.md) in the protocol docs.
|
|
713
|
+
|
|
714
|
+
---
|
|
715
|
+
|
|
716
|
+
<a id="example-audit-utilities"></a>
|
|
717
|
+
### Example: Audit and pretty-print utilities
|
|
718
|
+
|
|
719
|
+
The core provides pure functions to format layer results and signals for clear, ordered audit output. Use them for logging, compliance, and debugging:
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
import {
|
|
723
|
+
segment,
|
|
724
|
+
sanitize,
|
|
725
|
+
emitSignal,
|
|
726
|
+
envelope,
|
|
727
|
+
resolveAgentAction,
|
|
728
|
+
buildDecisionReason,
|
|
729
|
+
buildRemovalPlan,
|
|
730
|
+
formatCSLForAudit,
|
|
731
|
+
formatISLForAudit,
|
|
732
|
+
formatISLSignalForAudit,
|
|
733
|
+
formatAALForAudit,
|
|
734
|
+
formatCPEForAudit,
|
|
735
|
+
formatPipelineAudit,
|
|
736
|
+
formatPipelineAuditFull,
|
|
737
|
+
formatPipelineAuditAsJson,
|
|
738
|
+
createAuditRunId,
|
|
739
|
+
buildAuditLogEntry,
|
|
740
|
+
buildFullAuditPayload
|
|
741
|
+
} from '@ai-pip/core'
|
|
742
|
+
import type { AgentPolicy } from '@ai-pip/core'
|
|
743
|
+
|
|
744
|
+
// Run pipeline
|
|
745
|
+
const cslResult = segment({ content: 'User input', source: 'UI', metadata: {} })
|
|
746
|
+
const islResult = sanitize(cslResult)
|
|
747
|
+
const islSignal = emitSignal(islResult)
|
|
748
|
+
const cpeResult = envelope(islResult, 'secret-key')
|
|
749
|
+
|
|
750
|
+
const policy: AgentPolicy = {
|
|
751
|
+
thresholds: { warn: 0.3, block: 0.7 },
|
|
752
|
+
removal: { enabled: true }
|
|
753
|
+
}
|
|
754
|
+
const action = resolveAgentAction(islSignal, policy)
|
|
755
|
+
const reason = buildDecisionReason(action, islSignal, policy)
|
|
756
|
+
const removalPlan = buildRemovalPlan(islSignal, policy)
|
|
757
|
+
|
|
758
|
+
// Pretty-print per layer (ordered, human-readable)
|
|
759
|
+
console.log(formatCSLForAudit(cslResult))
|
|
760
|
+
console.log(formatISLForAudit(islResult))
|
|
761
|
+
console.log(formatISLSignalForAudit(islSignal))
|
|
762
|
+
console.log(formatAALForAudit(reason, removalPlan))
|
|
763
|
+
console.log(formatCPEForAudit(cpeResult))
|
|
764
|
+
|
|
765
|
+
// Full pipeline audit report (CSL → ISL → CPE)
|
|
766
|
+
const fullAudit = formatPipelineAudit(cslResult, islResult, cpeResult, {
|
|
767
|
+
title: 'AI-PIP Pipeline Audit',
|
|
768
|
+
sectionSeparator: '\n\n'
|
|
769
|
+
})
|
|
770
|
+
console.log(fullAudit)
|
|
771
|
+
|
|
772
|
+
// Full pipeline with run id and Signal + AAL (CSL → ISL → Signal → AAL → optional CPE)
|
|
773
|
+
const runId = createAuditRunId()
|
|
774
|
+
const generatedAt = Date.now()
|
|
775
|
+
const fullReport = formatPipelineAuditFull(cslResult, islResult, islSignal, reason, removalPlan, cpeResult, {
|
|
776
|
+
runId,
|
|
777
|
+
generatedAt,
|
|
778
|
+
includeCpe: true,
|
|
779
|
+
title: 'AI-PIP Pipeline Audit (full)'
|
|
780
|
+
})
|
|
781
|
+
console.log(fullReport)
|
|
782
|
+
|
|
783
|
+
// JSON for logs / SIEM / machine consumption
|
|
784
|
+
const payload = buildFullAuditPayload(cslResult, islResult, islSignal, reason, { runId, generatedAt, removalPlan, cpe: cpeResult })
|
|
785
|
+
const jsonReport = formatPipelineAuditAsJson(cslResult, islResult, islSignal, reason, { runId, generatedAt, removalPlan, compact: true })
|
|
786
|
+
logger.info(jsonReport)
|
|
787
|
+
|
|
788
|
+
// Compact log entry (one line per request)
|
|
789
|
+
const logEntry = buildAuditLogEntry(islSignal, reason, { runId, generatedAt })
|
|
790
|
+
logger.info(JSON.stringify(logEntry))
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
**What this example demonstrates:**
|
|
794
|
+
|
|
795
|
+
- **`formatCSLForAudit(result)`**: Formats CSL result (segments, trust, lineage) for audit.
|
|
796
|
+
- **`formatISLForAudit(result)`**: Formats ISL result (segments, sanitization level, metadata, lineage).
|
|
797
|
+
- **`formatISLSignalForAudit(signal)`**: Formats ISL signal (risk score, threats, detections) for audit.
|
|
798
|
+
- **`formatAALForAudit(reason, removalPlan?)`**: Formats AAL decision reason and optional removal plan.
|
|
799
|
+
- **`formatCPEForAudit(result)`**: Formats CPE result (metadata, signature, lineage).
|
|
800
|
+
- **`formatPipelineAudit(csl, isl, cpe, options?)`**: Builds a single full pipeline audit string (CSL → ISL → CPE). Use **`options.includeSignalAndAAL`** with **`options.signal`** and **`options.aalReason`** to include ISL Signal and AAL sections.
|
|
801
|
+
- **`formatPipelineAuditFull(csl, isl, signal, aalReason, removalPlan?, cpe?, options?)`**: Full pipeline report (CSL → ISL → Signal → AAL → optional CPE) with **run id** and **generated at** timestamp; lineage in each section.
|
|
802
|
+
- **Run identifier**: **`createAuditRunId()`** generates a unique run id; pass **`options.runId`** and **`options.generatedAt`** to formatters for correlation across reports and logs.
|
|
803
|
+
- **JSON variant**: **`buildFullAuditPayload(csl, isl, signal, reason, options?)`** returns a JSON-serializable object (runId, generatedAt, summary, sections with lineage). **`formatPipelineAuditAsJson(...)`** returns the JSON string; use **`options.compact: true`** for one-line output (logs, SIEM).
|
|
804
|
+
- **Audit for logs**: **`buildAuditLogEntry(signal, reason, options?)`** returns a compact summary (`runId`, `generatedAtIso`, `action`, `riskScore`, `hasThreats`, `detectionCount`) for one-line logging (e.g. `logger.info(JSON.stringify(entry))`).
|
|
805
|
+
|
|
806
|
+
All formatters accept minimal shapes (layer-agnostic) so you can pass any compatible object. Output is ordered and consistent for compliance and debugging. Lineage is preserved in every section for traceability.
|
|
807
|
+
|
|
808
|
+
<a id="use-cases"></a>
|
|
809
|
+
### Use cases
|
|
810
|
+
|
|
811
|
+
Typical scenarios where AI-PIP core is used:
|
|
812
|
+
|
|
813
|
+
| Use case | Layers involved | Goal |
|
|
814
|
+
|----------|-----------------|------|
|
|
815
|
+
| **Secure user chat** | CSL → ISL → CPE | Segment UI input, sanitize, wrap in envelope before sending to the model. |
|
|
816
|
+
| **Policy-based moderation** | CSL → ISL → emitSignal → AAL | Get risk signal from ISL, resolve ALLOW/WARN/BLOCK; use `buildRemovalPlanFromResult` + `applyRemovalPlan` to get cleaned content for the LLM. |
|
|
817
|
+
| **Audit and compliance** | Shared audit formatters | Pretty-print CSL/ISL/AAL/CPE results; full pipeline with run id (`formatPipelineAuditFull`); JSON variant (`buildFullAuditPayload`, `formatPipelineAuditAsJson`) for SIEM; compact log entry (`buildAuditLogEntry`) for one-line logging. |
|
|
818
|
+
| **DOM / scraped content** | CSL (source: DOM) → ISL → CPE | Treat web content as untrusted (UC), apply aggressive sanitization. |
|
|
819
|
+
| **System instructions** | CSL (source: SYSTEM) → ISL → CPE | Trusted content (TC), minimal sanitization. |
|
|
820
|
+
| **Lineage and forensics** | All layers | Use lineage from results and `filterLineageByStep` / `getLastLineageEntry` for tracing. |
|
|
821
|
+
|
|
822
|
+
**Example: policy-based moderation (ISL + AAL)**
|
|
823
|
+
|
|
824
|
+
```typescript
|
|
825
|
+
const cslResult = segment({ content: userInput, source: 'UI', metadata: {} })
|
|
826
|
+
const islResult = sanitize(cslResult)
|
|
827
|
+
const signal = emitSignal(islResult)
|
|
828
|
+
const action = resolveAgentAction(signal, policy)
|
|
829
|
+
const reason = buildDecisionReason(action, signal, policy)
|
|
830
|
+
const plan = buildRemovalPlan(signal, policy)
|
|
831
|
+
const planFromResult = buildRemovalPlanFromResult(islResult, policy)
|
|
832
|
+
const cleanedResult = applyRemovalPlan(islResult, planFromResult)
|
|
833
|
+
// Use action, reason, plan; send cleanedResult.segments to the LLM when removal is enabled.
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
**Example: audit report**
|
|
837
|
+
|
|
838
|
+
```typescript
|
|
839
|
+
// Text report (CSL → ISL → CPE)
|
|
840
|
+
const report = formatPipelineAudit(cslResult, islResult, cpeResult, {
|
|
841
|
+
title: 'Request Audit',
|
|
842
|
+
sectionSeparator: '\n---\n'
|
|
843
|
+
})
|
|
844
|
+
logger.info(report)
|
|
845
|
+
|
|
846
|
+
// Full report with run id and Signal + AAL
|
|
847
|
+
const runId = createAuditRunId()
|
|
848
|
+
const fullReport = formatPipelineAuditFull(cslResult, islResult, signal, reason, removalPlan, cpeResult, {
|
|
849
|
+
runId, generatedAt: Date.now(), includeCpe: true
|
|
850
|
+
})
|
|
851
|
+
logger.info(fullReport)
|
|
852
|
+
|
|
853
|
+
// JSON for SIEM / machine consumption
|
|
854
|
+
const jsonReport = formatPipelineAuditAsJson(cslResult, islResult, signal, reason, { runId, generatedAt: Date.now(), removalPlan, compact: true })
|
|
855
|
+
logger.info(jsonReport)
|
|
856
|
+
|
|
857
|
+
// One-line log entry per request
|
|
858
|
+
const logEntry = buildAuditLogEntry(signal, reason, { runId, generatedAt: Date.now() })
|
|
859
|
+
logger.info(JSON.stringify(logEntry))
|
|
860
|
+
```
|
|
861
|
+
|
|
532
862
|
<a id="documentation"></a>
|
|
533
863
|
## 📚 Documentation
|
|
534
864
|
|
|
@@ -545,6 +875,7 @@ All AI-PIP protocol documentation is centralized in the [documentation repositor
|
|
|
545
875
|
- **[Core Overview](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/CORE.md)** - Semantic core description
|
|
546
876
|
- **[CSL (Context Segmentation Layer)](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/CSL.md)** - Context segmentation layer
|
|
547
877
|
- **[ISL (Instruction Sanitization Layer)](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/ISL.md)** - Instruction sanitization layer
|
|
878
|
+
- **[AAL (Agent Action Lock)](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/AAL.md)** - Agent Action Lock (hybrid layer)
|
|
548
879
|
- **[CPE (Cryptographic Prompt Envelope)](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/CPE.md)** - Cryptographic prompt envelope
|
|
549
880
|
- **[Shared](https://github.com/AI-PIP/ai-pip-docs/blob/main/docs/core/layers/shared.md)** - Shared features and lineage
|
|
550
881
|
|
|
@@ -556,6 +887,7 @@ All AI-PIP protocol documentation is centralized in the [documentation repositor
|
|
|
556
887
|
### Code-Specific Documentation
|
|
557
888
|
|
|
558
889
|
- **[CHANGELOG](./CHANGELOG.md)** - Package version history
|
|
890
|
+
- **[FEATURE](./FEATURE.md)** - New and modified features by version
|
|
559
891
|
- **[API Reference](#-basic-usage)** - Usage examples in this README
|
|
560
892
|
|
|
561
893
|
<a id="testing"></a>
|
|
@@ -575,7 +907,9 @@ pnpm test:coverage
|
|
|
575
907
|
pnpm test:ui
|
|
576
908
|
```
|
|
577
909
|
|
|
578
|
-
|
|
910
|
+
### Coverage
|
|
911
|
+
- **Current coverage**: 92%+ (CSL, ISL, AAL, CPE, shared)
|
|
912
|
+
|
|
579
913
|
|
|
580
914
|
<a id="development"></a>
|
|
581
915
|
## 🔧 Development
|
|
@@ -750,7 +1084,13 @@ For SDK development updates and roadmap, see the [AI-PIP Documentation Repositor
|
|
|
750
1084
|
|
|
751
1085
|
For complete details and all version history, see [CHANGELOG.md](./CHANGELOG.md).
|
|
752
1086
|
|
|
1087
|
+
<a id="features"></a>
|
|
1088
|
+
## 📋 Features
|
|
1089
|
+
|
|
1090
|
+
Summary of new and modified features per version (aligned with the changelog): **[FEATURE.md](./FEATURE.md)**.
|
|
1091
|
+
|
|
753
1092
|
---
|
|
754
1093
|
|
|
755
|
-
**Current Version**: 0.
|
|
756
|
-
**Status**: Phase 1 - Core Layers (100% completed)
|
|
1094
|
+
**Current Version**: 0.2.0
|
|
1095
|
+
**Status**: Phase 1 - Core Layers (100% completed)
|
|
1096
|
+
**Latest**: Architectural refactor with ISL/AAL separation and signal-based communication
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AAL display constants - semantic mapping for SDK/UI.
|
|
3
|
+
* Used for consistent display of AAL decisions (e.g. colors).
|
|
4
|
+
*/
|
|
5
|
+
import type { AnomalyAction } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Display color for each AAL action.
|
|
8
|
+
* SDK/UI can use this for consistent styling (e.g. green = allow, yellow = warn, red = block).
|
|
9
|
+
*/
|
|
10
|
+
export declare const ACTION_DISPLAY_COLORS: Record<AnomalyAction, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the display color for an AAL action.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getActionDisplayColor(action: AnomalyAction): string;
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|