@sylphx/flow 2.1.4 → 2.1.5
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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/commands/settings/checkbox-config.ts +128 -0
- package/src/commands/settings/index.ts +6 -0
- package/src/commands/settings-command.ts +63 -138
- package/src/core/attach/file-attacher.ts +172 -0
- package/src/core/attach/index.ts +5 -0
- package/src/core/attach-manager.ts +32 -94
- package/src/services/global-config.ts +1 -1
- package/src/services/target-installer.ts +2 -19
- package/src/targets/claude-code.ts +12 -70
- package/src/targets/opencode.ts +11 -62
- package/src/targets/shared/index.ts +7 -0
- package/src/targets/shared/mcp-transforms.ts +132 -0
- package/src/targets/shared/target-operations.ts +135 -0
- package/src/utils/target-selection.ts +1 -6
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure functions for common target operations
|
|
3
|
+
* Shared logic between claude-code and opencode targets
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import type { CommonOptions, SetupResult, TargetConfig } from '../../types.js';
|
|
9
|
+
import { installToDirectory } from '../../core/installers/file-installer.js';
|
|
10
|
+
import { getAgentsDir, getSlashCommandsDir } from '../../utils/config/paths.js';
|
|
11
|
+
import { yamlUtils } from '../../utils/config/target-utils.js';
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Types
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
export type ContentTransformer = (content: string, sourcePath?: string) => Promise<string>;
|
|
18
|
+
|
|
19
|
+
export interface SetupOptions extends CommonOptions {
|
|
20
|
+
showProgress?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Pure Functions - Environment Detection
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Check if target config file exists in directory
|
|
29
|
+
*/
|
|
30
|
+
export const detectTargetConfig = (cwd: string, configFile: string): boolean => {
|
|
31
|
+
try {
|
|
32
|
+
return fs.existsSync(path.join(cwd, configFile));
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Pure Functions - Content Transformation
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Strip YAML front matter from content
|
|
44
|
+
* Used for rules transformation in both targets
|
|
45
|
+
*/
|
|
46
|
+
export const stripFrontMatter = (content: string): Promise<string> =>
|
|
47
|
+
Promise.resolve(yamlUtils.stripFrontMatter(content));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Identity transformer - returns content unchanged
|
|
51
|
+
*/
|
|
52
|
+
export const identityTransform: ContentTransformer = (content: string) =>
|
|
53
|
+
Promise.resolve(content);
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Pure Functions - Setup Operations
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Setup agents to target directory
|
|
61
|
+
* Generic function used by both targets
|
|
62
|
+
*/
|
|
63
|
+
export const setupAgentsTo = async (
|
|
64
|
+
targetDir: string,
|
|
65
|
+
transformer: ContentTransformer,
|
|
66
|
+
options: SetupOptions = {}
|
|
67
|
+
): Promise<SetupResult> => {
|
|
68
|
+
const results = await installToDirectory(
|
|
69
|
+
getAgentsDir(),
|
|
70
|
+
targetDir,
|
|
71
|
+
transformer,
|
|
72
|
+
{ ...options, showProgress: false }
|
|
73
|
+
);
|
|
74
|
+
return { count: results.length };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Setup slash commands to target directory
|
|
79
|
+
* Generic function used by both targets
|
|
80
|
+
*/
|
|
81
|
+
export const setupSlashCommandsTo = async (
|
|
82
|
+
targetDir: string,
|
|
83
|
+
transformer: ContentTransformer = identityTransform,
|
|
84
|
+
options: SetupOptions = {}
|
|
85
|
+
): Promise<SetupResult> => {
|
|
86
|
+
const results = await installToDirectory(
|
|
87
|
+
getSlashCommandsDir(),
|
|
88
|
+
targetDir,
|
|
89
|
+
transformer,
|
|
90
|
+
{ ...options, showProgress: false }
|
|
91
|
+
);
|
|
92
|
+
return { count: results.length };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// Pure Functions - Config Operations
|
|
97
|
+
// ============================================================================
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Ensure config has required structure
|
|
101
|
+
* Returns new object, doesn't mutate input
|
|
102
|
+
*/
|
|
103
|
+
export const ensureConfigStructure = <T extends Record<string, unknown>>(
|
|
104
|
+
config: T,
|
|
105
|
+
key: string,
|
|
106
|
+
defaultValue: unknown = {}
|
|
107
|
+
): T => {
|
|
108
|
+
if (config[key] !== undefined) return config;
|
|
109
|
+
return { ...config, [key]: defaultValue };
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get MCP config key for target
|
|
114
|
+
*/
|
|
115
|
+
export const getMCPKey = (targetId: string): string =>
|
|
116
|
+
targetId === 'claude-code' ? 'mcpServers' : 'mcp';
|
|
117
|
+
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Pure Functions - Path Resolution
|
|
120
|
+
// ============================================================================
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolve target directory paths
|
|
124
|
+
*/
|
|
125
|
+
export const resolveTargetPaths = (cwd: string, config: TargetConfig) => ({
|
|
126
|
+
configDir: path.join(cwd, config.configDir),
|
|
127
|
+
agentDir: path.join(cwd, config.agentDir),
|
|
128
|
+
configFile: path.join(cwd, config.configFile),
|
|
129
|
+
slashCommandsDir: config.slashCommandsDir
|
|
130
|
+
? path.join(cwd, config.slashCommandsDir)
|
|
131
|
+
: undefined,
|
|
132
|
+
rulesFile: config.rulesFile
|
|
133
|
+
? path.join(cwd, config.rulesFile)
|
|
134
|
+
: undefined,
|
|
135
|
+
});
|
|
@@ -15,7 +15,7 @@ export interface TargetChoice {
|
|
|
15
15
|
/** Display name of the target */
|
|
16
16
|
name: string;
|
|
17
17
|
/** Target identifier */
|
|
18
|
-
value: 'claude-code' | 'opencode'
|
|
18
|
+
value: 'claude-code' | 'opencode';
|
|
19
19
|
/** Whether the target is currently installed */
|
|
20
20
|
installed: boolean;
|
|
21
21
|
}
|
|
@@ -37,11 +37,6 @@ export function buildAvailableTargets(installedTargets: string[]): TargetChoice[
|
|
|
37
37
|
value: 'opencode',
|
|
38
38
|
installed: installedTargets.includes('opencode'),
|
|
39
39
|
},
|
|
40
|
-
{
|
|
41
|
-
name: 'Cursor',
|
|
42
|
-
value: 'cursor',
|
|
43
|
-
installed: installedTargets.includes('cursor'),
|
|
44
|
-
},
|
|
45
40
|
];
|
|
46
41
|
}
|
|
47
42
|
|