mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 13:01:41 +00:00
fix(coding-agent): follow symlinked directories in prompt template loading (#601)
This commit is contained in:
parent
fbc4e89f84
commit
cfef1069bb
2 changed files with 21 additions and 3 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Symlinked directories in `prompts/` folders are now followed when loading prompt templates ([#601](https://github.com/badlogic/pi-mono/pull/601) by [@aliou](https://github.com/aliou))
|
||||||
|
|
||||||
## [0.42.0] - 2026-01-09
|
## [0.42.0] - 2026-01-09
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { existsSync, readdirSync, readFileSync } from "fs";
|
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
||||||
import { join, resolve } from "path";
|
import { join, resolve } from "path";
|
||||||
import { CONFIG_DIR_NAME, getPromptsDir } from "../config.js";
|
import { CONFIG_DIR_NAME, getPromptsDir } from "../config.js";
|
||||||
|
|
||||||
|
|
@ -124,11 +124,25 @@ function loadTemplatesFromDir(dir: string, source: "user" | "project", subdir: s
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const fullPath = join(dir, entry.name);
|
const fullPath = join(dir, entry.name);
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
// For symlinks, check if they point to a directory and follow them
|
||||||
|
let isDirectory = entry.isDirectory();
|
||||||
|
let isFile = entry.isFile();
|
||||||
|
if (entry.isSymbolicLink()) {
|
||||||
|
try {
|
||||||
|
const stats = statSync(fullPath);
|
||||||
|
isDirectory = stats.isDirectory();
|
||||||
|
isFile = stats.isFile();
|
||||||
|
} catch {
|
||||||
|
// Broken symlink, skip it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDirectory) {
|
||||||
// Recurse into subdirectory
|
// Recurse into subdirectory
|
||||||
const newSubdir = subdir ? `${subdir}:${entry.name}` : entry.name;
|
const newSubdir = subdir ? `${subdir}:${entry.name}` : entry.name;
|
||||||
templates.push(...loadTemplatesFromDir(fullPath, source, newSubdir));
|
templates.push(...loadTemplatesFromDir(fullPath, source, newSubdir));
|
||||||
} else if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".md")) {
|
} else if (isFile && entry.name.endsWith(".md")) {
|
||||||
try {
|
try {
|
||||||
const rawContent = readFileSync(fullPath, "utf-8");
|
const rawContent = readFileSync(fullPath, "utf-8");
|
||||||
const { frontmatter, content } = parseFrontmatter(rawContent);
|
const { frontmatter, content } = parseFrontmatter(rawContent);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue