patchwork-os 0.2.0-beta.9.canary.92 → 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,203 @@
|
|
|
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 { ownsAction, ownsClassKey, priorFor, } from "./worker.js";
|
|
6
|
+
import { WorkerLevelStore, } from "./workerLevelStore.js";
|
|
7
|
+
/** Default durability window — a non-reversible success must survive this long
|
|
8
|
+
* before it counts as earned trust. 24h is long enough to catch a revert /
|
|
9
|
+
* close-as-junk / rollback, short enough that a genuinely-good action graduates
|
|
10
|
+
* within a day. */
|
|
11
|
+
export const DEFAULT_DURABILITY_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
12
|
+
/**
|
|
13
|
+
* Durable-outcome label. `good = step.status:ok` is an OPTIMISTIC proxy: a PR
|
|
14
|
+
* that merged, an issue that filed — but a junk issue closed seconds later, or a
|
|
15
|
+
* commit reverted within the hour, "succeeded" at the moment yet is not earned
|
|
16
|
+
* trust. So a SUCCESS on a non-reversible (compensable/irreversible) action is
|
|
17
|
+
* "durable" — i.e. counts as evidence — only once it has survived the durability
|
|
18
|
+
* window. Reversible successes (undoable / re-runnable: reads, ledgered writes,
|
|
19
|
+
* local commits, CI) are always durable. Failures are unaffected (a failure is
|
|
20
|
+
* durable evidence of failure regardless of age).
|
|
21
|
+
*
|
|
22
|
+
* This only ever WITHHOLDS recent risky successes (reduces evidence → lower
|
|
23
|
+
* trust → more gating), so it never widens autonomy. See
|
|
24
|
+
* docs/worker-autonomy-policy-gate.md §3d.
|
|
25
|
+
*/
|
|
26
|
+
export function isDurableSuccess(reversibility, runAt, now, windowMs) {
|
|
27
|
+
if (reversibility === "reversible")
|
|
28
|
+
return true;
|
|
29
|
+
return runAt <= now - windowMs;
|
|
30
|
+
}
|
|
31
|
+
export function foldOutcome(step, runAt, opts) {
|
|
32
|
+
if (!step.tool)
|
|
33
|
+
return { fold: false };
|
|
34
|
+
if (step.status !== "ok")
|
|
35
|
+
return { fold: true, good: false };
|
|
36
|
+
// Success. Without a wall-clock, keep the prior status-only fold (back-compat).
|
|
37
|
+
if (opts.now === undefined)
|
|
38
|
+
return { fold: true, good: true };
|
|
39
|
+
const ac = classifyActionClass(step.tool);
|
|
40
|
+
// For a non-reversible filing, read the operator disposition up front (issue /
|
|
41
|
+
// PR URL). Reversible successes never consult the store — they are always durable.
|
|
42
|
+
const outcomeStore = ac.reversibility !== "reversible" ? opts.outcomeStore : undefined;
|
|
43
|
+
const url = outcomeStore && step.output && typeof step.output.url === "string"
|
|
44
|
+
? step.output.url
|
|
45
|
+
: null;
|
|
46
|
+
const disposition = url ? (outcomeStore?.getDisposition(url) ?? null) : null;
|
|
47
|
+
// A human REJECTION demotes IMMEDIATELY. Junk is durable evidence of failure
|
|
48
|
+
// the moment it lands, so — like any outright failure (status ≠ ok above) — it
|
|
49
|
+
// must NOT sit withheld for the durability window ("demotion is instant", see
|
|
50
|
+
// trustLevel.ts). Checked BEFORE the window. Confirmed/unknown must NOT
|
|
51
|
+
// short-circuit the window: folding a still-provisional success early would
|
|
52
|
+
// WIDEN evidence, so this is junk-early only.
|
|
53
|
+
if (disposition === "junk")
|
|
54
|
+
return { fold: true, good: false };
|
|
55
|
+
if (!isDurableSuccess(ac.reversibility, runAt, opts.now, opts.windowMs))
|
|
56
|
+
return { fold: false }; // pending — survives the window before it earns trust
|
|
57
|
+
// Past the window: an unactioned filing (unknown / no record) is WITHHELD —
|
|
58
|
+
// unactioned ≠ correct (trust-by-neglect fix). Confirmed / no-url → good:true.
|
|
59
|
+
if (url && (disposition === "unknown" || disposition === null))
|
|
60
|
+
return { fold: false }; // withheld — not evidence
|
|
61
|
+
return { fold: true, good: true };
|
|
62
|
+
}
|
|
63
|
+
export class WorkerShadowObserver {
|
|
64
|
+
store;
|
|
65
|
+
cfg;
|
|
66
|
+
workers;
|
|
67
|
+
compare = new Map();
|
|
68
|
+
/** Wall-clock supplied by the I/O entry (the observer stays pure — no
|
|
69
|
+
* Date.now). When set, durable-outcome labelling is active; when undefined,
|
|
70
|
+
* the prior status-only behaviour is preserved (back-compat for pure tests). */
|
|
71
|
+
now;
|
|
72
|
+
durabilityWindowMs;
|
|
73
|
+
/** Optional outcome store — when present, junk issues flip good:false past
|
|
74
|
+
* the durability window instead of counting as earned trust. */
|
|
75
|
+
outcomeStore;
|
|
76
|
+
constructor(workers, opts = {}) {
|
|
77
|
+
this.workers = workers;
|
|
78
|
+
this.store = opts.store ?? new WorkerLevelStore();
|
|
79
|
+
this.cfg = opts.cfg ?? DEFAULT_GRADUATION_CONFIG;
|
|
80
|
+
this.now = opts.now;
|
|
81
|
+
this.durabilityWindowMs =
|
|
82
|
+
opts.durabilityWindowMs ?? DEFAULT_DURABILITY_WINDOW_MS;
|
|
83
|
+
this.outcomeStore = opts.outcomeStore;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The populated level store. Exposed so the LIVE worker-autonomy gate
|
|
87
|
+
* (`workerGate.decideWorkerAction`) can read the same earned levels this
|
|
88
|
+
* observer derives from the run log — one source of truth for the dial and
|
|
89
|
+
* the gate. Read-only intent; callers must not mutate.
|
|
90
|
+
*/
|
|
91
|
+
get levelStore() {
|
|
92
|
+
return this.store;
|
|
93
|
+
}
|
|
94
|
+
/** The worker whose recipe body is `recipeName`, if any. */
|
|
95
|
+
workerForRecipe(recipeName) {
|
|
96
|
+
return this.workers.find((w) => w.recipe === recipeName);
|
|
97
|
+
}
|
|
98
|
+
/** Attribute a tool call to its SOLE owning worker (ambiguous → skip). */
|
|
99
|
+
workerForAction(toolName, params) {
|
|
100
|
+
const ac = classifyActionClass(toolName, params);
|
|
101
|
+
const owners = this.workers.filter((w) => ownsAction(w, ac));
|
|
102
|
+
return owners.length === 1 ? owners[0] : undefined;
|
|
103
|
+
}
|
|
104
|
+
/** Feed a recipe run's step outcomes into the owning worker's dial. */
|
|
105
|
+
ingestRun(run) {
|
|
106
|
+
const worker = this.workerForRecipe(run.recipeName);
|
|
107
|
+
if (!worker)
|
|
108
|
+
return;
|
|
109
|
+
const prior = priorFor(worker);
|
|
110
|
+
for (const step of run.steps) {
|
|
111
|
+
if (!step.tool || step.status === "skipped")
|
|
112
|
+
continue; // skipped ≠ evidence
|
|
113
|
+
// L2: a step halted because a HUMAN rejected / let expire / cancelled the
|
|
114
|
+
// approval is a control decision, not a worker failure — counting it as
|
|
115
|
+
// `good: false` would demote the worker for every correct "not yet", so
|
|
116
|
+
// the gate could never self-clear. Skip it (non-evidence). Genuine tool
|
|
117
|
+
// errors still count.
|
|
118
|
+
if (step.status === "error" &&
|
|
119
|
+
categoriseHaltReason(step.haltReason) === "approval_rejected")
|
|
120
|
+
continue;
|
|
121
|
+
// Durable-outcome fold (shared with the backtest via foldOutcome): a recent
|
|
122
|
+
// SUCCESS on a non-reversible action is provisional, and past the window a
|
|
123
|
+
// junk filing flips good:false while an unknown/unactioned one is WITHHELD
|
|
124
|
+
// (trust-by-neglect fix). Only active when `now` was supplied; otherwise the
|
|
125
|
+
// prior status-only fold is used. Withholds evidence only → never widens.
|
|
126
|
+
const decision = foldOutcome(step, run.at, {
|
|
127
|
+
now: this.now,
|
|
128
|
+
windowMs: this.durabilityWindowMs,
|
|
129
|
+
outcomeStore: this.outcomeStore,
|
|
130
|
+
});
|
|
131
|
+
if (!decision.fold)
|
|
132
|
+
continue;
|
|
133
|
+
this.store.apply(worker.id, { toolName: step.tool, good: decision.good, at: run.at }, { prior, cfg: this.cfg });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Compare what the ramp WOULD recommend (given the dial as of now) against
|
|
137
|
+
* the gate's actual decision. Read-only — records agreement + divergences.
|
|
138
|
+
*
|
|
139
|
+
* Only worker-gate decisions (those with a recipeName) are counted. Plain
|
|
140
|
+
* Claude-session MCP tool approvals share the same ActivityLog event type
|
|
141
|
+
* but have no recipeName — including them would inflate divergences with
|
|
142
|
+
* calls the worker gate never saw. */
|
|
143
|
+
ingestDecision(d) {
|
|
144
|
+
if (!d.recipeName)
|
|
145
|
+
return;
|
|
146
|
+
const worker = this.workerForAction(d.toolName, d.params);
|
|
147
|
+
if (!worker)
|
|
148
|
+
return;
|
|
149
|
+
const rec = recommend(worker, d.toolName, d.params, this.store);
|
|
150
|
+
const rampBypass = rec.decision === "bypass";
|
|
151
|
+
const gateAllowed = d.decision === "allow";
|
|
152
|
+
// ramp "bypass" ↔ gate would not need to gate; ramp "queue" ↔ gate gates.
|
|
153
|
+
const agree = rampBypass === gateAllowed;
|
|
154
|
+
const slot = this.compare.get(worker.id) ?? {
|
|
155
|
+
compared: 0,
|
|
156
|
+
agreed: 0,
|
|
157
|
+
divergences: [],
|
|
158
|
+
};
|
|
159
|
+
slot.compared++;
|
|
160
|
+
if (agree) {
|
|
161
|
+
slot.agreed++;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
slot.divergences.push({
|
|
165
|
+
classKey: rec.classKey,
|
|
166
|
+
toolName: d.toolName,
|
|
167
|
+
ramp: rec.decision,
|
|
168
|
+
gate: d.decision,
|
|
169
|
+
at: d.at,
|
|
170
|
+
note: rampBypass
|
|
171
|
+
? `ramp would auto-run (${rec.reason}); gate still gated`
|
|
172
|
+
: "ramp would gate; gate allowed",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
this.compare.set(worker.id, slot);
|
|
176
|
+
}
|
|
177
|
+
report() {
|
|
178
|
+
return this.workers.map((w) => {
|
|
179
|
+
const c = this.compare.get(w.id) ?? {
|
|
180
|
+
compared: 0,
|
|
181
|
+
agreed: 0,
|
|
182
|
+
divergences: [],
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
workerId: w.id,
|
|
186
|
+
name: w.name,
|
|
187
|
+
autonomyCeiling: w.autonomyCeiling,
|
|
188
|
+
// L3: flag rows for classes the worker performs but does NOT own — the
|
|
189
|
+
// dial shows accrued evidence there, but the live gate floors them to 0
|
|
190
|
+
// (a worker has no standing trust outside its `owns`). Without the flag
|
|
191
|
+
// the dial looks like earned autonomy that the gate silently ignores.
|
|
192
|
+
board: this.store
|
|
193
|
+
.board(w.id)
|
|
194
|
+
.map((r) => ({ ...r, owned: ownsClassKey(w, r.classKey) })),
|
|
195
|
+
events: this.store.events(w.id),
|
|
196
|
+
compared: c.compared,
|
|
197
|
+
agreed: c.agreed,
|
|
198
|
+
divergences: c.divergences,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=shadowObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadowObserver.js","sourceRoot":"","sources":["../../src/workers/shadowObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AA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CAAC;gBACT,WAAW,EAAE,EAAE;aAChB,CAAC;YACF,OAAO;gBACL,QAAQ,EAAE,CAAC,CAAC,EAAE;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,eAAe,EAAE,CAAC,CAAC,eAAe;gBAClC,uEAAuE;gBACvE,wEAAwE;gBACxE,wEAAwE;gBACxE,sEAAsE;gBACtE,KAAK,EAAE,IAAI,CAAC,KAAK;qBACd,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;qBACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAC7D,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/B,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,WAAW,EAAE,CAAC,CAAC,WAAW;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GraduationConfig } from "./graduation.js";
|
|
2
|
+
import type { OutcomeStore } from "./outcomeStore.js";
|
|
3
|
+
import { type DecisionRecord, type RunRecord, type WorkerShadowReport } from "./shadowObserver.js";
|
|
4
|
+
import type { WorkerManifest } from "./worker.js";
|
|
5
|
+
/**
|
|
6
|
+
* Build the shadow report by feeding runs + decisions into the observer in
|
|
7
|
+
* timestamp order, so each ramp-vs-gate comparison sees the dial as it stood AT
|
|
8
|
+
* that moment (not the final state). Pure — the I/O entry (runWorkerShadow)
|
|
9
|
+
* supplies the records read from the real logs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildShadowReport(workers: WorkerManifest[], runs: RunRecord[], decisions: DecisionRecord[], cfg?: GraduationConfig, opts?: {
|
|
12
|
+
now?: number;
|
|
13
|
+
durabilityWindowMs?: number;
|
|
14
|
+
outcomeStore?: OutcomeStore;
|
|
15
|
+
}): WorkerShadowReport[];
|
|
16
|
+
export declare function formatShadowReport(reports: WorkerShadowReport[]): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { WorkerShadowObserver, } from "./shadowObserver.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the shadow report by feeding runs + decisions into the observer in
|
|
4
|
+
* timestamp order, so each ramp-vs-gate comparison sees the dial as it stood AT
|
|
5
|
+
* that moment (not the final state). Pure — the I/O entry (runWorkerShadow)
|
|
6
|
+
* supplies the records read from the real logs.
|
|
7
|
+
*/
|
|
8
|
+
export function buildShadowReport(workers, runs, decisions, cfg, opts = {}) {
|
|
9
|
+
const obs = new WorkerShadowObserver(workers, {
|
|
10
|
+
cfg,
|
|
11
|
+
...(opts.now !== undefined && { now: opts.now }),
|
|
12
|
+
...(opts.durabilityWindowMs !== undefined && {
|
|
13
|
+
durabilityWindowMs: opts.durabilityWindowMs,
|
|
14
|
+
}),
|
|
15
|
+
...(opts.outcomeStore !== undefined && { outcomeStore: opts.outcomeStore }),
|
|
16
|
+
});
|
|
17
|
+
const merged = [
|
|
18
|
+
...runs.map((r) => ({ at: r.at, run: r })),
|
|
19
|
+
...decisions.map((d) => ({ at: d.at, dec: d })),
|
|
20
|
+
].sort((a, b) => a.at - b.at);
|
|
21
|
+
for (const e of merged) {
|
|
22
|
+
if (e.run)
|
|
23
|
+
obs.ingestRun(e.run);
|
|
24
|
+
else if (e.dec)
|
|
25
|
+
obs.ingestDecision(e.dec);
|
|
26
|
+
}
|
|
27
|
+
return obs.report();
|
|
28
|
+
}
|
|
29
|
+
export function formatShadowReport(reports) {
|
|
30
|
+
const lines = [
|
|
31
|
+
"Worker trust dial — SHADOW (read-only; no live gate change)",
|
|
32
|
+
"",
|
|
33
|
+
];
|
|
34
|
+
for (const r of reports) {
|
|
35
|
+
lines.push(`▸ ${r.name} [${r.workerId}] · autonomy ceiling L${r.autonomyCeiling}`);
|
|
36
|
+
if (r.board.length === 0) {
|
|
37
|
+
lines.push(" (no attributed activity yet — dial fills as the worker runs)");
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
for (const b of r.board) {
|
|
41
|
+
const capped = b.level > r.autonomyCeiling
|
|
42
|
+
? ` → operating L${r.autonomyCeiling} (ceiling)`
|
|
43
|
+
: "";
|
|
44
|
+
// L3: a class the worker performs but doesn't own is floored to L0 by
|
|
45
|
+
// the gate regardless of the evidence shown here — flag it so the dial
|
|
46
|
+
// isn't read as earned autonomy the gate will honour.
|
|
47
|
+
const notOwned = b.owned ? "" : " ⚠ NOT OWNED — gate floors to L0";
|
|
48
|
+
lines.push(` ${b.classKey.padEnd(36)} earned L${b.level}${capped} · ${b.observations} obs · ${(b.mean * 100).toFixed(0)}% mean${notOwned}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (r.compared > 0) {
|
|
52
|
+
lines.push(` ramp vs gate: ${r.agreed}/${r.compared} agree · ${r.divergences.length} divergence(s)`);
|
|
53
|
+
for (const d of r.divergences.slice(0, 5)) {
|
|
54
|
+
lines.push(` ⚠ ${d.toolName} — ${d.note}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
return lines.join("\n");
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=shadowReport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadowReport.js","sourceRoot":"","sources":["../../src/workers/shadowReport.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,oBAAoB,GAErB,MAAM,qBAAqB,CAAC;AAG7B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,IAAiB,EACjB,SAA2B,EAC3B,GAAsB,EACtB,OAII,EAAE;IAEN,MAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,OAAO,EAAE;QAC5C,GAAG;QACH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AAQ,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type GraduationConfig, type Outcome } from "./graduation.js";
|
|
2
|
+
import { type WorkerManifest } from "./worker.js";
|
|
3
|
+
import { type AuditEvent, type BoardRow, WorkerLevelStore } from "./workerLevelStore.js";
|
|
4
|
+
/**
|
|
5
|
+
* Replay an outcome sequence for a worker and capture the per-step dial
|
|
6
|
+
* trajectory. This is the cheapest test of the evidence-latency risk: it shows,
|
|
7
|
+
* deterministically, how many real observations (and how much wall-clock) a
|
|
8
|
+
* worker needs to climb each class — and how one catastrophic outcome demotes
|
|
9
|
+
* it in a single step. No model calls, no live gate — pure replay.
|
|
10
|
+
*/
|
|
11
|
+
export interface TrajectoryStep {
|
|
12
|
+
index: number;
|
|
13
|
+
at: number;
|
|
14
|
+
toolName: string;
|
|
15
|
+
good: boolean;
|
|
16
|
+
classKey: string;
|
|
17
|
+
level: number;
|
|
18
|
+
changed: "promote" | "demote" | null;
|
|
19
|
+
}
|
|
20
|
+
export interface ShadowRunResult {
|
|
21
|
+
workerId: string;
|
|
22
|
+
trajectory: TrajectoryStep[];
|
|
23
|
+
board: BoardRow[];
|
|
24
|
+
events: AuditEvent[];
|
|
25
|
+
store: WorkerLevelStore;
|
|
26
|
+
}
|
|
27
|
+
export declare function shadowRun(worker: WorkerManifest, outcomes: Outcome[], opts?: {
|
|
28
|
+
cfg?: GraduationConfig;
|
|
29
|
+
store?: WorkerLevelStore;
|
|
30
|
+
}): ShadowRunResult;
|
|
31
|
+
/** First trajectory step where `classKey` reached at least `level`. */
|
|
32
|
+
export declare function firstReached(result: ShadowRunResult, classKey: string, level: number): TrajectoryStep | undefined;
|
|
33
|
+
/** Build a steady cadence of same-tool outcomes spaced `intervalMs` apart. */
|
|
34
|
+
export declare function cadence(toolName: string, count: number, opts?: {
|
|
35
|
+
startAt?: number;
|
|
36
|
+
intervalMs?: number;
|
|
37
|
+
good?: boolean;
|
|
38
|
+
}): Outcome[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DEFAULT_GRADUATION_CONFIG, } from "./graduation.js";
|
|
2
|
+
import { priorFor } from "./worker.js";
|
|
3
|
+
import { WorkerLevelStore, } from "./workerLevelStore.js";
|
|
4
|
+
export function shadowRun(worker, outcomes, opts = {}) {
|
|
5
|
+
const store = opts.store ?? new WorkerLevelStore();
|
|
6
|
+
const cfg = opts.cfg ?? DEFAULT_GRADUATION_CONFIG;
|
|
7
|
+
const prior = priorFor(worker);
|
|
8
|
+
const trajectory = [];
|
|
9
|
+
outcomes.forEach((o, index) => {
|
|
10
|
+
const r = store.apply(worker.id, o, { prior, cfg });
|
|
11
|
+
trajectory.push({
|
|
12
|
+
index,
|
|
13
|
+
at: o.at,
|
|
14
|
+
toolName: o.toolName,
|
|
15
|
+
good: o.good,
|
|
16
|
+
classKey: r.classKey,
|
|
17
|
+
level: r.state.level,
|
|
18
|
+
changed: r.event?.type ?? null,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
workerId: worker.id,
|
|
23
|
+
trajectory,
|
|
24
|
+
board: store.board(worker.id),
|
|
25
|
+
events: store.events(worker.id),
|
|
26
|
+
store,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** First trajectory step where `classKey` reached at least `level`. */
|
|
30
|
+
export function firstReached(result, classKey, level) {
|
|
31
|
+
return result.trajectory.find((s) => s.classKey === classKey && s.level >= level);
|
|
32
|
+
}
|
|
33
|
+
/** Build a steady cadence of same-tool outcomes spaced `intervalMs` apart. */
|
|
34
|
+
export function cadence(toolName, count, opts = {}) {
|
|
35
|
+
const start = opts.startAt ?? 0;
|
|
36
|
+
const interval = opts.intervalMs ?? 6 * 60 * 60 * 1000; // 6h
|
|
37
|
+
const good = opts.good ?? true;
|
|
38
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
39
|
+
toolName,
|
|
40
|
+
good,
|
|
41
|
+
at: start + i * interval,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=shadowRun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadowRun.js","sourceRoot":"","sources":["../../src/workers/shadowRun.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,GAG1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAuB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAGL,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AA4B/B,MAAM,UAAU,SAAS,CACvB,MAAsB,EACtB,QAAmB,EACnB,OAA6D,EAAE;IAE/D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,gBAAgB,EAAE,CAAC;IACnD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,yBAAyB,CAAC;IAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAqB,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAC5B,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACpD,UAAU,CAAC,IAAI,CAAC;YACd,KAAK;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK;YACpB,OAAO,E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(the probability that an action of this class is "good") is a
|
|
5
|
+
* Beta(α, β) posterior. The discrete autonomy rung L0–L4 is a threshold
|
|
6
|
+
* crossing of the posterior's LOWER confidence bound, not its mean. Using the
|
|
7
|
+
* lower bound is what makes the ramp behave correctly:
|
|
8
|
+
* - cold-start floors automatically: a fresh/wide posterior has a low bound
|
|
9
|
+
* even if its mean is optimistic, so a worker (or a marketplace prior) can't
|
|
10
|
+
* start trusted — uncertainty must collapse on local evidence first;
|
|
11
|
+
* - climbing is slow: the bound only rises as the mean rises AND variance
|
|
12
|
+
* shrinks, i.e. with sustained evidence;
|
|
13
|
+
* - demotion is instant: one high-weight failure spikes β, the mean drops and
|
|
14
|
+
* the bound craters in a single step.
|
|
15
|
+
*
|
|
16
|
+
* Asymmetry ("slow up, instant down") is therefore information, not a tuned
|
|
17
|
+
* rule — it falls out of weighting failures by blast radius (see actionClass).
|
|
18
|
+
*/
|
|
19
|
+
export interface Posterior {
|
|
20
|
+
readonly alpha: number;
|
|
21
|
+
readonly beta: number;
|
|
22
|
+
}
|
|
23
|
+
/** Uniform prior — maximally uncertain, no shipped competence. */
|
|
24
|
+
export declare const DEFAULT_PRIOR: Posterior;
|
|
25
|
+
/**
|
|
26
|
+
* Build a prior from a competence claim: a mean reliability + a strength
|
|
27
|
+
* (pseudo-count). Low strength = wide uncertainty = the bound stays low until
|
|
28
|
+
* local evidence accumulates. This is how a marketplace worker ships
|
|
29
|
+
* competence (a mean) without shipping trust (the bound only tightens on the
|
|
30
|
+
* operator's own data). Strength is capped low on purpose.
|
|
31
|
+
*/
|
|
32
|
+
export declare function priorFromCompetence(mean: number, strength: number): Posterior;
|
|
33
|
+
export declare function posteriorMean(p: Posterior): number;
|
|
34
|
+
export declare function posteriorStddev(p: Posterior): number;
|
|
35
|
+
/** Lower confidence bound: mean − k·σ, clamped to [0, 1]. The level reads off
|
|
36
|
+
* THIS, not the mean. */
|
|
37
|
+
export declare function lowerConfidenceBound(p: Posterior, k?: number): number;
|
|
38
|
+
/** Apply one outcome. A good outcome adds to α, a bad one to β, scaled by the
|
|
39
|
+
* blast-weighted evidence weight from actionClass.outcomeWeight. */
|
|
40
|
+
export declare function applyOutcome(p: Posterior, good: boolean, weight: number): Posterior;
|
|
41
|
+
/** Total evidence accumulated relative to the prior (pseudo-observations). */
|
|
42
|
+
export declare function evidenceCount(p: Posterior, prior: Posterior): number;
|
|
43
|
+
export type TrustLevel = 0 | 1 | 2 | 3 | 4;
|
|
44
|
+
/** LCB → rung. Tunable; conservative by default. */
|
|
45
|
+
export declare const DEFAULT_THRESHOLDS: ReadonlyArray<{
|
|
46
|
+
min: number;
|
|
47
|
+
level: TrustLevel;
|
|
48
|
+
}>;
|
|
49
|
+
export interface LevelOpts {
|
|
50
|
+
k?: number;
|
|
51
|
+
/** Min evidence before a class may exceed L1 (novel-class floor). */
|
|
52
|
+
minEvidenceForGraduation?: number;
|
|
53
|
+
/** Rungs reachable for this class (irreversible classes omit L2/L3). */
|
|
54
|
+
reachable?: number[];
|
|
55
|
+
thresholds?: ReadonlyArray<{
|
|
56
|
+
min: number;
|
|
57
|
+
level: TrustLevel;
|
|
58
|
+
}>;
|
|
59
|
+
}
|
|
60
|
+
export interface LevelResult {
|
|
61
|
+
level: TrustLevel;
|
|
62
|
+
/** Level before the novel-floor + reachability clamps (for diagnostics). */
|
|
63
|
+
rawLevel: TrustLevel;
|
|
64
|
+
lcb: number;
|
|
65
|
+
mean: number;
|
|
66
|
+
evidence: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Map a posterior to a discrete rung, applying:
|
|
70
|
+
* 1. LCB → raw level via thresholds.
|
|
71
|
+
* 2. Novel-class floor: below the effective evidence minimum, cap at L1.
|
|
72
|
+
* "Effective evidence" = real observations + prior pseudo-count beyond the
|
|
73
|
+
* uniform baseline (prior.alpha + prior.beta − 2). A strong operator prior
|
|
74
|
+
* (strength 8 → contributes 6) reduces the real observations needed before
|
|
75
|
+
* graduation is permitted; the default uniform prior contributes 0 so
|
|
76
|
+
* existing behaviour is unchanged. No class can skip the floor entirely via
|
|
77
|
+
* prior alone — the prior's LCB is still too wide without real data.
|
|
78
|
+
* 3. Reachability clamp: drop to the highest reachable rung ≤ the computed one,
|
|
79
|
+
* so an irreversible class climbing through "would-be L2/L3" stays at L1
|
|
80
|
+
* until it actually clears the L4 bar.
|
|
81
|
+
*/
|
|
82
|
+
export declare function levelFromPosterior(p: Posterior, prior: Posterior, opts?: LevelOpts): LevelResult;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bayesian trust model for a single (worker × action-class) pair.
|
|
3
|
+
*
|
|
4
|
+
* Reliability `p` (the probability that an action of this class is "good") is a
|
|
5
|
+
* Beta(α, β) posterior. The discrete autonomy rung L0–L4 is a threshold
|
|
6
|
+
* crossing of the posterior's LOWER confidence bound, not its mean. Using the
|
|
7
|
+
* lower bound is what makes the ramp behave correctly:
|
|
8
|
+
* - cold-start floors automatically: a fresh/wide posterior has a low bound
|
|
9
|
+
* even if its mean is optimistic, so a worker (or a marketplace prior) can't
|
|
10
|
+
* start trusted — uncertainty must collapse on local evidence first;
|
|
11
|
+
* - climbing is slow: the bound only rises as the mean rises AND variance
|
|
12
|
+
* shrinks, i.e. with sustained evidence;
|
|
13
|
+
* - demotion is instant: one high-weight failure spikes β, the mean drops and
|
|
14
|
+
* the bound craters in a single step.
|
|
15
|
+
*
|
|
16
|
+
* Asymmetry ("slow up, instant down") is therefore information, not a tuned
|
|
17
|
+
* rule — it falls out of weighting failures by blast radius (see actionClass).
|
|
18
|
+
*/
|
|
19
|
+
/** Uniform prior — maximally uncertain, no shipped competence. */
|
|
20
|
+
export const DEFAULT_PRIOR = { alpha: 1, beta: 1 };
|
|
21
|
+
/**
|
|
22
|
+
* Build a prior from a competence claim: a mean reliability + a strength
|
|
23
|
+
* (pseudo-count). Low strength = wide uncertainty = the bound stays low until
|
|
24
|
+
* local evidence accumulates. This is how a marketplace worker ships
|
|
25
|
+
* competence (a mean) without shipping trust (the bound only tightens on the
|
|
26
|
+
* operator's own data). Strength is capped low on purpose.
|
|
27
|
+
*/
|
|
28
|
+
export function priorFromCompetence(mean, strength) {
|
|
29
|
+
const m = Math.min(0.99, Math.max(0.01, mean));
|
|
30
|
+
const s = Math.min(8, Math.max(0.5, strength));
|
|
31
|
+
return { alpha: m * s, beta: (1 - m) * s };
|
|
32
|
+
}
|
|
33
|
+
export function posteriorMean(p) {
|
|
34
|
+
return p.alpha / (p.alpha + p.beta);
|
|
35
|
+
}
|
|
36
|
+
export function posteriorStddev(p) {
|
|
37
|
+
const n = p.alpha + p.beta;
|
|
38
|
+
return Math.sqrt((p.alpha * p.beta) / (n * n * (n + 1)));
|
|
39
|
+
}
|
|
40
|
+
/** Lower confidence bound: mean − k·σ, clamped to [0, 1]. The level reads off
|
|
41
|
+
* THIS, not the mean. */
|
|
42
|
+
export function lowerConfidenceBound(p, k = 1.5) {
|
|
43
|
+
return Math.max(0, Math.min(1, posteriorMean(p) - k * posteriorStddev(p)));
|
|
44
|
+
}
|
|
45
|
+
/** Apply one outcome. A good outcome adds to α, a bad one to β, scaled by the
|
|
46
|
+
* blast-weighted evidence weight from actionClass.outcomeWeight. */
|
|
47
|
+
export function applyOutcome(p, good, weight) {
|
|
48
|
+
return good
|
|
49
|
+
? { alpha: p.alpha + weight, beta: p.beta }
|
|
50
|
+
: { alpha: p.alpha, beta: p.beta + weight };
|
|
51
|
+
}
|
|
52
|
+
/** Total evidence accumulated relative to the prior (pseudo-observations). */
|
|
53
|
+
export function evidenceCount(p, prior) {
|
|
54
|
+
return p.alpha + p.beta - (prior.alpha + prior.beta);
|
|
55
|
+
}
|
|
56
|
+
/** LCB → rung. Tunable; conservative by default. */
|
|
57
|
+
export const DEFAULT_THRESHOLDS = [
|
|
58
|
+
{ min: 0.95, level: 4 },
|
|
59
|
+
{ min: 0.85, level: 3 },
|
|
60
|
+
{ min: 0.7, level: 2 },
|
|
61
|
+
{ min: 0.5, level: 1 },
|
|
62
|
+
{ min: 0, level: 0 },
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Map a posterior to a discrete rung, applying:
|
|
66
|
+
* 1. LCB → raw level via thresholds.
|
|
67
|
+
* 2. Novel-class floor: below the effective evidence minimum, cap at L1.
|
|
68
|
+
* "Effective evidence" = real observations + prior pseudo-count beyond the
|
|
69
|
+
* uniform baseline (prior.alpha + prior.beta − 2). A strong operator prior
|
|
70
|
+
* (strength 8 → contributes 6) reduces the real observations needed before
|
|
71
|
+
* graduation is permitted; the default uniform prior contributes 0 so
|
|
72
|
+
* existing behaviour is unchanged. No class can skip the floor entirely via
|
|
73
|
+
* prior alone — the prior's LCB is still too wide without real data.
|
|
74
|
+
* 3. Reachability clamp: drop to the highest reachable rung ≤ the computed one,
|
|
75
|
+
* so an irreversible class climbing through "would-be L2/L3" stays at L1
|
|
76
|
+
* until it actually clears the L4 bar.
|
|
77
|
+
*/
|
|
78
|
+
export function levelFromPosterior(p, prior, opts = {}) {
|
|
79
|
+
const k = opts.k ?? 1.5;
|
|
80
|
+
const minEvidence = opts.minEvidenceForGraduation ?? 10;
|
|
81
|
+
const reachable = opts.reachable ?? [0, 1, 2, 3, 4];
|
|
82
|
+
const thresholds = opts.thresholds ?? DEFAULT_THRESHOLDS;
|
|
83
|
+
const lcb = lowerConfidenceBound(p, k);
|
|
84
|
+
const mean = posteriorMean(p);
|
|
85
|
+
const evidence = evidenceCount(p, prior);
|
|
86
|
+
const rawLevel = thresholds.find((t) => lcb >= t.min)?.level ?? 0;
|
|
87
|
+
let level = rawLevel;
|
|
88
|
+
// Novel-class floor: prior pseudo-count beyond the uniform baseline counts
|
|
89
|
+
// toward the evidence minimum, reducing cold-start latency for operator-
|
|
90
|
+
// configured workers without letting the prior alone bypass the floor.
|
|
91
|
+
const priorContribution = Math.max(0, prior.alpha + prior.beta - 2);
|
|
92
|
+
const effectiveEvidence = evidence + priorContribution;
|
|
93
|
+
if (effectiveEvidence < minEvidence && level > 1)
|
|
94
|
+
level = 1;
|
|
95
|
+
// Reachability clamp (highest reachable rung ≤ level).
|
|
96
|
+
const allowed = reachable.filter((r) => r <= level);
|
|
97
|
+
level = (allowed.length ? Math.max(...allowed) : 0);
|
|
98
|
+
return { level, rawLevel, lcb, mean, evidence };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=trustLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trustLevel.js","sourceRoot":"","sources":["../../src/workers/trustLevel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAOH,kEAAkE;AAClE,MAAM,CAAC,MAAM,aAAa,GAAc,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,QAAgB;IAChE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/C,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAY;IACxC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAY;IAC1C,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC;IAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG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AAI,KAAK,CAAC,CAAC;IACpD,KAAK,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAe,CAAC;IAElE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ActionClass } from "./actionClass.js";
|
|
2
|
+
import { type Posterior, type TrustLevel } from "./trustLevel.js";
|
|
3
|
+
export interface WorkerCompetence {
|
|
4
|
+
/** Claimed reliability mean (0–1) — a competence claim, not trust. */
|
|
5
|
+
mean: number;
|
|
6
|
+
/** Prior strength (pseudo-count); capped low so local evidence dominates. */
|
|
7
|
+
strength: number;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkerManifest {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
responsibilities: string[];
|
|
13
|
+
/** Recipe name that forms this worker's body (its triggers + steps). */
|
|
14
|
+
recipe?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Action-classes this worker is responsible for. Each pattern matches a
|
|
17
|
+
* class by its domain, or by an exact/prefix class-key match
|
|
18
|
+
* (`vcs-local` matches `vcs-local:*`; `fs-write:reversible:medium` is exact).
|
|
19
|
+
*/
|
|
20
|
+
owns: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Policy/regulatory cap on the max ramp level this worker may EVER reach,
|
|
23
|
+
* independent of earned track record — the schema encoding of the
|
|
24
|
+
* autonomy-tolerance axis. The dial still shows *earned* level; the gate
|
|
25
|
+
* operates at min(earned, ceiling). Note: ceiling=2 is PERMISSIVE for
|
|
26
|
+
* compensable classes (they auto-allow at L2), not conservative — use
|
|
27
|
+
* ceiling=1 to keep compensable actions gated on a new or restricted worker.
|
|
28
|
+
*/
|
|
29
|
+
autonomyCeiling: TrustLevel;
|
|
30
|
+
/** Optional shipped competence → the per-class prior. */
|
|
31
|
+
competence?: WorkerCompetence;
|
|
32
|
+
/** Free-form sector tag (drives default ceilings / reporting). */
|
|
33
|
+
sector?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class WorkerParseError extends Error {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
export declare function parseWorker(raw: unknown): WorkerManifest;
|
|
39
|
+
/** The per-class trust prior for a worker (its shipped competence, or uniform). */
|
|
40
|
+
export declare function priorFor(worker: WorkerManifest): Posterior;
|
|
41
|
+
/** Whether a worker is responsible for a given action-class. A pattern matches
|
|
42
|
+
* the class domain, an exact key, or a key prefix. Empty `owns` ⇒ owns nothing. */
|
|
43
|
+
export declare function ownsAction(worker: WorkerManifest, ac: ActionClass): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Ownership check against a raw class key (`domain:reversibility:blastTier`),
|
|
46
|
+
* for callers that have a board row's `classKey` but not a full ActionClass
|
|
47
|
+
* (e.g. the dial). Mirrors `ownsAction`: the domain is the key's first segment.
|
|
48
|
+
*/
|
|
49
|
+
export declare function ownsClassKey(worker: WorkerManifest, classKey: string): boolean;
|