Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): require declared Forge package files

Yuewei-LLd2a328f0d4e7
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
index 9a1dc91146..99bbc0b930 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
@@ -406,6 +406,92 @@ describe('packGhostDir', () => {
});
});
+ it('rejects a declared file below a linked ancestor instead of omitting it from the package', async () => {
+ const manifest = {
+ ...GOOD_MANIFEST,
+ slots: ['tool', 'panel'],
+ panel: { title: 'Linked panel', html: 'linked/panel.html', minWidth: 240 },
+ };
+ const dir = await makeSrcDir({
+ 'ghost.json': JSON.stringify(manifest),
+ 'main.js': '// authoring source',
+ });
+ const realPanelDir = path.join(workDir, 'real-panel');
+ await fs.promises.mkdir(realPanelDir);
+ await fs.promises.writeFile(path.join(realPanelDir, 'panel.html'), '<main>linked</main>');
+ try {
+ await fs.promises.symlink(realPanelDir, path.join(dir, 'linked'), directoryLinkType);
+ } catch {
+ return;
+ }
+
+ await expect(packGhostDir(dir)).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'ENTRY_MISSING',
+ });
+ });
+
+ it('rejects a required path whose casing differs from the collected ZIP entry', async () => {
+ const manifest = { ...GOOD_MANIFEST, entry: 'Main.js' };
+ const dir = await makeSrcDir({
+ 'ghost.json': JSON.stringify(manifest),
+ 'main.js': '// actual lower-case path',
+ });
+ const declaredEntry = path.join(dir, 'Main.js');
+ const actualEntry = path.join(dir, 'main.js');
+ const originalLstat = fs.promises.lstat.bind(fs.promises);
+ const lstatSpy = vi.spyOn(fs.promises, 'lstat').mockImplementation(async (file: fs.PathLike, options?: fs.StatOptions) => {
+ const target = path.resolve(String(file)) === path.resolve(declaredEntry) ? actualEntry : file;
+ return (
+ originalLstat as (p: fs.PathLike, o?: fs.StatOptions) => Promise<fs.Stats & fs.BigIntStats>
+ )(target, options);
+ });
+ try {
+ await expect(packGhostDir(dir)).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'ENTRY_MISSING',
+ });
+ } finally {
+ lstatSpy.mockRestore();
+ }
+ });
+
+ it('rejects a missing extra node entry instead of producing a partially runnable package', async () => {
+ const manifest = {
+ ...GOOD_MANIFEST,
+ slots: ['node'],
+ tools: undefined,
+ node: {
+ entry: 'node/worker.cjs',
+ entries: ['node/secondary.cjs'],
+ protocol: 'json-rpc-stdio',
+ },
+ };
+ const dir = await makeSrcDir({
+ 'ghost.json': JSON.stringify(manifest),
+ 'main.js': '// browser brain',
+ 'node/worker.cjs': '// primary worker',
+ });
+
+ await expect(packGhostDir(dir)).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'ENTRY_MISSING',
+ });
+ });
+
+ it('rejects a missing declared icon when no icon overlay is supplied', async () => {
+ const manifest = { ...GOOD_MANIFEST, icon: 'assets/icon.png' };
+ const dir = await makeSrcDir({
+ 'ghost.json': JSON.stringify(manifest),
+ 'main.js': '// browser brain',
+ });
+
+ await expect(packGhostDir(dir)).resolves.toMatchObject({
+ ok: false,
+ errorCode: 'ENTRY_MISSING',
+ });
+ });
+
it('allows an independent authoring directory outside managed roots', async () => {
const dir = await makeSrcDir({
'ghost.json': JSON.stringify(GOOD_MANIFEST),
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index a046162172..4434676a2d 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -755,10 +755,13 @@ async function buildGhostPackage(
// 3) 清单声明的入口文件必须真实在场(打包期拦,别等装入后沙箱 404)。
const mustExist: string[] = [];
if (manifest.entry) mustExist.push(manifest.entry);
- if (manifest.node?.entry) mustExist.push(manifest.node.entry);
+ if (manifest.node?.entry) {
+ mustExist.push(manifest.node.entry, ...(manifest.node.entries ?? []));
+ }
if (manifest.panel?.html) mustExist.push(manifest.panel.html);
if (manifest.settingsHtml) mustExist.push(manifest.settingsHtml);
for (const item of manifest.skill?.items ?? []) mustExist.push(`${item.dir}/SKILL.md`);
+ if (iconPng === undefined && manifest.icon) mustExist.push(manifest.icon);
for (const rel of mustExist) {
try {
// lstat 与收集侧(walk 的 Dirent)同一语义:声明的入口若是符号链接,
@@ -901,6 +904,17 @@ async function buildGhostPackage(
};
const tooLarge = await walk(dir, '');
if (tooLarge) return tooLarge;
+ const collectedPackPaths = new Set(files.map((file) => file.rel));
+ const omittedRequiredPath = mustExist.find(
+ (requiredPath) => !collectedPackPaths.has(requiredPath),
+ );
+ if (omittedRequiredPath) {
+ return {
+ ok: false,
+ errorCode: 'ENTRY_MISSING',
+ message: `清单声明的文件未进入打包内容:${omittedRequiredPath}`,
+ };
+ }
// AI icon overlay changes both the manifest snapshot and the icon bytes. A
// source tree carrying a publisher/reviewer signature cannot be modified
// here without re-signing, so let the host fall back to the original icon