@myrialabs/clopen 0.4.43 → 0.4.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/artifacts/project/bridge.ts +218 -0
- package/backend/artifacts/project/edit.ts +243 -0
- package/backend/artifacts/project/index.ts +38 -0
- package/backend/artifacts/project/project.test.ts +181 -0
- package/backend/artifacts/project/scan.ts +368 -0
- package/backend/artifacts/project/sources.ts +100 -0
- package/backend/artifacts/sync.ts +1 -1
- package/backend/auth/permissions.ts +15 -0
- package/backend/chat/stream-manager.ts +26 -8
- package/backend/database/migrations/083_create_project_mcp_trust.ts +32 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +2 -0
- package/backend/database/queries/project-mcp-trust-queries.ts +43 -0
- package/backend/engine/adapters/claude/message-converter.ts +6 -2
- package/backend/engine/adapters/claude/stream.ts +36 -8
- package/backend/engine/adapters/cline/mcp-tools.ts +26 -4
- package/backend/engine/adapters/cline/stream.ts +20 -6
- package/backend/engine/adapters/codex/stream.ts +21 -4
- package/backend/engine/adapters/copilot/stream.ts +6 -3
- package/backend/engine/adapters/cursor/stream.ts +19 -8
- package/backend/engine/adapters/opencode/server.ts +14 -4
- package/backend/engine/adapters/opencode/stream.ts +18 -3
- package/backend/engine/adapters/pi/mcp-tools.ts +26 -4
- package/backend/engine/adapters/pi/stream.ts +35 -3
- package/backend/engine/adapters/qwen/message-converter.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +8 -0
- package/backend/engine/artifact-sync.ts +12 -5
- package/backend/engine/docs/lessons-learned.md +118 -0
- package/backend/files/file-watcher.test.ts +77 -0
- package/backend/files/file-watcher.ts +92 -60
- package/backend/files/watch-ignore.test.ts +182 -0
- package/backend/files/watch-ignore.ts +244 -0
- package/backend/git/git-executor.ts +14 -4
- package/backend/index.ts +11 -1
- package/backend/instructions/service.ts +5 -3
- package/backend/instructions/sync.ts +10 -27
- package/backend/mcp/external/config.ts +65 -23
- package/backend/mcp/external/project.ts +124 -0
- package/backend/mcp/external/proxy.ts +65 -11
- package/backend/mcp/index.ts +14 -9
- package/backend/mcp/internal/remote-server.ts +11 -1
- package/backend/skills/marketplace.ts +1 -1
- package/backend/snapshot/blob-store.ts +9 -5
- package/backend/snapshot/git-attribution.test.ts +42 -0
- package/backend/snapshot/git-attribution.ts +306 -0
- package/backend/snapshot/gitignore.test.ts +62 -0
- package/backend/snapshot/gitignore.ts +158 -78
- package/backend/snapshot/snapshot-service.test.ts +270 -0
- package/backend/snapshot/snapshot-service.ts +412 -136
- package/backend/snapshot/turn-activity.test.ts +52 -0
- package/backend/snapshot/turn-activity.ts +83 -0
- package/backend/snapshot/turn-changes.test.ts +58 -1
- package/backend/snapshot/turn-changes.ts +66 -0
- package/backend/worktrees/tree.ts +1 -1
- package/backend/ws/chat/composer.ts +504 -0
- package/backend/ws/chat/index.ts +3 -1
- package/backend/ws/chat/stream.ts +252 -440
- package/backend/ws/index.ts +4 -0
- package/backend/ws/project-artifacts/index.ts +236 -0
- package/backend/ws/snapshot/changes.ts +66 -31
- package/dist/assets/{index-BeUKiRiY.js → index-Am-rJRxA.js} +1 -1
- package/dist/assets/{index-B6u8cait.js → index-D-Ad1N96.js} +1 -1
- package/dist/assets/main--PLCDxSy.css +1 -0
- package/dist/assets/main-DelPm2Xt.js +1239 -0
- package/dist/index.html +2 -2
- package/package.json +5 -5
- package/shared/types/stores/settings.ts +5 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +2 -0
- package/shared/types/unified/stream.ts +38 -1
- package/dist/assets/main-CMRXlv2f.js +0 -1215
- package/dist/assets/main-DzCY0n-j.css +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project artifacts: the coverage the scanner reports is the same rule the
|
|
3
|
+
* bridge delivers by, and edits never leave `.agents/` or the managed block of
|
|
4
|
+
* `AGENTS.md`. Fixtures are throwaway repos under the OS temp dir.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test, beforeEach, afterEach } from 'bun:test';
|
|
8
|
+
import { mkdtemp, mkdir, writeFile, readFile, rm, symlink, stat } from 'node:fs/promises';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
import { scanProject, parseProjectMcpJson, hashContent } from './scan';
|
|
13
|
+
import { resolveProjectBridge, buildProjectPromptContext } from './bridge';
|
|
14
|
+
import {
|
|
15
|
+
saveProjectSkill,
|
|
16
|
+
deleteProjectSkill,
|
|
17
|
+
saveProjectSubagent,
|
|
18
|
+
copyToAgents,
|
|
19
|
+
readAgentsMd,
|
|
20
|
+
saveAgentsMd,
|
|
21
|
+
saveProjectMcp,
|
|
22
|
+
readProjectFile
|
|
23
|
+
} from './edit';
|
|
24
|
+
|
|
25
|
+
let root = '';
|
|
26
|
+
|
|
27
|
+
async function put(rel: string, content: string): Promise<void> {
|
|
28
|
+
const file = join(root, rel);
|
|
29
|
+
await mkdir(join(file, '..'), { recursive: true });
|
|
30
|
+
await writeFile(file, content, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const skillDoc = (name: string, description: string) => `---\nname: ${name}\ndescription: ${description}\n---\n\nDo the thing.\n`;
|
|
34
|
+
|
|
35
|
+
beforeEach(async () => {
|
|
36
|
+
root = await mkdtemp(join(tmpdir(), 'clopen-project-artifacts-'));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(async () => {
|
|
40
|
+
await rm(root, { recursive: true, force: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('scanProject coverage', () => {
|
|
44
|
+
test('.agents/skills is native where engines read it and bridged elsewhere', async () => {
|
|
45
|
+
await put('.agents/skills/release/SKILL.md', skillDoc('release', 'Cut a release'));
|
|
46
|
+
const { skills } = await scanProject(root);
|
|
47
|
+
expect(skills).toHaveLength(1);
|
|
48
|
+
const [skill] = skills;
|
|
49
|
+
expect(skill.editable).toBe(true);
|
|
50
|
+
expect(skill.coverage.codex).toBe('native');
|
|
51
|
+
expect(skill.coverage.pi).toBe('native');
|
|
52
|
+
// Claude Code does not read .agents/skills; Cursor runs with its project source off.
|
|
53
|
+
expect(skill.coverage.claude).toBe('bridged');
|
|
54
|
+
expect(skill.coverage.cursor).toBe('bridged');
|
|
55
|
+
expect(skill.coverage.cline).toBe('bridged');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a slug an engine already reads natively elsewhere is not bridged twice', async () => {
|
|
59
|
+
await put('.agents/skills/release/SKILL.md', skillDoc('release', 'Cut a release'));
|
|
60
|
+
await put('.claude/skills/release/SKILL.md', skillDoc('release', 'Cut a release (claude copy)'));
|
|
61
|
+
const { skills } = await scanProject(root);
|
|
62
|
+
const agents = skills.find(s => s.sourceId === 'agents-skills')!;
|
|
63
|
+
const claude = skills.find(s => s.sourceId === 'claude-skills')!;
|
|
64
|
+
expect(agents.coverage.claude).toBe('none');
|
|
65
|
+
expect(claude.coverage.claude).toBe('native');
|
|
66
|
+
expect(claude.shadowedBy).toBe('agents-skills');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('subagents are only bridged to engines that can delegate', async () => {
|
|
70
|
+
await put('.agents/agents/reviewer.md', '---\nname: reviewer\ndescription: Reviews diffs\ntools: Read, Grep\n---\n\nReview carefully.\n');
|
|
71
|
+
const [sub] = (await scanProject(root)).subagents;
|
|
72
|
+
expect(sub.coverage.claude).toBe('bridged');
|
|
73
|
+
expect(sub.coverage.opencode).toBe('bridged');
|
|
74
|
+
expect(sub.coverage.codex).toBe('none');
|
|
75
|
+
expect(sub.coverage.qwen).toBe('none');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('CLAUDE.md importing AGENTS.md makes AGENTS.md native for Claude', async () => {
|
|
79
|
+
await put('AGENTS.md', 'Use bun.\n');
|
|
80
|
+
let file = (await scanProject(root)).instructions.find(f => f.sourceId === 'agents-md')!;
|
|
81
|
+
expect(file.coverage.claude).toBe('bridged');
|
|
82
|
+
await put('CLAUDE.md', '@AGENTS.md\n');
|
|
83
|
+
file = (await scanProject(root)).instructions.find(f => f.sourceId === 'agents-md')!;
|
|
84
|
+
expect(file.coverage.claude).toBe('native');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('.agents/mcp.json is only delivered once its exact content is trusted', async () => {
|
|
88
|
+
const raw = JSON.stringify({ mcpServers: { fs: { command: 'npx', args: ['server'] } } });
|
|
89
|
+
await put('.agents/mcp.json', raw);
|
|
90
|
+
const untrusted = (await scanProject(root)).mcp.find(f => f.sourceId === 'agents-mcp')!;
|
|
91
|
+
expect(untrusted.coverage.claude).toBe('none');
|
|
92
|
+
const trusted = (await scanProject(root, h => h === hashContent(raw))).mcp.find(f => f.sourceId === 'agents-mcp')!;
|
|
93
|
+
expect(trusted.coverage.claude).toBe('bridged');
|
|
94
|
+
expect(trusted.servers[0]).toMatchObject({ name: 'fs', transport: 'stdio', command: 'npx' });
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('parseProjectMcpJson', () => {
|
|
99
|
+
test('infers http from a url and rejects a server with neither command nor url', () => {
|
|
100
|
+
expect(parseProjectMcpJson('{"mcpServers":{"api":{"url":"https://example.com/mcp"}}}')[0].transport).toBe('http');
|
|
101
|
+
expect(() => parseProjectMcpJson('{"mcpServers":{"bad":{}}}')).toThrow();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('resolveProjectBridge', () => {
|
|
106
|
+
test('delivers only what the engine does not read natively', async () => {
|
|
107
|
+
await put('.agents/skills/release/SKILL.md', skillDoc('release', 'Cut a release'));
|
|
108
|
+
await put('AGENTS.md', 'Use bun.\n');
|
|
109
|
+
|
|
110
|
+
const codex = await resolveProjectBridge('codex', root);
|
|
111
|
+
expect(codex.skills).toHaveLength(0);
|
|
112
|
+
expect(codex.agentsMd).toBeNull();
|
|
113
|
+
|
|
114
|
+
const cursor = await resolveProjectBridge('cursor', root);
|
|
115
|
+
expect(cursor.skills.map(s => s.slug)).toEqual(['release']);
|
|
116
|
+
expect(cursor.agentsMd).toBe('Use bun.');
|
|
117
|
+
const context = buildProjectPromptContext(cursor);
|
|
118
|
+
expect(context).toContain('Project Skills');
|
|
119
|
+
expect(context).toContain(join(root, '.agents/skills/release/SKILL.md'));
|
|
120
|
+
expect(context).toContain('Use bun.');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('edit in place', () => {
|
|
125
|
+
test('skills are written under .agents/skills and renames move the folder', async () => {
|
|
126
|
+
const saved = await saveProjectSkill(root, { name: 'Release Notes', description: 'Draft notes', body: 'Steps' });
|
|
127
|
+
expect(saved.path).toBe('.agents/skills/release-notes');
|
|
128
|
+
expect(await readFile(join(root, '.agents/skills/release-notes/SKILL.md'), 'utf8')).toContain('description: Draft notes');
|
|
129
|
+
|
|
130
|
+
await saveProjectSkill(root, { originalSlug: 'release-notes', name: 'changelog', description: 'Draft notes', body: 'Steps' });
|
|
131
|
+
await expect(stat(join(root, '.agents/skills/release-notes'))).rejects.toThrow();
|
|
132
|
+
expect(await readFile(join(root, '.agents/skills/changelog/SKILL.md'), 'utf8')).toContain('name: changelog');
|
|
133
|
+
|
|
134
|
+
await deleteProjectSkill(root, 'changelog');
|
|
135
|
+
await expect(stat(join(root, '.agents/skills/changelog'))).rejects.toThrow();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('saving a subagent keeps frontmatter keys it does not edit', async () => {
|
|
139
|
+
await put('.agents/agents/reviewer.md', '---\nname: reviewer\ndescription: old\ncolor: blue\n---\n\nBody\n');
|
|
140
|
+
await saveProjectSubagent(root, { originalSlug: 'reviewer', name: 'reviewer', description: 'new', tools: 'Read,Grep', body: 'New body' });
|
|
141
|
+
const doc = await readFile(join(root, '.agents/agents/reviewer.md'), 'utf8');
|
|
142
|
+
expect(doc).toContain('color: blue');
|
|
143
|
+
expect(doc).toContain('tools: Read, Grep');
|
|
144
|
+
expect(doc).toContain('New body');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('copyToAgents copies (never moves) and refuses to overwrite', async () => {
|
|
148
|
+
await put('.claude/skills/lint/SKILL.md', skillDoc('lint', 'Run lint'));
|
|
149
|
+
await copyToAgents(root, 'skill', '.claude/skills/lint');
|
|
150
|
+
expect(await readFile(join(root, '.agents/skills/lint/SKILL.md'), 'utf8')).toContain('Run lint');
|
|
151
|
+
expect(await readFile(join(root, '.claude/skills/lint/SKILL.md'), 'utf8')).toContain('Run lint');
|
|
152
|
+
await expect(copyToAgents(root, 'skill', '.claude/skills/lint')).rejects.toThrow();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('AGENTS.md is read and written verbatim', async () => {
|
|
156
|
+
await put('AGENTS.md', '# Team rules\n\nBe kind.\n');
|
|
157
|
+
expect((await readAgentsMd(root)).content).toBe('# Team rules\n\nBe kind.\n');
|
|
158
|
+
await saveAgentsMd(root, '# Team rules\n\nRun bun test first.');
|
|
159
|
+
expect(await readFile(join(root, 'AGENTS.md'), 'utf8')).toBe('# Team rules\n\nRun bun test first.');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('empty content never creates AGENTS.md', async () => {
|
|
163
|
+
await saveAgentsMd(root, ' ');
|
|
164
|
+
await expect(stat(join(root, 'AGENTS.md'))).rejects.toThrow();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('invalid .agents/mcp.json is rejected before anything is written', async () => {
|
|
168
|
+
await expect(saveProjectMcp(root, '{"mcpServers":{"x":{}}}')).rejects.toThrow();
|
|
169
|
+
await expect(stat(join(root, '.agents/mcp.json'))).rejects.toThrow();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('reads stay inside the repository and only serve artifact documents', async () => {
|
|
173
|
+
await put('.agents/skills/a/SKILL.md', skillDoc('a', 'A'));
|
|
174
|
+
await put('secrets.env', 'TOKEN=1');
|
|
175
|
+
expect(await readProjectFile(root, '.agents/skills/a')).toContain('name: a');
|
|
176
|
+
await expect(readProjectFile(root, '../etc/passwd')).rejects.toThrow();
|
|
177
|
+
await expect(readProjectFile(root, 'secrets.env')).rejects.toThrow();
|
|
178
|
+
await symlink(join(root, 'secrets.env'), join(root, 'link.env'));
|
|
179
|
+
await expect(readProjectFile(root, 'link.env')).rejects.toThrow();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project scanner — reads what a repository actually carries in every location
|
|
3
|
+
* of {@link PROJECT_SOURCES} and works out, per engine, whether each artifact
|
|
4
|
+
* reaches that engine natively, through Clopen's bridge, or not at all.
|
|
5
|
+
*
|
|
6
|
+
* The coverage rules live here and nowhere else: the Settings badges and the
|
|
7
|
+
* per-stream bridge both call {@link scanProject}, so what the UI claims is the
|
|
8
|
+
* same computation that decides what gets delivered.
|
|
9
|
+
*
|
|
10
|
+
* Read-only. Never throws for a missing or malformed file — an unreadable entry
|
|
11
|
+
* is skipped, a broken frontmatter falls back to the file name.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { join, relative, sep } from 'path';
|
|
15
|
+
import { readdir, readFile, stat, lstat, readlink, realpath } from 'node:fs/promises';
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { parseSkillMd } from '$backend/skills/spec';
|
|
18
|
+
import { ARTIFACT_ENGINES, type ArtifactEngine } from '../types';
|
|
19
|
+
import { canDelegateSubagents } from '../matrix';
|
|
20
|
+
import { parseDoc } from '../frontmatter';
|
|
21
|
+
import { PROJECT_SOURCES, sourcesOf, type ProjectSource } from './sources';
|
|
22
|
+
|
|
23
|
+
export type EngineCoverage = 'native' | 'bridged' | 'none';
|
|
24
|
+
export type CoverageMap = Record<ArtifactEngine, EngineCoverage>;
|
|
25
|
+
|
|
26
|
+
/** A skill or subagent found in the repository. */
|
|
27
|
+
export interface ProjectItem {
|
|
28
|
+
kind: 'skill' | 'subagent';
|
|
29
|
+
slug: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
sourceId: string;
|
|
33
|
+
/** Source directory, relative to the repo root. */
|
|
34
|
+
sourcePath: string;
|
|
35
|
+
/** The item itself (skill folder or `.md` file), relative to the repo root. */
|
|
36
|
+
path: string;
|
|
37
|
+
/** Absolute path of the entry file (`SKILL.md` or the subagent `.md`). */
|
|
38
|
+
entryFile: string;
|
|
39
|
+
editable: boolean;
|
|
40
|
+
/** Set when a higher-priority source already carries the same slug. */
|
|
41
|
+
shadowedBy: string | null;
|
|
42
|
+
coverage: CoverageMap;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ProjectInstructionFile {
|
|
46
|
+
sourceId: string;
|
|
47
|
+
path: string;
|
|
48
|
+
/** `md-dir` sources report how many rule files they hold. */
|
|
49
|
+
fileCount: number | null;
|
|
50
|
+
size: number;
|
|
51
|
+
editable: boolean;
|
|
52
|
+
/** Human note on a coverage special case (e.g. CLAUDE.md importing AGENTS.md). */
|
|
53
|
+
note: string | null;
|
|
54
|
+
coverage: CoverageMap;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ProjectMcpServer {
|
|
58
|
+
name: string;
|
|
59
|
+
transport: 'stdio' | 'http' | 'sse';
|
|
60
|
+
command: string | null;
|
|
61
|
+
args: string[];
|
|
62
|
+
env: Record<string, string>;
|
|
63
|
+
url: string | null;
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ProjectMcpFile {
|
|
68
|
+
sourceId: string;
|
|
69
|
+
path: string;
|
|
70
|
+
editable: boolean;
|
|
71
|
+
servers: ProjectMcpServer[];
|
|
72
|
+
/** Parse error, shown raw. */
|
|
73
|
+
error: string | null;
|
|
74
|
+
/** sha256 of the file bytes — the identity the trust gate approves. */
|
|
75
|
+
hash: string;
|
|
76
|
+
coverage: CoverageMap;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ProjectPermissionsFile {
|
|
80
|
+
path: string;
|
|
81
|
+
allow: string[];
|
|
82
|
+
deny: string[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ProjectScan {
|
|
86
|
+
root: string;
|
|
87
|
+
skills: ProjectItem[];
|
|
88
|
+
subagents: ProjectItem[];
|
|
89
|
+
instructions: ProjectInstructionFile[];
|
|
90
|
+
mcp: ProjectMcpFile[];
|
|
91
|
+
/** `.claude/settings*.json` permission rules Claude applies on its own. */
|
|
92
|
+
claudePermissions: ProjectPermissionsFile[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Largest file the scanner will read. Artifacts are prose; anything bigger is not one. */
|
|
96
|
+
const MAX_READ_BYTES = 512 * 1024;
|
|
97
|
+
|
|
98
|
+
async function isDir(path: string): Promise<boolean> {
|
|
99
|
+
try { return (await stat(path)).isDirectory(); } catch { return false; }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function fileSize(path: string): Promise<number | null> {
|
|
103
|
+
try {
|
|
104
|
+
const info = await stat(path);
|
|
105
|
+
return info.isFile() ? info.size : null;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function readSmallFile(path: string): Promise<string | null> {
|
|
112
|
+
const size = await fileSize(path);
|
|
113
|
+
if (size == null || size > MAX_READ_BYTES) return null;
|
|
114
|
+
try { return await readFile(path, 'utf8'); } catch { return null; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function hashContent(content: string): string {
|
|
118
|
+
return createHash('sha256').update(content).digest('hex');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function rel(root: string, path: string): string {
|
|
122
|
+
return relative(root, path).split(sep).join('/');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function emptyCoverage(): CoverageMap {
|
|
126
|
+
return Object.fromEntries(ARTIFACT_ENGINES.map(e => [e, 'none'])) as CoverageMap;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Name + description of a skill folder, tolerant of frontmatter the strict parser rejects. */
|
|
130
|
+
async function readSkillMeta(skillMd: string, slug: string): Promise<{ name: string; description: string } | null> {
|
|
131
|
+
const raw = await readSmallFile(skillMd);
|
|
132
|
+
if (raw == null) return null;
|
|
133
|
+
try {
|
|
134
|
+
const { frontmatter } = parseSkillMd(raw);
|
|
135
|
+
return { name: frontmatter.name || slug, description: frontmatter.description || '' };
|
|
136
|
+
} catch {
|
|
137
|
+
const { frontmatter } = parseDoc(raw);
|
|
138
|
+
return { name: frontmatter.name || slug, description: frontmatter.description || '' };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Strip the extensions a subagent file may carry (`.agent.md` is Copilot's). */
|
|
143
|
+
export function subagentSlugFromFile(fileName: string): string | null {
|
|
144
|
+
if (!fileName.endsWith('.md')) return null;
|
|
145
|
+
return fileName.replace(/\.agent\.md$/, '').replace(/\.md$/, '');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function scanSource(root: string, source: ProjectSource): Promise<Omit<ProjectItem, 'shadowedBy' | 'coverage'>[]> {
|
|
149
|
+
const dir = join(root, source.path);
|
|
150
|
+
if (!(await isDir(dir))) return [];
|
|
151
|
+
let entries;
|
|
152
|
+
try { entries = await readdir(dir, { withFileTypes: true }); } catch { return []; }
|
|
153
|
+
const out: Omit<ProjectItem, 'shadowedBy' | 'coverage'>[] = [];
|
|
154
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
155
|
+
if (entry.name.startsWith('.')) continue;
|
|
156
|
+
const itemPath = join(dir, entry.name);
|
|
157
|
+
if (source.layout === 'skill-dirs') {
|
|
158
|
+
// Symlinked skill folders are common (one copy shared between tools).
|
|
159
|
+
if (!entry.isDirectory() && !(entry.isSymbolicLink() && (await isDir(itemPath)))) continue;
|
|
160
|
+
const entryFile = join(itemPath, 'SKILL.md');
|
|
161
|
+
const meta = await readSkillMeta(entryFile, entry.name);
|
|
162
|
+
if (!meta) continue;
|
|
163
|
+
out.push({
|
|
164
|
+
kind: 'skill', slug: entry.name, ...meta,
|
|
165
|
+
sourceId: source.id, sourcePath: source.path, path: rel(root, itemPath), entryFile,
|
|
166
|
+
editable: !!source.editable
|
|
167
|
+
});
|
|
168
|
+
} else if (source.layout === 'md-files') {
|
|
169
|
+
const slug = subagentSlugFromFile(entry.name);
|
|
170
|
+
if (!slug || entry.isDirectory()) continue;
|
|
171
|
+
const raw = await readSmallFile(itemPath);
|
|
172
|
+
if (raw == null) continue;
|
|
173
|
+
const { frontmatter } = parseDoc(raw);
|
|
174
|
+
out.push({
|
|
175
|
+
kind: 'subagent', slug, name: frontmatter.name || slug, description: frontmatter.description || '',
|
|
176
|
+
sourceId: source.id, sourcePath: source.path, path: rel(root, itemPath), entryFile: itemPath,
|
|
177
|
+
editable: !!source.editable
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Whether `engine` can receive a bridged artifact of this kind at all. */
|
|
185
|
+
function canBridge(kind: 'skill' | 'subagent', engine: ArtifactEngine): boolean {
|
|
186
|
+
// Every engine can be told about a skill (natively, by plugin, or in its
|
|
187
|
+
// prompt). Subagents need a real delegation surface; engines without one are
|
|
188
|
+
// never told a subagent exists — same rule as the global Subagents feature.
|
|
189
|
+
return kind === 'skill' || canDelegateSubagents(engine);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Resolve coverage for every item of one kind. An engine sees a slug natively
|
|
194
|
+
* when ANY source it reads carries that slug; otherwise the highest-priority
|
|
195
|
+
* copy (source order in {@link PROJECT_SOURCES}) is the one Clopen bridges.
|
|
196
|
+
*/
|
|
197
|
+
function resolveItems(kind: 'skill' | 'subagent', raw: Omit<ProjectItem, 'shadowedBy' | 'coverage'>[]): ProjectItem[] {
|
|
198
|
+
const sources = sourcesOf(kind);
|
|
199
|
+
const nativeBySource = new Map(sources.map(s => [s.id, s.native]));
|
|
200
|
+
const winner = new Map<string, string>();
|
|
201
|
+
for (const item of raw) if (!winner.has(item.slug)) winner.set(item.slug, item.sourceId);
|
|
202
|
+
|
|
203
|
+
return raw.map(item => {
|
|
204
|
+
const coverage = emptyCoverage();
|
|
205
|
+
for (const engine of ARTIFACT_ENGINES) {
|
|
206
|
+
if (nativeBySource.get(item.sourceId)?.includes(engine)) {
|
|
207
|
+
coverage[engine] = 'native';
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const seenNatively = raw.some(o => o.slug === item.slug && nativeBySource.get(o.sourceId)?.includes(engine));
|
|
211
|
+
if (seenNatively) continue; // another copy reaches it natively; this one is redundant there
|
|
212
|
+
if (winner.get(item.slug) === item.sourceId && canBridge(kind, engine)) coverage[engine] = 'bridged';
|
|
213
|
+
}
|
|
214
|
+
const top = winner.get(item.slug);
|
|
215
|
+
return { ...item, shadowedBy: top && top !== item.sourceId ? top : null, coverage };
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** True when `CLAUDE.md` pulls `AGENTS.md` in (symlink or an `@AGENTS.md` import line). */
|
|
220
|
+
async function claudeMdIncludesAgentsMd(root: string): Promise<boolean> {
|
|
221
|
+
const claudeMd = join(root, 'CLAUDE.md');
|
|
222
|
+
try {
|
|
223
|
+
if ((await lstat(claudeMd)).isSymbolicLink()) {
|
|
224
|
+
const target = await readlink(claudeMd);
|
|
225
|
+
if (target.replace(/^\.\//, '') === 'AGENTS.md') return true;
|
|
226
|
+
if ((await realpath(claudeMd)) === (await realpath(join(root, 'AGENTS.md')))) return true;
|
|
227
|
+
}
|
|
228
|
+
} catch { /* missing */ }
|
|
229
|
+
const raw = await readSmallFile(claudeMd);
|
|
230
|
+
return raw != null && /^\s*@\.?\/?AGENTS\.md\s*$/m.test(raw);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function scanInstructions(root: string): Promise<ProjectInstructionFile[]> {
|
|
234
|
+
const out: ProjectInstructionFile[] = [];
|
|
235
|
+
const agentsMdExists = (await fileSize(join(root, 'AGENTS.md'))) != null;
|
|
236
|
+
const claudeImports = agentsMdExists && (await claudeMdIncludesAgentsMd(root));
|
|
237
|
+
|
|
238
|
+
for (const source of sourcesOf('instruction')) {
|
|
239
|
+
const abs = join(root, source.path);
|
|
240
|
+
let size: number | null = null;
|
|
241
|
+
let fileCount: number | null = null;
|
|
242
|
+
if (source.layout === 'md-dir' || (source.id === 'clinerules' && (await isDir(abs)))) {
|
|
243
|
+
if (!(await isDir(abs))) continue;
|
|
244
|
+
try {
|
|
245
|
+
const files = (await readdir(abs, { withFileTypes: true })).filter(e => e.isFile() && /\.(md|mdc|txt)$/.test(e.name));
|
|
246
|
+
fileCount = files.length;
|
|
247
|
+
size = 0;
|
|
248
|
+
} catch { continue; }
|
|
249
|
+
} else {
|
|
250
|
+
size = await fileSize(abs);
|
|
251
|
+
if (size == null) continue;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const coverage = emptyCoverage();
|
|
255
|
+
for (const engine of source.native) coverage[engine] = 'native';
|
|
256
|
+
let note: string | null = null;
|
|
257
|
+
if (source.id === 'agents-md') {
|
|
258
|
+
// Engines that don't read AGENTS.md get it from Clopen: Claude (unless
|
|
259
|
+
// CLAUDE.md already imports it), and Cline/Cursor which read no repo file.
|
|
260
|
+
if (claudeImports) {
|
|
261
|
+
coverage.claude = 'native';
|
|
262
|
+
note = 'Claude reads it through CLAUDE.md';
|
|
263
|
+
}
|
|
264
|
+
for (const engine of ARTIFACT_ENGINES) if (coverage[engine] === 'none') coverage[engine] = 'bridged';
|
|
265
|
+
}
|
|
266
|
+
if (source.id === 'claude-md' && !agentsMdExists) {
|
|
267
|
+
// Pi loads AGENTS.md, and falls back to CLAUDE.md when there is none.
|
|
268
|
+
coverage.pi = 'native';
|
|
269
|
+
}
|
|
270
|
+
out.push({ sourceId: source.id, path: source.path, fileCount, size: size ?? 0, editable: !!source.editable, note, coverage });
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function asStringRecord(value: unknown): Record<string, string> {
|
|
276
|
+
if (!value || typeof value !== 'object') return {};
|
|
277
|
+
const out: Record<string, string> = {};
|
|
278
|
+
for (const [k, v] of Object.entries(value as Record<string, unknown>)) if (typeof v === 'string') out[k] = v;
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Parse an `.mcp.json`-shaped document: `{ "mcpServers": { name: config } }`.
|
|
284
|
+
* Accepts the bare map too. Throws a readable error for anything else.
|
|
285
|
+
*/
|
|
286
|
+
export function parseProjectMcpJson(raw: string): ProjectMcpServer[] {
|
|
287
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
288
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('Expected a JSON object with an "mcpServers" map');
|
|
289
|
+
const map = ((parsed as Record<string, unknown>).mcpServers ?? parsed) as Record<string, unknown>;
|
|
290
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) throw new Error('"mcpServers" must be an object');
|
|
291
|
+
const servers: ProjectMcpServer[] = [];
|
|
292
|
+
for (const [name, value] of Object.entries(map)) {
|
|
293
|
+
if (!value || typeof value !== 'object') throw new Error(`Server "${name}" must be an object`);
|
|
294
|
+
const cfg = value as Record<string, unknown>;
|
|
295
|
+
const url = typeof cfg.url === 'string' ? cfg.url : null;
|
|
296
|
+
const command = typeof cfg.command === 'string' ? cfg.command : null;
|
|
297
|
+
const declared = typeof cfg.type === 'string' ? cfg.type : null;
|
|
298
|
+
const transport = declared === 'sse' ? 'sse' : declared === 'http' || declared === 'streamable-http' ? 'http' : url ? 'http' : 'stdio';
|
|
299
|
+
if (transport === 'stdio' && !command) throw new Error(`Server "${name}" needs a "command" (stdio) or a "url" (http/sse)`);
|
|
300
|
+
if (transport !== 'stdio' && !url) throw new Error(`Server "${name}" is ${transport} but has no "url"`);
|
|
301
|
+
servers.push({
|
|
302
|
+
name,
|
|
303
|
+
transport,
|
|
304
|
+
command: transport === 'stdio' ? command : null,
|
|
305
|
+
args: Array.isArray(cfg.args) ? cfg.args.filter((a): a is string => typeof a === 'string') : [],
|
|
306
|
+
env: asStringRecord(cfg.env),
|
|
307
|
+
url: transport === 'stdio' ? null : url,
|
|
308
|
+
headers: asStringRecord(cfg.headers)
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return servers;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function scanMcp(root: string, isTrusted: (hash: string) => boolean): Promise<ProjectMcpFile[]> {
|
|
315
|
+
const out: ProjectMcpFile[] = [];
|
|
316
|
+
for (const source of sourcesOf('mcp')) {
|
|
317
|
+
const raw = await readSmallFile(join(root, source.path));
|
|
318
|
+
if (raw == null) continue;
|
|
319
|
+
let servers: ProjectMcpServer[] = [];
|
|
320
|
+
let error: string | null = null;
|
|
321
|
+
try { servers = parseProjectMcpJson(raw); } catch (e) { error = e instanceof Error ? e.message : String(e); }
|
|
322
|
+
const hash = hashContent(raw);
|
|
323
|
+
const coverage = emptyCoverage();
|
|
324
|
+
for (const engine of source.native) coverage[engine] = 'native';
|
|
325
|
+
if (source.editable && !error && servers.length > 0 && isTrusted(hash)) {
|
|
326
|
+
for (const engine of ARTIFACT_ENGINES) if (coverage[engine] === 'none') coverage[engine] = 'bridged';
|
|
327
|
+
}
|
|
328
|
+
out.push({ sourceId: source.id, path: source.path, editable: !!source.editable, servers, error, hash, coverage });
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function scanClaudePermissions(root: string): Promise<ProjectPermissionsFile[]> {
|
|
334
|
+
const out: ProjectPermissionsFile[] = [];
|
|
335
|
+
for (const path of ['.claude/settings.json', '.claude/settings.local.json']) {
|
|
336
|
+
const raw = await readSmallFile(join(root, path));
|
|
337
|
+
if (raw == null) continue;
|
|
338
|
+
try {
|
|
339
|
+
const perms = (JSON.parse(raw) as { permissions?: { allow?: unknown; deny?: unknown } }).permissions;
|
|
340
|
+
const list = (v: unknown) => (Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : []);
|
|
341
|
+
const allow = list(perms?.allow);
|
|
342
|
+
const deny = list(perms?.deny);
|
|
343
|
+
if (allow.length || deny.length) out.push({ path, allow, deny });
|
|
344
|
+
} catch { /* not JSON — Claude would reject it too */ }
|
|
345
|
+
}
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Scan one repository root. `isMcpTrusted` answers whether a given
|
|
351
|
+
* `.agents/mcp.json` hash has been approved for the project (the scan itself has
|
|
352
|
+
* no database access, so it stays usable from tests and the bridge alike).
|
|
353
|
+
*/
|
|
354
|
+
export async function scanProject(root: string, isMcpTrusted: (hash: string) => boolean = () => false): Promise<ProjectScan> {
|
|
355
|
+
const collect = async (kind: 'skill' | 'subagent') => {
|
|
356
|
+
const raw: Omit<ProjectItem, 'shadowedBy' | 'coverage'>[] = [];
|
|
357
|
+
for (const source of PROJECT_SOURCES.filter(s => s.kind === kind)) raw.push(...(await scanSource(root, source)));
|
|
358
|
+
return resolveItems(kind, raw);
|
|
359
|
+
};
|
|
360
|
+
const [skills, subagents, instructions, mcp, claudePermissions] = await Promise.all([
|
|
361
|
+
collect('skill'),
|
|
362
|
+
collect('subagent'),
|
|
363
|
+
scanInstructions(root),
|
|
364
|
+
scanMcp(root, isMcpTrusted),
|
|
365
|
+
scanClaudePermissions(root)
|
|
366
|
+
]);
|
|
367
|
+
return { root, skills, subagents, instructions, mcp, claudePermissions };
|
|
368
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project artifact sources — the single table of WHERE a repository keeps its
|
|
3
|
+
* engine artifacts and WHICH engines read each location on their own.
|
|
4
|
+
*
|
|
5
|
+
* Settings shows a project's artifacts from this table, and the per-stream
|
|
6
|
+
* bridge (`./bridge.ts`) uses the same `native` lists to decide what Clopen has
|
|
7
|
+
* to deliver itself: an engine gets an artifact bridged only when none of the
|
|
8
|
+
* locations it reads natively already carries it. One table for both keeps the
|
|
9
|
+
* UI badge and the runtime behaviour from disagreeing.
|
|
10
|
+
*
|
|
11
|
+
* `native` describes the engine AS CLOPEN RUNS IT, not the engine's CLI in the
|
|
12
|
+
* abstract. Cursor is the clearest case: its SDK scans `.agents/skills`,
|
|
13
|
+
* `.cursor/rules` and friends only when `settingSources` enables the project
|
|
14
|
+
* source, and Clopen leaves that unset — so Cursor reads nothing here and every
|
|
15
|
+
* project artifact reaches it through Clopen. Cline is in the same position
|
|
16
|
+
* because Clopen drives its stateless `Agent`, not the rule-loading core.
|
|
17
|
+
*
|
|
18
|
+
* Verified against the installed engines (2026-09): Claude Code 0.3.284 reads
|
|
19
|
+
* `.claude/*`, `CLAUDE.md` and `.mcp.json` but NOT `.agents/skills` (the string
|
|
20
|
+
* only appears in its config importer); Codex 0.147, OpenCode 1.18, Copilot and
|
|
21
|
+
* Pi read `.agents/skills`; Copilot also reads `.github/skills`/`.claude/skills`.
|
|
22
|
+
* Re-check these lists when an engine is upgraded.
|
|
23
|
+
*
|
|
24
|
+
* `.agents/` is where Clopen WRITES (`editable`). Everything else is read and
|
|
25
|
+
* shown, never modified.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ArtifactEngine } from '../types';
|
|
29
|
+
|
|
30
|
+
export type ProjectArtifactKind = 'skill' | 'subagent' | 'instruction' | 'mcp';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* How a source is laid out on disk.
|
|
34
|
+
* - `skill-dirs`: one folder per skill, each with a `SKILL.md`.
|
|
35
|
+
* - `md-files` : one Markdown file per artifact.
|
|
36
|
+
* - `file` : a single file (instructions, MCP config).
|
|
37
|
+
* - `md-dir` : a directory of rule files read as one instruction source.
|
|
38
|
+
*/
|
|
39
|
+
export type ProjectSourceLayout = 'skill-dirs' | 'md-files' | 'file' | 'md-dir';
|
|
40
|
+
|
|
41
|
+
export interface ProjectSource {
|
|
42
|
+
id: string;
|
|
43
|
+
kind: ProjectArtifactKind;
|
|
44
|
+
/** Path relative to the repository root, `/`-separated. */
|
|
45
|
+
path: string;
|
|
46
|
+
layout: ProjectSourceLayout;
|
|
47
|
+
/** Engines that read this location without Clopen's help. */
|
|
48
|
+
native: readonly ArtifactEngine[];
|
|
49
|
+
/** True for the locations Clopen writes to (`.agents/…`, the managed block of `AGENTS.md`). */
|
|
50
|
+
editable?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const PROJECT_SOURCES: readonly ProjectSource[] = [
|
|
54
|
+
// ── Skills ── `.agents/skills` first: it wins a slug collision everywhere.
|
|
55
|
+
{ id: 'agents-skills', kind: 'skill', path: '.agents/skills', layout: 'skill-dirs', native: ['codex', 'opencode', 'copilot', 'pi'], editable: true },
|
|
56
|
+
{ id: 'claude-skills', kind: 'skill', path: '.claude/skills', layout: 'skill-dirs', native: ['claude', 'opencode', 'copilot'] },
|
|
57
|
+
{ id: 'opencode-skills', kind: 'skill', path: '.opencode/skills', layout: 'skill-dirs', native: ['opencode'] },
|
|
58
|
+
{ id: 'opencode-skill', kind: 'skill', path: '.opencode/skill', layout: 'skill-dirs', native: ['opencode'] },
|
|
59
|
+
{ id: 'github-skills', kind: 'skill', path: '.github/skills', layout: 'skill-dirs', native: ['copilot'] },
|
|
60
|
+
{ id: 'pi-skills', kind: 'skill', path: '.pi/skills', layout: 'skill-dirs', native: ['pi'] },
|
|
61
|
+
{ id: 'qwen-skills', kind: 'skill', path: '.qwen/skills', layout: 'skill-dirs', native: ['qwen'] },
|
|
62
|
+
{ id: 'cursor-skills', kind: 'skill', path: '.cursor/skills', layout: 'skill-dirs', native: [] },
|
|
63
|
+
|
|
64
|
+
// ── Subagents ── `.agents/agents` is Clopen's convention; no engine reads it natively.
|
|
65
|
+
{ id: 'agents-agents', kind: 'subagent', path: '.agents/agents', layout: 'md-files', native: [], editable: true },
|
|
66
|
+
{ id: 'claude-agents', kind: 'subagent', path: '.claude/agents', layout: 'md-files', native: ['claude'] },
|
|
67
|
+
{ id: 'opencode-agents', kind: 'subagent', path: '.opencode/agents', layout: 'md-files', native: ['opencode'] },
|
|
68
|
+
{ id: 'opencode-agent', kind: 'subagent', path: '.opencode/agent', layout: 'md-files', native: ['opencode'] },
|
|
69
|
+
{ id: 'github-agents', kind: 'subagent', path: '.github/agents', layout: 'md-files', native: ['copilot'] },
|
|
70
|
+
{ id: 'qwen-agents', kind: 'subagent', path: '.qwen/agents', layout: 'md-files', native: ['qwen'] },
|
|
71
|
+
|
|
72
|
+
// ── Instructions ── `AGENTS.md` is the cross-engine file; Clopen edits only its managed block.
|
|
73
|
+
{ id: 'agents-md', kind: 'instruction', path: 'AGENTS.md', layout: 'file', native: ['codex', 'opencode', 'copilot', 'qwen', 'pi'], editable: true },
|
|
74
|
+
{ id: 'claude-md', kind: 'instruction', path: 'CLAUDE.md', layout: 'file', native: ['claude'] },
|
|
75
|
+
{ id: 'qwen-md', kind: 'instruction', path: 'QWEN.md', layout: 'file', native: ['qwen'] },
|
|
76
|
+
{ id: 'gemini-md', kind: 'instruction', path: 'GEMINI.md', layout: 'file', native: [] },
|
|
77
|
+
{ id: 'copilot-instructions', kind: 'instruction', path: '.github/copilot-instructions.md', layout: 'file', native: ['copilot'] },
|
|
78
|
+
{ id: 'cursor-rules', kind: 'instruction', path: '.cursor/rules', layout: 'md-dir', native: [] },
|
|
79
|
+
{ id: 'clinerules', kind: 'instruction', path: '.clinerules', layout: 'file', native: [] },
|
|
80
|
+
|
|
81
|
+
// ── MCP ── `.agents/mcp.json` is Clopen's convention, delivered after an admin trusts it.
|
|
82
|
+
{ id: 'agents-mcp', kind: 'mcp', path: '.agents/mcp.json', layout: 'file', native: [], editable: true },
|
|
83
|
+
{ id: 'root-mcp', kind: 'mcp', path: '.mcp.json', layout: 'file', native: ['claude'] }
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
/** Where Clopen writes each editable kind. */
|
|
87
|
+
export const PROJECT_WRITE_PATHS = {
|
|
88
|
+
skills: '.agents/skills',
|
|
89
|
+
subagents: '.agents/agents',
|
|
90
|
+
instructions: 'AGENTS.md',
|
|
91
|
+
mcp: '.agents/mcp.json'
|
|
92
|
+
} as const;
|
|
93
|
+
|
|
94
|
+
export function sourcesOf(kind: ProjectArtifactKind): ProjectSource[] {
|
|
95
|
+
return PROJECT_SOURCES.filter(s => s.kind === kind);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function sourceById(id: string): ProjectSource | undefined {
|
|
99
|
+
return PROJECT_SOURCES.find(s => s.id === id);
|
|
100
|
+
}
|
|
@@ -77,7 +77,7 @@ async function folderInSync(sourceDir: string, destDir: string): Promise<boolean
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/** Mirror one canonical folder into a destination dir under `<slug>/`, skipping the copy when it is already current. */
|
|
80
|
-
async function mirrorFolder(sourceDir: string, destDir: string, slug: string): Promise<void> {
|
|
80
|
+
export async function mirrorFolder(sourceDir: string, destDir: string, slug: string): Promise<void> {
|
|
81
81
|
if (!(await pathExists(sourceDir))) return;
|
|
82
82
|
const dest = join(destDir, slug);
|
|
83
83
|
if (await folderInSync(sourceDir, dest)) return;
|