@highflame/policy 1.1.3 → 1.2.1

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 (55) hide show
  1. package/dist/actions.gen.d.ts +21 -0
  2. package/dist/actions.gen.d.ts.map +1 -1
  3. package/dist/actions.gen.js +21 -0
  4. package/dist/actions.gen.js.map +1 -1
  5. package/dist/builder.d.ts +47 -10
  6. package/dist/builder.d.ts.map +1 -1
  7. package/dist/builder.js.map +1 -1
  8. package/dist/engine.d.ts +37 -0
  9. package/dist/engine.d.ts.map +1 -1
  10. package/dist/engine.js +99 -0
  11. package/dist/engine.js.map +1 -1
  12. package/dist/engine.test.d.ts +8 -0
  13. package/dist/engine.test.d.ts.map +1 -0
  14. package/dist/engine.test.js +190 -0
  15. package/dist/engine.test.js.map +1 -0
  16. package/dist/entities.gen.d.ts +4 -0
  17. package/dist/entities.gen.d.ts.map +1 -1
  18. package/dist/entities.gen.js +4 -0
  19. package/dist/entities.gen.js.map +1 -1
  20. package/dist/errors.d.ts +102 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +127 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/parser.d.ts +34 -0
  29. package/dist/parser.d.ts.map +1 -0
  30. package/dist/parser.js +393 -0
  31. package/dist/parser.js.map +1 -0
  32. package/dist/parser.test.d.ts +8 -0
  33. package/dist/parser.test.d.ts.map +1 -0
  34. package/dist/parser.test.js +143 -0
  35. package/dist/parser.test.js.map +1 -0
  36. package/dist/schema.gen.d.ts +1 -1
  37. package/dist/schema.gen.d.ts.map +1 -1
  38. package/dist/schema.gen.js +331 -17
  39. package/dist/schema.gen.js.map +1 -1
  40. package/dist/types.d.ts +1 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/types.js +2 -0
  43. package/dist/types.js.map +1 -1
  44. package/package.json +8 -2
  45. package/src/actions.gen.ts +21 -0
  46. package/src/builder.ts +52 -10
  47. package/src/engine.test.ts +371 -0
  48. package/src/engine.ts +145 -0
  49. package/src/entities.gen.ts +4 -0
  50. package/src/errors.ts +195 -0
  51. package/src/index.ts +2 -0
  52. package/src/parser.test.ts +169 -0
  53. package/src/parser.ts +517 -0
  54. package/src/schema.gen.ts +331 -17
  55. package/src/types.ts +3 -0
