@node9/policy-engine 1.67.1 → 1.67.2

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/dist/index.d.mts CHANGED
@@ -166,6 +166,10 @@ declare function redactText(text: string): {
166
166
  found: string[];
167
167
  };
168
168
 
169
+ /**
170
+ * The POSIX reading of a command. Kept as the single-string API every existing
171
+ * caller (canonical.ts, the detectors, `explain`) already depends on.
172
+ */
169
173
  declare function normalizeCommandForPolicy(command: string): string;
170
174
  /**
171
175
  * AST-based detection of dangerous shell execution patterns.
@@ -193,6 +197,31 @@ interface FsOpVerdict {
193
197
  declare const BASH_TOOL_NAMES: Set<string>;
194
198
  declare function isBashTool(toolName: string): boolean;
195
199
  declare const AST_FS_REGEX_RULES: Set<string>;
200
+ /**
201
+ * Does `toolName` carry a shell command? True for BASH_TOOL_NAMES spellings and
202
+ * for any tool whose toolInspection field is `command` (e.g. `terminal.execute`).
203
+ *
204
+ * THE definition of "shell-shaped" — the gate, the CLI scan, and `explain` must
205
+ * all use this one, or they disagree about which rules apply to which tool
206
+ * (/code-review 2026-08-13: the gate reviewed `sudo …` on `shell` while scan
207
+ * reported nothing, so the customer-facing report under-counted).
208
+ */
209
+ declare function isShellShapedTool(toolName: string, toolInspection?: Record<string, string>): boolean;
210
+ /**
211
+ * Does a smart rule's `tool` scope cover this tool? Adds the shell-shape alias:
212
+ * the six default shell-safety rules and shield bundles are written
213
+ * `tool:'bash'`, and an agent's choice of tool-name spelling (`shell`,
214
+ * `run_shell_command`, `execute_bash`, `terminal.execute`) must not silently
215
+ * void them. An absent rule scope matches everything (callers' prior semantics).
216
+ */
217
+ declare function toolMatchesRule(toolName: string, ruleTool: string | string[] | undefined, toolInspection?: Record<string, string>): boolean;
218
+ /**
219
+ * AST-aware inline-execution detector. Returns true when the command runs code
220
+ * supplied on the command line, via stdin, or via a pipe into a bare
221
+ * interpreter. Structural, so it is not fooled by quoting, escapes, option
222
+ * bundles, or wrapper nesting. Pure.
223
+ */
224
+ declare function detectInlineExec(command: string): boolean;
196
225
  /**
197
226
  * True when `path` is under $HOME (~ or absolute /home/* or /root) AND not in
198
227
  * the tool-managed cache allow-list. Used to gate `rm -rf` on home paths.
@@ -367,6 +396,15 @@ interface PolicyContext {
367
396
  activeEnvironment?: {
368
397
  requireApproval?: boolean;
369
398
  };
399
+ /**
400
+ * Task #20: evaluate the full rule chain even for an ignoredTools match.
401
+ * Set by the orchestrator's jail guard AFTER it has already found a
402
+ * jailed/sensitive path in a file-tool call — without this, the tier-1
403
+ * fast path below returns 'allow' before the jail shield's `tool:'*'`
404
+ * rules are ever consulted, making the jail engine-invisible to
405
+ * Read/Grep/Glob. Opt-in per call; never set on the hot path.
406
+ */
407
+ skipIgnoredFastPath?: boolean;
370
408
  }
371
409
  type ProvenanceTrust = 'system' | 'managed' | 'user' | 'suspect' | 'unknown';
