Просмотр исходного кода

tweak: adjust order of system prompt instructions: Global, Project, Skills (#24974)

Aiden Cline 4 месяцев назад
Родитель
Сommit
00bb9836a6

+ 7 - 7
packages/opencode/src/session/instruction.ts

@@ -122,6 +122,13 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Config.S
         const ctx = yield* InstanceState.context
         const ctx = yield* InstanceState.context
         const paths = new Set<string>()
         const paths = new Set<string>()
 
 
+        for (const file of globalFiles()) {
+          if (yield* fs.existsSafe(file)) {
+            paths.add(path.resolve(file))
+            break
+          }
+        }
+
         // The first project-level match wins so we don't stack AGENTS.md/CLAUDE.md from every ancestor.
         // The first project-level match wins so we don't stack AGENTS.md/CLAUDE.md from every ancestor.
         if (!Flag.OPENCODE_DISABLE_PROJECT_CONFIG) {
         if (!Flag.OPENCODE_DISABLE_PROJECT_CONFIG) {
           for (const file of FILES) {
           for (const file of FILES) {
@@ -133,13 +140,6 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Config.S
           }
           }
         }
         }
 
 
-        for (const file of globalFiles()) {
-          if (yield* fs.existsSafe(file)) {
-            paths.add(path.resolve(file))
-            break
-          }
-        }
-
         if (config.instructions) {
         if (config.instructions) {
           for (const raw of config.instructions) {
           for (const raw of config.instructions) {
             if (raw.startsWith("https://") || raw.startsWith("http://")) continue
             if (raw.startsWith("https://") || raw.startsWith("http://")) continue

+ 1 - 1
packages/opencode/src/session/prompt.ts

@@ -1445,7 +1445,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
               instruction.system().pipe(Effect.orDie),
               instruction.system().pipe(Effect.orDie),
               MessageV2.toModelMessagesEffect(msgs, model),
               MessageV2.toModelMessagesEffect(msgs, model),
             ])
             ])
-            const system = [...env, ...(skills ? [skills] : []), ...instructions]
+            const system = [...env, ...instructions, ...(skills ? [skills] : [])]
             const format = lastUser.format ?? { type: "text" as const }
             const format = lastUser.format ?? { type: "text" as const }
             if (format.type === "json_schema") system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT)
             if (format.type === "json_schema") system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT)
             const result = yield* handle.process({
             const result = yield* handle.process({

+ 4 - 4
packages/opencode/test/session/instruction.test.ts

@@ -251,12 +251,12 @@ describe("Instruction.system", () => {
 
 
                 const rules = yield* svc.system()
                 const rules = yield* svc.system()
                 expect(rules).toHaveLength(2)
                 expect(rules).toHaveLength(2)
-                expect(rules).toContain(
-                  `Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`,
-                )
-                expect(rules).toContain(
+                expect(rules[0]).toBe(
                   `Instructions from: ${path.join(globalTmp.path, "AGENTS.md")}\n# Global Instructions`,
                   `Instructions from: ${path.join(globalTmp.path, "AGENTS.md")}\n# Global Instructions`,
                 )
                 )
+                expect(rules[1]).toBe(
+                  `Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`,
+                )
               }),
               }),
             ),
             ),
           ),
           ),