@phuetz/code-buddy 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +211 -163
- package/dist/agent/autonomous/agentic-coding-contract.d.ts +12 -12
- package/dist/agent/base-agent.d.ts +4 -0
- package/dist/agent/base-agent.js +6 -0
- package/dist/agent/codebuddy-agent.d.ts +1 -1
- package/dist/agent/codebuddy-agent.js +69 -14
- package/dist/agent/execution/agent-executor.js +122 -12
- package/dist/agent/execution/tool-dependency-graph.js +7 -0
- package/dist/agent/execution/tool-hooks.d.ts +6 -0
- package/dist/agent/execution/tool-hooks.js +13 -5
- package/dist/agent/execution/tool-selection-strategy.d.ts +11 -2
- package/dist/agent/execution/tool-selection-strategy.js +67 -10
- package/dist/agent/extended-thinking.d.ts +8 -0
- package/dist/agent/extended-thinking.js +27 -0
- package/dist/agent/facades/infrastructure-facade.d.ts +9 -2
- package/dist/agent/facades/infrastructure-facade.js +15 -6
- package/dist/agent/hermes-browser-backends.js +151 -11
- package/dist/agent/hermes-claw-migrate.d.ts +59 -0
- package/dist/agent/hermes-claw-migrate.js +427 -26
- package/dist/agent/hermes-parity-manifest.js +78 -71
- package/dist/agent/hermes-runtime-lifecycle.d.ts +67 -0
- package/dist/agent/hermes-runtime-lifecycle.js +468 -0
- package/dist/agent/middleware/index.d.ts +1 -0
- package/dist/agent/middleware/index.js +1 -0
- package/dist/agent/middleware/visual-validation-middleware.d.ts +17 -0
- package/dist/agent/middleware/visual-validation-middleware.js +67 -0
- package/dist/agent/model-benchmark.d.ts +77 -0
- package/dist/agent/model-benchmark.js +309 -0
- package/dist/agent/model-tier.d.ts +14 -0
- package/dist/agent/model-tier.js +71 -0
- package/dist/agent/multi-agent/agents/orchestrator-agent.js +17 -6
- package/dist/agent/multi-agent/multi-agent-system.js +3 -1
- package/dist/agent/multi-agent/session-fleet-bridge.d.ts +2 -0
- package/dist/agent/multi-agent/session-fleet-bridge.js +9 -1
- package/dist/agent/multi-agent/session-tools.js +22 -5
- package/dist/agent/reasoning/mcts.js +20 -6
- package/dist/agent/self-improvement/authored-artifact-gate.d.ts +18 -0
- package/dist/agent/self-improvement/authored-artifact-gate.js +42 -0
- package/dist/agent/self-improvement/authored-tool-runtime.d.ts +27 -0
- package/dist/agent/self-improvement/authored-tool-runtime.js +57 -0
- package/dist/agent/self-improvement/authored-tool-store.d.ts +24 -0
- package/dist/agent/self-improvement/authored-tool-store.js +57 -0
- package/dist/agent/self-improvement/llm-tool-proposer.d.ts +41 -0
- package/dist/agent/self-improvement/llm-tool-proposer.js +136 -0
- package/dist/agent/self-improvement/sandbox-scorer.d.ts +17 -0
- package/dist/agent/self-improvement/sandbox-scorer.js +43 -0
- package/dist/agent/self-improvement/self-knowledge.d.ts +8 -0
- package/dist/agent/self-improvement/self-knowledge.js +24 -0
- package/dist/agent/self-improvement/skill-benchmark.d.ts +9 -0
- package/dist/agent/self-improvement/skill-benchmark.js +22 -0
- package/dist/agent/self-improvement/skill-consolidator.d.ts +71 -0
- package/dist/agent/self-improvement/skill-consolidator.js +137 -0
- package/dist/agent/self-improvement/skill-engine.d.ts +42 -0
- package/dist/agent/self-improvement/skill-engine.js +87 -0
- package/dist/agent/self-improvement/skill-gate.d.ts +19 -0
- package/dist/agent/self-improvement/skill-gate.js +62 -0
- package/dist/agent/self-improvement/skill-mutator.d.ts +74 -0
- package/dist/agent/self-improvement/skill-mutator.js +223 -0
- package/dist/agent/self-improvement/skill-proposer.d.ts +40 -0
- package/dist/agent/self-improvement/skill-proposer.js +82 -0
- package/dist/agent/self-improvement/skill-types.d.ts +41 -0
- package/dist/agent/self-improvement/skill-types.js +13 -0
- package/dist/agent/self-improvement/tool-benchmark.d.ts +10 -0
- package/dist/agent/self-improvement/tool-benchmark.js +37 -0
- package/dist/agent/self-improvement/tool-engine.d.ts +54 -0
- package/dist/agent/self-improvement/tool-engine.js +101 -0
- package/dist/agent/self-improvement/tool-gate.d.ts +20 -0
- package/dist/agent/self-improvement/tool-gate.js +78 -0
- package/dist/agent/self-improvement/tool-proposer.d.ts +31 -0
- package/dist/agent/self-improvement/tool-proposer.js +34 -0
- package/dist/agent/self-improvement/tool-skill-mutator.d.ts +40 -0
- package/dist/agent/self-improvement/tool-skill-mutator.js +79 -0
- package/dist/agent/self-improvement/tool-types.d.ts +48 -0
- package/dist/agent/self-improvement/tool-types.js +9 -0
- package/dist/agent/self-improvement/types.d.ts +3 -1
- package/dist/agent/session-end-flush.d.ts +6 -1
- package/dist/agent/session-end-flush.js +20 -4
- package/dist/agent/streaming/streaming-handler.d.ts +7 -0
- package/dist/agent/streaming/streaming-handler.js +8 -1
- package/dist/agent/tool-executor.js +1 -0
- package/dist/agent/tool-handler.d.ts +5 -0
- package/dist/agent/tool-handler.js +133 -4
- package/dist/browser-automation/browser-operator-executor.js +15 -0
- package/dist/browser-automation/browser-use-runner.d.ts +96 -0
- package/dist/browser-automation/browser-use-runner.js +492 -0
- package/dist/browser-automation/camofox-runner.d.ts +107 -0
- package/dist/browser-automation/camofox-runner.js +287 -0
- package/dist/channels/dingtalk/index.js +3 -0
- package/dist/channels/discord/client.d.ts +9 -0
- package/dist/channels/discord/client.js +12 -0
- package/dist/channels/feishu/index.d.ts +167 -1
- package/dist/channels/feishu/index.js +432 -7
- package/dist/channels/gateway-lifecycle.d.ts +132 -0
- package/dist/channels/gateway-lifecycle.js +219 -0
- package/dist/channels/google-chat/index.d.ts +5 -1
- package/dist/channels/google-chat/index.js +5 -1
- package/dist/channels/imessage/index.d.ts +14 -0
- package/dist/channels/imessage/index.js +64 -17
- package/dist/channels/index.d.ts +4 -0
- package/dist/channels/index.js +4 -0
- package/dist/channels/irc/index.d.ts +73 -3
- package/dist/channels/irc/index.js +446 -11
- package/dist/channels/line/index.js +3 -0
- package/dist/channels/mattermost/index.d.ts +51 -4
- package/dist/channels/mattermost/index.js +303 -20
- package/dist/channels/nextcloud-talk/index.d.ts +89 -8
- package/dist/channels/nextcloud-talk/index.js +367 -16
- package/dist/channels/nostr/index.d.ts +121 -1
- package/dist/channels/nostr/index.js +396 -8
- package/dist/channels/ntfy/index.js +3 -0
- package/dist/channels/qq/index.js +3 -0
- package/dist/channels/slash-parity.d.ts +117 -0
- package/dist/channels/slash-parity.js +185 -0
- package/dist/channels/synology-chat/index.js +3 -0
- package/dist/channels/teams/index.d.ts +3 -0
- package/dist/channels/teams/index.js +3 -0
- package/dist/channels/telegram/client.d.ts +9 -0
- package/dist/channels/telegram/client.js +12 -0
- package/dist/channels/twilio-voice/index.js +3 -0
- package/dist/channels/webchat/index.d.ts +7 -1
- package/dist/channels/webchat/index.js +7 -1
- package/dist/channels/wecom/index.js +3 -0
- package/dist/channels/weixin/index.js +3 -0
- package/dist/channels/zalo/index.js +3 -0
- package/dist/cli/config-loader.js +1 -1
- package/dist/codebuddy/client.d.ts +30 -1
- package/dist/codebuddy/client.js +167 -20
- package/dist/codebuddy/providers/provider-chatgpt-responses.d.ts +5 -0
- package/dist/codebuddy/providers/provider-chatgpt-responses.js +7 -1
- package/dist/codebuddy/providers/provider-gemini-native.js +1 -1
- package/dist/codebuddy/providers/provider-openai-compat.d.ts +5 -0
- package/dist/codebuddy/providers/provider-openai-compat.js +82 -2
- package/dist/codebuddy/tool-definitions/computer-control-tools.js +32 -2
- package/dist/codebuddy/tool-definitions/core-tools.js +3 -3
- package/dist/codebuddy/tool-definitions/index.d.ts +2 -1
- package/dist/codebuddy/tool-definitions/index.js +2 -1
- package/dist/codebuddy/tool-definitions/multimodal-tools.d.ts +1 -0
- package/dist/codebuddy/tool-definitions/multimodal-tools.js +44 -1
- package/dist/codebuddy/tool-definitions/windows-tools.d.ts +2 -0
- package/dist/codebuddy/tool-definitions/windows-tools.js +34 -0
- package/dist/codebuddy/tools.d.ts +8 -1
- package/dist/codebuddy/tools.js +67 -24
- package/dist/commands/cli/hermes-commands.js +108 -0
- package/dist/commands/cli/improve-command.js +123 -0
- package/dist/commands/cli/native-engine-commands.js +102 -3
- package/dist/commands/cli/utility-commands.js +45 -0
- package/dist/commands/enhanced-command-handler.js +2 -2
- package/dist/commands/goal-cli.d.ts +30 -0
- package/dist/commands/goal-cli.js +210 -27
- package/dist/commands/handlers/goal-handler.d.ts +9 -2
- package/dist/commands/handlers/goal-handler.js +36 -9
- package/dist/commands/handlers/infra-handlers.js +36 -0
- package/dist/commands/handlers/memory-handlers.js +96 -1
- package/dist/commands/handlers/missing-handlers.d.ts +1 -1
- package/dist/commands/handlers/missing-handlers.js +26 -3
- package/dist/commands/headless-slash.d.ts +2 -0
- package/dist/commands/headless-slash.js +12 -0
- package/dist/commands/llm-provider-resolution.d.ts +5 -3
- package/dist/commands/llm-provider-resolution.js +87 -33
- package/dist/commands/ollama.d.ts +25 -0
- package/dist/commands/ollama.js +100 -0
- package/dist/commands/provider.d.ts +5 -0
- package/dist/commands/provider.js +106 -55
- package/dist/commands/skills-cli/index.js +123 -0
- package/dist/commands/slash/builtin-commands.js +1 -1
- package/dist/commands/spec-next.js +2 -1
- package/dist/commands/spec-plan.js +5 -16
- package/dist/commands/tunnel.d.ts +2 -0
- package/dist/commands/tunnel.js +48 -0
- package/dist/companion/percepts.js +11 -1
- package/dist/config/config-resolver.d.ts +2 -1
- package/dist/config/config-resolver.js +54 -41
- package/dist/config/constants.d.ts +28 -0
- package/dist/config/constants.js +7 -0
- package/dist/config/env-schema.js +756 -0
- package/dist/config/model-tools.js +4 -4
- package/dist/config/toml-config.d.ts +16 -0
- package/dist/config/toml-config.js +3 -0
- package/dist/context/bootstrap-loader.js +6 -23
- package/dist/context/context-manager-v2.js +1 -0
- package/dist/context/import-directive-parser.d.ts +4 -0
- package/dist/context/import-directive-parser.js +51 -6
- package/dist/context/instruction-excludes.d.ts +30 -1
- package/dist/context/instruction-excludes.js +71 -1
- package/dist/context/jit-context.d.ts +8 -10
- package/dist/context/jit-context.js +28 -106
- package/dist/context/project-context.d.ts +90 -0
- package/dist/context/project-context.js +295 -0
- package/dist/daemon/autonomous-daemon.d.ts +1 -1
- package/dist/daemon/autonomous-daemon.js +3 -3
- package/dist/daemon/autonomous-loop.d.ts +31 -1
- package/dist/daemon/autonomous-loop.js +91 -4
- package/dist/daemon/colab-goal.js +9 -1
- package/dist/daemon/cron-agent-bridge.d.ts +12 -3
- package/dist/daemon/cron-agent-bridge.js +25 -9
- package/dist/desktop/codebuddy-engine-adapter.d.ts +32 -0
- package/dist/desktop/codebuddy-engine-adapter.js +257 -80
- package/dist/desktop/engine-adapter.d.ts +14 -0
- package/dist/desktop-automation/automation-manager.js +16 -0
- package/dist/desktop-automation/omniparser-runner.d.ts +63 -0
- package/dist/desktop-automation/omniparser-runner.js +115 -0
- package/dist/desktop-automation/smart-snapshot.d.ts +11 -0
- package/dist/desktop-automation/smart-snapshot.js +72 -5
- package/dist/doctor/index.js +40 -23
- package/dist/events/types.d.ts +11 -0
- package/dist/fleet/colab-store.js +14 -2
- package/dist/fleet/peer-session-bridge.js +50 -12
- package/dist/fleet/peer-tool-bridge.js +14 -0
- package/dist/goals/goal-decomposer.d.ts +27 -0
- package/dist/goals/goal-decomposer.js +293 -0
- package/dist/goals/goal-judge-client.d.ts +15 -0
- package/dist/goals/goal-judge-client.js +45 -0
- package/dist/goals/goal-judge.d.ts +2 -0
- package/dist/goals/goal-judge.js +35 -6
- package/dist/goals/goal-loop.d.ts +14 -0
- package/dist/goals/goal-loop.js +47 -2
- package/dist/goals/goal-manager.d.ts +6 -0
- package/dist/goals/goal-manager.js +67 -14
- package/dist/goals/goal-state.d.ts +13 -0
- package/dist/goals/goal-state.js +83 -13
- package/dist/goals/goal-store.d.ts +3 -0
- package/dist/goals/goal-store.js +31 -15
- package/dist/harness/contract.d.ts +28 -28
- package/dist/hooks/user-hooks.js +17 -3
- package/dist/identity/identity-manager.js +3 -2
- package/dist/index.js +481 -26
- package/dist/input/text-to-speech.d.ts +2 -6
- package/dist/input/text-to-speech.js +2 -27
- package/dist/integrations/screenpipe/screenpipe-client.d.ts +10 -0
- package/dist/integrations/screenpipe/screenpipe-client.js +12 -2
- package/dist/integrations/tailscale.d.ts +13 -0
- package/dist/integrations/tailscale.js +87 -34
- package/dist/knowledge/workspace-indexer.js +53 -9
- package/dist/mcp/client.js +1 -0
- package/dist/mcp/mcp-desktop-tools.d.ts +23 -0
- package/dist/mcp/mcp-desktop-tools.js +158 -0
- package/dist/mcp/mcp-resources.js +2 -3
- package/dist/mcp/mcp-server.js +2 -0
- package/dist/memory/enhanced-memory.d.ts +10 -0
- package/dist/memory/enhanced-memory.js +33 -2
- package/dist/memory/index.d.ts +3 -1
- package/dist/memory/index.js +4 -1
- package/dist/memory/memory-auto-proposer.d.ts +23 -0
- package/dist/memory/memory-auto-proposer.js +308 -0
- package/dist/memory/memory-candidate-queue.d.ts +92 -0
- package/dist/memory/memory-candidate-queue.js +261 -0
- package/dist/memory/persistent-memory.d.ts +45 -2
- package/dist/memory/persistent-memory.js +236 -40
- package/dist/ml/bayesian-qualifier.d.ts +1 -1
- package/dist/ml/bayesian-qualifier.js +35 -2
- package/dist/openclaw/gateway-bridge.js +5 -0
- package/dist/plugins/marketplace.d.ts +1 -0
- package/dist/plugins/marketplace.js +7 -0
- package/dist/prompts/execution-discipline.d.ts +14 -0
- package/dist/prompts/execution-discipline.js +29 -0
- package/dist/prompts/variation-injector.js +9 -2
- package/dist/protocols/acp/acp-agentic-runner.d.ts +7 -6
- package/dist/protocols/acp/acp-agentic-runner.js +115 -18
- package/dist/protocols/acp/acp-session-store.d.ts +23 -0
- package/dist/protocols/acp/acp-session-store.js +77 -0
- package/dist/protocols/acp/acp-stdio-server.d.ts +7 -0
- package/dist/protocols/acp/acp-stdio-server.js +71 -16
- package/dist/providers/active-llm-registry.d.ts +37 -0
- package/dist/providers/active-llm-registry.js +186 -0
- package/dist/providers/auxiliary-provider.d.ts +25 -0
- package/dist/providers/auxiliary-provider.js +192 -0
- package/dist/providers/codex-oauth.d.ts +1 -1
- package/dist/providers/codex-oauth.js +27 -4
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/provider-catalog.d.ts +70 -0
- package/dist/providers/provider-catalog.js +738 -0
- package/dist/providers/provider-fallback.d.ts +35 -0
- package/dist/providers/provider-fallback.js +171 -0
- package/dist/providers/xai-oauth.d.ts +128 -0
- package/dist/providers/xai-oauth.js +735 -0
- package/dist/scheduler/cron-scheduler.d.ts +15 -3
- package/dist/scheduler/cron-scheduler.js +53 -7
- package/dist/scheduler/script-runner.d.ts +2 -0
- package/dist/scheduler/script-runner.js +19 -4
- package/dist/scheduler/watchdog-handlers.js +7 -20
- package/dist/search/usearch-index.js +7 -2
- package/dist/security/tool-policy/tool-groups.js +2 -0
- package/dist/sensory/dreaming.d.ts +45 -0
- package/dist/sensory/dreaming.js +114 -0
- package/dist/sensory/heartbeat-scheduler.d.ts +38 -0
- package/dist/sensory/heartbeat-scheduler.js +72 -0
- package/dist/sensory/reactions.d.ts +24 -0
- package/dist/sensory/reactions.js +31 -0
- package/dist/sensory/screen-reaction.d.ts +23 -0
- package/dist/sensory/screen-reaction.js +59 -0
- package/dist/sensory/sensory-bridge.d.ts +23 -0
- package/dist/sensory/sensory-bridge.js +85 -0
- package/dist/sensory/sensory-memory.d.ts +20 -0
- package/dist/sensory/sensory-memory.js +39 -0
- package/dist/sensory/speech-reaction.d.ts +21 -0
- package/dist/sensory/speech-reaction.js +83 -0
- package/dist/sensory/vision-reaction.d.ts +31 -0
- package/dist/sensory/vision-reaction.js +74 -0
- package/dist/server/index.js +106 -2
- package/dist/server/routes/mobile.d.ts +12 -4
- package/dist/server/routes/mobile.js +116 -1
- package/dist/server/tls-config.d.ts +35 -0
- package/dist/server/tls-config.js +142 -0
- package/dist/server/tunnel-manager.d.ts +20 -0
- package/dist/server/tunnel-manager.js +58 -0
- package/dist/server/websocket/fleet-bridge.js +5 -0
- package/dist/services/prompt-builder.d.ts +11 -0
- package/dist/services/prompt-builder.js +124 -17
- package/dist/shared/engine-types.d.ts +15 -1
- package/dist/sidecar/sidecar-bridge.d.ts +1 -0
- package/dist/sidecar/sidecar-bridge.js +21 -10
- package/dist/skills/parser.js +3 -0
- package/dist/skills/skill-importer.d.ts +58 -0
- package/dist/skills/skill-importer.js +261 -0
- package/dist/skills/skill-sources.d.ts +20 -0
- package/dist/skills/skill-sources.js +102 -0
- package/dist/skills/types.d.ts +6 -0
- package/dist/spec/spec-store.js +8 -1
- package/dist/talk-mode/providers/audioreader-tts.d.ts +1 -1
- package/dist/talk-mode/providers/audioreader-tts.js +8 -8
- package/dist/templates/project-scaffolding.js +3 -2
- package/dist/themes/theme-schema.d.ts +10 -10
- package/dist/tools/application-profiles.js +38 -0
- package/dist/tools/bash/bash-tool.d.ts +1 -0
- package/dist/tools/bash/bash-tool.js +16 -2
- package/dist/tools/bash/command-validator.js +3 -0
- package/dist/tools/bash/rtk-rewrite.d.ts +16 -0
- package/dist/tools/bash/rtk-rewrite.js +100 -0
- package/dist/tools/bash/streaming-executor.js +14 -1
- package/dist/tools/computer-control-tool.d.ts +16 -1
- package/dist/tools/computer-control-tool.js +317 -5
- package/dist/tools/document-generator.d.ts +14 -0
- package/dist/tools/document-generator.js +79 -0
- package/dist/tools/execute-code-rpc-invoker.d.ts +26 -2
- package/dist/tools/execute-code-rpc-invoker.js +46 -5
- package/dist/tools/metadata.js +28 -0
- package/dist/tools/office-macro-tool.d.ts +10 -0
- package/dist/tools/office-macro-tool.js +93 -0
- package/dist/tools/register-tool-handler.d.ts +25 -0
- package/dist/tools/register-tool-handler.js +100 -0
- package/dist/tools/registry/index.d.ts +2 -1
- package/dist/tools/registry/index.js +2 -1
- package/dist/tools/registry/memory-tools.d.ts +20 -0
- package/dist/tools/registry/memory-tools.js +225 -3
- package/dist/tools/registry/multimodal-tools.js +2 -2
- package/dist/tools/registry/vision-tools.d.ts +33 -0
- package/dist/tools/registry/vision-tools.js +308 -6
- package/dist/tools/registry/windows-tools.d.ts +2 -0
- package/dist/tools/registry/windows-tools.js +47 -0
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +8 -0
- package/dist/tools/route-peer-tool.js +14 -0
- package/dist/tools/screenshot-tool.js +14 -2
- package/dist/tools/text-to-speech-tool.d.ts +1 -1
- package/dist/tools/text-to-speech-tool.js +2 -12
- package/dist/tools/tool-selector.js +3 -59
- package/dist/utils/config-validation/schema.d.ts +40 -7
- package/dist/utils/config-validation/schema.js +130 -1
- package/dist/utils/cost-tracker.js +21 -1
- package/dist/utils/disk-guard.d.ts +180 -0
- package/dist/utils/disk-guard.js +404 -0
- package/dist/utils/init-project.d.ts +7 -0
- package/dist/utils/init-project.js +37 -0
- package/dist/utils/interactive-setup.js +35 -2
- package/dist/utils/model-utils.js +11 -2
- package/dist/utils/output-sanitizer.js +11 -0
- package/dist/utils/provider-detector.d.ts +8 -7
- package/dist/utils/provider-detector.js +19 -77
- package/dist/utils/settings-manager.d.ts +19 -0
- package/dist/utils/token-display.d.ts +3 -3
- package/dist/utils/token-display.js +22 -4
- package/dist/wizard/onboarding.d.ts +39 -0
- package/dist/wizard/onboarding.js +433 -21
- package/dist/wizard/provider-onboarding.d.ts +8 -23
- package/dist/wizard/provider-onboarding.js +39 -158
- package/package.json +4 -2
- package/dist/plugins/provider-onboarding.d.ts +0 -23
- package/dist/plugins/provider-onboarding.js +0 -116
- package/dist/utils/kokoro-tts.d.ts +0 -8
- package/dist/utils/kokoro-tts.js +0 -67
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored-artifact gate — the static (no-execution) safety scan applied to any
|
|
3
|
+
* code the agent authors for itself (tools or skill scripts) BEFORE it is run or
|
|
4
|
+
* registered. Blocking and ordered; the behavioural held-out scoring (which DOES
|
|
5
|
+
* run the code, sandboxed) lives in sandbox-scorer.ts and runs only after this.
|
|
6
|
+
*
|
|
7
|
+
* @module agent/self-improvement/authored-artifact-gate
|
|
8
|
+
*/
|
|
9
|
+
import { matchAllDangerousPatterns } from '../../security/dangerous-patterns.js';
|
|
10
|
+
/** Omission placeholders that signal truncated / non-self-contained code. */
|
|
11
|
+
const OMISSION_RE = /\/\/\s*\.\.\.\s*(rest|remaining|other|more|implementation|code)\b|#\s*\.\.\.\s*(rest|remaining)\b/i;
|
|
12
|
+
/** Obvious secret shapes — never let an authored artifact embed these. */
|
|
13
|
+
const SECRET_RE = /(sk-[a-z0-9]{16,}|api[_-]?key\s*[:=]\s*['"]?\S{12,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|ghp_[a-zA-Z0-9]{20,}|AKIA[0-9A-Z]{16})/i;
|
|
14
|
+
/** Writing under src/ is the hard self-modification invariant — refuse it. */
|
|
15
|
+
const SRC_WRITE_RE = /(writeFile|writeFileSync|appendFile\w*|fs\.\w*write|open\s*\([^)]*['"]w|>>?\s*['"]?\.{0,2}\/?src\/)/i;
|
|
16
|
+
const MAX_CODE_BYTES = 64 * 1024;
|
|
17
|
+
/**
|
|
18
|
+
* Statically inspect authored code. Returns ok=false with one or more reasons on
|
|
19
|
+
* any finding. `subsystem` selects the dangerous-pattern set ('code' for tools,
|
|
20
|
+
* 'skill' for skill scripts).
|
|
21
|
+
*/
|
|
22
|
+
export function inspectAuthoredCode(code, subsystem = 'code') {
|
|
23
|
+
const reasons = [];
|
|
24
|
+
const text = String(code ?? '');
|
|
25
|
+
if (!text.trim())
|
|
26
|
+
reasons.push('code is empty');
|
|
27
|
+
if (text.length > MAX_CODE_BYTES)
|
|
28
|
+
reasons.push(`code too large (${text.length} > ${MAX_CODE_BYTES} bytes)`);
|
|
29
|
+
const dangerous = matchAllDangerousPatterns(text, subsystem);
|
|
30
|
+
if (dangerous.length > 0) {
|
|
31
|
+
reasons.push(`matched ${dangerous.length} dangerous pattern(s): ${dangerous.map((d) => d.description).slice(0, 4).join('; ')}`);
|
|
32
|
+
}
|
|
33
|
+
if (SECRET_RE.test(text))
|
|
34
|
+
reasons.push('looks like it embeds a secret');
|
|
35
|
+
if (OMISSION_RE.test(text))
|
|
36
|
+
reasons.push('contains an omission placeholder (not self-contained)');
|
|
37
|
+
if (/src\//.test(text) && SRC_WRITE_RE.test(text)) {
|
|
38
|
+
reasons.push('writes under src/ (forbidden self-modification invariant)');
|
|
39
|
+
}
|
|
40
|
+
return { ok: reasons.length === 0, reasons };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=authored-artifact-gate.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored-tool runtime — shared by `register_tool` (the live capability) and the
|
|
3
|
+
* self-improvement engine's sandbox scorer (the gate). One definition of "how an
|
|
4
|
+
* authored tool runs" so the thing we GATE is exactly the thing we REGISTER.
|
|
5
|
+
*
|
|
6
|
+
* An authored tool runs its `code` SANDBOXED: a throwaway cwd, RPC off (no
|
|
7
|
+
* callback into the tool system), and its call arguments arrive as JSON in the
|
|
8
|
+
* CODEBUDDY_TOOL_INPUT env var; the script prints its result to stdout.
|
|
9
|
+
*
|
|
10
|
+
* @module agent/self-improvement/authored-tool-runtime
|
|
11
|
+
*/
|
|
12
|
+
import type { ITool } from '../../tools/registry/types.js';
|
|
13
|
+
import { type ExecuteCodeLanguage } from '../../tools/execute-code-runner.js';
|
|
14
|
+
export declare const AUTHORED_PREFIX = "authored__";
|
|
15
|
+
export declare const AUTHORED_LANGUAGES: ExecuteCodeLanguage[];
|
|
16
|
+
export interface AuthoredToolSpec {
|
|
17
|
+
/** Namespaced tool name (see toAuthoredName). */
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
parameters: Record<string, unknown>;
|
|
21
|
+
language: ExecuteCodeLanguage;
|
|
22
|
+
code: string;
|
|
23
|
+
}
|
|
24
|
+
/** Namespace + sanitize a raw tool name to `authored__<slug>` (never shadows a built-in). */
|
|
25
|
+
export declare function toAuthoredName(raw: string): string;
|
|
26
|
+
/** Build an ITool that runs the authored `code` sandboxed when invoked. */
|
|
27
|
+
export declare function buildAuthoredTool(spec: AuthoredToolSpec): ITool;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored-tool runtime — shared by `register_tool` (the live capability) and the
|
|
3
|
+
* self-improvement engine's sandbox scorer (the gate). One definition of "how an
|
|
4
|
+
* authored tool runs" so the thing we GATE is exactly the thing we REGISTER.
|
|
5
|
+
*
|
|
6
|
+
* An authored tool runs its `code` SANDBOXED: a throwaway cwd, RPC off (no
|
|
7
|
+
* callback into the tool system), and its call arguments arrive as JSON in the
|
|
8
|
+
* CODEBUDDY_TOOL_INPUT env var; the script prints its result to stdout.
|
|
9
|
+
*
|
|
10
|
+
* @module agent/self-improvement/authored-tool-runtime
|
|
11
|
+
*/
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import { randomUUID } from 'crypto';
|
|
15
|
+
import { executeCode } from '../../tools/execute-code-runner.js';
|
|
16
|
+
export const AUTHORED_PREFIX = 'authored__';
|
|
17
|
+
export const AUTHORED_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
18
|
+
/** Namespace + sanitize a raw tool name to `authored__<slug>` (never shadows a built-in). */
|
|
19
|
+
export function toAuthoredName(raw) {
|
|
20
|
+
const base = String(raw)
|
|
21
|
+
.trim()
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/[^a-z0-9_]+/g, '_')
|
|
24
|
+
.replace(/^_+|_+$/g, '');
|
|
25
|
+
return base.startsWith(AUTHORED_PREFIX) ? base : `${AUTHORED_PREFIX}${base || 'tool'}`;
|
|
26
|
+
}
|
|
27
|
+
/** Build an ITool that runs the authored `code` sandboxed when invoked. */
|
|
28
|
+
export function buildAuthoredTool(spec) {
|
|
29
|
+
const { name, description, parameters, language, code } = spec;
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
description,
|
|
33
|
+
async execute(input) {
|
|
34
|
+
const rootDir = path.join(os.tmpdir(), `cb-authored-${randomUUID()}`);
|
|
35
|
+
try {
|
|
36
|
+
const res = await executeCode({ code, language, env: { CODEBUDDY_TOOL_INPUT: JSON.stringify(input ?? {}) } }, { rootDir, rpcEnabled: false });
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: `authored tool "${name}" failed (exit ${res.exitCode}): ${res.stderr.slice(0, 2000) || res.error || 'no output'}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return { success: true, output: res.stdout.slice(0, 100_000) || '(no stdout)' };
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: `authored tool "${name}" error: ${err instanceof Error ? err.message : String(err)}`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
getSchema() {
|
|
53
|
+
return { name, description, parameters: parameters };
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=authored-tool-runtime.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored-tool store — durable persistence for tools the agent has authored and
|
|
3
|
+
* kept (auto-apply). Without this, authored tools live only for the session; with
|
|
4
|
+
* it, they are reloaded into both registries at startup so a self-improvement
|
|
5
|
+
* survives a restart. A flat JSON file alongside the evolutionary archive.
|
|
6
|
+
*
|
|
7
|
+
* @module agent/self-improvement/authored-tool-store
|
|
8
|
+
*/
|
|
9
|
+
import type { AuthoredToolSpec } from './authored-tool-runtime.js';
|
|
10
|
+
export declare const AUTHORED_TOOL_STORE_SCHEMA_VERSION = 1;
|
|
11
|
+
export interface AuthoredToolStoreOptions {
|
|
12
|
+
workDir?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class AuthoredToolStore {
|
|
15
|
+
private readonly filePath;
|
|
16
|
+
constructor(options?: AuthoredToolStoreOptions);
|
|
17
|
+
get path(): string;
|
|
18
|
+
private read;
|
|
19
|
+
private write;
|
|
20
|
+
list(): AuthoredToolSpec[];
|
|
21
|
+
/** Upsert a spec by name (a re-authored tool replaces the prior version). */
|
|
22
|
+
add(spec: AuthoredToolSpec): void;
|
|
23
|
+
remove(name: string): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored-tool store — durable persistence for tools the agent has authored and
|
|
3
|
+
* kept (auto-apply). Without this, authored tools live only for the session; with
|
|
4
|
+
* it, they are reloaded into both registries at startup so a self-improvement
|
|
5
|
+
* survives a restart. A flat JSON file alongside the evolutionary archive.
|
|
6
|
+
*
|
|
7
|
+
* @module agent/self-improvement/authored-tool-store
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
export const AUTHORED_TOOL_STORE_SCHEMA_VERSION = 1;
|
|
12
|
+
export class AuthoredToolStore {
|
|
13
|
+
filePath;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
const root = options.workDir ?? process.cwd();
|
|
16
|
+
this.filePath = path.join(root, '.codebuddy', 'self-improvement', 'authored-tools.json');
|
|
17
|
+
}
|
|
18
|
+
get path() {
|
|
19
|
+
return this.filePath;
|
|
20
|
+
}
|
|
21
|
+
read() {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(fs.readFileSync(this.filePath, 'utf-8'));
|
|
24
|
+
if (Array.isArray(parsed.tools)) {
|
|
25
|
+
return { schemaVersion: AUTHORED_TOOL_STORE_SCHEMA_VERSION, tools: parsed.tools };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* no store yet */
|
|
30
|
+
}
|
|
31
|
+
return { schemaVersion: AUTHORED_TOOL_STORE_SCHEMA_VERSION, tools: [] };
|
|
32
|
+
}
|
|
33
|
+
write(file) {
|
|
34
|
+
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
35
|
+
fs.writeFileSync(this.filePath, JSON.stringify(file, null, 2), 'utf-8');
|
|
36
|
+
}
|
|
37
|
+
list() {
|
|
38
|
+
return this.read().tools;
|
|
39
|
+
}
|
|
40
|
+
/** Upsert a spec by name (a re-authored tool replaces the prior version). */
|
|
41
|
+
add(spec) {
|
|
42
|
+
const file = this.read();
|
|
43
|
+
file.tools = file.tools.filter((t) => t.name !== spec.name);
|
|
44
|
+
file.tools.push(spec);
|
|
45
|
+
this.write(file);
|
|
46
|
+
}
|
|
47
|
+
remove(name) {
|
|
48
|
+
const file = this.read();
|
|
49
|
+
const before = file.tools.length;
|
|
50
|
+
file.tools = file.tools.filter((t) => t.name !== name);
|
|
51
|
+
if (file.tools.length === before)
|
|
52
|
+
return false;
|
|
53
|
+
this.write(file);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=authored-tool-store.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM tool proposer — authors a candidate tool with the agent's own model from a
|
|
3
|
+
* REDACTED scenario view (capability + visible cases only; never the held-out
|
|
4
|
+
* cases). The behavioural held-out gate validates every draft, so even a gamed or
|
|
5
|
+
* broken draft is caught — the LLM is a generator, not a trusted oracle.
|
|
6
|
+
*
|
|
7
|
+
* Lazy + graceful: if no provider is configured the proposer declines (null) and
|
|
8
|
+
* the engine simply finds no proposal.
|
|
9
|
+
*
|
|
10
|
+
* @module agent/self-improvement/llm-tool-proposer
|
|
11
|
+
*/
|
|
12
|
+
import { type AuthoredToolSpec } from './authored-tool-runtime.js';
|
|
13
|
+
import type { ProposerScenarioView, ToolProposer } from './tool-proposer.js';
|
|
14
|
+
import type { ToolProposal } from './tool-types.js';
|
|
15
|
+
interface MinimalClient {
|
|
16
|
+
chat(messages: Array<{
|
|
17
|
+
role: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}>, tools?: unknown[]): Promise<{
|
|
20
|
+
choices?: Array<{
|
|
21
|
+
message?: {
|
|
22
|
+
content?: string | null;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildToolDraftPrompt(view: ProposerScenarioView): string;
|
|
28
|
+
/** Parse + validate a model draft into an AuthoredToolSpec, or null. */
|
|
29
|
+
export declare function parseToolDraft(text: string): AuthoredToolSpec | null;
|
|
30
|
+
export interface LlmToolProposerOptions {
|
|
31
|
+
/** Override the chat client (tests). Defaults to provider-detected CodeBuddyClient. */
|
|
32
|
+
client?: MinimalClient | null;
|
|
33
|
+
}
|
|
34
|
+
export declare class LlmToolProposer implements ToolProposer {
|
|
35
|
+
private readonly options;
|
|
36
|
+
private clientPromise;
|
|
37
|
+
constructor(options?: LlmToolProposerOptions);
|
|
38
|
+
private getClient;
|
|
39
|
+
propose(view: ProposerScenarioView): Promise<ToolProposal | null>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM tool proposer — authors a candidate tool with the agent's own model from a
|
|
3
|
+
* REDACTED scenario view (capability + visible cases only; never the held-out
|
|
4
|
+
* cases). The behavioural held-out gate validates every draft, so even a gamed or
|
|
5
|
+
* broken draft is caught — the LLM is a generator, not a trusted oracle.
|
|
6
|
+
*
|
|
7
|
+
* Lazy + graceful: if no provider is configured the proposer declines (null) and
|
|
8
|
+
* the engine simply finds no proposal.
|
|
9
|
+
*
|
|
10
|
+
* @module agent/self-improvement/llm-tool-proposer
|
|
11
|
+
*/
|
|
12
|
+
import { AUTHORED_LANGUAGES, toAuthoredName } from './authored-tool-runtime.js';
|
|
13
|
+
export function buildToolDraftPrompt(view) {
|
|
14
|
+
const examples = view.visibleCases
|
|
15
|
+
.map((c, i) => ` ${i + 1}. input ${JSON.stringify(c.input)} → output must contain ${JSON.stringify(c.expectIncludes)}`)
|
|
16
|
+
.join('\n');
|
|
17
|
+
return [
|
|
18
|
+
`Author a small, self-contained tool for this capability:`,
|
|
19
|
+
` ${view.capability}`,
|
|
20
|
+
``,
|
|
21
|
+
`Example behaviour (these are ONLY examples — the tool must GENERALIZE to any valid input;`,
|
|
22
|
+
`do NOT hardcode these outputs, that will be rejected by a held-out check):`,
|
|
23
|
+
examples,
|
|
24
|
+
``,
|
|
25
|
+
`The tool runs as a standalone script: it reads its arguments as JSON from the`,
|
|
26
|
+
`environment variable CODEBUDDY_TOOL_INPUT and prints ONLY its result to stdout.`,
|
|
27
|
+
`It must not touch the network or the filesystem.`,
|
|
28
|
+
``,
|
|
29
|
+
`Return ONLY a JSON object (no prose, no code fence) with exactly these fields:`,
|
|
30
|
+
`{"name": "<short_snake_case>", "description": "<one line>",`,
|
|
31
|
+
` "params": <JSON Schema for the input object>,`,
|
|
32
|
+
` "language": "javascript" | "python",`,
|
|
33
|
+
` "code": "<the full script source>"}`,
|
|
34
|
+
].join('\n');
|
|
35
|
+
}
|
|
36
|
+
/** Extract the first balanced top-level JSON object from a model response. */
|
|
37
|
+
function extractJsonObject(text) {
|
|
38
|
+
const start = text.indexOf('{');
|
|
39
|
+
if (start < 0)
|
|
40
|
+
return null;
|
|
41
|
+
let depth = 0;
|
|
42
|
+
let inStr = false;
|
|
43
|
+
let esc = false;
|
|
44
|
+
for (let i = start; i < text.length; i++) {
|
|
45
|
+
const ch = text[i];
|
|
46
|
+
if (inStr) {
|
|
47
|
+
if (esc)
|
|
48
|
+
esc = false;
|
|
49
|
+
else if (ch === '\\')
|
|
50
|
+
esc = true;
|
|
51
|
+
else if (ch === '"')
|
|
52
|
+
inStr = false;
|
|
53
|
+
}
|
|
54
|
+
else if (ch === '"')
|
|
55
|
+
inStr = true;
|
|
56
|
+
else if (ch === '{')
|
|
57
|
+
depth++;
|
|
58
|
+
else if (ch === '}') {
|
|
59
|
+
depth--;
|
|
60
|
+
if (depth === 0)
|
|
61
|
+
return text.slice(start, i + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** Parse + validate a model draft into an AuthoredToolSpec, or null. */
|
|
67
|
+
export function parseToolDraft(text) {
|
|
68
|
+
const json = extractJsonObject(text);
|
|
69
|
+
if (!json)
|
|
70
|
+
return null;
|
|
71
|
+
let raw;
|
|
72
|
+
try {
|
|
73
|
+
raw = JSON.parse(json);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const name = String(raw.name ?? '').trim();
|
|
79
|
+
const description = String(raw.description ?? '').trim();
|
|
80
|
+
const code = typeof raw.code === 'string' ? raw.code : '';
|
|
81
|
+
const language = String(raw.language ?? 'javascript').toLowerCase();
|
|
82
|
+
if (!name || !description || !code.trim())
|
|
83
|
+
return null;
|
|
84
|
+
if (!AUTHORED_LANGUAGES.includes(language))
|
|
85
|
+
return null;
|
|
86
|
+
const parameters = raw.params && typeof raw.params === 'object'
|
|
87
|
+
? raw.params
|
|
88
|
+
: { type: 'object', properties: {} };
|
|
89
|
+
return { name: toAuthoredName(name), description, parameters, language, code };
|
|
90
|
+
}
|
|
91
|
+
export class LlmToolProposer {
|
|
92
|
+
options;
|
|
93
|
+
clientPromise;
|
|
94
|
+
constructor(options = {}) {
|
|
95
|
+
this.options = options;
|
|
96
|
+
this.clientPromise = options.client !== undefined ? Promise.resolve(options.client) : null;
|
|
97
|
+
}
|
|
98
|
+
getClient() {
|
|
99
|
+
if (!this.clientPromise) {
|
|
100
|
+
this.clientPromise = (async () => {
|
|
101
|
+
try {
|
|
102
|
+
const { detectProviderFromEnv } = await import('../../utils/provider-detector.js');
|
|
103
|
+
const { CodeBuddyClient } = await import('../../codebuddy/client.js');
|
|
104
|
+
const detected = detectProviderFromEnv();
|
|
105
|
+
if (!detected)
|
|
106
|
+
return null;
|
|
107
|
+
return new CodeBuddyClient(detected.apiKey, detected.defaultModel, detected.baseURL);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
}
|
|
114
|
+
return this.clientPromise;
|
|
115
|
+
}
|
|
116
|
+
async propose(view) {
|
|
117
|
+
const client = await this.getClient();
|
|
118
|
+
if (!client)
|
|
119
|
+
return null;
|
|
120
|
+
try {
|
|
121
|
+
const prompt = buildToolDraftPrompt(view);
|
|
122
|
+
const response = await client.chat([{ role: 'user', content: prompt }], []);
|
|
123
|
+
const text = response?.choices?.[0]?.message?.content?.trim();
|
|
124
|
+
if (!text)
|
|
125
|
+
return null;
|
|
126
|
+
const spec = parseToolDraft(text);
|
|
127
|
+
if (!spec)
|
|
128
|
+
return null;
|
|
129
|
+
return { id: `llm-tool:${view.id}`, targetScenarioId: view.id, spec };
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=llm-tool-proposer.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox scorer — behavioural scoring of an authored tool. Builds the tool and
|
|
3
|
+
* RUNS it (sandboxed, via authored-tool-runtime: throwaway cwd, RPC off) on a set
|
|
4
|
+
* of cases, asserting the output. The tool is NOT registered to score it, so a
|
|
5
|
+
* rejected proposal leaves both registries untouched (no rollback needed).
|
|
6
|
+
*
|
|
7
|
+
* @module agent/self-improvement/sandbox-scorer
|
|
8
|
+
*/
|
|
9
|
+
import { type AuthoredToolSpec } from './authored-tool-runtime.js';
|
|
10
|
+
import type { ToolCase } from './tool-types.js';
|
|
11
|
+
export interface ToolScore {
|
|
12
|
+
passed: number;
|
|
13
|
+
total: number;
|
|
14
|
+
failures: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Run the authored tool over `cases`; a case passes if its output contains all expectIncludes. */
|
|
17
|
+
export declare function scoreToolCases(spec: AuthoredToolSpec, cases: ToolCase[]): Promise<ToolScore>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox scorer — behavioural scoring of an authored tool. Builds the tool and
|
|
3
|
+
* RUNS it (sandboxed, via authored-tool-runtime: throwaway cwd, RPC off) on a set
|
|
4
|
+
* of cases, asserting the output. The tool is NOT registered to score it, so a
|
|
5
|
+
* rejected proposal leaves both registries untouched (no rollback needed).
|
|
6
|
+
*
|
|
7
|
+
* @module agent/self-improvement/sandbox-scorer
|
|
8
|
+
*/
|
|
9
|
+
import { buildAuthoredTool } from './authored-tool-runtime.js';
|
|
10
|
+
/** Run the authored tool over `cases`; a case passes if its output contains all expectIncludes. */
|
|
11
|
+
export async function scoreToolCases(spec, cases) {
|
|
12
|
+
const tool = buildAuthoredTool(spec);
|
|
13
|
+
const failures = [];
|
|
14
|
+
let passed = 0;
|
|
15
|
+
for (let i = 0; i < cases.length; i++) {
|
|
16
|
+
const c = cases[i];
|
|
17
|
+
let output = '';
|
|
18
|
+
let ok = true;
|
|
19
|
+
try {
|
|
20
|
+
const res = await tool.execute(c.input);
|
|
21
|
+
output = `${res.output ?? ''}`;
|
|
22
|
+
if (!res.success) {
|
|
23
|
+
ok = false;
|
|
24
|
+
failures.push(`case ${i}: tool errored (${(res.error ?? '').slice(0, 120)})`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
ok = false;
|
|
29
|
+
failures.push(`case ${i}: threw (${err instanceof Error ? err.message : String(err)})`);
|
|
30
|
+
}
|
|
31
|
+
if (ok) {
|
|
32
|
+
const missing = c.expectIncludes.filter((s) => !output.includes(s));
|
|
33
|
+
if (missing.length > 0) {
|
|
34
|
+
failures.push(`case ${i}: output missing ${JSON.stringify(missing)} (got ${JSON.stringify(output.slice(0, 80))})`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
passed++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { passed, total: cases.length, failures };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=sandbox-scorer.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-knowledge — the prompt block that makes Code Buddy aware it can extend
|
|
3
|
+
* and improve itself, and the hard limits on doing so.
|
|
4
|
+
*
|
|
5
|
+
* Injected (gated) by the prompt builder when `CODEBUDDY_SELF_IMPROVE=true`.
|
|
6
|
+
* Kept tiny and stable so it doesn't disturb prompt-cache stability.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildSelfKnowledgeBlock(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-knowledge — the prompt block that makes Code Buddy aware it can extend
|
|
3
|
+
* and improve itself, and the hard limits on doing so.
|
|
4
|
+
*
|
|
5
|
+
* Injected (gated) by the prompt builder when `CODEBUDDY_SELF_IMPROVE=true`.
|
|
6
|
+
* Kept tiny and stable so it doesn't disturb prompt-cache stability.
|
|
7
|
+
*/
|
|
8
|
+
export function buildSelfKnowledgeBlock() {
|
|
9
|
+
return [
|
|
10
|
+
'You are Code Buddy — a coding agent that can extend and improve itself.',
|
|
11
|
+
'',
|
|
12
|
+
'- You can author a NEW tool for yourself with `register_tool` (name, description,',
|
|
13
|
+
' params, language, code). Once registered it is namespaced `authored__<name>` and',
|
|
14
|
+
' becomes callable by you on your next turn — the code you build can call your own tools.',
|
|
15
|
+
'- You can author/edit skills with `skill_manage`.',
|
|
16
|
+
'- Self-extensions are gated for safety: authored code is scanned for secrets and',
|
|
17
|
+
' dangerous patterns, runs sandboxed, and is kept only if it measurably helps.',
|
|
18
|
+
'- HARD LIMIT: you may NOT modify your own source under `src/`. That invariant',
|
|
19
|
+
' exists so an improvement can never weaken the gates that validate it.',
|
|
20
|
+
'- When a task would benefit from a reusable capability you do not yet have,',
|
|
21
|
+
' consider authoring a small, well-scoped tool for it, then call it.',
|
|
22
|
+
].join('\n');
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=self-knowledge.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed coverage benchmark for self-authored SKILLS. Each scenario is a situation
|
|
3
|
+
* the agent should have reusable guidance for; an authored skill "covers" it when
|
|
4
|
+
* its content surfaces the expected terms. Curated separately from any proposer.
|
|
5
|
+
*
|
|
6
|
+
* @module agent/self-improvement/skill-benchmark
|
|
7
|
+
*/
|
|
8
|
+
import type { SkillBenchmarkScenario } from './skill-types.js';
|
|
9
|
+
export declare const SEED_SKILL_SCENARIOS: SkillBenchmarkScenario[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed coverage benchmark for self-authored SKILLS. Each scenario is a situation
|
|
3
|
+
* the agent should have reusable guidance for; an authored skill "covers" it when
|
|
4
|
+
* its content surfaces the expected terms. Curated separately from any proposer.
|
|
5
|
+
*
|
|
6
|
+
* @module agent/self-improvement/skill-benchmark
|
|
7
|
+
*/
|
|
8
|
+
export const SEED_SKILL_SCENARIOS = [
|
|
9
|
+
{
|
|
10
|
+
id: 'git-bisect',
|
|
11
|
+
query: 'find which commit introduced a regression',
|
|
12
|
+
expectIncludes: ['git bisect', 'good', 'bad'],
|
|
13
|
+
description: 'guidance for bisecting a regression',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'safe-delete',
|
|
17
|
+
query: 'delete files safely without losing data',
|
|
18
|
+
expectIncludes: ['backup', 'dry run', 'confirm'],
|
|
19
|
+
description: 'guidance for deleting files safely',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
//# sourceMappingURL=skill-benchmark.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill consolidator — merges a CLUSTER of overlapping authored skills into one
|
|
3
|
+
* "umbrella" skill (Hermes's idea) but with OUR distinctive safety net: the merge
|
|
4
|
+
* is accepted only if the umbrella still passes the firewall AND COVERS EVERY
|
|
5
|
+
* scenario the absorbed siblings covered. A merge that drops coverage is rejected
|
|
6
|
+
* (Hermes consolidates by LLM judgment alone; we gate it empirically).
|
|
7
|
+
*
|
|
8
|
+
* Operates only on authored-* skills; pinned siblings are skipped (kept intact);
|
|
9
|
+
* absorbed siblings are ARCHIVED (recoverable), never deleted; each is recorded in
|
|
10
|
+
* the evolutionary archive with `absorbedInto` for audit.
|
|
11
|
+
*
|
|
12
|
+
* @module agent/self-improvement/skill-consolidator
|
|
13
|
+
*/
|
|
14
|
+
import { EvolutionaryArchive } from './evolutionary-archive.js';
|
|
15
|
+
import { LiveSkillMutator } from './skill-mutator.js';
|
|
16
|
+
import type { SkillBenchmarkScenario } from './skill-types.js';
|
|
17
|
+
export interface ClusterSibling {
|
|
18
|
+
name: string;
|
|
19
|
+
scenario: SkillBenchmarkScenario;
|
|
20
|
+
}
|
|
21
|
+
export interface ConsolidationCluster {
|
|
22
|
+
siblings: ClusterSibling[];
|
|
23
|
+
}
|
|
24
|
+
export interface UmbrellaProposal {
|
|
25
|
+
name: string;
|
|
26
|
+
content: string;
|
|
27
|
+
}
|
|
28
|
+
export interface UmbrellaProposer {
|
|
29
|
+
propose(cluster: ConsolidationCluster): Promise<UmbrellaProposal | null>;
|
|
30
|
+
}
|
|
31
|
+
export type ConsolidationRejection = 'cluster-too-small' | 'no-proposal' | 'firewall' | 'coverage-loss';
|
|
32
|
+
export interface ConsolidationOutcome {
|
|
33
|
+
accepted: boolean;
|
|
34
|
+
umbrellaName?: string;
|
|
35
|
+
absorbed: string[];
|
|
36
|
+
skippedPinned: string[];
|
|
37
|
+
rejectionReason?: ConsolidationRejection;
|
|
38
|
+
reasons: string[];
|
|
39
|
+
}
|
|
40
|
+
/** Build a cluster from installed authored skills that map to a known scenario. */
|
|
41
|
+
export declare function buildClusterFromInstalled(mutator: LiveSkillMutator, scenarios: SkillBenchmarkScenario[]): ConsolidationCluster;
|
|
42
|
+
export declare function consolidateCluster(cluster: ConsolidationCluster, proposer: UmbrellaProposer, mutator: LiveSkillMutator, archive: EvolutionaryArchive, options: {
|
|
43
|
+
keepOnAccept: boolean;
|
|
44
|
+
}): Promise<ConsolidationOutcome>;
|
|
45
|
+
/** Deterministic umbrella proposer (fixture for tests). */
|
|
46
|
+
export declare class StaticUmbrellaProposer implements UmbrellaProposer {
|
|
47
|
+
private readonly umbrella;
|
|
48
|
+
constructor(umbrella: UmbrellaProposal | null);
|
|
49
|
+
propose(): Promise<UmbrellaProposal | null>;
|
|
50
|
+
}
|
|
51
|
+
interface MinimalClient {
|
|
52
|
+
chat(messages: Array<{
|
|
53
|
+
role: string;
|
|
54
|
+
content: string;
|
|
55
|
+
}>, tools?: unknown[]): Promise<{
|
|
56
|
+
choices?: Array<{
|
|
57
|
+
message?: {
|
|
58
|
+
content?: string | null;
|
|
59
|
+
};
|
|
60
|
+
}>;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
export declare class LlmUmbrellaProposer implements UmbrellaProposer {
|
|
64
|
+
private clientPromise;
|
|
65
|
+
constructor(options?: {
|
|
66
|
+
client?: MinimalClient | null;
|
|
67
|
+
});
|
|
68
|
+
private getClient;
|
|
69
|
+
propose(cluster: ConsolidationCluster): Promise<UmbrellaProposal | null>;
|
|
70
|
+
}
|
|
71
|
+
export {};
|