372
410
  interface ProvenanceLookup {
@@ -1079,7 +1117,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
1079
1117
  * and fails CI when the hash drifts without a version bump — forgetting
1080
1118
  * is loud, not silent.
1081
1119
  */
1082
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v6";
1120
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v8";
1083
1121
  /**
1084
1122
  * SHA-256 prefix of the detector-source files
1085
1123
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -1090,7 +1128,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v6";
1090
1128
  * files changed, this hash must change too, and you must consciously
1091
1129
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
1092
1130
  */
1093
- declare const CANONICAL_EXTRACTOR_HASH = "a0e2bb339fe67e19";
1131
+ declare const CANONICAL_EXTRACTOR_HASH = "80f40f974263b281";
1094
1132
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
1095
1133
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
1096
1134
  /**
@@ -1117,4 +1155,4 @@ declare function previewArgs(input: Record<string, unknown>, max: number): strin
1117
1155
  /** Engine version stamped on audit entries for future drift detection. */
1118
1156
  declare const ENGINE_VERSION = "1.4.0";
1119
1157
 
1120
- export { AST_FS_REGEX_RULES, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, COST_PER_LOOP_ITER_USD, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, DEFAULT_EGRESS_ALLOWLIST, DESTRUCTIVE_OP_RE, DLP_PATTERNS, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LoopWindowEvaluation, PRIVILEGE_ESCALATION_RE, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, type ScanFinding, type ScanSignals, type ScanSummary, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestination, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type ToolCallEntry, type ToolCallRecord, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, checkDangerousSql, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, dedupeCanonicalFindings, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateSmartConditions, extractAllSshHosts, extractCanonicalFindings, extractNetworkTargets, extractPositionalArgs, extractSessionLevelFindings, extractShellDestinations, getCompiledRegex, getNestedValue, hostMatches, isBashTool, isIgnoredTool, isPrivateHost, isProtectedHomePath, isShieldVerdict, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, parseAllSshHostsFromCommand, parseDestHost, previewArgs, redactText, resolvePinned, scanArgs, scanInjection, scanText, sensitivePathMatch, summarizeBlast, summarizeScan, toScanFinding, truncateBlastPath, validateOverrides, validateRegex, validateShieldDefinition };
1158
+ export { AST_FS_REGEX_RULES, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, COST_PER_LOOP_ITER_USD, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, DEFAULT_EGRESS_ALLOWLIST, DESTRUCTIVE_OP_RE, DLP_PATTERNS, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LoopWindowEvaluation, PRIVILEGE_ESCALATION_RE, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, type ScanFinding, type ScanSignals, type ScanSummary, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestination, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type ToolCallEntry, type ToolCallRecord, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, checkDangerousSql, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, dedupeCanonicalFindings, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateSmartConditions, extractAllSshHosts, extractCanonicalFindings, extractNetworkTargets, extractPositionalArgs, extractSessionLevelFindings, extractShellDestinations, getCompiledRegex, getNestedValue, hostMatches, isBashTool, isIgnoredTool, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, parseAllSshHostsFromCommand, parseDestHost, previewArgs, redactText, resolvePinned, scanArgs, scanInjection, scanText, sensitivePathMatch, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, validateOverrides, validateRegex, validateShieldDefinition };
package/dist/index.d.ts CHANGED
@@ -166,6 +166,10 @@ declare function redactText(text: string): {
166
166
  found: string[];
167
167
  };
168
168
 
169
+ /**
170
+ * The POSIX reading of a command. Kept as the single-string API every existing
171
+ * caller (canonical.ts, the detectors, `explain`) already depends on.
172
+ */
169
173
  declare function normalizeCommandForPolicy(command: string): string;
170
174
  /**
171
175
  * AST-based detection of dangerous shell execution patterns.
@@ -193,6 +197,31 @@ interface FsOpVerdict {
193
197
  declare const BASH_TOOL_NAMES: Set<string>;
194
198
  declare function isBashTool(toolName: string): boolean;
195
199
  declare const AST_FS_REGEX_RULES: Set<string>;
200
+ /**
201
+ * Does `toolName` carry a shell command? True for BASH_TOOL_NAMES spellings and
202
+ * for any tool whose toolInspection field is `command` (e.g. `terminal.execute`).
203
+ *
204
+ * THE definition of "shell-shaped" — the gate, the CLI scan, and `explain` must
205
+ * all use this one, or they disagree about which rules apply to which tool
206
+ * (/code-review 2026-08-13: the gate reviewed `sudo …` on `shell` while scan
207
+ * reported nothing, so the customer-facing report under-counted).
208
+ */
209
+ declare function isShellShapedTool(toolName: string, toolInspection?: Record<string, string>): boolean;
210
+ /**
211
+ * Does a smart rule's `tool` scope cover this tool? Adds the shell-shape alias:
212
+ * the six default shell-safety rules and shield bundles are written
213
+ * `tool:'bash'`, and an agent's choice of tool-name spelling (`shell`,
214
+ * `run_shell_command`, `execute_bash`, `terminal.execute`) must not silently
215
+ * void them. An absent rule scope matches everything (callers' prior semantics).
216
+ */
217
+ declare function toolMatchesRule(toolName: string, ruleTool: string | string[] | undefined, toolInspection?: Record<string, string>): boolean;
218
+ /**
219
+ * AST-aware inline-execution detector. Returns true when the command runs code
220
+ * supplied on the command line, via stdin, or via a pipe into a bare
221
+ * interpreter. Structural, so it is not fooled by quoting, escapes, option
222
+ * bundles, or wrapper nesting. Pure.
223
+ */
224
+ declare function detectInlineExec(command: string): boolean;
196
225
  /**
197
226
  * True when `path` is under $HOME (~ or absolute /home/* or /root) AND not in
198
227
  * the tool-managed cache allow-list. Used to gate `rm -rf` on home paths.
@@ -367,6 +396,15 @@ interface PolicyContext {
367
396
  activeEnvironment?: {
368
397
  requireApproval?: boolean;
369
398
  };
399
+ /**
400
+ * Task #20: evaluate the full rule chain even for an ignoredTools match.
401
+ * Set by the orchestrator's jail guard AFTER it has already found a
402
+ * jailed/sensitive path in a file-tool call — without this, the tier-1
403
+ * fast path below returns 'allow' before the jail shield's `tool:'*'`
404
+ * rules are ever consulted, making the jail engine-invisible to
405
+ * Read/Grep/Glob. Opt-in per call; never set on the hot path.
406
+ */
407
+ skipIgnoredFastPath?: boolean;
370
408
  }