package/src/schema.gen.ts CHANGED
@@ -32,7 +32,7 @@ entity User {
32
32
 
33
33
  // AI agent or bot
34
34
  entity Agent {
35
- // Agent type: "llm", "scanner", "bot"
35
+ // Agent type: "llm", "scanner", "bot", "coding_assistant"
36
36
  agent_type: String,
37
37
  };
38
38
 
@@ -130,37 +130,90 @@ entity Package {
130
130
  version: String,
131
131
  };
132
132
 
133
+ // Git branch (for branch protection policies)
134
+ entity GitBranch {
135
+ // Branch name (e.g., "main", "develop", "feature/xyz")
136
+ branch_name: String,
137
+ // Whether this is a protected branch
138
+ is_protected: Bool,
139
+ };
140
+
141
+ // LLM Model (for model-specific policies)
142
+ entity Model {
143
+ // Model name (e.g., "gpt-4", "claude-3-opus")
144
+ model_name: String,
145
+ // Provider (e.g., "openai", "anthropic", "google")
146
+ provider: String,
147
+ // Whether model is in preview/beta
148
+ is_preview: Bool,
149
+ };
150
+
151
+ // External API endpoint (for external service calls)
152
+ entity ExternalAPI {
153
+ // API name or identifier
154
+ api_name: String,
155
+ // Base URL or hostname
156
+ base_url: String,
157
+ // Whether the API is trusted/verified
158
+ is_trusted: Bool,
159
+ };
160
+
161
+ // Agent memory or RAG storage
162
+ entity Memory {
163
+ // Memory type: "short_term", "long_term", "rag", "vector_store"
164
+ memory_type: String,
165
+ // Whether memory contains sensitive data
166
+ is_sensitive: Bool,
167
+ };
168
+
133
169
  // =============================================================================
134
- // ACTIONS
170
+ // ACTIONS - LLM/Guardrails
135
171
  // =============================================================================
136
172
 
137
- // --- LLM/Guardrails Actions ---
138
-
139
173
  // Process an LLM prompt
140
174
  // Context: prompt_text, yara_threats, threat_count, max_threat_severity,
141
- // user_type, monitoring_enabled
175
+ // user_type, monitoring_enabled, injection_score, content_score
142
176
  action process_prompt appliesTo {
143
177
  principal: [User, Agent],
144
178
  resource: [Resource],
145
179
  };
146
180
 
147
181
  // Process an LLM response
148
- // Context: response_size_mb
182
+ // Context: response_size_mb, contains_pii, pii_types, content_category
149
183
  action process_response appliesTo {
150
184
  principal: [User, Agent],
151
185
  resource: [ResponseData],
152
186
  };
153
187
 
154
- // --- MCP/Tool Actions ---
188
+ // Invoke an LLM model
189
+ // Context: model_name, model_provider, is_preview_model, estimated_tokens,
190
+ // max_tokens, temperature, top_p, is_streaming
191
+ action invoke_model appliesTo {
192
+ principal: [User, Agent, Service],
193
+ resource: [Model, Resource],
194
+ };
195
+
196
+ // Filter content (apply content filtering policies)
197
+ // Context: content_type, content_category, content_score, harm_categories,
198
+ // language, is_harmful, filter_action
199
+ action filter_content appliesTo {
200
+ principal: [User, Agent, Service],
201
+ resource: [Resource, ResponseData],
202
+ };
203
+
204
+ // =============================================================================
205
+ // ACTIONS - MCP/Tool
206
+ // =============================================================================
155
207
 
156
208
  // Call an MCP tool
157
- // Context: tool_name
209
+ // Context: tool_name, tool_arguments, risk_level
158
210
  action call_tool appliesTo {
159
211
  principal: [User, Agent, Service],
160
212
  resource: [Tool, Resource],
161
213
  };
162
214
 
163
215
  // Connect to an MCP server
216
+ // Context: server_name, server_url, transport_type
164
217
  action connect_server appliesTo {
165
218
  principal: [User, Agent, Service],
166
219
  resource: [Server, Resource],
@@ -179,32 +232,171 @@ action skip_guardrails appliesTo {
179
232
  resource: [Resource],
180
233
  };
181
234
 
182
- // --- File System Actions ---
235
+ // =============================================================================
236
+ // ACTIONS - File System
237
+ // =============================================================================
183
238
 
184
239
  // Read a file
185
- // Context: path
240
+ // Context: path, extension, is_sensitive
186
241
  action read_file appliesTo {
187
242
  principal: [User, Agent, Scanner],
188
243
  resource: [FilePath, Resource],
189
244
  };
190
245
 
191
246
  // Write a file
192
- // Context: path
247
+ // Context: path, extension, is_sensitive, file_size_bytes
193
248
  action write_file appliesTo {
194
249
  principal: [User, Agent],
195
250
  resource: [FilePath, Resource],
196
251
  };
197
252
 
198
- // --- HTTP Actions ---
253
+ // Delete a file
254
+ // Context: path, extension, is_sensitive
255
+ action delete_file appliesTo {
256
+ principal: [User, Agent],
257
+ resource: [FilePath, Resource],
258
+ };
259
+
260
+ // =============================================================================
261
+ // ACTIONS - HTTP/Network
262
+ // =============================================================================
199
263
 
200
264
  // Make an HTTP request
201
- // Context: hostname, ip_address, scheme, port
265
+ // Context: hostname, ip_address, scheme, port, method, is_internal
202
266
  action http_request appliesTo {
203
267
  principal: [User, Agent, Service],
204
268
  resource: [HttpEndpoint, Resource],
205
269
  };
206
270
 
207
- // --- Scanner Actions ---
271
+ // Call an external API
272
+ // Context: api_name, endpoint_path, method, is_trusted, request_size_bytes
273
+ action call_external_api appliesTo {
274
+ principal: [User, Agent, Service],
275
+ resource: [ExternalAPI, HttpEndpoint, Resource],
276
+ };
277
+
278
+ // =============================================================================
279
+ // ACTIONS - Code Execution
280
+ // =============================================================================
281
+
282
+ // Execute code in a sandbox or environment
283
+ // Context: code_language, is_sandboxed, code_size_bytes, has_network_access,
284
+ // has_filesystem_access, execution_timeout_ms
285
+ action execute_code appliesTo {
286
+ principal: [User, Agent],
287
+ resource: [Resource],
288
+ };
289
+
290
+ // Run tests
291
+ // Context: test_framework, test_count, is_sandboxed, code_language
292
+ action run_tests appliesTo {
293
+ principal: [User, Agent, Service],
294
+ resource: [Repository, Resource],
295
+ };
296
+
297
+ // Run build process
298
+ // Context: build_tool, is_sandboxed, code_language
299
+ action run_build appliesTo {
300
+ principal: [User, Agent, Service],
301
+ resource: [Repository, Resource],
302
+ };
303
+
304
+ // =============================================================================
305
+ // ACTIONS - Git Operations
306
+ // =============================================================================
307
+
308
+ // General git operation (use for policies that apply to all git actions)
309
+ // Context: git_op, target_branch, source_branch, is_force, is_protected_branch,
310
+ // changed_files_count, commit_message, remote_url
311
+ action git_operation appliesTo {
312
+ principal: [User, Agent],
313
+ resource: [Repository, GitBranch, Resource],
314
+ };
315
+
316
+ // Clone a repository
317
+ // Context: remote_url, is_shallow, depth
318
+ action git_clone appliesTo {
319
+ principal: [User, Agent],
320
+ resource: [Repository, Resource],
321
+ };
322
+
323
+ // Create a commit
324
+ // Context: commit_message, changed_files_count, author, is_amend
325
+ action git_commit appliesTo {
326
+ principal: [User, Agent],
327
+ resource: [Repository, GitBranch, Resource],
328
+ };
329
+
330
+ // Push changes to remote
331
+ // Context: target_branch, is_force_push, is_protected_branch, remote_url
332
+ action git_push appliesTo {
333
+ principal: [User, Agent],
334
+ resource: [Repository, GitBranch, Resource],
335
+ };
336
+
337
+ // Pull changes from remote
338
+ // Context: source_branch, remote_url, is_rebase
339
+ action git_pull appliesTo {
340
+ principal: [User, Agent],
341
+ resource: [Repository, GitBranch, Resource],
342
+ };
343
+
344
+ // Merge branches
345
+ // Context: source_branch, target_branch, is_protected_branch, merge_strategy
346
+ action git_merge appliesTo {
347
+ principal: [User, Agent],
348
+ resource: [Repository, GitBranch, Resource],
349
+ };
350
+
351
+ // Checkout branch or commit
352
+ // Context: target_branch, is_new_branch, commit_hash
353
+ action git_checkout appliesTo {
354
+ principal: [User, Agent],
355
+ resource: [Repository, GitBranch, Resource],
356
+ };
357
+
358
+ // Reset changes (potentially destructive)
359
+ // Context: reset_mode, target_commit, is_hard_reset
360
+ action git_reset appliesTo {
361
+ principal: [User, Agent],
362
+ resource: [Repository, GitBranch, Resource],
363
+ };
364
+
365
+ // Rebase branch
366
+ // Context: source_branch, target_branch, is_interactive
367
+ action git_rebase appliesTo {
368
+ principal: [User, Agent],
369
+ resource: [Repository, GitBranch, Resource],
370
+ };
371
+
372
+ // =============================================================================
373
+ // ACTIONS - Agent Orchestration
374
+ // =============================================================================
375
+
376
+ // Delegate task to another agent
377
+ // Context: delegation_depth, parent_agent_id, task_type, is_autonomous
378
+ action delegate_task appliesTo {
379
+ principal: [Agent, Service],
380
+ resource: [Resource],
381
+ };
382
+
383
+ // Spawn a subprocess or child process
384
+ // Context: process_name, is_sandboxed, has_network_access, has_filesystem_access
385
+ action spawn_subprocess appliesTo {
386
+ principal: [User, Agent, Service],
387
+ resource: [Resource],
388
+ };
389
+
390
+ // Access agent memory or RAG storage
391
+ // Context: memory_type, operation (read, write, delete), is_sensitive
392
+ action access_memory appliesTo {
393
+ principal: [Agent, Service],
394
+ resource: [Memory, Resource],
395
+ };
396
+
397
+ // =============================================================================
398
+ // ACTIONS - Scanner
399
+ // =============================================================================
208
400
 
209
401
  // Scan a target (MCP server, repository, etc.)
210
402
  action scan_target appliesTo {
@@ -218,7 +410,9 @@ action scan_package appliesTo {
218
410
  resource: [Package, Resource],
219
411
  };
220
412
 
221
- // --- Palisade/ML Actions ---
413
+ // =============================================================================
414
+ // ACTIONS - Palisade/ML
415
+ // =============================================================================
222
416
 
223
417
  // Scan an ML artifact
224
418
  // Context: environment, artifact_format, artifact_signed, severity, finding_type,
@@ -261,13 +455,34 @@ action deploy_model appliesTo {
261
455
  resource: [Artifact],
262
456
  };
263
457
 
458
+ // =============================================================================
459
+ // ACTIONS - Data Loss Prevention (DLP)
460
+ // =============================================================================
461
+
462
+ // Transfer data (for DLP policies)
463
+ // Context: data_classification, destination_type, transfer_size_bytes,
464
+ // contains_pii, pii_types, is_encrypted
465
+ action transfer_data appliesTo {
466
+ principal: [User, Agent, Service],
467
+ resource: [Resource],
468
+ };
469
+
470
+ // Export data (for DLP policies)
471
+ // Context: export_format, data_classification, destination_type, is_encrypted
472
+ action export_data appliesTo {
473
+ principal: [User, Agent, Service],
474
+ resource: [Resource],
475
+ };
476
+
264
477
  // =============================================================================
265
478
  // CONTEXT ATTRIBUTES REFERENCE (Documentation Only)
266
479
  // =============================================================================
267
480
  // Cedar context is dynamic and not enforced by schema, but these are the
268
481
  // standard attributes used across Highflame services:
269
482
  //
270
- // GUARDRAILS/CORE:
483
+ // -----------------------------------------------------------------------------
484
+ // GUARDRAILS/CORE
485
+ // -----------------------------------------------------------------------------
271
486
  // tool_name: String - Name of tool being called
272
487
  // resource_name: String - Name of resource being accessed
273
488
  // prompt_name: String - Name of prompt
@@ -284,7 +499,105 @@ action deploy_model appliesTo {
284
499
  // scheme: String - HTTP scheme
285
500
  // port: Long - Port number
286
501
  //
287
- // PALISADE:
502
+ // -----------------------------------------------------------------------------
503
+ // MODEL INVOCATION
504
+ // -----------------------------------------------------------------------------
505
+ // model_name: String - Name of the model (e.g., "gpt-4", "claude-3-opus")
506
+ // model_provider: String - Provider name (e.g., "openai", "anthropic", "google", "azure", "bedrock")
507
+ // is_preview_model: Bool - Whether model is in preview/beta
508
+ // estimated_tokens: Long - Estimated input + output tokens
509
+ // max_tokens: Long - Maximum tokens allowed for response
510
+ // temperature: Long - Temperature setting (scaled by 100, e.g., 70 = 0.7)
511
+ // top_p: Long - Top-p sampling (scaled by 100)
512
+ // is_streaming: Bool - Whether response is streamed
513
+ //
514
+ // -----------------------------------------------------------------------------
515
+ // CONTENT FILTERING
516
+ // -----------------------------------------------------------------------------
517
+ // content_type: String - Type of content ("text", "code", "image", "audio", "video")
518
+ // content_category: String - Category ("general", "adult", "violence", "hate", etc.)
519
+ // content_score: Long - Content risk score (0-100)
520
+ // injection_score: Long - Prompt injection detection score (0-100)
521
+ // jailbreak_score: Long - Jailbreak attempt detection score (0-100)
522
+ // contains_pii: Bool - Whether content contains PII
523
+ // pii_types: Set<String> - Types of PII detected ("email", "phone", "ssn", "credit_card", etc.)
524
+ // language: String - Detected language code (e.g., "en", "es", "zh")
525
+ // is_harmful: Bool - Whether content is harmful
526
+ // harm_categories: Set<String> - Categories of harm ("violence", "hate", "self_harm", "sexual", etc.)
527
+ // filter_action: String - Action to take ("inspect", "mask", "redact", "replace", "anonymize", "reject")
528
+ // csam_detected: Bool - Whether CSAM was detected
529
+ // hallucination_score: Long - Hallucination detection score (0-100)
530
+ //
531
+ // -----------------------------------------------------------------------------
532
+ // RATE LIMITING
533
+ // -----------------------------------------------------------------------------
534
+ // concurrent_calls: Long - Current number of concurrent calls
535
+ // requests_per_minute: Long - Current requests per minute
536
+ // tokens_per_minute: Long - Current tokens per minute
537
+ // rate_limit_bucket: String - Rate limit bucket identifier
538
+ // is_rate_limited: Bool - Whether rate limit is exceeded
539
+ //
540
+ // -----------------------------------------------------------------------------
541
+ // GIT OPERATIONS
542
+ // -----------------------------------------------------------------------------
543
+ // git_op: String - Type of git operation ("clone", "commit", "push", "pull", etc.)
544
+ // target_branch: String - Target branch name
545
+ // source_branch: String - Source branch name
546
+ // is_force_push: Bool - Whether this is a force push
547
+ // is_protected_branch: Bool - Whether target is a protected branch
548
+ // changed_files_count: Long - Number of files changed
549
+ // commit_message: String - Commit message text
550
+ // remote_url: String - Remote repository URL
551
+ // is_shallow: Bool - Whether clone is shallow
552
+ // depth: Long - Clone depth for shallow clones
553
+ // is_amend: Bool - Whether commit is an amend
554
+ // merge_strategy: String - Merge strategy ("merge", "rebase", "squash")
555
+ // is_hard_reset: Bool - Whether reset is hard (destructive)
556
+ // reset_mode: String - Reset mode ("soft", "mixed", "hard")
557
+ // is_interactive: Bool - Whether operation is interactive
558
+ //
559
+ // -----------------------------------------------------------------------------
560
+ // CODE EXECUTION
561
+ // -----------------------------------------------------------------------------
562
+ // code_language: String - Programming language ("python", "javascript", "go", etc.)
563
+ // is_sandboxed: Bool - Whether code runs in a sandbox
564
+ // code_size_bytes: Long - Size of code in bytes
565
+ // has_network_access: Bool - Whether code has network access
566
+ // has_filesystem_access: Bool - Whether code has filesystem access
567
+ // execution_timeout_ms: Long - Execution timeout in milliseconds
568
+ // test_framework: String - Test framework being used
569
+ // test_count: Long - Number of tests being run
570
+ // build_tool: String - Build tool being used
571
+ //
572
+ // -----------------------------------------------------------------------------
573
+ // AGENT ORCHESTRATION
574
+ // -----------------------------------------------------------------------------
575
+ // delegation_depth: Long - Current delegation nesting depth
576
+ // parent_agent_id: String - ID of parent agent (if delegated)
577
+ // task_type: String - Type of task being performed
578
+ // is_autonomous: Bool - Whether agent is operating autonomously
579
+ // session_id: String - Agent session identifier
580
+ // process_name: String - Name of subprocess being spawned
581
+ //
582
+ // -----------------------------------------------------------------------------
583
+ // MEMORY/RAG
584
+ // -----------------------------------------------------------------------------
585
+ // memory_type: String - Type of memory ("short_term", "long_term", "rag", "vector_store")
586
+ // memory_operation: String - Operation being performed ("read", "write", "delete", "search")
587
+ // memory_is_sensitive: Bool - Whether memory contains sensitive data
588
+ //
589
+ // -----------------------------------------------------------------------------
590
+ // DATA LOSS PREVENTION (DLP)
591
+ // -----------------------------------------------------------------------------
592
+ // data_classification: String - Classification level ("public", "internal", "confidential", "restricted")
593
+ // destination_type: String - Where data is going ("internal", "external", "cloud", "email")
594
+ // transfer_size_bytes: Long - Size of data being transferred
595
+ // is_encrypted: Bool - Whether data is encrypted
596
+ // export_format: String - Format of exported data ("json", "csv", "pdf", etc.)
597
+ //
598
+ // -----------------------------------------------------------------------------
599
+ // PALISADE/ML
600
+ // -----------------------------------------------------------------------------
288
601
  // environment: String - "production", "development", "research"
289
602
  // artifact_format: String - "pickle", "safetensors", "gguf", "onnx"
290
603
  // artifact_signed: Bool - Whether artifact has signature
@@ -298,4 +611,5 @@ action deploy_model appliesTo {
298
611
  // gguf_suspicious_metadata: Bool - Suspicious GGUF metadata
299
612
  // adapter_base_digest_mismatch: Bool - LoRA adapter digest mismatch
300
613
  // metadata_cosai_level_numeric: Long - CoSAI maturity level (0-5)
614
+ //
301
615
  `;
package/src/types.ts CHANGED
@@ -13,3 +13,6 @@ export * from './schema.gen.js';
13
13
 
14
14
  // PolicyBuilder - works in browser (no WASM dependency)
15
15
  export * from './builder.js';
16
+
17
+ // Error types - works in browser (no WASM dependency)
18
+ export * from './errors.js';