index.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * Permission subsystem — public surface.
  3. *
  4. * The public surface is:
  5. *
  6. * - `PermissionEngine` + deterministic checkers in `tools/*` — checker
  7. * dispatch and the explicit legacy rollback path used by
  8. * `LocalPermissionFacade`.
  9. * - `permission-core.ts` — the default production policy reducer plus the
  10. * structured CommandIntent / ExecutionPlan contract.
  11. * - HARD/SOFT dangerous-pattern registries in `classifier/dangerous-patterns.ts`
  12. * consumed internally by the tool checkers.
  13. * - `cloud-classify-client.ts` — utility for hosts to know whether to call
  14. * the cloud gateway (`shouldUseCloudClassify`) and to resolve the API URL.
  15. * - `reason-format.ts` — localized DecisionReason formatter shared by
  16. * decision callers (facade, future cloud-runtime).
  17. * - `cloud-gateway.ts` / `http-cloud-gateway-client.ts` /
  18. * `conversation-renderer.ts` / `ask-policy.ts` — the cloud-gateway decision
  19. * path the facade routes `auto` mode through.
  20. *
  21. * Hosts must call `configurePermissionHost(...)` once at startup to wire the
  22. * concrete ports declared in `host-ports.ts`. Cross-cutting helpers (logger,
  23. * region/build-env, datetime) flow through `configurePermissionHost`.
  24. */
  25. // ── Core types ──
  26. export type {
  27. PermissionBehavior,
  28. PermissionMode,
  29. PermissionRule,
  30. PermissionRuleValue,
  31. PermissionRuleAction,
  32. PermissionRuleMatcher,
  33. PermissionRuleSource,
  34. ShellPermissionRule,
  35. DecisionReason,
  36. SubcommandResult,
  37. PermissionDecision,
  38. ToolCheckResult,
  39. CandidateScope,
  40. CandidateScopeGroup,
  41. PathCheckContext,
  42. PermissionUpdate,
  43. PermissionFileConfig,
  44. ToolPermissionContext,
  45. } from './types.js';
  46. // ── Deterministic safety registries (verbatim regex source of truth) ──
  47. export {
  48. HARD_BLOCKED_REGISTRY,
  49. SOFT_RISK_REGISTRY,
  50. SUBCOMMAND_DANGEROUS_PATTERNS,
  51. ALL_DANGEROUS_COMMAND_PATTERNS,
  52. DESTRUCTIVE_STANDALONE_COMMANDS,
  53. CROSS_PLATFORM_CODE_EXEC,
  54. DANGEROUS_BASH_PATTERNS,
  55. PIPE_TO_SHELL_PATTERN,
  56. LOCAL_SCRIPT_INTERPRETERS_RE,
  57. hardBlockedCategoryIsFinalDeny,
  58. matchHardBlockedBash,
  59. matchHardBlockedFsRead,
  60. matchSecretReadForm,
  61. allPipeToShellAreInlineLiteralC,
  62. isDangerousBashPermission,
  63. type HardBlockedMatch,
  64. type HardBlockedCategory,
  65. type SoftRiskCategory,
  66. type ClassifierRule,
  67. type ClassifierRuleValue,
  68. } from './classifier/dangerous-patterns.js';
  69. // ── Decision engine ──
  70. export { PermissionEngine } from './engine.js';
  71. export { registerDefaultCheckers } from './tools/index.js';
  72. export { unwrapCommandWrappers } from './tools/bash-wrapper-unwrap.js';
  73. export { isRmCommand, parseRmTargets, splitCommand } from './tools/bash-permission.js';
  74. export {
  75. parseScriptPlainCommands,
  76. parseShellLcPlainCommands,
  77. parseShellLcSingleCommandPrefix,
  78. } from './tools/bash-ast.js';
  79. export {
  80. parseWindowsNativeDelete,
  81. type WindowsNativeDeleteCommand,
  82. } from './tools/windows-native-delete.js';
  83. export {
  84. readWindowsTrashExecution,
  85. withWindowsTrashExecution,
  86. type WindowsTrashExecution,
  87. } from './windows-trash-execution.js';
  88. export { snapshotPermissionEffectiveInput, snapshotPermissionInput } from './effective-input.js';
  89. export {
  90. createPermissionExecutionPlan,
  91. validatePermissionExecutionPlan,
  92. } from './execution-plan.js';
  93. export type { CreatePermissionExecutionPlanInput } from './execution-plan.js';
  94. export { isKnownSafeCommand } from './tools/safe-command.js';
  95. export { isKnownSafePowerShellCommand } from './tools/safe-command.js';
  96. export { isSameResolvedPath } from './tools/path-identity.js';
  97. export type { ToolPermissionChecker } from './engine.js';
  98. export { createToolPermissionContext } from './context.js';
  99. export { resolvePermissionPath } from './path-resolver.js';
  100. export { extractBashPathIntents } from './tools/path-capability.js';
  101. export type { PermissionPathResolutionContext } from './path-resolver.js';
  102. // ── Permission Core contract / reducer ──
  103. export {
  104. reducePermissionClassifierDecision,
  105. reducePermissionDecision,
  106. reducePermissionEvaluation,
  107. permissionModeToProfile,
  108. } from './permission-core.js';
  109. export type {
  110. PermissionPolicyOwner,
  111. PermissionCheckOptions,
  112. PermissionCheckerDecisionTrace,
  113. PermissionCoreDecisionInput,
  114. PermissionAction,
  115. ShellFamily,
  116. PathValue,
  117. CommandIntent,
  118. PermissionEvidence,
  119. ExecutionTransform,
  120. ExecutionPlan,
  121. PermissionModeProfile,
  122. PermissionEvaluationInput,
  123. PermissionApprovalRequest,
  124. PermissionEvaluation,
  125. } from './permission-core.js';
  126. export {
  127. adaptLegacyPermissionResult,
  128. evaluateLegacyPermission,
  129. } from './legacy-permission-adapter.js';
  130. export type {
  131. LegacyAdapterInput,
  132. LegacyEvaluationInput,
  133. LegacyParserAdapterResult,
  134. } from './legacy-permission-adapter.js';
  135. // ── Cloud gateway gating ──
  136. export { shouldUseCloudClassify } from './classifier/cloud-classify-client.js';
  137. // ── Default cloud-gateway classifier budget. `HttpCloudGatewayClient` uses
  138. // this as its per-call timeout default.
  139. export const AUTO_CLASSIFIER_TIMEOUT_MS_DEFAULT = 60_000;
  140. // ── Host-port surface (consumed by hosts to wire concrete deps) ──
  141. export {
  142. configurePermissionHost,
  143. resetPermissionHostForTesting,
  144. getPermissionManagedAuthToken,
  145. getPermissionPrompt,
  146. type PermissionHostUtils,
  147. } from './host-utils.js';
  148. export type {
  149. PermissionPromptProvider,
  150. ManagedAuthTokenGetter,
  151. PermissionStorePort,
  152. SessionResolverPort,
  153. AgentResolverPort,
  154. MessageStorePort,
  155. ConfigWriterPort,
  156. PermissionRequestStore,
  157. PermissionRequestRecord,
  158. } from './host-ports.js';
  159. // ── Localized reason formatter (shared wire output) ──
  160. export {
  161. formatDecisionReason,
  162. formatAutoClassifierReason,
  163. formatBlockedToolReason,
  164. localeOrDefault,
  165. type Lang,
  166. type ToolDenialSource,
  167. type BlockedToolReasonInput,
  168. } from './reason-format.js';
  169. // ── User-locale detection (used by hosts to pick zh/en templates) ──
  170. export { detectTextLocale, detectMessagesLocale, type UserLocaleHint } from './locale-detect.js';
  171. // ── Ask-policy + cloud gateway ──
  172. export { modeToAskPolicy } from './ask-policy.js';
  173. export type { AskForApproval, ProposedRule, ProposedRuleScope } from './ask-policy.js';
  174. export { renderConversationContext } from './conversation-renderer.js';
  175. export type { RenderConversationContextInput } from './conversation-renderer.js';
  176. export type {
  177. CloudGatewayClient,
  178. CloudClassifyRequest,
  179. CloudClassifyVerdict,
  180. } from './cloud-gateway.js';
  181. export { HttpCloudGatewayClient } from './http-cloud-gateway-client.js';
  182. export type { HttpCloudGatewayClientOptions } from './http-cloud-gateway-client.js';
  183. export { InMemoryCloudGatewayClient } from './in-memory-cloud-gateway-client.js';
  184. export type { InMemoryCloudGatewayClientOptions } from './in-memory-cloud-gateway-client.js';