@ai-pip/core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/README.md +5 -2
  3. package/dist/isl/index.d.ts +2 -0
  4. package/dist/isl/index.d.ts.map +1 -1
  5. package/dist/isl/index.js +2 -0
  6. package/dist/isl/index.js.map +1 -1
  7. package/dist/isl/process/buildISLResult.d.ts +3 -1
  8. package/dist/isl/process/buildISLResult.d.ts.map +1 -1
  9. package/dist/isl/process/buildISLResult.js +3 -1
  10. package/dist/isl/process/buildISLResult.js.map +1 -1
  11. package/dist/isl/sanitize.d.ts.map +1 -1
  12. package/dist/isl/sanitize.js +13 -1
  13. package/dist/isl/sanitize.js.map +1 -1
  14. package/dist/isl/tags/index.d.ts +19 -0
  15. package/dist/isl/tags/index.d.ts.map +1 -0
  16. package/dist/isl/tags/index.js +17 -0
  17. package/dist/isl/tags/index.js.map +1 -0
  18. package/dist/isl/tags/namespace.d.ts +18 -0
  19. package/dist/isl/tags/namespace.d.ts.map +1 -0
  20. package/dist/isl/tags/namespace.js +18 -0
  21. package/dist/isl/tags/namespace.js.map +1 -0
  22. package/dist/isl/tags/serializer.d.ts +39 -0
  23. package/dist/isl/tags/serializer.d.ts.map +1 -0
  24. package/dist/isl/tags/serializer.js +45 -0
  25. package/dist/isl/tags/serializer.js.map +1 -0
  26. package/dist/isl/tags/tag-registry.d.ts +15 -0
  27. package/dist/isl/tags/tag-registry.d.ts.map +1 -0
  28. package/dist/isl/tags/tag-registry.js +17 -0
  29. package/dist/isl/tags/tag-registry.js.map +1 -0
  30. package/dist/isl/tags/threat-tag-type.d.ts +13 -0
  31. package/dist/isl/tags/threat-tag-type.d.ts.map +1 -0
  32. package/dist/isl/tags/threat-tag-type.js +9 -0
  33. package/dist/isl/tags/threat-tag-type.js.map +1 -0
  34. package/dist/isl/tags/threat-tag.d.ts +32 -0
  35. package/dist/isl/tags/threat-tag.d.ts.map +1 -0
  36. package/dist/isl/tags/threat-tag.js +43 -0
  37. package/dist/isl/tags/threat-tag.js.map +1 -0
  38. package/dist/isl/types.d.ts +13 -0
  39. package/dist/isl/types.d.ts.map +1 -1
  40. package/package.json +3 -2
  41. package/dist/AAL/process/applyRemovalPlan.d.ts +0 -23
  42. package/dist/AAL/process/applyRemovalPlan.d.ts.map +0 -1
  43. package/dist/AAL/process/applyRemovalPlan.js +0 -157
  44. package/dist/AAL/process/applyRemovalPlan.js.map +0 -1
  45. package/dist/AAL/process/buildRemovalPlan.d.ts +0 -50
  46. package/dist/AAL/process/buildRemovalPlan.d.ts.map +0 -1
  47. package/dist/AAL/process/buildRemovalPlan.js +0 -116
  48. package/dist/AAL/process/buildRemovalPlan.js.map +0 -1
  49. package/dist/cpe/envelope.d.ts +0 -34
  50. package/dist/cpe/envelope.d.ts.map +0 -1
  51. package/dist/cpe/envelope.js +0 -70
  52. package/dist/cpe/envelope.js.map +0 -1
  53. package/dist/cpe/exceptions/EnvelopeError.d.ts +0 -8
  54. package/dist/cpe/exceptions/EnvelopeError.d.ts.map +0 -1
  55. package/dist/cpe/exceptions/EnvelopeError.js +0 -13
  56. package/dist/cpe/exceptions/EnvelopeError.js.map +0 -1
  57. package/dist/cpe/exceptions/index.d.ts +0 -5
  58. package/dist/cpe/exceptions/index.d.ts.map +0 -1
  59. package/dist/cpe/exceptions/index.js +0 -5
  60. package/dist/cpe/exceptions/index.js.map +0 -1
  61. package/dist/cpe/index.d.ts +0 -24
  62. package/dist/cpe/index.d.ts.map +0 -1
  63. package/dist/cpe/index.js +0 -26
  64. package/dist/cpe/index.js.map +0 -1
  65. package/dist/cpe/types.d.ts +0 -58
  66. package/dist/cpe/types.d.ts.map +0 -1
  67. package/dist/cpe/types.js +0 -5
  68. package/dist/cpe/types.js.map +0 -1
  69. package/dist/cpe/utils.d.ts +0 -38
  70. package/dist/cpe/utils.d.ts.map +0 -1
  71. package/dist/cpe/utils.js +0 -47
  72. package/dist/cpe/utils.js.map +0 -1
  73. package/dist/cpe/value-objects/Metadata.d.ts +0 -32
  74. package/dist/cpe/value-objects/Metadata.d.ts.map +0 -1
  75. package/dist/cpe/value-objects/Metadata.js +0 -65
  76. package/dist/cpe/value-objects/Metadata.js.map +0 -1
  77. package/dist/cpe/value-objects/Nonce.d.ts +0 -33
  78. package/dist/cpe/value-objects/Nonce.d.ts.map +0 -1
  79. package/dist/cpe/value-objects/Nonce.js +0 -44
  80. package/dist/cpe/value-objects/Nonce.js.map +0 -1
  81. package/dist/cpe/value-objects/Signature.d.ts +0 -39
  82. package/dist/cpe/value-objects/Signature.d.ts.map +0 -1
  83. package/dist/cpe/value-objects/Signature.js +0 -60
  84. package/dist/cpe/value-objects/Signature.js.map +0 -1
  85. package/dist/cpe/value-objects/index.d.ts +0 -9
  86. package/dist/cpe/value-objects/index.d.ts.map +0 -1
  87. package/dist/cpe/value-objects/index.js +0 -7
  88. package/dist/cpe/value-objects/index.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-pip/core",
