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,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch_attachment — single-call primitive that fetches a URL, reads the
|
|
3
|
+
* bytes (under a size cap), dispatches to `extractBinary` or UTF-8 decode
|
|
4
|
+
* based on content-type, and returns a structured envelope.
|
|
5
|
+
*
|
|
6
|
+
* Used by REST connectors (Confluence/Notion/Jira/GitHub) to implement
|
|
7
|
+
* `get_attachment` actions without each reimplementing the fetch +
|
|
8
|
+
* extract + checksum pipeline.
|
|
9
|
+
*
|
|
10
|
+
* Contract:
|
|
11
|
+
* - Never throws on unsupported mime types or missing optional extraction
|
|
12
|
+
* deps. Surfaces `extracted.format = "skipped"` + a populated `warning`.
|
|
13
|
+
* - Throws on invalid URL scheme (anything but http/https) before
|
|
14
|
+
* making the network call.
|
|
15
|
+
* - Throws when response body exceeds `maxBytes`.
|
|
16
|
+
* - Returns `{ rawBytes, contentType, filename, checksum, extracted,
|
|
17
|
+
* sizeBytes, sourceUrl }`. Filename is sanitized via `sanitizeLabel`.
|
|
18
|
+
*
|
|
19
|
+
* For tests, `fetchImpl` can be injected to bypass the real network.
|
|
20
|
+
*/
|
|
21
|
+
import * as fs from "node:fs";
|
|
22
|
+
import * as os from "node:os";
|
|
23
|
+
import * as path from "node:path";
|
|
24
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
25
|
+
import { validateUrl, sanitizeLabel } from "./security_check.js";
|
|
26
|
+
import { FETCH_MAX_BYTES_DEFAULT, FETCH_TIMEOUT_MS_DEFAULT, FetchCapExceeded } from "./fetch_helper.js";
|
|
27
|
+
import { extract as extractBinary, FORMAT_MAP } from "./extract_binary.js";
|
|
28
|
+
const MIME_TO_FORMAT = {
|
|
29
|
+
"application/pdf": "pdf",
|
|
30
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
31
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
|
|
32
|
+
};
|
|
33
|
+
function parseContentDispositionFilename(header) {
|
|
34
|
+
if (!header)
|
|
35
|
+
return null;
|
|
36
|
+
// Handle quoted: `attachment; filename="a.txt"` and unquoted: `attachment; filename=a.txt`.
|
|
37
|
+
const match = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(header);
|
|
38
|
+
return match && match[1] ? match[1].trim() : null;
|
|
39
|
+
}
|
|
40
|
+
function filenameFromUrl(url) {
|
|
41
|
+
try {
|
|
42
|
+
const u = new URL(url);
|
|
43
|
+
const tail = u.pathname.split("/").filter(Boolean).pop();
|
|
44
|
+
return tail ?? "attachment";
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return "attachment";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function formatExtension(fmt) {
|
|
51
|
+
if (fmt === "pdf")
|
|
52
|
+
return ".pdf";
|
|
53
|
+
if (fmt === "docx")
|
|
54
|
+
return ".docx";
|
|
55
|
+
return ".pptx";
|
|
56
|
+
}
|
|
57
|
+
export async function fetchAttachment(url, opts = {}) {
|
|
58
|
+
if (!validateUrl(url)) {
|
|
59
|
+
throw new Error(`fetchAttachment: invalid URL scheme for '${url}' (only http/https allowed)`);
|
|
60
|
+
}
|
|
61
|
+
const maxBytes = opts.maxBytes ?? FETCH_MAX_BYTES_DEFAULT;
|
|
62
|
+
const timeoutMs = opts.timeoutMs ?? FETCH_TIMEOUT_MS_DEFAULT;
|
|
63
|
+
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
66
|
+
const init = { signal: controller.signal };
|
|
67
|
+
if (opts.headers !== undefined) {
|
|
68
|
+
init.headers = opts.headers;
|
|
69
|
+
}
|
|
70
|
+
let response;
|
|
71
|
+
try {
|
|
72
|
+
response = await doFetch(url, init);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
const contentLength = Number(response.headers.get("content-length") ?? "0");
|
|
78
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
79
|
+
throw new FetchCapExceeded(maxBytes, contentLength, url);
|
|
80
|
+
}
|
|
81
|
+
const buffer = await response.arrayBuffer();
|
|
82
|
+
const rawBytes = new Uint8Array(buffer);
|
|
83
|
+
if (rawBytes.byteLength > maxBytes) {
|
|
84
|
+
throw new FetchCapExceeded(maxBytes, rawBytes.byteLength, url);
|
|
85
|
+
}
|
|
86
|
+
const contentType = (response.headers.get("content-type") ?? "application/octet-stream")
|
|
87
|
+
.split(";")[0]
|
|
88
|
+
?.trim()
|
|
89
|
+
.toLowerCase() ?? "application/octet-stream";
|
|
90
|
+
const dispositionFilename = parseContentDispositionFilename(response.headers.get("content-disposition"));
|
|
91
|
+
const rawFilename = dispositionFilename ?? filenameFromUrl(url);
|
|
92
|
+
const filename = sanitizeLabel(rawFilename, 255);
|
|
93
|
+
const checksum = createHash("sha256").update(rawBytes).digest("hex");
|
|
94
|
+
let extracted;
|
|
95
|
+
if (contentType.startsWith("text/")) {
|
|
96
|
+
extracted = {
|
|
97
|
+
format: "text",
|
|
98
|
+
text: new TextDecoder("utf-8").decode(rawBytes),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
else if (contentType in MIME_TO_FORMAT) {
|
|
102
|
+
const fmt = MIME_TO_FORMAT[contentType];
|
|
103
|
+
const ext = formatExtension(fmt);
|
|
104
|
+
const tmp = path.join(os.tmpdir(), `toolkit-attach-${randomUUID()}${ext}`);
|
|
105
|
+
try {
|
|
106
|
+
fs.writeFileSync(tmp, rawBytes);
|
|
107
|
+
const r = await extractBinary(tmp, fmt, { maxBytes });
|
|
108
|
+
extracted = { format: r.format, text: r.text };
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
extracted = {
|
|
112
|
+
format: "skipped",
|
|
113
|
+
text: null,
|
|
114
|
+
warning: e instanceof Error ? e.message : String(e),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
try {
|
|
119
|
+
fs.unlinkSync(tmp);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* best-effort cleanup */
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (FORMAT_MAP[path.extname(filename).toLowerCase()]) {
|
|
127
|
+
// Server advertised a generic mime (octet-stream etc.) but the filename
|
|
128
|
+
// extension is one we can extract — still try.
|
|
129
|
+
const fmt = FORMAT_MAP[path.extname(filename).toLowerCase()];
|
|
130
|
+
const tmp = path.join(os.tmpdir(), `toolkit-attach-${randomUUID()}${formatExtension(fmt)}`);
|
|
131
|
+
try {
|
|
132
|
+
fs.writeFileSync(tmp, rawBytes);
|
|
133
|
+
const r = await extractBinary(tmp, fmt, { maxBytes });
|
|
134
|
+
extracted = { format: r.format, text: r.text };
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
extracted = {
|
|
138
|
+
format: "skipped",
|
|
139
|
+
text: null,
|
|
140
|
+
warning: e instanceof Error ? e.message : String(e),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
try {
|
|
145
|
+
fs.unlinkSync(tmp);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
/* best-effort cleanup */
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
extracted = {
|
|
154
|
+
format: "skipped",
|
|
155
|
+
text: null,
|
|
156
|
+
warning: `Unsupported mime type '${contentType}' — no extractor configured`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
rawBytes,
|
|
161
|
+
contentType,
|
|
162
|
+
filename,
|
|
163
|
+
checksum,
|
|
164
|
+
extracted,
|
|
165
|
+
sizeBytes: rawBytes.byteLength,
|
|
166
|
+
sourceUrl: url,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=fetch_attachment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch_attachment.js","sourceRoot":"","sources":["../../src/toolkit/fetch_attachment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAA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AAC,GAAG,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;YACtD,SAAS,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,SAAS,GAAG;gBACV,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;aACpD,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC;gBACH,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;YAAC,MAAM,CAAC;gBACP,yBAAyB;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,SAAS,GAAG;YACV,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,0BAA0B,WAAW,6BAA6B;SAC5E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ;QACR,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,SAAS,EAAE,QAAQ,CAAC,UAAU;QAC9B,SAAS,EAAE,GAAG;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch_helper — shared HTTP fetch wrapper with size + timeout caps.
|
|
3
|
+
*
|
|
4
|
+
* Behaviour:
|
|
5
|
+
* - `AbortController` enforces the timeout. On overrun, the returned
|
|
6
|
+
* promise rejects with the underlying `AbortError`.
|
|
7
|
+
* - Body size is enforced by streaming the response and counting
|
|
8
|
+
* bytes. If `content-length` is present and already exceeds the
|
|
9
|
+
* cap, we short-circuit before reading. Otherwise we read chunks;
|
|
10
|
+
* once the running total exceeds `maxBytes`, we abort and throw
|
|
11
|
+
* `FetchCapExceeded`.
|
|
12
|
+
* - Consumers receive a plain `Response` whose `body` has been
|
|
13
|
+
* replaced by a `ReadableStream` that reads from an in-memory
|
|
14
|
+
* buffer; calling `.text()` or `.arrayBuffer()` on that Response
|
|
15
|
+
* returns exactly the (capped) bytes.
|
|
16
|
+
*/
|
|
17
|
+
export declare const FETCH_MAX_BYTES_DEFAULT: number;
|
|
18
|
+
export declare const FETCH_TIMEOUT_MS_DEFAULT = 60000;
|
|
19
|
+
/** Options controlling the caps. Missing fields fall back to defaults. */
|
|
20
|
+
export interface FetchCapsOptions {
|
|
21
|
+
maxBytes?: number;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
/** Optional external signal composed with the internal timeout. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** Thrown when the response body grows past `maxBytes`. */
|
|
27
|
+
export declare class FetchCapExceeded extends Error {
|
|
28
|
+
readonly capBytes: number;
|
|
29
|
+
readonly observedBytes: number;
|
|
30
|
+
constructor(capBytes: number, observedBytes: number, url: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Perform a cap-limited fetch. The returned Response is safe to treat
|
|
34
|
+
* as a normal `Response`; its body has already been read into memory
|
|
35
|
+
* (bounded by `maxBytes`), and the Response is rebuilt around that
|
|
36
|
+
* buffer so downstream `.text()` / `.json()` / `.arrayBuffer()` calls
|
|
37
|
+
* work without re-hitting the network.
|
|
38
|
+
*
|
|
39
|
+
* Throws:
|
|
40
|
+
* - `FetchCapExceeded` when `content-length` or streamed bytes
|
|
41
|
+
* exceed `maxBytes`.
|
|
42
|
+
* - `DOMException` / `AbortError` when the timeout fires or an
|
|
43
|
+
* external signal is aborted.
|
|
44
|
+
* - Any other error thrown by `fetch` itself (network, DNS, etc.).
|
|
45
|
+
*/
|
|
46
|
+
export declare function fetchWithCaps(url: string, init?: RequestInit, caps?: FetchCapsOptions): Promise<Response>;
|
|
47
|
+
//# sourceMappingURL=fetch_helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch_helper.d.ts","sourceRoot":"","sources":["../../src/toolkit/fetch_helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,uBAAuB,QAAmB,CAAC;AACxD,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,2DAA2D;AAC3D,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBACnB,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CASjE;AAsBD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAuDnB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch_helper — shared HTTP fetch wrapper with size + timeout caps.
|
|
3
|
+
*
|
|
4
|
+
* Behaviour:
|
|
5
|
+
* - `AbortController` enforces the timeout. On overrun, the returned
|
|
6
|
+
* promise rejects with the underlying `AbortError`.
|
|
7
|
+
* - Body size is enforced by streaming the response and counting
|
|
8
|
+
* bytes. If `content-length` is present and already exceeds the
|
|
9
|
+
* cap, we short-circuit before reading. Otherwise we read chunks;
|
|
10
|
+
* once the running total exceeds `maxBytes`, we abort and throw
|
|
11
|
+
* `FetchCapExceeded`.
|
|
12
|
+
* - Consumers receive a plain `Response` whose `body` has been
|
|
13
|
+
* replaced by a `ReadableStream` that reads from an in-memory
|
|
14
|
+
* buffer; calling `.text()` or `.arrayBuffer()` on that Response
|
|
15
|
+
* returns exactly the (capped) bytes.
|
|
16
|
+
*/
|
|
17
|
+
export const FETCH_MAX_BYTES_DEFAULT = 50 * 1024 * 1024; // 50 MB
|
|
18
|
+
export const FETCH_TIMEOUT_MS_DEFAULT = 60_000; // 60 s
|
|
19
|
+
/** Thrown when the response body grows past `maxBytes`. */
|
|
20
|
+
export class FetchCapExceeded extends Error {
|
|
21
|
+
capBytes;
|
|
22
|
+
observedBytes;
|
|
23
|
+
constructor(capBytes, observedBytes, url) {
|
|
24
|
+
super(`fetch_helper: response body exceeded cap of ${capBytes} bytes ` +
|
|
25
|
+
`(observed ${observedBytes} while fetching ${url})`);
|
|
26
|
+
this.name = "FetchCapExceeded";
|
|
27
|
+
this.capBytes = capBytes;
|
|
28
|
+
this.observedBytes = observedBytes;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function mergeSignals(internal, external) {
|
|
32
|
+
if (external === undefined)
|
|
33
|
+
return internal;
|
|
34
|
+
const anyFn = AbortSignal.any;
|
|
35
|
+
if (typeof anyFn === "function") {
|
|
36
|
+
return anyFn([internal, external]);
|
|
37
|
+
}
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const onAbort = (reason) => {
|
|
40
|
+
controller.abort(reason);
|
|
41
|
+
};
|
|
42
|
+
if (internal.aborted)
|
|
43
|
+
controller.abort(internal.reason);
|
|
44
|
+
else
|
|
45
|
+
internal.addEventListener("abort", () => onAbort(internal.reason), { once: true });
|
|
46
|
+
if (external.aborted)
|
|
47
|
+
controller.abort(external.reason);
|
|
48
|
+
else
|
|
49
|
+
external.addEventListener("abort", () => onAbort(external.reason), { once: true });
|
|
50
|
+
return controller.signal;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Perform a cap-limited fetch. The returned Response is safe to treat
|
|
54
|
+
* as a normal `Response`; its body has already been read into memory
|
|
55
|
+
* (bounded by `maxBytes`), and the Response is rebuilt around that
|
|
56
|
+
* buffer so downstream `.text()` / `.json()` / `.arrayBuffer()` calls
|
|
57
|
+
* work without re-hitting the network.
|
|
58
|
+
*
|
|
59
|
+
* Throws:
|
|
60
|
+
* - `FetchCapExceeded` when `content-length` or streamed bytes
|
|
61
|
+
* exceed `maxBytes`.
|
|
62
|
+
* - `DOMException` / `AbortError` when the timeout fires or an
|
|
63
|
+
* external signal is aborted.
|
|
64
|
+
* - Any other error thrown by `fetch` itself (network, DNS, etc.).
|
|
65
|
+
*/
|
|
66
|
+
export async function fetchWithCaps(url, init = {}, caps = {}) {
|
|
67
|
+
const maxBytes = caps.maxBytes ?? FETCH_MAX_BYTES_DEFAULT;
|
|
68
|
+
const timeoutMs = caps.timeoutMs ?? FETCH_TIMEOUT_MS_DEFAULT;
|
|
69
|
+
const timeoutCtl = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => timeoutCtl.abort(new Error("fetch_helper timeout")), timeoutMs);
|
|
71
|
+
const signal = mergeSignals(timeoutCtl.signal, caps.signal ?? init.signal ?? undefined);
|
|
72
|
+
let response;
|
|
73
|
+
try {
|
|
74
|
+
response = await fetch(url, { ...init, signal });
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
const clHeader = response.headers.get("content-length");
|
|
80
|
+
if (clHeader !== null) {
|
|
81
|
+
const cl = Number(clHeader);
|
|
82
|
+
if (Number.isFinite(cl) && cl > maxBytes) {
|
|
83
|
+
try {
|
|
84
|
+
await response.body?.cancel();
|
|
85
|
+
}
|
|
86
|
+
catch { /* best-effort */ }
|
|
87
|
+
throw new FetchCapExceeded(maxBytes, cl, url);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const reader = response.body?.getReader();
|
|
91
|
+
if (reader === undefined) {
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
const chunks = [];
|
|
95
|
+
let total = 0;
|
|
96
|
+
while (true) {
|
|
97
|
+
const { done, value } = await reader.read();
|
|
98
|
+
if (done)
|
|
99
|
+
break;
|
|
100
|
+
if (value === undefined)
|
|
101
|
+
continue;
|
|
102
|
+
total += value.byteLength;
|
|
103
|
+
if (total > maxBytes) {
|
|
104
|
+
try {
|
|
105
|
+
await reader.cancel();
|
|
106
|
+
}
|
|
107
|
+
catch { /* best-effort */ }
|
|
108
|
+
throw new FetchCapExceeded(maxBytes, total, url);
|
|
109
|
+
}
|
|
110
|
+
chunks.push(value);
|
|
111
|
+
}
|
|
112
|
+
const merged = new Uint8Array(total);
|
|
113
|
+
let offset = 0;
|
|
114
|
+
for (const chunk of chunks) {
|
|
115
|
+
merged.set(chunk, offset);
|
|
116
|
+
offset += chunk.byteLength;
|
|
117
|
+
}
|
|
118
|
+
return new Response(merged, {
|
|
119
|
+
status: response.status,
|
|
120
|
+
statusText: response.statusText,
|
|
121
|
+
headers: response.headers,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=fetch_helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch_helper.js","sourceRoot":"","sources":["../../src/toolkit/fetch_helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,QAAQ;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,CAAC,OAAO;AAUvD,2DAA2D;AAC3D,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,QAAQ,CAAS;IACjB,aAAa,CAAS;IAC/B,YAAY,QAAgB,EAAE,aAAqB,EAAE,GAAW;QAC9D,KAAK,CACH,+CAA+C,QAAQ,SAAS;YAC9D,aAAa,aAAa,mBAAmB,GAAG,GAAG,CACtD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,Q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IAClB,CAAC;IAED,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAChB,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC;QAC1B,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC;gBAAC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAC1D,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* guardrail — connector-side rules for blocking dangerous Bash invocations,
|
|
3
|
+
* reusable from any plugin's PreToolUse hook.
|
|
4
|
+
*
|
|
5
|
+
* This module supplies:
|
|
6
|
+
* - The data shapes for a guardrail manifest (one JSON file per connector
|
|
7
|
+
* under `plugin/hooks/guardrails.json`).
|
|
8
|
+
* - A loader that reads + validates a manifest from disk.
|
|
9
|
+
* - A matching engine extracted from db-agent-connector's db-guard hook
|
|
10
|
+
* so every consumer (the per-connector hooks AND the hub's unified hook)
|
|
11
|
+
* evaluates the same way.
|
|
12
|
+
*
|
|
13
|
+
* Best-effort, not a security boundary. The engine fails open on parse
|
|
14
|
+
* errors; callers are expected to handle missing/invalid manifests gracefully.
|
|
15
|
+
*/
|
|
16
|
+
export interface GuardrailRule {
|
|
17
|
+
/**
|
|
18
|
+
* Match when the first whitespace-separated token of a Bash segment, after
|
|
19
|
+
* stripping env-var prefixes and shell openers, has a basename in this list.
|
|
20
|
+
*/
|
|
21
|
+
block_first_token_basename?: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* Match when the first two tokens (joined by a single space) of a Bash
|
|
24
|
+
* segment match one of these strings. Used for things like
|
|
25
|
+
* `aws dynamodb` where the program is `aws` but only the dynamodb subcommand
|
|
26
|
+
* should be blocked.
|
|
27
|
+
*/
|
|
28
|
+
block_two_token_command?: readonly string[];
|
|
29
|
+
/** Optional redirect/help string appended to the default deny message. */
|
|
30
|
+
redirect?: string;
|
|
31
|
+
/** Override the default deny message entirely. `${blocked}` is substituted with the matched token. */
|
|
32
|
+
deny_message?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GuardrailManifest {
|
|
35
|
+
/** Schema version. Always `1` for now. */
|
|
36
|
+
version: 1;
|
|
37
|
+
/** Source connector name; surfaces in deny messages. */
|
|
38
|
+
name: string;
|
|
39
|
+
rules: GuardrailRule[];
|
|
40
|
+
}
|
|
41
|
+
export interface BlockMatch {
|
|
42
|
+
manifest: GuardrailManifest;
|
|
43
|
+
rule: GuardrailRule;
|
|
44
|
+
/** What was matched, e.g. `"psql"` or `"aws dynamodb"`. */
|
|
45
|
+
blockedToken: string;
|
|
46
|
+
/** The original full command string from `tool_input.command`. */
|
|
47
|
+
command: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Read a guardrail manifest JSON file from disk and validate its shape.
|
|
51
|
+
* Throws on parse/validation errors; the caller is responsible for fail-open
|
|
52
|
+
* behaviour in PreToolUse hooks (catch + ignore).
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadGuardrailManifest(filePath: string): GuardrailManifest;
|
|
55
|
+
/**
|
|
56
|
+
* Walk a Bash command, including `&&`/`||`/`;`/`|` segments and nested
|
|
57
|
+
* `bash -c "..."` invocations, and return the first matching block, or
|
|
58
|
+
* null if nothing matches.
|
|
59
|
+
*/
|
|
60
|
+
export declare function findBlockingRule(command: string, manifests: readonly GuardrailManifest[], depth?: number): BlockMatch | null;
|
|
61
|
+
/** Compose the deny message — uses `rule.deny_message` if set, otherwise a default. */
|
|
62
|
+
export declare function defaultDenyMessage(match: BlockMatch): string;
|
|
63
|
+
//# sourceMappingURL=guardrail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardrail.d.ts","sourceRoot":"","sources":["../../src/toolkit/guardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,0BAA0B,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,OAAO,EAAE,CAAC,CAAC;IACX,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CASzE;AAyBD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,KAAK,SAAI,GACR,UAAU,GAAG,IAAI,CAwCnB;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAW5D"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* guardrail — connector-side rules for blocking dangerous Bash invocations,
|
|
3
|
+
* reusable from any plugin's PreToolUse hook.
|
|
4
|
+
*
|
|
5
|
+
* This module supplies:
|
|
6
|
+
* - The data shapes for a guardrail manifest (one JSON file per connector
|
|
7
|
+
* under `plugin/hooks/guardrails.json`).
|
|
8
|
+
* - A loader that reads + validates a manifest from disk.
|
|
9
|
+
* - A matching engine extracted from db-agent-connector's db-guard hook
|
|
10
|
+
* so every consumer (the per-connector hooks AND the hub's unified hook)
|
|
11
|
+
* evaluates the same way.
|
|
12
|
+
*
|
|
13
|
+
* Best-effort, not a security boundary. The engine fails open on parse
|
|
14
|
+
* errors; callers are expected to handle missing/invalid manifests gracefully.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
const SHELLS = new Set(["bash", "sh", "zsh", "ksh", "dash"]);
|
|
18
|
+
/**
|
|
19
|
+
* Read a guardrail manifest JSON file from disk and validate its shape.
|
|
20
|
+
* Throws on parse/validation errors; the caller is responsible for fail-open
|
|
21
|
+
* behaviour in PreToolUse hooks (catch + ignore).
|
|
22
|
+
*/
|
|
23
|
+
export function loadGuardrailManifest(filePath) {
|
|
24
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw new Error(`Failed to parse guardrail manifest at ${filePath}: ${err.message}`);
|
|
31
|
+
}
|
|
32
|
+
return validateManifest(parsed, filePath);
|
|
33
|
+
}
|
|
34
|
+
function validateManifest(value, filePath) {
|
|
35
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
36
|
+
throw new Error(`Guardrail manifest at ${filePath} must be a JSON object.`);
|
|
37
|
+
}
|
|
38
|
+
const obj = value;
|
|
39
|
+
if (obj["version"] !== 1) {
|
|
40
|
+
throw new Error(`Guardrail manifest at ${filePath} must have version: 1.`);
|
|
41
|
+
}
|
|
42
|
+
if (typeof obj["name"] !== "string" || obj["name"] === "") {
|
|
43
|
+
throw new Error(`Guardrail manifest at ${filePath} must have a non-empty 'name'.`);
|
|
44
|
+
}
|
|
45
|
+
if (!Array.isArray(obj["rules"])) {
|
|
46
|
+
throw new Error(`Guardrail manifest at ${filePath} must have a 'rules' array.`);
|
|
47
|
+
}
|
|
48
|
+
const rules = obj["rules"].map((r, i) => {
|
|
49
|
+
if (r === null || typeof r !== "object" || Array.isArray(r)) {
|
|
50
|
+
throw new Error(`Guardrail manifest at ${filePath}: rules[${i}] must be an object.`);
|
|
51
|
+
}
|
|
52
|
+
return r;
|
|
53
|
+
});
|
|
54
|
+
return { version: 1, name: obj["name"], rules };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Walk a Bash command, including `&&`/`||`/`;`/`|` segments and nested
|
|
58
|
+
* `bash -c "..."` invocations, and return the first matching block, or
|
|
59
|
+
* null if nothing matches.
|
|
60
|
+
*/
|
|
61
|
+
export function findBlockingRule(command, manifests, depth = 0) {
|
|
62
|
+
if (depth > 3)
|
|
63
|
+
return null;
|
|
64
|
+
const segments = splitSegments(command);
|
|
65
|
+
for (const seg of segments) {
|
|
66
|
+
const cleaned = stripOpeners(stripEnvPrefix(seg));
|
|
67
|
+
if (cleaned === "")
|
|
68
|
+
continue;
|
|
69
|
+
const tokens = tokenize(cleaned);
|
|
70
|
+
if (tokens.length === 0)
|
|
71
|
+
continue;
|
|
72
|
+
const head = basename(tokens[0] ?? "");
|
|
73
|
+
// Recurse into shell -c "..." subcommands.
|
|
74
|
+
const nested = unwrapShellDashC(tokens);
|
|
75
|
+
if (nested !== null) {
|
|
76
|
+
const inner = findBlockingRule(nested, manifests, depth + 1);
|
|
77
|
+
if (inner !== null)
|
|
78
|
+
return inner;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
// Two-token prefix match (e.g., "aws dynamodb").
|
|
82
|
+
if (tokens.length >= 2) {
|
|
83
|
+
const twoToken = `${head} ${tokens[1] ?? ""}`;
|
|
84
|
+
for (const m of manifests) {
|
|
85
|
+
for (const r of m.rules) {
|
|
86
|
+
if (r.block_two_token_command?.includes(twoToken)) {
|
|
87
|
+
return { manifest: m, rule: r, blockedToken: twoToken, command };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// First-token basename match.
|
|
93
|
+
for (const m of manifests) {
|
|
94
|
+
for (const r of m.rules) {
|
|
95
|
+
if (r.block_first_token_basename?.includes(head)) {
|
|
96
|
+
return { manifest: m, rule: r, blockedToken: head, command };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/** Compose the deny message — uses `rule.deny_message` if set, otherwise a default. */
|
|
104
|
+
export function defaultDenyMessage(match) {
|
|
105
|
+
if (typeof match.rule.deny_message === "string" && match.rule.deny_message !== "") {
|
|
106
|
+
return match.rule.deny_message.replace(/\$\{blocked\}/g, match.blockedToken);
|
|
107
|
+
}
|
|
108
|
+
const redirect = match.rule.redirect !== undefined && match.rule.redirect !== ""
|
|
109
|
+
? ` ${match.rule.redirect}`
|
|
110
|
+
: "";
|
|
111
|
+
return (`${match.manifest.name} guardrail: direct \`${match.blockedToken}\` invocation blocked.` +
|
|
112
|
+
`${redirect} Do NOT bypass this guardrail by obfuscating the invocation — reformulate the intent.`);
|
|
113
|
+
}
|
|
114
|
+
// ── internal helpers (extracted from db-guard.mjs so every hook agrees) ──
|
|
115
|
+
function splitSegments(cmd) {
|
|
116
|
+
return cmd
|
|
117
|
+
.split(/\|\||&&|;|\|/)
|
|
118
|
+
.map((s) => s.trim())
|
|
119
|
+
.filter((s) => s !== "");
|
|
120
|
+
}
|
|
121
|
+
function tokenize(s) {
|
|
122
|
+
return s.split(/\s+/).filter((t) => t !== "");
|
|
123
|
+
}
|
|
124
|
+
function basename(tok) {
|
|
125
|
+
const i = tok.lastIndexOf("/");
|
|
126
|
+
return i === -1 ? tok : tok.slice(i + 1);
|
|
127
|
+
}
|
|
128
|
+
function stripEnvPrefix(segment) {
|
|
129
|
+
let s = segment.trimStart();
|
|
130
|
+
if (s.startsWith("env "))
|
|
131
|
+
s = s.slice(4).trimStart();
|
|
132
|
+
while (/^[A-Za-z_][A-Za-z0-9_]*=/.test(s)) {
|
|
133
|
+
const m = s.match(/^\S+\s*/);
|
|
134
|
+
if (m === null)
|
|
135
|
+
break;
|
|
136
|
+
s = s.slice(m[0].length);
|
|
137
|
+
}
|
|
138
|
+
return s;
|
|
139
|
+
}
|
|
140
|
+
function stripOpeners(segment) {
|
|
141
|
+
let s = segment.trimStart();
|
|
142
|
+
while (s.length > 0) {
|
|
143
|
+
const c = s[0];
|
|
144
|
+
if (c === "(" || c === "{" || c === "!" || c === "`") {
|
|
145
|
+
s = s.slice(1).trimStart();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return s;
|
|
152
|
+
}
|
|
153
|
+
function unwrapShellDashC(tokens) {
|
|
154
|
+
if (tokens.length < 3)
|
|
155
|
+
return null;
|
|
156
|
+
const shell = basename(tokens[0] ?? "");
|
|
157
|
+
if (!SHELLS.has(shell))
|
|
158
|
+
return null;
|
|
159
|
+
const ci = tokens.indexOf("-c");
|
|
160
|
+
if (ci === -1 || ci + 1 >= tokens.length)
|
|
161
|
+
return null;
|
|
162
|
+
let inner = tokens.slice(ci + 1).join(" ").trim();
|
|
163
|
+
inner = inner.replace(/^(['"])([\s\S]*)\1$/, "$2");
|
|
164
|
+
return inner;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=guardrail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardrail.js","sourceRoot":"","sources":["../../src/toolkit/guardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAsC9B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAS,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,QAAgB;IACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE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AAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACrD,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAyB;IACjD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACtD,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curation helpers. Cluster raw JSONL hardships into proposed MD promotions.
|
|
3
|
+
*
|
|
4
|
+
* Curation happens in two phases:
|
|
5
|
+
*
|
|
6
|
+
* 1. Cluster — deterministic, no LLM: group entries by
|
|
7
|
+
* (connector, action, kind, normalized context key). Pure text work.
|
|
8
|
+
* 2. Promote — LLM-assisted: given clusters, propose which section of the
|
|
9
|
+
* MD file they belong in (Auth & Tokens / Rate Limits / ...) and write
|
|
10
|
+
* a human-readable summary. This module provides the *structure*;
|
|
11
|
+
* the actual LLM prompting is invoked by the `/connector-curate`
|
|
12
|
+
* slash command (which embeds prompt text that reads + invokes these
|
|
13
|
+
* helpers via the connector CLI).
|
|
14
|
+
*/
|
|
15
|
+
import type { HardshipEntry } from "./record.js";
|
|
16
|
+
export interface HardshipCluster {
|
|
17
|
+
signature: string;
|
|
18
|
+
connector: string;
|
|
19
|
+
action: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
scope: string | null;
|
|
22
|
+
count: number;
|
|
23
|
+
first_ts: string;
|
|
24
|
+
last_ts: string;
|
|
25
|
+
sample_contexts: string[];
|
|
26
|
+
sample_resolutions: string[];
|
|
27
|
+
sessions: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Normalize a free-form context string so minor differences (whitespace,
|
|
31
|
+
* timestamps, UUIDs) collapse into the same cluster.
|
|
32
|
+
*/
|
|
33
|
+
export declare function normalizeContext(raw: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Cluster a flat list of entries. Stable output: clusters are sorted by
|
|
36
|
+
* count descending, then by last_ts descending.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clusterHardships(entries: readonly HardshipEntry[]): HardshipCluster[];
|
|
39
|
+
export interface CurationMarker {
|
|
40
|
+
last_curated_ts: string | null;
|
|
41
|
+
last_curated_count: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function readCurationMarker(md: string): CurationMarker;
|
|
44
|
+
export declare function writeCurationMarker(md: string, marker: CurationMarker): string;
|
|
45
|
+
/** Filter entries newer than the last-curated timestamp. */
|
|
46
|
+
export declare function entriesSinceLastCuration(entries: readonly HardshipEntry[], marker: CurationMarker): HardshipEntry[];
|
|
47
|
+
//# sourceMappingURL=curate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curate.d.ts","sourceRoot":"","sources":["../../../src/toolkit/hardship/curate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQpD;AAiBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,aAAa,EAAE,GAChC,eAAe,EAAE,CAiCnB;AAQD,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,CAmB7D;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,CAU9E;AAED,4DAA4D;AAC5D,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,SAAS,aAAa,EAAE,EACjC,MAAM,EAAE,cAAc,GACrB,aAAa,EAAE,CAGjB"}
|