371
409
  type ProvenanceTrust = 'system' | 'managed' | 'user' | 'suspect' | 'unknown';
372
410
  interface ProvenanceLookup {
@@ -1079,7 +1117,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
1079
1117
  * and fails CI when the hash drifts without a version bump — forgetting
1080
1118
  * is loud, not silent.
1081
1119
  */
1082
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v6";
1120
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v8";
1083
1121
  /**
1084
1122
  * SHA-256 prefix of the detector-source files
1085
1123
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -1090,7 +1128,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v6";
1090
1128
  * files changed, this hash must change too, and you must consciously
1091
1129
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
1092
1130
  */
1093
- declare const CANONICAL_EXTRACTOR_HASH = "a0e2bb339fe67e19";
1131
+ declare const CANONICAL_EXTRACTOR_HASH = "80f40f974263b281";
1094
1132
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
1095
1133
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
1096
1134
  /**
@@ -1117,4 +1155,4 @@ declare function previewArgs(input: Record<string, unknown>, max: number): strin
1117
1155
  /** Engine version stamped on audit entries for future drift detection. */
1118
1156
  declare const ENGINE_VERSION = "1.4.0";
1119
1157
 
1120
- export { AST_FS_REGEX_RULES, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, COST_PER_LOOP_ITER_USD, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, DEFAULT_EGRESS_ALLOWLIST, DESTRUCTIVE_OP_RE, DLP_PATTERNS, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LoopWindowEvaluation, PRIVILEGE_ESCALATION_RE, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, type ScanFinding, type ScanSignals, type ScanSummary, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestination, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type ToolCallEntry, type ToolCallRecord, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, checkDangerousSql, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, dedupeCanonicalFindings, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateSmartConditions, extractAllSshHosts, extractCanonicalFindings, extractNetworkTargets, extractPositionalArgs, extractSessionLevelFindings, extractShellDestinations, getCompiledRegex, getNestedValue, hostMatches, isBashTool, isIgnoredTool, isPrivateHost, isProtectedHomePath, isShieldVerdict, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, parseAllSshHostsFromCommand, parseDestHost, previewArgs, redactText, resolvePinned, scanArgs, scanInjection, scanText, sensitivePathMatch, summarizeBlast, summarizeScan, toScanFinding, truncateBlastPath, validateOverrides, validateRegex, validateShieldDefinition };
1158
+ export { AST_FS_REGEX_RULES, type AuditEntryForClassify, BASH_TOOL_NAMES, BUILTIN_SHIELDS, type BlastEnvFinding, type BlastFinding, type BlastResult, type BlastSummary, CANONICAL_EXTRACTOR_HASH, CANONICAL_EXTRACTOR_VERSION, COST_PER_LOOP_ITER_USD, type CanonicalAgent, type CanonicalFinding, type CanonicalFindingType, type CanonicalSourceType, DEFAULT_EGRESS_ALLOWLIST, DESTRUCTIVE_OP_RE, DLP_PATTERNS, type DlpMatch, ENGINE_VERSION, type EgressPolicy, type EgressVerdict, type ExtractContext, FILE_TOOLS, FLAGS_WITH_VALUES, type FsOpVerdict, type InjectionConfidence, type InjectionContext, type InjectionMatch, LONG_OUTPUT_THRESHOLD_BYTES, LOOP_MAX_RECORDS, LOOP_THRESHOLD_FOR_WASTE, type LoopWindowEvaluation, PRIVILEGE_ESCALATION_RE, type PiiPattern, type PipeChainAnalysis, type PolicyConfig, type PolicyContext, type PolicyHostHooks, type PolicyVerdict, type ProvenanceLookup, type ProvenanceTrust, REALTIME_PII_PATTERNS, type RiskMetadata, SCAN_SIGNAL_WEIGHTS, SENSITIVE_PATH_RE, SENSITIVE_PATH_REGEXES, type ScanFinding, type ScanSignals, type ScanSummary, type ScoreTier, type SessionExtractContext, type SessionToolCall, type Severity, type ShellCommandAnalysis, type ShellDestination, type ShieldDefinition, type ShieldOverrides, type ShieldVerdict, type SmartCondition, type SmartRule, type ToolCallEntry, type ToolCallRecord, analyzeFsOperation, analyzePipeChain, analyzeShellCommand, checkDangerousSql, classifyAuditEntry, classifyRuleSeverity, classifyScanSignal, computeAgentDeviceScore, computeArgsHash, computeBlendedSecurityScore, computeScanScore, computeSecurityScore, dedupeCanonicalFindings, detectArgsPii, detectDangerousEval, detectDangerousShellExec, detectInlineExec, detectPii, evaluateEgress, evaluateLoopWindow, evaluatePolicy, evaluateSmartConditions, extractAllSshHosts, extractCanonicalFindings, extractNetworkTargets, extractPositionalArgs, extractSessionLevelFindings, extractShellDestinations, getCompiledRegex, getNestedValue, hostMatches, isBashTool, isIgnoredTool, isPrivateHost, isProtectedHomePath, isShellShapedTool, isShieldVerdict, matchSensitivePath, matchesPattern, narrativeRuleLabel, normalizeCommandForPolicy, parseAllSshHostsFromCommand, parseDestHost, previewArgs, redactText, resolvePinned, scanArgs, scanInjection, scanText, sensitivePathMatch, summarizeBlast, summarizeScan, toScanFinding, toolMatchesRule, truncateBlastPath, validateOverrides, validateRegex, validateShieldDefinition };