3
- "version": "0.4.0",
4
- "description": "Core implementation of the AI-PIP protocol. Provides layered, zero-trust context processing (CSL, ISL, AAL)",
3
+ "version": "0.5.0",
4
+ "description": "Core implementation of the AI-PIP protocol. Provides layered, zero-trust context processing (CSL, ISL, AAL) and transversal integrity (CPE)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -87,6 +87,7 @@
87
87
  "test:ui": "vitest --ui",
88
88
  "test:coverage": "vitest --coverage",
89
89
  "test:install": "node test-package-install.js",
90
+ "test:tags": "node scripts/test-tags-exhaustive.mjs",
90
91
  "verify-risk": "node scripts/verify-risk-score.mjs",
91
92
  "demo-menu": "node scripts/interactive-risk-menu.mjs",
92
93
  "demo-full": "node scripts/demo-full-flow.mjs",
@@ -1,23 +0,0 @@
1
- /**
2
- * applyRemovalPlan - Applies a removal plan to ISL result (pure, deterministic).
3
- *
4
- * @remarks
5
- * For each segment, only instructions with segmentId === segment.id are applied.
6
- * Each instruction's position is in segment-local coordinates (indices within that
7
- * segment's sanitizedContent). We remove only those ranges from that segment's string,
8
- * then return a new ISLResult. Do not mix positions from one segment with another or
9
- * use document-level offsets; this avoids corrupting legitimate content.
10
- */
11
- import type { RemovalPlan } from './buildRemovalPlan.js';
12
- import type { ISLResult } from '../../isl/types.js';
13
- /**
14
- * Applies a removal plan to an ISL result.
15
- * Produces a new ISLResult with segment sanitizedContent updated (malicious ranges removed).
16
- * Instructions without segmentId are ignored. Positions are clamped to [0, content.length] per segment; invalid or empty ranges are dropped. Lineage and metadata are preserved.
17
- *
18
- * @param islResult - ISL result (segments with sanitizedContent and optional piDetection)
19
- * @param plan - Removal plan from buildRemovalPlanFromResult (must include segmentIds for removal)
20
- * @returns New ISLResult with sanitizedContent updated per segment
21
- */
22
- export declare function applyRemovalPlan(islResult: ISLResult, plan: RemovalPlan): ISLResult;
23
- //# sourceMappingURL=applyRemovalPlan.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applyRemovalPlan.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/applyRemovalPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAA;AAwG/D;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,CAwCnF"}
@@ -1,157 +0,0 @@
1
- /**
2
- * applyRemovalPlan - Applies a removal plan to ISL result (pure, deterministic).
3
- *
4
- * @remarks
5
- * For each segment, only instructions with segmentId === segment.id are applied.
6
- * Each instruction's position is in segment-local coordinates (indices within that
7
- * segment's sanitizedContent). We remove only those ranges from that segment's string,
8
- * then return a new ISLResult. Do not mix positions from one segment with another or
9
- * use document-level offsets; this avoids corrupting legitimate content.
10
- */
11
- /**
12
- * Clamps position ranges to valid [0, contentLength) and drops empty or invalid ranges.
13
- * Ensures 0 <= start <= end <= contentLength and start < end.
14
- */
15
- function clampRangesToContent(ranges, contentLength) {
16
- if (contentLength <= 0 || ranges.length === 0)
17
- return [];
18
- const result = [];
19
- for (const r of ranges) {
20
- const start = Math.max(0, Math.min(Number(r.start), contentLength));
21
- const end = Math.max(0, Math.min(Number(r.end), contentLength));
22
- if (start < end)
23
- result.push({ start, end });
24
- }
25
- return result;
26
- }
27
- /**
28
- * Merges overlapping ranges (start inclusive, end exclusive). Sorted by start.
29
- */
30
- function mergeRanges(ranges) {
31
- if (ranges.length === 0)
32
- return [];
33
- const sorted = [...ranges].sort((a, b) => a.start - b.start);
34
- const merged = [{ start: sorted[0].start, end: sorted[0].end }];
35
- for (let i = 1; i < sorted.length; i++) {
36
- const r = sorted[i];
37
- const last = merged.at(-1);
38
- if (r.start <= last.end) {
39
- merged[merged.length - 1] = { start: last.start, end: Math.max(last.end, r.end) };
40
- }
41
- else {
42
- merged.push({ start: r.start, end: r.end });
43
- }
44
- }
45
- return merged;
46
- }
47
- /** Max gap (chars) between ranges to consider for merging when gap is only punctuation/whitespace */
48
- const MAX_PUNCTUATION_GAP = 10;
49
- /** True if the substring is only whitespace and/or common punctuation (no words). */
50
- function isOnlyPunctuationOrWhitespace(s) {
51
- return /^[\s.,;:!?'"-]*$/.test(s);
52
- }
53
- /**
54
- * Merges consecutive ranges when the gap between them is only punctuation/whitespace,
55
- * so we remove one contiguous block instead of leaving fragments like ", . ".
56
- */
57
- function mergeAdjacentByPunctuation(ranges, content) {
58
- if (ranges.length <= 1)
59
- return [...ranges];
60
- const result = [{ ...ranges[0] }];
61
- for (let i = 1; i < ranges.length; i++) {
62
- const r = ranges[i];
63
- const last = result.at(-1);
64
- const gapStart = last.end;
65
- const gapEnd = r.start;
66
- if (gapEnd > gapStart && gapEnd - gapStart <= MAX_PUNCTUATION_GAP) {
67
- const gap = content.slice(gapStart, gapEnd);
68
- if (isOnlyPunctuationOrWhitespace(gap)) {
69
- result[result.length - 1] = { start: last.start, end: r.end };
70
- continue;
71
- }
72
- }
73
- result.push({ ...r });
74
- }
75
- return result;
76
- }
77
- /**
78
- * Removes given ranges from content. Ranges must be non-overlapping and sorted by start.
79
- */
80
- function removeRanges(content, ranges) {
81
- if (ranges.length === 0)
82
- return content;
83
- let result = '';
84
- let pos = 0;
85
- for (const r of ranges) {
86
- if (r.start > pos)
87
- result += content.slice(pos, r.start);
88
- pos = Math.max(pos, r.end);
89
- }
90
- if (pos < content.length)
91
- result += content.slice(pos);
92
- return result;
93
- }
94
- function assertApplyRemovalPlanArgs(islResult, plan) {
95
- if (islResult == null || typeof islResult !== 'object') {
96
- throw new TypeError('AAL applyRemovalPlan: islResult must be a non-null object');
97
- }
98
- if (!Array.isArray(islResult.segments)) {
99
- throw new TypeError('AAL applyRemovalPlan: islResult.segments must be an array');
100
- }
101
- if (plan == null || typeof plan !== 'object') {
102
- throw new TypeError('AAL applyRemovalPlan: plan must be a non-null object');
103
- }
104
- if (!Array.isArray(plan.instructionsToRemove)) {
105
- throw new TypeError('AAL applyRemovalPlan: plan.instructionsToRemove must be an array');
106
- }
107
- }
108
- /**
109
- * Applies a removal plan to an ISL result.
110
- * Produces a new ISLResult with segment sanitizedContent updated (malicious ranges removed).
111
- * Instructions without segmentId are ignored. Positions are clamped to [0, content.length] per segment; invalid or empty ranges are dropped. Lineage and metadata are preserved.
112
- *
113
- * @param islResult - ISL result (segments with sanitizedContent and optional piDetection)
114
- * @param plan - Removal plan from buildRemovalPlanFromResult (must include segmentIds for removal)
115
- * @returns New ISLResult with sanitizedContent updated per segment
116
- */
117
- export function applyRemovalPlan(islResult, plan) {
118
- assertApplyRemovalPlanArgs(islResult, plan);
119
- if (!plan.shouldRemove || plan.instructionsToRemove.length === 0) {
120
- return islResult;
121
- }
122
- // Group instructions by segmentId. Each instruction's position is segment-local
123
- // (indices within that segment's sanitizedContent). We never use positions from
124
- // one segment on another segment or any global document offset.
125
- const bySegmentId = new Map();
126
- for (const inst of plan.instructionsToRemove) {
127
- if (inst.segmentId == null)
128
- continue;
129
- const list = bySegmentId.get(inst.segmentId) ?? [];
130
- list.push(inst.position);
131
- bySegmentId.set(inst.segmentId, list);
132
- }
133
- if (bySegmentId.size === 0)
134
- return islResult;
135
- // For each segment, take only instructions with segmentId === segment.id,
136
- // apply those ranges only to this segment's sanitizedContent, produce new segment.
137
- const newSegments = islResult.segments.map((seg) => {
138
- const ranges = bySegmentId.get(seg.id);
139
- if (ranges == null || ranges.length === 0)
140
- return seg;
141
- const content = seg.sanitizedContent ?? '';
142
- const len = typeof content === 'string' ? content.length : 0;
143
- const clamped = clampRangesToContent(ranges, len);
144
- if (clamped.length === 0)
145
- return seg;
146
- const merged = mergeRanges(clamped);
147
- const mergedAdjacent = mergeAdjacentByPunctuation(merged, content);
148
- const newContent = removeRanges(content, mergedAdjacent);
149
- return { ...seg, sanitizedContent: newContent };
150
- });
151
- return {
152
- segments: Object.freeze(newSegments),
153
- lineage: islResult.lineage,
154
- metadata: islResult.metadata
155
- };
156
- }
157
- //# sourceMappingURL=applyRemovalPlan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applyRemovalPlan.js","sourceRoot":"","sources":["../../../src/AAL/process/applyRemovalPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH;;;GAGG;AACH,SAAS,oBAAoB,CAC3B,MAA2B,EAC3B,aAAqB;IAErB,IAAI,aAAa,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACxD,MAAM,MAAM,GAAe,EAAE,CAAA;IAC7B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC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K,CAAC;YAAE,OAAO,GAAG,CAAA;QACrD,MAAM,OAAO,GAAG,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAA;QAC1C,MAAM,GAAG,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5D,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QACjD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,GAAG,CAAA;QACpC,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;QACnC,MAAM,cAAc,GAAG,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAClE,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;QACxD,OAAO,EAAE,GAAG,GAAG,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAA;IACjD,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QACpC,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,QAAQ,EAAE,SAAS,CAAC,QAAQ;KAC7B,CAAA;AACH,CAAC"}
@@ -1,50 +0,0 @@
1
- /**
2
- * buildRemovalPlan - Builds a plan for instruction removal
3
- *
4
- * @remarks
5
- * Each instruction in the plan must be tied to one segment and one range in that segment:
6
- * - segmentId: same as segment.id in ISLResult (so applyRemovalPlan knows which segment to cut).
7
- * - position: { start, end } in segment-local coordinates (indices within segment.sanitizedContent).
8
- * So "remove instruction X" means: in the segment with id segmentId, delete exactly [start, end) of that segment's sanitizedContent.
9
- *
10
- * Two entry points:
11
- * - buildRemovalPlan(islSignal, policy): from signal only; no segmentId (descriptive).
12
- * - buildRemovalPlanFromResult(islResult, policy): from result; includes segmentId and segment-local position for applyRemovalPlan.
13
- */
14
- import type { RemovedInstruction } from '../types.js';
15
- import type { AgentPolicy } from '../types.js';
16
- import type { ISLSignal } from '../../isl/signals.js';
17
- import type { ISLResult } from '../../isl/types.js';
18
- /**
19
- * Plan for instruction removal
20
- */
21
- export interface RemovalPlan {
22
- readonly instructionsToRemove: readonly RemovedInstruction[];
23
- readonly shouldRemove: boolean;
24
- readonly removalEnabled: boolean;
25
- }
26
- /**
27
- * Builds a plan for instruction removal from ISL signal (no segment ids).
28
- * Use when you only have the signal; plan is descriptive. For actionable removal use buildRemovalPlanFromResult.
29
- *
30
- * @param islSignal - ISL signal with detections
31
- * @param policy - Agent policy
32
- * @returns RemovalPlan with instructions to remove (no segmentId)
33
- */
34
- export declare function buildRemovalPlan(islSignal: ISLSignal, policy: AgentPolicy): RemovalPlan;
35
- /**
36
- * Builds a plan for instruction removal from ISL result (with segment ids).
37
- * Use with applyRemovalPlan to produce content with malicious ranges removed.
38
- *
39
- * Each instruction is built from one segment only:
40
- * - segmentId = segment.id (so applyRemovalPlan knows which segment to cut).
41
- * - position = detection.position as-is (already segment-local: indices within
42
- * that segment's sanitizedContent, from detectThreats run on that segment).
43
- * No document-concatenated or global offsets are used.
44
- *
45
- * @param islResult - ISL result with segments and per-segment piDetection
46
- * @param policy - Agent policy
47
- * @returns RemovalPlan with instructions to remove (segmentId + segment-local position per instruction)
48
- */
49
- export declare function buildRemovalPlanFromResult(islResult: ISLResult, policy: AgentPolicy): RemovalPlan;
50
- //# sourceMappingURL=buildRemovalPlan.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildRemovalPlan.d.ts","sourceRoot":"","sources":["../../../src/AAL/process/buildRemovalPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,oBAAoB,EAAE,SAAS,kBAAkB,EAAE,CAAA;IAC5D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;CACjC;AA0CD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,WAAW,GAClB,WAAW,CAoBb;AAWD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,WAAW,GAClB,WAAW,CAoBb"}
@@ -1,116 +0,0 @@
1
- /**
2
- * buildRemovalPlan - Builds a plan for instruction removal
3
- *
4
- * @remarks
5
- * Each instruction in the plan must be tied to one segment and one range in that segment:
6
- * - segmentId: same as segment.id in ISLResult (so applyRemovalPlan knows which segment to cut).
7
- * - position: { start, end } in segment-local coordinates (indices within segment.sanitizedContent).
8
- * So "remove instruction X" means: in the segment with id segmentId, delete exactly [start, end) of that segment's sanitizedContent.
9
- *
10
- * Two entry points:
11
- * - buildRemovalPlan(islSignal, policy): from signal only; no segmentId (descriptive).
12
- * - buildRemovalPlanFromResult(islResult, policy): from result; includes segmentId and segment-local position for applyRemovalPlan.
13
- */
14
- function mapDetectionToRemovedInstruction(detection, segmentId) {
15
- return {
16
- type: detection.pattern_type,
17
- pattern: detection.matched_pattern,
18
- position: detection.position,
19
- description: `Detected ${detection.pattern_type} pattern with confidence ${detection.confidence.toFixed(3)}`,
20
- ...(segmentId != null && { segmentId })
21
- };
22
- }
23
- const EMPTY_PLAN_DISABLED = Object.freeze({
24
- instructionsToRemove: Object.freeze([]),
25
- shouldRemove: false,
26
- removalEnabled: false
27
- });
28
- const EMPTY_PLAN_NO_THREATS = Object.freeze({
29
- instructionsToRemove: Object.freeze([]),
30
- shouldRemove: false,
31
- removalEnabled: true
32
- });
33
- function assertPolicyForRemoval(policy) {
34
- if (policy == null || typeof policy !== 'object') {
35
- throw new TypeError('AAL buildRemovalPlan: policy must be a non-null object');
36
- }
37
- const r = policy.removal;
38
- if (r == null || typeof r !== 'object' || typeof r.enabled !== 'boolean') {
39
- throw new TypeError('AAL buildRemovalPlan: policy.removal.enabled must be a boolean');
40
- }
41
- }
42
- function assertISLSignalForRemoval(signal) {
43
- if (signal == null || typeof signal !== 'object') {
44
- throw new TypeError('AAL buildRemovalPlan: islSignal must be a non-null object');
45
- }
46
- }
47
- /**
48
- * Builds a plan for instruction removal from ISL signal (no segment ids).
49
- * Use when you only have the signal; plan is descriptive. For actionable removal use buildRemovalPlanFromResult.
50
- *
51
- * @param islSignal - ISL signal with detections
52
- * @param policy - Agent policy
53
- * @returns RemovalPlan with instructions to remove (no segmentId)
54
- */
55
- export function buildRemovalPlan(islSignal, policy) {
56
- assertPolicyForRemoval(policy);
57
- assertISLSignalForRemoval(islSignal);
58
- if (!policy.removal.enabled)
59
- return EMPTY_PLAN_DISABLED;
60
- if (!islSignal.hasThreats)
61
- return EMPTY_PLAN_NO_THREATS;
62
- const detections = islSignal.piDetection?.detections;
63
- if (!Array.isArray(detections) || detections.length === 0) {
64
- return EMPTY_PLAN_NO_THREATS;
65
- }
66
- const instructionsToRemove = detections.map((d) => mapDetectionToRemovedInstruction(d));
67
- return {
68
- instructionsToRemove: Object.freeze(instructionsToRemove),
69
- shouldRemove: instructionsToRemove.length > 0,
70
- removalEnabled: true
71
- };
72
- }
73
- function assertISLResultForRemoval(islResult) {
74
- if (islResult == null || typeof islResult !== 'object') {
75
- throw new TypeError('AAL buildRemovalPlanFromResult: islResult must be a non-null object');
76
- }
77
- if (!Array.isArray(islResult.segments)) {
78
- throw new TypeError('AAL buildRemovalPlanFromResult: islResult.segments must be an array');
79
- }
80
- }
81
- /**
82
- * Builds a plan for instruction removal from ISL result (with segment ids).
83
- * Use with applyRemovalPlan to produce content with malicious ranges removed.
84
- *
85
- * Each instruction is built from one segment only:
86
- * - segmentId = segment.id (so applyRemovalPlan knows which segment to cut).
87
- * - position = detection.position as-is (already segment-local: indices within
88
- * that segment's sanitizedContent, from detectThreats run on that segment).
89
- * No document-concatenated or global offsets are used.
90
- *
91
- * @param islResult - ISL result with segments and per-segment piDetection
92
- * @param policy - Agent policy
93
- * @returns RemovalPlan with instructions to remove (segmentId + segment-local position per instruction)
94
- */
95
- export function buildRemovalPlanFromResult(islResult, policy) {
96
- assertPolicyForRemoval(policy);
97
- assertISLResultForRemoval(islResult);
98
- if (!policy.removal.enabled)
99
- return EMPTY_PLAN_DISABLED;
100
- const instructionsToRemove = [];
101
- for (const segment of islResult.segments) {
102
- const detections = segment.piDetection?.detections;
103
- if (!Array.isArray(detections) || detections.length === 0)
104
- continue;
105
- for (const d of detections) {
106
- // position is segment-local (from detectThreats on this segment's sanitizedContent)
107
- instructionsToRemove.push(mapDetectionToRemovedInstruction(d, segment.id));
108
- }
109
- }
110
- return {
111
- instructionsToRemove: Object.freeze(instructionsToRemove),
112
- shouldRemove: instructionsToRemove.length > 0,
113
- removalEnabled: true
114
- };
115
- }
116
- //# sourceMappingURL=buildRemovalPlan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildRemovalPlan.js","sourceRoot":"","sources":["../../../src/AAL/process/buildRemovalPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiBH,SAAS,gCAAgC,CACvC,SAAsB,EACtB,SAAkB;IAElB,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,YAAY;QAC5B,OAAO,EAAE,SAAS,CAAC,eAAe;QAClC,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,WAAW,EAAE,YAAY,SAAS,CAAC,YAAY,4BAA4B,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC5G,GAAG,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,CAAC;KACxC,CAAA;AAC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,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QACnE,KAAK,MAAM,CAAC,IAAI,UAA2B,EAAE,CAAC;YAC5C,oFAAoF;YACpF,oBAAoB,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAC5E,CAAC;IACH,CAAC;IACD,OAAO;QACL,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACzD,YAAY,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC;QAC7C,cAAc,EAAE,IAAI;KACrB,CAAA;AACH,CAAC"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Genera el envoltorio criptográfico (CPEEvelope) - función pura principal de CPE
3
- *
4
- * @remarks
5
- * Esta es la función principal de CPE. Genera un envoltorio criptográfico
6
- * que garantiza la integridad y autenticidad del prompt procesado.
7
- *
8
- * **Funciones:**
9
- * - Genera metadata de seguridad (timestamp, nonce, versión)
10
- * - Firma criptográficamente el contenido con HMAC-SHA256
11
- * - Encapsula el contenido sanitizado con metadata
12
- * - Preserva el linaje completo para auditoría
13
- *
14
- * @param islResult - Resultado de ISL con contenido sanitizado
15
- * @param secretKey - Clave secreta para HMAC (debe ser proporcionada por el SDK)
16
- * @returns CPEResult con el envelope criptográfico
17
- *
18
- * @throws {EnvelopeError} Si la generación del envelope falla
19
- *
20
- * @example
21
- * ```typescript
22
- * const cpeResult = envelope(islResult, secretKey)
23
- *
24
- * // cpeResult.envelope contiene:
25
- * // - content: contenido sanitizado serializado
26
- * // - signature: firma HMAC-SHA256
27
- * // - metadata: timestamp, nonce, versión
28
- * // - lineage: linaje completo
29
- * ```
30
- */
31
- import type { ISLResult } from '../isl/types.js';
32
- import type { CPEResult } from './types.js';
33
- export declare function envelope(islResult: ISLResult, secretKey: string): CPEResult;
34
- //# sourceMappingURL=envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/cpe/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,YAAY,CAAA;AAUvD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CAwE3E"}
@@ -1,70 +0,0 @@
1
- import { createNonce } from './value-objects/Nonce.js';
2
- import { createMetadata } from './value-objects/Metadata.js';
3
- import { createSignature } from './value-objects/Signature.js';
4
- import { EnvelopeError } from './exceptions/index.js';
5
- // Serialización NO es core - va al SDK
6
- // El core solo define la estructura del envelope
7
- import { addLineageEntries } from '../shared/lineage.js';
8
- import { createLineageEntry } from '../csl/value-objects/LineageEntry.js';
9
- export function envelope(islResult, secretKey) {
10
- const startTime = Date.now();
11
- try {
12
- // 1. Validar input
13
- if (!islResult?.segments?.length) {
14
- throw new EnvelopeError('ISLResult must contain at least one segment');
15
- }
16
- if (!secretKey || secretKey.length === 0) {
17
- throw new EnvelopeError('Secret key is required for envelope generation');
18
- }
19
- // 2. Generar metadata de seguridad
20
- const timestamp = Date.now();
21
- const nonce = createNonce();
22
- const metadata = createMetadata(timestamp, nonce);
23
- // 3. Preparar payload semántico (contenido procesado por ISL)
24
- // El payload puede ser cualquier estructura que represente el contenido procesado
25
- const payload = {
26
- segments: islResult.segments.map((segment) => ({
27
- id: segment.id,
28
- content: segment.sanitizedContent,
29
- trust: segment.trust.value,
30
- sanitizationLevel: segment.sanitizationLevel,
31
- })),
32
- };
33
- // 4. Generar firma criptográfica HMAC-SHA256
34
- // Nota: La serialización del contenido para firma debe hacerse en el SDK
35
- // El core solo define que se debe firmar el payload + metadata
36
- // Por ahora, serializamos de forma básica para mantener funcionalidad
37
- const algorithm = 'HMAC-SHA256';
38
- const signableContent = JSON.stringify({
39
- payload,
40
- metadata,
41
- algorithm
42
- });
43
- const signatureVO = createSignature(signableContent, secretKey);
44
- // 5. Actualizar linaje con entrada CPE
45
- const cpeLineageEntry = createLineageEntry('CPE', timestamp);
46
- const updatedLineage = addLineageEntries(islResult.lineage, [cpeLineageEntry]);
47
- // 9. Construir envelope según especificación
48
- const envelope = {
49
- payload,
50
- metadata,
51
- signature: {
52
- value: signatureVO.value,
53
- algorithm: signatureVO.algorithm,
54
- },
55
- lineage: updatedLineage,
56
- };
57
- const processingTime = Date.now() - startTime;
58
- return {
59
- envelope,
60
- processingTimeMs: processingTime,
61
- };
62
- }
63
- catch (error) {
64
- if (error instanceof EnvelopeError) {
65
- throw error;
66
- }
67
- throw new EnvelopeError(`Failed to generate envelope: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
68
- }
69
- }
70
- //# sourceMappingURL=envelope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/cpe/envelope.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,uCAAuC;AACvC,iDAAiD;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAEzE,MAAM,UAAU,QAAQ,CAAC,SAAoB,EAAE,SAAiB;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAE5B,IAAI,CAAC;QACH,mBAAmB;QACnB,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YACjC,MAAM,IAAI,aAAa,CAAC,6CA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E,WAAW,CAAC,KAAK;gBACxB,SAAS,EAAE,WAAW,CAAC,SAAS;aACjC;YACD,OAAO,EAAE,cAAc;SACxB,CAAA;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QAE7C,OAAO;YACL,QAAQ;YACR,gBAAgB,EAAE,cAAc;SACjC,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACnC,MAAM,KAAK,CAAA;QACb,CAAC;QACD,MAAM,IAAI,aAAa,CACrB,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAC1F,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -1,8 +0,0 @@
1
- /**
2
- * EnvelopeError - Error al generar el envelope criptográfico
3
- */
4
- export declare class EnvelopeError extends Error {
5
- readonly cause?: Error | undefined;
6
- constructor(message: string, cause?: Error | undefined);
7
- }
8
- //# sourceMappingURL=EnvelopeError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvelopeError.d.ts","sourceRoot":"","sources":["../../../src/cpe/exceptions/EnvelopeError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;aACO,KAAK,CAAC,EAAE,KAAK;gBAA9C,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,KAAK,YAAA;CAK3D"}
@@ -1,13 +0,0 @@
1
- /**
2
- * EnvelopeError - Error al generar el envelope criptográfico
3
- */
4
- export class EnvelopeError extends Error {
5
- cause;
6
- constructor(message, cause) {
7
- super(message);
8
- this.cause = cause;
9
- this.name = 'EnvelopeError';
10
- Object.setPrototypeOf(this, EnvelopeError.prototype);
11
- }
12
- }
13
- //# sourceMappingURL=EnvelopeError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvelopeError.js","sourceRoot":"","sources":["../../../src/cpe/exceptions/EnvelopeError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACO;IAA7C,YAAY,OAAe,EAAkB,KAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QAD6B,UAAK,GAAL,KAAK,CAAQ;QAExD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IACtD,CAAC;CACF"}
@@ -1,5 +0,0 @@
1
- /**
2
- * CPE Exceptions - Exports
3
- */
4
- export { EnvelopeError } from './EnvelopeError.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cpe/exceptions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
@@ -1,5 +0,0 @@
1
- /**
2
- * CPE Exceptions - Exports
3
- */
4
- export { EnvelopeError } from './EnvelopeError.js';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cpe/exceptions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
@@ -1,24 +0,0 @@
1
- /**
2
- * CPE (Cryptographic Prompt Envelope) - Core Semántico
3
- *
4
- * @remarks
5
- * Este es el core semántico de CPE. Solo contiene:
6
- * - Funciones puras (sin estado)
7
- * - Value objects inmutables
8
- * - Tipos y excepciones
9
- *
10
- * **Funciones principales:**
11
- * - Generación de metadata de seguridad (timestamp, nonce, versión)
12
- * - Firma criptográfica HMAC-SHA256
13
- * - Construcción del envelope criptográfico
14
- * - Preservación del linaje completo
15
- */
16
- export { envelope } from './envelope.js';
17
- export { createNonce, isValidNonce, equalsNonce } from './value-objects/Nonce.js';
18
- export type { Nonce } from './value-objects/Nonce.js';
19
- export { createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION } from './value-objects/Metadata.js';
20
- export { createSignature } from './value-objects/Signature.js';
21
- export type { SignatureVO } from './value-objects/Signature.js';
22
- export { EnvelopeError } from './exceptions/EnvelopeError.js';
23
- export type { ProtocolVersion, Timestamp, NonceValue, SignatureAlgorithm, Signature, CPEMetadata, CPEEvelope, CPEResult } from './types.js';
24
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cpe/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjF,YAAY,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AACvG,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAG/D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAG7D,YAAY,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAA"}
package/dist/cpe/index.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * CPE (Cryptographic Prompt Envelope) - Core Semántico
3
- *
4
- * @remarks
5
- * Este es el core semántico de CPE. Solo contiene:
6
- * - Funciones puras (sin estado)
7
- * - Value objects inmutables
8
- * - Tipos y excepciones
9
- *
10
- * **Funciones principales:**
11
- * - Generación de metadata de seguridad (timestamp, nonce, versión)
12
- * - Firma criptográfica HMAC-SHA256
13
- * - Construcción del envelope criptográfico
14
- * - Preservación del linaje completo
15
- */
16
- // Funciones puras principales
17
- export { envelope } from './envelope.js';
18
- // Value objects
19
- export { createNonce, isValidNonce, equalsNonce } from './value-objects/Nonce.js';
20
- export { createMetadata, isValidMetadata, CURRENT_PROTOCOL_VERSION } from './value-objects/Metadata.js';
21
- export { createSignature } from './value-objects/Signature.js';
22
- // Exceptions
23
- export { EnvelopeError } from './exceptions/EnvelopeError.js';
24
- // Serialización y verificación NO son core - van al SDK
25
- // El core solo define la estructura del envelope, no implementa serialización
26
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cpe/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8BAA8B;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEjF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AACvG,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAG9D,aAAa;AACb,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAc7D,wDAAwD;AACxD,8EAA8E"}