diff --git a/.gitattributes b/.gitattributes index 18177b31a5..27a99603b2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ packages/core/migration/**/snapshot.json linguist-generated packages/core/src/database/migration.gen.ts linguist-generated +packages/core/src/**/*.txt text eol=lf diff --git a/bun.lock b/bun.lock index 87354a2d82..cac06d1303 100644 --- a/bun.lock +++ b/bun.lock @@ -30,6 +30,27 @@ "turbo": "2.10.2", }, }, + "packages/ai": { + "name": "@opencode-ai/ai", + "version": "1.17.20", + "dependencies": { + "@opencode-ai/schema": "workspace:*", + "@smithy/eventstream-codec": "4.2.14", + "@smithy/util-utf8": "4.2.2", + "aws4fetch": "1.0.20", + "effect": "catalog:", + "google-auth-library": "10.5.0", + }, + "devDependencies": { + "@clack/prompts": "1.0.0-alpha.1", + "@effect/platform-node": "catalog:", + "@opencode-ai/http-recorder": "workspace:*", + "@tsconfig/bun": "catalog:", + "@types/bun": "catalog:", + "@typescript/native-preview": "catalog:", + "typescript": "catalog:", + }, + }, "packages/app": { "name": "@opencode-ai/app", "version": "1.17.20", @@ -168,7 +189,6 @@ "@tsconfig/bun": "catalog:", "@types/bun": "catalog:", "@typescript/native-preview": "catalog:", - "typescript": "catalog:", }, }, "packages/console/app": { @@ -336,10 +356,10 @@ "@modelcontextprotocol/sdk": "1.29.0", "@npmcli/arborist": "9.4.0", "@npmcli/config": "10.8.1", + "@opencode-ai/ai": "workspace:*", "@opencode-ai/codemode": "workspace:*", "@opencode-ai/effect-drizzle-sqlite": "workspace:*", "@opencode-ai/effect-sqlite-node": "workspace:*", - "@opencode-ai/ai": "workspace:*", "@opencode-ai/plugin": "workspace:*", "@opencode-ai/schema": "workspace:*", "@openrouter/ai-sdk-provider": "2.9.0", @@ -562,26 +582,6 @@ "@typescript/native-preview": "catalog:", }, }, - "packages/ai": { - "name": "@opencode-ai/ai", - "version": "1.17.20", - "dependencies": { - "@opencode-ai/schema": "workspace:*", - "@smithy/eventstream-codec": "4.2.14", - "@smithy/util-utf8": "4.2.2", - "aws4fetch": "1.0.20", - "effect": "catalog:", - "google-auth-library": "10.5.0", - }, - "devDependencies": { - "@clack/prompts": "1.0.0-alpha.1", - "@effect/platform-node": "catalog:", - "@opencode-ai/http-recorder": "workspace:*", - "@tsconfig/bun": "catalog:", - "@types/bun": "catalog:", - "@typescript/native-preview": "catalog:", - }, - }, "packages/opencode": { "name": "opencode", "version": "1.17.20", @@ -621,10 +621,10 @@ "@octokit/graphql": "9.0.2", "@octokit/rest": "catalog:", "@openauthjs/openauth": "catalog:", + "@opencode-ai/ai": "workspace:*", "@opencode-ai/cli": "workspace:*", "@opencode-ai/client": "workspace:*", "@opencode-ai/codemode": "workspace:*", - "@opencode-ai/ai": "workspace:*", "@opencode-ai/plugin": "workspace:*", "@opencode-ai/protocol": "workspace:*", "@opencode-ai/schema": "workspace:*", @@ -885,8 +885,8 @@ "dependencies": { "@fontsource/commit-mono": "5.2.5", "@napi-rs/canvas": "1.0.2", - "@opencode-ai/core": "workspace:*", "@opencode-ai/ai": "workspace:*", + "@opencode-ai/core": "workspace:*", "@opentui/core": "catalog:", "effect": "catalog:", }, @@ -2168,6 +2168,8 @@ "@openauthjs/openauth": ["@openauthjs/openauth@0.0.0-20250322224806", "", { "dependencies": { "@standard-schema/spec": "1.0.0-beta.3", "aws4fetch": "1.0.20", "jose": "5.9.6" }, "peerDependencies": { "arctic": "^2.2.2", "hono": "^4.0.0" } }, "sha512-p5IWSRXvABcwocH2dNI0w8c1QJelIOFulwhKk+aLLFfUbs8u1pr7kQbYe8yCSM2+bcLHiwbogpUQc2ovrGwCuw=="], + "@opencode-ai/ai": ["@opencode-ai/ai@workspace:packages/ai"], + "@opencode-ai/app": ["@opencode-ai/app@workspace:packages/app"], "@opencode-ai/cli": ["@opencode-ai/cli@workspace:packages/cli"], @@ -2206,8 +2208,6 @@ "@opencode-ai/httpapi-codegen": ["@opencode-ai/httpapi-codegen@workspace:packages/httpapi-codegen"], - "@opencode-ai/ai": ["@opencode-ai/ai@workspace:packages/ai"], - "@opencode-ai/plugin": ["@opencode-ai/plugin@workspace:packages/plugin"], "@opencode-ai/protocol": ["@opencode-ai/protocol@workspace:packages/protocol"], @@ -2872,7 +2872,7 @@ "@smithy/credential-provider-imds": ["@smithy/credential-provider-imds@4.3.6", "", { "dependencies": { "@smithy/core": "^3.24.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-tHhdiWZfG1ZIh2YcRfPJmY2gHcBmqbAzqm3ER4TIDFYsSEqTD5tICT7cgQ/kI8LRakxp12myOYyK68XPn7MnHw=="], - "@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.7", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.11.0", "@smithy/util-hex-encoding": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-DrpkEoM3j9cBBWhufqBwnbbn+3nf1N9FP6xuVJ+e220jbactKuQgaZwjwP5CP1t+O94brm2JgVMD2atMGX3xIQ=="], + "@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.14", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.14.1", "@smithy/util-hex-encoding": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-erZq0nOIpzfeZdCyzZjdJb4nVSKLUmSkaQUVkRGQTXs30gyUGeKnrYEg+Xe1W5gE3aReS7IgsvANwVPxSzY6Pw=="], "@smithy/eventstream-serde-browser": ["@smithy/eventstream-serde-browser@4.3.5", "", { "dependencies": { "@smithy/core": "^3.24.5", "tslib": "^2.6.2" } }, "sha512-M9rMkTar7JcRrvUHsK1271AuWDmrISIPQpQ4TSHmYZ4KMisGnMH0gfjCWnBwdndR7skvvp/UheHhZGvO3Cr8/g=="], @@ -2946,7 +2946,7 @@ "@smithy/util-stream": ["@smithy/util-stream@4.6.5", "", { "dependencies": { "@smithy/core": "^3.24.5", "tslib": "^2.6.2" } }, "sha512-PFzBVEBP5k8R+mK/c+VAKmtpUTL+KzBIXWJ6oM0GWOb31K+QgymXV9IW03XLPM1wtkC7oAb9ZBN2aswSSVbNFg=="], - "@smithy/util-utf8": ["@smithy/util-utf8@4.2.0", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-zBPfuzoI8xyBtR2P6WQj63Rz8i3AmfAaJLuNG8dWsfvPe8lO4aCPYLn879mEgHndZH1zQ2oXmG8O1GGzzaoZiw=="], + "@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], "@smithy/util-waiter": ["@smithy/util-waiter@4.4.5", "", { "dependencies": { "@smithy/core": "^3.24.5", "tslib": "^2.6.2" } }, "sha512-EYviebytZE6vplW0AGwZ2Rc3sNuVR83lfUCNZu11VchUiKhMwJqrRWy7iVDTNEwG/vEwItno591Iad6/prj6Bw=="], @@ -6336,10 +6336,6 @@ "@ai-sdk/amazon-bedrock/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.27", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ubkAJ+xODouwtmN1tYlvTPphH1hPOBfZaEQe8U7skGvFAnIRs9PPpsq57bC2+Ky/MB4yzhd6YOsxTAx9sGpazw=="], - "@ai-sdk/amazon-bedrock/@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.14", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.14.1", "@smithy/util-hex-encoding": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-erZq0nOIpzfeZdCyzZjdJb4nVSKLUmSkaQUVkRGQTXs30gyUGeKnrYEg+Xe1W5gE3aReS7IgsvANwVPxSzY6Pw=="], - - "@ai-sdk/amazon-bedrock/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@ai-sdk/anthropic/@ai-sdk/provider": ["@ai-sdk/provider@3.0.10", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-Q3BZ27qfpYqnCYGvE3vt+Qi6LGOF9R5Nmzn+9JoM1lCRsD9mYaIhfJLkSunN48nfGXJ6n+XNV0J/XVpqGQl7Dw=="], "@ai-sdk/anthropic/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.27", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ubkAJ+xODouwtmN1tYlvTPphH1hPOBfZaEQe8U7skGvFAnIRs9PPpsq57bC2+Ky/MB4yzhd6YOsxTAx9sGpazw=="], @@ -6458,26 +6454,18 @@ "@aws-crypto/util/@smithy/util-utf8": ["@smithy/util-utf8@2.3.0", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="], - "@aws-sdk/client-athena/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/client-cognito-identity/@aws-sdk/core": ["@aws-sdk/core@3.974.15", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@aws-sdk/xml-builder": "^3.972.26", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/core": "^3.24.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-UpA0rTGW/tHGITcCqHisbuuEPraYg9GG+mWmXjY5+RxZBMLGe6aL9oe0ix50LztwAcPIkGZLH0yWdMIkCM10hw=="], "@aws-sdk/client-cognito-identity/@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.972.47", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.41", "@aws-sdk/credential-provider-http": "^3.972.43", "@aws-sdk/credential-provider-ini": "^3.972.46", "@aws-sdk/credential-provider-process": "^3.972.41", "@aws-sdk/credential-provider-sso": "^3.972.45", "@aws-sdk/credential-provider-web-identity": "^3.972.45", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/credential-provider-imds": "^4.3.6", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-HrId+C0DWA5qDIyLG64/kjUB2RNtPypxmABnIctK+TA1P1kHlOYoE/Wf5T5tKOMKgb08P7k/zNyhvfJ3lh5Oag=="], "@aws-sdk/client-cognito-identity/@aws-sdk/types": ["@aws-sdk/types@3.973.9", "", { "dependencies": { "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-kuBfgQVdcz5Bmapc4A13YbpVw/pXkesfhetcFYwbntqas8sF41OHyd4o28+/TG2ZQdHBsv90Lsu5y6oitvYCdg=="], - "@aws-sdk/client-firehose/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/client-lambda/@aws-sdk/core": ["@aws-sdk/core@3.974.15", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@aws-sdk/xml-builder": "^3.972.26", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/core": "^3.24.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-UpA0rTGW/tHGITcCqHisbuuEPraYg9GG+mWmXjY5+RxZBMLGe6aL9oe0ix50LztwAcPIkGZLH0yWdMIkCM10hw=="], "@aws-sdk/client-lambda/@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.972.47", "", { "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.41", "@aws-sdk/credential-provider-http": "^3.972.43", "@aws-sdk/credential-provider-ini": "^3.972.46", "@aws-sdk/credential-provider-process": "^3.972.41", "@aws-sdk/credential-provider-sso": "^3.972.45", "@aws-sdk/credential-provider-web-identity": "^3.972.45", "@aws-sdk/types": "^3.973.9", "@smithy/core": "^3.24.5", "@smithy/credential-provider-imds": "^4.3.6", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-HrId+C0DWA5qDIyLG64/kjUB2RNtPypxmABnIctK+TA1P1kHlOYoE/Wf5T5tKOMKgb08P7k/zNyhvfJ3lh5Oag=="], "@aws-sdk/client-lambda/@aws-sdk/types": ["@aws-sdk/types@3.973.9", "", { "dependencies": { "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-kuBfgQVdcz5Bmapc4A13YbpVw/pXkesfhetcFYwbntqas8sF41OHyd4o28+/TG2ZQdHBsv90Lsu5y6oitvYCdg=="], - "@aws-sdk/client-s3/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - - "@aws-sdk/client-sso/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/client-sts/@aws-sdk/core": ["@aws-sdk/core@3.775.0", "", { "dependencies": { "@aws-sdk/types": "3.775.0", "@smithy/core": "^3.2.0", "@smithy/node-config-provider": "^4.0.2", "@smithy/property-provider": "^4.0.2", "@smithy/protocol-http": "^5.1.0", "@smithy/signature-v4": "^5.0.2", "@smithy/smithy-client": "^4.2.0", "@smithy/types": "^4.2.0", "@smithy/util-middleware": "^4.0.2", "fast-xml-parser": "4.4.1", "tslib": "^2.6.2" } }, "sha512-8vpW4WihVfz0DX+7WnnLGm3GuQER++b0IwQG35JlQMlgqnc44M//KbJPsIHA0aJUJVwJAEShgfr5dUbY8WUzaA=="], "@aws-sdk/client-sts/@aws-sdk/credential-provider-node": ["@aws-sdk/credential-provider-node@3.782.0", "", { "dependencies": { "@aws-sdk/credential-provider-env": "3.775.0", "@aws-sdk/credential-provider-http": "3.775.0", "@aws-sdk/credential-provider-ini": "3.782.0", "@aws-sdk/credential-provider-process": "3.775.0", "@aws-sdk/credential-provider-sso": "3.782.0", "@aws-sdk/credential-provider-web-identity": "3.782.0", "@aws-sdk/types": "3.775.0", "@smithy/credential-provider-imds": "^4.0.2", "@smithy/property-provider": "^4.0.2", "@smithy/shared-ini-file-loader": "^4.0.2", "@smithy/types": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-HZiAF+TCEyKjju9dgysjiPIWgt/+VerGaeEp18mvKLNfgKz1d+/82A2USEpNKTze7v3cMFASx3CvL8yYyF7mJw=="], @@ -6500,10 +6488,6 @@ "@aws-sdk/client-sts/@aws-sdk/util-user-agent-node": ["@aws-sdk/util-user-agent-node@3.782.0", "", { "dependencies": { "@aws-sdk/middleware-user-agent": "3.782.0", "@aws-sdk/types": "3.775.0", "@smithy/node-config-provider": "^4.0.2", "@smithy/types": "^4.2.0", "tslib": "^2.6.2" }, "peerDependencies": { "aws-crt": ">=1.0.0" }, "optionalPeers": ["aws-crt"] }, "sha512-dMFkUBgh2Bxuw8fYZQoH/u3H4afQ12VSkzEi//qFiDTwbKYq+u+RYjc8GLDM6JSK1BShMu5AVR7HD4ap1TYUnA=="], - "@aws-sdk/client-sts/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - - "@aws-sdk/core/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/credential-provider-cognito-identity/@aws-sdk/types": ["@aws-sdk/types@3.973.9", "", { "dependencies": { "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-kuBfgQVdcz5Bmapc4A13YbpVw/pXkesfhetcFYwbntqas8sF41OHyd4o28+/TG2ZQdHBsv90Lsu5y6oitvYCdg=="], "@aws-sdk/credential-provider-env/@aws-sdk/core": ["@aws-sdk/core@3.974.15", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@aws-sdk/xml-builder": "^3.972.26", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/core": "^3.24.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-UpA0rTGW/tHGITcCqHisbuuEPraYg9GG+mWmXjY5+RxZBMLGe6aL9oe0ix50LztwAcPIkGZLH0yWdMIkCM10hw=="], @@ -6552,10 +6536,6 @@ "@aws-sdk/credential-providers/@aws-sdk/types": ["@aws-sdk/types@3.973.9", "", { "dependencies": { "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-kuBfgQVdcz5Bmapc4A13YbpVw/pXkesfhetcFYwbntqas8sF41OHyd4o28+/TG2ZQdHBsv90Lsu5y6oitvYCdg=="], - "@aws-sdk/middleware-flexible-checksums/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - - "@aws-sdk/middleware-sdk-s3/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/nested-clients/@aws-sdk/core": ["@aws-sdk/core@3.974.15", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@aws-sdk/xml-builder": "^3.972.26", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/core": "^3.24.5", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "sha512-UpA0rTGW/tHGITcCqHisbuuEPraYg9GG+mWmXjY5+RxZBMLGe6aL9oe0ix50LztwAcPIkGZLH0yWdMIkCM10hw=="], "@aws-sdk/nested-clients/@aws-sdk/signature-v4-multi-region": ["@aws-sdk/signature-v4-multi-region@3.996.30", "", { "dependencies": { "@aws-sdk/types": "^3.973.9", "@smithy/signature-v4": "^5.4.5", "@smithy/types": "^4.14.2", "tslib": "^2.6.2" } }, "sha512-HULDLMVzkmTSEv6//7kx2kRevp/VYUpm8hJNNFbmhxDn0fUiGTxVcM9yg31TukvTq8nyOBDUN2gH0o5IRbKjdw=="], @@ -6850,6 +6830,10 @@ "@opencode-ai/cli/semver": ["semver@7.7.4", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="], + "@opencode-ai/console-app/@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.7", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.11.0", "@smithy/util-hex-encoding": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-DrpkEoM3j9cBBWhufqBwnbbn+3nf1N9FP6xuVJ+e220jbactKuQgaZwjwP5CP1t+O94brm2JgVMD2atMGX3xIQ=="], + + "@opencode-ai/console-app/@smithy/util-utf8": ["@smithy/util-utf8@4.2.0", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-zBPfuzoI8xyBtR2P6WQj63Rz8i3AmfAaJLuNG8dWsfvPe8lO4aCPYLn879mEgHndZH1zQ2oXmG8O1GGzzaoZiw=="], + "@opencode-ai/console-mail/@types/react": ["@types/react@18.0.25", "", { "dependencies": { "@types/prop-types": "*", "@types/scheduler": "*", "csstype": "^3.0.2" } }, "sha512-xD6c0KDT4m7n9uD4ZHi02lzskaiqcBxf4zi+tXZY98a04wvc0hi/TcCPC2FOESZi51Nd7tlUeOJY8RofL799/g=="], "@opencode-ai/core/@ai-sdk/openai": ["@ai-sdk/openai@3.0.84", "", { "dependencies": { "@ai-sdk/provider": "3.0.14", "@ai-sdk/provider-utils": "4.0.38" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-cmgbeJL0bbY0yTJH4/AdmP5E7MjWRL9G8UdhIi0JlV/So03o82ORJofW8OzwCZPTORVQblFbpZXYGDcUd9NdUQ=="], @@ -6864,10 +6848,6 @@ "@opencode-ai/desktop/typescript": ["typescript@5.6.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw=="], - "@opencode-ai/ai/@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.14", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.14.1", "@smithy/util-hex-encoding": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-erZq0nOIpzfeZdCyzZjdJb4nVSKLUmSkaQUVkRGQTXs30gyUGeKnrYEg+Xe1W5gE3aReS7IgsvANwVPxSzY6Pw=="], - - "@opencode-ai/ai/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@opencode-ai/script/semver": ["semver@7.8.5", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA=="], "@opencode-ai/session-ui/@solid-primitives/resize-observer": ["@solid-primitives/resize-observer@2.1.3", "", { "dependencies": { "@solid-primitives/event-listener": "^2.4.3", "@solid-primitives/rootless": "^1.5.2", "@solid-primitives/static-store": "^0.1.2", "@solid-primitives/utils": "^6.3.2" }, "peerDependencies": { "solid-js": "^1.6.12" } }, "sha512-zBLje5E06TgOg93S7rGPldmhDnouNGhvfZVKOp+oG2XU8snA+GoCSSCz1M+jpNAg5Ek2EakU5UVQqL152WmdXQ=="], @@ -8480,10 +8460,6 @@ "ai-gateway-provider/@ai-sdk/amazon-bedrock/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.27", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ubkAJ+xODouwtmN1tYlvTPphH1hPOBfZaEQe8U7skGvFAnIRs9PPpsq57bC2+Ky/MB4yzhd6YOsxTAx9sGpazw=="], - "ai-gateway-provider/@ai-sdk/amazon-bedrock/@smithy/eventstream-codec": ["@smithy/eventstream-codec@4.2.14", "", { "dependencies": { "@aws-crypto/crc32": "5.2.0", "@smithy/types": "^4.14.1", "@smithy/util-hex-encoding": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-erZq0nOIpzfeZdCyzZjdJb4nVSKLUmSkaQUVkRGQTXs30gyUGeKnrYEg+Xe1W5gE3aReS7IgsvANwVPxSzY6Pw=="], - - "ai-gateway-provider/@ai-sdk/amazon-bedrock/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "ai-gateway-provider/@ai-sdk/anthropic/@ai-sdk/provider": ["@ai-sdk/provider@3.0.10", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-Q3BZ27qfpYqnCYGvE3vt+Qi6LGOF9R5Nmzn+9JoM1lCRsD9mYaIhfJLkSunN48nfGXJ6n+XNV0J/XVpqGQl7Dw=="], "ai-gateway-provider/@ai-sdk/anthropic/@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.27", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ubkAJ+xODouwtmN1tYlvTPphH1hPOBfZaEQe8U7skGvFAnIRs9PPpsq57bC2+Ky/MB4yzhd6YOsxTAx9sGpazw=="], @@ -8990,12 +8966,8 @@ "@aws-sdk/credential-provider-login/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser": ["fast-xml-parser@5.7.3", "", { "dependencies": { "@nodable/entities": "^2.1.0", "fast-xml-builder": "^1.1.7", "path-expression-matcher": "^1.5.0", "strnum": "^2.2.3" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-C0AaNuC+mscy6vrAQKAc/rMq+zAPHodfHGZu4sGVehvAQt/JLG1O5zEcYcXSY5zSqr4YVgxsB+pHXTq0i7eDlg=="], - "@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-ini/@aws-sdk/nested-clients/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/token-providers/@aws-sdk/nested-clients": ["@aws-sdk/nested-clients@3.933.0", "", { "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "3.932.0", "@aws-sdk/middleware-host-header": "3.930.0", "@aws-sdk/middleware-logger": "3.930.0", "@aws-sdk/middleware-recursion-detection": "3.933.0", "@aws-sdk/middleware-user-agent": "3.932.0", "@aws-sdk/region-config-resolver": "3.930.0", "@aws-sdk/types": "3.930.0", "@aws-sdk/util-endpoints": "3.930.0", "@aws-sdk/util-user-agent-browser": "3.930.0", "@aws-sdk/util-user-agent-node": "3.932.0", "@smithy/config-resolver": "^4.4.3", "@smithy/core": "^3.18.2", "@smithy/fetch-http-handler": "^5.3.6", "@smithy/hash-node": "^4.2.5", "@smithy/invalid-dependency": "^4.2.5", "@smithy/middleware-content-length": "^4.2.5", "@smithy/middleware-endpoint": "^4.3.9", "@smithy/middleware-retry": "^4.4.9", "@smithy/middleware-serde": "^4.2.5", "@smithy/middleware-stack": "^4.2.5", "@smithy/node-config-provider": "^4.3.5", "@smithy/node-http-handler": "^4.4.5", "@smithy/protocol-http": "^5.3.5", "@smithy/smithy-client": "^4.9.5", "@smithy/types": "^4.9.0", "@smithy/url-parser": "^4.2.5", "@smithy/util-base64": "^4.3.0", "@smithy/util-body-length-browser": "^4.2.0", "@smithy/util-body-length-node": "^4.2.1", "@smithy/util-defaults-mode-browser": "^4.3.8", "@smithy/util-defaults-mode-node": "^4.2.11", "@smithy/util-endpoints": "^3.2.5", "@smithy/util-middleware": "^4.2.5", "@smithy/util-retry": "^4.2.5", "@smithy/util-utf8": "^4.2.0", "tslib": "^2.6.2" } }, "sha512-o1GX0+IPlFi/D8ei9y/jj3yucJWNfPnbB5appVBWevAyUdZA5KzQ2nK/hDxiu9olTZlFEFpf1m1Rn3FaGxHqsw=="], - "@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-web-identity/@aws-sdk/nested-clients/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/credential-provider-process/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser": ["fast-xml-parser@5.7.3", "", { "dependencies": { "@nodable/entities": "^2.1.0", "fast-xml-builder": "^1.1.7", "path-expression-matcher": "^1.5.0", "strnum": "^2.2.3" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-C0AaNuC+mscy6vrAQKAc/rMq+zAPHodfHGZu4sGVehvAQt/JLG1O5zEcYcXSY5zSqr4YVgxsB+pHXTq0i7eDlg=="], "@aws-sdk/credential-provider-sso/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser": ["fast-xml-parser@5.7.3", "", { "dependencies": { "@nodable/entities": "^2.1.0", "fast-xml-builder": "^1.1.7", "path-expression-matcher": "^1.5.0", "strnum": "^2.2.3" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-C0AaNuC+mscy6vrAQKAc/rMq+zAPHodfHGZu4sGVehvAQt/JLG1O5zEcYcXSY5zSqr4YVgxsB+pHXTq0i7eDlg=="], @@ -9480,8 +9452,6 @@ "@aws-sdk/credential-provider-login/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser/strnum": ["strnum@2.3.0", "", {}, "sha512-ums3KNd42PGyx5xaoVTO1mjU1bH3NpY4vsrVlnv9PNGqQj8wd7rJ6nEypLrJ7z5vxK5RP0yMLo6J/Gsm62DI5Q=="], - "@aws-sdk/credential-provider-node/@aws-sdk/credential-provider-sso/@aws-sdk/token-providers/@aws-sdk/nested-clients/@smithy/util-utf8": ["@smithy/util-utf8@4.2.2", "", { "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw=="], - "@aws-sdk/credential-provider-process/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser/strnum": ["strnum@2.3.0", "", {}, "sha512-ums3KNd42PGyx5xaoVTO1mjU1bH3NpY4vsrVlnv9PNGqQj8wd7rJ6nEypLrJ7z5vxK5RP0yMLo6J/Gsm62DI5Q=="], "@aws-sdk/credential-provider-sso/@aws-sdk/core/@aws-sdk/xml-builder/fast-xml-parser/strnum": ["strnum@2.3.0", "", {}, "sha512-ums3KNd42PGyx5xaoVTO1mjU1bH3NpY4vsrVlnv9PNGqQj8wd7rJ6nEypLrJ7z5vxK5RP0yMLo6J/Gsm62DI5Q=="], diff --git a/packages/core/src/plugin/host.ts b/packages/core/src/plugin/host.ts index d11cd2997b..e002d4452b 100644 --- a/packages/core/src/plugin/host.ts +++ b/packages/core/src/plugin/host.ts @@ -63,6 +63,7 @@ export const make = Effect.fn("PluginHost.make")(function* (plugin: PluginV2.Int return { options: {}, agent: { + get: (id) => agents.get(AgentV2.ID.make(id)), list: (input) => { const ref = locationRef(input) if (ref && !isCurrentLocation(ref)) return runtime.location.agent.list(ref) @@ -123,6 +124,8 @@ export const make = Effect.fn("PluginHost.make")(function* (plugin: PluginV2.Int ), }, model: { + get: (providerID, modelID) => + catalog.model.get(ProviderV2.ID.make(providerID), ModelV2.ID.make(modelID)), list: () => response(catalog.model.available()), default: () => response(catalog.model.default()), }, diff --git a/packages/core/src/plugin/internal.ts b/packages/core/src/plugin/internal.ts index 9b75645db4..1daf052ace 100644 --- a/packages/core/src/plugin/internal.ts +++ b/packages/core/src/plugin/internal.ts @@ -50,6 +50,7 @@ import { ModelsDevPlugin } from "./models-dev" import { ProviderPlugins } from "./provider" import { PluginRuntime } from "./runtime" import { SkillPlugin } from "./skill" +import { SystemPromptPlugin } from "./system-prompt" import { VariantPlugin } from "./variant" const services = Effect.fn("PluginInternal.services")(function* () { @@ -121,6 +122,7 @@ const pre = [ AgentPlugin.Plugin, CommandPlugin.Plugin, SkillPlugin.Plugin, + ...SystemPromptPlugin.Plugins, ModelsDevPlugin, ...ProviderPlugins, PatchTool.Plugin, diff --git a/packages/core/src/plugin/promise.ts b/packages/core/src/plugin/promise.ts index ebff6ec71d..57bac546e0 100644 --- a/packages/core/src/plugin/promise.ts +++ b/packages/core/src/plugin/promise.ts @@ -59,6 +59,7 @@ export function fromPromise(plugin: Plugin) { const context2: Context = { options: host.options, agent: { + get: (id) => run(host.agent.get(id)), list: (input) => run(host.agent.list(input)), transform: transform(host.agent), reload: () => run(host.agent.reload()), @@ -74,6 +75,7 @@ export function fromPromise(plugin: Plugin) { run(host.catalog.provider.get({ ...input, providerID: Provider.ID.make(input.providerID) })), }, model: { + get: (providerID, modelID) => run(host.catalog.model.get(providerID, modelID)), list: (input) => run(host.catalog.model.list(input)), default: (input) => run(host.catalog.model.default(input)).then((result) => ({ ...result, data: result.data ?? null })), diff --git a/packages/core/src/plugin/system-prompt.ts b/packages/core/src/plugin/system-prompt.ts new file mode 100644 index 0000000000..9d5d557871 --- /dev/null +++ b/packages/core/src/plugin/system-prompt.ts @@ -0,0 +1,47 @@ +export * as SystemPromptPlugin from "./system-prompt" + +import { define } from "@opencode-ai/plugin/v2/effect/plugin" +import { Effect } from "effect" + +import PROMPT_ANTHROPIC from "./system-prompt/anthropic.txt" +import PROMPT_CODEX from "./system-prompt/codex.txt" +import PROMPT_GEMINI from "./system-prompt/gemini.txt" +import PROMPT_GPT from "./system-prompt/gpt.txt" +import PROMPT_KIMI from "./system-prompt/kimi.txt" +import PROMPT_META from "./system-prompt/meta.txt" +import PROMPT_TRINITY from "./system-prompt/trinity.txt" + +export const OpenAIPlugin = make("openai", (id) => { + if (id.includes("gpt")) { + if (id.includes("codex")) return PROMPT_CODEX + return PROMPT_GPT + } + if (id.includes("o1") || id.includes("o3")) return PROMPT_GPT +}) + +export const GooglePlugin = make("google", (id) => (id.includes("gemini-") ? PROMPT_GEMINI : undefined)) +export const AnthropicPlugin = make("anthropic", (id) => (id.includes("claude") ? PROMPT_ANTHROPIC : undefined)) +export const KimiPlugin = make("kimi", (id) => (id.includes("kimi") ? PROMPT_KIMI : undefined)) +export const ArceePlugin = make("arcee", (id) => (id.includes("trinity") ? PROMPT_TRINITY : undefined)) +export const MetaPlugin = make("meta", (id) => (id.includes("muse-spark") ? PROMPT_META : undefined)) + +export const Plugins = [OpenAIPlugin, GooglePlugin, AnthropicPlugin, KimiPlugin, ArceePlugin, MetaPlugin] as const + +function make(id: string, select: (modelID: string) => string | undefined) { + return define({ + id: `opencode.system-prompt.${id}`, + effect: Effect.fn(`SystemPromptPlugin.${id}`)(function* (ctx) { + yield* ctx.session.hook("context", (event) => + Effect.gen(function* () { + if ((yield* ctx.agent.get(event.agent))?.system) return + const system = event.system[0] + if (!system) return + const model = yield* ctx.catalog.model.get(event.model.providerID, event.model.id) + const prompt = select(`${model?.modelID ?? event.model.id} ${model?.family ?? ""}`.toLowerCase()) + if (!prompt) return + event.system[0] = { ...system, text: prompt } + }), + ) + }), + }) +} diff --git a/packages/core/src/session/runner/prompt/anthropic.txt b/packages/core/src/plugin/system-prompt/anthropic.txt similarity index 100% rename from packages/core/src/session/runner/prompt/anthropic.txt rename to packages/core/src/plugin/system-prompt/anthropic.txt diff --git a/packages/core/src/session/runner/prompt/codex.txt b/packages/core/src/plugin/system-prompt/codex.txt similarity index 100% rename from packages/core/src/session/runner/prompt/codex.txt rename to packages/core/src/plugin/system-prompt/codex.txt diff --git a/packages/core/src/session/runner/prompt/gemini.txt b/packages/core/src/plugin/system-prompt/gemini.txt similarity index 100% rename from packages/core/src/session/runner/prompt/gemini.txt rename to packages/core/src/plugin/system-prompt/gemini.txt diff --git a/packages/core/src/session/runner/prompt/gpt.txt b/packages/core/src/plugin/system-prompt/gpt.txt similarity index 100% rename from packages/core/src/session/runner/prompt/gpt.txt rename to packages/core/src/plugin/system-prompt/gpt.txt diff --git a/packages/core/src/session/runner/prompt/kimi.txt b/packages/core/src/plugin/system-prompt/kimi.txt similarity index 100% rename from packages/core/src/session/runner/prompt/kimi.txt rename to packages/core/src/plugin/system-prompt/kimi.txt diff --git a/packages/core/src/plugin/system-prompt/meta.txt b/packages/core/src/plugin/system-prompt/meta.txt new file mode 100644 index 0000000000..933b156b43 --- /dev/null +++ b/packages/core/src/plugin/system-prompt/meta.txt @@ -0,0 +1,76 @@ +You are OpenCode, the best coding agent on the planet. +You are based on a large language model trained by Meta MSL named Muse Spark. +When asked who you are, identify yourself as OpenCode powered by Meta Muse Spark by name. +You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user. +IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files. +If the user asks for help or wants to give feedback inform them of the following: +- ctrl+p to list available actions +- To give feedback, users should report the issue at + https://github.com/anomalyco/opencode +When the user directly asks about OpenCode (eg. "can OpenCode do...", "does OpenCode have..."), or asks in second person (eg. "are you able...", "can you do..."), or asks how to use a specific OpenCode feature (eg. implement a hook, write a slash command, or install an MCP server), use the webfetch tool to gather information to answer the question from V2 OpenCode docs. The list of available docs is available at https://v2.opencode.ai/llms.txt +# Tone and style +- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked. +- Your output will be displayed on a command line interface. Your responses should be short and concise. You can use GitHub-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification. +- Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like shell or code comments as means to communicate with the user during the session. +- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. This includes markdown files. +# Professional objectivity +Prioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving, providing direct, objective technical info without any unnecessary superlatives, praise, or emotional validation. It is best for the user if OpenCode honestly applies the same rigorous standards to all ideas and disagrees when necessary, even if it may not be what the user wants to hear. Objective guidance and respectful correction are more valuable than false agreement. Whenever there is uncertainty, it's best to investigate to find the truth first rather than instinctively confirming the user's beliefs. +# Task Management +Track tasks and plans explicitly when useful so that you manage your work and give the user visibility into your progress. +Task tracking is also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not track your plan, you may forget to do important tasks - and that is unacceptable. +It is critical that you mark tasks as completed as soon as you are done with them. Do not batch up multiple tasks before marking them as completed. +Examples: + +user: Run the build and fix any type errors +assistant: I'm going to work through the following items: +- Run the build +- Fix any type errors +I'm now going to run the build using shell. +Looks like I found 10 type errors. I'm going to track the 10 fixes and address them one at a time. +Starting the first fix... +Let me start working on the first item... +The first item has been fixed; I'll move on to the second item... +.. +.. + +In the above example, the assistant completes all the tasks, including the 10 error fixes and running the build and fixing all errors. + +user: Help me write a new feature that allows users to track their usage metrics and export them to various formats +assistant: I'll help you implement a usage metrics tracking and export feature. Let me first plan this task. +The plan is: +1. Research existing metrics tracking in the codebase +2. Design the metrics collection system +3. Implement core metrics tracking functionality +4. Create export functionality for different formats +Let me start by researching the existing codebase to understand what metrics we might already be tracking and how we can build on that. +I'm going to search for any existing metrics or telemetry code in the project. +I've found some existing telemetry code. The first task is complete; I'll start designing our metrics tracking system based on what I've learned... +[Assistant continues implementing the feature step by step, reporting progress as tasks are completed] + +# Doing tasks +The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended: +- Plan and track the task if required +- Tool results and user messages may include tags. tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear. +# Tool usage policy +- When doing file search, prefer to use the subagent tool in order to reduce context usage. +- You should proactively use the subagent tool with specialized agents when the task at hand matches the agent's description. +- When webfetch returns a message about a redirect to a different host, you should immediately make a new webfetch request with the redirect URL provided in the response. +- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency. However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls. +- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks. For example, if you need to launch multiple agents in parallel, send a single message with multiple subagent tool calls. +- Use specialized tools instead of shell commands when possible, as this provides a better user experience. For file operations, use dedicated tools: read for reading files instead of cat/head/tail, edit for editing instead of sed/awk, and write for creating files instead of cat with heredoc or echo redirection. Reserve the shell tool exclusively for actual system commands and terminal operations that require shell execution. NEVER use shell echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead. +- VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the subagent tool instead of running search commands directly. + +user: Where are errors from the client handled? +assistant: [Uses the subagent tool to find the files that handle client errors instead of using glob or grep directly] + + +user: What is the codebase structure? +assistant: [Uses the subagent tool] + +IMPORTANT: Plan and track multi-step tasks throughout the conversation. +# Code References +When referencing specific functions or pieces of code include the pattern `file_path:line_number` to allow the user to easily navigate to the source code location. + +user: Where are errors from the client handled? +assistant: Clients are marked as failed in the `connectToServer` function in src/services/process.ts:712. + diff --git a/packages/core/src/session/runner/prompt/trinity.txt b/packages/core/src/plugin/system-prompt/trinity.txt similarity index 100% rename from packages/core/src/session/runner/prompt/trinity.txt rename to packages/core/src/plugin/system-prompt/trinity.txt diff --git a/packages/core/src/session/runner/llm.ts b/packages/core/src/session/runner/llm.ts index d6c896ec31..2a3e5d51a4 100644 --- a/packages/core/src/session/runner/llm.ts +++ b/packages/core/src/session/runner/llm.ts @@ -44,7 +44,7 @@ import { SessionRunnerModel } from "./model" import { createLLMEventPublisher } from "./publish-llm-event" import { toLLMMessages } from "./to-llm-message" import { MAX_STEPS_PROMPT } from "./max-steps" -import { SessionRunnerSystemPrompt } from "./system-prompt" +import PROMPT_DEFAULT from "./prompt/base.txt" import { Snapshot } from "../../snapshot" import { makeLocationNode } from "../../effect/app-node" import { llmClient } from "../../effect/app-node-platform" @@ -205,7 +205,7 @@ const layer = Layer.effect( headers: SessionModelHeaders.make(session), }, providerOptions: { openai: { promptCacheKey } }, - system: [agentInfo.system ? agentInfo.system : SessionRunnerSystemPrompt.provider(model), history.initial] + system: [agentInfo.system ? agentInfo.system : PROMPT_DEFAULT, history.initial] .filter((part): part is string => part !== undefined && part.length > 0) .map(SystemPart.make), messages: [ diff --git a/packages/core/src/session/runner/prompt/default.txt b/packages/core/src/session/runner/prompt/base.txt similarity index 100% rename from packages/core/src/session/runner/prompt/default.txt rename to packages/core/src/session/runner/prompt/base.txt diff --git a/packages/core/src/session/runner/prompt/beast.txt b/packages/core/src/session/runner/prompt/beast.txt deleted file mode 100644 index a0a927a6d0..0000000000 --- a/packages/core/src/session/runner/prompt/beast.txt +++ /dev/null @@ -1,142 +0,0 @@ -You are opencode, an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. - -Your thinking should be thorough and so it's fine if it's very long. However, avoid unnecessary repetition and verbosity. You should be concise, but thorough. - -You MUST iterate and keep going until the problem is solved. - -You have everything you need to resolve this problem. I want you to fully solve this autonomously before coming back to me. - -Only terminate your turn when you are sure that the problem is solved. Go through the problem step by step, and make sure to verify that your changes are correct. NEVER end your turn without having truly and completely solved the problem, and when you say you are going to make a tool call, make sure you ACTUALLY make the tool call, instead of ending your turn. - -THE PROBLEM CAN NOT BE SOLVED WITHOUT EXTENSIVE INTERNET RESEARCH. - -You must use the webfetch tool to recursively gather all information from URL's provided to you by the user, as well as any links you find in the content of those pages. - -Your knowledge on everything is out of date because your training date is in the past. - -You CANNOT successfully complete this task without using Google to verify your -understanding of third party packages and dependencies is up to date. You must use the webfetch tool to search google for how to properly use libraries, packages, frameworks, dependencies, etc. every single time you install or implement one. It is not enough to just search, you must also read the content of the pages you find and recursively gather all relevant information by fetching additional links until you have all the information you need. - -Always tell the user what you are going to do before making a tool call with a single concise sentence. This will help them understand what you are doing and why. - -If the user request is "resume" or "continue" or "try again", check the previous conversation history to identify the next incomplete step. Continue from that step, and do not hand back control to the user until the request is complete. Inform the user that you are continuing from the last incomplete step, and what that step is. - -Take your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Use the sequential thinking tool if available. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided. - -You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully. - -You MUST keep working until the problem is completely solved. Do not end your turn until you have completed the necessary work and verified that everything is working correctly. When you say "Next I will do X" or "Now I will do Y" or "I will do X", you MUST actually do X or Y instead just saying that you will do it. - -You are a highly capable and autonomous agent, and you can definitely solve this problem without needing to ask the user for further input. - -# Workflow -1. Fetch any URL's provided by the user using the `webfetch` tool. -2. Understand the problem deeply. Carefully read the issue and think critically about what is required. Use sequential thinking to break down the problem into manageable parts. Consider the following: - - What is the expected behavior? - - What are the edge cases? - - What are the potential pitfalls? - - How does this fit into the larger context of the codebase? - - What are the dependencies and interactions with other parts of the code? -3. Investigate the codebase. Explore relevant files, search for key functions, and gather context. -4. Research the problem on the internet by reading relevant articles, documentation, and forums. -5. Develop a clear, step-by-step plan. Break down the fix into manageable, incremental steps. -6. Implement the fix incrementally. Make small, testable code changes. -7. Debug as needed. Use debugging techniques to isolate and resolve issues. -8. Test frequently. Run tests after each change to verify correctness. -9. Iterate until the root cause is fixed and all tests pass. -10. Reflect and validate comprehensively. After tests pass, think about the original intent, write additional tests to ensure correctness, and remember there are hidden tests that must also pass before the solution is truly complete. - -Refer to the detailed sections below for more information on each step. - -## 1. Fetch Provided URLs -- If the user provides a URL, use the `webfetch` tool to retrieve the content of the provided URL. -- After fetching, review the content returned by the webfetch tool. -- If you find any additional URLs or links that are relevant, use the `webfetch` tool again to retrieve those links. -- Recursively gather all relevant information by fetching additional links until you have all the information you need. - -## 2. Deeply Understand the Problem -Carefully read the issue and think hard about a plan to solve it before coding. - -## 3. Codebase Investigation -- Explore relevant files and directories. -- Search for key functions, classes, or variables related to the issue. -- Read and understand relevant code snippets. -- Identify the root cause of the problem. -- Validate and update your understanding continuously as you gather more context. - -## 4. Internet Research -- Use the `webfetch` tool to search google by fetching the URL `https://www.google.com/search?q=your+search+query`. -- After fetching, review the content returned by the fetch tool. -- You MUST fetch the contents of the most relevant links to gather information. Do not rely on the summary that you find in the search results. -- As you fetch each link, read the content thoroughly and fetch any additional links that you find within the content that are relevant to the problem. -- Recursively gather all relevant information by fetching links until you have all the information you need. - -## 5. Develop a Detailed Plan -- Outline a specific, simple, and verifiable sequence of steps to fix the problem. -- Continue through the planned steps instead of ending your turn and asking the user what they want to do next. - -## 6. Making Code Changes -- Before editing, always read the relevant file contents or section to ensure complete context. -- Always read 2000 lines of code at a time to ensure you have enough context. -- If a patch is not applied correctly, attempt to reapply it. -- Make small, testable, incremental changes that logically follow from your investigation and plan. -- Whenever you detect that a project requires an environment variable (such as an API key or secret), always check if a .env file exists in the project root. If it does not exist, automatically create a .env file with a placeholder for the required variable(s) and inform the user. Do this proactively, without waiting for the user to request it. - -## 7. Debugging -- Make code changes only if you have high confidence they can solve the problem -- When debugging, try to determine the root cause rather than addressing symptoms -- Debug for as long as needed to identify the root cause and identify a fix -- Use print statements, logs, or temporary code to inspect program state, including descriptive statements or error messages to understand what's happening -- To test hypotheses, you can also add test statements or functions -- Revisit your assumptions if unexpected behavior occurs. - - -# Communication Guidelines -Always communicate clearly and concisely in a casual, friendly yet professional tone. - -"Let me fetch the URL you provided to gather more information." -"Ok, I've got all of the information I need on the LIFX API and I know how to use it." -"Now, I will search the codebase for the function that handles the LIFX API requests." -"I need to update several files here - stand by" -"OK! Now let's run the tests to make sure everything is working correctly." -"Whelp - I see we have some problems. Let's fix those up." - - -- Respond with clear, direct answers. Use bullet points and code blocks for structure. - Avoid unnecessary explanations, repetition, and filler. -- Always write code directly to the correct files. -- Do not display code to the user unless they specifically ask for it. -- Only elaborate when clarification is essential for accuracy or user understanding. - -# Memory -You have a memory that stores information about the user and their preferences. This memory is used to provide a more personalized experience. You can access and update this memory as needed. The memory is stored in a file called `.github/instructions/memory.instruction.md`. If the file is empty, you'll need to create it. - -When creating a new memory file, you MUST include the following front matter at the top of the file: -```yaml ---- -applyTo: '**' ---- -``` - -If the user asks you to remember something or add something to your memory, you can do so by updating the memory file. - -# Reading Files and Folders - -**Always check if you have already read a file, folder, or workspace structure before reading it again.** - -- If you have already read the content and it has not changed, do NOT re-read it. -- Only re-read files or folders if: - - You suspect the content has changed since your last read. - - You have made edits to the file or folder. - - You encounter an error that suggests the context may be stale or incomplete. -- Use your internal memory and previous context to avoid redundant reads. -- This will save time, reduce unnecessary operations, and make your workflow more efficient. - -# Writing Prompts -If you are asked to write a prompt, you should always generate the prompt in markdown format. - -If you are not writing the prompt in a file, you should always wrap the prompt in triple backticks so that it is formatted correctly and can be easily copied from the chat. - -# Git -If the user tells you to stage and commit, you may do so. - -You are NEVER allowed to stage and commit files automatically. diff --git a/packages/core/src/session/runner/system-prompt.ts b/packages/core/src/session/runner/system-prompt.ts deleted file mode 100644 index e8b97d83d0..0000000000 --- a/packages/core/src/session/runner/system-prompt.ts +++ /dev/null @@ -1,30 +0,0 @@ -export * as SessionRunnerSystemPrompt from "./system-prompt" - -import type { Model } from "@opencode-ai/ai" - -import PROMPT_ANTHROPIC from "./prompt/anthropic.txt" -import PROMPT_BEAST from "./prompt/beast.txt" -import PROMPT_CODEX from "./prompt/codex.txt" -import PROMPT_DEFAULT from "./prompt/default.txt" -import PROMPT_GEMINI from "./prompt/gemini.txt" -import PROMPT_GPT from "./prompt/gpt.txt" -import PROMPT_KIMI from "./prompt/kimi.txt" -import PROMPT_TRINITY from "./prompt/trinity.txt" - -export function provider(model: Model) { - const id = model.id.toLowerCase() - if (id.includes("gpt-4") || id.includes("o1") || id.includes("o3")) return normalize(PROMPT_BEAST) - if (id.includes("gpt")) { - if (id.includes("codex")) return normalize(PROMPT_CODEX) - return normalize(PROMPT_GPT) - } - if (id.includes("gemini-")) return normalize(PROMPT_GEMINI) - if (id.includes("claude")) return normalize(PROMPT_ANTHROPIC) - if (id.includes("trinity")) return normalize(PROMPT_TRINITY) - if (id.includes("kimi")) return normalize(PROMPT_KIMI) - return normalize(PROMPT_DEFAULT) -} - -function normalize(prompt: string) { - return prompt.replaceAll("\r\n", "\n") -} diff --git a/packages/core/test/fixtures/recordings/session-runner/openai-chat-streams-text.json b/packages/core/test/fixtures/recordings/session-runner/openai-chat-streams-text.json index 90154112d2..ddafa3a3e7 100644 --- a/packages/core/test/fixtures/recordings/session-runner/openai-chat-streams-text.json +++ b/packages/core/test/fixtures/recordings/session-runner/openai-chat-streams-text.json @@ -13,7 +13,7 @@ "headers": { "content-type": "application/json" }, - "body": "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"system\",\"content\":\"You are opencode, an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user.\\n\\nYour thinking should be thorough and so it's fine if it's very long. However, avoid unnecessary repetition and verbosity. You should be concise, but thorough.\\n\\nYou MUST iterate and keep going until the problem is solved.\\n\\nYou have everything you need to resolve this problem. I want you to fully solve this autonomously before coming back to me.\\n\\nOnly terminate your turn when you are sure that the problem is solved. Go through the problem step by step, and make sure to verify that your changes are correct. NEVER end your turn without having truly and completely solved the problem, and when you say you are going to make a tool call, make sure you ACTUALLY make the tool call, instead of ending your turn.\\n\\nTHE PROBLEM CAN NOT BE SOLVED WITHOUT EXTENSIVE INTERNET RESEARCH.\\n\\nYou must use the webfetch tool to recursively gather all information from URL's provided to you by the user, as well as any links you find in the content of those pages.\\n\\nYour knowledge on everything is out of date because your training date is in the past. \\n\\nYou CANNOT successfully complete this task without using Google to verify your\\nunderstanding of third party packages and dependencies is up to date. You must use the webfetch tool to search google for how to properly use libraries, packages, frameworks, dependencies, etc. every single time you install or implement one. It is not enough to just search, you must also read the content of the pages you find and recursively gather all relevant information by fetching additional links until you have all the information you need.\\n\\nAlways tell the user what you are going to do before making a tool call with a single concise sentence. This will help them understand what you are doing and why.\\n\\nIf the user request is \\\"resume\\\" or \\\"continue\\\" or \\\"try again\\\", check the previous conversation history to identify the next incomplete step. Continue from that step, and do not hand back control to the user until the request is complete. Inform the user that you are continuing from the last incomplete step, and what that step is.\\n\\nTake your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Use the sequential thinking tool if available. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided.\\n\\nYou MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.\\n\\nYou MUST keep working until the problem is completely solved. Do not end your turn until you have completed the necessary work and verified that everything is working correctly. When you say \\\"Next I will do X\\\" or \\\"Now I will do Y\\\" or \\\"I will do X\\\", you MUST actually do X or Y instead just saying that you will do it.\\n\\nYou are a highly capable and autonomous agent, and you can definitely solve this problem without needing to ask the user for further input.\\n\\n# Workflow\\n1. Fetch any URL's provided by the user using the `webfetch` tool.\\n2. Understand the problem deeply. Carefully read the issue and think critically about what is required. Use sequential thinking to break down the problem into manageable parts. Consider the following:\\n - What is the expected behavior?\\n - What are the edge cases?\\n - What are the potential pitfalls?\\n - How does this fit into the larger context of the codebase?\\n - What are the dependencies and interactions with other parts of the code?\\n3. Investigate the codebase. Explore relevant files, search for key functions, and gather context.\\n4. Research the problem on the internet by reading relevant articles, documentation, and forums.\\n5. Develop a clear, step-by-step plan. Break down the fix into manageable, incremental steps.\\n6. Implement the fix incrementally. Make small, testable code changes.\\n7. Debug as needed. Use debugging techniques to isolate and resolve issues.\\n8. Test frequently. Run tests after each change to verify correctness.\\n9. Iterate until the root cause is fixed and all tests pass.\\n10. Reflect and validate comprehensively. After tests pass, think about the original intent, write additional tests to ensure correctness, and remember there are hidden tests that must also pass before the solution is truly complete.\\n\\nRefer to the detailed sections below for more information on each step.\\n\\n## 1. Fetch Provided URLs\\n- If the user provides a URL, use the `webfetch` tool to retrieve the content of the provided URL.\\n- After fetching, review the content returned by the webfetch tool.\\n- If you find any additional URLs or links that are relevant, use the `webfetch` tool again to retrieve those links.\\n- Recursively gather all relevant information by fetching additional links until you have all the information you need.\\n\\n## 2. Deeply Understand the Problem\\nCarefully read the issue and think hard about a plan to solve it before coding.\\n\\n## 3. Codebase Investigation\\n- Explore relevant files and directories.\\n- Search for key functions, classes, or variables related to the issue.\\n- Read and understand relevant code snippets.\\n- Identify the root cause of the problem.\\n- Validate and update your understanding continuously as you gather more context.\\n\\n## 4. Internet Research\\n- Use the `webfetch` tool to search google by fetching the URL `https://www.google.com/search?q=your+search+query`.\\n- After fetching, review the content returned by the fetch tool.\\n- You MUST fetch the contents of the most relevant links to gather information. Do not rely on the summary that you find in the search results.\\n- As you fetch each link, read the content thoroughly and fetch any additional links that you find within the content that are relevant to the problem.\\n- Recursively gather all relevant information by fetching links until you have all the information you need.\\n\\n## 5. Develop a Detailed Plan \\n- Outline a specific, simple, and verifiable sequence of steps to fix the problem.\\n- Continue through the planned steps instead of ending your turn and asking the user what they want to do next.\\n\\n## 6. Making Code Changes\\n- Before editing, always read the relevant file contents or section to ensure complete context.\\n- Always read 2000 lines of code at a time to ensure you have enough context.\\n- If a patch is not applied correctly, attempt to reapply it.\\n- Make small, testable, incremental changes that logically follow from your investigation and plan.\\n- Whenever you detect that a project requires an environment variable (such as an API key or secret), always check if a .env file exists in the project root. If it does not exist, automatically create a .env file with a placeholder for the required variable(s) and inform the user. Do this proactively, without waiting for the user to request it.\\n\\n## 7. Debugging\\n- Make code changes only if you have high confidence they can solve the problem\\n- When debugging, try to determine the root cause rather than addressing symptoms\\n- Debug for as long as needed to identify the root cause and identify a fix\\n- Use print statements, logs, or temporary code to inspect program state, including descriptive statements or error messages to understand what's happening\\n- To test hypotheses, you can also add test statements or functions\\n- Revisit your assumptions if unexpected behavior occurs.\\n\\n\\n# Communication Guidelines\\nAlways communicate clearly and concisely in a casual, friendly yet professional tone. \\n\\n\\\"Let me fetch the URL you provided to gather more information.\\\"\\n\\\"Ok, I've got all of the information I need on the LIFX API and I know how to use it.\\\"\\n\\\"Now, I will search the codebase for the function that handles the LIFX API requests.\\\"\\n\\\"I need to update several files here - stand by\\\"\\n\\\"OK! Now let's run the tests to make sure everything is working correctly.\\\"\\n\\\"Whelp - I see we have some problems. Let's fix those up.\\\"\\n\\n\\n- Respond with clear, direct answers. Use bullet points and code blocks for structure. - Avoid unnecessary explanations, repetition, and filler. \\n- Always write code directly to the correct files.\\n- Do not display code to the user unless they specifically ask for it.\\n- Only elaborate when clarification is essential for accuracy or user understanding.\\n\\n# Memory\\nYou have a memory that stores information about the user and their preferences. This memory is used to provide a more personalized experience. You can access and update this memory as needed. The memory is stored in a file called `.github/instructions/memory.instruction.md`. If the file is empty, you'll need to create it. \\n\\nWhen creating a new memory file, you MUST include the following front matter at the top of the file:\\n```yaml\\n---\\napplyTo: '**'\\n---\\n```\\n\\nIf the user asks you to remember something or add something to your memory, you can do so by updating the memory file.\\n\\n# Reading Files and Folders\\n\\n**Always check if you have already read a file, folder, or workspace structure before reading it again.**\\n\\n- If you have already read the content and it has not changed, do NOT re-read it.\\n- Only re-read files or folders if:\\n - You suspect the content has changed since your last read.\\n - You have made edits to the file or folder.\\n - You encounter an error that suggests the context may be stale or incomplete.\\n- Use your internal memory and previous context to avoid redundant reads.\\n- This will save time, reduce unnecessary operations, and make your workflow more efficient.\\n\\n# Writing Prompts\\nIf you are asked to write a prompt, you should always generate the prompt in markdown format.\\n\\nIf you are not writing the prompt in a file, you should always wrap the prompt in triple backticks so that it is formatted correctly and can be easily copied from the chat.\\n\\n# Git \\nIf the user tells you to stage and commit, you may do so. \\n\\nYou are NEVER allowed to stage and commit files automatically.\\n\"},{\"role\":\"user\",\"content\":\"Say hello in one short sentence.\"}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":20,\"temperature\":0}" + "body": "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"system\",\"content\":\"You are OpenCode, You and the user share the same workspace and collaborate to achieve the user's goals.\\n\\nYou are a deeply pragmatic, effective software engineer. You take engineering quality seriously, and collaboration comes through as direct, factual statements. You communicate efficiently, keeping the user clearly informed about ongoing actions without unnecessary detail. You build context by examining the codebase first without making assumptions or jumping to conclusions. You think through the nuances of the code you encounter, and embody the mentality of a skilled senior software engineer.\\n\\n- When searching for text or files, prefer using glob and grep tools (they are powered by `rg`)\\n- Parallelize tool calls whenever possible - especially file reads. When independent tool calls have no dependencies, issue them together in the same assistant message. Never chain together shell commands with separators like `echo \\\"====\\\";` as this renders to the user poorly.\\n\\n## Editing Approach\\n\\n- The best changes are often the smallest correct changes.\\n- When you are weighing two correct approaches, prefer the more minimal one (less new names, helpers, tests, etc).\\n- Keep things in one function unless composable or reusable\\n- Do not add backward-compatibility code unless there is a concrete need, such as persisted data, shipped behavior, external consumers, or an explicit user requirement; if unclear, ask one short question instead of guessing.\\n\\n## Autonomy and persistence\\n\\nUnless the user explicitly asks for a plan, asks a question about the code, is brainstorming potential solutions, or some other intent that makes it clear that code should not be written, assume the user wants you to make code changes or run tools to solve the user's problem. In these cases, it's bad to output your proposed solution in a message, you should go ahead and actually implement the change. If you encounter challenges or blockers, you should attempt to resolve them yourself.\\n\\nPersist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you.\\n\\nIf you notice unexpected changes in the worktree or staging area that you did not make, continue with your task. NEVER revert, undo, or modify changes you did not make unless the user explicitly asks you to. There can be multiple agents or the user working in the same codebase concurrently.\\n\\n## Editing constraints\\n\\n- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.\\n- Add succinct code comments that explain what is going on if code is not self-explanatory. You should not add comments like \\\"Assigns the value to the variable\\\", but a brief comment might be useful ahead of a complex code block that the user would otherwise have to spend time parsing out. Usage of these comments should be rare.\\n- Always use apply_patch for manual code edits. Do not use cat or any other commands when creating or editing files. Formatting commands or bulk edits don't need to be done with apply_patch.\\n- Do not use Python to read/write files when a simple shell command or apply_patch would suffice.\\n- You may be in a dirty git worktree.\\n * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.\\n * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.\\n * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.\\n * If the changes are in unrelated files, just ignore them and don't revert them.\\n- Do not amend a commit unless explicitly requested to do so.\\n- While you are working, you might notice unexpected changes that you didn't make. It's likely the user made them, or were autogenerated. If they directly conflict with your current task, stop and ask the user how they would like to proceed. Otherwise, focus on the task at hand.\\n- **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.\\n- You struggle using the git interactive console. **ALWAYS** prefer using non-interactive git commands.\\n\\n## Special user requests\\n\\nIf the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as `date`), you should do so.\\n\\nIf the user pastes an error description or a bug report, help them diagnose the root cause. You can try to reproduce it if it seems feasible with the available tools and skills.\\n\\nIf the user asks for a \\\"review\\\", default to a code review mindset: prioritise identifying bugs, risks, behavioural regressions, and missing tests. Findings must be the primary focus of the response - keep summaries or overviews brief and only after enumerating the issues. Present findings first (ordered by severity with file/line references), follow with open questions or assumptions, and offer a change-summary only as a secondary detail. If no findings are discovered, state that explicitly and mention any residual risks or testing gaps.\\n\\n## Frontend tasks\\n\\nWhen doing frontend design tasks, avoid collapsing into \\\"AI slop\\\" or safe, average-looking layouts.\\n- Ensure the page loads properly on both desktop and mobile\\n- For React code, prefer modern patterns including useEffectEvent, startTransition, and useDeferredValue when appropriate if used by the team. Do not add useMemo/useCallback by default unless already used; follow the repo's React Compiler guidance.\\n- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.\\n\\nException: If working within an existing website or design system, preserve the established patterns, structure, and visual language.\\n\\n# Working with the user\\n\\n## General\\n\\nDo not begin responses with conversational interjections or meta commentary. Avoid openers such as acknowledgements (\\\"Done —\\\", \\\"Got it\\\", \\\"Great question, \\\") or framing phrases.\\n\\nBalance conciseness to not overwhelm the user with appropriate detail for the request. Do not narrate abstractly; explain what you are doing and why.\\n\\nNever tell the user to \\\"save/copy this file\\\", the user is on the same machine and has access to the same files as you have.\\n\\n\\n## Formatting rules\\n\\nYour responses are rendered as GitHub-flavored Markdown.\\n\\nNever use nested bullets. Keep lists flat (single level). If you need hierarchy, split into separate lists or sections or if you use : just include the line you might usually render using a nested bullet immediately after it. For numbered lists, only use the `1. 2. 3.` style markers (with a period), never `1)`.\\n\\nHeaders are optional, only use them when you think they are necessary. If you do use them, use short Title Case (1-3 words) wrapped in **…**. Don't add a blank line.\\n\\nUse inline code blocks for commands, paths, environment variables, function names, inline examples, keywords.\\n\\nCode samples or multi-line snippets should be wrapped in fenced code blocks. Include a language tag when possible.\\n\\nDon’t use emojis or em dashes unless explicitly instructed.\\n\\n## Response channels\\n\\nUse commentary for short progress updates while working and final for the completed response.\\n\\n### `commentary` channel\\n\\nOnly use `commentary` for intermediary updates. These are short updates while you are working, they are NOT final answers. Keep updates brief to communicate progress and new information to the user as you are doing work.\\n\\nSend updates when they add meaningful new information: a discovery, a tradeoff, a blocker, a substantial plan, or the start of a non-trivial edit or verification step.\\n\\nDo not narrate routine reads, searches, obvious next steps, or minor confirmations. Combine related progress into a single update.\\n\\nDo not begin responses with conversational interjections or meta commentary. Avoid openers such as acknowledgements (\\\"Done —\\\", \\\"Got it\\\", \\\"Great question\\\") or framing phrases.\\n\\nBefore substantial work, send a short update describing your first step. Before editing files, send an update describing the edit.\\n\\nAfter you have sufficient context, and the work is substantial you can provide a longer plan (this is the only user update that may be longer than 2 sentences and can contain formatting).\\n\\n### `final` channel\\n\\nUse final for the completed response.\\n\\nStructure your final response if necessary. The complexity of the answer should match the task. If the task is simple, your answer should be a one-liner. Order sections from general to specific to supporting.\\n\\nIf the user asks for a code explanation, include code references. For simple tasks, just state the outcome without heavy formatting.\\n\\nFor large or complex changes, lead with the solution, then explain what you did and why. For casual chat, just chat. If something couldn’t be done (tests, builds, etc.), say so. Suggest next steps only when they are natural and useful; if you list options, use numbered items.\\n\"},{\"role\":\"user\",\"content\":\"Say hello in one short sentence.\"}],\"stream\":true,\"stream_options\":{\"include_usage\":true},\"max_tokens\":20,\"temperature\":0}" }, "response": { "status": 200, diff --git a/packages/core/test/plugin/host.ts b/packages/core/test/plugin/host.ts index 3274ddf261..b999e46252 100644 --- a/packages/core/test/plugin/host.ts +++ b/packages/core/test/plugin/host.ts @@ -21,6 +21,7 @@ export function host(overrides: Overrides = {}): PluginContext { return { options: {}, agent: overrides.agent ?? { + get: () => Effect.die("unused agent.get"), list: () => Effect.die("unused agent.list"), transform: () => Effect.die("unused agent.transform"), reload: () => Effect.die("unused agent.reload"), @@ -34,6 +35,7 @@ export function host(overrides: Overrides = {}): PluginContext { get: () => Effect.die("unused catalog.provider.get"), }, model: { + get: () => Effect.die("unused catalog.model.get"), list: () => Effect.die("unused catalog.model.list"), default: () => Effect.die("unused catalog.model.default"), }, @@ -102,6 +104,7 @@ export function host(overrides: Overrides = {}): PluginContext { export function agentHost(agent: AgentV2.Interface): PluginContext["agent"] { return { + get: (id) => agent.get(AgentV2.ID.make(id)).pipe(Effect.map((value) => value && agentInfo(value))), list: () => Effect.die("unused agent.list"), reload: agent.reload, transform: (callback) => @@ -132,6 +135,10 @@ export function catalogHost(catalog: Catalog.Interface): PluginContext["catalog" get: () => Effect.die("unused catalog.provider.get"), }, model: { + get: (providerID, modelID) => + catalog.model + .get(ProviderV2.ID.make(providerID), ModelV2.ID.make(modelID)) + .pipe(Effect.map((value) => value && modelInfo(value))), list: () => Effect.die("unused catalog.model.list"), default: () => Effect.die("unused catalog.model.default"), }, diff --git a/packages/core/test/plugin/promise.test.ts b/packages/core/test/plugin/promise.test.ts index b0250b1b25..8619b0e39c 100644 --- a/packages/core/test/plugin/promise.test.ts +++ b/packages/core/test/plugin/promise.test.ts @@ -2,6 +2,8 @@ import { describe, expect } from "bun:test" import { Message, SystemPart } from "@opencode-ai/ai" import { Effect, Schema } from "effect" import { AgentV2 } from "@opencode-ai/core/agent" +import { Catalog } from "@opencode-ai/core/catalog" +import { ModelV2 } from "@opencode-ai/core/model" import { PluginV2 } from "@opencode-ai/core/plugin" import { PluginHooks } from "@opencode-ai/core/plugin/hooks" import { PluginHost } from "@opencode-ai/core/plugin/host" @@ -9,6 +11,7 @@ import { PluginPromise } from "@opencode-ai/core/plugin/promise" import { SessionV2 } from "@opencode-ai/core/session" import { SessionMessage } from "@opencode-ai/core/session/message" import { ToolRegistry } from "@opencode-ai/core/tool/registry" +import { ProviderV2 } from "@opencode-ai/core/provider" import { Plugin } from "@opencode-ai/plugin/v2" import type { SessionHooks } from "@opencode-ai/plugin/v2/effect/session" import { Model } from "@opencode-ai/schema/model" @@ -48,6 +51,37 @@ describe("fromPromise", () => { }), ) + it.effect("forwards direct agent and model reads", () => + Effect.gen(function* () { + const agents = yield* AgentV2.Service + const catalog = yield* Catalog.Service + const plugin = yield* PluginV2.Service + const host = yield* PluginHost.make(plugin) + yield* agents.transform((draft) => + draft.update(AgentV2.ID.make("reviewer"), (agent) => { + agent.description = "Reviews code" + }), + ) + yield* catalog.transform((draft) => + draft.model.update(ProviderV2.ID.make("test"), ModelV2.ID.make("alias"), (model) => { + model.modelID = ModelV2.ID.make("gpt-5") + }), + ) + + yield* PluginPromise.fromPromise( + Plugin.define({ + id: "promise-direct-reads", + setup: async (ctx) => { + expect(await ctx.agent.get("reviewer")).toMatchObject({ description: "Reviews code" }) + expect(await ctx.agent.get("missing")).toBeUndefined() + expect(await ctx.catalog.model.get("test", "alias")).toMatchObject({ modelID: "gpt-5" }) + expect(await ctx.catalog.model.get("test", "missing")).toBeUndefined() + }, + }), + ).effect(host) + }), + ) + it.effect("loads a promise plugin and registers a transform hook", () => Effect.gen(function* () { const agents = yield* AgentV2.Service diff --git a/packages/core/test/plugin/system-prompt.test.ts b/packages/core/test/plugin/system-prompt.test.ts new file mode 100644 index 0000000000..724ab681b1 --- /dev/null +++ b/packages/core/test/plugin/system-prompt.test.ts @@ -0,0 +1,161 @@ +import { describe, expect, test } from "bun:test" +import { SystemPart } from "@opencode-ai/ai" +import { AgentV2 } from "@opencode-ai/core/agent" +import { Catalog } from "@opencode-ai/core/catalog" +import { PluginV2 } from "@opencode-ai/core/plugin" +import { PluginHooks } from "@opencode-ai/core/plugin/hooks" +import { PluginHost } from "@opencode-ai/core/plugin/host" +import { SystemPromptPlugin } from "@opencode-ai/core/plugin/system-prompt" +import { SessionV2 } from "@opencode-ai/core/session" +import type { SessionHooks } from "@opencode-ai/plugin/v2/effect/session" +import { Model } from "@opencode-ai/schema/model" +import { Provider } from "@opencode-ai/schema/provider" +import { Effect } from "effect" +import { testEffect } from "../lib/effect" +import { PluginTestLayer } from "./fixture" +import PROMPT_META from "../../src/plugin/system-prompt/meta.txt" +import PROMPT_DEFAULT from "../../src/session/runner/prompt/base.txt" + +const it = testEffect(PluginTestLayer) +const fallback = PROMPT_DEFAULT +const makeHost = Effect.gen(function* () { + const plugins = yield* PluginV2.Service + return yield* PluginHost.make(plugins) +}) + +const context = (id: string, system = fallback): SessionHooks["context"] => ({ + sessionID: SessionV2.ID.make("ses_system_prompt"), + agent: AgentV2.ID.make("build"), + model: Model.Ref.make({ providerID: Provider.ID.make("test"), id: Model.ID.make(id) }), + system: [SystemPart.make(system)], + messages: [], + tools: {}, +}) + +describe("SystemPromptPlugin", () => { + test("uses V2 vocabulary in the Meta prompt", () => { + expect(PROMPT_META).toContain("webfetch tool") + expect(PROMPT_META).toContain("subagent tool") + expect(PROMPT_META).toContain("shell tool") + expect(PROMPT_META).toContain("read for reading files") + expect(PROMPT_META).toContain("edit for editing") + expect(PROMPT_META).toContain("write for creating files") + expect(PROMPT_META).toContain("https://v2.opencode.ai/llms.txt") + expect(PROMPT_META).not.toMatch( + /TodoWrite|Task tool|WebFetch|\bBash\b|Read for reading files|Edit for editing|Write for creating files|https:\/\/opencode\.ai\/docs/, + ) + }) + + test("uses granular IDs with a common prefix", () => { + expect(SystemPromptPlugin.Plugins.map((plugin) => plugin.id)).toEqual([ + "opencode.system-prompt.openai", + "opencode.system-prompt.google", + "opencode.system-prompt.anthropic", + "opencode.system-prompt.kimi", + "opencode.system-prompt.arcee", + "opencode.system-prompt.meta", + ]) + }) + + it.effect("selects model-lab prompts through session context hooks", () => + Effect.gen(function* () { + const hooks = yield* PluginHooks.Service + const pluginHost = yield* makeHost + yield* Effect.forEach(SystemPromptPlugin.Plugins, (plugin) => plugin.effect(pluginHost), { + discard: true, + }) + const cases = [ + ["gpt-5", "You are OpenCode, You and the user share the same workspace"], + ["gpt-4.1", "You are OpenCode, You and the user share the same workspace"], + ["o3", "You are OpenCode, You and the user share the same workspace"], + ["gpt-5-codex", "## Editing constraints"], + ["gemini-2.5-pro", "# Core Mandates"], + ["claude-sonnet-4", "# Professional objectivity"], + ["kimi-k2", "# Prompt and Tool Use"], + ["trinity", "what command should I run to list files"], + ["meta/muse-spark-1.1", "OpenCode powered by Meta Muse Spark"], + ["llama-3.3", "You are opencode, an interactive CLI tool"], + ] as const + + yield* Effect.forEach( + cases, + ([id, expected]) => { + const event = context(id) + return hooks + .trigger("session", "context", event) + .pipe(Effect.tap(() => Effect.sync(() => expect(event.system[0]?.text).toContain(expected)))) + }, + { discard: true }, + ) + }), + ) + + it.effect("preserves an explicit agent system prompt", () => + Effect.gen(function* () { + const agents = yield* AgentV2.Service + const hooks = yield* PluginHooks.Service + yield* agents.transform((draft) => + draft.update(AgentV2.ID.make("build"), (agent) => { + agent.system = "Custom agent prompt" + }), + ) + const pluginHost = yield* makeHost + yield* Effect.forEach(SystemPromptPlugin.Plugins, (plugin) => plugin.effect(pluginHost), { + discard: true, + }) + const event = context("gpt-5", "Custom agent prompt") + + yield* hooks.trigger("session", "context", event) + + expect(event.system.map((part) => part.text)).toEqual(["Custom agent prompt"]) + }), + ) + + it.effect("allows one model-lab prompt plugin to be enabled independently", () => + Effect.gen(function* () { + const hooks = yield* PluginHooks.Service + const pluginHost = yield* makeHost + yield* SystemPromptPlugin.GooglePlugin.effect(pluginHost) + const gemini = context("gemini-2.5-pro") + const claude = context("claude-sonnet-4") + + yield* hooks.trigger("session", "context", gemini) + yield* hooks.trigger("session", "context", claude) + + expect(gemini.system[0]?.text).toContain("# Core Mandates") + expect(claude.system[0]?.text).toBe(fallback) + }), + ) + + it.effect("selects against the catalog model ID instead of its alias", () => + Effect.gen(function* () { + const catalog = yield* Catalog.Service + const hooks = yield* PluginHooks.Service + const pluginHost = yield* makeHost + yield* catalog.transform((draft) => { + draft.model.update(Provider.ID.make("test"), Model.ID.make("openai-alias"), (model) => { + model.modelID = Model.ID.make("gpt-5") + }) + draft.model.update(Provider.ID.make("test"), Model.ID.make("gpt-5-alias"), (model) => { + model.modelID = Model.ID.make("custom-model") + }) + draft.model.update(Provider.ID.make("test"), Model.ID.make("codex-family-alias"), (model) => { + model.modelID = Model.ID.make("custom-deployment") + model.family = Model.Family.make("gpt-codex") + }) + }) + yield* SystemPromptPlugin.OpenAIPlugin.effect(pluginHost) + const physicalOpenAI = context("openai-alias") + const physicalCustom = context("gpt-5-alias") + const familyOpenAI = context("codex-family-alias") + + yield* hooks.trigger("session", "context", physicalOpenAI) + yield* hooks.trigger("session", "context", physicalCustom) + yield* hooks.trigger("session", "context", familyOpenAI) + + expect(physicalOpenAI.system[0]?.text).toContain("You are OpenCode, You and the user share the same workspace") + expect(physicalCustom.system[0]?.text).toBe(fallback) + expect(familyOpenAI.system[0]?.text).toContain("## Editing constraints") + }), + ) +}) diff --git a/packages/core/test/session-runner-recorded.test.ts b/packages/core/test/session-runner-recorded.test.ts index 58893bbb0f..c5e4d6c52d 100644 --- a/packages/core/test/session-runner-recorded.test.ts +++ b/packages/core/test/session-runner-recorded.test.ts @@ -1,6 +1,7 @@ import { HttpRecorder } from "@opencode-ai/http-recorder" import * as OpenAIChat from "@opencode-ai/ai/protocols/openai-chat" import { Auth, LLMClient, RequestExecutor } from "@opencode-ai/ai/route" +import { Catalog } from "@opencode-ai/core/catalog" import { Database } from "@opencode-ai/core/database/database" import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder" import { LayerNodePlatform } from "@opencode-ai/core/effect/app-node-platform" @@ -36,11 +37,14 @@ import { SkillGuidance } from "@opencode-ai/core/skill/guidance" import { ReferenceGuidance } from "@opencode-ai/core/reference/guidance" import { McpGuidance } from "@opencode-ai/core/mcp/guidance" import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor" +import { PluginHooks } from "@opencode-ai/core/plugin/hooks" +import { SystemPromptPlugin } from "@opencode-ai/core/plugin/system-prompt" import { describe, expect } from "bun:test" import { eq } from "drizzle-orm" import { Effect, Layer } from "effect" import path from "node:path" import { testEffect } from "./lib/effect" +import { agentHost, catalogHost, host } from "./plugin/host" const cassetteName = "session-runner/openai-chat-streams-text" const cassetteDirectory = path.resolve(import.meta.dir, "fixtures/recordings") @@ -77,6 +81,20 @@ const referenceGuidance = Layer.mock(ReferenceGuidance.Service, { load: () => Ef const mcpGuidance = Layer.mock(McpGuidance.Service, { load: () => Effect.succeed(Instructions.empty) }) const config = Layer.succeed(Config.Service, Config.Service.of({ entries: () => Effect.succeed([]) })) const pluginSupervisor = Layer.succeed(PluginSupervisor.Service, PluginSupervisor.Service.of({ flush: Effect.void })) +const promptCatalog = Layer.mock(Catalog.Service, { + provider: { + get: () => Effect.succeed(undefined), + all: () => Effect.succeed([]), + available: () => Effect.succeed([]), + }, + model: { + get: () => Effect.succeed(undefined), + all: () => Effect.succeed([]), + available: () => Effect.succeed([]), + default: () => Effect.succeed(undefined), + small: () => Effect.succeed(undefined), + }, +}) const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [ [Snapshot.node, Snapshot.noopLayer], [LayerNodePlatform.llmClient, client], @@ -116,6 +134,8 @@ const it = testEffect( SessionProjector.node, SessionStore.node, AgentV2.node, + Catalog.node, + PluginHooks.node, ToolRegistry.node, SessionRunnerModel.node, InstructionBuiltIns.node, @@ -130,6 +150,7 @@ const it = testEffect( [ [LayerNodePlatform.llmClient, client], [PermissionV2.node, permission], + [Catalog.node, promptCatalog], [ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig], [SessionRunnerModel.node, models], [InstructionBuiltIns.node, systemContext], @@ -150,11 +171,19 @@ describe("SessionRunnerLLM recorded", () => { it.effect("executes one recorded V2 prompt through the recorded HTTP transport", () => Effect.gen(function* () { const agents = yield* AgentV2.Service + const catalog = yield* Catalog.Service + const hooks = yield* PluginHooks.Service yield* agents.transform((draft) => draft.update(AgentV2.ID.make("build"), (agent) => { agent.mode = "primary" }), ) + const pluginHost = host({ + agent: agentHost(agents), + catalog: catalogHost(catalog), + session: { hook: (name, callback) => hooks.register("session", name, callback) }, + }) + yield* Effect.forEach(SystemPromptPlugin.Plugins, (plugin) => plugin.effect(pluginHost), { discard: true }) const { db } = yield* Database.Service yield* db .insert(ProjectTable) diff --git a/packages/core/test/session-runner-system-prompt.test.ts b/packages/core/test/session-runner-system-prompt.test.ts deleted file mode 100644 index a367d913e5..0000000000 --- a/packages/core/test/session-runner-system-prompt.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, test } from "bun:test" -import { Model } from "@opencode-ai/ai" -import * as OpenAIChat from "@opencode-ai/ai/protocols/openai-chat" -import { SessionRunnerSystemPrompt } from "@opencode-ai/core/session/runner/system-prompt" - -const prompt = (id: string) => - SessionRunnerSystemPrompt.provider(Model.make({ id, provider: "test", route: OpenAIChat.route })) - -describe("SessionRunnerSystemPrompt", () => { - test("selects the legacy provider-family prompts from the model id", () => { - expect(prompt("gpt-5")).toContain("You are OpenCode, You and the user share the same workspace") - expect(prompt("gpt-4.1")).toContain("THE PROBLEM CAN NOT BE SOLVED WITHOUT EXTENSIVE INTERNET RESEARCH") - expect(prompt("o3")).toContain("THE PROBLEM CAN NOT BE SOLVED WITHOUT EXTENSIVE INTERNET RESEARCH") - expect(prompt("gpt-5-codex")).toContain("## Editing constraints") - expect(prompt("gemini-2.5-pro")).toContain("# Core Mandates") - expect(prompt("claude-sonnet-4")).toContain("# Professional objectivity") - expect(prompt("kimi-k2")).toContain("# Prompt and Tool Use") - expect(prompt("trinity")).toContain("what command should I run to list files") - expect(prompt("llama-3.3")).toContain("You are opencode, an interactive CLI tool") - }) -}) diff --git a/packages/core/test/session-runner.test.ts b/packages/core/test/session-runner.test.ts index 6c35f02d87..79df6ad1cb 100644 --- a/packages/core/test/session-runner.test.ts +++ b/packages/core/test/session-runner.test.ts @@ -15,6 +15,7 @@ import { type LLMRequest, } from "@opencode-ai/ai" import * as OpenAIChat from "@opencode-ai/ai/protocols/openai-chat" +import { Catalog } from "@opencode-ai/core/catalog" import { Database } from "@opencode-ai/core/database/database" import { makeLocationNode } from "@opencode-ai/core/effect/app-node" import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder" @@ -41,10 +42,10 @@ import { SessionRunCoordinator } from "@opencode-ai/core/session/run-coordinator import { SessionRunner } from "@opencode-ai/core/session/runner" import * as SessionRunnerLLM from "@opencode-ai/core/session/runner/llm" import { SessionRunnerModel } from "@opencode-ai/core/session/runner/model" -import { SessionRunnerSystemPrompt } from "@opencode-ai/core/session/runner/system-prompt" import { ToolRegistry } from "@opencode-ai/core/tool/registry" import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor" import { PluginHooks } from "@opencode-ai/core/plugin/hooks" +import { SystemPromptPlugin } from "@opencode-ai/core/plugin/system-prompt" import { QuestionTool } from "@opencode-ai/core/tool/question" import { ToolOutputStore } from "@opencode-ai/core/tool-output-store" import { AgentV2 } from "@opencode-ai/core/agent" @@ -72,6 +73,8 @@ import { Cause, DateTime, Deferred, Effect, Exit, Fiber, Layer, Schema, Scope, S import { TestClock } from "effect/testing" import { asc, eq } from "drizzle-orm" import { testEffect } from "./lib/effect" +import { agentHost, catalogHost, host } from "./plugin/host" +import PROMPT_DEFAULT from "../src/session/runner/prompt/base.txt" const requests: LLMRequest[] = [] let response: LLMEvent[] = [] @@ -137,7 +140,7 @@ const reply = { ], } const model = Model.make({ id: "fake-model", provider: "fake", route: OpenAIChat.route }) -const defaultSystem = SessionRunnerSystemPrompt.provider(model) +const defaultSystem = PROMPT_DEFAULT const replacementModel = Model.make({ id: "replacement", provider: "fake", route: OpenAIChat.route }) const compactModel = Model.make({ id: "compact", @@ -358,6 +361,20 @@ const pluginSupervisor = Layer.succeed( flush: Effect.suspend(() => pluginFlushHook), }), ) +const promptCatalog = Layer.mock(Catalog.Service, { + provider: { + get: () => Effect.succeed(undefined), + all: () => Effect.succeed([]), + available: () => Effect.succeed([]), + }, + model: { + get: () => Effect.succeed(undefined), + all: () => Effect.succeed([]), + available: () => Effect.succeed([]), + default: () => Effect.succeed(undefined), + small: () => Effect.succeed(undefined), + }, +}) const runnerLayer = AppNodeBuilder.build(SessionRunnerLLM.node, [ [Snapshot.node, Snapshot.noopLayer], [LayerNodePlatform.llmClient, client], @@ -398,6 +415,7 @@ const it = testEffect( SessionProjector.node, SessionStore.node, AgentV2.node, + Catalog.node, ToolRegistry.node, ToolRegistry.toolsNode, PluginHooks.node, @@ -417,6 +435,7 @@ const it = testEffect( [ [LayerNodePlatform.llmClient, client], [PermissionV2.node, permission], + [Catalog.node, promptCatalog], [SessionRunnerModel.node, models], [InstructionBuiltIns.node, systemContext], [InstructionDiscovery.node, instructionContext], @@ -455,6 +474,17 @@ const insertSession = (id: SessionV2.ID) => const setup = Effect.gen(function* () { const { db } = yield* Database.Service + const agents = yield* AgentV2.Service + const catalog = yield* Catalog.Service + const hooks = yield* PluginHooks.Service + const pluginHost = host({ + agent: agentHost(agents), + catalog: catalogHost(catalog), + session: { hook: (name, callback) => hooks.register("session", name, callback) }, + }) + yield* Effect.forEach(SystemPromptPlugin.Plugins, (plugin) => plugin.effect(pluginHost), { + discard: true, + }) requests.length = 0 authorizations.length = 0 executions.length = 0 @@ -478,7 +508,6 @@ const setup = Effect.gen(function* () { toolExecutionsReady = 5 activeToolExecutions = 0 maxActiveToolExecutions = 0 - const agents = yield* AgentV2.Service yield* agents.transform((draft) => draft.update(AgentV2.ID.make("build"), (agent) => { agent.mode = "primary" diff --git a/packages/docs/build/plugins.mdx b/packages/docs/build/plugins.mdx index ad9cff8a3e..0a8c1c7d0f 100644 --- a/packages/docs/build/plugins.mdx +++ b/packages/docs/build/plugins.mdx @@ -169,9 +169,9 @@ and plugin options. | Capability | Available operations | | ---------------------- | -------------------------------------------------------------------------------------------- | -| `ctx.agent` | `list`, `transform`, `reload` | +| `ctx.agent` | `list`, `get`, `transform`, `reload` | | `ctx.catalog.provider` | `list`, `get` | -| `ctx.catalog.model` | `list`, `default` | +| `ctx.catalog.model` | `list`, `get`, `default` | | `ctx.catalog` | `transform`, `reload` | | `ctx.command` | `list`, `transform`, `reload` | | `ctx.integration` | `list`, `get`, `connect`, `attempt`, `transform`, `reload`, and connection lookup/resolution | diff --git a/packages/plugin/src/v2/effect/agent.ts b/packages/plugin/src/v2/effect/agent.ts index d5125cca2a..e14777af77 100644 --- a/packages/plugin/src/v2/effect/agent.ts +++ b/packages/plugin/src/v2/effect/agent.ts @@ -12,6 +12,9 @@ export interface AgentDraft { } export interface AgentDomain extends AgentApi { + readonly get: (id: string) => Effect.Effect readonly transform: Transform readonly reload: () => Effect.Effect } + +type AgentGetOutput = Effect.Success["list"]>>["data"][number] diff --git a/packages/plugin/src/v2/effect/catalog.ts b/packages/plugin/src/v2/effect/catalog.ts index b96ceec4a8..834578dd60 100644 --- a/packages/plugin/src/v2/effect/catalog.ts +++ b/packages/plugin/src/v2/effect/catalog.ts @@ -27,6 +27,11 @@ export interface CatalogDraft { } export interface CatalogDomain extends CatalogApi { + readonly model: CatalogApi["model"] & { + readonly get: (providerID: string, modelID: string) => Effect.Effect + } readonly transform: Transform readonly reload: () => Effect.Effect } + +type ModelGetOutput = Effect.Success["model"]["list"]>>["data"][number] diff --git a/packages/plugin/src/v2/promise/agent.ts b/packages/plugin/src/v2/promise/agent.ts index bfffdebb4e..af5a1f6850 100644 --- a/packages/plugin/src/v2/promise/agent.ts +++ b/packages/plugin/src/v2/promise/agent.ts @@ -5,6 +5,9 @@ import type { Transform } from "./registration.js" export type { AgentDraft } export interface AgentDomain extends AgentApi { + readonly get: (id: string) => Promise readonly transform: Transform readonly reload: () => Promise } + +type AgentGetOutput = Awaited>["data"][number] diff --git a/packages/plugin/src/v2/promise/catalog.ts b/packages/plugin/src/v2/promise/catalog.ts index e0a51f5e52..26cc25caa3 100644 --- a/packages/plugin/src/v2/promise/catalog.ts +++ b/packages/plugin/src/v2/promise/catalog.ts @@ -5,6 +5,11 @@ import type { Transform } from "./registration.js" export type { CatalogDraft, CatalogProviderRecord } export interface CatalogDomain extends CatalogApi { + readonly model: CatalogApi["model"] & { + readonly get: (providerID: string, modelID: string) => Promise + } readonly transform: Transform readonly reload: () => Promise } + +type ModelGetOutput = Awaited>["data"][number]