@eminent337/aery 0.1.80 → 0.1.81
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/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +23 -30
- package/dist/migrations.js.map +1 -1
- package/examples/extensions/stitch.ts +168 -0
- package/package.json +3 -3
package/dist/migrations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAoDhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CA+CnD;AA+ID;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/E;AA0DD;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAoB3C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC9B,CAQA","sourcesContent":["/**\n * One-time migrations that run on startup.\n */\n\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir, getBinDir } from \"./config.js\";\nimport { migrateKeybindingsConfig } from \"./core/keybindings.js\";\n\nconst MIGRATION_GUIDE_URL =\n\t\"https://github.com/eminent337/aery/blob/main/packages/coding-agent/CHANGELOG.md#extensions-migration\";\nconst EXTENSIONS_DOC_URL = \"https://github.com/eminent337/aery/blob/main/packages/coding-agent/docs/extensions.md\";\n\n/**\n * Migrate legacy oauth.json and settings.json apiKeys to auth.json.\n *\n * @returns Array of provider names that were migrated\n */\nexport function migrateAuthToAuthJson(): string[] {\n\tconst agentDir = getAgentDir();\n\tconst authPath = join(agentDir, \"auth.json\");\n\tconst oauthPath = join(agentDir, \"oauth.json\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\t// Skip if auth.json already exists\n\tif (existsSync(authPath)) return [];\n\n\tconst migrated: Record<string, unknown> = {};\n\tconst providers: string[] = [];\n\n\t// Migrate oauth.json\n\tif (existsSync(oauthPath)) {\n\t\ttry {\n\t\t\tconst oauth = JSON.parse(readFileSync(oauthPath, \"utf-8\"));\n\t\t\tfor (const [provider, cred] of Object.entries(oauth)) {\n\t\t\t\tmigrated[provider] = { type: \"oauth\", ...(cred as object) };\n\t\t\t\tproviders.push(provider);\n\t\t\t}\n\t\t\trenameSync(oauthPath, `${oauthPath}.migrated`);\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\t// Migrate settings.json apiKeys\n\tif (existsSync(settingsPath)) {\n\t\ttry {\n\t\t\tconst content = readFileSync(settingsPath, \"utf-8\");\n\t\t\tconst settings = JSON.parse(content);\n\t\t\tif (settings.apiKeys && typeof settings.apiKeys === \"object\") {\n\t\t\t\tfor (const [provider, key] of Object.entries(settings.apiKeys)) {\n\t\t\t\t\tif (!migrated[provider] && typeof key === \"string\") {\n\t\t\t\t\t\tmigrated[provider] = { type: \"api_key\", key };\n\t\t\t\t\t\tproviders.push(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete settings.apiKeys;\n\t\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\tif (Object.keys(migrated).length > 0) {\n\t\tmkdirSync(dirname(authPath), { recursive: true });\n\t\twriteFileSync(authPath, JSON.stringify(migrated, null, 2), { mode: 0o600 });\n\t}\n\n\treturn providers;\n}\n\n/**\n * Migrate sessions from ~/.aery/agent/*.jsonl to proper session directories.\n *\n * Bug in v0.30.0: Sessions were saved to ~/.aery/agent/ instead of\n * ~/.aery/agent/sessions/<encoded-cwd>/. This migration moves them\n * to the correct location based on the cwd in their session header.\n *\n * See: https://github.com/eminent337/aery/issues/320\n */\nexport function migrateSessionsFromAgentRoot(): void {\n\tconst agentDir = getAgentDir();\n\n\t// Find all .jsonl files directly in agentDir (not in subdirectories)\n\tlet files: string[];\n\ttry {\n\t\tfiles = readdirSync(agentDir)\n\t\t\t.filter((f) => f.endsWith(\".jsonl\"))\n\t\t\t.map((f) => join(agentDir, f));\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (files.length === 0) return;\n\n\tfor (const file of files) {\n\t\ttry {\n\t\t\t// Read first line to get session header\n\t\t\tconst content = readFileSync(file, \"utf8\");\n\t\t\tconst firstLine = content.split(\"\\n\")[0];\n\t\t\tif (!firstLine?.trim()) continue;\n\n\t\t\tconst header = JSON.parse(firstLine);\n\t\t\tif (header.type !== \"session\" || !header.cwd) continue;\n\n\t\t\tconst cwd: string = header.cwd;\n\n\t\t\t// Compute the correct session directory (same encoding as session-manager.ts)\n\t\t\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\t\t\tconst correctDir = join(agentDir, \"sessions\", safePath);\n\n\t\t\t// Create directory if needed\n\t\t\tif (!existsSync(correctDir)) {\n\t\t\t\tmkdirSync(correctDir, { recursive: true });\n\t\t\t}\n\n\t\t\t// Move the file\n\t\t\tconst fileName = file.split(\"/\").pop() || file.split(\"\\\\\").pop();\n\t\t\tconst newPath = join(correctDir, fileName!);\n\n\t\t\tif (existsSync(newPath)) continue; // Skip if target exists\n\n\t\t\trenameSync(file, newPath);\n\t\t} catch {\n\t\t\t// Skip files that can't be migrated\n\t\t}\n\t}\n}\n\n/**\n * Migrate commands/ to prompts/ if needed.\n * Works for both regular directories and symlinks.\n */\nfunction migrateCommandsToPrompts(baseDir: string, label: string): boolean {\n\tconst commandsDir = join(baseDir, \"commands\");\n\tconst promptsDir = join(baseDir, \"prompts\");\n\n\tif (existsSync(commandsDir) && !existsSync(promptsDir)) {\n\t\ttry {\n\t\t\trenameSync(commandsDir, promptsDir);\n\t\t\tconsole.log(chalk.green(`Migrated ${label} commands/ → prompts/`));\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tconsole.log(\n\t\t\t\tchalk.yellow(\n\t\t\t\t\t`Warning: Could not migrate ${label} commands/ to prompts/: ${err instanceof Error ? err.message : err}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction migrateKeybindingsConfigFile(): void {\n\tconst configPath = join(getAgentDir(), \"keybindings.json\");\n\tif (!existsSync(configPath)) return;\n\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(configPath, \"utf-8\")) as unknown;\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { config, migrated } = migrateKeybindingsConfig(parsed as Record<string, unknown>);\n\t\tif (!migrated) return;\n\t\twriteFileSync(configPath, `${JSON.stringify(config, null, 2)}\\n`, \"utf-8\");\n\t} catch {\n\t\t// Ignore malformed files during migration\n\t}\n}\n\n/**\n * Move fd/rg binaries from tools/ to bin/ if they exist.\n */\nfunction migrateToolsToBin(): void {\n\tconst agentDir = getAgentDir();\n\tconst toolsDir = join(agentDir, \"tools\");\n\tconst binDir = getBinDir();\n\n\tif (!existsSync(toolsDir)) return;\n\n\tconst binaries = [\"fd\", \"rg\", \"fd.exe\", \"rg.exe\"];\n\tlet movedAny = false;\n\n\tfor (const bin of binaries) {\n\t\tconst oldPath = join(toolsDir, bin);\n\t\tconst newPath = join(binDir, bin);\n\n\t\tif (existsSync(oldPath)) {\n\t\t\tif (!existsSync(binDir)) {\n\t\t\t\tmkdirSync(binDir, { recursive: true });\n\t\t\t}\n\t\t\tif (!existsSync(newPath)) {\n\t\t\t\ttry {\n\t\t\t\t\trenameSync(oldPath, newPath);\n\t\t\t\t\tmovedAny = true;\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore errors\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Target exists, just delete the old one\n\t\t\t\ttry {\n\t\t\t\t\trmSync?.(oldPath, { force: true });\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (movedAny) {\n\t\tconsole.log(chalk.green(`Migrated managed binaries tools/ → bin/`));\n\t}\n}\n\n/**\n * Check for deprecated hooks/ and tools/ directories.\n * Note: tools/ may contain fd/rg binaries extracted by aery, so only warn if it has other files.\n */\nfunction checkDeprecatedExtensionDirs(baseDir: string, label: string): string[] {\n\tconst hooksDir = join(baseDir, \"hooks\");\n\tconst toolsDir = join(baseDir, \"tools\");\n\tconst warnings: string[] = [];\n\n\tif (existsSync(hooksDir)) {\n\t\twarnings.push(`${label} hooks/ directory found. Hooks have been renamed to extensions.`);\n\t}\n\n\tif (existsSync(toolsDir)) {\n\t\t// Check if tools/ contains anything other than fd/rg (which are auto-extracted binaries)\n\t\ttry {\n\t\t\tconst entries = readdirSync(toolsDir);\n\t\t\tconst customTools = entries.filter((e) => {\n\t\t\t\tconst lower = e.toLowerCase();\n\t\t\t\treturn (\n\t\t\t\t\tlower !== \"fd\" && lower !== \"rg\" && lower !== \"fd.exe\" && lower !== \"rg.exe\" && !e.startsWith(\".\") // Ignore .DS_Store and other hidden files\n\t\t\t\t);\n\t\t\t});\n\t\t\tif (customTools.length > 0) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label} tools/ directory contains custom tools. Custom tools have been merged into extensions.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors\n\t\t}\n\t}\n\n\treturn warnings;\n}\n\n/**\n * Run extension system migrations (commands→prompts) and collect warnings about deprecated directories.\n */\nfunction migrateExtensionSystem(cwd: string): string[] {\n\tconst agentDir = getAgentDir();\n\tconst projectDir = join(cwd, CONFIG_DIR_NAME);\n\n\t// Migrate commands/ to prompts/\n\tmigrateCommandsToPrompts(agentDir, \"Global\");\n\tmigrateCommandsToPrompts(projectDir, \"Project\");\n\n\t// Check for deprecated directories\n\tconst warnings = [\n\t\t...checkDeprecatedExtensionDirs(agentDir, \"Global\"),\n\t\t...checkDeprecatedExtensionDirs(projectDir, \"Project\"),\n\t];\n\n\treturn warnings;\n}\n\n/**\n * Print deprecation warnings and wait for keypress.\n */\nexport async function showDeprecationWarnings(warnings: string[]): Promise<void> {\n\tif (warnings.length === 0) return;\n\n\tfor (const warning of warnings) {\n\t\tconsole.log(chalk.yellow(`Warning: ${warning}`));\n\t}\n\tconsole.log(chalk.yellow(`\\nMove your extensions to the extensions/ directory.`));\n\tconsole.log(chalk.yellow(`Migration guide: ${MIGRATION_GUIDE_URL}`));\n\tconsole.log(chalk.yellow(`Documentation: ${EXTENSIONS_DOC_URL}`));\n\tconsole.log(chalk.dim(`\\nPress any key to continue...`));\n\n\tawait new Promise<void>((resolve) => {\n\t\tprocess.stdin.setRawMode?.(true);\n\t\tprocess.stdin.resume();\n\t\tprocess.stdin.once(\"data\", () => {\n\t\t\tprocess.stdin.setRawMode?.(false);\n\t\t\tprocess.stdin.pause();\n\t\t\tresolve();\n\t\t});\n\t});\n\tconsole.log();\n}\n\n/**\n * Wire any missing core extensions for existing users who already have aery-extensions installed.\n * Runs on every startup but is idempotent — only adds extensions not already in settings.\n */\nfunction wireMissingCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\tif (!existsSync(repoPath) || !existsSync(settingsPath)) return;\n\n\tconst CORE: Array<string | [string, string]> = [\n\t\t\"damage-control\",\n\t\t\"provider-profiles\",\n\t\t\"model-failover\",\n\t\t\"web-search\",\n\t\t\"web-fetch\",\n\t\t\"commands\",\n\t\t\"hooks\",\n\t\t\"circuit-breaker\",\n\t\t\"auto-router\",\n\t\t\"memory-include\",\n\t\t\"aery-header\",\n\t\t\"aery-footer\",\n\t\t\"multi-agent\",\n\t\t\"agent-chain\",\n\t\t\"agent-teams\",\n\t\t\"help\",\n\t\t\"default-agents\",\n\t\t\"aery-doctor\",\n\t\t\"aery-team\",\n\t\t[\"subagent\", \"subagent/index\"],\n\t];\n\n\ttry {\n\t\tconst settings = JSON.parse(readFileSync(settingsPath, \"utf-8\"));\n\t\tconst existing = new Set<string>(settings.extensions || []);\n\t\tlet added = false;\n\t\tfor (const ext of CORE) {\n\t\t\tconst [, filePath] = Array.isArray(ext) ? ext : [ext, ext];\n\t\t\tconst p = join(repoPath, \"core\", `${filePath}.ts`);\n\t\t\tif (existsSync(p) && !existing.has(p)) {\n\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\tsettings.extensions.push(p);\n\t\t\t\texisting.add(p);\n\t\t\t\tadded = true;\n\t\t\t}\n\t\t}\n\t\tif (added) {\n\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t}\n\t} catch {\n\t\t// Silent fail\n\t}\n}\n\n/**\n * Ensure aery-extensions is cloned and core extensions are wired.\n * Called at startup — installs aery-extensions if missing, then wires core extensions.\n * Safe to call multiple times (idempotent).\n */\nexport function ensureCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\n\t// Clone if missing\n\tif (!existsSync(repoPath)) {\n\t\ttry {\n\t\t\tmkdirSync(join(agentDir, \"git\", \"github.com\", \"eminent337\"), { recursive: true });\n\t\t\texecSync(`git clone --depth=1 https://github.com/eminent337/aery-extensions.git \"${repoPath}\"`, {\n\t\t\t\tstdio: \"pipe\",\n\t\t\t\ttimeout: 30000,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Network unavailable or git missing — skip silently\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Wire core extensions into settings\n\twireMissingCoreExtensions();\n}\n\n/**\n * Run all migrations. Called once on startup.\n *\n * @returns Object with migration results and deprecation warnings\n */\nexport function runMigrations(cwd: string): {\n\tmigratedAuthProviders: string[];\n\tdeprecationWarnings: string[];\n} {\n\tconst migratedAuthProviders = migrateAuthToAuthJson();\n\tmigrateSessionsFromAgentRoot();\n\tmigrateToolsToBin();\n\tmigrateKeybindingsConfigFile();\n\twireMissingCoreExtensions();\n\tconst deprecationWarnings = migrateExtensionSystem(cwd);\n\treturn { migratedAuthProviders, deprecationWarnings };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAoDhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CA+CnD;AA+ID;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/E;AAoDD;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAoB3C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAC3C,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC9B,CAQA","sourcesContent":["/**\n * One-time migrations that run on startup.\n */\n\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir, getBinDir } from \"./config.js\";\nimport { migrateKeybindingsConfig } from \"./core/keybindings.js\";\n\nconst MIGRATION_GUIDE_URL =\n\t\"https://github.com/eminent337/aery/blob/main/packages/coding-agent/CHANGELOG.md#extensions-migration\";\nconst EXTENSIONS_DOC_URL = \"https://github.com/eminent337/aery/blob/main/packages/coding-agent/docs/extensions.md\";\n\n/**\n * Migrate legacy oauth.json and settings.json apiKeys to auth.json.\n *\n * @returns Array of provider names that were migrated\n */\nexport function migrateAuthToAuthJson(): string[] {\n\tconst agentDir = getAgentDir();\n\tconst authPath = join(agentDir, \"auth.json\");\n\tconst oauthPath = join(agentDir, \"oauth.json\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\t// Skip if auth.json already exists\n\tif (existsSync(authPath)) return [];\n\n\tconst migrated: Record<string, unknown> = {};\n\tconst providers: string[] = [];\n\n\t// Migrate oauth.json\n\tif (existsSync(oauthPath)) {\n\t\ttry {\n\t\t\tconst oauth = JSON.parse(readFileSync(oauthPath, \"utf-8\"));\n\t\t\tfor (const [provider, cred] of Object.entries(oauth)) {\n\t\t\t\tmigrated[provider] = { type: \"oauth\", ...(cred as object) };\n\t\t\t\tproviders.push(provider);\n\t\t\t}\n\t\t\trenameSync(oauthPath, `${oauthPath}.migrated`);\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\t// Migrate settings.json apiKeys\n\tif (existsSync(settingsPath)) {\n\t\ttry {\n\t\t\tconst content = readFileSync(settingsPath, \"utf-8\");\n\t\t\tconst settings = JSON.parse(content);\n\t\t\tif (settings.apiKeys && typeof settings.apiKeys === \"object\") {\n\t\t\t\tfor (const [provider, key] of Object.entries(settings.apiKeys)) {\n\t\t\t\t\tif (!migrated[provider] && typeof key === \"string\") {\n\t\t\t\t\t\tmigrated[provider] = { type: \"api_key\", key };\n\t\t\t\t\t\tproviders.push(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete settings.apiKeys;\n\t\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\tif (Object.keys(migrated).length > 0) {\n\t\tmkdirSync(dirname(authPath), { recursive: true });\n\t\twriteFileSync(authPath, JSON.stringify(migrated, null, 2), { mode: 0o600 });\n\t}\n\n\treturn providers;\n}\n\n/**\n * Migrate sessions from ~/.aery/agent/*.jsonl to proper session directories.\n *\n * Bug in v0.30.0: Sessions were saved to ~/.aery/agent/ instead of\n * ~/.aery/agent/sessions/<encoded-cwd>/. This migration moves them\n * to the correct location based on the cwd in their session header.\n *\n * See: https://github.com/eminent337/aery/issues/320\n */\nexport function migrateSessionsFromAgentRoot(): void {\n\tconst agentDir = getAgentDir();\n\n\t// Find all .jsonl files directly in agentDir (not in subdirectories)\n\tlet files: string[];\n\ttry {\n\t\tfiles = readdirSync(agentDir)\n\t\t\t.filter((f) => f.endsWith(\".jsonl\"))\n\t\t\t.map((f) => join(agentDir, f));\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (files.length === 0) return;\n\n\tfor (const file of files) {\n\t\ttry {\n\t\t\t// Read first line to get session header\n\t\t\tconst content = readFileSync(file, \"utf8\");\n\t\t\tconst firstLine = content.split(\"\\n\")[0];\n\t\t\tif (!firstLine?.trim()) continue;\n\n\t\t\tconst header = JSON.parse(firstLine);\n\t\t\tif (header.type !== \"session\" || !header.cwd) continue;\n\n\t\t\tconst cwd: string = header.cwd;\n\n\t\t\t// Compute the correct session directory (same encoding as session-manager.ts)\n\t\t\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\t\t\tconst correctDir = join(agentDir, \"sessions\", safePath);\n\n\t\t\t// Create directory if needed\n\t\t\tif (!existsSync(correctDir)) {\n\t\t\t\tmkdirSync(correctDir, { recursive: true });\n\t\t\t}\n\n\t\t\t// Move the file\n\t\t\tconst fileName = file.split(\"/\").pop() || file.split(\"\\\\\").pop();\n\t\t\tconst newPath = join(correctDir, fileName!);\n\n\t\t\tif (existsSync(newPath)) continue; // Skip if target exists\n\n\t\t\trenameSync(file, newPath);\n\t\t} catch {\n\t\t\t// Skip files that can't be migrated\n\t\t}\n\t}\n}\n\n/**\n * Migrate commands/ to prompts/ if needed.\n * Works for both regular directories and symlinks.\n */\nfunction migrateCommandsToPrompts(baseDir: string, label: string): boolean {\n\tconst commandsDir = join(baseDir, \"commands\");\n\tconst promptsDir = join(baseDir, \"prompts\");\n\n\tif (existsSync(commandsDir) && !existsSync(promptsDir)) {\n\t\ttry {\n\t\t\trenameSync(commandsDir, promptsDir);\n\t\t\tconsole.log(chalk.green(`Migrated ${label} commands/ → prompts/`));\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tconsole.log(\n\t\t\t\tchalk.yellow(\n\t\t\t\t\t`Warning: Could not migrate ${label} commands/ to prompts/: ${err instanceof Error ? err.message : err}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction migrateKeybindingsConfigFile(): void {\n\tconst configPath = join(getAgentDir(), \"keybindings.json\");\n\tif (!existsSync(configPath)) return;\n\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(configPath, \"utf-8\")) as unknown;\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { config, migrated } = migrateKeybindingsConfig(parsed as Record<string, unknown>);\n\t\tif (!migrated) return;\n\t\twriteFileSync(configPath, `${JSON.stringify(config, null, 2)}\\n`, \"utf-8\");\n\t} catch {\n\t\t// Ignore malformed files during migration\n\t}\n}\n\n/**\n * Move fd/rg binaries from tools/ to bin/ if they exist.\n */\nfunction migrateToolsToBin(): void {\n\tconst agentDir = getAgentDir();\n\tconst toolsDir = join(agentDir, \"tools\");\n\tconst binDir = getBinDir();\n\n\tif (!existsSync(toolsDir)) return;\n\n\tconst binaries = [\"fd\", \"rg\", \"fd.exe\", \"rg.exe\"];\n\tlet movedAny = false;\n\n\tfor (const bin of binaries) {\n\t\tconst oldPath = join(toolsDir, bin);\n\t\tconst newPath = join(binDir, bin);\n\n\t\tif (existsSync(oldPath)) {\n\t\t\tif (!existsSync(binDir)) {\n\t\t\t\tmkdirSync(binDir, { recursive: true });\n\t\t\t}\n\t\t\tif (!existsSync(newPath)) {\n\t\t\t\ttry {\n\t\t\t\t\trenameSync(oldPath, newPath);\n\t\t\t\t\tmovedAny = true;\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore errors\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Target exists, just delete the old one\n\t\t\t\ttry {\n\t\t\t\t\trmSync?.(oldPath, { force: true });\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (movedAny) {\n\t\tconsole.log(chalk.green(`Migrated managed binaries tools/ → bin/`));\n\t}\n}\n\n/**\n * Check for deprecated hooks/ and tools/ directories.\n * Note: tools/ may contain fd/rg binaries extracted by aery, so only warn if it has other files.\n */\nfunction checkDeprecatedExtensionDirs(baseDir: string, label: string): string[] {\n\tconst hooksDir = join(baseDir, \"hooks\");\n\tconst toolsDir = join(baseDir, \"tools\");\n\tconst warnings: string[] = [];\n\n\tif (existsSync(hooksDir)) {\n\t\twarnings.push(`${label} hooks/ directory found. Hooks have been renamed to extensions.`);\n\t}\n\n\tif (existsSync(toolsDir)) {\n\t\t// Check if tools/ contains anything other than fd/rg (which are auto-extracted binaries)\n\t\ttry {\n\t\t\tconst entries = readdirSync(toolsDir);\n\t\t\tconst customTools = entries.filter((e) => {\n\t\t\t\tconst lower = e.toLowerCase();\n\t\t\t\treturn (\n\t\t\t\t\tlower !== \"fd\" && lower !== \"rg\" && lower !== \"fd.exe\" && lower !== \"rg.exe\" && !e.startsWith(\".\") // Ignore .DS_Store and other hidden files\n\t\t\t\t);\n\t\t\t});\n\t\t\tif (customTools.length > 0) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label} tools/ directory contains custom tools. Custom tools have been merged into extensions.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors\n\t\t}\n\t}\n\n\treturn warnings;\n}\n\n/**\n * Run extension system migrations (commands→prompts) and collect warnings about deprecated directories.\n */\nfunction migrateExtensionSystem(cwd: string): string[] {\n\tconst agentDir = getAgentDir();\n\tconst projectDir = join(cwd, CONFIG_DIR_NAME);\n\n\t// Migrate commands/ to prompts/\n\tmigrateCommandsToPrompts(agentDir, \"Global\");\n\tmigrateCommandsToPrompts(projectDir, \"Project\");\n\n\t// Check for deprecated directories\n\tconst warnings = [\n\t\t...checkDeprecatedExtensionDirs(agentDir, \"Global\"),\n\t\t...checkDeprecatedExtensionDirs(projectDir, \"Project\"),\n\t];\n\n\treturn warnings;\n}\n\n/**\n * Print deprecation warnings and wait for keypress.\n */\nexport async function showDeprecationWarnings(warnings: string[]): Promise<void> {\n\tif (warnings.length === 0) return;\n\n\tfor (const warning of warnings) {\n\t\tconsole.log(chalk.yellow(`Warning: ${warning}`));\n\t}\n\tconsole.log(chalk.yellow(`\\nMove your extensions to the extensions/ directory.`));\n\tconsole.log(chalk.yellow(`Migration guide: ${MIGRATION_GUIDE_URL}`));\n\tconsole.log(chalk.yellow(`Documentation: ${EXTENSIONS_DOC_URL}`));\n\tconsole.log(chalk.dim(`\\nPress any key to continue...`));\n\n\tawait new Promise<void>((resolve) => {\n\t\tprocess.stdin.setRawMode?.(true);\n\t\tprocess.stdin.resume();\n\t\tprocess.stdin.once(\"data\", () => {\n\t\t\tprocess.stdin.setRawMode?.(false);\n\t\t\tprocess.stdin.pause();\n\t\t\tresolve();\n\t\t});\n\t});\n\tconsole.log();\n}\n\n/**\n * Wire any missing core extensions for existing users who already have aery-extensions installed.\n * Runs on every startup but is idempotent — only adds extensions not already in settings.\n */\nfunction wireMissingCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\tif (!existsSync(repoPath) || !existsSync(settingsPath)) return;\n\n\tconst coreDir = join(repoPath, \"core\");\n\tif (!existsSync(coreDir)) return;\n\n\ttry {\n\t\tconst settings = JSON.parse(readFileSync(settingsPath, \"utf-8\"));\n\t\tconst existing = new Set<string>(settings.extensions || []);\n\t\tlet added = false;\n\n\t\t// Wire all .ts files directly in core/\n\t\tfor (const entry of readdirSync(coreDir, { withFileTypes: true })) {\n\t\t\tif (entry.isFile() && entry.name.endsWith(\".ts\")) {\n\t\t\t\tconst p = join(coreDir, entry.name);\n\t\t\t\tif (!existing.has(p)) {\n\t\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\t\tsettings.extensions.push(p);\n\t\t\t\t\texisting.add(p);\n\t\t\t\t\tadded = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Wire subdirectory index files (e.g. subagent/index.ts)\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tconst indexPath = join(coreDir, entry.name, \"index.ts\");\n\t\t\t\tif (existsSync(indexPath) && !existing.has(indexPath)) {\n\t\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\t\tsettings.extensions.push(indexPath);\n\t\t\t\t\texisting.add(indexPath);\n\t\t\t\t\tadded = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (added) {\n\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t}\n\t} catch {\n\t\t// Silent fail\n\t}\n}\n\n/**\n * Ensure aery-extensions is cloned and core extensions are wired.\n * Called at startup — installs aery-extensions if missing, then wires core extensions.\n * Safe to call multiple times (idempotent).\n */\nexport function ensureCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\n\t// Clone if missing\n\tif (!existsSync(repoPath)) {\n\t\ttry {\n\t\t\tmkdirSync(join(agentDir, \"git\", \"github.com\", \"eminent337\"), { recursive: true });\n\t\t\texecSync(`git clone --depth=1 https://github.com/eminent337/aery-extensions.git \"${repoPath}\"`, {\n\t\t\t\tstdio: \"pipe\",\n\t\t\t\ttimeout: 30000,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Network unavailable or git missing — skip silently\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Wire core extensions into settings\n\twireMissingCoreExtensions();\n}\n\n/**\n * Run all migrations. Called once on startup.\n *\n * @returns Object with migration results and deprecation warnings\n */\nexport function runMigrations(cwd: string): {\n\tmigratedAuthProviders: string[];\n\tdeprecationWarnings: string[];\n} {\n\tconst migratedAuthProviders = migrateAuthToAuthJson();\n\tmigrateSessionsFromAgentRoot();\n\tmigrateToolsToBin();\n\tmigrateKeybindingsConfigFile();\n\twireMissingCoreExtensions();\n\tconst deprecationWarnings = migrateExtensionSystem(cwd);\n\treturn { migratedAuthProviders, deprecationWarnings };\n}\n"]}
|
package/dist/migrations.js
CHANGED
|
@@ -276,40 +276,33 @@ function wireMissingCoreExtensions() {
|
|
|
276
276
|
const settingsPath = join(agentDir, "settings.json");
|
|
277
277
|
if (!existsSync(repoPath) || !existsSync(settingsPath))
|
|
278
278
|
return;
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
"model-failover",
|
|
283
|
-
"web-search",
|
|
284
|
-
"web-fetch",
|
|
285
|
-
"commands",
|
|
286
|
-
"hooks",
|
|
287
|
-
"circuit-breaker",
|
|
288
|
-
"auto-router",
|
|
289
|
-
"memory-include",
|
|
290
|
-
"aery-header",
|
|
291
|
-
"aery-footer",
|
|
292
|
-
"multi-agent",
|
|
293
|
-
"agent-chain",
|
|
294
|
-
"agent-teams",
|
|
295
|
-
"help",
|
|
296
|
-
"default-agents",
|
|
297
|
-
"aery-doctor",
|
|
298
|
-
"aery-team",
|
|
299
|
-
["subagent", "subagent/index"],
|
|
300
|
-
];
|
|
279
|
+
const coreDir = join(repoPath, "core");
|
|
280
|
+
if (!existsSync(coreDir))
|
|
281
|
+
return;
|
|
301
282
|
try {
|
|
302
283
|
const settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
303
284
|
const existing = new Set(settings.extensions || []);
|
|
304
285
|
let added = false;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
286
|
+
// Wire all .ts files directly in core/
|
|
287
|
+
for (const entry of readdirSync(coreDir, { withFileTypes: true })) {
|
|
288
|
+
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
289
|
+
const p = join(coreDir, entry.name);
|
|
290
|
+
if (!existing.has(p)) {
|
|
291
|
+
settings.extensions = settings.extensions || [];
|
|
292
|
+
settings.extensions.push(p);
|
|
293
|
+
existing.add(p);
|
|
294
|
+
added = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Wire subdirectory index files (e.g. subagent/index.ts)
|
|
298
|
+
if (entry.isDirectory()) {
|
|
299
|
+
const indexPath = join(coreDir, entry.name, "index.ts");
|
|
300
|
+
if (existsSync(indexPath) && !existing.has(indexPath)) {
|
|
301
|
+
settings.extensions = settings.extensions || [];
|
|
302
|
+
settings.extensions.push(indexPath);
|
|
303
|
+
existing.add(indexPath);
|
|
304
|
+
added = true;
|
|
305
|
+
}
|
|
313
306
|
}
|
|
314
307
|
}
|
|
315
308
|
if (added) {
|
package/dist/migrations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACzG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MA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AAE,CAAC;AAAA,CACtD","sourcesContent":["/**\n * One-time migrations that run on startup.\n */\n\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir, getBinDir } from \"./config.js\";\nimport { migrateKeybindingsConfig } from \"./core/keybindings.js\";\n\nconst MIGRATION_GUIDE_URL =\n\t\"https://github.com/eminent337/aery/blob/main/packages/coding-agent/CHANGELOG.md#extensions-migration\";\nconst EXTENSIONS_DOC_URL = \"https://github.com/eminent337/aery/blob/main/packages/coding-agent/docs/extensions.md\";\n\n/**\n * Migrate legacy oauth.json and settings.json apiKeys to auth.json.\n *\n * @returns Array of provider names that were migrated\n */\nexport function migrateAuthToAuthJson(): string[] {\n\tconst agentDir = getAgentDir();\n\tconst authPath = join(agentDir, \"auth.json\");\n\tconst oauthPath = join(agentDir, \"oauth.json\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\t// Skip if auth.json already exists\n\tif (existsSync(authPath)) return [];\n\n\tconst migrated: Record<string, unknown> = {};\n\tconst providers: string[] = [];\n\n\t// Migrate oauth.json\n\tif (existsSync(oauthPath)) {\n\t\ttry {\n\t\t\tconst oauth = JSON.parse(readFileSync(oauthPath, \"utf-8\"));\n\t\t\tfor (const [provider, cred] of Object.entries(oauth)) {\n\t\t\t\tmigrated[provider] = { type: \"oauth\", ...(cred as object) };\n\t\t\t\tproviders.push(provider);\n\t\t\t}\n\t\t\trenameSync(oauthPath, `${oauthPath}.migrated`);\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\t// Migrate settings.json apiKeys\n\tif (existsSync(settingsPath)) {\n\t\ttry {\n\t\t\tconst content = readFileSync(settingsPath, \"utf-8\");\n\t\t\tconst settings = JSON.parse(content);\n\t\t\tif (settings.apiKeys && typeof settings.apiKeys === \"object\") {\n\t\t\t\tfor (const [provider, key] of Object.entries(settings.apiKeys)) {\n\t\t\t\t\tif (!migrated[provider] && typeof key === \"string\") {\n\t\t\t\t\t\tmigrated[provider] = { type: \"api_key\", key };\n\t\t\t\t\t\tproviders.push(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete settings.apiKeys;\n\t\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\tif (Object.keys(migrated).length > 0) {\n\t\tmkdirSync(dirname(authPath), { recursive: true });\n\t\twriteFileSync(authPath, JSON.stringify(migrated, null, 2), { mode: 0o600 });\n\t}\n\n\treturn providers;\n}\n\n/**\n * Migrate sessions from ~/.aery/agent/*.jsonl to proper session directories.\n *\n * Bug in v0.30.0: Sessions were saved to ~/.aery/agent/ instead of\n * ~/.aery/agent/sessions/<encoded-cwd>/. This migration moves them\n * to the correct location based on the cwd in their session header.\n *\n * See: https://github.com/eminent337/aery/issues/320\n */\nexport function migrateSessionsFromAgentRoot(): void {\n\tconst agentDir = getAgentDir();\n\n\t// Find all .jsonl files directly in agentDir (not in subdirectories)\n\tlet files: string[];\n\ttry {\n\t\tfiles = readdirSync(agentDir)\n\t\t\t.filter((f) => f.endsWith(\".jsonl\"))\n\t\t\t.map((f) => join(agentDir, f));\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (files.length === 0) return;\n\n\tfor (const file of files) {\n\t\ttry {\n\t\t\t// Read first line to get session header\n\t\t\tconst content = readFileSync(file, \"utf8\");\n\t\t\tconst firstLine = content.split(\"\\n\")[0];\n\t\t\tif (!firstLine?.trim()) continue;\n\n\t\t\tconst header = JSON.parse(firstLine);\n\t\t\tif (header.type !== \"session\" || !header.cwd) continue;\n\n\t\t\tconst cwd: string = header.cwd;\n\n\t\t\t// Compute the correct session directory (same encoding as session-manager.ts)\n\t\t\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\t\t\tconst correctDir = join(agentDir, \"sessions\", safePath);\n\n\t\t\t// Create directory if needed\n\t\t\tif (!existsSync(correctDir)) {\n\t\t\t\tmkdirSync(correctDir, { recursive: true });\n\t\t\t}\n\n\t\t\t// Move the file\n\t\t\tconst fileName = file.split(\"/\").pop() || file.split(\"\\\\\").pop();\n\t\t\tconst newPath = join(correctDir, fileName!);\n\n\t\t\tif (existsSync(newPath)) continue; // Skip if target exists\n\n\t\t\trenameSync(file, newPath);\n\t\t} catch {\n\t\t\t// Skip files that can't be migrated\n\t\t}\n\t}\n}\n\n/**\n * Migrate commands/ to prompts/ if needed.\n * Works for both regular directories and symlinks.\n */\nfunction migrateCommandsToPrompts(baseDir: string, label: string): boolean {\n\tconst commandsDir = join(baseDir, \"commands\");\n\tconst promptsDir = join(baseDir, \"prompts\");\n\n\tif (existsSync(commandsDir) && !existsSync(promptsDir)) {\n\t\ttry {\n\t\t\trenameSync(commandsDir, promptsDir);\n\t\t\tconsole.log(chalk.green(`Migrated ${label} commands/ → prompts/`));\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tconsole.log(\n\t\t\t\tchalk.yellow(\n\t\t\t\t\t`Warning: Could not migrate ${label} commands/ to prompts/: ${err instanceof Error ? err.message : err}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction migrateKeybindingsConfigFile(): void {\n\tconst configPath = join(getAgentDir(), \"keybindings.json\");\n\tif (!existsSync(configPath)) return;\n\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(configPath, \"utf-8\")) as unknown;\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { config, migrated } = migrateKeybindingsConfig(parsed as Record<string, unknown>);\n\t\tif (!migrated) return;\n\t\twriteFileSync(configPath, `${JSON.stringify(config, null, 2)}\\n`, \"utf-8\");\n\t} catch {\n\t\t// Ignore malformed files during migration\n\t}\n}\n\n/**\n * Move fd/rg binaries from tools/ to bin/ if they exist.\n */\nfunction migrateToolsToBin(): void {\n\tconst agentDir = getAgentDir();\n\tconst toolsDir = join(agentDir, \"tools\");\n\tconst binDir = getBinDir();\n\n\tif (!existsSync(toolsDir)) return;\n\n\tconst binaries = [\"fd\", \"rg\", \"fd.exe\", \"rg.exe\"];\n\tlet movedAny = false;\n\n\tfor (const bin of binaries) {\n\t\tconst oldPath = join(toolsDir, bin);\n\t\tconst newPath = join(binDir, bin);\n\n\t\tif (existsSync(oldPath)) {\n\t\t\tif (!existsSync(binDir)) {\n\t\t\t\tmkdirSync(binDir, { recursive: true });\n\t\t\t}\n\t\t\tif (!existsSync(newPath)) {\n\t\t\t\ttry {\n\t\t\t\t\trenameSync(oldPath, newPath);\n\t\t\t\t\tmovedAny = true;\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore errors\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Target exists, just delete the old one\n\t\t\t\ttry {\n\t\t\t\t\trmSync?.(oldPath, { force: true });\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (movedAny) {\n\t\tconsole.log(chalk.green(`Migrated managed binaries tools/ → bin/`));\n\t}\n}\n\n/**\n * Check for deprecated hooks/ and tools/ directories.\n * Note: tools/ may contain fd/rg binaries extracted by aery, so only warn if it has other files.\n */\nfunction checkDeprecatedExtensionDirs(baseDir: string, label: string): string[] {\n\tconst hooksDir = join(baseDir, \"hooks\");\n\tconst toolsDir = join(baseDir, \"tools\");\n\tconst warnings: string[] = [];\n\n\tif (existsSync(hooksDir)) {\n\t\twarnings.push(`${label} hooks/ directory found. Hooks have been renamed to extensions.`);\n\t}\n\n\tif (existsSync(toolsDir)) {\n\t\t// Check if tools/ contains anything other than fd/rg (which are auto-extracted binaries)\n\t\ttry {\n\t\t\tconst entries = readdirSync(toolsDir);\n\t\t\tconst customTools = entries.filter((e) => {\n\t\t\t\tconst lower = e.toLowerCase();\n\t\t\t\treturn (\n\t\t\t\t\tlower !== \"fd\" && lower !== \"rg\" && lower !== \"fd.exe\" && lower !== \"rg.exe\" && !e.startsWith(\".\") // Ignore .DS_Store and other hidden files\n\t\t\t\t);\n\t\t\t});\n\t\t\tif (customTools.length > 0) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label} tools/ directory contains custom tools. Custom tools have been merged into extensions.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors\n\t\t}\n\t}\n\n\treturn warnings;\n}\n\n/**\n * Run extension system migrations (commands→prompts) and collect warnings about deprecated directories.\n */\nfunction migrateExtensionSystem(cwd: string): string[] {\n\tconst agentDir = getAgentDir();\n\tconst projectDir = join(cwd, CONFIG_DIR_NAME);\n\n\t// Migrate commands/ to prompts/\n\tmigrateCommandsToPrompts(agentDir, \"Global\");\n\tmigrateCommandsToPrompts(projectDir, \"Project\");\n\n\t// Check for deprecated directories\n\tconst warnings = [\n\t\t...checkDeprecatedExtensionDirs(agentDir, \"Global\"),\n\t\t...checkDeprecatedExtensionDirs(projectDir, \"Project\"),\n\t];\n\n\treturn warnings;\n}\n\n/**\n * Print deprecation warnings and wait for keypress.\n */\nexport async function showDeprecationWarnings(warnings: string[]): Promise<void> {\n\tif (warnings.length === 0) return;\n\n\tfor (const warning of warnings) {\n\t\tconsole.log(chalk.yellow(`Warning: ${warning}`));\n\t}\n\tconsole.log(chalk.yellow(`\\nMove your extensions to the extensions/ directory.`));\n\tconsole.log(chalk.yellow(`Migration guide: ${MIGRATION_GUIDE_URL}`));\n\tconsole.log(chalk.yellow(`Documentation: ${EXTENSIONS_DOC_URL}`));\n\tconsole.log(chalk.dim(`\\nPress any key to continue...`));\n\n\tawait new Promise<void>((resolve) => {\n\t\tprocess.stdin.setRawMode?.(true);\n\t\tprocess.stdin.resume();\n\t\tprocess.stdin.once(\"data\", () => {\n\t\t\tprocess.stdin.setRawMode?.(false);\n\t\t\tprocess.stdin.pause();\n\t\t\tresolve();\n\t\t});\n\t});\n\tconsole.log();\n}\n\n/**\n * Wire any missing core extensions for existing users who already have aery-extensions installed.\n * Runs on every startup but is idempotent — only adds extensions not already in settings.\n */\nfunction wireMissingCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\tif (!existsSync(repoPath) || !existsSync(settingsPath)) return;\n\n\tconst CORE: Array<string | [string, string]> = [\n\t\t\"damage-control\",\n\t\t\"provider-profiles\",\n\t\t\"model-failover\",\n\t\t\"web-search\",\n\t\t\"web-fetch\",\n\t\t\"commands\",\n\t\t\"hooks\",\n\t\t\"circuit-breaker\",\n\t\t\"auto-router\",\n\t\t\"memory-include\",\n\t\t\"aery-header\",\n\t\t\"aery-footer\",\n\t\t\"multi-agent\",\n\t\t\"agent-chain\",\n\t\t\"agent-teams\",\n\t\t\"help\",\n\t\t\"default-agents\",\n\t\t\"aery-doctor\",\n\t\t\"aery-team\",\n\t\t[\"subagent\", \"subagent/index\"],\n\t];\n\n\ttry {\n\t\tconst settings = JSON.parse(readFileSync(settingsPath, \"utf-8\"));\n\t\tconst existing = new Set<string>(settings.extensions || []);\n\t\tlet added = false;\n\t\tfor (const ext of CORE) {\n\t\t\tconst [, filePath] = Array.isArray(ext) ? ext : [ext, ext];\n\t\t\tconst p = join(repoPath, \"core\", `${filePath}.ts`);\n\t\t\tif (existsSync(p) && !existing.has(p)) {\n\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\tsettings.extensions.push(p);\n\t\t\t\texisting.add(p);\n\t\t\t\tadded = true;\n\t\t\t}\n\t\t}\n\t\tif (added) {\n\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t}\n\t} catch {\n\t\t// Silent fail\n\t}\n}\n\n/**\n * Ensure aery-extensions is cloned and core extensions are wired.\n * Called at startup — installs aery-extensions if missing, then wires core extensions.\n * Safe to call multiple times (idempotent).\n */\nexport function ensureCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\n\t// Clone if missing\n\tif (!existsSync(repoPath)) {\n\t\ttry {\n\t\t\tmkdirSync(join(agentDir, \"git\", \"github.com\", \"eminent337\"), { recursive: true });\n\t\t\texecSync(`git clone --depth=1 https://github.com/eminent337/aery-extensions.git \"${repoPath}\"`, {\n\t\t\t\tstdio: \"pipe\",\n\t\t\t\ttimeout: 30000,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Network unavailable or git missing — skip silently\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Wire core extensions into settings\n\twireMissingCoreExtensions();\n}\n\n/**\n * Run all migrations. Called once on startup.\n *\n * @returns Object with migration results and deprecation warnings\n */\nexport function runMigrations(cwd: string): {\n\tmigratedAuthProviders: string[];\n\tdeprecationWarnings: string[];\n} {\n\tconst migratedAuthProviders = migrateAuthToAuthJson();\n\tmigrateSessionsFromAgentRoot();\n\tmigrateToolsToBin();\n\tmigrateKeybindingsConfigFile();\n\twireMissingCoreExtensions();\n\tconst deprecationWarnings = migrateExtensionSystem(cwd);\n\treturn { migratedAuthProviders, deprecationWarnings };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACzG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtE,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5B;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAGvC;IACD,MAAM,qBAAqB,GAAG,qBAAqB,EAAE,CAAC;IACtD,4BAA4B,EAAE,CAAC;IAC/B,iBAAiB,EAAE,CAAC;IACpB,4BAA4B,EAAE,CAAC;IAC/B,yBAAyB,EAAE,CAAC;IAC5B,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACxD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,CAAC;AAAA,CACtD","sourcesContent":["/**\n * One-time migrations that run on startup.\n */\n\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir, getBinDir } from \"./config.js\";\nimport { migrateKeybindingsConfig } from \"./core/keybindings.js\";\n\nconst MIGRATION_GUIDE_URL =\n\t\"https://github.com/eminent337/aery/blob/main/packages/coding-agent/CHANGELOG.md#extensions-migration\";\nconst EXTENSIONS_DOC_URL = \"https://github.com/eminent337/aery/blob/main/packages/coding-agent/docs/extensions.md\";\n\n/**\n * Migrate legacy oauth.json and settings.json apiKeys to auth.json.\n *\n * @returns Array of provider names that were migrated\n */\nexport function migrateAuthToAuthJson(): string[] {\n\tconst agentDir = getAgentDir();\n\tconst authPath = join(agentDir, \"auth.json\");\n\tconst oauthPath = join(agentDir, \"oauth.json\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\t// Skip if auth.json already exists\n\tif (existsSync(authPath)) return [];\n\n\tconst migrated: Record<string, unknown> = {};\n\tconst providers: string[] = [];\n\n\t// Migrate oauth.json\n\tif (existsSync(oauthPath)) {\n\t\ttry {\n\t\t\tconst oauth = JSON.parse(readFileSync(oauthPath, \"utf-8\"));\n\t\t\tfor (const [provider, cred] of Object.entries(oauth)) {\n\t\t\t\tmigrated[provider] = { type: \"oauth\", ...(cred as object) };\n\t\t\t\tproviders.push(provider);\n\t\t\t}\n\t\t\trenameSync(oauthPath, `${oauthPath}.migrated`);\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\t// Migrate settings.json apiKeys\n\tif (existsSync(settingsPath)) {\n\t\ttry {\n\t\t\tconst content = readFileSync(settingsPath, \"utf-8\");\n\t\t\tconst settings = JSON.parse(content);\n\t\t\tif (settings.apiKeys && typeof settings.apiKeys === \"object\") {\n\t\t\t\tfor (const [provider, key] of Object.entries(settings.apiKeys)) {\n\t\t\t\t\tif (!migrated[provider] && typeof key === \"string\") {\n\t\t\t\t\t\tmigrated[provider] = { type: \"api_key\", key };\n\t\t\t\t\t\tproviders.push(provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete settings.apiKeys;\n\t\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip on error\n\t\t}\n\t}\n\n\tif (Object.keys(migrated).length > 0) {\n\t\tmkdirSync(dirname(authPath), { recursive: true });\n\t\twriteFileSync(authPath, JSON.stringify(migrated, null, 2), { mode: 0o600 });\n\t}\n\n\treturn providers;\n}\n\n/**\n * Migrate sessions from ~/.aery/agent/*.jsonl to proper session directories.\n *\n * Bug in v0.30.0: Sessions were saved to ~/.aery/agent/ instead of\n * ~/.aery/agent/sessions/<encoded-cwd>/. This migration moves them\n * to the correct location based on the cwd in their session header.\n *\n * See: https://github.com/eminent337/aery/issues/320\n */\nexport function migrateSessionsFromAgentRoot(): void {\n\tconst agentDir = getAgentDir();\n\n\t// Find all .jsonl files directly in agentDir (not in subdirectories)\n\tlet files: string[];\n\ttry {\n\t\tfiles = readdirSync(agentDir)\n\t\t\t.filter((f) => f.endsWith(\".jsonl\"))\n\t\t\t.map((f) => join(agentDir, f));\n\t} catch {\n\t\treturn;\n\t}\n\n\tif (files.length === 0) return;\n\n\tfor (const file of files) {\n\t\ttry {\n\t\t\t// Read first line to get session header\n\t\t\tconst content = readFileSync(file, \"utf8\");\n\t\t\tconst firstLine = content.split(\"\\n\")[0];\n\t\t\tif (!firstLine?.trim()) continue;\n\n\t\t\tconst header = JSON.parse(firstLine);\n\t\t\tif (header.type !== \"session\" || !header.cwd) continue;\n\n\t\t\tconst cwd: string = header.cwd;\n\n\t\t\t// Compute the correct session directory (same encoding as session-manager.ts)\n\t\t\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\t\t\tconst correctDir = join(agentDir, \"sessions\", safePath);\n\n\t\t\t// Create directory if needed\n\t\t\tif (!existsSync(correctDir)) {\n\t\t\t\tmkdirSync(correctDir, { recursive: true });\n\t\t\t}\n\n\t\t\t// Move the file\n\t\t\tconst fileName = file.split(\"/\").pop() || file.split(\"\\\\\").pop();\n\t\t\tconst newPath = join(correctDir, fileName!);\n\n\t\t\tif (existsSync(newPath)) continue; // Skip if target exists\n\n\t\t\trenameSync(file, newPath);\n\t\t} catch {\n\t\t\t// Skip files that can't be migrated\n\t\t}\n\t}\n}\n\n/**\n * Migrate commands/ to prompts/ if needed.\n * Works for both regular directories and symlinks.\n */\nfunction migrateCommandsToPrompts(baseDir: string, label: string): boolean {\n\tconst commandsDir = join(baseDir, \"commands\");\n\tconst promptsDir = join(baseDir, \"prompts\");\n\n\tif (existsSync(commandsDir) && !existsSync(promptsDir)) {\n\t\ttry {\n\t\t\trenameSync(commandsDir, promptsDir);\n\t\t\tconsole.log(chalk.green(`Migrated ${label} commands/ → prompts/`));\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tconsole.log(\n\t\t\t\tchalk.yellow(\n\t\t\t\t\t`Warning: Could not migrate ${label} commands/ to prompts/: ${err instanceof Error ? err.message : err}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction migrateKeybindingsConfigFile(): void {\n\tconst configPath = join(getAgentDir(), \"keybindings.json\");\n\tif (!existsSync(configPath)) return;\n\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(configPath, \"utf-8\")) as unknown;\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\treturn;\n\t\t}\n\t\tconst { config, migrated } = migrateKeybindingsConfig(parsed as Record<string, unknown>);\n\t\tif (!migrated) return;\n\t\twriteFileSync(configPath, `${JSON.stringify(config, null, 2)}\\n`, \"utf-8\");\n\t} catch {\n\t\t// Ignore malformed files during migration\n\t}\n}\n\n/**\n * Move fd/rg binaries from tools/ to bin/ if they exist.\n */\nfunction migrateToolsToBin(): void {\n\tconst agentDir = getAgentDir();\n\tconst toolsDir = join(agentDir, \"tools\");\n\tconst binDir = getBinDir();\n\n\tif (!existsSync(toolsDir)) return;\n\n\tconst binaries = [\"fd\", \"rg\", \"fd.exe\", \"rg.exe\"];\n\tlet movedAny = false;\n\n\tfor (const bin of binaries) {\n\t\tconst oldPath = join(toolsDir, bin);\n\t\tconst newPath = join(binDir, bin);\n\n\t\tif (existsSync(oldPath)) {\n\t\t\tif (!existsSync(binDir)) {\n\t\t\t\tmkdirSync(binDir, { recursive: true });\n\t\t\t}\n\t\t\tif (!existsSync(newPath)) {\n\t\t\t\ttry {\n\t\t\t\t\trenameSync(oldPath, newPath);\n\t\t\t\t\tmovedAny = true;\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore errors\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Target exists, just delete the old one\n\t\t\t\ttry {\n\t\t\t\t\trmSync?.(oldPath, { force: true });\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (movedAny) {\n\t\tconsole.log(chalk.green(`Migrated managed binaries tools/ → bin/`));\n\t}\n}\n\n/**\n * Check for deprecated hooks/ and tools/ directories.\n * Note: tools/ may contain fd/rg binaries extracted by aery, so only warn if it has other files.\n */\nfunction checkDeprecatedExtensionDirs(baseDir: string, label: string): string[] {\n\tconst hooksDir = join(baseDir, \"hooks\");\n\tconst toolsDir = join(baseDir, \"tools\");\n\tconst warnings: string[] = [];\n\n\tif (existsSync(hooksDir)) {\n\t\twarnings.push(`${label} hooks/ directory found. Hooks have been renamed to extensions.`);\n\t}\n\n\tif (existsSync(toolsDir)) {\n\t\t// Check if tools/ contains anything other than fd/rg (which are auto-extracted binaries)\n\t\ttry {\n\t\t\tconst entries = readdirSync(toolsDir);\n\t\t\tconst customTools = entries.filter((e) => {\n\t\t\t\tconst lower = e.toLowerCase();\n\t\t\t\treturn (\n\t\t\t\t\tlower !== \"fd\" && lower !== \"rg\" && lower !== \"fd.exe\" && lower !== \"rg.exe\" && !e.startsWith(\".\") // Ignore .DS_Store and other hidden files\n\t\t\t\t);\n\t\t\t});\n\t\t\tif (customTools.length > 0) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label} tools/ directory contains custom tools. Custom tools have been merged into extensions.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors\n\t\t}\n\t}\n\n\treturn warnings;\n}\n\n/**\n * Run extension system migrations (commands→prompts) and collect warnings about deprecated directories.\n */\nfunction migrateExtensionSystem(cwd: string): string[] {\n\tconst agentDir = getAgentDir();\n\tconst projectDir = join(cwd, CONFIG_DIR_NAME);\n\n\t// Migrate commands/ to prompts/\n\tmigrateCommandsToPrompts(agentDir, \"Global\");\n\tmigrateCommandsToPrompts(projectDir, \"Project\");\n\n\t// Check for deprecated directories\n\tconst warnings = [\n\t\t...checkDeprecatedExtensionDirs(agentDir, \"Global\"),\n\t\t...checkDeprecatedExtensionDirs(projectDir, \"Project\"),\n\t];\n\n\treturn warnings;\n}\n\n/**\n * Print deprecation warnings and wait for keypress.\n */\nexport async function showDeprecationWarnings(warnings: string[]): Promise<void> {\n\tif (warnings.length === 0) return;\n\n\tfor (const warning of warnings) {\n\t\tconsole.log(chalk.yellow(`Warning: ${warning}`));\n\t}\n\tconsole.log(chalk.yellow(`\\nMove your extensions to the extensions/ directory.`));\n\tconsole.log(chalk.yellow(`Migration guide: ${MIGRATION_GUIDE_URL}`));\n\tconsole.log(chalk.yellow(`Documentation: ${EXTENSIONS_DOC_URL}`));\n\tconsole.log(chalk.dim(`\\nPress any key to continue...`));\n\n\tawait new Promise<void>((resolve) => {\n\t\tprocess.stdin.setRawMode?.(true);\n\t\tprocess.stdin.resume();\n\t\tprocess.stdin.once(\"data\", () => {\n\t\t\tprocess.stdin.setRawMode?.(false);\n\t\t\tprocess.stdin.pause();\n\t\t\tresolve();\n\t\t});\n\t});\n\tconsole.log();\n}\n\n/**\n * Wire any missing core extensions for existing users who already have aery-extensions installed.\n * Runs on every startup but is idempotent — only adds extensions not already in settings.\n */\nfunction wireMissingCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\tconst settingsPath = join(agentDir, \"settings.json\");\n\n\tif (!existsSync(repoPath) || !existsSync(settingsPath)) return;\n\n\tconst coreDir = join(repoPath, \"core\");\n\tif (!existsSync(coreDir)) return;\n\n\ttry {\n\t\tconst settings = JSON.parse(readFileSync(settingsPath, \"utf-8\"));\n\t\tconst existing = new Set<string>(settings.extensions || []);\n\t\tlet added = false;\n\n\t\t// Wire all .ts files directly in core/\n\t\tfor (const entry of readdirSync(coreDir, { withFileTypes: true })) {\n\t\t\tif (entry.isFile() && entry.name.endsWith(\".ts\")) {\n\t\t\t\tconst p = join(coreDir, entry.name);\n\t\t\t\tif (!existing.has(p)) {\n\t\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\t\tsettings.extensions.push(p);\n\t\t\t\t\texisting.add(p);\n\t\t\t\t\tadded = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Wire subdirectory index files (e.g. subagent/index.ts)\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tconst indexPath = join(coreDir, entry.name, \"index.ts\");\n\t\t\t\tif (existsSync(indexPath) && !existing.has(indexPath)) {\n\t\t\t\t\tsettings.extensions = settings.extensions || [];\n\t\t\t\t\tsettings.extensions.push(indexPath);\n\t\t\t\t\texisting.add(indexPath);\n\t\t\t\t\tadded = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (added) {\n\t\t\twriteFileSync(settingsPath, JSON.stringify(settings, null, 2));\n\t\t}\n\t} catch {\n\t\t// Silent fail\n\t}\n}\n\n/**\n * Ensure aery-extensions is cloned and core extensions are wired.\n * Called at startup — installs aery-extensions if missing, then wires core extensions.\n * Safe to call multiple times (idempotent).\n */\nexport function ensureCoreExtensions(): void {\n\tconst agentDir = getAgentDir();\n\tconst repoPath = join(agentDir, \"git\", \"github.com\", \"eminent337\", \"aery-extensions\");\n\n\t// Clone if missing\n\tif (!existsSync(repoPath)) {\n\t\ttry {\n\t\t\tmkdirSync(join(agentDir, \"git\", \"github.com\", \"eminent337\"), { recursive: true });\n\t\t\texecSync(`git clone --depth=1 https://github.com/eminent337/aery-extensions.git \"${repoPath}\"`, {\n\t\t\t\tstdio: \"pipe\",\n\t\t\t\ttimeout: 30000,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Network unavailable or git missing — skip silently\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Wire core extensions into settings\n\twireMissingCoreExtensions();\n}\n\n/**\n * Run all migrations. Called once on startup.\n *\n * @returns Object with migration results and deprecation warnings\n */\nexport function runMigrations(cwd: string): {\n\tmigratedAuthProviders: string[];\n\tdeprecationWarnings: string[];\n} {\n\tconst migratedAuthProviders = migrateAuthToAuthJson();\n\tmigrateSessionsFromAgentRoot();\n\tmigrateToolsToBin();\n\tmigrateKeybindingsConfigFile();\n\twireMissingCoreExtensions();\n\tconst deprecationWarnings = migrateExtensionSystem(cwd);\n\treturn { migratedAuthProviders, deprecationWarnings };\n}\n"]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stitch Extension
|
|
3
|
+
*
|
|
4
|
+
* Integrates Google Stitch UI design platform into Aery.
|
|
5
|
+
* Exposes Stitch MCP tools as native Aery tools so the agent can
|
|
6
|
+
* fetch design HTML, screenshots, and build full sites from Stitch projects.
|
|
7
|
+
*
|
|
8
|
+
* Setup:
|
|
9
|
+
* 1. Get a Stitch API key from https://stitch.google.com/settings
|
|
10
|
+
* 2. Set STITCH_API_KEY=<your-key> in your environment
|
|
11
|
+
* 3. Install: aery install stitch (or copy to ~/.aery/agent/extensions/)
|
|
12
|
+
*
|
|
13
|
+
* Tools registered:
|
|
14
|
+
* stitch_build_site - Build a site from a Stitch project by mapping screens to routes
|
|
15
|
+
* stitch_get_screen_code - Get the HTML/CSS code for a specific screen
|
|
16
|
+
* stitch_get_screen_image - Get a screenshot of a screen as base64
|
|
17
|
+
* stitch_list_projects - List all Stitch projects
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { execFile } from "node:child_process";
|
|
21
|
+
import { promisify } from "node:util";
|
|
22
|
+
import type { ExtensionAPI } from "@eminent337/aery";
|
|
23
|
+
import { Type } from "typebox";
|
|
24
|
+
|
|
25
|
+
const execFileAsync = promisify(execFile);
|
|
26
|
+
|
|
27
|
+
async function callStitchTool(toolName: string, data: unknown): Promise<string> {
|
|
28
|
+
const apiKey = process.env.STITCH_API_KEY;
|
|
29
|
+
const useSystemGcloud = process.env.STITCH_USE_SYSTEM_GCLOUD;
|
|
30
|
+
|
|
31
|
+
if (!apiKey && !useSystemGcloud) {
|
|
32
|
+
throw new Error("Not authenticated. Run /stitch login to set up Stitch authentication.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { stdout, stderr } = await execFileAsync(
|
|
36
|
+
"npx",
|
|
37
|
+
["@_davideast/stitch-mcp", "tool", toolName, "-d", JSON.stringify(data)],
|
|
38
|
+
{
|
|
39
|
+
env: { ...process.env },
|
|
40
|
+
timeout: 30000,
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (stderr && !stdout) throw new Error(stderr);
|
|
45
|
+
return stdout.trim();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function stitchExtension(pi: ExtensionAPI) {
|
|
49
|
+
// Prompt for login on first use if not authenticated
|
|
50
|
+
pi.on("session_start", (_event, ctx) => {
|
|
51
|
+
const isAuthed = process.env.STITCH_API_KEY || process.env.STITCH_USE_SYSTEM_GCLOUD;
|
|
52
|
+
if (!isAuthed) {
|
|
53
|
+
ctx.ui.notify(
|
|
54
|
+
"Stitch extension loaded but not authenticated.\nRun /stitch login to connect to Google Stitch.",
|
|
55
|
+
"info",
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
pi.registerTool({
|
|
60
|
+
name: "stitch_build_site",
|
|
61
|
+
label: "Stitch: Build Site",
|
|
62
|
+
description:
|
|
63
|
+
"Build a site from a Google Stitch project by mapping screens to routes. Returns the design HTML for each page so the agent can implement it.",
|
|
64
|
+
promptSnippet: "Use stitch_build_site to get design HTML from a Stitch project before implementing UI.",
|
|
65
|
+
parameters: Type.Object({
|
|
66
|
+
projectId: Type.String({ description: "The Stitch project ID" }),
|
|
67
|
+
routes: Type.Array(
|
|
68
|
+
Type.Object({
|
|
69
|
+
screenId: Type.String({ description: "The screen ID" }),
|
|
70
|
+
route: Type.String({ description: 'The route path, e.g. "/" or "/about"' }),
|
|
71
|
+
}),
|
|
72
|
+
{ description: "Mapping of screen IDs to route paths" },
|
|
73
|
+
),
|
|
74
|
+
}),
|
|
75
|
+
async execute(_toolCallId, params) {
|
|
76
|
+
const result = await callStitchTool("build_site", params);
|
|
77
|
+
return { content: [{ type: "text", text: result }], details: {} };
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
pi.registerTool({
|
|
82
|
+
name: "stitch_get_screen_code",
|
|
83
|
+
label: "Stitch: Get Screen Code",
|
|
84
|
+
description: "Get the HTML/CSS code for a specific screen from a Google Stitch project.",
|
|
85
|
+
promptSnippet: "Use stitch_get_screen_code to fetch the design HTML for a single screen.",
|
|
86
|
+
parameters: Type.Object({
|
|
87
|
+
projectId: Type.String({ description: "The Stitch project ID" }),
|
|
88
|
+
screenId: Type.String({ description: "The screen ID" }),
|
|
89
|
+
}),
|
|
90
|
+
async execute(_toolCallId, params) {
|
|
91
|
+
const result = await callStitchTool("get_screen_code", params);
|
|
92
|
+
return { content: [{ type: "text", text: result }], details: {} };
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
pi.registerTool({
|
|
97
|
+
name: "stitch_get_screen_image",
|
|
98
|
+
label: "Stitch: Get Screen Image",
|
|
99
|
+
description: "Get a screenshot of a Stitch screen as a base64 image.",
|
|
100
|
+
promptSnippet: "Use stitch_get_screen_image to see what a Stitch screen looks like visually.",
|
|
101
|
+
parameters: Type.Object({
|
|
102
|
+
projectId: Type.String({ description: "The Stitch project ID" }),
|
|
103
|
+
screenId: Type.String({ description: "The screen ID" }),
|
|
104
|
+
}),
|
|
105
|
+
async execute(_toolCallId, params) {
|
|
106
|
+
const result = await callStitchTool("get_screen_image", params);
|
|
107
|
+
// Result is base64 image data
|
|
108
|
+
return {
|
|
109
|
+
content: [{ type: "image", data: result, mimeType: "image/png" }],
|
|
110
|
+
details: {},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
pi.registerTool({
|
|
116
|
+
name: "stitch_list_projects",
|
|
117
|
+
label: "Stitch: List Projects",
|
|
118
|
+
description: "List all Google Stitch projects available to your account.",
|
|
119
|
+
promptSnippet: "Use stitch_list_projects to discover available Stitch projects and their IDs.",
|
|
120
|
+
parameters: Type.Object({}),
|
|
121
|
+
async execute(_toolCallId, _params) {
|
|
122
|
+
const result = await callStitchTool("list_projects", {});
|
|
123
|
+
return { content: [{ type: "text", text: result }], details: {} };
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
pi.registerCommand("stitch", {
|
|
128
|
+
description: "Stitch integration — /stitch login | /stitch projects",
|
|
129
|
+
handler: async (args, ctx) => {
|
|
130
|
+
const cmd = args.trim();
|
|
131
|
+
|
|
132
|
+
if (cmd === "login") {
|
|
133
|
+
ctx.ui.notify("Opening Stitch authentication wizard...", "info");
|
|
134
|
+
try {
|
|
135
|
+
// Run stitch-mcp init in a visible subprocess
|
|
136
|
+
await execFileAsync("npx", ["@_davideast/stitch-mcp", "init"], {
|
|
137
|
+
env: { ...process.env },
|
|
138
|
+
timeout: 120000,
|
|
139
|
+
stdio: "inherit",
|
|
140
|
+
} as Parameters<typeof execFileAsync>[2]);
|
|
141
|
+
ctx.ui.notify("Stitch authentication complete.", "info");
|
|
142
|
+
} catch (err) {
|
|
143
|
+
ctx.ui.notify(
|
|
144
|
+
`Auth failed: ${err instanceof Error ? err.message : err}\n\nAlternatively, set STITCH_API_KEY=<your-key> from https://stitch.google.com/settings`,
|
|
145
|
+
"error",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (cmd === "projects") {
|
|
152
|
+
ctx.ui.notify("Fetching Stitch projects...", "info");
|
|
153
|
+
try {
|
|
154
|
+
const result = await callStitchTool("list_projects", {});
|
|
155
|
+
ctx.ui.notify(result, "info");
|
|
156
|
+
} catch (err) {
|
|
157
|
+
ctx.ui.notify(`Error: ${err instanceof Error ? err.message : err}`, "error");
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
ctx.ui.notify(
|
|
163
|
+
"Usage:\n /stitch login — authenticate with Google Stitch\n /stitch projects — list your Stitch projects",
|
|
164
|
+
"info",
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eminent337/aery",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.81",
|
|
4
4
|
"description": "Aery — AI coding agent by Aryee",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"aeryConfig": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"prepublishOnly": "npm run clean && ../../node_modules/.bin/tsgo -p tsconfig.build.json && ../../node_modules/.bin/shx chmod +x dist/cli.js && npm run copy-assets"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@eminent337/aery-ai": "0.67.
|
|
43
|
-
"@eminent337/aery-core": "0.67.
|
|
42
|
+
"@eminent337/aery-ai": "0.67.93",
|
|
43
|
+
"@eminent337/aery-core": "0.67.86",
|
|
44
44
|
"@eminent337/aery-tui": "0.67.68",
|
|
45
45
|
"@mariozechner/jiti": "2.6.2",
|
|
46
46
|
"@silvia-odwyer/photon-node": "^0.3.4",
|