patchwork-os 0.2.0-beta.9.canary.93 → 1.1.0-beta.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/README.bridge.md +15 -16
- package/README.md +46 -458
- package/dist/activationMetrics.js +2 -3
- package/dist/activationMetrics.js.map +1 -1
- package/dist/activityLog.d.ts +1 -0
- package/dist/activityLog.js +8 -3
- package/dist/activityLog.js.map +1 -1
- package/dist/adapters/gemini.js +2 -2
- package/dist/adapters/gemini.js.map +1 -1
- package/dist/adapters/grok.js +6 -1
- package/dist/adapters/grok.js.map +1 -1
- package/dist/adapters/openai.js +4 -0
- package/dist/adapters/openai.js.map +1 -1
- package/dist/approvalHttp.d.ts +9 -0
- package/dist/approvalHttp.js +210 -171
- package/dist/approvalHttp.js.map +1 -1
- package/dist/approvalKpi.d.ts +102 -0
- package/dist/approvalKpi.js +282 -0
- package/dist/approvalKpi.js.map +1 -0
- package/dist/approvalQueue.d.ts +1 -1
- package/dist/approvalQueue.js.map +1 -1
- package/dist/automation.d.ts +45 -4
- package/dist/automation.js +123 -15
- package/dist/automation.js.map +1 -1
- package/dist/bridge.d.ts +10 -0
- package/dist/bridge.js +225 -46
- package/dist/bridge.js.map +1 -1
- package/dist/bridgeLockDiscovery.d.ts +16 -1
- package/dist/bridgeLockDiscovery.js +38 -4
- package/dist/bridgeLockDiscovery.js.map +1 -1
- package/dist/bridgeToolsRules.js +3 -18
- package/dist/bridgeToolsRules.js.map +1 -1
- package/dist/claudeAuthHttp.d.ts +25 -0
- package/dist/claudeAuthHttp.js +219 -0
- package/dist/claudeAuthHttp.js.map +1 -0
- package/dist/claudeDriver.js +4 -1
- package/dist/claudeDriver.js.map +1 -1
- package/dist/claudeOrchestrator.d.ts +15 -0
- package/dist/claudeOrchestrator.js +44 -0
- package/dist/claudeOrchestrator.js.map +1 -1
- package/dist/commands/connect.d.ts +47 -0
- package/dist/commands/connect.js +419 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/install.js +3 -10
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/launchd.d.ts +7 -0
- package/dist/commands/launchd.js +20 -2
- package/dist/commands/launchd.js.map +1 -1
- package/dist/commands/patchworkInit.d.ts +7 -0
- package/dist/commands/patchworkInit.js +26 -0
- package/dist/commands/patchworkInit.js.map +1 -1
- package/dist/commands/recipe.d.ts +59 -4
- package/dist/commands/recipe.js +206 -5
- package/dist/commands/recipe.js.map +1 -1
- package/dist/commands/recipeInstall.d.ts +9 -0
- package/dist/commands/recipeInstall.js +56 -3
- package/dist/commands/recipeInstall.js.map +1 -1
- package/dist/commands/task.d.ts +25 -0
- package/dist/commands/task.js +61 -41
- package/dist/commands/task.js.map +1 -1
- package/dist/commands/tokenEfficiency.d.ts +4 -0
- package/dist/commands/tokenEfficiency.js +23 -26
- package/dist/commands/tokenEfficiency.js.map +1 -1
- package/dist/commands/tracesExport.d.ts +15 -1
- package/dist/commands/tracesExport.js +39 -5
- package/dist/commands/tracesExport.js.map +1 -1
- package/dist/config.js +16 -0
- package/dist/config.js.map +1 -1
- package/dist/connectorRoutes.js +613 -62
- package/dist/connectorRoutes.js.map +1 -1
- package/dist/connectors/asana.js +9 -3
- package/dist/connectors/asana.js.map +1 -1
- package/dist/connectors/baseConnector.d.ts +16 -0
- package/dist/connectors/baseConnector.js +2 -0
- package/dist/connectors/baseConnector.js.map +1 -1
- package/dist/connectors/caldiy.js +34 -0
- package/dist/connectors/caldiy.js.map +1 -1
- package/dist/connectors/confluence.js +9 -2
- package/dist/connectors/confluence.js.map +1 -1
- package/dist/connectors/connectorActivity.d.ts +24 -0
- package/dist/connectors/connectorActivity.js +32 -0
- package/dist/connectors/connectorActivity.js.map +1 -0
- package/dist/connectors/connectorRedirectUri.js +22 -2
- package/dist/connectors/connectorRedirectUri.js.map +1 -1
- package/dist/connectors/connectorRegistry.d.ts +0 -3
- package/dist/connectors/connectorRegistry.js +8 -8
- package/dist/connectors/connectorRegistry.js.map +1 -1
- package/dist/connectors/datadog.js +8 -1
- package/dist/connectors/datadog.js.map +1 -1
- package/dist/connectors/discord.js +4 -3
- package/dist/connectors/discord.js.map +1 -1
- package/dist/connectors/elasticsearch.js +22 -0
- package/dist/connectors/elasticsearch.js.map +1 -1
- package/dist/connectors/github.d.ts +38 -0
- package/dist/connectors/github.js +91 -5
- package/dist/connectors/github.js.map +1 -1
- package/dist/connectors/gitlab.js +19 -16
- package/dist/connectors/gitlab.js.map +1 -1
- package/dist/connectors/gmail.d.ts +5 -0
- package/dist/connectors/gmail.js +53 -11
- package/dist/connectors/gmail.js.map +1 -1
- package/dist/connectors/googleCalendar.js +5 -4
- package/dist/connectors/googleCalendar.js.map +1 -1
- package/dist/connectors/googleDocs.js +7 -6
- package/dist/connectors/googleDocs.js.map +1 -1
- package/dist/connectors/googleDrive.js +15 -8
- package/dist/connectors/googleDrive.js.map +1 -1
- package/dist/connectors/grafana.js +39 -3
- package/dist/connectors/grafana.js.map +1 -1
- package/dist/connectors/jira.d.ts +1 -1
- package/dist/connectors/jira.js +19 -4
- package/dist/connectors/jira.js.map +1 -1
- package/dist/connectors/linear.js +2 -2
- package/dist/connectors/linear.js.map +1 -1
- package/dist/connectors/mcpClient.d.ts +29 -1
- package/dist/connectors/mcpClient.js +114 -44
- package/dist/connectors/mcpClient.js.map +1 -1
- package/dist/connectors/mcpOAuth.d.ts +1 -0
- package/dist/connectors/mcpOAuth.js +49 -4
- package/dist/connectors/mcpOAuth.js.map +1 -1
- package/dist/connectors/monday.js +5 -4
- package/dist/connectors/monday.js.map +1 -1
- package/dist/connectors/mongodb.js +32 -5
- package/dist/connectors/mongodb.js.map +1 -1
- package/dist/connectors/notion.d.ts +1 -1
- package/dist/connectors/notion.js +22 -6
- package/dist/connectors/notion.js.map +1 -1
- package/dist/connectors/oauthError.d.ts +17 -0
- package/dist/connectors/oauthError.js +50 -0
- package/dist/connectors/oauthError.js.map +1 -0
- package/dist/connectors/postgres.d.ts +7 -0
- package/dist/connectors/postgres.js +32 -2
- package/dist/connectors/postgres.js.map +1 -1
- package/dist/connectors/posthog.js +26 -0
- package/dist/connectors/posthog.js.map +1 -1
- package/dist/connectors/redis.d.ts +1 -0
- package/dist/connectors/redis.js +47 -20
- package/dist/connectors/redis.js.map +1 -1
- package/dist/connectors/salesforce.js +66 -5
- package/dist/connectors/salesforce.js.map +1 -1
- package/dist/connectors/sentry.js +2 -2
- package/dist/connectors/sentry.js.map +1 -1
- package/dist/connectors/slack.js +37 -14
- package/dist/connectors/slack.js.map +1 -1
- package/dist/connectors/snowflake.js +24 -0
- package/dist/connectors/snowflake.js.map +1 -1
- package/dist/connectors/stripe.js +9 -2
- package/dist/connectors/stripe.js.map +1 -1
- package/dist/connectors/supabase.js +34 -0
- package/dist/connectors/supabase.js.map +1 -1
- package/dist/connectors/tokenStorage.d.ts +20 -0
- package/dist/connectors/tokenStorage.js +196 -64
- package/dist/connectors/tokenStorage.js.map +1 -1
- package/dist/connectors/woocommerce.js +34 -0
- package/dist/connectors/woocommerce.js.map +1 -1
- package/dist/copilot/parseIntent.d.ts +58 -0
- package/dist/copilot/parseIntent.js +149 -0
- package/dist/copilot/parseIntent.js.map +1 -0
- package/dist/decisionReplay.d.ts +8 -6
- package/dist/decisionReplay.js +35 -11
- package/dist/decisionReplay.js.map +1 -1
- package/dist/decisionTraceLog.d.ts +9 -0
- package/dist/decisionTraceLog.js +6 -0
- package/dist/decisionTraceLog.js.map +1 -1
- package/dist/drivers/claude/api.js +49 -7
- package/dist/drivers/claude/api.js.map +1 -1
- package/dist/drivers/claude/envSanitizer.d.ts +9 -1
- package/dist/drivers/claude/envSanitizer.js +41 -3
- package/dist/drivers/claude/envSanitizer.js.map +1 -1
- package/dist/drivers/claude/streamParser.d.ts +13 -0
- package/dist/drivers/claude/streamParser.js.map +1 -1
- package/dist/drivers/claude/subprocess.js +131 -16
- package/dist/drivers/claude/subprocess.js.map +1 -1
- package/dist/drivers/claude/subprocessSettings.d.ts +1 -1
- package/dist/drivers/claude/subprocessSettings.js +18 -4
- package/dist/drivers/claude/subprocessSettings.js.map +1 -1
- package/dist/drivers/gemini/index.d.ts +13 -0
- package/dist/drivers/gemini/index.js +211 -67
- package/dist/drivers/gemini/index.js.map +1 -1
- package/dist/drivers/local/index.d.ts +2 -17
- package/dist/drivers/local/index.js +5 -92
- package/dist/drivers/local/index.js.map +1 -1
- package/dist/drivers/openai/index.js +69 -9
- package/dist/drivers/openai/index.js.map +1 -1
- package/dist/drivers/outputCap.d.ts +27 -0
- package/dist/drivers/outputCap.js +50 -0
- package/dist/drivers/outputCap.js.map +1 -0
- package/dist/embeddings/cosine.d.ts +23 -0
- package/dist/embeddings/cosine.js +59 -0
- package/dist/embeddings/cosine.js.map +1 -0
- package/dist/embeddings/index.d.ts +19 -0
- package/dist/embeddings/index.js +35 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/localEmbeddings.d.ts +29 -0
- package/dist/embeddings/localEmbeddings.js +103 -0
- package/dist/embeddings/localEmbeddings.js.map +1 -0
- package/dist/embeddings/localEndpoints.d.ts +24 -0
- package/dist/embeddings/localEndpoints.js +37 -0
- package/dist/embeddings/localEndpoints.js.map +1 -0
- package/dist/embeddings/types.d.ts +32 -0
- package/dist/embeddings/types.js +12 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/featureFlags.d.ts +18 -0
- package/dist/featureFlags.js +32 -0
- package/dist/featureFlags.js.map +1 -1
- package/dist/fp/automationInterpreter.js +118 -39
- package/dist/fp/automationInterpreter.js.map +1 -1
- package/dist/fp/automationProgram.d.ts +10 -0
- package/dist/fp/automationProgram.js.map +1 -1
- package/dist/fp/automationState.d.ts +6 -0
- package/dist/fp/automationState.js +38 -0
- package/dist/fp/automationState.js.map +1 -1
- package/dist/fp/commandDescription.d.ts +6 -0
- package/dist/fp/commandDescription.js +18 -5
- package/dist/fp/commandDescription.js.map +1 -1
- package/dist/fp/interpreterContext.d.ts +16 -5
- package/dist/fp/interpreterContext.js +59 -3
- package/dist/fp/interpreterContext.js.map +1 -1
- package/dist/fp/policyParser.js +18 -8
- package/dist/fp/policyParser.js.map +1 -1
- package/dist/haltPushDispatch.d.ts +4 -0
- package/dist/haltPushDispatch.js +7 -22
- package/dist/haltPushDispatch.js.map +1 -1
- package/dist/inboxRoutes.js +2 -2
- package/dist/inboxRoutes.js.map +1 -1
- package/dist/index.js +672 -135
- package/dist/index.js.map +1 -1
- package/dist/installGuard.js +6 -0
- package/dist/installGuard.js.map +1 -1
- package/dist/localEndpointGuard.d.ts +25 -0
- package/dist/localEndpointGuard.js +101 -0
- package/dist/localEndpointGuard.js.map +1 -0
- package/dist/mcpRoutes.js +1 -1
- package/dist/mcpRoutes.js.map +1 -1
- package/dist/oauth.d.ts +13 -0
- package/dist/oauth.js +53 -9
- package/dist/oauth.js.map +1 -1
- package/dist/orchestrator/childBridgeClient.d.ts +7 -0
- package/dist/orchestrator/childBridgeClient.js +42 -1
- package/dist/orchestrator/childBridgeClient.js.map +1 -1
- package/dist/orchestrator/orchestratorBridge.d.ts +33 -0
- package/dist/orchestrator/orchestratorBridge.js +75 -9
- package/dist/orchestrator/orchestratorBridge.js.map +1 -1
- package/dist/patchworkConfig.d.ts +4 -0
- package/dist/patchworkConfig.js +33 -4
- package/dist/patchworkConfig.js.map +1 -1
- package/dist/probe.js +39 -5
- package/dist/probe.js.map +1 -1
- package/dist/recipeOrchestration.d.ts +59 -0
- package/dist/recipeOrchestration.js +314 -60
- package/dist/recipeOrchestration.js.map +1 -1
- package/dist/recipeRoutes.d.ts +93 -0
- package/dist/recipeRoutes.js +664 -27
- package/dist/recipeRoutes.js.map +1 -1
- package/dist/recipes/RecipeOrchestrator.d.ts +14 -0
- package/dist/recipes/RecipeOrchestrator.js +42 -2
- package/dist/recipes/RecipeOrchestrator.js.map +1 -1
- package/dist/recipes/agentExecutor.d.ts +51 -2
- package/dist/recipes/agentExecutor.js +86 -13
- package/dist/recipes/agentExecutor.js.map +1 -1
- package/dist/recipes/chainedRunner.d.ts +111 -3
- package/dist/recipes/chainedRunner.js +440 -45
- package/dist/recipes/chainedRunner.js.map +1 -1
- package/dist/recipes/compiler.js +42 -29
- package/dist/recipes/compiler.js.map +1 -1
- package/dist/recipes/connectorPreflight.js +31 -0
- package/dist/recipes/connectorPreflight.js.map +1 -1
- package/dist/recipes/dependencyGraph.d.ts +16 -0
- package/dist/recipes/dependencyGraph.js +37 -2
- package/dist/recipes/dependencyGraph.js.map +1 -1
- package/dist/recipes/eventTriggerPrograms.d.ts +36 -0
- package/dist/recipes/eventTriggerPrograms.js +158 -0
- package/dist/recipes/eventTriggerPrograms.js.map +1 -0
- package/dist/recipes/githubInstallSource.d.ts +9 -2
- package/dist/recipes/githubInstallSource.js +36 -6
- package/dist/recipes/githubInstallSource.js.map +1 -1
- package/dist/recipes/haltCategory.d.ts +10 -0
- package/dist/recipes/haltCategory.js +11 -1
- package/dist/recipes/haltCategory.js.map +1 -1
- package/dist/recipes/idempotencyKey.d.ts +30 -3
- package/dist/recipes/idempotencyKey.js +89 -5
- package/dist/recipes/idempotencyKey.js.map +1 -1
- package/dist/recipes/installer.js +12 -35
- package/dist/recipes/installer.js.map +1 -1
- package/dist/recipes/judgeVerdict.d.ts +11 -1
- package/dist/recipes/judgeVerdict.js +47 -7
- package/dist/recipes/judgeVerdict.js.map +1 -1
- package/dist/recipes/names.d.ts +5 -0
- package/dist/recipes/names.js +10 -5
- package/dist/recipes/names.js.map +1 -1
- package/dist/recipes/parser.js +74 -10
- package/dist/recipes/parser.js.map +1 -1
- package/dist/recipes/pricing/costRouter.d.ts +43 -0
- package/dist/recipes/pricing/costRouter.js +44 -0
- package/dist/recipes/pricing/costRouter.js.map +1 -0
- package/dist/recipes/pricing/priceTable.d.ts +76 -0
- package/dist/recipes/pricing/priceTable.js +144 -0
- package/dist/recipes/pricing/priceTable.js.map +1 -0
- package/dist/recipes/replayRun.js +5 -2
- package/dist/recipes/replayRun.js.map +1 -1
- package/dist/recipes/resolveRecipePath.js +15 -1
- package/dist/recipes/resolveRecipePath.js.map +1 -1
- package/dist/recipes/runBudget.d.ts +93 -32
- package/dist/recipes/runBudget.js +213 -49
- package/dist/recipes/runBudget.js.map +1 -1
- package/dist/recipes/runRegistry.d.ts +32 -0
- package/dist/recipes/runRegistry.js +54 -0
- package/dist/recipes/runRegistry.js.map +1 -0
- package/dist/recipes/scheduler.js +6 -2
- package/dist/recipes/scheduler.js.map +1 -1
- package/dist/recipes/schema.d.ts +59 -6
- package/dist/recipes/schemaGenerator.d.ts +9 -0
- package/dist/recipes/schemaGenerator.js +446 -77
- package/dist/recipes/schemaGenerator.js.map +1 -1
- package/dist/recipes/simulation/aggregateRunRisk.d.ts +46 -0
- package/dist/recipes/simulation/aggregateRunRisk.js +120 -0
- package/dist/recipes/simulation/aggregateRunRisk.js.map +1 -0
- package/dist/recipes/simulation/costProjector.d.ts +32 -0
- package/dist/recipes/simulation/costProjector.js +194 -0
- package/dist/recipes/simulation/costProjector.js.map +1 -0
- package/dist/recipes/simulation/sideEffects.d.ts +32 -0
- package/dist/recipes/simulation/sideEffects.js +62 -0
- package/dist/recipes/simulation/sideEffects.js.map +1 -0
- package/dist/recipes/simulation/simulate.d.ts +36 -0
- package/dist/recipes/simulation/simulate.js +264 -0
- package/dist/recipes/simulation/simulate.js.map +1 -0
- package/dist/recipes/simulation/simulateMockedRun.d.ts +52 -0
- package/dist/recipes/simulation/simulateMockedRun.js +84 -0
- package/dist/recipes/simulation/simulateMockedRun.js.map +1 -0
- package/dist/recipes/simulation/synthesizeMockedOutputs.d.ts +31 -0
- package/dist/recipes/simulation/synthesizeMockedOutputs.js +50 -0
- package/dist/recipes/simulation/synthesizeMockedOutputs.js.map +1 -0
- package/dist/recipes/simulation/types.d.ts +198 -0
- package/dist/recipes/simulation/types.js +30 -0
- package/dist/recipes/simulation/types.js.map +1 -0
- package/dist/recipes/stepObservation.d.ts +12 -0
- package/dist/recipes/stepObservation.js +21 -1
- package/dist/recipes/stepObservation.js.map +1 -1
- package/dist/recipes/toolRegistry.js +61 -24
- package/dist/recipes/toolRegistry.js.map +1 -1
- package/dist/recipes/tools/airtable.d.ts +15 -0
- package/dist/recipes/tools/airtable.js +240 -0
- package/dist/recipes/tools/airtable.js.map +1 -0
- package/dist/recipes/tools/caldiy.d.ts +13 -0
- package/dist/recipes/tools/caldiy.js +215 -0
- package/dist/recipes/tools/caldiy.js.map +1 -0
- package/dist/recipes/tools/circleci.d.ts +10 -0
- package/dist/recipes/tools/circleci.js +204 -0
- package/dist/recipes/tools/circleci.js.map +1 -0
- package/dist/recipes/tools/cloudflare.d.ts +13 -0
- package/dist/recipes/tools/cloudflare.js +211 -0
- package/dist/recipes/tools/cloudflare.js.map +1 -0
- package/dist/recipes/tools/confluence.js +11 -10
- package/dist/recipes/tools/confluence.js.map +1 -1
- package/dist/recipes/tools/datadog.js +13 -12
- package/dist/recipes/tools/datadog.js.map +1 -1
- package/dist/recipes/tools/docs.d.ts +18 -0
- package/dist/recipes/tools/docs.js +95 -0
- package/dist/recipes/tools/docs.js.map +1 -0
- package/dist/recipes/tools/elasticsearch.d.ts +11 -0
- package/dist/recipes/tools/elasticsearch.js +157 -0
- package/dist/recipes/tools/elasticsearch.js.map +1 -0
- package/dist/recipes/tools/fanOut.js +4 -4
- package/dist/recipes/tools/fanOut.js.map +1 -1
- package/dist/recipes/tools/figma.d.ts +12 -0
- package/dist/recipes/tools/figma.js +195 -0
- package/dist/recipes/tools/figma.js.map +1 -0
- package/dist/recipes/tools/file.js +43 -22
- package/dist/recipes/tools/file.js.map +1 -1
- package/dist/recipes/tools/github.js +162 -5
- package/dist/recipes/tools/github.js.map +1 -1
- package/dist/recipes/tools/gmail.js +45 -33
- package/dist/recipes/tools/gmail.js.map +1 -1
- package/dist/recipes/tools/grafana.d.ts +11 -0
- package/dist/recipes/tools/grafana.js +216 -0
- package/dist/recipes/tools/grafana.js.map +1 -0
- package/dist/recipes/tools/http.d.ts +1 -1
- package/dist/recipes/tools/http.js +10 -28
- package/dist/recipes/tools/http.js.map +1 -1
- package/dist/recipes/tools/hubspot.js +13 -12
- package/dist/recipes/tools/hubspot.js.map +1 -1
- package/dist/recipes/tools/index.d.ts +28 -0
- package/dist/recipes/tools/index.js +28 -0
- package/dist/recipes/tools/index.js.map +1 -1
- package/dist/recipes/tools/intercom.js +11 -10
- package/dist/recipes/tools/intercom.js.map +1 -1
- package/dist/recipes/tools/jira.js +13 -0
- package/dist/recipes/tools/jira.js.map +1 -1
- package/dist/recipes/tools/meetingNotes.js +2 -2
- package/dist/recipes/tools/monday.d.ts +22 -0
- package/dist/recipes/tools/monday.js +242 -0
- package/dist/recipes/tools/monday.js.map +1 -0
- package/dist/recipes/tools/mongodb.d.ts +19 -0
- package/dist/recipes/tools/mongodb.js +194 -0
- package/dist/recipes/tools/mongodb.js.map +1 -0
- package/dist/recipes/tools/notion.js +11 -10
- package/dist/recipes/tools/notion.js.map +1 -1
- package/dist/recipes/tools/obsidian.d.ts +15 -0
- package/dist/recipes/tools/obsidian.js +173 -0
- package/dist/recipes/tools/obsidian.js.map +1 -0
- package/dist/recipes/tools/outcomes.d.ts +15 -0
- package/dist/recipes/tools/outcomes.js +111 -0
- package/dist/recipes/tools/outcomes.js.map +1 -0
- package/dist/recipes/tools/paystack.d.ts +11 -0
- package/dist/recipes/tools/paystack.js +212 -0
- package/dist/recipes/tools/paystack.js.map +1 -0
- package/dist/recipes/tools/pipedrive.d.ts +16 -0
- package/dist/recipes/tools/pipedrive.js +234 -0
- package/dist/recipes/tools/pipedrive.js.map +1 -0
- package/dist/recipes/tools/postgres.d.ts +15 -0
- package/dist/recipes/tools/postgres.js +186 -0
- package/dist/recipes/tools/postgres.js.map +1 -0
- package/dist/recipes/tools/posthog.d.ts +16 -0
- package/dist/recipes/tools/posthog.js +219 -0
- package/dist/recipes/tools/posthog.js.map +1 -0
- package/dist/recipes/tools/redis.d.ts +9 -0
- package/dist/recipes/tools/redis.js +141 -0
- package/dist/recipes/tools/redis.js.map +1 -0
- package/dist/recipes/tools/resend.d.ts +8 -0
- package/dist/recipes/tools/resend.js +153 -0
- package/dist/recipes/tools/resend.js.map +1 -0
- package/dist/recipes/tools/salesforce.d.ts +16 -0
- package/dist/recipes/tools/salesforce.js +184 -0
- package/dist/recipes/tools/salesforce.js.map +1 -0
- package/dist/recipes/tools/sendgrid.d.ts +9 -0
- package/dist/recipes/tools/sendgrid.js +175 -0
- package/dist/recipes/tools/sendgrid.js.map +1 -0
- package/dist/recipes/tools/shopify.d.ts +16 -0
- package/dist/recipes/tools/shopify.js +266 -0
- package/dist/recipes/tools/shopify.js.map +1 -0
- package/dist/recipes/tools/snowflake.d.ts +16 -0
- package/dist/recipes/tools/snowflake.js +173 -0
- package/dist/recipes/tools/snowflake.js.map +1 -0
- package/dist/recipes/tools/stripe.js +13 -12
- package/dist/recipes/tools/stripe.js.map +1 -1
- package/dist/recipes/tools/supabase.d.ts +9 -0
- package/dist/recipes/tools/supabase.js +133 -0
- package/dist/recipes/tools/supabase.js.map +1 -0
- package/dist/recipes/tools/todoist.d.ts +15 -0
- package/dist/recipes/tools/todoist.js +228 -0
- package/dist/recipes/tools/todoist.js.map +1 -0
- package/dist/recipes/tools/twilio.d.ts +11 -0
- package/dist/recipes/tools/twilio.js +180 -0
- package/dist/recipes/tools/twilio.js.map +1 -0
- package/dist/recipes/tools/vercel.d.ts +9 -0
- package/dist/recipes/tools/vercel.js +146 -0
- package/dist/recipes/tools/vercel.js.map +1 -0
- package/dist/recipes/tools/webflow.d.ts +11 -0
- package/dist/recipes/tools/webflow.js +244 -0
- package/dist/recipes/tools/webflow.js.map +1 -0
- package/dist/recipes/tools/woocommerce.d.ts +18 -0
- package/dist/recipes/tools/woocommerce.js +260 -0
- package/dist/recipes/tools/woocommerce.js.map +1 -0
- package/dist/recipes/tools/wrapConnectorExecute.d.ts +25 -0
- package/dist/recipes/tools/wrapConnectorExecute.js +37 -0
- package/dist/recipes/tools/wrapConnectorExecute.js.map +1 -0
- package/dist/recipes/tools/zendesk.js +11 -10
- package/dist/recipes/tools/zendesk.js.map +1 -1
- package/dist/recipes/triggerVars.d.ts +15 -0
- package/dist/recipes/triggerVars.js +57 -0
- package/dist/recipes/triggerVars.js.map +1 -0
- package/dist/recipes/validation.d.ts +1 -1
- package/dist/recipes/validation.js +536 -12
- package/dist/recipes/validation.js.map +1 -1
- package/dist/recipes/yamlPositions.d.ts +1 -1
- package/dist/recipes/yamlPositions.js +7 -2
- package/dist/recipes/yamlPositions.js.map +1 -1
- package/dist/recipes/yamlRunner.d.ts +216 -4
- package/dist/recipes/yamlRunner.js +1030 -96
- package/dist/recipes/yamlRunner.js.map +1 -1
- package/dist/recipesHttp.d.ts +5 -0
- package/dist/recipesHttp.js +68 -6
- package/dist/recipesHttp.js.map +1 -1
- package/dist/resources.js +14 -1
- package/dist/resources.js.map +1 -1
- package/dist/riskSignals.d.ts +42 -0
- package/dist/riskSignals.js +197 -0
- package/dist/riskSignals.js.map +1 -0
- package/dist/riskTier.d.ts +9 -0
- package/dist/riskTier.js +48 -0
- package/dist/riskTier.js.map +1 -1
- package/dist/runLog.d.ts +53 -0
- package/dist/runLog.js +75 -16
- package/dist/runLog.js.map +1 -1
- package/dist/schemas/recipe.v1.json +360 -16
- package/dist/server.d.ts +60 -0
- package/dist/server.js +192 -31
- package/dist/server.js.map +1 -1
- package/dist/sessionCheckpoint.js +4 -1
- package/dist/sessionCheckpoint.js.map +1 -1
- package/dist/sessionDetail.d.ts +43 -0
- package/dist/sessionDetail.js +59 -0
- package/dist/sessionDetail.js.map +1 -0
- package/dist/settingsEnv.d.ts +47 -0
- package/dist/settingsEnv.js +88 -0
- package/dist/settingsEnv.js.map +1 -0
- package/dist/streamableHttp.js +44 -10
- package/dist/streamableHttp.js.map +1 -1
- package/dist/ta/backtest/abnday.d.ts +53 -0
- package/dist/ta/backtest/abnday.js +123 -0
- package/dist/ta/backtest/abnday.js.map +1 -0
- package/dist/ta/backtest/directional.d.ts +48 -0
- package/dist/ta/backtest/directional.js +103 -0
- package/dist/ta/backtest/directional.js.map +1 -0
- package/dist/ta/backtest/fundx.d.ts +67 -0
- package/dist/ta/backtest/fundx.js +264 -0
- package/dist/ta/backtest/fundx.js.map +1 -0
- package/dist/ta/backtest/fvg.d.ts +62 -0
- package/dist/ta/backtest/fvg.js +236 -0
- package/dist/ta/backtest/fvg.js.map +1 -0
- package/dist/ta/backtest/ichimoku.d.ts +41 -0
- package/dist/ta/backtest/ichimoku.js +146 -0
- package/dist/ta/backtest/ichimoku.js.map +1 -0
- package/dist/ta/backtest/ingest.d.ts +20 -0
- package/dist/ta/backtest/ingest.js +104 -0
- package/dist/ta/backtest/ingest.js.map +1 -0
- package/dist/ta/backtest/msb.d.ts +49 -0
- package/dist/ta/backtest/msb.js +162 -0
- package/dist/ta/backtest/msb.js.map +1 -0
- package/dist/ta/backtest/scoring.d.ts +33 -0
- package/dist/ta/backtest/scoring.js +82 -0
- package/dist/ta/backtest/scoring.js.map +1 -0
- package/dist/ta/backtest/summary.d.ts +20 -0
- package/dist/ta/backtest/summary.js +42 -0
- package/dist/ta/backtest/summary.js.map +1 -0
- package/dist/ta/backtest/tsmom.d.ts +72 -0
- package/dist/ta/backtest/tsmom.js +202 -0
- package/dist/ta/backtest/tsmom.js.map +1 -0
- package/dist/ta/backtest/volsq.d.ts +34 -0
- package/dist/ta/backtest/volsq.js +154 -0
- package/dist/ta/backtest/volsq.js.map +1 -0
- package/dist/ta/backtest/walkForward.d.ts +45 -0
- package/dist/ta/backtest/walkForward.js +136 -0
- package/dist/ta/backtest/walkForward.js.map +1 -0
- package/dist/ta/cycles.d.ts +15 -0
- package/dist/ta/cycles.js +31 -0
- package/dist/ta/cycles.js.map +1 -0
- package/dist/ta/desk/accrualEmitter.d.ts +59 -0
- package/dist/ta/desk/accrualEmitter.js +136 -0
- package/dist/ta/desk/accrualEmitter.js.map +1 -0
- package/dist/ta/desk/cellBacktest.d.ts +179 -0
- package/dist/ta/desk/cellBacktest.js +514 -0
- package/dist/ta/desk/cellBacktest.js.map +1 -0
- package/dist/ta/desk/cells/wpMaRejection.d.ts +49 -0
- package/dist/ta/desk/cells/wpMaRejection.js +141 -0
- package/dist/ta/desk/cells/wpMaRejection.js.map +1 -0
- package/dist/ta/desk/cells/wpVolumeClimax.d.ts +57 -0
- package/dist/ta/desk/cells/wpVolumeClimax.js +193 -0
- package/dist/ta/desk/cells/wpVolumeClimax.js.map +1 -0
- package/dist/ta/desk/collectors.d.ts +18 -0
- package/dist/ta/desk/collectors.js +450 -0
- package/dist/ta/desk/collectors.js.map +1 -0
- package/dist/ta/desk/contract.d.ts +51 -0
- package/dist/ta/desk/contract.js +261 -0
- package/dist/ta/desk/contract.js.map +1 -0
- package/dist/ta/desk/deskLedger.d.ts +36 -0
- package/dist/ta/desk/deskLedger.js +239 -0
- package/dist/ta/desk/deskLedger.js.map +1 -0
- package/dist/ta/desk/liqTape.d.ts +37 -0
- package/dist/ta/desk/liqTape.js +99 -0
- package/dist/ta/desk/liqTape.js.map +1 -0
- package/dist/ta/desk/post.d.ts +20 -0
- package/dist/ta/desk/post.js +65 -0
- package/dist/ta/desk/post.js.map +1 -0
- package/dist/ta/desk/render.d.ts +25 -0
- package/dist/ta/desk/render.js +398 -0
- package/dist/ta/desk/render.js.map +1 -0
- package/dist/ta/desk/surfaces.d.ts +216 -0
- package/dist/ta/desk/surfaces.js +472 -0
- package/dist/ta/desk/surfaces.js.map +1 -0
- package/dist/ta/desk/types.d.ts +174 -0
- package/dist/ta/desk/types.js +104 -0
- package/dist/ta/desk/types.js.map +1 -0
- package/dist/ta/index.d.ts +23 -0
- package/dist/ta/index.js +54 -0
- package/dist/ta/index.js.map +1 -0
- package/dist/ta/ledger.d.ts +44 -0
- package/dist/ta/ledger.js +95 -0
- package/dist/ta/ledger.js.map +1 -0
- package/dist/ta/levels.d.ts +21 -0
- package/dist/ta/levels.js +41 -0
- package/dist/ta/levels.js.map +1 -0
- package/dist/ta/swings.d.ts +30 -0
- package/dist/ta/swings.js +83 -0
- package/dist/ta/swings.js.map +1 -0
- package/dist/ta/types.d.ts +81 -0
- package/dist/ta/types.js +20 -0
- package/dist/ta/types.js.map +1 -0
- package/dist/telemetry.js +20 -9
- package/dist/telemetry.js.map +1 -1
- package/dist/tokenUsageTracker.d.ts +2 -1
- package/dist/tokenUsageTracker.js +38 -20
- package/dist/tokenUsageTracker.js.map +1 -1
- package/dist/tools/contextBundle.js +13 -9
- package/dist/tools/contextBundle.js.map +1 -1
- package/dist/tools/ctxGetTaskContext.js +8 -3
- package/dist/tools/ctxGetTaskContext.js.map +1 -1
- package/dist/tools/ctxQueryTraces.d.ts +18 -1
- package/dist/tools/ctxQueryTraces.js +176 -27
- package/dist/tools/ctxQueryTraces.js.map +1 -1
- package/dist/tools/enrichCommit.js +5 -2
- package/dist/tools/enrichCommit.js.map +1 -1
- package/dist/tools/getDependencyTree.js +2 -2
- package/dist/tools/getDependencyTree.js.map +1 -1
- package/dist/tools/getDiagnostics.js +3 -0
- package/dist/tools/getDiagnostics.js.map +1 -1
- package/dist/tools/getDocumentSymbols.js +5 -1
- package/dist/tools/getDocumentSymbols.js.map +1 -1
- package/dist/tools/getGitHotspots.js +12 -1
- package/dist/tools/getGitHotspots.js.map +1 -1
- package/dist/tools/getGitLog.js +5 -2
- package/dist/tools/getGitLog.js.map +1 -1
- package/dist/tools/getGitStatus.js +6 -1
- package/dist/tools/getGitStatus.js.map +1 -1
- package/dist/tools/getProjectContext.js +3 -1
- package/dist/tools/getProjectContext.js.map +1 -1
- package/dist/tools/getToolCapabilities.js +39 -4
- package/dist/tools/getToolCapabilities.js.map +1 -1
- package/dist/tools/gitWrite.js +12 -3
- package/dist/tools/gitWrite.js.map +1 -1
- package/dist/tools/github/composite.d.ts +1 -1
- package/dist/tools/github/composite.js +7 -7
- package/dist/tools/github/composite.js.map +1 -1
- package/dist/tools/github/pr.d.ts +6 -6
- package/dist/tools/github/pr.js +18 -11
- package/dist/tools/github/pr.js.map +1 -1
- package/dist/tools/httpClient.js +55 -3
- package/dist/tools/httpClient.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +19 -12
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp.d.ts +6 -0
- package/dist/tools/lsp.js +81 -12
- package/dist/tools/lsp.js.map +1 -1
- package/dist/tools/previewEdit.js +16 -1
- package/dist/tools/previewEdit.js.map +1 -1
- package/dist/tools/resumeClaudeTask.js +17 -0
- package/dist/tools/resumeClaudeTask.js.map +1 -1
- package/dist/tools/searchAndReplace.js +9 -5
- package/dist/tools/searchAndReplace.js.map +1 -1
- package/dist/tools/searchTools.d.ts +26 -0
- package/dist/tools/searchTools.js +42 -2
- package/dist/tools/searchTools.js.map +1 -1
- package/dist/tools/terminal.js +23 -51
- package/dist/tools/terminal.js.map +1 -1
- package/dist/tools/transaction.d.ts +9 -1
- package/dist/tools/transaction.js +59 -4
- package/dist/tools/transaction.js.map +1 -1
- package/dist/tools/utils.d.ts +16 -0
- package/dist/tools/utils.js +77 -7
- package/dist/tools/utils.js.map +1 -1
- package/dist/transport.d.ts +31 -0
- package/dist/transport.js +117 -14
- package/dist/transport.js.map +1 -1
- package/dist/wireHaltPushDispatch.js +12 -0
- package/dist/wireHaltPushDispatch.js.map +1 -1
- package/dist/workerGateDecisionLog.d.ts +141 -0
- package/dist/workerGateDecisionLog.js +361 -0
- package/dist/workerGateDecisionLog.js.map +1 -0
- package/dist/workers/actionClass.d.ts +38 -0
- package/dist/workers/actionClass.js +155 -0
- package/dist/workers/actionClass.js.map +1 -0
- package/dist/workers/backtest.d.ts +68 -0
- package/dist/workers/backtest.js +113 -0
- package/dist/workers/backtest.js.map +1 -0
- package/dist/workers/contextRisk.d.ts +35 -0
- package/dist/workers/contextRisk.js +20 -0
- package/dist/workers/contextRisk.js.map +1 -0
- package/dist/workers/contextRiskScorer.d.ts +48 -0
- package/dist/workers/contextRiskScorer.js +94 -0
- package/dist/workers/contextRiskScorer.js.map +1 -0
- package/dist/workers/graduation.d.ts +61 -0
- package/dist/workers/graduation.js +112 -0
- package/dist/workers/graduation.js.map +1 -0
- package/dist/workers/outcomeStore.d.ts +98 -0
- package/dist/workers/outcomeStore.js +146 -0
- package/dist/workers/outcomeStore.js.map +1 -0
- package/dist/workers/outcomesCli.d.ts +34 -0
- package/dist/workers/outcomesCli.js +91 -0
- package/dist/workers/outcomesCli.js.map +1 -0
- package/dist/workers/runWorkerShadow.d.ts +90 -0
- package/dist/workers/runWorkerShadow.js +323 -0
- package/dist/workers/runWorkerShadow.js.map +1 -0
- package/dist/workers/shadowGate.d.ts +30 -0
- package/dist/workers/shadowGate.js +58 -0
- package/dist/workers/shadowGate.js.map +1 -0
- package/dist/workers/shadowObserver.d.ts +165 -0
- package/dist/workers/shadowObserver.js +203 -0
- package/dist/workers/shadowObserver.js.map +1 -0
- package/dist/workers/shadowReport.d.ts +16 -0
- package/dist/workers/shadowReport.js +61 -0
- package/dist/workers/shadowReport.js.map +1 -0
- package/dist/workers/shadowRun.d.ts +38 -0
- package/dist/workers/shadowRun.js +44 -0
- package/dist/workers/shadowRun.js.map +1 -0
- package/dist/workers/trustLevel.d.ts +82 -0
- package/dist/workers/trustLevel.js +100 -0
- package/dist/workers/trustLevel.js.map +1 -0
- package/dist/workers/worker.d.ts +49 -0
- package/dist/workers/worker.js +88 -0
- package/dist/workers/worker.js.map +1 -0
- package/dist/workers/workerGate.d.ts +101 -0
- package/dist/workers/workerGate.js +210 -0
- package/dist/workers/workerGate.js.map +1 -0
- package/dist/workers/workerLevelStore.d.ts +33 -0
- package/dist/workers/workerLevelStore.js +87 -0
- package/dist/workers/workerLevelStore.js.map +1 -0
- package/dist/workers/workerLoader.d.ts +7 -0
- package/dist/workers/workerLoader.js +31 -0
- package/dist/workers/workerLoader.js.map +1 -0
- package/dist/writeFileAtomic.js +40 -13
- package/dist/writeFileAtomic.js.map +1 -1
- package/package.json +14 -6
- package/scripts/mcp-stdio-shim.cjs +247 -87
- package/templates/CLAUDE.bridge.md +1 -1
- package/templates/recipes/dependency-bump.yaml +33 -0
- package/templates/recipes/incident-to-pr.yaml +187 -0
- package/templates/recipes/outcome-ingester.yaml +53 -0
- package/templates/recipes/release-notes.yaml +30 -0
- package/templates/recipes/triage-failing-tests-autofile.yaml +152 -0
- package/templates/recipes/triage-failing-tests.yaml +38 -0
- package/templates/workers/dependency-upkeep.worker.yaml +26 -0
- package/templates/workers/release-notes.worker.yaml +17 -0
- package/templates/workers/test-guardian.worker.yaml +24 -0
- package/deploy/README.md +0 -172
- package/deploy/bootstrap-new-vps.sh +0 -364
- package/deploy/bootstrap-vps.sh +0 -192
- package/deploy/claude-ide-bridge.service.template +0 -67
- package/deploy/claude-ide-bridge@.service +0 -31
- package/deploy/deploy-dashboard.sh +0 -198
- package/deploy/deploy-landing.sh +0 -136
- package/deploy/ecosystem.config.js.example +0 -36
- package/deploy/install-vps-service.sh +0 -240
- package/deploy/macos/README.md +0 -153
- package/deploy/macos/com.patchwork.bridge.plist.template +0 -54
- package/deploy/macos/com.patchwork.tunnel.plist.template +0 -76
- package/deploy/macos/install-mac-bridge.sh +0 -244
- package/deploy/macos/uninstall-mac-bridge.sh +0 -22
- package/deploy/nginx-claude-bridge.conf.template +0 -129
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { classifyTool } from "../riskTier.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tool → capability domain. Coarse on purpose. Unknown tools fall to "other"
|
|
4
|
+
* (treated as irreversible — conservative: an unrecognised side effect is
|
|
5
|
+
* assumed unrecoverable until proven otherwise).
|
|
6
|
+
*/
|
|
7
|
+
const DOMAIN_BY_TOOL = {
|
|
8
|
+
// version control — read
|
|
9
|
+
getGitStatus: "vcs-read",
|
|
10
|
+
getGitDiff: "vcs-read",
|
|
11
|
+
getGitLog: "vcs-read",
|
|
12
|
+
gitBlame: "vcs-read",
|
|
13
|
+
gitListBranches: "vcs-read",
|
|
14
|
+
// version control — local mutations (reversible: reset/reflog/restore)
|
|
15
|
+
gitAdd: "vcs-local",
|
|
16
|
+
gitCommit: "vcs-local",
|
|
17
|
+
gitCheckout: "vcs-local",
|
|
18
|
+
gitStash: "vcs-local",
|
|
19
|
+
// version control — remote / shared history.
|
|
20
|
+
// Each operation has its OWN domain so trust earned on one never unlocks
|
|
21
|
+
// another (trust-transfer prevention: a worker grinding PR creation must
|
|
22
|
+
// separately earn evidence on push, and separately on merge).
|
|
23
|
+
gitPush: "vcs-push", // can be force-reverted; compensable
|
|
24
|
+
githubCreatePR: "vcs-remote", // PR is a proposal; closeable
|
|
25
|
+
githubMergePR: "vcs-merge", // lands commits in main; hard to undo cleanly
|
|
26
|
+
// filesystem
|
|
27
|
+
editText: "fs-write",
|
|
28
|
+
searchAndReplace: "fs-write",
|
|
29
|
+
createFile: "fs-write",
|
|
30
|
+
formatDocument: "fs-write",
|
|
31
|
+
getBufferContent: "fs-read",
|
|
32
|
+
findFiles: "fs-read",
|
|
33
|
+
// shell
|
|
34
|
+
runCommand: "shell",
|
|
35
|
+
runInTerminal: "shell",
|
|
36
|
+
sendTerminalCommand: "shell",
|
|
37
|
+
// outbound messaging
|
|
38
|
+
slackPostMessage: "messaging",
|
|
39
|
+
// generic network
|
|
40
|
+
sendHttpRequest: "http",
|
|
41
|
+
WebFetch: "http",
|
|
42
|
+
// issue trackers
|
|
43
|
+
githubCreateIssue: "issue",
|
|
44
|
+
createLinearIssue: "issue",
|
|
45
|
+
addLinearComment: "issue",
|
|
46
|
+
updateLinearIssue: "issue",
|
|
47
|
+
// CI / tests
|
|
48
|
+
runTests: "ci",
|
|
49
|
+
githubActions: "ci",
|
|
50
|
+
// dependency intel (read-only)
|
|
51
|
+
auditDependencies: "deps-read",
|
|
52
|
+
getSecurityAdvisories: "deps-read",
|
|
53
|
+
// recipe-tool ids — RecipeRunLog records THESE (not the MCP names), so the
|
|
54
|
+
// shadow dial attributes recipe-run steps by them. git.*/github.list_* are
|
|
55
|
+
// reads; file.* writes; slack/http are outbound. (worker-ramp-v0 dogfood)
|
|
56
|
+
"git.log_since": "vcs-read",
|
|
57
|
+
"git.stale_branches": "vcs-read",
|
|
58
|
+
"github.list_commits": "vcs-read",
|
|
59
|
+
"github.list_prs": "vcs-read",
|
|
60
|
+
"github.list_issues": "vcs-read",
|
|
61
|
+
"github.create_issue": "issue", // write — compensable (closeable) + brand-exposed
|
|
62
|
+
"file.read": "fs-read",
|
|
63
|
+
"file.write": "fs-write",
|
|
64
|
+
"file.append": "fs-write",
|
|
65
|
+
"slack.post_message": "messaging",
|
|
66
|
+
"http.post": "http",
|
|
67
|
+
"linear.list_issues": "issue-read", // read-only; reversible
|
|
68
|
+
"sentry.get_issue": "issue-read", // read-only; reversible
|
|
69
|
+
"diagnostics.get": "fs-read",
|
|
70
|
+
};
|
|
71
|
+
/** Domain → reversibility. The middle ramp rungs (L2/L3) only exist for a class
|
|
72
|
+
* whose reversibility is not "irreversible", so this is load-bearing. */
|
|
73
|
+
const REVERSIBILITY_BY_DOMAIN = {
|
|
74
|
+
"vcs-read": "reversible",
|
|
75
|
+
"vcs-local": "reversible", // reset / reflog / restore
|
|
76
|
+
"vcs-remote": "compensable", // close PR — lossy but possible
|
|
77
|
+
"vcs-push": "compensable", // force-revert / reflog — lossy but possible
|
|
78
|
+
"vcs-merge": "compensable", // git revert on main — painful but recoverable
|
|
79
|
+
"fs-write": "reversible", // transactions + WriteEffectLedger
|
|
80
|
+
"fs-read": "reversible",
|
|
81
|
+
shell: "irreversible", // arbitrary side effects — assume unrecoverable
|
|
82
|
+
messaging: "irreversible", // a sent message can't be unsent reliably
|
|
83
|
+
http: "irreversible", // a POST may not be undoable
|
|
84
|
+
issue: "compensable", // close / delete the created issue
|
|
85
|
+
"issue-read": "reversible", // read-only issue queries
|
|
86
|
+
ci: "reversible", // re-runnable, no durable side effect
|
|
87
|
+
"deps-read": "reversible",
|
|
88
|
+
other: "irreversible",
|
|
89
|
+
};
|
|
90
|
+
/** Domains whose actions are externally visible — failure is reputational. */
|
|
91
|
+
const BRAND_EXPOSED_DOMAINS = new Set([
|
|
92
|
+
"messaging",
|
|
93
|
+
"vcs-remote",
|
|
94
|
+
"vcs-push",
|
|
95
|
+
"vcs-merge",
|
|
96
|
+
"issue",
|
|
97
|
+
"http",
|
|
98
|
+
]);
|
|
99
|
+
/**
|
|
100
|
+
* The tool names this module can classify (MCP names + recipe-tool ids). Exposed
|
|
101
|
+
* so the worker-agent sandbox can enumerate every risky tool to consider
|
|
102
|
+
* blocking. NOT exhaustive of the whole MCP surface — any unknown tool classifies
|
|
103
|
+
* as `other:irreversible` and is gated at the per-step gate regardless.
|
|
104
|
+
*/
|
|
105
|
+
export function knownActionTools() {
|
|
106
|
+
return Object.keys(DOMAIN_BY_TOOL);
|
|
107
|
+
}
|
|
108
|
+
export function classifyActionClass(toolName, _params) {
|
|
109
|
+
const domain = DOMAIN_BY_TOOL[toolName] ?? "other";
|
|
110
|
+
const reversibility = REVERSIBILITY_BY_DOMAIN[domain] ?? "irreversible";
|
|
111
|
+
const blastTier = classifyTool(toolName);
|
|
112
|
+
return {
|
|
113
|
+
key: `${domain}:${reversibility}:${blastTier}`,
|
|
114
|
+
domain,
|
|
115
|
+
reversibility,
|
|
116
|
+
blastTier,
|
|
117
|
+
brandExposed: BRAND_EXPOSED_DOMAINS.has(domain),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const BLAST_MULTIPLIER = {
|
|
121
|
+
low: 2,
|
|
122
|
+
medium: 5,
|
|
123
|
+
high: 12,
|
|
124
|
+
};
|
|
125
|
+
const REVERSIBILITY_MULTIPLIER = {
|
|
126
|
+
reversible: 1,
|
|
127
|
+
compensable: 1.5,
|
|
128
|
+
irreversible: 3,
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Evidence weight for one outcome. A routine success is low-information
|
|
132
|
+
* (weight 1 → the posterior climbs slowly). A failure is weighted by
|
|
133
|
+
* blast-tier × reversibility, so a high-blast irreversible failure is high
|
|
134
|
+
* information and craters the posterior (instant demote). This is the entire
|
|
135
|
+
* anti-trust-transfer-grinding defence: count alone never graduates a risky
|
|
136
|
+
* class, and one catastrophic outcome dominates a thousand trivial ones.
|
|
137
|
+
*/
|
|
138
|
+
const BRAND_MULTIPLIER = 1.5;
|
|
139
|
+
export function outcomeWeight(actionClass, good) {
|
|
140
|
+
if (good)
|
|
141
|
+
return 1;
|
|
142
|
+
const brand = actionClass.brandExposed ? BRAND_MULTIPLIER : 1;
|
|
143
|
+
return (BLAST_MULTIPLIER[actionClass.blastTier] *
|
|
144
|
+
REVERSIBILITY_MULTIPLIER[actionClass.reversibility] *
|
|
145
|
+
brand);
|
|
146
|
+
}
|
|
147
|
+
/** Which ramp rungs are reachable for a class. Irreversible classes skip the
|
|
148
|
+
* safety-net rungs L2/L3 (no compensating action exists), so they must clear a
|
|
149
|
+
* higher bar to reach L4. */
|
|
150
|
+
export function reachableLevels(actionClass) {
|
|
151
|
+
return actionClass.reversibility === "irreversible"
|
|
152
|
+
? [0, 1, 4]
|
|
153
|
+
: [0, 1, 2, 3, 4];
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=actionClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionClass.js","sourceRoot":"","sources":["../../src/workers/actionClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,gBAAgB,CAAC;AA6B7D;;;;GAIG;AACH,MAAM,cAAc,GAA2B;IAC7C,yBAAyB;IACzB,YAAY,EAAE,UAAU;IACxB,UAAU,EAAE,UAAU;IACtB,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,UAAU;IAC3B,uEAAuE;IACvE,MAAM,EAAE,WAAW;IACnB,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,WAAW;IACxB,QAAQ,EAAE,WAAW;IACrB,6CAA6C;IAC7C,yEAAyE;IACzE,yEAAyE;IACzE,8DAA8D;IAC9D,OAAO,EAAE,UAAU,EAAE,qCAAqC;IAC1D,cAAc,EAAE,YAAY,EAAE,8BAA8B;IAC5D,aAAa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CACT,CAAC;AACF,MAAM,wBAAwB,GAAkC;IAC9D,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,GAAG;IAChB,YAAY,EAAE,CAAC;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,IAAa;IACnE,IAAI,IAAI;QAAE,OAAO,CAAC,CAAC;IACnB,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,OAAO,CACL,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC;QACvC,wBAAwB,CAAC,WAAW,CAAC,aAAa,CAAC;QACnD,KAAK,CACN,CAAC;AACJ,CAAC;AAED;;6BAE6B;AAC7B,MAAM,UAAU,eAAe,CAAC,WAAwB;IACtD,OAAO,WAAW,CAAC,aAAa,KAAK,cAAc;QACjD,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type GraduationConfig } from "./graduation.js";
|
|
2
|
+
import type { OutcomeStore } from "./outcomeStore.js";
|
|
3
|
+
import { type RunRecord } from "./shadowObserver.js";
|
|
4
|
+
import { type WorkerManifest } from "./worker.js";
|
|
5
|
+
/**
|
|
6
|
+
* Backtest-as-DIVERGENCE (cold-start calibration; see
|
|
7
|
+
* docs/worker-autonomy-policy-gate.md §3c).
|
|
8
|
+
*
|
|
9
|
+
* Replays a worker's HISTORICAL run log and, at each risky owned action, asks:
|
|
10
|
+
* what would the trust ramp have decided AS OF THAT MOMENT (using only the
|
|
11
|
+
* evidence accrued so far — no lookahead), and how does that compare to what
|
|
12
|
+
* actually happened? This is deliberately NOT a "success rate" — replaying past
|
|
13
|
+
* outcomes scores agreement with what already happened, a censored sample. The
|
|
14
|
+
* honest, demoable metric is DIVERGENCE:
|
|
15
|
+
*
|
|
16
|
+
* - false-allow: the ramp would have AUTO-RUN an action that turned out BAD.
|
|
17
|
+
* The dangerous miscalibration — over-trust. This is the number that matters.
|
|
18
|
+
* - false-gate: the ramp would have GATED an action that turned out GOOD.
|
|
19
|
+
* The cost of caution — over-gating, not unsafe.
|
|
20
|
+
*
|
|
21
|
+
* "Agreement" = ramp-bypass on a good outcome OR ramp-queue on a bad outcome.
|
|
22
|
+
* Only risky (non-reversible) OWNED actions are scored — reversible always
|
|
23
|
+
* bypasses and unowned always queues, so neither is informative.
|
|
24
|
+
*/
|
|
25
|
+
export type DivergenceKind = "false-allow" | "false-gate";
|
|
26
|
+
export interface BacktestDivergence {
|
|
27
|
+
classKey: string;
|
|
28
|
+
tool: string;
|
|
29
|
+
at: number;
|
|
30
|
+
ramp: "bypass" | "queue";
|
|
31
|
+
outcome: "good" | "bad";
|
|
32
|
+
kind: DivergenceKind;
|
|
33
|
+
/** Earned level the ramp was operating at when it made the call. */
|
|
34
|
+
effectiveLevel: number;
|
|
35
|
+
}
|
|
36
|
+
export interface BacktestReport {
|
|
37
|
+
workerId: string;
|
|
38
|
+
/** risky owned actions scored */
|
|
39
|
+
considered: number;
|
|
40
|
+
agreed: number;
|
|
41
|
+
/** ramp would auto-run a BAD action (over-trust) — the dangerous miscalibration. */
|
|
42
|
+
falseAllow: number;
|
|
43
|
+
/** ramp would gate a GOOD action (over-caution) — the cost, not unsafe. */
|
|
44
|
+
falseGate: number;
|
|
45
|
+
/** agreed / considered (0 when nothing scored). */
|
|
46
|
+
agreementRate: number;
|
|
47
|
+
divergences: BacktestDivergence[];
|
|
48
|
+
}
|
|
49
|
+
export interface BacktestOpts {
|
|
50
|
+
cfg?: GraduationConfig;
|
|
51
|
+
/** Wall-clock for durable-outcome labelling. Defaults to past-all-runs so the
|
|
52
|
+
* whole history is treated as durable (a backtest looks at settled outcomes). */
|
|
53
|
+
now?: number;
|
|
54
|
+
durabilityWindowMs?: number;
|
|
55
|
+
/** When present, non-reversible durable successes are outcome-verified exactly
|
|
56
|
+
* as the live dial does (junk → bad, unknown/null → withheld) via the shared
|
|
57
|
+
* foldOutcome. Without it the backtest falls back to status-only labelling —
|
|
58
|
+
* which diverges from `workers shadow` whenever dispositions exist, so the
|
|
59
|
+
* live entry (runWorkerBacktest) always passes one. */
|
|
60
|
+
outcomeStore?: OutcomeStore;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Pure backtest of one worker over a set of runs. Folds outcomes chronologically
|
|
64
|
+
* (durable-outcome aware), taking the ramp's recommendation BEFORE folding each
|
|
65
|
+
* step so every decision uses only prior evidence.
|
|
66
|
+
*/
|
|
67
|
+
export declare function backtestWorker(worker: WorkerManifest, runs: RunRecord[], opts?: BacktestOpts): BacktestReport;
|
|
68
|
+
export declare function formatBacktestReport(r: BacktestReport): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { categoriseHaltReason } from "../recipes/haltCategory.js";
|
|
2
|
+
import { classifyActionClass } from "./actionClass.js";
|
|
3
|
+
import { DEFAULT_GRADUATION_CONFIG, } from "./graduation.js";
|
|
4
|
+
import { recommend } from "./shadowGate.js";
|
|
5
|
+
import { DEFAULT_DURABILITY_WINDOW_MS, foldOutcome, } from "./shadowObserver.js";
|
|
6
|
+
import { ownsAction, priorFor } from "./worker.js";
|
|
7
|
+
import { WorkerLevelStore } from "./workerLevelStore.js";
|
|
8
|
+
/**
|
|
9
|
+
* Pure backtest of one worker over a set of runs. Folds outcomes chronologically
|
|
10
|
+
* (durable-outcome aware), taking the ramp's recommendation BEFORE folding each
|
|
11
|
+
* step so every decision uses only prior evidence.
|
|
12
|
+
*/
|
|
13
|
+
export function backtestWorker(worker, runs, opts = {}) {
|
|
14
|
+
const store = new WorkerLevelStore();
|
|
15
|
+
const prior = priorFor(worker);
|
|
16
|
+
const cfg = opts.cfg ?? DEFAULT_GRADUATION_CONFIG;
|
|
17
|
+
const windowMs = opts.durabilityWindowMs ?? DEFAULT_DURABILITY_WINDOW_MS;
|
|
18
|
+
const sorted = [...runs]
|
|
19
|
+
.filter((r) => r.recipeName === worker.recipe)
|
|
20
|
+
.sort((a, b) => a.at - b.at);
|
|
21
|
+
// Default `now` past every run so settled history counts as durable.
|
|
22
|
+
const last = sorted.at(-1);
|
|
23
|
+
const now = opts.now ?? (last ? last.at + windowMs + 1 : 0);
|
|
24
|
+
const divergences = [];
|
|
25
|
+
let considered = 0;
|
|
26
|
+
let agreed = 0;
|
|
27
|
+
let falseAllow = 0;
|
|
28
|
+
let falseGate = 0;
|
|
29
|
+
for (const run of sorted) {
|
|
30
|
+
for (const step of run.steps) {
|
|
31
|
+
if (!step.tool || step.status === "skipped")
|
|
32
|
+
continue;
|
|
33
|
+
// Human reject/expire/cancel is a control decision, not worker evidence.
|
|
34
|
+
if (step.status === "error" &&
|
|
35
|
+
categoriseHaltReason(step.haltReason) === "approval_rejected")
|
|
36
|
+
continue;
|
|
37
|
+
const ac = classifyActionClass(step.tool);
|
|
38
|
+
// Durable-outcome fold — the SAME labelling the live dial/gate uses (shared
|
|
39
|
+
// foldOutcome): junk → bad, unknown/null → withheld, pending → withheld.
|
|
40
|
+
const decision = foldOutcome(step, run.at, {
|
|
41
|
+
now,
|
|
42
|
+
windowMs,
|
|
43
|
+
outcomeStore: opts.outcomeStore,
|
|
44
|
+
});
|
|
45
|
+
// Score only risky OWNED actions with a KNOWN durable outcome. A withheld
|
|
46
|
+
// step (pending, or unknown disposition) has no ground truth to calibrate
|
|
47
|
+
// against, so it is excluded from the divergence sample rather than counted
|
|
48
|
+
// as a spurious "good" (which is exactly the status-only bug this fixes).
|
|
49
|
+
if (ac.reversibility !== "reversible" &&
|
|
50
|
+
ownsAction(worker, ac) &&
|
|
51
|
+
decision.fold) {
|
|
52
|
+
const rec = recommend(worker, step.tool, undefined, store); // as-of decision
|
|
53
|
+
const outcomeGood = decision.good;
|
|
54
|
+
const rampBypass = rec.decision === "bypass";
|
|
55
|
+
considered++;
|
|
56
|
+
if (rampBypass === outcomeGood) {
|
|
57
|
+
agreed++;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const kind = rampBypass
|
|
61
|
+
? "false-allow"
|
|
62
|
+
: "false-gate";
|
|
63
|
+
if (rampBypass)
|
|
64
|
+
falseAllow++;
|
|
65
|
+
else
|
|
66
|
+
falseGate++;
|
|
67
|
+
divergences.push({
|
|
68
|
+
classKey: ac.key,
|
|
69
|
+
tool: step.tool,
|
|
70
|
+
at: run.at,
|
|
71
|
+
ramp: rec.decision,
|
|
72
|
+
outcome: outcomeGood ? "good" : "bad",
|
|
73
|
+
kind,
|
|
74
|
+
effectiveLevel: rec.effectiveLevel,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Fold so the ramp evolves over the replay (skips withheld steps).
|
|
79
|
+
if (decision.fold) {
|
|
80
|
+
store.apply(worker.id, { toolName: step.tool, good: decision.good, at: run.at }, { prior, cfg });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
workerId: worker.id,
|
|
86
|
+
considered,
|
|
87
|
+
agreed,
|
|
88
|
+
falseAllow,
|
|
89
|
+
falseGate,
|
|
90
|
+
agreementRate: considered ? agreed / considered : 0,
|
|
91
|
+
divergences,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function formatBacktestReport(r) {
|
|
95
|
+
if (r.considered === 0) {
|
|
96
|
+
return `▸ ${r.workerId}: no risky owned actions in the replay window — nothing to calibrate.\n`;
|
|
97
|
+
}
|
|
98
|
+
const pct = (r.agreementRate * 100).toFixed(0);
|
|
99
|
+
const lines = [
|
|
100
|
+
`▸ ${r.workerId} — backtest over ${r.considered} risky owned action(s)`,
|
|
101
|
+
` agreed with the outcome: ${r.agreed}/${r.considered} (${pct}%)`,
|
|
102
|
+
` false-allow: ${r.falseAllow} (ramp would AUTO-RUN a bad action — over-trust)`,
|
|
103
|
+
` false-gate: ${r.falseGate} (ramp would gate a good action — cost of caution)`,
|
|
104
|
+
];
|
|
105
|
+
const fa = r.divergences.filter((d) => d.kind === "false-allow").slice(0, 5);
|
|
106
|
+
if (fa.length) {
|
|
107
|
+
lines.push(" ⚠ false-allow divergences (the ones to look at):");
|
|
108
|
+
for (const d of fa)
|
|
109
|
+
lines.push(` ${d.tool} [${d.classKey}] at L${d.effectiveLevel} → ramp bypass, outcome BAD`);
|
|
110
|
+
}
|
|
111
|
+
return `${lines.join("\n")}\n`;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=backtest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backtest.js","sourceRoot":"","sources":["../../src/workers/backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,yBAAyB,GAE1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,WAAW,GAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAuB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAgEzD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAsB,EACtB,IAAiB,EACjB,OAAqB,EAAE;IAEvB,MAAM,KAAK,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,yBAAyB,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB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AAS,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC,cAAc,6BAA6B,CACrF,CAAC;IACN,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { TrustLevel } from "./trustLevel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Context-risk — the FAST, situational half of the autonomy decision.
|
|
4
|
+
*
|
|
5
|
+
* Earned trust answers "is this worker generally reliable on this action-class?"
|
|
6
|
+
* (slow, accrued over many runs). Context-risk answers a DIFFERENT, orthogonal
|
|
7
|
+
* question: "is THIS situation safe to act in RIGHT NOW?" — computed per-action
|
|
8
|
+
* from signals the bridge already exposes (open diagnostics in the touched
|
|
9
|
+
* files, test coverage, git hotspot-ness, diff size, CI status). It has no
|
|
10
|
+
* cold-start: it is fully computable on day one, so it can de-rate autonomy from
|
|
11
|
+
* the very first action while the trust posterior is still accruing.
|
|
12
|
+
*
|
|
13
|
+
* It is a DE-RATER only: it can lower the effective autonomy level, never raise
|
|
14
|
+
* it (never-widen). Combined with earned trust + the autonomy ceiling, the gate
|
|
15
|
+
* becomes `min(earned, ceiling, contextCeiling)` — a worker stays at its earned
|
|
16
|
+
* level when the situation is clean and is throttled toward propose-only as live
|
|
17
|
+
* risk climbs. This is the dimension "approve-once / approve-similar" structurally
|
|
18
|
+
* cannot model. See docs/worker-autonomy-policy-gate.md §3a.
|
|
19
|
+
*/
|
|
20
|
+
export interface ContextRisk {
|
|
21
|
+
/** 0 (clean) … 1 (dangerous). Out-of-range / NaN is treated as "unknown". */
|
|
22
|
+
score: number;
|
|
23
|
+
/** Human-readable contributors (e.g. "CI red", "diff 1.2k lines", "hotspot
|
|
24
|
+
* file"), surfaced in the gate reason + audit trail. */
|
|
25
|
+
reasons?: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Map a context-risk score to the MAX autonomy rung permitted in this situation.
|
|
29
|
+
* DESCENDING only — higher risk ⇒ lower ceiling. Returns L4 (no de-rate) for a
|
|
30
|
+
* clean OR unknown/unmeasurable score: context-risk adds caution when danger is
|
|
31
|
+
* MEASURED; when it can't be measured the base gate (earned trust + ceiling)
|
|
32
|
+
* still applies its own floor, so an unknown situation must not silently throttle
|
|
33
|
+
* everything to zero.
|
|
34
|
+
*/
|
|
35
|
+
export declare function contextRiskCeiling(score: number): TrustLevel;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map a context-risk score to the MAX autonomy rung permitted in this situation.
|
|
3
|
+
* DESCENDING only — higher risk ⇒ lower ceiling. Returns L4 (no de-rate) for a
|
|
4
|
+
* clean OR unknown/unmeasurable score: context-risk adds caution when danger is
|
|
5
|
+
* MEASURED; when it can't be measured the base gate (earned trust + ceiling)
|
|
6
|
+
* still applies its own floor, so an unknown situation must not silently throttle
|
|
7
|
+
* everything to zero.
|
|
8
|
+
*/
|
|
9
|
+
export function contextRiskCeiling(score) {
|
|
10
|
+
if (!Number.isFinite(score) || score <= 0)
|
|
11
|
+
return 4; // clean / unknown → no de-rate
|
|
12
|
+
if (score >= 0.8)
|
|
13
|
+
return 0; // dangerous → propose-only: every risky action gated
|
|
14
|
+
if (score >= 0.5)
|
|
15
|
+
return 1; // elevated → reversible only flows freely
|
|
16
|
+
if (score >= 0.3)
|
|
17
|
+
return 2; // moderate → compensable ok, irreversible still gated
|
|
18
|
+
return 4; // mild → no de-rate
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=contextRisk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextRisk.js","sourceRoot":"","sources":["../../src/workers/contextRisk.ts"],"names":[],"mappings":"AA4BA;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,+BAA+B;IACpF,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,CAAC,CAAC,CAAC,qDAAqD;IACjF,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,CAAC,CAAC,CAAC,0CAA0C;IACtE,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,CAAC,CAAC,CAAC,sDAAsD;IAClF,OAAO,CAAC,CAAC,CAAC,oBAAoB;AAChC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ContextRisk } from "./contextRisk.js";
|
|
2
|
+
/**
|
|
3
|
+
* The live producer behind the context-risk seam (workerGate / contextRisk.ts).
|
|
4
|
+
* Gathers cheap, dependency-light situational signals from the workspace and
|
|
5
|
+
* scores them into a `ContextRisk` the gate uses as a DESCENDING de-rater.
|
|
6
|
+
*
|
|
7
|
+
* Signals are deliberately the ones reliably available server-side during a
|
|
8
|
+
* recipe run (the bridge runs in a git repo): working-tree size + which branch.
|
|
9
|
+
* Diagnostics / coverage / CI are richer but require the extension / network and
|
|
10
|
+
* are added later. Everything is fail-soft: an unavailable signal simply doesn't
|
|
11
|
+
* contribute, and a total failure yields score 0 (no de-rate, never widens).
|
|
12
|
+
* See docs/worker-autonomy-policy-gate.md §3a.
|
|
13
|
+
*/
|
|
14
|
+
/** Raw situational signals. All optional — absent ⇒ no contribution. */
|
|
15
|
+
export interface ContextSignals {
|
|
16
|
+
/** Uncommitted lines changed (added + deleted) vs HEAD. */
|
|
17
|
+
diffLines?: number;
|
|
18
|
+
/** Files with uncommitted changes vs HEAD. */
|
|
19
|
+
dirtyFiles?: number;
|
|
20
|
+
/** HEAD is the default branch (main/master) — acting on trunk is riskier
|
|
21
|
+
* than on a feature branch that can be reviewed before merge. */
|
|
22
|
+
onDefaultBranch?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Pure scorer: signals → ContextRisk (0..1 + human reasons). Each signal
|
|
26
|
+
* contributes risk independently and they combine by NOISY-OR
|
|
27
|
+
* (`1 − ∏(1 − sᵢ)`), so several moderate signals compound toward "act with
|
|
28
|
+
* caution" without any single one needing to be severe. Higher = more dangerous
|
|
29
|
+
* to act RIGHT NOW. Pure + deterministic.
|
|
30
|
+
*/
|
|
31
|
+
export declare function scoreContextRisk(signals: ContextSignals): ContextRisk;
|
|
32
|
+
/** Injectable command runner (returns stdout). Defaults to the bridge's
|
|
33
|
+
* allowlisted `execSafe` over `cwd`. Exposed so tests supply fake git output. */
|
|
34
|
+
export type ExecFn = (cmd: string, args: string[]) => Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Gather git working-tree signals. Fully fail-soft: any git error leaves the
|
|
37
|
+
* corresponding signal undefined (→ no contribution). Never throws.
|
|
38
|
+
*/
|
|
39
|
+
export declare function collectGitContextSignals(opts: {
|
|
40
|
+
cwd: string;
|
|
41
|
+
exec?: ExecFn;
|
|
42
|
+
}): Promise<ContextSignals>;
|
|
43
|
+
/** Convenience: collect + score in one fail-soft call. Returns undefined when
|
|
44
|
+
* the situation is clean (score 0) so callers can omit the field. */
|
|
45
|
+
export declare function resolveGitContextRisk(opts: {
|
|
46
|
+
cwd: string;
|
|
47
|
+
exec?: ExecFn;
|
|
48
|
+
}): Promise<ContextRisk | undefined>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { execSafe } from "../tools/utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure scorer: signals → ContextRisk (0..1 + human reasons). Each signal
|
|
4
|
+
* contributes risk independently and they combine by NOISY-OR
|
|
5
|
+
* (`1 − ∏(1 − sᵢ)`), so several moderate signals compound toward "act with
|
|
6
|
+
* caution" without any single one needing to be severe. Higher = more dangerous
|
|
7
|
+
* to act RIGHT NOW. Pure + deterministic.
|
|
8
|
+
*/
|
|
9
|
+
export function scoreContextRisk(signals) {
|
|
10
|
+
const contribs = [];
|
|
11
|
+
if (signals.diffLines !== undefined) {
|
|
12
|
+
if (signals.diffLines >= 2000)
|
|
13
|
+
contribs.push({
|
|
14
|
+
score: 0.9,
|
|
15
|
+
reason: `huge uncommitted diff (${signals.diffLines} lines)`,
|
|
16
|
+
});
|
|
17
|
+
else if (signals.diffLines >= 500)
|
|
18
|
+
contribs.push({
|
|
19
|
+
score: 0.5,
|
|
20
|
+
reason: `large uncommitted diff (${signals.diffLines} lines)`,
|
|
21
|
+
});
|
|
22
|
+
else if (signals.diffLines >= 200)
|
|
23
|
+
contribs.push({
|
|
24
|
+
score: 0.3,
|
|
25
|
+
reason: `sizeable uncommitted diff (${signals.diffLines} lines)`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (signals.dirtyFiles !== undefined && signals.dirtyFiles >= 20)
|
|
29
|
+
contribs.push({
|
|
30
|
+
score: 0.5,
|
|
31
|
+
reason: `${signals.dirtyFiles} files with uncommitted changes`,
|
|
32
|
+
});
|
|
33
|
+
if (signals.onDefaultBranch)
|
|
34
|
+
contribs.push({
|
|
35
|
+
score: 0.3,
|
|
36
|
+
reason: "operating directly on the default branch",
|
|
37
|
+
});
|
|
38
|
+
const score = contribs.length === 0
|
|
39
|
+
? 0
|
|
40
|
+
: 1 - contribs.reduce((p, c) => p * (1 - c.score), 1);
|
|
41
|
+
return {
|
|
42
|
+
score,
|
|
43
|
+
...(contribs.length > 0 && { reasons: contribs.map((c) => c.reason) }),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gather git working-tree signals. Fully fail-soft: any git error leaves the
|
|
48
|
+
* corresponding signal undefined (→ no contribution). Never throws.
|
|
49
|
+
*/
|
|
50
|
+
export async function collectGitContextSignals(opts) {
|
|
51
|
+
const exec = opts.exec ??
|
|
52
|
+
(async (cmd, args) => (await execSafe(cmd, args, { cwd: opts.cwd, timeout: 5000 })).stdout);
|
|
53
|
+
const signals = {};
|
|
54
|
+
try {
|
|
55
|
+
// `diff HEAD` = staged + unstaged vs the last commit (the full uncommitted
|
|
56
|
+
// delta). `--numstat` is `<added>\t<deleted>\t<path>` per file ("-" binary).
|
|
57
|
+
const numstat = await exec("git", ["diff", "HEAD", "--numstat"]);
|
|
58
|
+
let lines = 0;
|
|
59
|
+
let files = 0;
|
|
60
|
+
for (const row of numstat.split("\n")) {
|
|
61
|
+
const m = /^(\d+|-)\t(\d+|-)\t/.exec(row);
|
|
62
|
+
if (!m)
|
|
63
|
+
continue;
|
|
64
|
+
files++;
|
|
65
|
+
lines +=
|
|
66
|
+
(m[1] === "-" ? 0 : Number(m[1])) + (m[2] === "-" ? 0 : Number(m[2]));
|
|
67
|
+
}
|
|
68
|
+
signals.diffLines = lines;
|
|
69
|
+
signals.dirtyFiles = files;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
/* git unavailable / not a repo → leave diff signals undefined */
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const branch = (await exec("git", ["rev-parse", "--abbrev-ref", "HEAD"])).trim();
|
|
76
|
+
signals.onDefaultBranch = branch === "main" || branch === "master";
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
/* ignore */
|
|
80
|
+
}
|
|
81
|
+
return signals;
|
|
82
|
+
}
|
|
83
|
+
/** Convenience: collect + score in one fail-soft call. Returns undefined when
|
|
84
|
+
* the situation is clean (score 0) so callers can omit the field. */
|
|
85
|
+
export async function resolveGitContextRisk(opts) {
|
|
86
|
+
try {
|
|
87
|
+
const risk = scoreContextRisk(await collectGitContextSignals(opts));
|
|
88
|
+
return risk.score > 0 ? risk : undefined;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=contextRiskScorer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextRiskScorer.js","sourceRoot":"","sources":["../../src/workers/contextRiskScorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA2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,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAC1B,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,iEAAiE;IACnE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,CACb,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,CACzD,CAAC,IAAI,EAAE,CAAC;QACT,OAAO,CAAC,eAAe,GAAG,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,QAAQ,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;sEACsE;AACtE,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,IAG3C;IACC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Posterior, type TrustLevel } from "./trustLevel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Folds outcomes into a (worker × action-class) trust state and decides
|
|
4
|
+
* promotions/demotions with the asymmetry + hysteresis the ramp requires:
|
|
5
|
+
* - DEMOTE is instant and can jump multiple rungs (one catastrophic outcome
|
|
6
|
+
* craters the posterior; we honor it immediately, even mid-dwell);
|
|
7
|
+
* - PROMOTE is gated by dwell-time (real elapsed time since the last level
|
|
8
|
+
* change) AND a post-demote cooldown, and climbs only to the NEXT reachable
|
|
9
|
+
* rung — so reaching L4 needs both sustained evidence and sustained time.
|
|
10
|
+
* Every level change emits an event — the promotion/demotion log is the
|
|
11
|
+
* compliance/audit artifact.
|
|
12
|
+
*/
|
|
13
|
+
export interface Outcome {
|
|
14
|
+
toolName: string;
|
|
15
|
+
good: boolean;
|
|
16
|
+
/** epoch ms (passed in — the runtime has no Date.now() in pure code). */
|
|
17
|
+
at: number;
|
|
18
|
+
params?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface ClassTrustState {
|
|
21
|
+
classKey: string;
|
|
22
|
+
posterior: Posterior;
|
|
23
|
+
prior: Posterior;
|
|
24
|
+
level: TrustLevel;
|
|
25
|
+
/** epoch ms of the last level change (drives dwell). */
|
|
26
|
+
lastChangeAt: number;
|
|
27
|
+
/** epoch ms before which promotions are blocked (post-demote cooldown). */
|
|
28
|
+
demoteUntil: number;
|
|
29
|
+
observations: number;
|
|
30
|
+
/**
|
|
31
|
+
* The `minEvidenceForGraduation` threshold in effect when this class last
|
|
32
|
+
* promoted ABOVE L1. The novel-class floor is a cold-start gate: once a class
|
|
33
|
+
* has cleared it, RAISING the config later must not retroactively re-apply the
|
|
34
|
+
* floor and demote an already-earned level. We honour the threshold the class
|
|
35
|
+
* actually graduated under. `undefined` = never promoted above L1 (cold-start;
|
|
36
|
+
* the current config applies in full).
|
|
37
|
+
*/
|
|
38
|
+
minEvidenceAtLastPromotion?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface GraduationConfig {
|
|
41
|
+
dwellMs: number;
|
|
42
|
+
demoteCooldownMs: number;
|
|
43
|
+
k?: number;
|
|
44
|
+
minEvidenceForGraduation?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_GRADUATION_CONFIG: GraduationConfig;
|
|
47
|
+
export interface GraduationEvent {
|
|
48
|
+
type: "promote" | "demote";
|
|
49
|
+
classKey: string;
|
|
50
|
+
from: TrustLevel;
|
|
51
|
+
to: TrustLevel;
|
|
52
|
+
at: number;
|
|
53
|
+
lcb: number;
|
|
54
|
+
evidence: number;
|
|
55
|
+
reason: string;
|
|
56
|
+
}
|
|
57
|
+
export declare function initialState(classKey: string, prior: Posterior, at?: number): ClassTrustState;
|
|
58
|
+
export declare function graduate(state: ClassTrustState, outcome: Outcome, cfg?: GraduationConfig): {
|
|
59
|
+
state: ClassTrustState;
|
|
60
|
+
event?: GraduationEvent;
|
|
61
|
+
};
|