Explorar el Código

fix(image-hook): scope .gitignore to images directory only

The previous content ('*') did not match files in subdirectories, so saved images were still tracked by git, while the plugin's own project config (.opencode/oh-my-opencode-slim.json) and prompt override files got silently ignored. Write 'images/' instead and cover it with a regression test.
pxmps hace 1 semana
padre
commit
200a307b4d
Se han modificado 2 ficheros con 20 adiciones y 1 borrados
  1. 14 0
      src/hooks/image-hook.test.ts
  2. 6 1
      src/hooks/image-hook.ts

+ 14 - 0
src/hooks/image-hook.test.ts

@@ -2,6 +2,7 @@ import { afterAll, describe, expect, it } from 'bun:test';
 import {
   chmodSync,
   mkdirSync,
+  readFileSync,
   rmSync,
   utimesSync,
   writeFileSync,
@@ -116,6 +117,19 @@ describe('processImageAttachments image routing', () => {
     expect(textParts[0]?.text).toContain('@observer');
   });
 
+  it('writes a .gitignore covering only the images directory', () => {
+    const { workDir } = makeTestDir('gitignore-scope');
+    processImageAttachments({
+      messages: [makeUserMsg([IMG])],
+      workDir,
+      imageRouting: 'auto',
+      disabledAgents: new Set<string>(),
+      log: () => {},
+    });
+    const gitignorePath = path.join(workDir, '.opencode', '.gitignore');
+    expect(readFileSync(gitignorePath, 'utf8')).toBe('images/\n');
+  });
+
   it('resolves omitted image routing to auto and intercepts for Observer', () => {
     const message = makeUserMsg([IMG]);
     processImageAttachments({

+ 6 - 1
src/hooks/image-hook.ts

@@ -254,7 +254,12 @@ export function processImageAttachments(args: {
   const gitignorePath = join(workDir, '.opencode', '.gitignore');
   try {
     mkdirSync(saveDir, { recursive: true });
-    if (!existsSync(gitignorePath)) writeFileSync(gitignorePath, '*\n');
+    // Only the images directory is ignored. Ignoring everything ('*\n')
+    // would also ignore the plugin's own project config
+    // (.opencode/oh-my-opencode-slim.json) and prompt overrides, and in
+    // gitignore semantics a bare '*' does not match files in subdirectories,
+    // so saved images would still be tracked.
+    if (!existsSync(gitignorePath)) writeFileSync(gitignorePath, 'images/\n');
   } catch (e) {
     log(`[image-hook] failed to create image directory: ${e}`);
   }