@ai-pip/core 0.2.0 → 0.4.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 +106 -3
- package/README.md +52 -951
- 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 +5 -4
- package/dist/AAL/index.d.ts.map +1 -1
- package/dist/AAL/index.js +4 -2
- package/dist/AAL/index.js.map +1 -1
- package/dist/AAL/process/applyRemovalPlan.d.ts +23 -0
- package/dist/AAL/process/applyRemovalPlan.d.ts.map +1 -0
- package/dist/AAL/process/applyRemovalPlan.js +157 -0
- package/dist/AAL/process/applyRemovalPlan.js.map +1 -0
- package/dist/AAL/process/buildDecisionReason.d.ts.map +1 -1
- package/dist/AAL/process/buildDecisionReason.js +24 -4
- package/dist/AAL/process/buildDecisionReason.js.map +1 -1
- package/dist/AAL/process/buildRemediationPlan.d.ts +22 -0
- package/dist/AAL/process/buildRemediationPlan.d.ts.map +1 -0
- package/dist/AAL/process/buildRemediationPlan.js +81 -0
- package/dist/AAL/process/buildRemediationPlan.js.map +1 -0
- package/dist/AAL/process/buildRemovalPlan.d.ts +27 -9
- package/dist/AAL/process/buildRemovalPlan.d.ts.map +1 -1
- package/dist/AAL/process/buildRemovalPlan.js +95 -29
- package/dist/AAL/process/buildRemovalPlan.js.map +1 -1
- package/dist/AAL/process/index.d.ts +2 -2
- package/dist/AAL/process/index.d.ts.map +1 -1
- package/dist/AAL/process/index.js +2 -1
- package/dist/AAL/process/index.js.map +1 -1
- package/dist/AAL/process/resolveAgentAction.d.ts.map +1 -1
- package/dist/AAL/process/resolveAgentAction.js +13 -0
- package/dist/AAL/process/resolveAgentAction.js.map +1 -1
- package/dist/AAL/process/validatePolicy.d.ts +20 -0
- package/dist/AAL/process/validatePolicy.d.ts.map +1 -0
- package/dist/AAL/process/validatePolicy.js +40 -0
- package/dist/AAL/process/validatePolicy.js.map +1 -0
- package/dist/AAL/types.d.ts +18 -31
- package/dist/AAL/types.d.ts.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- 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 +8 -1
- package/dist/isl/index.d.ts.map +1 -1
- package/dist/isl/index.js +5 -0
- package/dist/isl/index.js.map +1 -1
- package/dist/isl/process/emitSignal.d.ts +19 -10
- package/dist/isl/process/emitSignal.d.ts.map +1 -1
- package/dist/isl/process/emitSignal.js +25 -23
- package/dist/isl/process/emitSignal.js.map +1 -1
- package/dist/isl/process/index.d.ts +1 -0
- package/dist/isl/process/index.d.ts.map +1 -1
- 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 +8 -1
- package/dist/isl/sanitize.d.ts.map +1 -1
- package/dist/isl/sanitize.js +13 -5
- package/dist/isl/sanitize.js.map +1 -1
- package/dist/isl/signals.d.ts +16 -1
- package/dist/isl/signals.d.ts.map +1 -1
- package/dist/isl/signals.js +4 -2
- package/dist/isl/signals.js.map +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/index.d.ts +2 -2
- package/dist/isl/value-objects/index.d.ts.map +1 -1
- package/dist/isl/value-objects/index.js +1 -1
- package/dist/isl/value-objects/index.js.map +1 -1
- package/dist/shared/audit.d.ts +126 -28
- package/dist/shared/audit.d.ts.map +1 -1
- package/dist/shared/audit.js +322 -44
- package/dist/shared/audit.js.map +1 -1
- package/dist/shared/envelope/envelope.d.ts +23 -0
- package/dist/shared/envelope/envelope.d.ts.map +1 -0
- package/dist/shared/envelope/envelope.js +58 -0
- package/dist/shared/envelope/envelope.js.map +1 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.d.ts +8 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.d.ts.map +1 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.js +13 -0
- package/dist/shared/envelope/exceptions/EnvelopeError.js.map +1 -0
- package/dist/shared/envelope/exceptions/index.d.ts +2 -0
- package/dist/shared/envelope/exceptions/index.d.ts.map +1 -0
- package/dist/shared/envelope/exceptions/index.js +2 -0
- package/dist/shared/envelope/exceptions/index.js.map +1 -0
- package/dist/shared/envelope/index.d.ts +18 -0
- package/dist/shared/envelope/index.d.ts.map +1 -0
- package/dist/shared/envelope/index.js +15 -0
- package/dist/shared/envelope/index.js.map +1 -0
- package/dist/shared/envelope/types.d.ts +45 -0
- package/dist/shared/envelope/types.d.ts.map +1 -0
- package/dist/shared/envelope/types.js +10 -0
- package/dist/shared/envelope/types.js.map +1 -0
- package/dist/shared/envelope/value-objects/Metadata.d.ts +27 -0
- package/dist/shared/envelope/value-objects/Metadata.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Metadata.js +57 -0
- package/dist/shared/envelope/value-objects/Metadata.js.map +1 -0
- package/dist/shared/envelope/value-objects/Nonce.d.ts +26 -0
- package/dist/shared/envelope/value-objects/Nonce.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Nonce.js +38 -0
- package/dist/shared/envelope/value-objects/Nonce.js.map +1 -0
- package/dist/shared/envelope/value-objects/Signature.d.ts +28 -0
- package/dist/shared/envelope/value-objects/Signature.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/Signature.js +50 -0
- package/dist/shared/envelope/value-objects/Signature.js.map +1 -0
- package/dist/shared/envelope/value-objects/index.d.ts +9 -0
- package/dist/shared/envelope/value-objects/index.d.ts.map +1 -0
- package/dist/shared/envelope/value-objects/index.js +7 -0
- package/dist/shared/envelope/value-objects/index.js.map +1 -0
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.js.map +1 -1
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,109 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - (unreleased)
|
|
11
|
+
|
|
12
|
+
### ✨ Added
|
|
13
|
+
|
|
14
|
+
- **AAL – Remediation plan (what to clean, not how)**
|
|
15
|
+
- `buildRemediationPlan(islResult, policy)`: builds a **RemediationPlan** describing *what* to clean (target segment IDs, goals, constraints). The SDK or an AI tool performs the actual cleanup.
|
|
16
|
+
- **RemediationPlan**: `strategy: 'AI_CLEANUP'`, `goals: string[]` (e.g. `remove_prompt_injection`, `remove_role_hijacking`), `constraints: string[]` (e.g. `preserve_user_intent`, `do_not_add_information`, `do_not_change_language`), `targetSegments: string[]` (segment IDs with detections), `needsRemediation: boolean`.
|
|
17
|
+
- Policy: **`remediation: { enabled: boolean }`** (replaces `removal`).
|
|
18
|
+
|
|
19
|
+
- **Shared – Audit with remediation plan**
|
|
20
|
+
- **RemediationPlanLike** (shared type) for audit payloads; same shape as RemediationPlan.
|
|
21
|
+
- `formatPipelineAuditFull(..., remediationPlan?, cpe?, options?)` and `buildFullAuditPayload` / `formatPipelineAuditAsJson` accept **`remediationPlan`** in options (replacing removal plan).
|
|
22
|
+
- `formatAALForAudit(reason, remediationPlan?)` documents the remediation plan in the AAL section.
|
|
23
|
+
|
|
24
|
+
- **CPE – Transversal (documented and clarified)**
|
|
25
|
+
- CPE (Cryptographic Prompt Envelope) is **transversal**: it **ensures the integrity of each layer** for greater security. It is not a sequential processing layer but a shared capability that wraps pipeline output (e.g. ISL or AAL result) with a cryptographic envelope (nonce, metadata, HMAC-SHA256), so that the result of each layer can be verified and tampering detected. Implementation lives in **`shared/envelope`**; the package exports it as **`@ai-pip/core/cpe`** for backward compatibility. Use `envelope(islResult, secretKey)` to wrap any pipeline result.
|
|
26
|
+
|
|
27
|
+
### 🗑️ Removed
|
|
28
|
+
|
|
29
|
+
- **AAL – Removal plan and application (moved to SDK)**
|
|
30
|
+
- **Removed**: `buildRemovalPlan`, `buildRemovalPlanFromResult`, `applyRemovalPlan`, **RemovalPlan**, **RemovedInstruction**.
|
|
31
|
+
- The core no longer performs instruction removal; it only produces a remediation plan. The SDK (or an AI cleanup tool) uses the plan to clean the content.
|
|
32
|
+
|
|
33
|
+
### 🔄 Changed
|
|
34
|
+
|
|
35
|
+
- **AgentPolicy**: `removal: { enabled }` → **`remediation: { enabled }`**.
|
|
36
|
+
- **Audit**: All formatters and payloads use **remediationPlan** / **RemediationPlanLike** instead of removal plan / RemovalPlanLike.
|
|
37
|
+
|
|
38
|
+
### 📚 Documentation
|
|
39
|
+
|
|
40
|
+
- **README.md**: Examples and use cases updated to remediation (buildRemediationPlan, RemediationPlan, policy.remediation); audit section uses remediationPlan; SDK responsibility clarified (remediation execution, e.g. AI cleanup). New subsection *CPE as transversal* in Architecture: CPE ensures the **integrity of each layer** for greater security (shared/envelope, export `@ai-pip/core/cpe`); pipeline clarified (CSL → ISL → optional AAL; CPE wraps result for verification).
|
|
41
|
+
- **FEATURE.md**: 0.4.0 section with new APIs, removed APIs, and CPE transversal; tables updated for remediation.
|
|
42
|
+
|
|
43
|
+
### 📎 More information
|
|
44
|
+
|
|
45
|
+
See **[FEATURE.md](./FEATURE.md)** for API details.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## [0.3.0] - (unreleased)
|
|
50
|
+
|
|
51
|
+
### ✨ Added
|
|
52
|
+
|
|
53
|
+
- **ISL – Threat detection**
|
|
54
|
+
- `detectThreats(content, options?)`: pure, deterministic function returning `readonly PiDetection[]`.
|
|
55
|
+
- Default patterns for known attack surfaces (prompt-injection, jailbreak, role hijacking, script_like, hidden_text); expanded set (~287 patterns).
|
|
56
|
+
- Integration in `sanitize`: each segment may carry `piDetection` (`PiDetectionResult`).
|
|
57
|
+
- Option `SanitizeOptions.detectThreatsOptions` for custom patterns or limits (`patterns`, `maxTotal`, `maxPerPattern`).
|
|
58
|
+
- `getDefaultThreatPatterns()`: returns the default set (cached, frozen).
|
|
59
|
+
- `THREAT_TYPES` and type `ThreatType` for deterministic taxonomy.
|
|
60
|
+
|
|
61
|
+
- **ISL – Risk score strategies**
|
|
62
|
+
- Enum `RiskScoreStrategy`: `MAX_CONFIDENCE`, `SEVERITY_PLUS_VOLUME`, `WEIGHTED_BY_TYPE`.
|
|
63
|
+
- Pure calculators: `maxConfidenceCalculator`, `severityPlusVolumeCalculator`, `weightedByTypeCalculator`, `defaultWeightedByTypeCalculator`.
|
|
64
|
+
- `getCalculator(strategy, typeWeights?)`: returns the registered calculator for the strategy.
|
|
65
|
+
- Strategy fixed at `emitSignal`; reflected in `ISLSignal.metadata.strategy` for audit.
|
|
66
|
+
|
|
67
|
+
- **emitSignal – Risk score options**
|
|
68
|
+
- `EmitSignalOptions`: `timestamp?`, `riskScore?: { strategy, typeWeights? }`.
|
|
69
|
+
- Default: `RiskScoreStrategy.MAX_CONFIDENCE`.
|
|
70
|
+
- Backward compatibility: `emitSignal(islResult, timestamp)` still supported.
|
|
71
|
+
|
|
72
|
+
- **ISLSignal – Strategy metadata**
|
|
73
|
+
- `ISLSignal.metadata?: { strategy: RiskScoreStrategy }` for traceability.
|
|
74
|
+
- `createISLSignal(..., metadata?)` accepts optional fourth argument `metadata`.
|
|
75
|
+
|
|
76
|
+
- **AAL – Actionable removal plan**
|
|
77
|
+
- `buildRemovalPlanFromResult(islResult, policy)`: builds `RemovalPlan` from `ISLResult` with `segmentId` per instruction.
|
|
78
|
+
- `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`.
|
|
79
|
+
- `RemovedInstruction.segmentId?`: optional, present when the plan is built from `ISLResult`.
|
|
80
|
+
- Guards in `resolveAgentAction`, `resolveAgentActionWithScore`, `buildDecisionReason`, `buildRemovalPlan`, and `buildRemovalPlanFromResult` for safe handling of detections and signals.
|
|
81
|
+
|
|
82
|
+
- **AAL – Resolve action with score**
|
|
83
|
+
- `resolveAgentActionWithScore(islSignal, policy)`: returns `{ action, anomalyScore }` for SDK/audit use.
|
|
84
|
+
|
|
85
|
+
- **AAL – Colors for UI/audit**
|
|
86
|
+
- `ACTION_DISPLAY_COLORS` and `getActionDisplayColor(action)` for ALLOW/WARN/BLOCK.
|
|
87
|
+
|
|
88
|
+
- **Shared – Audit improvements (run id, JSON, logs, full pipeline)**
|
|
89
|
+
- **Run identifier**: `createAuditRunId()` generates a unique run id; full-pipeline formatters accept `options.runId` and `options.generatedAt` for correlation across reports and logs.
|
|
90
|
+
- **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.
|
|
91
|
+
- **formatPipelineAudit** extended: `options.includeSignalAndAAL`, `options.signal`, `options.aalReason`, `options.removalPlan` to include ISL Signal and AAL sections in the pipeline report.
|
|
92
|
+
- **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).
|
|
93
|
+
- **Audit for logs**: `buildAuditLogEntry(signal, reason, options?)` returns a compact summary (runId, generatedAtIso, action, riskScore, hasThreats, detectionCount) for one-line logging.
|
|
94
|
+
- Types: `AuditRunInfo`, `AuditLogSummary`, `FullPipelineAuditOptions`, `PipelineAuditJsonOptions`.
|
|
95
|
+
|
|
96
|
+
### 🔄 Changed
|
|
97
|
+
|
|
98
|
+
- **sanitize (ISL)**: optional second argument `SanitizeOptions`; uses `detectThreats` per segment and assigns `piDetection` when detections exist; option `detectThreatsOptions` for patterns or limits.
|
|
99
|
+
- **emitSignal (ISL)**: second argument may be `EmitSignalOptions` (object) or `number` (timestamp); computes risk score with configured strategy; includes `metadata.strategy` on the signal.
|
|
100
|
+
- **RemovedInstruction (AAL)**: `type` is now `string` (any `pattern_type`); added `segmentId?: string`.
|
|
101
|
+
|
|
102
|
+
### 📚 Documentation
|
|
103
|
+
|
|
104
|
+
- **FEATURE.md**: per-version detail of new and modified features; table of methods/APIs changed in 0.3.0 with description of each change.
|
|
105
|
+
- **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.
|
|
106
|
+
|
|
107
|
+
### 📎 More information
|
|
108
|
+
|
|
109
|
+
For specific method signatures and API changes in 0.3.0, see **[FEATURE.md](./FEATURE.md)**.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
10
113
|
## [0.2.0] - 2026-01-26
|
|
11
114
|
|
|
12
115
|
### ♻️ Architectural Refactor - ISL / AAL Separation
|
|
@@ -161,7 +264,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
161
264
|
|
|
162
265
|
**Problem**: When importing types from `@ai-pip/core` in SDK projects, TypeScript could not resolve nested type properties:
|
|
163
266
|
- `this.data.trust.value` appeared as `any` instead of `TrustLevelType`
|
|
164
|
-
- No
|
|
267
|
+
- No autocomplete for nested properties
|
|
165
268
|
- Type inference failed for complex types
|
|
166
269
|
|
|
167
270
|
**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.
|
|
@@ -173,7 +276,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
173
276
|
|
|
174
277
|
**Impact**:
|
|
175
278
|
- ✅ Nested types now resolve correctly
|
|
176
|
-
- ✅
|
|
279
|
+
- ✅ Autocomplete works for all type properties
|
|
177
280
|
- ✅ Type inference works correctly in consuming projects
|
|
178
281
|
- ✅ Better compatibility with Node.js ESM module resolution
|
|
179
282
|
|
|
@@ -350,6 +453,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
350
453
|
|
|
351
454
|
---
|
|
352
455
|
|
|
353
|
-
**Current Version**: 0.
|
|
456
|
+
**Current Version**: 0.4.0
|
|
354
457
|
**Status**: Phase 1 - Core Layers (100% completed)
|
|
355
458
|
|