narai-primitives 2.0.0-rc.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.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/config/bootstrap.d.ts +28 -0
- package/dist/config/bootstrap.d.ts.map +1 -0
- package/dist/config/bootstrap.js +80 -0
- package/dist/config/bootstrap.js.map +1 -0
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +12 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +37 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +99 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/resolve.d.ts +23 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +198 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/secrets.d.ts +20 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +43 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/types.d.ts +104 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +11 -0
- package/dist/config/types.js.map +1 -0
- package/dist/connectors/aws/cli.d.ts +3 -0
- package/dist/connectors/aws/cli.d.ts.map +1 -0
- package/dist/connectors/aws/cli.js +27 -0
- package/dist/connectors/aws/cli.js.map +1 -0
- package/dist/connectors/aws/index.d.ts +27 -0
- package/dist/connectors/aws/index.d.ts.map +1 -0
- package/dist/connectors/aws/index.js +281 -0
- package/dist/connectors/aws/index.js.map +1 -0
- package/dist/connectors/aws/lib/aws_client.d.ts +140 -0
- package/dist/connectors/aws/lib/aws_client.d.ts.map +1 -0
- package/dist/connectors/aws/lib/aws_client.js +196 -0
- package/dist/connectors/aws/lib/aws_client.js.map +1 -0
- package/dist/connectors/aws/lib/aws_error.d.ts +10 -0
- package/dist/connectors/aws/lib/aws_error.d.ts.map +1 -0
- package/dist/connectors/aws/lib/aws_error.js +15 -0
- package/dist/connectors/aws/lib/aws_error.js.map +1 -0
- package/dist/connectors/confluence/cli.d.ts +3 -0
- package/dist/connectors/confluence/cli.d.ts.map +1 -0
- package/dist/connectors/confluence/cli.js +24 -0
- package/dist/connectors/confluence/cli.js.map +1 -0
- package/dist/connectors/confluence/index.d.ts +15 -0
- package/dist/connectors/confluence/index.d.ts.map +1 -0
- package/dist/connectors/confluence/index.js +295 -0
- package/dist/connectors/confluence/index.js.map +1 -0
- package/dist/connectors/confluence/lib/confluence_client.d.ts +135 -0
- package/dist/connectors/confluence/lib/confluence_client.d.ts.map +1 -0
- package/dist/connectors/confluence/lib/confluence_client.js +329 -0
- package/dist/connectors/confluence/lib/confluence_client.js.map +1 -0
- package/dist/connectors/confluence/lib/confluence_error.d.ts +13 -0
- package/dist/connectors/confluence/lib/confluence_error.d.ts.map +1 -0
- package/dist/connectors/confluence/lib/confluence_error.js +19 -0
- package/dist/connectors/confluence/lib/confluence_error.js.map +1 -0
- package/dist/connectors/db/cli.d.ts +5 -0
- package/dist/connectors/db/cli.d.ts.map +1 -0
- package/dist/connectors/db/cli.js +34 -0
- package/dist/connectors/db/cli.js.map +1 -0
- package/dist/connectors/db/config.d.ts +18 -0
- package/dist/connectors/db/config.d.ts.map +1 -0
- package/dist/connectors/db/config.js +142 -0
- package/dist/connectors/db/config.js.map +1 -0
- package/dist/connectors/db/connector.d.ts +31 -0
- package/dist/connectors/db/connector.d.ts.map +1 -0
- package/dist/connectors/db/connector.js +175 -0
- package/dist/connectors/db/connector.js.map +1 -0
- package/dist/connectors/db/dispatcher.d.ts +36 -0
- package/dist/connectors/db/dispatcher.d.ts.map +1 -0
- package/dist/connectors/db/dispatcher.js +597 -0
- package/dist/connectors/db/dispatcher.js.map +1 -0
- package/dist/connectors/db/index.d.ts +22 -0
- package/dist/connectors/db/index.d.ts.map +1 -0
- package/dist/connectors/db/index.js +26 -0
- package/dist/connectors/db/index.js.map +1 -0
- package/dist/connectors/db/lib/audit.d.ts +32 -0
- package/dist/connectors/db/lib/audit.d.ts.map +1 -0
- package/dist/connectors/db/lib/audit.js +130 -0
- package/dist/connectors/db/lib/audit.js.map +1 -0
- package/dist/connectors/db/lib/connection.d.ts +61 -0
- package/dist/connectors/db/lib/connection.d.ts.map +1 -0
- package/dist/connectors/db/lib/connection.js +326 -0
- package/dist/connectors/db/lib/connection.js.map +1 -0
- package/dist/connectors/db/lib/credentials.d.ts +60 -0
- package/dist/connectors/db/lib/credentials.d.ts.map +1 -0
- package/dist/connectors/db/lib/credentials.js +117 -0
- package/dist/connectors/db/lib/credentials.js.map +1 -0
- package/dist/connectors/db/lib/drivers/base.d.ts +83 -0
- package/dist/connectors/db/lib/drivers/base.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/base.js +46 -0
- package/dist/connectors/db/lib/drivers/base.js.map +1 -0
- package/dist/connectors/db/lib/drivers/dynamodb.d.ts +108 -0
- package/dist/connectors/db/lib/drivers/dynamodb.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/dynamodb.js +468 -0
- package/dist/connectors/db/lib/drivers/dynamodb.js.map +1 -0
- package/dist/connectors/db/lib/drivers/mongodb.d.ts +60 -0
- package/dist/connectors/db/lib/drivers/mongodb.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/mongodb.js +371 -0
- package/dist/connectors/db/lib/drivers/mongodb.js.map +1 -0
- package/dist/connectors/db/lib/drivers/mysql.d.ts +45 -0
- package/dist/connectors/db/lib/drivers/mysql.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/mysql.js +265 -0
- package/dist/connectors/db/lib/drivers/mysql.js.map +1 -0
- package/dist/connectors/db/lib/drivers/oracle.d.ts +53 -0
- package/dist/connectors/db/lib/drivers/oracle.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/oracle.js +350 -0
- package/dist/connectors/db/lib/drivers/oracle.js.map +1 -0
- package/dist/connectors/db/lib/drivers/postgresql.d.ts +65 -0
- package/dist/connectors/db/lib/drivers/postgresql.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/postgresql.js +294 -0
- package/dist/connectors/db/lib/drivers/postgresql.js.map +1 -0
- package/dist/connectors/db/lib/drivers/register.d.ts +16 -0
- package/dist/connectors/db/lib/drivers/register.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/register.js +111 -0
- package/dist/connectors/db/lib/drivers/register.js.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlite.d.ts +11 -0
- package/dist/connectors/db/lib/drivers/sqlite.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlite.js +147 -0
- package/dist/connectors/db/lib/drivers/sqlite.js.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlserver.d.ts +58 -0
- package/dist/connectors/db/lib/drivers/sqlserver.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlserver.js +274 -0
- package/dist/connectors/db/lib/drivers/sqlserver.js.map +1 -0
- package/dist/connectors/db/lib/environments.d.ts +68 -0
- package/dist/connectors/db/lib/environments.d.ts.map +1 -0
- package/dist/connectors/db/lib/environments.js +53 -0
- package/dist/connectors/db/lib/environments.js.map +1 -0
- package/dist/connectors/db/lib/index.d.ts +28 -0
- package/dist/connectors/db/lib/index.d.ts.map +1 -0
- package/dist/connectors/db/lib/index.js +30 -0
- package/dist/connectors/db/lib/index.js.map +1 -0
- package/dist/connectors/db/lib/plugin_config.d.ts +64 -0
- package/dist/connectors/db/lib/plugin_config.d.ts.map +1 -0
- package/dist/connectors/db/lib/plugin_config.js +287 -0
- package/dist/connectors/db/lib/plugin_config.js.map +1 -0
- package/dist/connectors/db/lib/policy.d.ts +162 -0
- package/dist/connectors/db/lib/policy.d.ts.map +1 -0
- package/dist/connectors/db/lib/policy.js +581 -0
- package/dist/connectors/db/lib/policy.js.map +1 -0
- package/dist/connectors/db/lib/query.d.ts +22 -0
- package/dist/connectors/db/lib/query.d.ts.map +1 -0
- package/dist/connectors/db/lib/query.js +93 -0
- package/dist/connectors/db/lib/query.js.map +1 -0
- package/dist/connectors/db/lib/schema.d.ts +13 -0
- package/dist/connectors/db/lib/schema.d.ts.map +1 -0
- package/dist/connectors/db/lib/schema.js +80 -0
- package/dist/connectors/db/lib/schema.js.map +1 -0
- package/dist/connectors/gcp/cli.d.ts +3 -0
- package/dist/connectors/gcp/cli.d.ts.map +1 -0
- package/dist/connectors/gcp/cli.js +24 -0
- package/dist/connectors/gcp/cli.js.map +1 -0
- package/dist/connectors/gcp/index.d.ts +24 -0
- package/dist/connectors/gcp/index.d.ts.map +1 -0
- package/dist/connectors/gcp/index.js +205 -0
- package/dist/connectors/gcp/index.js.map +1 -0
- package/dist/connectors/gcp/lib/gcp_client.d.ts +88 -0
- package/dist/connectors/gcp/lib/gcp_client.d.ts.map +1 -0
- package/dist/connectors/gcp/lib/gcp_client.js +434 -0
- package/dist/connectors/gcp/lib/gcp_client.js.map +1 -0
- package/dist/connectors/gcp/lib/gcp_error.d.ts +10 -0
- package/dist/connectors/gcp/lib/gcp_error.d.ts.map +1 -0
- package/dist/connectors/gcp/lib/gcp_error.js +15 -0
- package/dist/connectors/gcp/lib/gcp_error.js.map +1 -0
- package/dist/connectors/github/cli.d.ts +3 -0
- package/dist/connectors/github/cli.d.ts.map +1 -0
- package/dist/connectors/github/cli.js +23 -0
- package/dist/connectors/github/cli.js.map +1 -0
- package/dist/connectors/github/index.d.ts +23 -0
- package/dist/connectors/github/index.d.ts.map +1 -0
- package/dist/connectors/github/index.js +462 -0
- package/dist/connectors/github/index.js.map +1 -0
- package/dist/connectors/github/lib/github_client.d.ts +181 -0
- package/dist/connectors/github/lib/github_client.d.ts.map +1 -0
- package/dist/connectors/github/lib/github_client.js +383 -0
- package/dist/connectors/github/lib/github_client.js.map +1 -0
- package/dist/connectors/github/lib/github_error.d.ts +11 -0
- package/dist/connectors/github/lib/github_error.d.ts.map +1 -0
- package/dist/connectors/github/lib/github_error.js +17 -0
- package/dist/connectors/github/lib/github_error.js.map +1 -0
- package/dist/connectors/jira/cli.d.ts +3 -0
- package/dist/connectors/jira/cli.d.ts.map +1 -0
- package/dist/connectors/jira/cli.js +24 -0
- package/dist/connectors/jira/cli.js.map +1 -0
- package/dist/connectors/jira/index.d.ts +13 -0
- package/dist/connectors/jira/index.d.ts.map +1 -0
- package/dist/connectors/jira/index.js +287 -0
- package/dist/connectors/jira/index.js.map +1 -0
- package/dist/connectors/jira/lib/adf.d.ts +25 -0
- package/dist/connectors/jira/lib/adf.d.ts.map +1 -0
- package/dist/connectors/jira/lib/adf.js +105 -0
- package/dist/connectors/jira/lib/adf.js.map +1 -0
- package/dist/connectors/jira/lib/jira_client.d.ts +143 -0
- package/dist/connectors/jira/lib/jira_client.d.ts.map +1 -0
- package/dist/connectors/jira/lib/jira_client.js +355 -0
- package/dist/connectors/jira/lib/jira_client.js.map +1 -0
- package/dist/connectors/jira/lib/jira_error.d.ts +11 -0
- package/dist/connectors/jira/lib/jira_error.d.ts.map +1 -0
- package/dist/connectors/jira/lib/jira_error.js +17 -0
- package/dist/connectors/jira/lib/jira_error.js.map +1 -0
- package/dist/connectors/notion/cli.d.ts +3 -0
- package/dist/connectors/notion/cli.d.ts.map +1 -0
- package/dist/connectors/notion/cli.js +22 -0
- package/dist/connectors/notion/cli.js.map +1 -0
- package/dist/connectors/notion/index.d.ts +20 -0
- package/dist/connectors/notion/index.d.ts.map +1 -0
- package/dist/connectors/notion/index.js +317 -0
- package/dist/connectors/notion/index.js.map +1 -0
- package/dist/connectors/notion/lib/notion_client.d.ts +117 -0
- package/dist/connectors/notion/lib/notion_client.d.ts.map +1 -0
- package/dist/connectors/notion/lib/notion_client.js +377 -0
- package/dist/connectors/notion/lib/notion_client.js.map +1 -0
- package/dist/connectors/notion/lib/notion_error.d.ts +12 -0
- package/dist/connectors/notion/lib/notion_error.d.ts.map +1 -0
- package/dist/connectors/notion/lib/notion_error.js +18 -0
- package/dist/connectors/notion/lib/notion_error.js.map +1 -0
- package/dist/hub/cli.d.ts +4 -0
- package/dist/hub/cli.d.ts.map +1 -0
- package/dist/hub/cli.js +93 -0
- package/dist/hub/cli.js.map +1 -0
- package/dist/hub/dispatch.d.ts +33 -0
- package/dist/hub/dispatch.d.ts.map +1 -0
- package/dist/hub/dispatch.js +297 -0
- package/dist/hub/dispatch.js.map +1 -0
- package/dist/hub/index.d.ts +9 -0
- package/dist/hub/index.d.ts.map +1 -0
- package/dist/hub/index.js +215 -0
- package/dist/hub/index.js.map +1 -0
- package/dist/hub/plan.d.ts +24 -0
- package/dist/hub/plan.d.ts.map +1 -0
- package/dist/hub/plan.js +103 -0
- package/dist/hub/plan.js.map +1 -0
- package/dist/hub/types.d.ts +65 -0
- package/dist/hub/types.d.ts.map +1 -0
- package/dist/hub/types.js +3 -0
- package/dist/hub/types.js.map +1 -0
- package/dist/toolkit/_optional.d.ts +14 -0
- package/dist/toolkit/_optional.d.ts.map +1 -0
- package/dist/toolkit/_optional.js +96 -0
- package/dist/toolkit/_optional.js.map +1 -0
- package/dist/toolkit/agent_cli.d.ts +33 -0
- package/dist/toolkit/agent_cli.d.ts.map +1 -0
- package/dist/toolkit/agent_cli.js +62 -0
- package/dist/toolkit/agent_cli.js.map +1 -0
- package/dist/toolkit/agent_resolver.d.ts +46 -0
- package/dist/toolkit/agent_resolver.d.ts.map +1 -0
- package/dist/toolkit/agent_resolver.js +78 -0
- package/dist/toolkit/agent_resolver.js.map +1 -0
- package/dist/toolkit/audit/events.d.ts +45 -0
- package/dist/toolkit/audit/events.d.ts.map +1 -0
- package/dist/toolkit/audit/events.js +8 -0
- package/dist/toolkit/audit/events.js.map +1 -0
- package/dist/toolkit/audit/writer.d.ts +16 -0
- package/dist/toolkit/audit/writer.d.ts.map +1 -0
- package/dist/toolkit/audit/writer.js +73 -0
- package/dist/toolkit/audit/writer.js.map +1 -0
- package/dist/toolkit/cli/usage-report.d.ts +3 -0
- package/dist/toolkit/cli/usage-report.d.ts.map +1 -0
- package/dist/toolkit/cli/usage-report.js +76 -0
- package/dist/toolkit/cli/usage-report.js.map +1 -0
- package/dist/toolkit/connector.d.ts +142 -0
- package/dist/toolkit/connector.d.ts.map +1 -0
- package/dist/toolkit/connector.js +593 -0
- package/dist/toolkit/connector.js.map +1 -0
- package/dist/toolkit/extract_binary.d.ts +45 -0
- package/dist/toolkit/extract_binary.d.ts.map +1 -0
- package/dist/toolkit/extract_binary.js +342 -0
- package/dist/toolkit/extract_binary.js.map +1 -0
- package/dist/toolkit/extract_multimodal.d.ts +22 -0
- package/dist/toolkit/extract_multimodal.d.ts.map +1 -0
- package/dist/toolkit/extract_multimodal.js +209 -0
- package/dist/toolkit/extract_multimodal.js.map +1 -0
- package/dist/toolkit/fetch_attachment.d.ts +21 -0
- package/dist/toolkit/fetch_attachment.d.ts.map +1 -0
- package/dist/toolkit/fetch_attachment.js +169 -0
- package/dist/toolkit/fetch_attachment.js.map +1 -0
- package/dist/toolkit/fetch_helper.d.ts +47 -0
- package/dist/toolkit/fetch_helper.d.ts.map +1 -0
- package/dist/toolkit/fetch_helper.js +124 -0
- package/dist/toolkit/fetch_helper.js.map +1 -0
- package/dist/toolkit/guardrail.d.ts +63 -0
- package/dist/toolkit/guardrail.d.ts.map +1 -0
- package/dist/toolkit/guardrail.js +166 -0
- package/dist/toolkit/guardrail.js.map +1 -0
- package/dist/toolkit/hardship/curate.d.ts +47 -0
- package/dist/toolkit/hardship/curate.d.ts.map +1 -0
- package/dist/toolkit/hardship/curate.js +113 -0
- package/dist/toolkit/hardship/curate.js.map +1 -0
- package/dist/toolkit/hardship/patterns.d.ts +32 -0
- package/dist/toolkit/hardship/patterns.d.ts.map +1 -0
- package/dist/toolkit/hardship/patterns.js +98 -0
- package/dist/toolkit/hardship/patterns.js.map +1 -0
- package/dist/toolkit/hardship/preamble.d.ts +13 -0
- package/dist/toolkit/hardship/preamble.d.ts.map +1 -0
- package/dist/toolkit/hardship/preamble.js +47 -0
- package/dist/toolkit/hardship/preamble.js.map +1 -0
- package/dist/toolkit/hardship/read.d.ts +34 -0
- package/dist/toolkit/hardship/read.d.ts.map +1 -0
- package/dist/toolkit/hardship/read.js +116 -0
- package/dist/toolkit/hardship/read.js.map +1 -0
- package/dist/toolkit/hardship/record.d.ts +43 -0
- package/dist/toolkit/hardship/record.d.ts.map +1 -0
- package/dist/toolkit/hardship/record.js +74 -0
- package/dist/toolkit/hardship/record.js.map +1 -0
- package/dist/toolkit/hardship/scope.d.ts +20 -0
- package/dist/toolkit/hardship/scope.d.ts.map +1 -0
- package/dist/toolkit/hardship/scope.js +56 -0
- package/dist/toolkit/hardship/scope.js.map +1 -0
- package/dist/toolkit/index.d.ts +42 -0
- package/dist/toolkit/index.d.ts.map +1 -0
- package/dist/toolkit/index.js +51 -0
- package/dist/toolkit/index.js.map +1 -0
- package/dist/toolkit/plugin/curate-cmd.d.ts +22 -0
- package/dist/toolkit/plugin/curate-cmd.d.ts.map +1 -0
- package/dist/toolkit/plugin/curate-cmd.js +72 -0
- package/dist/toolkit/plugin/curate-cmd.js.map +1 -0
- package/dist/toolkit/plugin/prefs.d.ts +15 -0
- package/dist/toolkit/plugin/prefs.d.ts.map +1 -0
- package/dist/toolkit/plugin/prefs.js +78 -0
- package/dist/toolkit/plugin/prefs.js.map +1 -0
- package/dist/toolkit/plugin/reminder.d.ts +28 -0
- package/dist/toolkit/plugin/reminder.d.ts.map +1 -0
- package/dist/toolkit/plugin/reminder.js +103 -0
- package/dist/toolkit/plugin/reminder.js.map +1 -0
- package/dist/toolkit/policy/approval.d.ts +24 -0
- package/dist/toolkit/policy/approval.d.ts.map +1 -0
- package/dist/toolkit/policy/approval.js +56 -0
- package/dist/toolkit/policy/approval.js.map +1 -0
- package/dist/toolkit/policy/config.d.ts +38 -0
- package/dist/toolkit/policy/config.d.ts.map +1 -0
- package/dist/toolkit/policy/config.js +172 -0
- package/dist/toolkit/policy/config.js.map +1 -0
- package/dist/toolkit/policy/gate.d.ts +28 -0
- package/dist/toolkit/policy/gate.d.ts.map +1 -0
- package/dist/toolkit/policy/gate.js +126 -0
- package/dist/toolkit/policy/gate.js.map +1 -0
- package/dist/toolkit/policy/types.d.ts +106 -0
- package/dist/toolkit/policy/types.d.ts.map +1 -0
- package/dist/toolkit/policy/types.js +22 -0
- package/dist/toolkit/policy/types.js.map +1 -0
- package/dist/toolkit/security_check.d.ts +15 -0
- package/dist/toolkit/security_check.d.ts.map +1 -0
- package/dist/toolkit/security_check.js +109 -0
- package/dist/toolkit/security_check.js.map +1 -0
- package/dist/toolkit/usage/aggregate-cross-session.d.ts +36 -0
- package/dist/toolkit/usage/aggregate-cross-session.d.ts.map +1 -0
- package/dist/toolkit/usage/aggregate-cross-session.js +142 -0
- package/dist/toolkit/usage/aggregate-cross-session.js.map +1 -0
- package/dist/toolkit/usage/aggregate.d.ts +4 -0
- package/dist/toolkit/usage/aggregate.d.ts.map +1 -0
- package/dist/toolkit/usage/aggregate.js +105 -0
- package/dist/toolkit/usage/aggregate.js.map +1 -0
- package/dist/toolkit/usage/index.d.ts +11 -0
- package/dist/toolkit/usage/index.d.ts.map +1 -0
- package/dist/toolkit/usage/index.js +7 -0
- package/dist/toolkit/usage/index.js.map +1 -0
- package/dist/toolkit/usage/parse.d.ts +5 -0
- package/dist/toolkit/usage/parse.d.ts.map +1 -0
- package/dist/toolkit/usage/parse.js +19 -0
- package/dist/toolkit/usage/parse.js.map +1 -0
- package/dist/toolkit/usage/record.d.ts +8 -0
- package/dist/toolkit/usage/record.d.ts.map +1 -0
- package/dist/toolkit/usage/record.js +18 -0
- package/dist/toolkit/usage/record.js.map +1 -0
- package/dist/toolkit/usage/retention.d.ts +6 -0
- package/dist/toolkit/usage/retention.d.ts.map +1 -0
- package/dist/toolkit/usage/retention.js +71 -0
- package/dist/toolkit/usage/retention.js.map +1 -0
- package/dist/toolkit/usage/tokenize.d.ts +11 -0
- package/dist/toolkit/usage/tokenize.d.ts.map +1 -0
- package/dist/toolkit/usage/tokenize.js +24 -0
- package/dist/toolkit/usage/tokenize.js.map +1 -0
- package/dist/toolkit/usage/types.d.ts +34 -0
- package/dist/toolkit/usage/types.d.ts.map +1 -0
- package/dist/toolkit/usage/types.js +2 -0
- package/dist/toolkit/usage/types.js.map +1 -0
- package/package.json +124 -0
- package/plugin-hooks/session-summary.mjs +138 -0
- package/plugin-hooks/stale-summarize.mjs +70 -0
- package/plugin-hooks/usage-record.mjs +112 -0
- package/plugins/aws-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/aws-agent/README.md +46 -0
- package/plugins/aws-agent/bin/aws-agent +22 -0
- package/plugins/aws-agent/commands/aws-agent.md +6 -0
- package/plugins/aws-agent/hooks/hooks.json +49 -0
- package/plugins/aws-agent/hooks/reminder.mjs +16 -0
- package/plugins/aws-agent/package.json +9 -0
- package/plugins/aws-agent/skills/aws-agent/SKILL.md +70 -0
- package/plugins/confluence-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/confluence-agent/README.md +15 -0
- package/plugins/confluence-agent/bin/confluence-agent +17 -0
- package/plugins/confluence-agent/commands/confluence-agent.md +6 -0
- package/plugins/confluence-agent/hooks/hooks.json +49 -0
- package/plugins/confluence-agent/hooks/reminder.mjs +25 -0
- package/plugins/confluence-agent/package.json +8 -0
- package/plugins/confluence-agent/skills/confluence-agent/SKILL.md +40 -0
- package/plugins/db-agent/.claude-plugin/plugin.json +20 -0
- package/plugins/db-agent/README.md +13 -0
- package/plugins/db-agent/bin/db-agent +17 -0
- package/plugins/db-agent/commands/db-agent.md +6 -0
- package/plugins/db-agent/hooks/db-guard.mjs +110 -0
- package/plugins/db-agent/hooks/guardrails.json +26 -0
- package/plugins/db-agent/hooks/hooks.json +61 -0
- package/plugins/db-agent/hooks/reminder.mjs +16 -0
- package/plugins/db-agent/package.json +8 -0
- package/plugins/db-agent/skills/db-agent/SKILL.md +50 -0
- package/plugins/gcp-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/gcp-agent/README.md +31 -0
- package/plugins/gcp-agent/bin/gcp-agent +18 -0
- package/plugins/gcp-agent/commands/gcp-agent.md +6 -0
- package/plugins/gcp-agent/hooks/hooks.json +49 -0
- package/plugins/gcp-agent/hooks/reminder.mjs +16 -0
- package/plugins/gcp-agent/package.json +9 -0
- package/plugins/gcp-agent/skills/gcp-agent/SKILL.md +54 -0
- package/plugins/github-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/github-agent/README.md +13 -0
- package/plugins/github-agent/bin/github-agent +17 -0
- package/plugins/github-agent/commands/github-agent.md +6 -0
- package/plugins/github-agent/hooks/hooks.json +49 -0
- package/plugins/github-agent/hooks/reminder.mjs +16 -0
- package/plugins/github-agent/package.json +8 -0
- package/plugins/github-agent/skills/github-agent/SKILL.md +41 -0
- package/plugins/jira-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/jira-agent/README.md +15 -0
- package/plugins/jira-agent/bin/jira-agent +17 -0
- package/plugins/jira-agent/commands/jira-agent.md +6 -0
- package/plugins/jira-agent/hooks/hooks.json +49 -0
- package/plugins/jira-agent/hooks/reminder.mjs +16 -0
- package/plugins/jira-agent/package.json +8 -0
- package/plugins/jira-agent/skills/jira-agent/SKILL.md +37 -0
- package/plugins/notion-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/notion-agent/README.md +23 -0
- package/plugins/notion-agent/bin/notion-agent +17 -0
- package/plugins/notion-agent/commands/notion-agent.md +6 -0
- package/plugins/notion-agent/hooks/hooks.json +49 -0
- package/plugins/notion-agent/hooks/reminder.mjs +17 -0
- package/plugins/notion-agent/package.json +8 -0
- package/plugins/notion-agent/skills/notion-agent/SKILL.md +48 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ApprovalMode, type PolicyRules } from "./types.js";
|
|
2
|
+
export interface LoadedPolicy {
|
|
3
|
+
rules: PolicyRules;
|
|
4
|
+
approval_mode: ApprovalMode;
|
|
5
|
+
}
|
|
6
|
+
export interface LoadPolicyConfigOptions {
|
|
7
|
+
/** Connector name — shapes the discovery path `~/.<name>-agent/config.yaml`. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Aspects that cannot be downgraded to `"success"` by operator config. */
|
|
10
|
+
floorAspects?: readonly string[];
|
|
11
|
+
/** Explicit path (overrides discovery). */
|
|
12
|
+
explicitPath?: string;
|
|
13
|
+
/** Working directory for the repo-level lookup. Defaults to `process.cwd()`. */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
/** Override home dir (tests). Defaults to `os.homedir()`. */
|
|
16
|
+
home?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DiscoveredPaths {
|
|
19
|
+
user?: string;
|
|
20
|
+
repo?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function discoverConfigPaths(name: string, cwd?: string, home?: string): DiscoveredPaths;
|
|
23
|
+
/** Recursive per-key merge. Overlay wins on collision; arrays replace wholesale. */
|
|
24
|
+
export declare function deepMerge<T extends Record<string, unknown>>(base: T, overlay: T): T;
|
|
25
|
+
/**
|
|
26
|
+
* Top-level validator: accepts a parsed YAML mapping with optional `policy`
|
|
27
|
+
* and `approval_mode` keys, returns a LoadedPolicy. Unknown top-level keys
|
|
28
|
+
* pass through silently — this lets connectors add their own sections
|
|
29
|
+
* (e.g., db-agent's `servers`, `audit`) without the toolkit needing to know
|
|
30
|
+
* about them.
|
|
31
|
+
*/
|
|
32
|
+
export declare function validatePolicyConfig(raw: unknown, floorAspects?: readonly string[]): LoadedPolicy;
|
|
33
|
+
/**
|
|
34
|
+
* Discover → merge → validate. Returns `null` if no config is found and no
|
|
35
|
+
* explicit path is provided; caller falls back to defaults.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadPolicyConfig(opts: LoadPolicyConfigOptions): LoadedPolicy | null;
|
|
38
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/toolkit/policy/config.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAGjB,MAAM,YAAY,CAAC;AAgBpB,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,YAAY,CAAC;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,MAAsB,EAC3B,IAAI,GAAE,MAAqB,GAC1B,eAAe,CAQjB;AAWD,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,GACT,CAAC,CAWH;AAsGD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,OAAO,EACZ,YAAY,GAAE,SAAS,MAAM,EAAO,GACnC,YAAY,CAUd;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,uBAAuB,GAC5B,YAAY,GAAG,IAAI,CAkBrB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator-facing config loader. Discovers two YAML files for each connector:
|
|
3
|
+
*
|
|
4
|
+
* 1. `~/.<name>-agent/config.yaml` — user-level base
|
|
5
|
+
* 2. `<cwd>/.<name>-agent/config.yaml` — repo-level overlay (wins on collision)
|
|
6
|
+
*
|
|
7
|
+
* Plus an optional explicit path (caller-provided). Returns validated
|
|
8
|
+
* `PolicyRules` + `ApprovalMode`, or `null` if no config is discovered and no
|
|
9
|
+
* explicit path is given — callers fall through to `DEFAULT_POLICY` + `"auto"`.
|
|
10
|
+
*
|
|
11
|
+
* Safety floor: `admin` can never be `"success"` in config. Connectors can
|
|
12
|
+
* declare additional floor aspects (e.g., db-agent declares `ddl`, `privilege`);
|
|
13
|
+
* those aspects are also rejected if set to `"success"`.
|
|
14
|
+
*/
|
|
15
|
+
import * as fs from "node:fs";
|
|
16
|
+
import * as os from "node:os";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import * as yaml from "js-yaml";
|
|
19
|
+
import { DEFAULT_POLICY, } from "./types.js";
|
|
20
|
+
const VALID_RULES = new Set([
|
|
21
|
+
"success",
|
|
22
|
+
"present",
|
|
23
|
+
"escalate",
|
|
24
|
+
"denied",
|
|
25
|
+
]);
|
|
26
|
+
const VALID_APPROVAL_MODES = new Set([
|
|
27
|
+
"auto",
|
|
28
|
+
"confirm_once",
|
|
29
|
+
"confirm_each",
|
|
30
|
+
"grant_required",
|
|
31
|
+
]);
|
|
32
|
+
export function discoverConfigPaths(name, cwd = process.cwd(), home = os.homedir()) {
|
|
33
|
+
const rel = `.${name}-agent/config.yaml`;
|
|
34
|
+
const userPath = path.join(home, rel);
|
|
35
|
+
const repoPath = path.join(cwd, rel);
|
|
36
|
+
const out = {};
|
|
37
|
+
if (fs.existsSync(userPath))
|
|
38
|
+
out.user = userPath;
|
|
39
|
+
if (fs.existsSync(repoPath))
|
|
40
|
+
out.repo = repoPath;
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function isPlainObject(v) {
|
|
44
|
+
return (typeof v === "object" &&
|
|
45
|
+
v !== null &&
|
|
46
|
+
!Array.isArray(v) &&
|
|
47
|
+
v.constructor === Object);
|
|
48
|
+
}
|
|
49
|
+
/** Recursive per-key merge. Overlay wins on collision; arrays replace wholesale. */
|
|
50
|
+
export function deepMerge(base, overlay) {
|
|
51
|
+
const out = { ...base };
|
|
52
|
+
for (const [k, v] of Object.entries(overlay)) {
|
|
53
|
+
const baseV = base[k];
|
|
54
|
+
if (isPlainObject(v) && isPlainObject(baseV)) {
|
|
55
|
+
out[k] = deepMerge(baseV, v);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
out[k] = v;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
function readYaml(filePath) {
|
|
64
|
+
const raw = fs.readFileSync(filePath, { encoding: "utf-8" });
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = yaml.load(raw);
|
|
68
|
+
}
|
|
69
|
+
catch (exc) {
|
|
70
|
+
const msg = exc instanceof Error ? exc.message : String(exc);
|
|
71
|
+
throw new Error(`Failed to parse YAML (${filePath}): ${msg}`);
|
|
72
|
+
}
|
|
73
|
+
if (parsed === null || parsed === undefined)
|
|
74
|
+
return {};
|
|
75
|
+
if (!isPlainObject(parsed)) {
|
|
76
|
+
throw new Error(`Config must be a YAML mapping (${filePath}), got: ${Array.isArray(parsed) ? "list" : typeof parsed}`);
|
|
77
|
+
}
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
function validateRule(field, value, restricted) {
|
|
81
|
+
if (typeof value !== "string" || !VALID_RULES.has(value)) {
|
|
82
|
+
throw new Error(`${field}: expected one of [success, present, escalate, denied], got: ${JSON.stringify(value)}`);
|
|
83
|
+
}
|
|
84
|
+
const rule = value;
|
|
85
|
+
if (restricted && rule === "success") {
|
|
86
|
+
throw new Error(`${field}: 'success' is not permitted (safety floor — cannot be downgraded to success)`);
|
|
87
|
+
}
|
|
88
|
+
return rule;
|
|
89
|
+
}
|
|
90
|
+
function validateRules(raw, floorAspects) {
|
|
91
|
+
if (raw === undefined || raw === null)
|
|
92
|
+
return { ...DEFAULT_POLICY };
|
|
93
|
+
if (!isPlainObject(raw)) {
|
|
94
|
+
throw new Error(`policy: expected an object, got: ${typeof raw}`);
|
|
95
|
+
}
|
|
96
|
+
const out = { ...DEFAULT_POLICY };
|
|
97
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
98
|
+
switch (k) {
|
|
99
|
+
case "read":
|
|
100
|
+
out.read = validateRule("policy.read", v, false);
|
|
101
|
+
break;
|
|
102
|
+
case "write":
|
|
103
|
+
out.write = validateRule("policy.write", v, false);
|
|
104
|
+
break;
|
|
105
|
+
case "admin":
|
|
106
|
+
out.admin = validateRule("policy.admin", v, true);
|
|
107
|
+
break;
|
|
108
|
+
case "aspects": {
|
|
109
|
+
if (!isPlainObject(v)) {
|
|
110
|
+
throw new Error(`policy.aspects: expected an object, got: ${typeof v}`);
|
|
111
|
+
}
|
|
112
|
+
const aspects = {};
|
|
113
|
+
const floorSet = new Set(floorAspects);
|
|
114
|
+
for (const [aspect, rule] of Object.entries(v)) {
|
|
115
|
+
aspects[aspect] = validateRule(`policy.aspects.${aspect}`, rule, floorSet.has(aspect));
|
|
116
|
+
}
|
|
117
|
+
out.aspects = aspects;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`policy: unknown key '${k}' (expected: read, write, admin, aspects)`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
function validateApprovalMode(raw) {
|
|
127
|
+
if (raw === undefined || raw === null)
|
|
128
|
+
return "auto";
|
|
129
|
+
if (typeof raw !== "string" || !VALID_APPROVAL_MODES.has(raw)) {
|
|
130
|
+
throw new Error(`approval_mode: expected one of [auto, confirm_once, confirm_each, grant_required], got: ${JSON.stringify(raw)}`);
|
|
131
|
+
}
|
|
132
|
+
return raw;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Top-level validator: accepts a parsed YAML mapping with optional `policy`
|
|
136
|
+
* and `approval_mode` keys, returns a LoadedPolicy. Unknown top-level keys
|
|
137
|
+
* pass through silently — this lets connectors add their own sections
|
|
138
|
+
* (e.g., db-agent's `servers`, `audit`) without the toolkit needing to know
|
|
139
|
+
* about them.
|
|
140
|
+
*/
|
|
141
|
+
export function validatePolicyConfig(raw, floorAspects = []) {
|
|
142
|
+
if (!isPlainObject(raw)) {
|
|
143
|
+
throw new Error(`config: expected a YAML mapping at root, got: ${typeof raw}`);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
rules: validateRules(raw["policy"], floorAspects),
|
|
147
|
+
approval_mode: validateApprovalMode(raw["approval_mode"]),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Discover → merge → validate. Returns `null` if no config is found and no
|
|
152
|
+
* explicit path is provided; caller falls back to defaults.
|
|
153
|
+
*/
|
|
154
|
+
export function loadPolicyConfig(opts) {
|
|
155
|
+
const floor = opts.floorAspects ?? [];
|
|
156
|
+
if (opts.explicitPath !== undefined && opts.explicitPath.length > 0) {
|
|
157
|
+
if (!fs.existsSync(opts.explicitPath)) {
|
|
158
|
+
throw new Error(`Config file not found: ${opts.explicitPath}`);
|
|
159
|
+
}
|
|
160
|
+
return validatePolicyConfig(readYaml(opts.explicitPath), floor);
|
|
161
|
+
}
|
|
162
|
+
const paths = discoverConfigPaths(opts.name, opts.cwd, opts.home);
|
|
163
|
+
if (paths.user === undefined && paths.repo === undefined)
|
|
164
|
+
return null;
|
|
165
|
+
let merged = {};
|
|
166
|
+
if (paths.user !== undefined)
|
|
167
|
+
merged = deepMerge(merged, readYaml(paths.user));
|
|
168
|
+
if (paths.repo !== undefined)
|
|
169
|
+
merged = deepMerge(merged, readYaml(paths.repo));
|
|
170
|
+
return validatePolicyConfig(merged, floor);
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/toolkit/policy/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,M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AAS,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAE/E,OAAO,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure rule → Decision mapping. Stateless; approval-mode state lives in
|
|
3
|
+
* `./approval.ts` (the factory wires it up per connector invocation).
|
|
4
|
+
*
|
|
5
|
+
* Rule combination: kind rule is the base; each aspect rule (if declared)
|
|
6
|
+
* applies on top via Rule strictness (denied > escalate > present > success).
|
|
7
|
+
* Note: Rule "present" collapses to Decision "escalate" — extendDecision
|
|
8
|
+
* hooks intercept escalate to emit ExtendedEnvelope.
|
|
9
|
+
* Ties go to the first offender so the `reason` message is predictable.
|
|
10
|
+
*/
|
|
11
|
+
import type { ApprovalMode, Classification, Decision, PolicyRules } from "./types.js";
|
|
12
|
+
/** Minimal state needed for approval-mode resolution. Pure-data. */
|
|
13
|
+
export interface ApprovalState {
|
|
14
|
+
sessionApproved: boolean;
|
|
15
|
+
hasActiveGrant: (grantType: string) => boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Evaluate a classification against rules + approval mode, returning a
|
|
19
|
+
* decision. No side effects — the caller is responsible for emitting audit
|
|
20
|
+
* events (see `../audit/writer.ts`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkPolicy(classification: Classification, rules: PolicyRules, approvalMode: ApprovalMode, approvalState: ApprovalState): Decision;
|
|
23
|
+
/**
|
|
24
|
+
* Combine multiple per-call decisions (e.g., db-agent classifies each SQL
|
|
25
|
+
* statement separately). Strictest decision wins; ties by first occurrence.
|
|
26
|
+
*/
|
|
27
|
+
export declare function combineDecisions(decisions: readonly Decision[]): Decision;
|
|
28
|
+
//# sourceMappingURL=gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../../src/toolkit/policy/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EAEZ,MAAM,YAAY,CAAC;AAWpB,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CAChD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,GAC3B,QAAQ,CA0CV;AAuCD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAYzE"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { DECISION_RANK } from "./types.js";
|
|
2
|
+
/** Strictness rank for combining Rule values (same order as DECISION_RANK). */
|
|
3
|
+
const RULE_RANK = {
|
|
4
|
+
success: 0,
|
|
5
|
+
present: 1,
|
|
6
|
+
escalate: 2,
|
|
7
|
+
denied: 3,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Evaluate a classification against rules + approval mode, returning a
|
|
11
|
+
* decision. No side effects — the caller is responsible for emitting audit
|
|
12
|
+
* events (see `../audit/writer.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export function checkPolicy(classification, rules, approvalMode, approvalState) {
|
|
15
|
+
const kind = classification.kind;
|
|
16
|
+
const kindRule = rules[kind];
|
|
17
|
+
// Combine kind rule with the strictest matching aspect rule.
|
|
18
|
+
let combinedRule = kindRule;
|
|
19
|
+
let strictestReasonSource = "kind";
|
|
20
|
+
let offendingAspect = null;
|
|
21
|
+
if (classification.aspects && rules.aspects) {
|
|
22
|
+
for (const aspect of classification.aspects) {
|
|
23
|
+
const aspectRule = rules.aspects[aspect];
|
|
24
|
+
if (aspectRule === undefined)
|
|
25
|
+
continue;
|
|
26
|
+
if (RULE_RANK[aspectRule] > RULE_RANK[combinedRule]) {
|
|
27
|
+
combinedRule = aspectRule;
|
|
28
|
+
strictestReasonSource = "aspect";
|
|
29
|
+
offendingAspect = aspect;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Map the combined rule to a decision.
|
|
34
|
+
switch (combinedRule) {
|
|
35
|
+
case "denied":
|
|
36
|
+
return { status: "denied", reason: denyReason(kind, strictestReasonSource, offendingAspect) };
|
|
37
|
+
case "escalate":
|
|
38
|
+
return {
|
|
39
|
+
status: "escalate",
|
|
40
|
+
reason: escalateReason(kind, strictestReasonSource, offendingAspect),
|
|
41
|
+
};
|
|
42
|
+
// Rule "present" collapses to Decision "escalate" in toolkit 3.0;
|
|
43
|
+
// extendDecision hooks (e.g. db-agent) intercept escalate to emit
|
|
44
|
+
// a connector-specific ExtendedEnvelope.
|
|
45
|
+
case "present":
|
|
46
|
+
return { status: "escalate", reason: presentReason(kind, strictestReasonSource, offendingAspect) };
|
|
47
|
+
case "success":
|
|
48
|
+
// A "success" rule for reads still has to pass the approval mode gate.
|
|
49
|
+
if (kind === "read") {
|
|
50
|
+
return resolveApprovalMode(approvalMode, approvalState);
|
|
51
|
+
}
|
|
52
|
+
return { status: "success", reason: `${kind} allowed by policy` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Read-specific: given that policy says "success", apply the approval-mode
|
|
57
|
+
* state machine.
|
|
58
|
+
*
|
|
59
|
+
* - auto: always success
|
|
60
|
+
* - confirm_once: escalate until sessionApproved, then success
|
|
61
|
+
* - confirm_each: always escalate
|
|
62
|
+
* - grant_required: success iff hasActiveGrant("read"), else denied
|
|
63
|
+
*/
|
|
64
|
+
function resolveApprovalMode(mode, state) {
|
|
65
|
+
switch (mode) {
|
|
66
|
+
case "auto":
|
|
67
|
+
return { status: "success", reason: "auto-approved" };
|
|
68
|
+
case "confirm_once":
|
|
69
|
+
if (state.sessionApproved) {
|
|
70
|
+
return { status: "success", reason: "session approved" };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
status: "escalate",
|
|
74
|
+
reason: "First read requires confirmation (confirm_once)",
|
|
75
|
+
};
|
|
76
|
+
case "confirm_each":
|
|
77
|
+
return {
|
|
78
|
+
status: "escalate",
|
|
79
|
+
reason: "Each read requires confirmation (confirm_each)",
|
|
80
|
+
};
|
|
81
|
+
case "grant_required":
|
|
82
|
+
if (state.hasActiveGrant("read")) {
|
|
83
|
+
return { status: "success", reason: "active read grant" };
|
|
84
|
+
}
|
|
85
|
+
return { status: "denied", reason: "No active read grant" };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Combine multiple per-call decisions (e.g., db-agent classifies each SQL
|
|
90
|
+
* statement separately). Strictest decision wins; ties by first occurrence.
|
|
91
|
+
*/
|
|
92
|
+
export function combineDecisions(decisions) {
|
|
93
|
+
if (decisions.length === 0) {
|
|
94
|
+
throw new Error("combineDecisions requires at least one decision");
|
|
95
|
+
}
|
|
96
|
+
let winner = decisions[0];
|
|
97
|
+
for (let i = 1; i < decisions.length; i++) {
|
|
98
|
+
const d = decisions[i];
|
|
99
|
+
if (DECISION_RANK[d.status] > DECISION_RANK[winner.status]) {
|
|
100
|
+
winner = d;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return winner;
|
|
104
|
+
}
|
|
105
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
106
|
+
// Reason builders — stable strings so tests/evals can assert on them.
|
|
107
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
108
|
+
function denyReason(kind, source, aspect) {
|
|
109
|
+
if (source === "aspect" && aspect !== null) {
|
|
110
|
+
return `${aspect} aspect is denied by policy`;
|
|
111
|
+
}
|
|
112
|
+
return `${kind} is denied by policy`;
|
|
113
|
+
}
|
|
114
|
+
function escalateReason(kind, source, aspect) {
|
|
115
|
+
if (source === "aspect" && aspect !== null) {
|
|
116
|
+
return `${aspect} aspect requires approval`;
|
|
117
|
+
}
|
|
118
|
+
return `${kind} requires approval`;
|
|
119
|
+
}
|
|
120
|
+
function presentReason(kind, source, aspect) {
|
|
121
|
+
if (source === "aspect" && aspect !== null) {
|
|
122
|
+
return `${aspect} aspect is displayed but not executed`;
|
|
123
|
+
}
|
|
124
|
+
return `${kind} is displayed but not executed`;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../../../src/toolkit/policy/gate.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,+EAA+E;AAC/E,MAAM,SAAS,GAAyB;IACtC,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;CACV,CAAC;AAQF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,cAA8B,EAC9B,KAAkB,EAClB,YAA0B,EAC1B,aAA4B;IAE5B,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC;IACjC,MAAM,QAAQ,GAAS,KAAK,CAAC,IAAI,CAAC,CAAC;IAEnC,6DAA6D;IAC7D,IAAI,YAAY,GAAS,QAAQ,CAAC;IAClC,IAAI,qBAAqB,GAAsB,MAAM,CAAC;IACtD,IAAI,eAAe,GAAkB,IAAI,CAAC;IAE1C,IAAI,cAAc,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACzC,IAAI,UAAU,KAAK,SAAS;gBAAE,SAAS;YACvC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,SAA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AC;IAChD,CAAC;IACD,OAAO,GAAG,IAAI,sBAAsB,CAAC;AACvC,CAAC;AAED,SAAS,cAAc,CACrB,IAAY,EACZ,MAAyB,EACzB,MAAqB;IAErB,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC3C,OAAO,GAAG,MAAM,2BAA2B,CAAC;IAC9C,CAAC;IACD,OAAO,GAAG,IAAI,oBAAoB,CAAC;AACrC,CAAC;AAED,SAAS,aAAa,CACpB,IAAY,EACZ,MAAyB,EACzB,MAAqB;IAErB,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC3C,OAAO,GAAG,MAAM,uCAAuC,CAAC;IAC1D,CAAC;IACD,OAAO,GAAG,IAAI,gCAAgC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval-gate type system. Shared across every connector.
|
|
3
|
+
*
|
|
4
|
+
* Wire formats are lowercase string literals so JSON round-trips without a
|
|
5
|
+
* codec step. The canonical envelope `status` is `success | denied | escalate
|
|
6
|
+
* | error`; connectors MAY extend with custom status values via the
|
|
7
|
+
* `extendDecision` hook on `createConnector` (db-agent uses `present_only`).
|
|
8
|
+
*/
|
|
9
|
+
/** The CRUD-ish base axis every connector classifies into. */
|
|
10
|
+
export type Kind = "read" | "write" | "admin";
|
|
11
|
+
/**
|
|
12
|
+
* Kind plus optional connector-specific aspects (free-form strings).
|
|
13
|
+
* Aspects layer on top of kind for finer gating (e.g. `unbounded_select`,
|
|
14
|
+
* `source_code`, `pii`, `bulk_read`). Rule lookup applies kind first, then
|
|
15
|
+
* the strictest aspect rule that matches wins.
|
|
16
|
+
*/
|
|
17
|
+
export interface Classification {
|
|
18
|
+
kind: Kind;
|
|
19
|
+
aspects?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/** Wire rules operators set per classification. */
|
|
22
|
+
export type Rule = "success" | "present" | "escalate" | "denied";
|
|
23
|
+
/** Rule without `"success"` — used for safety-floor slots (admin, ddl, privilege). */
|
|
24
|
+
export type RestrictedRule = Exclude<Rule, "success">;
|
|
25
|
+
export interface PolicyRules {
|
|
26
|
+
read: Rule;
|
|
27
|
+
write: Rule;
|
|
28
|
+
admin: RestrictedRule;
|
|
29
|
+
/** Per-aspect rule map. Absent aspects fall through to the kind's rule. */
|
|
30
|
+
aspects?: Record<string, Rule>;
|
|
31
|
+
}
|
|
32
|
+
export type ApprovalMode = "auto" | "confirm_once" | "confirm_each" | "grant_required";
|
|
33
|
+
/** Defaults matching db-agent's historical behavior, generalized to CRUD. */
|
|
34
|
+
export declare const DEFAULT_POLICY: PolicyRules;
|
|
35
|
+
/**
|
|
36
|
+
* A gate decision. `extendDecision` hooks (e.g., db-agent's `present_only`)
|
|
37
|
+
* widen this by returning an envelope with additional fields; the base
|
|
38
|
+
* discriminants are fixed.
|
|
39
|
+
*/
|
|
40
|
+
export type Decision = {
|
|
41
|
+
status: "success";
|
|
42
|
+
reason: string;
|
|
43
|
+
} | {
|
|
44
|
+
status: "denied";
|
|
45
|
+
reason: string;
|
|
46
|
+
} | {
|
|
47
|
+
status: "escalate";
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
/** Strictness rank for combining multiple decisions (denied wins). */
|
|
51
|
+
export declare const DECISION_RANK: Record<Decision["status"], number>;
|
|
52
|
+
/** Canonical 7-code error taxonomy used across every connector. */
|
|
53
|
+
export type ErrorCode = "AUTH_ERROR" | "NOT_FOUND" | "RATE_LIMITED" | "TIMEOUT" | "VALIDATION_ERROR" | "CONFIG_ERROR" | "CONNECTION_ERROR";
|
|
54
|
+
/** Success envelope — data payload is connector-specific. */
|
|
55
|
+
export interface SuccessEnvelope {
|
|
56
|
+
status: "success";
|
|
57
|
+
action: string;
|
|
58
|
+
data: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolution hint attached to non-success envelopes when a curated hardship
|
|
62
|
+
* pattern matches. Task 6.2 attaches these at runtime.
|
|
63
|
+
*/
|
|
64
|
+
export interface ResolutionHint {
|
|
65
|
+
pattern_id: string;
|
|
66
|
+
advice: string;
|
|
67
|
+
confidence: number;
|
|
68
|
+
scope: "tenant" | "global";
|
|
69
|
+
}
|
|
70
|
+
/** Gate-deny envelope. */
|
|
71
|
+
export interface DeniedEnvelope {
|
|
72
|
+
status: "denied";
|
|
73
|
+
action: string;
|
|
74
|
+
reason: string;
|
|
75
|
+
resolution_hint?: ResolutionHint;
|
|
76
|
+
}
|
|
77
|
+
/** Gate-escalate envelope. */
|
|
78
|
+
export interface EscalateEnvelope {
|
|
79
|
+
status: "escalate";
|
|
80
|
+
action: string;
|
|
81
|
+
reason: string;
|
|
82
|
+
resolution_hint?: ResolutionHint;
|
|
83
|
+
}
|
|
84
|
+
/** Runtime error envelope. */
|
|
85
|
+
export interface ErrorEnvelope {
|
|
86
|
+
status: "error";
|
|
87
|
+
action: string;
|
|
88
|
+
error_code: ErrorCode;
|
|
89
|
+
message: string;
|
|
90
|
+
retriable: boolean;
|
|
91
|
+
resolution_hint?: ResolutionHint;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Connector-extended envelope. `extendDecision` hooks may emit custom status
|
|
95
|
+
* values (e.g., `present_only`). The `extension` field carries the
|
|
96
|
+
* connector-specific payload; arbitrary extra fields are accessed via cast.
|
|
97
|
+
*/
|
|
98
|
+
export interface ExtendedEnvelope {
|
|
99
|
+
status: string;
|
|
100
|
+
action: string;
|
|
101
|
+
message?: string;
|
|
102
|
+
extension: Record<string, unknown>;
|
|
103
|
+
resolution_hint?: ResolutionHint;
|
|
104
|
+
}
|
|
105
|
+
export type Envelope = SuccessEnvelope | DeniedEnvelope | EscalateEnvelope | ErrorEnvelope | ExtendedEnvelope;
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../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GAChB,eAAe,GACf,cAAc,GACd,gBAAgB,GAChB,aAAa,GACb,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval-gate type system. Shared across every connector.
|
|
3
|
+
*
|
|
4
|
+
* Wire formats are lowercase string literals so JSON round-trips without a
|
|
5
|
+
* codec step. The canonical envelope `status` is `success | denied | escalate
|
|
6
|
+
* | error`; connectors MAY extend with custom status values via the
|
|
7
|
+
* `extendDecision` hook on `createConnector` (db-agent uses `present_only`).
|
|
8
|
+
*/
|
|
9
|
+
/** Defaults matching db-agent's historical behavior, generalized to CRUD. */
|
|
10
|
+
export const DEFAULT_POLICY = {
|
|
11
|
+
read: "success",
|
|
12
|
+
write: "present",
|
|
13
|
+
admin: "denied",
|
|
14
|
+
aspects: {},
|
|
15
|
+
};
|
|
16
|
+
/** Strictness rank for combining multiple decisions (denied wins). */
|
|
17
|
+
export const DECISION_RANK = {
|
|
18
|
+
success: 0,
|
|
19
|
+
escalate: 1,
|
|
20
|
+
denied: 2,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/toolkit/policy/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA4CH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,cAAc,GAAgB;IACzC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,EAAE;CACZ,CAAC;AAgBF,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAuC;IAC/D,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;CACV,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { FETCH_MAX_BYTES_DEFAULT, FETCH_TIMEOUT_MS_DEFAULT, FetchCapExceeded, fetchWithCaps, type FetchCapsOptions, } from "./fetch_helper.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check that a URL uses an allowed scheme (http or https only).
|
|
4
|
+
*/
|
|
5
|
+
export declare function validateUrl(url: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Verify that `p` resolves to a location inside `wikiRoot`.
|
|
8
|
+
* Symlinks are resolved before the prefix comparison, to prevent traversal.
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkPathContainment(p: string, wikiRoot: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Sanitize a label by stripping control characters, capping length, and HTML-escaping.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeLabel(label: string, maxLength?: number): string;
|
|
15
|
+
//# sourceMappingURL=security_check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security_check.d.ts","sourceRoot":"","sources":["../../src/toolkit/security_check.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,GACtB,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUhD;AA+CD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWzE;AAkBD;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAK5E"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* security_check — URL validation, path containment, and label sanitization.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the fetch-cap symbols from `fetch_helper` so the two
|
|
5
|
+
* security-baseline knobs live under one import at call sites.
|
|
6
|
+
* `fetch_helper` remains the canonical owner; update the numbers there.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
export { FETCH_MAX_BYTES_DEFAULT, FETCH_TIMEOUT_MS_DEFAULT, FetchCapExceeded, fetchWithCaps, } from "./fetch_helper.js";
|
|
11
|
+
const ALLOWED_SCHEMES = new Set(["http", "https"]);
|
|
12
|
+
/**
|
|
13
|
+
* Check that a URL uses an allowed scheme (http or https only).
|
|
14
|
+
*/
|
|
15
|
+
export function validateUrl(url) {
|
|
16
|
+
if (!url) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const match = url.match(/^([A-Za-z][A-Za-z0-9+.\-]*):/);
|
|
20
|
+
if (!match || match[1] === undefined) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const scheme = match[1].toLowerCase();
|
|
24
|
+
return ALLOWED_SCHEMES.has(scheme);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Best-effort realpath that mirrors Python's pathlib.Path.resolve(strict=False).
|
|
28
|
+
*
|
|
29
|
+
* Resolves existing symlinks in the path even when the full path does not
|
|
30
|
+
* exist: walks up from the target until finding an existing ancestor,
|
|
31
|
+
* realpaths it, then re-appends the non-existent tail.
|
|
32
|
+
*
|
|
33
|
+
* TOCTOU note: this function calls `existsSync` / `lstatSync` and then
|
|
34
|
+
* `realpathSync.native` as two distinct system calls. On POSIX there is
|
|
35
|
+
* no atomic replacement (Node's fs API does not expose `openat` /
|
|
36
|
+
* `O_NOFOLLOW`), so on a shared host a malicious local user could swap
|
|
37
|
+
* a parent directory between the two calls and defeat path containment
|
|
38
|
+
* checks built on top of this function. Callers must run this helper in
|
|
39
|
+
* a directory hierarchy under their own control — a developer workstation
|
|
40
|
+
* or a CI runner with a private filesystem. If multi-user isolation is
|
|
41
|
+
* required, sandbox the toolchain (container, user namespace, etc.)
|
|
42
|
+
* rather than relying on this function to police the filesystem.
|
|
43
|
+
*/
|
|
44
|
+
function bestEffortRealpath(p) {
|
|
45
|
+
const abs = path.resolve(p);
|
|
46
|
+
const tail = [];
|
|
47
|
+
let cur = abs;
|
|
48
|
+
while (cur && cur !== path.dirname(cur)) {
|
|
49
|
+
let entryExists = fs.existsSync(cur);
|
|
50
|
+
if (!entryExists) {
|
|
51
|
+
try {
|
|
52
|
+
fs.lstatSync(cur);
|
|
53
|
+
entryExists = true;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
/* path truly absent; continue walking up */
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (entryExists) {
|
|
60
|
+
const real = fs.realpathSync.native(cur);
|
|
61
|
+
if (tail.length === 0) {
|
|
62
|
+
return real;
|
|
63
|
+
}
|
|
64
|
+
return path.join(real, ...tail.reverse());
|
|
65
|
+
}
|
|
66
|
+
tail.push(path.basename(cur));
|
|
67
|
+
cur = path.dirname(cur);
|
|
68
|
+
}
|
|
69
|
+
return abs;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Verify that `p` resolves to a location inside `wikiRoot`.
|
|
73
|
+
* Symlinks are resolved before the prefix comparison, to prevent traversal.
|
|
74
|
+
*/
|
|
75
|
+
export function checkPathContainment(p, wikiRoot) {
|
|
76
|
+
try {
|
|
77
|
+
const resolvedPath = bestEffortRealpath(p);
|
|
78
|
+
const resolvedRoot = bestEffortRealpath(wikiRoot);
|
|
79
|
+
return (resolvedPath.startsWith(resolvedRoot + path.sep) ||
|
|
80
|
+
resolvedPath === resolvedRoot);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* HTML-escape a string the same way Python's html.escape(s, quote=True) does.
|
|
88
|
+
* Ampersand must be escaped first so subsequent replacements don't double-escape.
|
|
89
|
+
*/
|
|
90
|
+
function htmlEscape(s) {
|
|
91
|
+
return s
|
|
92
|
+
.replace(/&/g, "&")
|
|
93
|
+
.replace(/</g, "<")
|
|
94
|
+
.replace(/>/g, ">")
|
|
95
|
+
.replace(/"/g, """)
|
|
96
|
+
.replace(/'/g, "'");
|
|
97
|
+
}
|
|
98
|
+
// Regex matching Unicode general-category "Cc" (control chars): U+0000..U+001F, U+007F..U+009F.
|
|
99
|
+
const CONTROL_CHARS_RE = /[\u0000-\u001F\u007F-\u009F]/g;
|
|
100
|
+
/**
|
|
101
|
+
* Sanitize a label by stripping control characters, capping length, and HTML-escaping.
|
|
102
|
+
*/
|
|
103
|
+
export function sanitizeLabel(label, maxLength = 256) {
|
|
104
|
+
let cleaned = label.replace(CONTROL_CHARS_RE, "");
|
|
105
|
+
cleaned = cleaned.slice(0, maxLength);
|
|
106
|
+
cleaned = htmlEscape(cleaned);
|
|
107
|
+
return cleaned;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=security_check.js.map
|