@4ge/cli 0.1.0
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/LICENSE +21 -0
- package/README.md +228 -0
- package/bin/dev.js +3 -0
- package/bin/run.js +3 -0
- package/dist/base.js +398 -0
- package/dist/commands/auth/login.js +197 -0
- package/dist/commands/auth/logout.js +31 -0
- package/dist/commands/auth/profile/delete.js +34 -0
- package/dist/commands/auth/profile/list.js +32 -0
- package/dist/commands/auth/profile/use.js +30 -0
- package/dist/commands/auth/status.js +107 -0
- package/dist/commands/config/get.js +37 -0
- package/dist/commands/config/index.js +9 -0
- package/dist/commands/config/manage.js +165 -0
- package/dist/commands/config/set.js +42 -0
- package/dist/commands/config/show.js +46 -0
- package/dist/commands/epic/index.js +10 -0
- package/dist/commands/epic/list.js +91 -0
- package/dist/commands/epic/pull.js +137 -0
- package/dist/commands/epic/show.js +67 -0
- package/dist/commands/epic/update.js +104 -0
- package/dist/commands/feature/index.js +2 -0
- package/dist/commands/feature/list.js +93 -0
- package/dist/commands/feature/pull.js +122 -0
- package/dist/commands/feature/show.js +60 -0
- package/dist/commands/feature/update.js +103 -0
- package/dist/commands/idea/create.js +88 -0
- package/dist/commands/idea/graduate.js +89 -0
- package/dist/commands/idea/index.js +5 -0
- package/dist/commands/idea/list.js +83 -0
- package/dist/commands/idea/show.js +86 -0
- package/dist/commands/idea/update.js +108 -0
- package/dist/commands/init.js +354 -0
- package/dist/commands/login.js +5 -0
- package/dist/commands/plan/index.js +10 -0
- package/dist/commands/plan/pull.js +104 -0
- package/dist/commands/plan/versions.js +64 -0
- package/dist/commands/project/create.js +84 -0
- package/dist/commands/project/index.js +9 -0
- package/dist/commands/project/info.js +74 -0
- package/dist/commands/project/list.js +78 -0
- package/dist/commands/project/pull.js +127 -0
- package/dist/commands/project/update.js +104 -0
- package/dist/commands/root.js +13 -0
- package/dist/commands/skill/index.js +8 -0
- package/dist/commands/skill/install.js +71 -0
- package/dist/commands/story/index.js +10 -0
- package/dist/commands/story/list.js +81 -0
- package/dist/commands/story/pull.js +125 -0
- package/dist/commands/story/show.js +57 -0
- package/dist/commands/story/update.js +103 -0
- package/dist/commands/template/create.js +72 -0
- package/dist/commands/template/delete.js +62 -0
- package/dist/commands/template/feature/create.js +70 -0
- package/dist/commands/template/feature/delete.js +75 -0
- package/dist/commands/template/feature/list.js +69 -0
- package/dist/commands/template/feature/update.js +82 -0
- package/dist/commands/template/info.js +52 -0
- package/dist/commands/template/list.js +76 -0
- package/dist/commands/template/pull.js +99 -0
- package/dist/commands/template/update.js +71 -0
- package/dist/commands/whoami.js +5 -0
- package/dist/core/api/action-hints.js +17 -0
- package/dist/core/api/index.js +3 -0
- package/dist/core/api/retry.js +95 -0
- package/dist/core/api/validate-response.js +41 -0
- package/dist/core/auth/api-client.js +156 -0
- package/dist/core/auth/config.js +3 -0
- package/dist/core/auth/credentials.js +143 -0
- package/dist/core/auth/email-auth.js +30 -0
- package/dist/core/auth/errors.js +20 -0
- package/dist/core/auth/index.js +6 -0
- package/dist/core/auth/realtime.js +82 -0
- package/dist/core/auth/resolution.js +63 -0
- package/dist/core/auth/state.js +9 -0
- package/dist/core/auth/token-refresh.js +100 -0
- package/dist/core/config/defaults.js +31 -0
- package/dist/core/config/index.js +3 -0
- package/dist/core/config/parser.js +213 -0
- package/dist/core/config/schema.js +29 -0
- package/dist/core/project/markdown.js +37 -0
- package/dist/core/skill/installer.js +59 -0
- package/dist/core/skill/paths.js +52 -0
- package/dist/generated/api/client/client.gen.js +217 -0
- package/dist/generated/api/client/index.js +6 -0
- package/dist/generated/api/client/types.gen.js +2 -0
- package/dist/generated/api/client/utils.gen.js +231 -0
- package/dist/generated/api/client.gen.js +3 -0
- package/dist/generated/api/core/auth.gen.js +14 -0
- package/dist/generated/api/core/bodySerializer.gen.js +57 -0
- package/dist/generated/api/core/params.gen.js +103 -0
- package/dist/generated/api/core/pathSerializer.gen.js +114 -0
- package/dist/generated/api/core/queryKeySerializer.gen.js +99 -0
- package/dist/generated/api/core/serverSentEvents.gen.js +136 -0
- package/dist/generated/api/core/types.gen.js +2 -0
- package/dist/generated/api/core/utils.gen.js +87 -0
- package/dist/generated/api/index.js +2 -0
- package/dist/generated/api/sdk.gen.js +556 -0
- package/dist/generated/api/types.gen.js +2 -0
- package/dist/generated/api/zod.gen.js +1262 -0
- package/dist/ui/components/action-hints.js +33 -0
- package/dist/ui/components/cli-header.js +91 -0
- package/dist/ui/components/confirm-prompt.js +28 -0
- package/dist/ui/components/data-table.js +35 -0
- package/dist/ui/components/detail-view.js +5 -0
- package/dist/ui/components/error-display.js +5 -0
- package/dist/ui/components/prompt-layout.js +6 -0
- package/dist/ui/components/select-prompt.js +28 -0
- package/dist/ui/components/spinner.js +14 -0
- package/dist/ui/components/success-message.js +5 -0
- package/dist/ui/components/text-input.js +29 -0
- package/dist/ui/hooks/use-action-hints.js +21 -0
- package/dist/ui/hooks/use-status.js +22 -0
- package/dist/ui/index.js +15 -0
- package/dist/ui/prompt-helpers.js +55 -0
- package/dist/ui/render.js +9 -0
- package/package.json +89 -0
- package/skills/4ge-cli.md +113 -0
- package/usage.md +320 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile, stat, readdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
|
+
import { ProjectConfigSchema } from './schema.js';
|
|
5
|
+
/**
|
|
6
|
+
* Path to local .4ge directory
|
|
7
|
+
*/
|
|
8
|
+
export function getLocal4geDir() {
|
|
9
|
+
return join(process.cwd(), '.4ge');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if .4ge directory exists
|
|
13
|
+
*/
|
|
14
|
+
export async function hasLocal4geDir() {
|
|
15
|
+
try {
|
|
16
|
+
const s = await stat(getLocal4geDir());
|
|
17
|
+
return s.isDirectory();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Path to local project config.
|
|
25
|
+
* Config lives at the .4ge root — root is reserved for config + secrets.
|
|
26
|
+
*/
|
|
27
|
+
export function getLocalConfigPath() {
|
|
28
|
+
return join(getLocal4geDir(), 'config.yaml');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Path to the assets subdirectory.
|
|
32
|
+
*
|
|
33
|
+
* Pulled / cached items (project.json, plan.json, template.json,
|
|
34
|
+
* stories/, epics/, features/, project/*.md) live under here, keeping the
|
|
35
|
+
* .4ge root clean for config + secrets.
|
|
36
|
+
*/
|
|
37
|
+
export function getAssetsDir() {
|
|
38
|
+
return join(getLocal4geDir(), 'assets');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve an asset path under .4ge/assets.
|
|
42
|
+
*
|
|
43
|
+
* Works for both singleton files (e.g. 'project.json') and collection
|
|
44
|
+
* directories (e.g. 'stories'). Caller joins further path segments as needed.
|
|
45
|
+
*/
|
|
46
|
+
export function getAssetPath(name) {
|
|
47
|
+
return join(getAssetsDir(), name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Path to a collection directory under .4ge/assets (e.g. 'stories', 'epics').
|
|
51
|
+
*
|
|
52
|
+
* Semantically distinct from getAssetPath() for singletons — signals that the
|
|
53
|
+
* caller will join further segments (typically per-id files) under this dir.
|
|
54
|
+
*/
|
|
55
|
+
export function getCollectionDir(name) {
|
|
56
|
+
return join(getAssetsDir(), name);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Path to the pulled project markdown docs directory (.4ge/assets/project).
|
|
60
|
+
*/
|
|
61
|
+
export function getProjectDocsDir() {
|
|
62
|
+
return join(getAssetsDir(), 'project');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Read and validate project configuration from .4ge/config.yaml.
|
|
66
|
+
* Returns null if the file is missing, empty, invalid YAML, or fails schema validation.
|
|
67
|
+
* Guaranteed not to throw.
|
|
68
|
+
*/
|
|
69
|
+
export async function readConfig() {
|
|
70
|
+
try {
|
|
71
|
+
const content = await readFile(getLocalConfigPath(), 'utf-8');
|
|
72
|
+
if (!content.trim())
|
|
73
|
+
return null;
|
|
74
|
+
const data = parse(content);
|
|
75
|
+
const result = ProjectConfigSchema.safeParse(data);
|
|
76
|
+
return result.success ? result.data : null;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function writeConfig(config) {
|
|
83
|
+
await mkdir(getLocal4geDir(), { recursive: true, mode: 0o700 });
|
|
84
|
+
const yamlContent = stringify(config, { indent: 2, aliasDuplicateObjects: false });
|
|
85
|
+
await writeFile(getLocalConfigPath(), yamlContent, 'utf-8');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Update project configuration with partial values.
|
|
89
|
+
* Deeply merges hierarchy, pull, and cli sections.
|
|
90
|
+
* @throws Error if config file is not found or validation fails.
|
|
91
|
+
*/
|
|
92
|
+
export async function updateConfig(updates) {
|
|
93
|
+
const current = await readConfig();
|
|
94
|
+
if (!current) {
|
|
95
|
+
throw new Error('No project config found. Run `4ge init` first.');
|
|
96
|
+
}
|
|
97
|
+
const merged = {
|
|
98
|
+
...current,
|
|
99
|
+
...updates,
|
|
100
|
+
hierarchy: { ...current.hierarchy, ...updates.hierarchy },
|
|
101
|
+
pull: { ...current.pull, ...updates.pull },
|
|
102
|
+
cli: { ...current.cli, ...updates.cli },
|
|
103
|
+
};
|
|
104
|
+
const validated = ProjectConfigSchema.parse(merged);
|
|
105
|
+
await writeConfig(validated);
|
|
106
|
+
return validated;
|
|
107
|
+
}
|
|
108
|
+
export async function isProjectInitialized() {
|
|
109
|
+
const config = await readConfig();
|
|
110
|
+
return Boolean(config?.project_id && config?.workspace_id);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Asset entries that previously lived at the .4ge root and must be moved
|
|
114
|
+
* under .4ge/assets/ during one-time migration.
|
|
115
|
+
*/
|
|
116
|
+
const LEGACY_ASSET_FILES = ['project.json', 'plan.json', 'template.json'];
|
|
117
|
+
const LEGACY_ASSET_DIRS = ['project', 'stories', 'epics', 'features'];
|
|
118
|
+
/**
|
|
119
|
+
* One-time, idempotent migration of legacy root-level assets into .4ge/assets/.
|
|
120
|
+
*
|
|
121
|
+
* Moves singletons (project.json, plan.json, template.json) and collection
|
|
122
|
+
* directories (project/, stories/, epics/, features/) that used to sit directly
|
|
123
|
+
* under .4ge/ into .4ge/assets/. Config and secrets at the root are never touched.
|
|
124
|
+
*
|
|
125
|
+
* If an asset already exists at the destination it is skipped (never overwritten),
|
|
126
|
+
* so re-runs are safe and never clobber newer pulls.
|
|
127
|
+
*/
|
|
128
|
+
export async function migrateLegacyAssets(opts = {}) {
|
|
129
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
130
|
+
const root = join(cwd, '.4ge');
|
|
131
|
+
const assetsDir = join(root, 'assets');
|
|
132
|
+
const moved = [];
|
|
133
|
+
const skipped = [];
|
|
134
|
+
// Bail fast if .4ge was never initialised.
|
|
135
|
+
try {
|
|
136
|
+
if (!(await stat(root)).isDirectory())
|
|
137
|
+
return { moved, skipped };
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return { moved, skipped };
|
|
141
|
+
}
|
|
142
|
+
await mkdir(assetsDir, { recursive: true });
|
|
143
|
+
for (const name of LEGACY_ASSET_FILES) {
|
|
144
|
+
const src = join(root, name);
|
|
145
|
+
const dest = join(assetsDir, name);
|
|
146
|
+
let srcStat;
|
|
147
|
+
try {
|
|
148
|
+
srcStat = await stat(src);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!srcStat.isFile())
|
|
154
|
+
continue;
|
|
155
|
+
try {
|
|
156
|
+
await stat(dest);
|
|
157
|
+
skipped.push(name);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// dest missing — proceed
|
|
162
|
+
}
|
|
163
|
+
await writeFile(dest, await readFile(src, 'utf-8'), 'utf-8');
|
|
164
|
+
await rm(src);
|
|
165
|
+
moved.push(name);
|
|
166
|
+
}
|
|
167
|
+
for (const name of LEGACY_ASSET_DIRS) {
|
|
168
|
+
const src = join(root, name);
|
|
169
|
+
const dest = join(assetsDir, name);
|
|
170
|
+
let srcStat;
|
|
171
|
+
try {
|
|
172
|
+
srcStat = await stat(src);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!srcStat.isDirectory())
|
|
178
|
+
continue;
|
|
179
|
+
// Skip entirely if destination already exists — never merge over a newer pull.
|
|
180
|
+
try {
|
|
181
|
+
await stat(dest);
|
|
182
|
+
skipped.push(`${name}/`);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// dest missing — proceed
|
|
187
|
+
}
|
|
188
|
+
await moveDir(src, dest);
|
|
189
|
+
moved.push(`${name}/`);
|
|
190
|
+
}
|
|
191
|
+
return { moved, skipped };
|
|
192
|
+
}
|
|
193
|
+
async function moveDir(src, dest) {
|
|
194
|
+
await mkdir(dest, { recursive: true });
|
|
195
|
+
for (const entry of await readdir(src, { withFileTypes: true })) {
|
|
196
|
+
const from = join(src, entry.name);
|
|
197
|
+
const to = join(dest, entry.name);
|
|
198
|
+
if (entry.isDirectory()) {
|
|
199
|
+
await moveDir(from, to);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
await writeFile(to, await readFile(from, 'utf-8'), 'utf-8');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
await rm(src, { recursive: true, force: true });
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Generate .gitignore entries for .4ge/ sensitive files.
|
|
209
|
+
* Paths are relative to the .4ge/ directory.
|
|
210
|
+
*/
|
|
211
|
+
export function getGitignoreEntries() {
|
|
212
|
+
return ['credentials.json', '.env'];
|
|
213
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Config schema for .4ge/config.yaml
|
|
3
|
+
export const ProjectConfigSchema = z.object({
|
|
4
|
+
project_id: z.string().uuid(),
|
|
5
|
+
workspace_id: z.string().uuid(),
|
|
6
|
+
project_name: z.string().optional(),
|
|
7
|
+
workspace_name: z.string().optional(),
|
|
8
|
+
hierarchy: z.object({
|
|
9
|
+
default_roadmap_filter: z.enum(['now', 'next', 'later', 'all']).default('now'),
|
|
10
|
+
recursive_pull: z.boolean().default(true),
|
|
11
|
+
}).default({
|
|
12
|
+
default_roadmap_filter: 'now',
|
|
13
|
+
recursive_pull: true,
|
|
14
|
+
}),
|
|
15
|
+
pull: z.object({
|
|
16
|
+
generate_stubs: z.boolean().default(false),
|
|
17
|
+
include_brief_deps: z.boolean().default(false),
|
|
18
|
+
}).default({
|
|
19
|
+
generate_stubs: false,
|
|
20
|
+
include_brief_deps: false,
|
|
21
|
+
}),
|
|
22
|
+
cli: z.object({
|
|
23
|
+
default_mode: z.enum(['pretty', 'interactive']).default('pretty'),
|
|
24
|
+
}).default({
|
|
25
|
+
default_mode: 'pretty',
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
// Partial config for init (some fields may not be set yet)
|
|
29
|
+
export const PartialProjectConfigSchema = ProjectConfigSchema.partial();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function generateProblemStatementMd(project) {
|
|
2
|
+
const content = project.problem_statement?.trim();
|
|
3
|
+
if (!content)
|
|
4
|
+
return null;
|
|
5
|
+
return `# ${project.name} — Problem Statement
|
|
6
|
+
|
|
7
|
+
${content}`;
|
|
8
|
+
}
|
|
9
|
+
export function generateProjectRulesMd(project) {
|
|
10
|
+
const content = project.project_rules?.trim();
|
|
11
|
+
if (!content)
|
|
12
|
+
return null;
|
|
13
|
+
return `# ${project.name} — Project Rules
|
|
14
|
+
|
|
15
|
+
${content}`;
|
|
16
|
+
}
|
|
17
|
+
export function generateReadmeMd(project, filesGenerated) {
|
|
18
|
+
const description = project.description?.trim() || 'No description';
|
|
19
|
+
const fileLinks = filesGenerated
|
|
20
|
+
.map((file) => `- [${file}](./${file})`)
|
|
21
|
+
.join('\n');
|
|
22
|
+
const date = new Date().toISOString();
|
|
23
|
+
return `# ${project.name}
|
|
24
|
+
|
|
25
|
+
> ${description}
|
|
26
|
+
|
|
27
|
+
**Status:** ${project.status}
|
|
28
|
+
**Project ID:** ${project.id}
|
|
29
|
+
**Workspace:** ${project.workspace_id}
|
|
30
|
+
|
|
31
|
+
## Local Reference Files
|
|
32
|
+
|
|
33
|
+
${fileLinks}
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
*Generated by \`4ge project pull\` on ${date}*`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
|
|
4
|
+
import { resolveSkillPath } from './paths.js';
|
|
5
|
+
/**
|
|
6
|
+
* Location of the canonical skill content, bundled with the package.
|
|
7
|
+
*
|
|
8
|
+
* Resolves relative to this compiled module:
|
|
9
|
+
* - prod: dist/core/skill/installer.js -> ../../skills/4ge-cli.md
|
|
10
|
+
* - dev: src/core/skill/installer.ts -> ../../skills/4ge-cli.md
|
|
11
|
+
*/
|
|
12
|
+
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const BUNDLED_SKILL_PATH = resolve(MODULE_DIR, '..', '..', '..', 'skills', '4ge-cli.md');
|
|
14
|
+
/**
|
|
15
|
+
* Read the canonical bundled skill content.
|
|
16
|
+
*/
|
|
17
|
+
export async function getSkillContent() {
|
|
18
|
+
return readFile(BUNDLED_SKILL_PATH, 'utf-8');
|
|
19
|
+
}
|
|
20
|
+
async function fileExists(path) {
|
|
21
|
+
try {
|
|
22
|
+
await access(path);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Install the 4ge CLI skill file to the resolved agent directory.
|
|
31
|
+
*
|
|
32
|
+
* Creates the target directory (recursive). Refuses to overwrite an existing
|
|
33
|
+
* skill file unless `force` is true.
|
|
34
|
+
*/
|
|
35
|
+
export async function installSkill(options) {
|
|
36
|
+
const resolved = resolveSkillPath({
|
|
37
|
+
agent: options.agent,
|
|
38
|
+
scope: options.scope,
|
|
39
|
+
cwd: options.cwd,
|
|
40
|
+
home: options.home,
|
|
41
|
+
});
|
|
42
|
+
const exists = await fileExists(resolved.path);
|
|
43
|
+
if (exists && !options.force) {
|
|
44
|
+
throw new Error(`Skill file already exists at ${resolved.path}. Re-run with --force to overwrite.`);
|
|
45
|
+
}
|
|
46
|
+
const content = await getSkillContent();
|
|
47
|
+
await mkdir(resolved.dir, { recursive: true });
|
|
48
|
+
await writeFile(resolved.path, content, 'utf-8');
|
|
49
|
+
return {
|
|
50
|
+
path: resolved.path,
|
|
51
|
+
agent: resolved.agent,
|
|
52
|
+
scope: resolved.scope,
|
|
53
|
+
overwritten: exists,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Re-exported for command-layer convenience.
|
|
58
|
+
*/
|
|
59
|
+
export { resolveSkillPath } from './paths.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
/**
|
|
5
|
+
* Agent skill directory conventions.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the `npx skills` (vercel-labs/skills) convention:
|
|
8
|
+
* - Project scope: `./<agent>/skills/`
|
|
9
|
+
* - User scope: `~/<agent>/skills/` (per-agent home dir)
|
|
10
|
+
*
|
|
11
|
+
* `universal` is the shared default used by Cursor, Cline, Codex, Gemini CLI,
|
|
12
|
+
* GitHub Copilot, OpenCode, and others.
|
|
13
|
+
*/
|
|
14
|
+
export const AGENT_SKILL_DIRS = {
|
|
15
|
+
universal: { project: '.agents/skills', user: '.config/agents/skills' },
|
|
16
|
+
pi: { project: '.pi/skills', user: '.pi/agent/skills' },
|
|
17
|
+
'claude-code': { project: '.claude/skills', user: '.claude/skills' },
|
|
18
|
+
cursor: { project: '.cursor/skills', user: '.cursor/skills' },
|
|
19
|
+
codex: { project: '.agents/skills', user: '.codex/skills' },
|
|
20
|
+
'gemini-cli': { project: '.agents/skills', user: '.gemini/skills' },
|
|
21
|
+
windsurf: { project: '.windsurf/skills', user: '.codeium/windsurf/skills' },
|
|
22
|
+
continue: { project: '.continue/skills', user: '.continue/skills' },
|
|
23
|
+
};
|
|
24
|
+
export function isKnownAgent(agent) {
|
|
25
|
+
return Object.prototype.hasOwnProperty.call(AGENT_SKILL_DIRS, agent);
|
|
26
|
+
}
|
|
27
|
+
const SKILL_NAME = '4ge-cli';
|
|
28
|
+
const SKILL_FILE = 'SKILL.md';
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the absolute path for a skill file, following the `npx skills`
|
|
31
|
+
* directory convention. Throws on unknown agent names.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveSkillPath(options) {
|
|
34
|
+
const agent = options.agent ?? 'universal';
|
|
35
|
+
const scope = options.scope ?? 'project';
|
|
36
|
+
if (!isKnownAgent(agent)) {
|
|
37
|
+
throw new Error(`Unknown agent "${agent}". Known agents: ${Object.keys(AGENT_SKILL_DIRS).join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
const dirs = AGENT_SKILL_DIRS[agent];
|
|
40
|
+
const baseRelative = scope === 'project' ? dirs.project : dirs.user;
|
|
41
|
+
const base = scope === 'project'
|
|
42
|
+
? (options.cwd ?? process.cwd())
|
|
43
|
+
: (options.home ?? homedir());
|
|
44
|
+
const dir = join(base, baseRelative, SKILL_NAME);
|
|
45
|
+
return {
|
|
46
|
+
dir,
|
|
47
|
+
file: SKILL_FILE,
|
|
48
|
+
path: join(dir, SKILL_FILE),
|
|
49
|
+
agent,
|
|
50
|
+
scope,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { createSseClient } from "../core/serverSentEvents.gen.js";
|
|
3
|
+
import { getValidRequestBody } from "../core/utils.gen.js";
|
|
4
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from "./utils.gen.js";
|
|
5
|
+
export const createClient = (config = {}) => {
|
|
6
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
7
|
+
const getConfig = () => ({ ..._config });
|
|
8
|
+
const setConfig = (config) => {
|
|
9
|
+
_config = mergeConfigs(_config, config);
|
|
10
|
+
return getConfig();
|
|
11
|
+
};
|
|
12
|
+
const interceptors = createInterceptors();
|
|
13
|
+
const beforeRequest = async (options) => {
|
|
14
|
+
const opts = {
|
|
15
|
+
..._config,
|
|
16
|
+
...options,
|
|
17
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
19
|
+
serializedBody: undefined,
|
|
20
|
+
};
|
|
21
|
+
if (opts.security) {
|
|
22
|
+
await setAuthParams(opts);
|
|
23
|
+
}
|
|
24
|
+
if (opts.requestValidator) {
|
|
25
|
+
await opts.requestValidator(opts);
|
|
26
|
+
}
|
|
27
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
28
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
29
|
+
}
|
|
30
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
31
|
+
if (opts.body === undefined || opts.serializedBody === "") {
|
|
32
|
+
opts.headers.delete("Content-Type");
|
|
33
|
+
}
|
|
34
|
+
const resolvedOpts = opts;
|
|
35
|
+
const url = buildUrl(resolvedOpts);
|
|
36
|
+
return { opts: resolvedOpts, url };
|
|
37
|
+
};
|
|
38
|
+
const request = async (options) => {
|
|
39
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
40
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
41
|
+
let request;
|
|
42
|
+
let response;
|
|
43
|
+
try {
|
|
44
|
+
const { opts, url } = await beforeRequest(options);
|
|
45
|
+
const requestInit = {
|
|
46
|
+
redirect: "follow",
|
|
47
|
+
...opts,
|
|
48
|
+
body: getValidRequestBody(opts),
|
|
49
|
+
};
|
|
50
|
+
request = new Request(url, requestInit);
|
|
51
|
+
for (const fn of interceptors.request.fns) {
|
|
52
|
+
if (fn) {
|
|
53
|
+
request = await fn(request, opts);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
57
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
58
|
+
const _fetch = opts.fetch;
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
for (const fn of interceptors.response.fns) {
|
|
61
|
+
if (fn) {
|
|
62
|
+
response = await fn(response, request, opts);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const result = {
|
|
66
|
+
request,
|
|
67
|
+
response,
|
|
68
|
+
};
|
|
69
|
+
if (response.ok) {
|
|
70
|
+
const parseAs = (opts.parseAs === "auto"
|
|
71
|
+
? getParseAs(response.headers.get("Content-Type"))
|
|
72
|
+
: opts.parseAs) ?? "json";
|
|
73
|
+
if (response.status === 204 ||
|
|
74
|
+
response.headers.get("Content-Length") === "0") {
|
|
75
|
+
let emptyData;
|
|
76
|
+
switch (parseAs) {
|
|
77
|
+
case "arrayBuffer":
|
|
78
|
+
case "blob":
|
|
79
|
+
case "text":
|
|
80
|
+
emptyData = await response[parseAs]();
|
|
81
|
+
break;
|
|
82
|
+
case "formData":
|
|
83
|
+
emptyData = new FormData();
|
|
84
|
+
break;
|
|
85
|
+
case "stream":
|
|
86
|
+
emptyData = response.body;
|
|
87
|
+
break;
|
|
88
|
+
case "json":
|
|
89
|
+
default:
|
|
90
|
+
emptyData = {};
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
return opts.responseStyle === "data"
|
|
94
|
+
? emptyData
|
|
95
|
+
: {
|
|
96
|
+
data: emptyData,
|
|
97
|
+
...result,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
let data;
|
|
101
|
+
switch (parseAs) {
|
|
102
|
+
case "arrayBuffer":
|
|
103
|
+
case "blob":
|
|
104
|
+
case "formData":
|
|
105
|
+
case "text":
|
|
106
|
+
data = await response[parseAs]();
|
|
107
|
+
break;
|
|
108
|
+
case "json": {
|
|
109
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
110
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
111
|
+
const text = await response.text();
|
|
112
|
+
data = text ? JSON.parse(text) : {};
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "stream":
|
|
116
|
+
return opts.responseStyle === "data"
|
|
117
|
+
? response.body
|
|
118
|
+
: {
|
|
119
|
+
data: response.body,
|
|
120
|
+
...result,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (parseAs === "json") {
|
|
124
|
+
if (opts.responseValidator) {
|
|
125
|
+
await opts.responseValidator(data);
|
|
126
|
+
}
|
|
127
|
+
if (opts.responseTransformer) {
|
|
128
|
+
data = await opts.responseTransformer(data);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return opts.responseStyle === "data"
|
|
132
|
+
? data
|
|
133
|
+
: {
|
|
134
|
+
data,
|
|
135
|
+
...result,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const textError = await response.text();
|
|
139
|
+
let jsonError;
|
|
140
|
+
try {
|
|
141
|
+
jsonError = JSON.parse(textError);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// noop
|
|
145
|
+
}
|
|
146
|
+
throw jsonError ?? textError;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
let finalError = error;
|
|
150
|
+
for (const fn of interceptors.error.fns) {
|
|
151
|
+
if (fn) {
|
|
152
|
+
finalError = await fn(finalError, response, request, options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
finalError = finalError || {};
|
|
156
|
+
if (throwOnError) {
|
|
157
|
+
throw finalError;
|
|
158
|
+
}
|
|
159
|
+
// TODO: we probably want to return error and improve types
|
|
160
|
+
return responseStyle === "data"
|
|
161
|
+
? undefined
|
|
162
|
+
: {
|
|
163
|
+
error: finalError,
|
|
164
|
+
request,
|
|
165
|
+
response,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
170
|
+
const makeSseFn = (method) => async (options) => {
|
|
171
|
+
const { opts, url } = await beforeRequest(options);
|
|
172
|
+
return createSseClient({
|
|
173
|
+
...opts,
|
|
174
|
+
body: opts.body,
|
|
175
|
+
method,
|
|
176
|
+
onRequest: async (url, init) => {
|
|
177
|
+
let request = new Request(url, init);
|
|
178
|
+
for (const fn of interceptors.request.fns) {
|
|
179
|
+
if (fn) {
|
|
180
|
+
request = await fn(request, opts);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return request;
|
|
184
|
+
},
|
|
185
|
+
serializedBody: getValidRequestBody(opts),
|
|
186
|
+
url,
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
190
|
+
return {
|
|
191
|
+
buildUrl: _buildUrl,
|
|
192
|
+
connect: makeMethodFn("CONNECT"),
|
|
193
|
+
delete: makeMethodFn("DELETE"),
|
|
194
|
+
get: makeMethodFn("GET"),
|
|
195
|
+
getConfig,
|
|
196
|
+
head: makeMethodFn("HEAD"),
|
|
197
|
+
interceptors,
|
|
198
|
+
options: makeMethodFn("OPTIONS"),
|
|
199
|
+
patch: makeMethodFn("PATCH"),
|
|
200
|
+
post: makeMethodFn("POST"),
|
|
201
|
+
put: makeMethodFn("PUT"),
|
|
202
|
+
request,
|
|
203
|
+
setConfig,
|
|
204
|
+
sse: {
|
|
205
|
+
connect: makeSseFn("CONNECT"),
|
|
206
|
+
delete: makeSseFn("DELETE"),
|
|
207
|
+
get: makeSseFn("GET"),
|
|
208
|
+
head: makeSseFn("HEAD"),
|
|
209
|
+
options: makeSseFn("OPTIONS"),
|
|
210
|
+
patch: makeSseFn("PATCH"),
|
|
211
|
+
post: makeSseFn("POST"),
|
|
212
|
+
put: makeSseFn("PUT"),
|
|
213
|
+
trace: makeSseFn("TRACE"),
|
|
214
|
+
},
|
|
215
|
+
trace: makeMethodFn("TRACE"),
|
|
216
|
+
};
|
|
217
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js";
|
|
3
|
+
export { buildClientParams } from "../core/params.gen.js";
|
|
4
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
5
|
+
export { createClient } from "./client.gen.js";
|
|
6
|
+
export { createConfig, mergeHeaders } from "./utils.gen.js";
|