open-multi-agent-kit 0.90.0 → 0.90.3
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/CHANGELOG.md +40 -0
- package/README.md +20 -31
- package/dist/cli/args.d.ts +0 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -7
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +41 -5
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bang-skill-invocation.d.ts +26 -0
- package/dist/core/bang-skill-invocation.d.ts.map +1 -0
- package/dist/core/bang-skill-invocation.js +59 -0
- package/dist/core/bang-skill-invocation.js.map +1 -0
- package/dist/core/compactor.d.ts.map +1 -1
- package/dist/core/compactor.js +0 -3
- package/dist/core/compactor.js.map +1 -1
- package/dist/core/context-budget-governor-v2.d.ts +2 -1
- package/dist/core/context-budget-governor-v2.d.ts.map +1 -1
- package/dist/core/context-budget-governor-v2.js +1 -0
- package/dist/core/context-budget-governor-v2.js.map +1 -1
- package/dist/core/context-budget-headroom-types.d.ts +8 -0
- package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-types.js.map +1 -1
- package/dist/core/context-budget-headroom.d.ts +1 -1
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +17 -4
- package/dist/core/context-budget-headroom.js.map +1 -1
- package/dist/core/context-budget-system-prompt.d.ts +2 -1
- package/dist/core/context-budget-system-prompt.d.ts.map +1 -1
- package/dist/core/context-budget-system-prompt.js +6 -1
- package/dist/core/context-budget-system-prompt.js.map +1 -1
- package/dist/core/context-budget-v2-cache-hash.d.ts +3 -0
- package/dist/core/context-budget-v2-cache-hash.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache-hash.js +16 -0
- package/dist/core/context-budget-v2-cache-hash.js.map +1 -0
- package/dist/core/context-budget-v2-cache-keys.d.ts +58 -0
- package/dist/core/context-budget-v2-cache-keys.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache-keys.js +128 -0
- package/dist/core/context-budget-v2-cache-keys.js.map +1 -0
- package/dist/core/context-budget-v2-cache-provider.d.ts +23 -0
- package/dist/core/context-budget-v2-cache-provider.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache-provider.js +29 -0
- package/dist/core/context-budget-v2-cache-provider.js.map +1 -0
- package/dist/core/context-budget-v2-cache-telemetry.d.ts +36 -0
- package/dist/core/context-budget-v2-cache-telemetry.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache-telemetry.js +64 -0
- package/dist/core/context-budget-v2-cache-telemetry.js.map +1 -0
- package/dist/core/context-budget-v2-cache-validation.d.ts +36 -0
- package/dist/core/context-budget-v2-cache-validation.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache-validation.js +98 -0
- package/dist/core/context-budget-v2-cache-validation.js.map +1 -0
- package/dist/core/context-budget-v2-cache.d.ts +36 -0
- package/dist/core/context-budget-v2-cache.d.ts.map +1 -0
- package/dist/core/context-budget-v2-cache.js +50 -0
- package/dist/core/context-budget-v2-cache.js.map +1 -0
- package/dist/core/context-budget-v2-plan-cache-keys.d.ts +16 -0
- package/dist/core/context-budget-v2-plan-cache-keys.d.ts.map +1 -0
- package/dist/core/context-budget-v2-plan-cache-keys.js +49 -0
- package/dist/core/context-budget-v2-plan-cache-keys.js.map +1 -0
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +55 -2
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-representation-cache.d.ts +27 -0
- package/dist/core/context-budget-v2-representation-cache.d.ts.map +1 -0
- package/dist/core/context-budget-v2-representation-cache.js +173 -0
- package/dist/core/context-budget-v2-representation-cache.js.map +1 -0
- package/dist/core/context-budget-v2-selection.d.ts +2 -0
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +12 -2
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +107 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- package/dist/core/headroom.d.ts.map +1 -1
- package/dist/core/headroom.js +0 -4
- package/dist/core/headroom.js.map +1 -1
- package/dist/core/hook-inventory.d.ts.map +1 -1
- package/dist/core/hook-inventory.js +6 -0
- package/dist/core/hook-inventory.js.map +1 -1
- package/dist/core/mcp-computer-use-presets.d.ts +64 -0
- package/dist/core/mcp-computer-use-presets.d.ts.map +1 -0
- package/dist/core/mcp-computer-use-presets.js +158 -0
- package/dist/core/mcp-computer-use-presets.js.map +1 -0
- package/dist/core/mcp-public-presets.d.ts +578 -0
- package/dist/core/mcp-public-presets.d.ts.map +1 -0
- package/dist/core/mcp-public-presets.js +647 -0
- package/dist/core/mcp-public-presets.js.map +1 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +1 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/pi-package-intake-candidates.d.ts +14 -1
- package/dist/core/pi-package-intake-candidates.d.ts.map +1 -1
- package/dist/core/pi-package-intake-candidates.js +182 -0
- package/dist/core/pi-package-intake-candidates.js.map +1 -1
- package/dist/core/pi-package-intake.d.ts +8 -1
- package/dist/core/pi-package-intake.d.ts.map +1 -1
- package/dist/core/pi-package-intake.js +14 -4
- package/dist/core/pi-package-intake.js.map +1 -1
- package/dist/core/reverse-skill.d.ts +2 -0
- package/dist/core/reverse-skill.d.ts.map +1 -0
- package/dist/core/reverse-skill.js +7 -0
- package/dist/core/reverse-skill.js.map +1 -0
- package/dist/core/settings-manager.d.ts +3 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts +2 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +58 -5
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrations.d.ts +19 -0
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +39 -15
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-box.d.ts +3 -3
- package/dist/modes/interactive/components/control-panel-box.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel-box.js +10 -10
- package/dist/modes/interactive/components/control-panel-box.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-gradient-motion.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel-gradient-motion.js +2 -1
- package/dist/modes/interactive/components/control-panel-gradient-motion.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-layout.d.ts +15 -1
- package/dist/modes/interactive/components/control-panel-layout.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel-layout.js +212 -68
- package/dist/modes/interactive/components/control-panel-layout.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-runtime-status.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel-runtime-status.js +10 -0
- package/dist/modes/interactive/components/control-panel-runtime-status.js.map +1 -1
- package/dist/modes/interactive/components/control-panel-sparkles.d.ts +27 -0
- package/dist/modes/interactive/components/control-panel-sparkles.d.ts.map +1 -0
- package/dist/modes/interactive/components/control-panel-sparkles.js +42 -0
- package/dist/modes/interactive/components/control-panel-sparkles.js.map +1 -0
- package/dist/modes/interactive/components/control-panel.d.ts +8 -0
- package/dist/modes/interactive/components/control-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/control-panel.js +40 -8
- package/dist/modes/interactive/components/control-panel.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +2 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +2 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +63 -14
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +2 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/docs/skills.md +8 -4
- package/docs/usage.md +4 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/preset.ts +2 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +27 -34
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAOpE,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { TokenOptimizerRuntimeStatus } from \"./token-optimizer.ts\";\n\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headroom.d.ts","sourceRoot":"","sources":["../../src/core/headroom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"headroom.d.ts","sourceRoot":"","sources":["../../src/core/headroom.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;CAChE;AAED,MAAM,WAAW,kBAAkB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,YAAY,GAAG,QAAQ,GAAG,YAAY,CAAC;IAC9C,iBAAiB,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,eAAgB,SAAQ,YAAY;IAChD,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAO;IAEzB,MAAM,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAOvC;IAED,OAAO,IAAI,kBAAkB,CAoB5B;IAED,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CA6B5E;CACD;AAED,qBAAa,uBAAwB,SAAQ,YAAY;IACxD,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAY,SAAS,SAAQ,EAG5B;IAED,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,OAAO,CAAA;KAAE,CAU5E;CACD;AAED,qBAAa,eAAgB,SAAQ,YAAY;IAChD,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAY,SAAS,SAAQ,EAK5B;IAED,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,gBAAgB,SAAI,EAAE,cAAc,SAAI,GAAG,gBAAgB,CAyBtF;IAED,OAAO,IAAI,kBAAkB,CAE5B;IAED,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,OAAO,CAAA;KAAE,CAEjF;CACD;AAED,eAAe,eAAe,CAAC","sourcesContent":["// OMK v6.2 — Headroom Manager (TypeScript)\n// ==================================================================\n// packages/coding-agent/src/core/headroom.ts\n//\n// STATUS: compatibility utility.\n// This file is preserved for legacy extension/API consumers and regression tests.\n//\n// ACTUAL HEADROOM / TOKEN BUDGET SYSTEM:\n// - context-budget-compressors.ts → context budget compression with adapters\n// - context-budget-token-counter.ts → token counting for budget decisions\n// - compaction/compaction.ts getCompactionHeadroomThreshold() → headroom threshold\n// - compaction/compaction.ts shouldCompact() → triggers compaction when headroom low\n//\n// Keep this utility deterministic and aligned with the active context budget policy.\n\nimport { EventEmitter } from \"events\";\n\nexport interface HeadroomSnapshot {\n\ttimestamp: number;\n\tpromptTokens: number;\n\ttoolOutputTokens: number;\n\tresponseTokens: number;\n\ttotalTokens: number;\n\theadroomRemaining: number;\n\tstatus: \"idle\" | \"active\" | \"stressed\" | \"critical\" | \"blocked\";\n}\n\nexport interface HeadroomPrediction {\n\tpredictedTokens: number;\n\tconfidence: number;\n\ttrend: \"increasing\" | \"stable\" | \"decreasing\";\n\trecommendedAction: string;\n}\n\nexport class HeadroomMonitor extends EventEmitter {\n\tprivate history: HeadroomSnapshot[] = [];\n\tprivate maxHistory = 100;\n\n\trecord(snapshot: HeadroomSnapshot): void {\n\t\tconst sanitized = sanitizeSnapshot(snapshot);\n\t\tthis.history.push(sanitized);\n\t\tif (this.history.length > this.maxHistory) {\n\t\t\tthis.history = this.history.slice(-this.maxHistory);\n\t\t}\n\t\tthis.emit(\"snapshot\", sanitized);\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\tif (this.history.length < 3) {\n\t\t\treturn { predictedTokens: 0, confidence: 0, trend: \"stable\", recommendedAction: \"collect more data\" };\n\t\t}\n\n\t\tconst recent = this.history.slice(-10);\n\t\tconst first = recent[0].totalTokens;\n\t\tconst last = recent[recent.length - 1].totalTokens;\n\t\tconst delta = last - first;\n\t\tconst slope = delta / Math.max(recent.length - 1, 1);\n\t\tconst trend = Math.abs(delta) <= Math.max(1, last * 0.02) ? \"stable\" : delta > 0 ? \"increasing\" : \"decreasing\";\n\t\tconst projectedTokens = trend === \"increasing\" ? last + Math.max(1, slope) : Math.max(0, last + slope);\n\t\tconst confidence = Math.min(0.95, 0.45 + recent.length * 0.05);\n\n\t\treturn {\n\t\t\tpredictedTokens: Math.round(projectedTokens),\n\t\t\tconfidence,\n\t\t\ttrend,\n\t\t\trecommendedAction: trend === \"increasing\" ? \"compress context\" : \"maintain\",\n\t\t};\n\t}\n\n\tgetStatus(totalTokens: number, maxTokens: number): HeadroomSnapshot[\"status\"] {\n\t\tconst normalizedTotalTokens = normalizeTokenInput(totalTokens);\n\t\tconst normalizedMaxTokens = normalizeTokenLimit(maxTokens);\n\t\tif (normalizedMaxTokens === 0) {\n\t\t\treturn normalizedTotalTokens === 0 ? \"idle\" : \"blocked\";\n\t\t}\n\n\t\tconst ratio = normalizedTotalTokens / normalizedMaxTokens;\n\t\tlet status: HeadroomSnapshot[\"status\"];\n\t\tif (ratio < 0.4) {\n\t\t\tstatus = \"idle\";\n\t\t} else if (ratio < 0.7) {\n\t\t\tstatus = \"active\";\n\t\t} else if (ratio < 0.8) {\n\t\t\tstatus = \"stressed\";\n\t\t} else if (ratio < 0.9) {\n\t\t\tstatus = \"critical\";\n\t\t} else {\n\t\t\tstatus = \"blocked\";\n\t\t}\n\n\t\tconst previous = this.history.at(-1)?.status;\n\t\tif (previous === \"critical\" && status === \"stressed\" && ratio >= 0.75) {\n\t\t\treturn \"critical\";\n\t\t}\n\t\tif (previous === \"blocked\" && status !== \"blocked\" && ratio >= 0.85) {\n\t\t\treturn \"blocked\";\n\t\t}\n\t\treturn status;\n\t}\n}\n\nexport class DynamicContextAllocator extends EventEmitter {\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t}\n\n\tallocate(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\tif (this.maxTokens === 0) {\n\t\t\treturn { maxTokens: 0, canAddAgents: false };\n\t\t}\n\t\tconst ratio = normalizeTokenInput(currentTokens) / this.maxTokens;\n\t\tif (ratio < 0.4) return { maxTokens: this.maxTokens, canAddAgents: true };\n\t\tif (ratio < 0.7) return { maxTokens: this.maxTokens * 0.9, canAddAgents: true };\n\t\tif (ratio < 0.8) return { maxTokens: this.maxTokens * 0.75, canAddAgents: false };\n\t\tif (ratio < 0.9) return { maxTokens: this.maxTokens * 0.5, canAddAgents: false };\n\t\treturn { maxTokens: 0, canAddAgents: false };\n\t}\n}\n\nexport class HeadroomManager extends EventEmitter {\n\tprivate monitor: HeadroomMonitor;\n\tprivate allocator: DynamicContextAllocator;\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t\tthis.monitor = new HeadroomMonitor();\n\t\tthis.allocator = new DynamicContextAllocator(this.maxTokens);\n\t}\n\n\tcheck(promptTokens: number, toolOutputTokens = 0, responseTokens = 0): HeadroomSnapshot {\n\t\tconst normalizedPromptTokens = normalizeTokenInput(promptTokens);\n\t\tconst normalizedToolOutputTokens = normalizeTokenInput(toolOutputTokens);\n\t\tconst normalizedResponseTokens = normalizeTokenInput(responseTokens);\n\t\tconst totalTokens = normalizedPromptTokens + normalizedToolOutputTokens + normalizedResponseTokens;\n\t\tconst status = this.monitor.getStatus(totalTokens, this.maxTokens);\n\t\tthis.allocator.allocate(totalTokens);\n\n\t\tconst snapshot: HeadroomSnapshot = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tpromptTokens: normalizedPromptTokens,\n\t\t\ttoolOutputTokens: normalizedToolOutputTokens,\n\t\t\tresponseTokens: normalizedResponseTokens,\n\t\t\ttotalTokens,\n\t\t\theadroomRemaining: this.maxTokens - totalTokens,\n\t\t\tstatus,\n\t\t};\n\n\t\tthis.monitor.record(snapshot);\n\n\t\tif (status === \"critical\" || status === \"blocked\") {\n\t\t\tthis.emit(\"warning\", { status, message: `Headroom ${status}: ${totalTokens}/${this.maxTokens} tokens` });\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\treturn this.monitor.predict();\n\t}\n\n\tgetAllocation(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\treturn this.allocator.allocate(currentTokens);\n\t}\n}\n\nexport default HeadroomManager;\n\nfunction sanitizeSnapshot(snapshot: HeadroomSnapshot): HeadroomSnapshot {\n\treturn {\n\t\ttimestamp: Number.isFinite(snapshot.timestamp) ? Math.floor(snapshot.timestamp) : 0,\n\t\tpromptTokens: normalizeTokenInput(snapshot.promptTokens),\n\t\ttoolOutputTokens: normalizeTokenInput(snapshot.toolOutputTokens),\n\t\tresponseTokens: normalizeTokenInput(snapshot.responseTokens),\n\t\ttotalTokens: normalizeTokenInput(snapshot.totalTokens),\n\t\theadroomRemaining: normalizeFiniteInteger(snapshot.headroomRemaining),\n\t\tstatus: snapshot.status,\n\t};\n}\n\nfunction normalizeTokenLimit(value: number): number {\n\treturn normalizeTokenInput(value);\n}\n\nfunction normalizeTokenInput(value: number): number {\n\tif (!Number.isFinite(value) || value < 0) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n\nfunction normalizeFiniteInteger(value: number): number {\n\tif (!Number.isFinite(value)) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n"]}
|
package/dist/core/headroom.js
CHANGED
|
@@ -6,15 +6,11 @@
|
|
|
6
6
|
// This file is preserved for legacy extension/API consumers and regression tests.
|
|
7
7
|
//
|
|
8
8
|
// ACTUAL HEADROOM / TOKEN BUDGET SYSTEM:
|
|
9
|
-
// - types/jailbreak.ts → defines HeadroomSnapshot, HeadroomPrediction (different shape)
|
|
10
9
|
// - context-budget-compressors.ts → context budget compression with adapters
|
|
11
10
|
// - context-budget-token-counter.ts → token counting for budget decisions
|
|
12
11
|
// - compaction/compaction.ts getCompactionHeadroomThreshold() → headroom threshold
|
|
13
12
|
// - compaction/compaction.ts shouldCompact() → triggers compaction when headroom low
|
|
14
13
|
//
|
|
15
|
-
// NOTE: types/jailbreak.ts defines similar types (HeadroomSnapshot, HeadroomPrediction)
|
|
16
|
-
// but with different field structures. Both are distinct from this file's types.
|
|
17
|
-
//
|
|
18
14
|
// Keep this utility deterministic and aligned with the active context budget policy.
|
|
19
15
|
import { EventEmitter } from "events";
|
|
20
16
|
export class HeadroomMonitor extends EventEmitter {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headroom.js","sourceRoot":"","sources":["../../src/core/headroom.ts"],"names":[],"mappings":"AAAA,6CAA2C;AAC3C,qEAAqE;AACrE,6CAA6C;AAC7C,EAAE;AACF,iCAAiC;AACjC,kFAAkF;AAClF,EAAE;AACF,yCAAyC;AACzC,4FAA0F;AAC1F,iFAA+E;AAC/E,8EAA4E;AAC5E,uFAAqF;AACrF,yFAAuF;AACvF,EAAE;AACF,wFAAwF;AACxF,iFAAiF;AACjF,EAAE;AACF,qFAAqF;AAErF,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAmBtC,MAAM,OAAO,eAAgB,SAAQ,YAAY;IACxC,OAAO,GAAuB,EAAE,CAAC;IACj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CAAC,QAAQ,CAAC,iBAAiB,CAAC;QACrE,MAAM,EAAE,QAAQ,CAAC,MAAM;KACvB,CAAC;AAAA,CACF;AAED,SAAS,mBAAmB,CAAC,KAAa,EAAU;IACnD,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAAA,CAClC;AAED,SAAS,mBAAmB,CAAC,KAAa,EAAU;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAAA,CACzB;AAED,SAAS,sBAAsB,CAAC,KAAa,EAAU;IACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAAA,CACzB","sourcesContent":["// OMK v6.2 — Headroom Manager (TypeScript)\n// ==================================================================\n// packages/coding-agent/src/core/headroom.ts\n//\n// STATUS: compatibility utility.\n// This file is preserved for legacy extension/API consumers and regression tests.\n//\n// ACTUAL HEADROOM / TOKEN BUDGET SYSTEM:\n// - types/jailbreak.ts → defines HeadroomSnapshot, HeadroomPrediction (different shape)\n// - context-budget-compressors.ts → context budget compression with adapters\n// - context-budget-token-counter.ts → token counting for budget decisions\n// - compaction/compaction.ts getCompactionHeadroomThreshold() → headroom threshold\n// - compaction/compaction.ts shouldCompact() → triggers compaction when headroom low\n//\n// NOTE: types/jailbreak.ts defines similar types (HeadroomSnapshot, HeadroomPrediction)\n// but with different field structures. Both are distinct from this file's types.\n//\n// Keep this utility deterministic and aligned with the active context budget policy.\n\nimport { EventEmitter } from \"events\";\n\nexport interface HeadroomSnapshot {\n\ttimestamp: number;\n\tpromptTokens: number;\n\ttoolOutputTokens: number;\n\tresponseTokens: number;\n\ttotalTokens: number;\n\theadroomRemaining: number;\n\tstatus: \"idle\" | \"active\" | \"stressed\" | \"critical\" | \"blocked\";\n}\n\nexport interface HeadroomPrediction {\n\tpredictedTokens: number;\n\tconfidence: number;\n\ttrend: \"increasing\" | \"stable\" | \"decreasing\";\n\trecommendedAction: string;\n}\n\nexport class HeadroomMonitor extends EventEmitter {\n\tprivate history: HeadroomSnapshot[] = [];\n\tprivate maxHistory = 100;\n\n\trecord(snapshot: HeadroomSnapshot): void {\n\t\tconst sanitized = sanitizeSnapshot(snapshot);\n\t\tthis.history.push(sanitized);\n\t\tif (this.history.length > this.maxHistory) {\n\t\t\tthis.history = this.history.slice(-this.maxHistory);\n\t\t}\n\t\tthis.emit(\"snapshot\", sanitized);\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\tif (this.history.length < 3) {\n\t\t\treturn { predictedTokens: 0, confidence: 0, trend: \"stable\", recommendedAction: \"collect more data\" };\n\t\t}\n\n\t\tconst recent = this.history.slice(-10);\n\t\tconst first = recent[0].totalTokens;\n\t\tconst last = recent[recent.length - 1].totalTokens;\n\t\tconst delta = last - first;\n\t\tconst slope = delta / Math.max(recent.length - 1, 1);\n\t\tconst trend = Math.abs(delta) <= Math.max(1, last * 0.02) ? \"stable\" : delta > 0 ? \"increasing\" : \"decreasing\";\n\t\tconst projectedTokens = trend === \"increasing\" ? last + Math.max(1, slope) : Math.max(0, last + slope);\n\t\tconst confidence = Math.min(0.95, 0.45 + recent.length * 0.05);\n\n\t\treturn {\n\t\t\tpredictedTokens: Math.round(projectedTokens),\n\t\t\tconfidence,\n\t\t\ttrend,\n\t\t\trecommendedAction: trend === \"increasing\" ? \"compress context\" : \"maintain\",\n\t\t};\n\t}\n\n\tgetStatus(totalTokens: number, maxTokens: number): HeadroomSnapshot[\"status\"] {\n\t\tconst normalizedTotalTokens = normalizeTokenInput(totalTokens);\n\t\tconst normalizedMaxTokens = normalizeTokenLimit(maxTokens);\n\t\tif (normalizedMaxTokens === 0) {\n\t\t\treturn normalizedTotalTokens === 0 ? \"idle\" : \"blocked\";\n\t\t}\n\n\t\tconst ratio = normalizedTotalTokens / normalizedMaxTokens;\n\t\tlet status: HeadroomSnapshot[\"status\"];\n\t\tif (ratio < 0.4) {\n\t\t\tstatus = \"idle\";\n\t\t} else if (ratio < 0.7) {\n\t\t\tstatus = \"active\";\n\t\t} else if (ratio < 0.8) {\n\t\t\tstatus = \"stressed\";\n\t\t} else if (ratio < 0.9) {\n\t\t\tstatus = \"critical\";\n\t\t} else {\n\t\t\tstatus = \"blocked\";\n\t\t}\n\n\t\tconst previous = this.history.at(-1)?.status;\n\t\tif (previous === \"critical\" && status === \"stressed\" && ratio >= 0.75) {\n\t\t\treturn \"critical\";\n\t\t}\n\t\tif (previous === \"blocked\" && status !== \"blocked\" && ratio >= 0.85) {\n\t\t\treturn \"blocked\";\n\t\t}\n\t\treturn status;\n\t}\n}\n\nexport class DynamicContextAllocator extends EventEmitter {\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t}\n\n\tallocate(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\tif (this.maxTokens === 0) {\n\t\t\treturn { maxTokens: 0, canAddAgents: false };\n\t\t}\n\t\tconst ratio = normalizeTokenInput(currentTokens) / this.maxTokens;\n\t\tif (ratio < 0.4) return { maxTokens: this.maxTokens, canAddAgents: true };\n\t\tif (ratio < 0.7) return { maxTokens: this.maxTokens * 0.9, canAddAgents: true };\n\t\tif (ratio < 0.8) return { maxTokens: this.maxTokens * 0.75, canAddAgents: false };\n\t\tif (ratio < 0.9) return { maxTokens: this.maxTokens * 0.5, canAddAgents: false };\n\t\treturn { maxTokens: 0, canAddAgents: false };\n\t}\n}\n\nexport class HeadroomManager extends EventEmitter {\n\tprivate monitor: HeadroomMonitor;\n\tprivate allocator: DynamicContextAllocator;\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t\tthis.monitor = new HeadroomMonitor();\n\t\tthis.allocator = new DynamicContextAllocator(this.maxTokens);\n\t}\n\n\tcheck(promptTokens: number, toolOutputTokens = 0, responseTokens = 0): HeadroomSnapshot {\n\t\tconst normalizedPromptTokens = normalizeTokenInput(promptTokens);\n\t\tconst normalizedToolOutputTokens = normalizeTokenInput(toolOutputTokens);\n\t\tconst normalizedResponseTokens = normalizeTokenInput(responseTokens);\n\t\tconst totalTokens = normalizedPromptTokens + normalizedToolOutputTokens + normalizedResponseTokens;\n\t\tconst status = this.monitor.getStatus(totalTokens, this.maxTokens);\n\t\tthis.allocator.allocate(totalTokens);\n\n\t\tconst snapshot: HeadroomSnapshot = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tpromptTokens: normalizedPromptTokens,\n\t\t\ttoolOutputTokens: normalizedToolOutputTokens,\n\t\t\tresponseTokens: normalizedResponseTokens,\n\t\t\ttotalTokens,\n\t\t\theadroomRemaining: this.maxTokens - totalTokens,\n\t\t\tstatus,\n\t\t};\n\n\t\tthis.monitor.record(snapshot);\n\n\t\tif (status === \"critical\" || status === \"blocked\") {\n\t\t\tthis.emit(\"warning\", { status, message: `Headroom ${status}: ${totalTokens}/${this.maxTokens} tokens` });\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\treturn this.monitor.predict();\n\t}\n\n\tgetAllocation(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\treturn this.allocator.allocate(currentTokens);\n\t}\n}\n\nexport default HeadroomManager;\n\nfunction sanitizeSnapshot(snapshot: HeadroomSnapshot): HeadroomSnapshot {\n\treturn {\n\t\ttimestamp: Number.isFinite(snapshot.timestamp) ? Math.floor(snapshot.timestamp) : 0,\n\t\tpromptTokens: normalizeTokenInput(snapshot.promptTokens),\n\t\ttoolOutputTokens: normalizeTokenInput(snapshot.toolOutputTokens),\n\t\tresponseTokens: normalizeTokenInput(snapshot.responseTokens),\n\t\ttotalTokens: normalizeTokenInput(snapshot.totalTokens),\n\t\theadroomRemaining: normalizeFiniteInteger(snapshot.headroomRemaining),\n\t\tstatus: snapshot.status,\n\t};\n}\n\nfunction normalizeTokenLimit(value: number): number {\n\treturn normalizeTokenInput(value);\n}\n\nfunction normalizeTokenInput(value: number): number {\n\tif (!Number.isFinite(value) || value < 0) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n\nfunction normalizeFiniteInteger(value: number): number {\n\tif (!Number.isFinite(value)) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"headroom.js","sourceRoot":"","sources":["../../src/core/headroom.ts"],"names":[],"mappings":"AAAA,6CAA2C;AAC3C,qEAAqE;AACrE,6CAA6C;AAC7C,EAAE;AACF,iCAAiC;AACjC,kFAAkF;AAClF,EAAE;AACF,yCAAyC;AACzC,iFAA+E;AAC/E,8EAA4E;AAC5E,uFAAqF;AACrF,yFAAuF;AACvF,EAAE;AACF,qFAAqF;AAErF,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAmBtC,MAAM,OAAO,eAAgB,SAAQ,YAAY;IACxC,OAAO,GAAuB,EAAE,CAAC;IACjC,UAAU,GAAG,GAAG,CAAC;IAEzB,MAAM,CAAC,QAA0B,EAAQ;QACxC,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAAA,CACjC;IA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,EAAU;IACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAAA,CACzB","sourcesContent":["// OMK v6.2 — Headroom Manager (TypeScript)\n// ==================================================================\n// packages/coding-agent/src/core/headroom.ts\n//\n// STATUS: compatibility utility.\n// This file is preserved for legacy extension/API consumers and regression tests.\n//\n// ACTUAL HEADROOM / TOKEN BUDGET SYSTEM:\n// - context-budget-compressors.ts → context budget compression with adapters\n// - context-budget-token-counter.ts → token counting for budget decisions\n// - compaction/compaction.ts getCompactionHeadroomThreshold() → headroom threshold\n// - compaction/compaction.ts shouldCompact() → triggers compaction when headroom low\n//\n// Keep this utility deterministic and aligned with the active context budget policy.\n\nimport { EventEmitter } from \"events\";\n\nexport interface HeadroomSnapshot {\n\ttimestamp: number;\n\tpromptTokens: number;\n\ttoolOutputTokens: number;\n\tresponseTokens: number;\n\ttotalTokens: number;\n\theadroomRemaining: number;\n\tstatus: \"idle\" | \"active\" | \"stressed\" | \"critical\" | \"blocked\";\n}\n\nexport interface HeadroomPrediction {\n\tpredictedTokens: number;\n\tconfidence: number;\n\ttrend: \"increasing\" | \"stable\" | \"decreasing\";\n\trecommendedAction: string;\n}\n\nexport class HeadroomMonitor extends EventEmitter {\n\tprivate history: HeadroomSnapshot[] = [];\n\tprivate maxHistory = 100;\n\n\trecord(snapshot: HeadroomSnapshot): void {\n\t\tconst sanitized = sanitizeSnapshot(snapshot);\n\t\tthis.history.push(sanitized);\n\t\tif (this.history.length > this.maxHistory) {\n\t\t\tthis.history = this.history.slice(-this.maxHistory);\n\t\t}\n\t\tthis.emit(\"snapshot\", sanitized);\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\tif (this.history.length < 3) {\n\t\t\treturn { predictedTokens: 0, confidence: 0, trend: \"stable\", recommendedAction: \"collect more data\" };\n\t\t}\n\n\t\tconst recent = this.history.slice(-10);\n\t\tconst first = recent[0].totalTokens;\n\t\tconst last = recent[recent.length - 1].totalTokens;\n\t\tconst delta = last - first;\n\t\tconst slope = delta / Math.max(recent.length - 1, 1);\n\t\tconst trend = Math.abs(delta) <= Math.max(1, last * 0.02) ? \"stable\" : delta > 0 ? \"increasing\" : \"decreasing\";\n\t\tconst projectedTokens = trend === \"increasing\" ? last + Math.max(1, slope) : Math.max(0, last + slope);\n\t\tconst confidence = Math.min(0.95, 0.45 + recent.length * 0.05);\n\n\t\treturn {\n\t\t\tpredictedTokens: Math.round(projectedTokens),\n\t\t\tconfidence,\n\t\t\ttrend,\n\t\t\trecommendedAction: trend === \"increasing\" ? \"compress context\" : \"maintain\",\n\t\t};\n\t}\n\n\tgetStatus(totalTokens: number, maxTokens: number): HeadroomSnapshot[\"status\"] {\n\t\tconst normalizedTotalTokens = normalizeTokenInput(totalTokens);\n\t\tconst normalizedMaxTokens = normalizeTokenLimit(maxTokens);\n\t\tif (normalizedMaxTokens === 0) {\n\t\t\treturn normalizedTotalTokens === 0 ? \"idle\" : \"blocked\";\n\t\t}\n\n\t\tconst ratio = normalizedTotalTokens / normalizedMaxTokens;\n\t\tlet status: HeadroomSnapshot[\"status\"];\n\t\tif (ratio < 0.4) {\n\t\t\tstatus = \"idle\";\n\t\t} else if (ratio < 0.7) {\n\t\t\tstatus = \"active\";\n\t\t} else if (ratio < 0.8) {\n\t\t\tstatus = \"stressed\";\n\t\t} else if (ratio < 0.9) {\n\t\t\tstatus = \"critical\";\n\t\t} else {\n\t\t\tstatus = \"blocked\";\n\t\t}\n\n\t\tconst previous = this.history.at(-1)?.status;\n\t\tif (previous === \"critical\" && status === \"stressed\" && ratio >= 0.75) {\n\t\t\treturn \"critical\";\n\t\t}\n\t\tif (previous === \"blocked\" && status !== \"blocked\" && ratio >= 0.85) {\n\t\t\treturn \"blocked\";\n\t\t}\n\t\treturn status;\n\t}\n}\n\nexport class DynamicContextAllocator extends EventEmitter {\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t}\n\n\tallocate(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\tif (this.maxTokens === 0) {\n\t\t\treturn { maxTokens: 0, canAddAgents: false };\n\t\t}\n\t\tconst ratio = normalizeTokenInput(currentTokens) / this.maxTokens;\n\t\tif (ratio < 0.4) return { maxTokens: this.maxTokens, canAddAgents: true };\n\t\tif (ratio < 0.7) return { maxTokens: this.maxTokens * 0.9, canAddAgents: true };\n\t\tif (ratio < 0.8) return { maxTokens: this.maxTokens * 0.75, canAddAgents: false };\n\t\tif (ratio < 0.9) return { maxTokens: this.maxTokens * 0.5, canAddAgents: false };\n\t\treturn { maxTokens: 0, canAddAgents: false };\n\t}\n}\n\nexport class HeadroomManager extends EventEmitter {\n\tprivate monitor: HeadroomMonitor;\n\tprivate allocator: DynamicContextAllocator;\n\tprivate maxTokens: number;\n\n\tconstructor(maxTokens = 15000) {\n\t\tsuper();\n\t\tthis.maxTokens = normalizeTokenLimit(maxTokens);\n\t\tthis.monitor = new HeadroomMonitor();\n\t\tthis.allocator = new DynamicContextAllocator(this.maxTokens);\n\t}\n\n\tcheck(promptTokens: number, toolOutputTokens = 0, responseTokens = 0): HeadroomSnapshot {\n\t\tconst normalizedPromptTokens = normalizeTokenInput(promptTokens);\n\t\tconst normalizedToolOutputTokens = normalizeTokenInput(toolOutputTokens);\n\t\tconst normalizedResponseTokens = normalizeTokenInput(responseTokens);\n\t\tconst totalTokens = normalizedPromptTokens + normalizedToolOutputTokens + normalizedResponseTokens;\n\t\tconst status = this.monitor.getStatus(totalTokens, this.maxTokens);\n\t\tthis.allocator.allocate(totalTokens);\n\n\t\tconst snapshot: HeadroomSnapshot = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tpromptTokens: normalizedPromptTokens,\n\t\t\ttoolOutputTokens: normalizedToolOutputTokens,\n\t\t\tresponseTokens: normalizedResponseTokens,\n\t\t\ttotalTokens,\n\t\t\theadroomRemaining: this.maxTokens - totalTokens,\n\t\t\tstatus,\n\t\t};\n\n\t\tthis.monitor.record(snapshot);\n\n\t\tif (status === \"critical\" || status === \"blocked\") {\n\t\t\tthis.emit(\"warning\", { status, message: `Headroom ${status}: ${totalTokens}/${this.maxTokens} tokens` });\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\tpredict(): HeadroomPrediction {\n\t\treturn this.monitor.predict();\n\t}\n\n\tgetAllocation(currentTokens: number): { maxTokens: number; canAddAgents: boolean } {\n\t\treturn this.allocator.allocate(currentTokens);\n\t}\n}\n\nexport default HeadroomManager;\n\nfunction sanitizeSnapshot(snapshot: HeadroomSnapshot): HeadroomSnapshot {\n\treturn {\n\t\ttimestamp: Number.isFinite(snapshot.timestamp) ? Math.floor(snapshot.timestamp) : 0,\n\t\tpromptTokens: normalizeTokenInput(snapshot.promptTokens),\n\t\ttoolOutputTokens: normalizeTokenInput(snapshot.toolOutputTokens),\n\t\tresponseTokens: normalizeTokenInput(snapshot.responseTokens),\n\t\ttotalTokens: normalizeTokenInput(snapshot.totalTokens),\n\t\theadroomRemaining: normalizeFiniteInteger(snapshot.headroomRemaining),\n\t\tstatus: snapshot.status,\n\t};\n}\n\nfunction normalizeTokenLimit(value: number): number {\n\treturn normalizeTokenInput(value);\n}\n\nfunction normalizeTokenInput(value: number): number {\n\tif (!Number.isFinite(value) || value < 0) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n\nfunction normalizeFiniteInteger(value: number): number {\n\tif (!Number.isFinite(value)) {\n\t\treturn 0;\n\t}\n\treturn Math.floor(value);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-inventory.d.ts","sourceRoot":"","sources":["../../src/core/hook-inventory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,kBAAkB,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;CACjC;AAMD,eAAO,MAAM,aAAa,EAAE,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"hook-inventory.d.ts","sourceRoot":"","sources":["../../src/core/hook-inventory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,kBAAkB,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;CACjC;AAMD,eAAO,MAAM,aAAa,EAAE,SAAS,cAAc,EA+ElD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,CAsBlE","sourcesContent":["/**\n * Minimal hook inventory for the loadout runtime.\n *\n * The external harness resolves `scriptPath` to an actual shell script.\n * This module provides canonical names plus safe policy metadata so the\n * loadout layer can validate selectors without executing hooks.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { HookPolicyMetadata } from \"./hooks/index.ts\";\nimport { DEFAULT_HOOK_POLICY, sanitizeHookPolicy } from \"./hooks/index.ts\";\n\nexport interface HookDescriptor {\n\tname: string;\n\tscriptPath?: string;\n\tbuiltin: boolean;\n\tpolicy: HookPolicyMetadata;\n}\n\nexport interface HookInventory {\n\thooks: readonly HookDescriptor[];\n}\n\nfunction builtinHook(name: string, policy: HookPolicyMetadata): HookDescriptor {\n\treturn { name, builtin: true, policy: sanitizeHookPolicy(policy) };\n}\n\nexport const BUILTIN_HOOKS: readonly HookDescriptor[] = [\n\tbuiltinHook(\"pre-shell-guard\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 3_000,\n\t}),\n\tbuiltinHook(\"protect-secrets\", {\n\t\tstages: [\"tool_call\", \"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"session-context\", {\n\t\tstages: [\"session_start\"],\n\t\teffects: [\"mutator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"precompact-checkpoint\", {\n\t\tstages: [\"pre_compact\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"typecheck-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"stop-verify\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"subagent-stop-audit\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"npm-audit-summary\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"notify-sound-on-stop\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"bounded-evidence\", {\n\t\tstages: [\"tool_result\", \"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"document-artifact-guard\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"component-spec-before-build\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"visual-diff-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n];\n\n/**\n * Load the hook inventory. Builtin hooks are always present; if an agent\n * directory is provided and its `hooks` subdirectory exists, any shell scripts\n * discovered there are appended as non-builtin descriptors.\n */\nexport function loadHookInventory(agentDir?: string): HookInventory {\n\tconst hooks: HookDescriptor[] = [...BUILTIN_HOOKS];\n\tif (agentDir) {\n\t\ttry {\n\t\t\tconst hooksDir = path.join(agentDir, \"hooks\");\n\t\t\tconst entries = fs.readdirSync(hooksDir).sort();\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (!entry.endsWith(\".sh\")) continue;\n\t\t\t\tconst name = entry.slice(0, -3);\n\t\t\t\tif (hooks.some((h) => h.name === name)) continue;\n\t\t\t\thooks.push({\n\t\t\t\t\tname,\n\t\t\t\t\tscriptPath: path.join(hooksDir, entry),\n\t\t\t\t\tbuiltin: false,\n\t\t\t\t\tpolicy: sanitizeHookPolicy(DEFAULT_HOOK_POLICY),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch {\n\t\t\t// Hooks directory may be absent; builtin inventory is sufficient.\n\t\t}\n\t}\n\treturn { hooks };\n}\n"]}
|
|
@@ -60,6 +60,12 @@ export const BUILTIN_HOOKS = [
|
|
|
60
60
|
failureMode: "fail-closed",
|
|
61
61
|
timeoutMs: 30_000,
|
|
62
62
|
}),
|
|
63
|
+
builtinHook("notify-sound-on-stop", {
|
|
64
|
+
stages: ["session_stop"],
|
|
65
|
+
effects: ["observer"],
|
|
66
|
+
failureMode: "fail-closed",
|
|
67
|
+
timeoutMs: 5_000,
|
|
68
|
+
}),
|
|
63
69
|
builtinHook("bounded-evidence", {
|
|
64
70
|
stages: ["tool_result", "session_stop"],
|
|
65
71
|
effects: ["validator"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-inventory.js","sourceRoot":"","sources":["../../src/core/hook-inventory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAa3E,SAAS,WAAW,CAAC,IAAY,EAAE,MAA0B,EAAkB;IAC9E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;AAAA,CACnE;AAED,MAAM,CAAC,MAAM,aAAa,GAA8B;IACvD,WAAW,CAAC,iBAAiB,EAAE;QAC9B,MAAM,EAAE,CAAC,WAAW,CAAC;QACrB,OAAO,EAAE,CAAC,WAAW,CAAC;QACtB,WAAW,EAAE,aAAa;QAC1B,SAAS,EAAE,KAAK;KAChB,CAAC;IACF,WAAW,CAAC,iBAAiB,EAAE;QAC9B,MAAM,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC;QACpC,OAAO,EAAE,CAAC,WAAW,CAAC;QACtB,WAAW,EAAE,aAAa;QAC1B,SAAS,EAAE,KAAK;KAChB,CAAC;IACF,WAAW,CAAC,iBAAiB,EAAE;QAC9B,MAAM,EAAE,C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/C,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,kEAAkE;QACnE,CAAC;IACF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AAAA,CACjB","sourcesContent":["/**\n * Minimal hook inventory for the loadout runtime.\n *\n * The external harness resolves `scriptPath` to an actual shell script.\n * This module provides canonical names plus safe policy metadata so the\n * loadout layer can validate selectors without executing hooks.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { HookPolicyMetadata } from \"./hooks/index.ts\";\nimport { DEFAULT_HOOK_POLICY, sanitizeHookPolicy } from \"./hooks/index.ts\";\n\nexport interface HookDescriptor {\n\tname: string;\n\tscriptPath?: string;\n\tbuiltin: boolean;\n\tpolicy: HookPolicyMetadata;\n}\n\nexport interface HookInventory {\n\thooks: readonly HookDescriptor[];\n}\n\nfunction builtinHook(name: string, policy: HookPolicyMetadata): HookDescriptor {\n\treturn { name, builtin: true, policy: sanitizeHookPolicy(policy) };\n}\n\nexport const BUILTIN_HOOKS: readonly HookDescriptor[] = [\n\tbuiltinHook(\"pre-shell-guard\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 3_000,\n\t}),\n\tbuiltinHook(\"protect-secrets\", {\n\t\tstages: [\"tool_call\", \"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"session-context\", {\n\t\tstages: [\"session_start\"],\n\t\teffects: [\"mutator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"precompact-checkpoint\", {\n\t\tstages: [\"pre_compact\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"typecheck-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"stop-verify\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"subagent-stop-audit\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"npm-audit-summary\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"bounded-evidence\", {\n\t\tstages: [\"tool_result\", \"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"document-artifact-guard\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"component-spec-before-build\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"visual-diff-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n];\n\n/**\n * Load the hook inventory. Builtin hooks are always present; if an agent\n * directory is provided and its `hooks` subdirectory exists, any shell scripts\n * discovered there are appended as non-builtin descriptors.\n */\nexport function loadHookInventory(agentDir?: string): HookInventory {\n\tconst hooks: HookDescriptor[] = [...BUILTIN_HOOKS];\n\tif (agentDir) {\n\t\ttry {\n\t\t\tconst hooksDir = path.join(agentDir, \"hooks\");\n\t\t\tconst entries = fs.readdirSync(hooksDir).sort();\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (!entry.endsWith(\".sh\")) continue;\n\t\t\t\tconst name = entry.slice(0, -3);\n\t\t\t\tif (hooks.some((h) => h.name === name)) continue;\n\t\t\t\thooks.push({\n\t\t\t\t\tname,\n\t\t\t\t\tscriptPath: path.join(hooksDir, entry),\n\t\t\t\t\tbuiltin: false,\n\t\t\t\t\tpolicy: sanitizeHookPolicy(DEFAULT_HOOK_POLICY),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch {\n\t\t\t// Hooks directory may be absent; builtin inventory is sufficient.\n\t\t}\n\t}\n\treturn { hooks };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hook-inventory.js","sourceRoot":"","sources":["../../src/core/hook-inventory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAa3E,SAAS,WAAW,CAAC,IAAY,EAAE,MAA0B,EAAkB;IAC9E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;AAAA,CACnE;AAED,MAAM,CAAC,MAAM,aAAa,GAA8B;IACvD,WAAW,CAAC,iBAAiB,EAAE;QAC9B,MAAM,EAAE,CAAC,WAAW,CAAC;QACrB,OAAO,EAAE,CAAC,WAAW,CAAC;QACtB,WAAW,EAAE,aAAa;QAC1B,SAAS,EAAE,KAAK;KAChB,CAAC;IACF,WAAW,CAAC,iBAAiB,EAAE;QAC9B,MAAM,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC;QACpC,OAAO,EAAE,CAAC,WAAW,CAAC;QACtB,WAAW,EAAE,aAAa;QAC1B,SAAS,EAAE,KAAK;KAChB,CAAC;IACF,WA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,CAAC;oBAAE,SAAS;gBACjD,KAAK,CAAC,IAAI,CAAC;oBACV,IAAI;oBACJ,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;oBACtC,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,kBAAkB,CAAC,mBAAmB,CAAC;iBAC/C,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,kEAAkE;QACnE,CAAC;IACF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AAAA,CACjB","sourcesContent":["/**\n * Minimal hook inventory for the loadout runtime.\n *\n * The external harness resolves `scriptPath` to an actual shell script.\n * This module provides canonical names plus safe policy metadata so the\n * loadout layer can validate selectors without executing hooks.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { HookPolicyMetadata } from \"./hooks/index.ts\";\nimport { DEFAULT_HOOK_POLICY, sanitizeHookPolicy } from \"./hooks/index.ts\";\n\nexport interface HookDescriptor {\n\tname: string;\n\tscriptPath?: string;\n\tbuiltin: boolean;\n\tpolicy: HookPolicyMetadata;\n}\n\nexport interface HookInventory {\n\thooks: readonly HookDescriptor[];\n}\n\nfunction builtinHook(name: string, policy: HookPolicyMetadata): HookDescriptor {\n\treturn { name, builtin: true, policy: sanitizeHookPolicy(policy) };\n}\n\nexport const BUILTIN_HOOKS: readonly HookDescriptor[] = [\n\tbuiltinHook(\"pre-shell-guard\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 3_000,\n\t}),\n\tbuiltinHook(\"protect-secrets\", {\n\t\tstages: [\"tool_call\", \"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"session-context\", {\n\t\tstages: [\"session_start\"],\n\t\teffects: [\"mutator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"precompact-checkpoint\", {\n\t\tstages: [\"pre_compact\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"typecheck-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"stop-verify\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"subagent-stop-audit\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"npm-audit-summary\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 30_000,\n\t}),\n\tbuiltinHook(\"notify-sound-on-stop\", {\n\t\tstages: [\"session_stop\"],\n\t\teffects: [\"observer\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"bounded-evidence\", {\n\t\tstages: [\"tool_result\", \"session_stop\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n\tbuiltinHook(\"document-artifact-guard\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"component-spec-before-build\", {\n\t\tstages: [\"tool_call\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 5_000,\n\t}),\n\tbuiltinHook(\"visual-diff-after-edit\", {\n\t\tstages: [\"tool_result\"],\n\t\teffects: [\"validator\"],\n\t\tfailureMode: \"fail-closed\",\n\t\ttimeoutMs: 10_000,\n\t}),\n];\n\n/**\n * Load the hook inventory. Builtin hooks are always present; if an agent\n * directory is provided and its `hooks` subdirectory exists, any shell scripts\n * discovered there are appended as non-builtin descriptors.\n */\nexport function loadHookInventory(agentDir?: string): HookInventory {\n\tconst hooks: HookDescriptor[] = [...BUILTIN_HOOKS];\n\tif (agentDir) {\n\t\ttry {\n\t\t\tconst hooksDir = path.join(agentDir, \"hooks\");\n\t\t\tconst entries = fs.readdirSync(hooksDir).sort();\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (!entry.endsWith(\".sh\")) continue;\n\t\t\t\tconst name = entry.slice(0, -3);\n\t\t\t\tif (hooks.some((h) => h.name === name)) continue;\n\t\t\t\thooks.push({\n\t\t\t\t\tname,\n\t\t\t\t\tscriptPath: path.join(hooksDir, entry),\n\t\t\t\t\tbuiltin: false,\n\t\t\t\t\tpolicy: sanitizeHookPolicy(DEFAULT_HOOK_POLICY),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch {\n\t\t\t// Hooks directory may be absent; builtin inventory is sufficient.\n\t\t}\n\t}\n\treturn { hooks };\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare const OMK_COMPUTER_USE_DEFAULT_PRESET_ID = "playwright-computer-use";
|
|
2
|
+
export type ComputerUsePresetKey = "browserUseAgent" | "playwrightComputerUse";
|
|
3
|
+
export type ComputerUsePresetId = "browser-use-agent" | "playwright-computer-use";
|
|
4
|
+
export type ComputerUseRisk = "R3";
|
|
5
|
+
export type ComputerUseEngine = "mcp" | "python-rust-sidecar";
|
|
6
|
+
export type ComputerUseBrowser = "chrome" | "firefox" | "msedge" | "webkit";
|
|
7
|
+
export type ComputerUseCookieMode = "existing-browser-session" | "isolated-storage-state" | "managed-profile" | "none";
|
|
8
|
+
export type ComputerUseCredentialScope = "none" | "session" | "workspace";
|
|
9
|
+
export type ComputerUseLaunchOption = "browser" | "cdp-endpoint" | "extension" | "storage-state" | "user-data-dir";
|
|
10
|
+
export interface ComputerUseTransport {
|
|
11
|
+
readonly args: readonly string[];
|
|
12
|
+
readonly command: string;
|
|
13
|
+
readonly packageName?: string;
|
|
14
|
+
readonly type: "stdio";
|
|
15
|
+
}
|
|
16
|
+
export interface ComputerUseBrowserMode {
|
|
17
|
+
readonly argsExtra?: readonly string[];
|
|
18
|
+
readonly browser?: ComputerUseBrowser;
|
|
19
|
+
readonly browserLimit?: "chrome-edge-only";
|
|
20
|
+
readonly cookieMode: ComputerUseCookieMode;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly id: "existing-chrome-session" | "isolated-storage-state" | "managed-chrome-profile" | "managed-firefox-profile";
|
|
23
|
+
readonly profileDir?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ComputerUsePolicy {
|
|
26
|
+
readonly allowedDomainsRequired?: boolean;
|
|
27
|
+
readonly allowedOriginsSecurityBoundary?: boolean;
|
|
28
|
+
readonly blockMetadataIp: boolean;
|
|
29
|
+
readonly blockPrivateNetwork: boolean;
|
|
30
|
+
readonly credentialScopes: readonly ComputerUseCredentialScope[];
|
|
31
|
+
readonly denyNoSandbox: boolean;
|
|
32
|
+
readonly descriptorHashPinned: boolean;
|
|
33
|
+
readonly evidenceLedger: boolean;
|
|
34
|
+
readonly maxActions: number;
|
|
35
|
+
readonly maxOutputBytes?: number;
|
|
36
|
+
readonly noManualProfileShellScript?: boolean;
|
|
37
|
+
readonly noUnrestrictedFileAccess: boolean;
|
|
38
|
+
readonly originAllowlistRequiredForCredentialedMode: boolean;
|
|
39
|
+
readonly outputGuard: boolean;
|
|
40
|
+
readonly profileBrokerOnly?: boolean;
|
|
41
|
+
readonly requiresExplicitPostconditions: boolean;
|
|
42
|
+
readonly requiresRequestInterception: boolean;
|
|
43
|
+
readonly sandboxRequired: boolean;
|
|
44
|
+
readonly secretBrokerOnly: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ComputerUsePreset {
|
|
47
|
+
readonly browserModes: readonly ComputerUseBrowserMode[];
|
|
48
|
+
readonly defaultEnabled: boolean;
|
|
49
|
+
readonly engine: ComputerUseEngine;
|
|
50
|
+
readonly id: ComputerUsePresetId;
|
|
51
|
+
readonly key: ComputerUsePresetKey;
|
|
52
|
+
readonly label: string;
|
|
53
|
+
readonly notes: readonly string[];
|
|
54
|
+
readonly policy: ComputerUsePolicy;
|
|
55
|
+
readonly risk: ComputerUseRisk;
|
|
56
|
+
readonly sourceUrls: readonly string[];
|
|
57
|
+
readonly supportedLaunchOptions: readonly ComputerUseLaunchOption[];
|
|
58
|
+
readonly transport?: ComputerUseTransport;
|
|
59
|
+
}
|
|
60
|
+
export declare const COMPUTER_USE_PRESETS: Record<ComputerUsePresetKey, ComputerUsePreset>;
|
|
61
|
+
export declare function listComputerUsePresets(): ComputerUsePreset[];
|
|
62
|
+
export declare function getComputerUsePreset(id: string): ComputerUsePreset | undefined;
|
|
63
|
+
export declare function requiresCredentialedOriginAllowlist(cookieMode: ComputerUseCookieMode): boolean;
|
|
64
|
+
//# sourceMappingURL=mcp-computer-use-presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-computer-use-presets.d.ts","sourceRoot":"","sources":["../../src/core/mcp-computer-use-presets.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,4BAA4B,CAAC;AAE5E,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,uBAAuB,CAAC;AAC/E,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,GAAG,yBAAyB,CAAC;AAClF,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC;AACnC,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,qBAAqB,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC5E,MAAM,MAAM,qBAAqB,GAAG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EAAE,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAGvE,CAAC;AAEX,wBAAgB,sBAAsB,IAAI,iBAAiB,EAAE,CAE5D;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAG9E;AAED,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAE9F","sourcesContent":["export const OMK_COMPUTER_USE_DEFAULT_PRESET_ID = \"playwright-computer-use\";\n\nexport type ComputerUsePresetKey = \"browserUseAgent\" | \"playwrightComputerUse\";\nexport type ComputerUsePresetId = \"browser-use-agent\" | \"playwright-computer-use\";\nexport type ComputerUseRisk = \"R3\";\nexport type ComputerUseEngine = \"mcp\" | \"python-rust-sidecar\";\nexport type ComputerUseBrowser = \"chrome\" | \"firefox\" | \"msedge\" | \"webkit\";\nexport type ComputerUseCookieMode = \"existing-browser-session\" | \"isolated-storage-state\" | \"managed-profile\" | \"none\";\nexport type ComputerUseCredentialScope = \"none\" | \"session\" | \"workspace\";\nexport type ComputerUseLaunchOption = \"browser\" | \"cdp-endpoint\" | \"extension\" | \"storage-state\" | \"user-data-dir\";\n\nexport interface ComputerUseTransport {\n\treadonly args: readonly string[];\n\treadonly command: string;\n\treadonly packageName?: string;\n\treadonly type: \"stdio\";\n}\n\nexport interface ComputerUseBrowserMode {\n\treadonly argsExtra?: readonly string[];\n\treadonly browser?: ComputerUseBrowser;\n\treadonly browserLimit?: \"chrome-edge-only\";\n\treadonly cookieMode: ComputerUseCookieMode;\n\treadonly description: string;\n\treadonly id:\n\t\t| \"existing-chrome-session\"\n\t\t| \"isolated-storage-state\"\n\t\t| \"managed-chrome-profile\"\n\t\t| \"managed-firefox-profile\";\n\treadonly profileDir?: string;\n}\n\nexport interface ComputerUsePolicy {\n\treadonly allowedDomainsRequired?: boolean;\n\treadonly allowedOriginsSecurityBoundary?: boolean;\n\treadonly blockMetadataIp: boolean;\n\treadonly blockPrivateNetwork: boolean;\n\treadonly credentialScopes: readonly ComputerUseCredentialScope[];\n\treadonly denyNoSandbox: boolean;\n\treadonly descriptorHashPinned: boolean;\n\treadonly evidenceLedger: boolean;\n\treadonly maxActions: number;\n\treadonly maxOutputBytes?: number;\n\treadonly noManualProfileShellScript?: boolean;\n\treadonly noUnrestrictedFileAccess: boolean;\n\treadonly originAllowlistRequiredForCredentialedMode: boolean;\n\treadonly outputGuard: boolean;\n\treadonly profileBrokerOnly?: boolean;\n\treadonly requiresExplicitPostconditions: boolean;\n\treadonly requiresRequestInterception: boolean;\n\treadonly sandboxRequired: boolean;\n\treadonly secretBrokerOnly: boolean;\n}\n\nexport interface ComputerUsePreset {\n\treadonly browserModes: readonly ComputerUseBrowserMode[];\n\treadonly defaultEnabled: boolean;\n\treadonly engine: ComputerUseEngine;\n\treadonly id: ComputerUsePresetId;\n\treadonly key: ComputerUsePresetKey;\n\treadonly label: string;\n\treadonly notes: readonly string[];\n\treadonly policy: ComputerUsePolicy;\n\treadonly risk: ComputerUseRisk;\n\treadonly sourceUrls: readonly string[];\n\treadonly supportedLaunchOptions: readonly ComputerUseLaunchOption[];\n\treadonly transport?: ComputerUseTransport;\n}\n\nconst PLAYWRIGHT_BROWSER_MODES: readonly ComputerUseBrowserMode[] = [\n\t{\n\t\tbrowser: \"chrome\",\n\t\tcookieMode: \"managed-profile\",\n\t\tdescription: \"OMK-managed Chrome profile with project-scoped persistent cookies and local storage.\",\n\t\tid: \"managed-chrome-profile\",\n\t\tprofileDir: \".omk/browser-profiles/chrome\",\n\t},\n\t{\n\t\tbrowser: \"firefox\",\n\t\tcookieMode: \"managed-profile\",\n\t\tdescription: \"OMK-managed Firefox profile; avoids attaching to the user's real Firefox profile.\",\n\t\tid: \"managed-firefox-profile\",\n\t\tprofileDir: \".omk/browser-profiles/firefox\",\n\t},\n\t{\n\t\targsExtra: [\"--isolated\", \"--storage-state\", \"<storageStatePath>\"],\n\t\tcookieMode: \"isolated-storage-state\",\n\t\tdescription: \"Loads cookies and local storage from an explicit Playwright storage-state file.\",\n\t\tid: \"isolated-storage-state\",\n\t},\n\t{\n\t\targsExtra: [\"--extension\"],\n\t\tbrowser: \"chrome\",\n\t\tbrowserLimit: \"chrome-edge-only\",\n\t\tcookieMode: \"existing-browser-session\",\n\t\tdescription: \"Connects to an existing Chrome or Edge session through the Playwright extension.\",\n\t\tid: \"existing-chrome-session\",\n\t},\n];\n\nconst PLAYWRIGHT_COMPUTER_USE_PRESET: ComputerUsePreset = {\n\tbrowserModes: PLAYWRIGHT_BROWSER_MODES,\n\tdefaultEnabled: true,\n\tengine: \"mcp\",\n\tid: \"playwright-computer-use\",\n\tkey: \"playwrightComputerUse\",\n\tlabel: \"Playwright Computer Use\",\n\tnotes: [\n\t\t\"Default computer-use preset built on Microsoft Playwright MCP accessibility-tree automation.\",\n\t\t\"Credentialed browser sessions must go through SecureComputerUseBroker preflight and request interception.\",\n\t\t\"Playwright allowed-origins are recorded as advisory only; OMK policy remains the security boundary.\",\n\t],\n\tpolicy: {\n\t\tallowedOriginsSecurityBoundary: false,\n\t\tblockMetadataIp: true,\n\t\tblockPrivateNetwork: true,\n\t\tcredentialScopes: [\"none\", \"session\", \"workspace\"],\n\t\tdenyNoSandbox: true,\n\t\tdescriptorHashPinned: true,\n\t\tevidenceLedger: true,\n\t\tmaxActions: 40,\n\t\tmaxOutputBytes: 25_000_000,\n\t\tnoUnrestrictedFileAccess: true,\n\t\toriginAllowlistRequiredForCredentialedMode: true,\n\t\toutputGuard: true,\n\t\trequiresExplicitPostconditions: true,\n\t\trequiresRequestInterception: true,\n\t\tsandboxRequired: true,\n\t\tsecretBrokerOnly: true,\n\t},\n\trisk: \"R3\",\n\tsourceUrls: [\"https://github.com/microsoft/playwright-mcp\"],\n\tsupportedLaunchOptions: [\"browser\", \"user-data-dir\", \"storage-state\", \"extension\", \"cdp-endpoint\"],\n\ttransport: {\n\t\targs: [\n\t\t\t\"-y\",\n\t\t\t\"@playwright/mcp@0.0.76\",\n\t\t\t\"--browser\",\n\t\t\t\"<browser>\",\n\t\t\t\"--user-data-dir\",\n\t\t\t\"<profileDir>\",\n\t\t\t\"--output-dir\",\n\t\t\t\"<outputDir>\",\n\t\t\t\"--output-mode\",\n\t\t\t\"file\",\n\t\t\t\"--block-service-workers\",\n\t\t\t\"--timeout-action\",\n\t\t\t\"5000\",\n\t\t\t\"--timeout-navigation\",\n\t\t\t\"60000\",\n\t\t],\n\t\tcommand: \"npx\",\n\t\tpackageName: \"@playwright/mcp\",\n\t\ttype: \"stdio\",\n\t},\n};\n\nconst BROWSER_USE_AGENT_PRESET: ComputerUsePreset = {\n\tbrowserModes: [],\n\tdefaultEnabled: false,\n\tengine: \"python-rust-sidecar\",\n\tid: \"browser-use-agent\",\n\tkey: \"browserUseAgent\",\n\tlabel: \"Browser Use Agent\",\n\tnotes: [\n\t\t\"Optional advanced runner for agentic browser tasks that need recovery loops or custom tools.\",\n\t\t\"Profiles and secrets must be injected through OMK brokers instead of manual shell profile scripts.\",\n\t],\n\tpolicy: {\n\t\tallowedDomainsRequired: true,\n\t\tblockMetadataIp: true,\n\t\tblockPrivateNetwork: true,\n\t\tcredentialScopes: [\"none\", \"session\", \"workspace\"],\n\t\tdenyNoSandbox: true,\n\t\tdescriptorHashPinned: true,\n\t\tevidenceLedger: true,\n\t\tmaxActions: 60,\n\t\tnoManualProfileShellScript: true,\n\t\tnoUnrestrictedFileAccess: true,\n\t\toriginAllowlistRequiredForCredentialedMode: true,\n\t\toutputGuard: true,\n\t\tprofileBrokerOnly: true,\n\t\trequiresExplicitPostconditions: true,\n\t\trequiresRequestInterception: true,\n\t\tsandboxRequired: true,\n\t\tsecretBrokerOnly: true,\n\t},\n\trisk: \"R3\",\n\tsourceUrls: [\"https://github.com/browser-use/browser-use\"],\n\tsupportedLaunchOptions: [],\n};\n\nexport const COMPUTER_USE_PRESETS: Record<ComputerUsePresetKey, ComputerUsePreset> = {\n\tplaywrightComputerUse: PLAYWRIGHT_COMPUTER_USE_PRESET,\n\tbrowserUseAgent: BROWSER_USE_AGENT_PRESET,\n} as const;\n\nexport function listComputerUsePresets(): ComputerUsePreset[] {\n\treturn Object.values(COMPUTER_USE_PRESETS).map((preset) => cloneComputerUsePreset(preset));\n}\n\nexport function getComputerUsePreset(id: string): ComputerUsePreset | undefined {\n\tconst preset = Object.values(COMPUTER_USE_PRESETS).find((candidate) => candidate.id === id);\n\treturn preset ? cloneComputerUsePreset(preset) : undefined;\n}\n\nexport function requiresCredentialedOriginAllowlist(cookieMode: ComputerUseCookieMode): boolean {\n\treturn cookieMode !== \"none\";\n}\n\nfunction cloneComputerUsePreset(preset: ComputerUsePreset): ComputerUsePreset {\n\treturn {\n\t\t...preset,\n\t\tbrowserModes: preset.browserModes.map((mode) => ({\n\t\t\t...mode,\n\t\t\targsExtra: mode.argsExtra ? [...mode.argsExtra] : undefined,\n\t\t})),\n\t\tnotes: [...preset.notes],\n\t\tpolicy: {\n\t\t\t...preset.policy,\n\t\t\tcredentialScopes: [...preset.policy.credentialScopes],\n\t\t},\n\t\tsourceUrls: [...preset.sourceUrls],\n\t\tsupportedLaunchOptions: [...preset.supportedLaunchOptions],\n\t\ttransport: preset.transport\n\t\t\t? {\n\t\t\t\t\t...preset.transport,\n\t\t\t\t\targs: [...preset.transport.args],\n\t\t\t\t}\n\t\t\t: undefined,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export const OMK_COMPUTER_USE_DEFAULT_PRESET_ID = "playwright-computer-use";
|
|
2
|
+
const PLAYWRIGHT_BROWSER_MODES = [
|
|
3
|
+
{
|
|
4
|
+
browser: "chrome",
|
|
5
|
+
cookieMode: "managed-profile",
|
|
6
|
+
description: "OMK-managed Chrome profile with project-scoped persistent cookies and local storage.",
|
|
7
|
+
id: "managed-chrome-profile",
|
|
8
|
+
profileDir: ".omk/browser-profiles/chrome",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
browser: "firefox",
|
|
12
|
+
cookieMode: "managed-profile",
|
|
13
|
+
description: "OMK-managed Firefox profile; avoids attaching to the user's real Firefox profile.",
|
|
14
|
+
id: "managed-firefox-profile",
|
|
15
|
+
profileDir: ".omk/browser-profiles/firefox",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
argsExtra: ["--isolated", "--storage-state", "<storageStatePath>"],
|
|
19
|
+
cookieMode: "isolated-storage-state",
|
|
20
|
+
description: "Loads cookies and local storage from an explicit Playwright storage-state file.",
|
|
21
|
+
id: "isolated-storage-state",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
argsExtra: ["--extension"],
|
|
25
|
+
browser: "chrome",
|
|
26
|
+
browserLimit: "chrome-edge-only",
|
|
27
|
+
cookieMode: "existing-browser-session",
|
|
28
|
+
description: "Connects to an existing Chrome or Edge session through the Playwright extension.",
|
|
29
|
+
id: "existing-chrome-session",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const PLAYWRIGHT_COMPUTER_USE_PRESET = {
|
|
33
|
+
browserModes: PLAYWRIGHT_BROWSER_MODES,
|
|
34
|
+
defaultEnabled: true,
|
|
35
|
+
engine: "mcp",
|
|
36
|
+
id: "playwright-computer-use",
|
|
37
|
+
key: "playwrightComputerUse",
|
|
38
|
+
label: "Playwright Computer Use",
|
|
39
|
+
notes: [
|
|
40
|
+
"Default computer-use preset built on Microsoft Playwright MCP accessibility-tree automation.",
|
|
41
|
+
"Credentialed browser sessions must go through SecureComputerUseBroker preflight and request interception.",
|
|
42
|
+
"Playwright allowed-origins are recorded as advisory only; OMK policy remains the security boundary.",
|
|
43
|
+
],
|
|
44
|
+
policy: {
|
|
45
|
+
allowedOriginsSecurityBoundary: false,
|
|
46
|
+
blockMetadataIp: true,
|
|
47
|
+
blockPrivateNetwork: true,
|
|
48
|
+
credentialScopes: ["none", "session", "workspace"],
|
|
49
|
+
denyNoSandbox: true,
|
|
50
|
+
descriptorHashPinned: true,
|
|
51
|
+
evidenceLedger: true,
|
|
52
|
+
maxActions: 40,
|
|
53
|
+
maxOutputBytes: 25_000_000,
|
|
54
|
+
noUnrestrictedFileAccess: true,
|
|
55
|
+
originAllowlistRequiredForCredentialedMode: true,
|
|
56
|
+
outputGuard: true,
|
|
57
|
+
requiresExplicitPostconditions: true,
|
|
58
|
+
requiresRequestInterception: true,
|
|
59
|
+
sandboxRequired: true,
|
|
60
|
+
secretBrokerOnly: true,
|
|
61
|
+
},
|
|
62
|
+
risk: "R3",
|
|
63
|
+
sourceUrls: ["https://github.com/microsoft/playwright-mcp"],
|
|
64
|
+
supportedLaunchOptions: ["browser", "user-data-dir", "storage-state", "extension", "cdp-endpoint"],
|
|
65
|
+
transport: {
|
|
66
|
+
args: [
|
|
67
|
+
"-y",
|
|
68
|
+
"@playwright/mcp@0.0.76",
|
|
69
|
+
"--browser",
|
|
70
|
+
"<browser>",
|
|
71
|
+
"--user-data-dir",
|
|
72
|
+
"<profileDir>",
|
|
73
|
+
"--output-dir",
|
|
74
|
+
"<outputDir>",
|
|
75
|
+
"--output-mode",
|
|
76
|
+
"file",
|
|
77
|
+
"--block-service-workers",
|
|
78
|
+
"--timeout-action",
|
|
79
|
+
"5000",
|
|
80
|
+
"--timeout-navigation",
|
|
81
|
+
"60000",
|
|
82
|
+
],
|
|
83
|
+
command: "npx",
|
|
84
|
+
packageName: "@playwright/mcp",
|
|
85
|
+
type: "stdio",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const BROWSER_USE_AGENT_PRESET = {
|
|
89
|
+
browserModes: [],
|
|
90
|
+
defaultEnabled: false,
|
|
91
|
+
engine: "python-rust-sidecar",
|
|
92
|
+
id: "browser-use-agent",
|
|
93
|
+
key: "browserUseAgent",
|
|
94
|
+
label: "Browser Use Agent",
|
|
95
|
+
notes: [
|
|
96
|
+
"Optional advanced runner for agentic browser tasks that need recovery loops or custom tools.",
|
|
97
|
+
"Profiles and secrets must be injected through OMK brokers instead of manual shell profile scripts.",
|
|
98
|
+
],
|
|
99
|
+
policy: {
|
|
100
|
+
allowedDomainsRequired: true,
|
|
101
|
+
blockMetadataIp: true,
|
|
102
|
+
blockPrivateNetwork: true,
|
|
103
|
+
credentialScopes: ["none", "session", "workspace"],
|
|
104
|
+
denyNoSandbox: true,
|
|
105
|
+
descriptorHashPinned: true,
|
|
106
|
+
evidenceLedger: true,
|
|
107
|
+
maxActions: 60,
|
|
108
|
+
noManualProfileShellScript: true,
|
|
109
|
+
noUnrestrictedFileAccess: true,
|
|
110
|
+
originAllowlistRequiredForCredentialedMode: true,
|
|
111
|
+
outputGuard: true,
|
|
112
|
+
profileBrokerOnly: true,
|
|
113
|
+
requiresExplicitPostconditions: true,
|
|
114
|
+
requiresRequestInterception: true,
|
|
115
|
+
sandboxRequired: true,
|
|
116
|
+
secretBrokerOnly: true,
|
|
117
|
+
},
|
|
118
|
+
risk: "R3",
|
|
119
|
+
sourceUrls: ["https://github.com/browser-use/browser-use"],
|
|
120
|
+
supportedLaunchOptions: [],
|
|
121
|
+
};
|
|
122
|
+
export const COMPUTER_USE_PRESETS = {
|
|
123
|
+
playwrightComputerUse: PLAYWRIGHT_COMPUTER_USE_PRESET,
|
|
124
|
+
browserUseAgent: BROWSER_USE_AGENT_PRESET,
|
|
125
|
+
};
|
|
126
|
+
export function listComputerUsePresets() {
|
|
127
|
+
return Object.values(COMPUTER_USE_PRESETS).map((preset) => cloneComputerUsePreset(preset));
|
|
128
|
+
}
|
|
129
|
+
export function getComputerUsePreset(id) {
|
|
130
|
+
const preset = Object.values(COMPUTER_USE_PRESETS).find((candidate) => candidate.id === id);
|
|
131
|
+
return preset ? cloneComputerUsePreset(preset) : undefined;
|
|
132
|
+
}
|
|
133
|
+
export function requiresCredentialedOriginAllowlist(cookieMode) {
|
|
134
|
+
return cookieMode !== "none";
|
|
135
|
+
}
|
|
136
|
+
function cloneComputerUsePreset(preset) {
|
|
137
|
+
return {
|
|
138
|
+
...preset,
|
|
139
|
+
browserModes: preset.browserModes.map((mode) => ({
|
|
140
|
+
...mode,
|
|
141
|
+
argsExtra: mode.argsExtra ? [...mode.argsExtra] : undefined,
|
|
142
|
+
})),
|
|
143
|
+
notes: [...preset.notes],
|
|
144
|
+
policy: {
|
|
145
|
+
...preset.policy,
|
|
146
|
+
credentialScopes: [...preset.policy.credentialScopes],
|
|
147
|
+
},
|
|
148
|
+
sourceUrls: [...preset.sourceUrls],
|
|
149
|
+
supportedLaunchOptions: [...preset.supportedLaunchOptions],
|
|
150
|
+
transport: preset.transport
|
|
151
|
+
? {
|
|
152
|
+
...preset.transport,
|
|
153
|
+
args: [...preset.transport.args],
|
|
154
|
+
}
|
|
155
|
+
: undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=mcp-computer-use-presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-computer-use-presets.js","sourceRoot":"","sources":["../../src/core/mcp-computer-use-presets.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kCAAkC,GAAG,yBAAyB,CAAC;AAqE5E,MAAM,wBAAwB,GAAsC;IACnE;QACC,OAAO,EAAE,QAAQ;QACjB,UAAU,EAAE,iBAAiB;QAC7B,WAAW,EAAE,sFAAsF;QACnG,EAAE,EAAE,wBAAwB;QAC5B,UAAU,EAAE,8BAA8B;KAC1C;IACD;QACC,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,iBAAiB;QAC7B,WAAW,EAAE,mFAAmF;QAChG,EAAE,EAAE,yBAAyB;QAC7B,UAAU,EAAE,+BAA+B;KAC3C;IACD;QACC,SAAS,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,CAAC;QAClE,UAAU,EAAE,wBAAwB;QACpC,WAAW,EAAE,iFAAiF;QAC9F,EAAE,EAAE,wBAAwB;KAC5B;IACD;QACC,SAAS,EAAE,CAAC,aAAa,CAAC;QAC1B,OAAO,EAAE,QAAQ;QACjB,YAAY,EAAE,kBAAkB;QAChC,UAAU,EAAE,0BAA0B;QACtC,WAAW,EAAE,kF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AAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CAC3D;AAED,MAAM,UAAU,mCAAmC,CAAC,UAAiC,EAAW;IAC/F,OAAO,UAAU,KAAK,MAAM,CAAC;AAAA,CAC7B;AAED,SAAS,sBAAsB,CAAC,MAAyB,EAAqB;IAC7E,OAAO;QACN,GAAG,MAAM;QACT,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAChD,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;SAC3D,CAAC,CAAC;QACH,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QACxB,MAAM,EAAE;YACP,GAAG,MAAM,CAAC,MAAM;YAChB,gBAAgB,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;SACrD;QACD,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC;QAClC,sBAAsB,EAAE,CAAC,GAAG,MAAM,CAAC,sBAAsB,CAAC;QAC1D,SAAS,EAAE,MAAM,CAAC,SAAS;YAC1B,CAAC,CAAC;gBACA,GAAG,MAAM,CAAC,SAAS;gBACnB,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;aAChC;YACF,CAAC,CAAC,SAAS;KACZ,CAAC;AAAA,CACF","sourcesContent":["export const OMK_COMPUTER_USE_DEFAULT_PRESET_ID = \"playwright-computer-use\";\n\nexport type ComputerUsePresetKey = \"browserUseAgent\" | \"playwrightComputerUse\";\nexport type ComputerUsePresetId = \"browser-use-agent\" | \"playwright-computer-use\";\nexport type ComputerUseRisk = \"R3\";\nexport type ComputerUseEngine = \"mcp\" | \"python-rust-sidecar\";\nexport type ComputerUseBrowser = \"chrome\" | \"firefox\" | \"msedge\" | \"webkit\";\nexport type ComputerUseCookieMode = \"existing-browser-session\" | \"isolated-storage-state\" | \"managed-profile\" | \"none\";\nexport type ComputerUseCredentialScope = \"none\" | \"session\" | \"workspace\";\nexport type ComputerUseLaunchOption = \"browser\" | \"cdp-endpoint\" | \"extension\" | \"storage-state\" | \"user-data-dir\";\n\nexport interface ComputerUseTransport {\n\treadonly args: readonly string[];\n\treadonly command: string;\n\treadonly packageName?: string;\n\treadonly type: \"stdio\";\n}\n\nexport interface ComputerUseBrowserMode {\n\treadonly argsExtra?: readonly string[];\n\treadonly browser?: ComputerUseBrowser;\n\treadonly browserLimit?: \"chrome-edge-only\";\n\treadonly cookieMode: ComputerUseCookieMode;\n\treadonly description: string;\n\treadonly id:\n\t\t| \"existing-chrome-session\"\n\t\t| \"isolated-storage-state\"\n\t\t| \"managed-chrome-profile\"\n\t\t| \"managed-firefox-profile\";\n\treadonly profileDir?: string;\n}\n\nexport interface ComputerUsePolicy {\n\treadonly allowedDomainsRequired?: boolean;\n\treadonly allowedOriginsSecurityBoundary?: boolean;\n\treadonly blockMetadataIp: boolean;\n\treadonly blockPrivateNetwork: boolean;\n\treadonly credentialScopes: readonly ComputerUseCredentialScope[];\n\treadonly denyNoSandbox: boolean;\n\treadonly descriptorHashPinned: boolean;\n\treadonly evidenceLedger: boolean;\n\treadonly maxActions: number;\n\treadonly maxOutputBytes?: number;\n\treadonly noManualProfileShellScript?: boolean;\n\treadonly noUnrestrictedFileAccess: boolean;\n\treadonly originAllowlistRequiredForCredentialedMode: boolean;\n\treadonly outputGuard: boolean;\n\treadonly profileBrokerOnly?: boolean;\n\treadonly requiresExplicitPostconditions: boolean;\n\treadonly requiresRequestInterception: boolean;\n\treadonly sandboxRequired: boolean;\n\treadonly secretBrokerOnly: boolean;\n}\n\nexport interface ComputerUsePreset {\n\treadonly browserModes: readonly ComputerUseBrowserMode[];\n\treadonly defaultEnabled: boolean;\n\treadonly engine: ComputerUseEngine;\n\treadonly id: ComputerUsePresetId;\n\treadonly key: ComputerUsePresetKey;\n\treadonly label: string;\n\treadonly notes: readonly string[];\n\treadonly policy: ComputerUsePolicy;\n\treadonly risk: ComputerUseRisk;\n\treadonly sourceUrls: readonly string[];\n\treadonly supportedLaunchOptions: readonly ComputerUseLaunchOption[];\n\treadonly transport?: ComputerUseTransport;\n}\n\nconst PLAYWRIGHT_BROWSER_MODES: readonly ComputerUseBrowserMode[] = [\n\t{\n\t\tbrowser: \"chrome\",\n\t\tcookieMode: \"managed-profile\",\n\t\tdescription: \"OMK-managed Chrome profile with project-scoped persistent cookies and local storage.\",\n\t\tid: \"managed-chrome-profile\",\n\t\tprofileDir: \".omk/browser-profiles/chrome\",\n\t},\n\t{\n\t\tbrowser: \"firefox\",\n\t\tcookieMode: \"managed-profile\",\n\t\tdescription: \"OMK-managed Firefox profile; avoids attaching to the user's real Firefox profile.\",\n\t\tid: \"managed-firefox-profile\",\n\t\tprofileDir: \".omk/browser-profiles/firefox\",\n\t},\n\t{\n\t\targsExtra: [\"--isolated\", \"--storage-state\", \"<storageStatePath>\"],\n\t\tcookieMode: \"isolated-storage-state\",\n\t\tdescription: \"Loads cookies and local storage from an explicit Playwright storage-state file.\",\n\t\tid: \"isolated-storage-state\",\n\t},\n\t{\n\t\targsExtra: [\"--extension\"],\n\t\tbrowser: \"chrome\",\n\t\tbrowserLimit: \"chrome-edge-only\",\n\t\tcookieMode: \"existing-browser-session\",\n\t\tdescription: \"Connects to an existing Chrome or Edge session through the Playwright extension.\",\n\t\tid: \"existing-chrome-session\",\n\t},\n];\n\nconst PLAYWRIGHT_COMPUTER_USE_PRESET: ComputerUsePreset = {\n\tbrowserModes: PLAYWRIGHT_BROWSER_MODES,\n\tdefaultEnabled: true,\n\tengine: \"mcp\",\n\tid: \"playwright-computer-use\",\n\tkey: \"playwrightComputerUse\",\n\tlabel: \"Playwright Computer Use\",\n\tnotes: [\n\t\t\"Default computer-use preset built on Microsoft Playwright MCP accessibility-tree automation.\",\n\t\t\"Credentialed browser sessions must go through SecureComputerUseBroker preflight and request interception.\",\n\t\t\"Playwright allowed-origins are recorded as advisory only; OMK policy remains the security boundary.\",\n\t],\n\tpolicy: {\n\t\tallowedOriginsSecurityBoundary: false,\n\t\tblockMetadataIp: true,\n\t\tblockPrivateNetwork: true,\n\t\tcredentialScopes: [\"none\", \"session\", \"workspace\"],\n\t\tdenyNoSandbox: true,\n\t\tdescriptorHashPinned: true,\n\t\tevidenceLedger: true,\n\t\tmaxActions: 40,\n\t\tmaxOutputBytes: 25_000_000,\n\t\tnoUnrestrictedFileAccess: true,\n\t\toriginAllowlistRequiredForCredentialedMode: true,\n\t\toutputGuard: true,\n\t\trequiresExplicitPostconditions: true,\n\t\trequiresRequestInterception: true,\n\t\tsandboxRequired: true,\n\t\tsecretBrokerOnly: true,\n\t},\n\trisk: \"R3\",\n\tsourceUrls: [\"https://github.com/microsoft/playwright-mcp\"],\n\tsupportedLaunchOptions: [\"browser\", \"user-data-dir\", \"storage-state\", \"extension\", \"cdp-endpoint\"],\n\ttransport: {\n\t\targs: [\n\t\t\t\"-y\",\n\t\t\t\"@playwright/mcp@0.0.76\",\n\t\t\t\"--browser\",\n\t\t\t\"<browser>\",\n\t\t\t\"--user-data-dir\",\n\t\t\t\"<profileDir>\",\n\t\t\t\"--output-dir\",\n\t\t\t\"<outputDir>\",\n\t\t\t\"--output-mode\",\n\t\t\t\"file\",\n\t\t\t\"--block-service-workers\",\n\t\t\t\"--timeout-action\",\n\t\t\t\"5000\",\n\t\t\t\"--timeout-navigation\",\n\t\t\t\"60000\",\n\t\t],\n\t\tcommand: \"npx\",\n\t\tpackageName: \"@playwright/mcp\",\n\t\ttype: \"stdio\",\n\t},\n};\n\nconst BROWSER_USE_AGENT_PRESET: ComputerUsePreset = {\n\tbrowserModes: [],\n\tdefaultEnabled: false,\n\tengine: \"python-rust-sidecar\",\n\tid: \"browser-use-agent\",\n\tkey: \"browserUseAgent\",\n\tlabel: \"Browser Use Agent\",\n\tnotes: [\n\t\t\"Optional advanced runner for agentic browser tasks that need recovery loops or custom tools.\",\n\t\t\"Profiles and secrets must be injected through OMK brokers instead of manual shell profile scripts.\",\n\t],\n\tpolicy: {\n\t\tallowedDomainsRequired: true,\n\t\tblockMetadataIp: true,\n\t\tblockPrivateNetwork: true,\n\t\tcredentialScopes: [\"none\", \"session\", \"workspace\"],\n\t\tdenyNoSandbox: true,\n\t\tdescriptorHashPinned: true,\n\t\tevidenceLedger: true,\n\t\tmaxActions: 60,\n\t\tnoManualProfileShellScript: true,\n\t\tnoUnrestrictedFileAccess: true,\n\t\toriginAllowlistRequiredForCredentialedMode: true,\n\t\toutputGuard: true,\n\t\tprofileBrokerOnly: true,\n\t\trequiresExplicitPostconditions: true,\n\t\trequiresRequestInterception: true,\n\t\tsandboxRequired: true,\n\t\tsecretBrokerOnly: true,\n\t},\n\trisk: \"R3\",\n\tsourceUrls: [\"https://github.com/browser-use/browser-use\"],\n\tsupportedLaunchOptions: [],\n};\n\nexport const COMPUTER_USE_PRESETS: Record<ComputerUsePresetKey, ComputerUsePreset> = {\n\tplaywrightComputerUse: PLAYWRIGHT_COMPUTER_USE_PRESET,\n\tbrowserUseAgent: BROWSER_USE_AGENT_PRESET,\n} as const;\n\nexport function listComputerUsePresets(): ComputerUsePreset[] {\n\treturn Object.values(COMPUTER_USE_PRESETS).map((preset) => cloneComputerUsePreset(preset));\n}\n\nexport function getComputerUsePreset(id: string): ComputerUsePreset | undefined {\n\tconst preset = Object.values(COMPUTER_USE_PRESETS).find((candidate) => candidate.id === id);\n\treturn preset ? cloneComputerUsePreset(preset) : undefined;\n}\n\nexport function requiresCredentialedOriginAllowlist(cookieMode: ComputerUseCookieMode): boolean {\n\treturn cookieMode !== \"none\";\n}\n\nfunction cloneComputerUsePreset(preset: ComputerUsePreset): ComputerUsePreset {\n\treturn {\n\t\t...preset,\n\t\tbrowserModes: preset.browserModes.map((mode) => ({\n\t\t\t...mode,\n\t\t\targsExtra: mode.argsExtra ? [...mode.argsExtra] : undefined,\n\t\t})),\n\t\tnotes: [...preset.notes],\n\t\tpolicy: {\n\t\t\t...preset.policy,\n\t\t\tcredentialScopes: [...preset.policy.credentialScopes],\n\t\t},\n\t\tsourceUrls: [...preset.sourceUrls],\n\t\tsupportedLaunchOptions: [...preset.supportedLaunchOptions],\n\t\ttransport: preset.transport\n\t\t\t? {\n\t\t\t\t\t...preset.transport,\n\t\t\t\t\targs: [...preset.transport.args],\n\t\t\t\t}\n\t\t\t: undefined,\n\t};\n}\n"]}
|