openvibe 0.60.4 → 0.62.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/CHANGELOG.md +15 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +18 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -1
- package/dist/utils/version-check.d.ts +2 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +115 -0
- package/dist/utils/version-check.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [0.61.0] - 2025-03-13
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Update Check**: Added automatic version check from npm registry on startup
|
|
13
|
+
- Checks for new versions without requiring a remote server
|
|
14
|
+
- Caches results for 24 hours to avoid frequent requests
|
|
15
|
+
- Shows update notification when a newer version is available
|
|
16
|
+
- Can be skipped with `--offline` flag or `PI_SKIP_VERSION_CHECK` env variable
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **Skills Loading**: Changed to priority-based fallback system
|
|
21
|
+
- Checks skill directories in priority order
|
|
22
|
+
- Stops checking once skills are found in a higher priority directory
|
|
23
|
+
- Allows overriding default skills by placing them in higher priority directories
|
|
24
|
+
|
|
10
25
|
### Fixed
|
|
11
26
|
|
|
12
27
|
- Fixed CI failures: resolved biome lint errors and TypeScript compilation issues
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAwE3D,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AACD,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,OAAO,CAAC;CAChC;AACD,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CAClC;AA6BD,MAAM,WAAW,wBAAwB;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CACf;AACD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,gBAAgB,CAGrF;AAwGD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAkC7D;AASD,MAAM,WAAW,iBAAiB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAmG5E","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/**\n * Get all global skill directories to search.\n * Returns paths in priority order (first found wins).\n */\nfunction getGlobalSkillPaths(): Array<{ path: string; source: string }> {\n\tconst home = homedir();\n\treturn [\n\t\t{ path: join(home, CONFIG_DIR_NAME, \"skills\"), source: \"user\" }, // ~/.openvibe/skills\n\t\t{ path: join(home, \".agents\", \"skills\"), source: \"agents\" }, // ~/.agents/skills (Agent Skills standard)\n\t\t{ path: join(home, \".claude\", \"skills\"), source: \"claude\" }, // ~/.claude/skills (Claude compatibility)\n\t\t{ path: join(home, \".codex\", \"skills\"), source: \"codex\" }, // ~/.codex/skills (OpenAI Codex compatibility)\n\t];\n}\n\n/**\n * Get all project-level skill directories to search.\n * Returns paths in priority order.\n */\nfunction getProjectSkillPaths(cwd: string): Array<{ path: string; source: string }> {\n\treturn [\n\t\t{ path: resolve(cwd, CONFIG_DIR_NAME, \"skills\"), source: \"project\" }, // .openvibe/skills\n\t\t{ path: resolve(cwd, \".agents\", \"skills\"), source: \"project-agents\" }, // .agents/skills\n\t\t{ path: resolve(cwd, \".claude\", \"skills\"), source: \"project-claude\" }, // .claude/skills\n\t];\n}\n\nfunction toPosixPath(p: string): string {\n\treturn p.split(sep).join(\"/\");\n}\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n}\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\treturn errors;\n}\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\nexport interface LoadSkillsFromDirOptions {\n\tdir: string;\n\tsource: string;\n}\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\treturn { skills, diagnostics };\n}\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst lines = [\n\t\t\"\\n\\n# Skills System\",\n\t\t\"\",\n\t\t\"Skills are specialized knowledge files that provide expert guidance for specific tasks.\",\n\t\t\"Each skill contains detailed instructions, best practices, and context for its domain.\",\n\t\t\"\",\n\t\t\"**How to use skills:**\",\n\t\t\"1. Review the available skills below to find one matching your current task\",\n\t\t\"2. Use the `read` tool to load the skill's full content from its location\",\n\t\t\"3. Apply the skill's guidance to your current task\",\n\t\t\"4. When a skill references relative paths, resolve them against the skill directory\",\n\t\t\"\",\n\t\t\"**Invoking a skill:**\",\n\t\t\"To load a skill, use: `read <location>` where location is the skill's file path\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\tlines.push(\"</available_skills>\");\n\tlines.push(\"\");\n\tlines.push(\"**Smart Skill Selection:**\");\n\tlines.push(\"Before responding to any task, consider if a skill could help. Skills provide domain expertise.\");\n\treturn lines.join(\"\\n\");\n}\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\nexport interface LoadSkillsOptions {\n\tcwd?: string;\n\tagentDir?: string;\n\tskillPaths?: string[];\n\tincludeDefaults?: boolean;\n}\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;\n\tconst resolvedAgentDir = agentDir ?? getAgentDir();\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\tif (includeDefaults) {\n\t\t// Load from all global skill directories\n\t\tfor (const { path, source } of getGlobalSkillPaths()) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(path, source, true));\n\t\t\t}\n\t\t}\n\t\t// Load from all project-level skill directories\n\t\tfor (const { path, source } of getProjectSkillPaths(cwd)) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(path, source, true));\n\t\t\t}\n\t\t}\n\t}\n\tconst userSkillsDir = join(resolvedAgentDir, \"skills\");\n\tconst projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, \"skills\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\treturn {\n\t\tskills: Array.from(skillMap.values()),\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAwE3D,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AACD,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,OAAO,CAAC;CAChC;AACD,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CAClC;AA6BD,MAAM,WAAW,wBAAwB;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CACf;AACD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,gBAAgB,CAGrF;AAwGD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAkC7D;AASD,MAAM,WAAW,iBAAiB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CA+G5E","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/**\n * Get all global skill directories to search.\n * Returns paths in priority order (first found wins).\n */\nfunction getGlobalSkillPaths(): Array<{ path: string; source: string }> {\n\tconst home = homedir();\n\treturn [\n\t\t{ path: join(home, CONFIG_DIR_NAME, \"skills\"), source: \"user\" }, // ~/.openvibe/skills\n\t\t{ path: join(home, \".agents\", \"skills\"), source: \"agents\" }, // ~/.agents/skills (Agent Skills standard)\n\t\t{ path: join(home, \".claude\", \"skills\"), source: \"claude\" }, // ~/.claude/skills (Claude compatibility)\n\t\t{ path: join(home, \".codex\", \"skills\"), source: \"codex\" }, // ~/.codex/skills (OpenAI Codex compatibility)\n\t];\n}\n\n/**\n * Get all project-level skill directories to search.\n * Returns paths in priority order.\n */\nfunction getProjectSkillPaths(cwd: string): Array<{ path: string; source: string }> {\n\treturn [\n\t\t{ path: resolve(cwd, CONFIG_DIR_NAME, \"skills\"), source: \"project\" }, // .openvibe/skills\n\t\t{ path: resolve(cwd, \".agents\", \"skills\"), source: \"project-agents\" }, // .agents/skills\n\t\t{ path: resolve(cwd, \".claude\", \"skills\"), source: \"project-claude\" }, // .claude/skills\n\t];\n}\n\nfunction toPosixPath(p: string): string {\n\treturn p.split(sep).join(\"/\");\n}\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n}\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\treturn errors;\n}\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\nexport interface LoadSkillsFromDirOptions {\n\tdir: string;\n\tsource: string;\n}\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\treturn { skills, diagnostics };\n}\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst lines = [\n\t\t\"\\n\\n# Skills System\",\n\t\t\"\",\n\t\t\"Skills are specialized knowledge files that provide expert guidance for specific tasks.\",\n\t\t\"Each skill contains detailed instructions, best practices, and context for its domain.\",\n\t\t\"\",\n\t\t\"**How to use skills:**\",\n\t\t\"1. Review the available skills below to find one matching your current task\",\n\t\t\"2. Use the `read` tool to load the skill's full content from its location\",\n\t\t\"3. Apply the skill's guidance to your current task\",\n\t\t\"4. When a skill references relative paths, resolve them against the skill directory\",\n\t\t\"\",\n\t\t\"**Invoking a skill:**\",\n\t\t\"To load a skill, use: `read <location>` where location is the skill's file path\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\tlines.push(\"</available_skills>\");\n\tlines.push(\"\");\n\tlines.push(\"**Smart Skill Selection:**\");\n\tlines.push(\"Before responding to any task, consider if a skill could help. Skills provide domain expertise.\");\n\treturn lines.join(\"\\n\");\n}\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\nexport interface LoadSkillsOptions {\n\tcwd?: string;\n\tagentDir?: string;\n\tskillPaths?: string[];\n\tincludeDefaults?: boolean;\n}\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;\n\tconst resolvedAgentDir = agentDir ?? getAgentDir();\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\tif (includeDefaults) {\n\t\t// Load from global skill directories with fallback\n\t\tconst globalPaths = getGlobalSkillPaths();\n\t\tfor (const { path, source } of globalPaths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tconst result = loadSkillsFromDirInternal(path, source, true);\n\t\t\t\taddSkills(result);\n\t\t\t\t// If found skills in this directory, stop checking other global paths\n\t\t\t\tif (result.skills.length > 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Load from project-level skill directories with fallback\n\t\tconst projectPaths = getProjectSkillPaths(cwd);\n\t\tfor (const { path, source } of projectPaths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tconst result = loadSkillsFromDirInternal(path, source, true);\n\t\t\t\taddSkills(result);\n\t\t\t\t// If found skills in this directory, stop checking other project paths\n\t\t\t\tif (result.skills.length > 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tconst userSkillsDir = join(resolvedAgentDir, \"skills\");\n\tconst projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, \"skills\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\treturn {\n\t\tskills: Array.from(skillMap.values()),\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
|
package/dist/core/skills.js
CHANGED
|
@@ -303,16 +303,28 @@ export function loadSkills(options = {}) {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
if (includeDefaults) {
|
|
306
|
-
// Load from
|
|
307
|
-
|
|
306
|
+
// Load from global skill directories with fallback
|
|
307
|
+
const globalPaths = getGlobalSkillPaths();
|
|
308
|
+
for (const { path, source } of globalPaths) {
|
|
308
309
|
if (existsSync(path)) {
|
|
309
|
-
|
|
310
|
+
const result = loadSkillsFromDirInternal(path, source, true);
|
|
311
|
+
addSkills(result);
|
|
312
|
+
// If found skills in this directory, stop checking other global paths
|
|
313
|
+
if (result.skills.length > 0) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
310
316
|
}
|
|
311
317
|
}
|
|
312
|
-
// Load from
|
|
313
|
-
|
|
318
|
+
// Load from project-level skill directories with fallback
|
|
319
|
+
const projectPaths = getProjectSkillPaths(cwd);
|
|
320
|
+
for (const { path, source } of projectPaths) {
|
|
314
321
|
if (existsSync(path)) {
|
|
315
|
-
|
|
322
|
+
const result = loadSkillsFromDirInternal(path, source, true);
|
|
323
|
+
addSkills(result);
|
|
324
|
+
// If found skills in this directory, stop checking other project paths
|
|
325
|
+
if (result.skills.length > 0) {
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
316
328
|
}
|
|
317
329
|
}
|
|
318
330
|
}
|
package/dist/core/skills.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WA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CAAC,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YAClE,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3D,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;gBACvD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;oBAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBACxE,CAAC;qBAAM,CAAC;oBACP,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC5C,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YAC5G,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACrF,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IACD,OAAO;QACN,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,WAAW,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,oBAAoB,CAAC;KACzD,CAAC;AAAA,CACF","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/**\n * Get all global skill directories to search.\n * Returns paths in priority order (first found wins).\n */\nfunction getGlobalSkillPaths(): Array<{ path: string; source: string }> {\n\tconst home = homedir();\n\treturn [\n\t\t{ path: join(home, CONFIG_DIR_NAME, \"skills\"), source: \"user\" }, // ~/.openvibe/skills\n\t\t{ path: join(home, \".agents\", \"skills\"), source: \"agents\" }, // ~/.agents/skills (Agent Skills standard)\n\t\t{ path: join(home, \".claude\", \"skills\"), source: \"claude\" }, // ~/.claude/skills (Claude compatibility)\n\t\t{ path: join(home, \".codex\", \"skills\"), source: \"codex\" }, // ~/.codex/skills (OpenAI Codex compatibility)\n\t];\n}\n\n/**\n * Get all project-level skill directories to search.\n * Returns paths in priority order.\n */\nfunction getProjectSkillPaths(cwd: string): Array<{ path: string; source: string }> {\n\treturn [\n\t\t{ path: resolve(cwd, CONFIG_DIR_NAME, \"skills\"), source: \"project\" }, // .openvibe/skills\n\t\t{ path: resolve(cwd, \".agents\", \"skills\"), source: \"project-agents\" }, // .agents/skills\n\t\t{ path: resolve(cwd, \".claude\", \"skills\"), source: \"project-claude\" }, // .claude/skills\n\t];\n}\n\nfunction toPosixPath(p: string): string {\n\treturn p.split(sep).join(\"/\");\n}\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n}\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\treturn errors;\n}\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\nexport interface LoadSkillsFromDirOptions {\n\tdir: string;\n\tsource: string;\n}\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\treturn { skills, diagnostics };\n}\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst lines = [\n\t\t\"\\n\\n# Skills System\",\n\t\t\"\",\n\t\t\"Skills are specialized knowledge files that provide expert guidance for specific tasks.\",\n\t\t\"Each skill contains detailed instructions, best practices, and context for its domain.\",\n\t\t\"\",\n\t\t\"**How to use skills:**\",\n\t\t\"1. Review the available skills below to find one matching your current task\",\n\t\t\"2. Use the `read` tool to load the skill's full content from its location\",\n\t\t\"3. Apply the skill's guidance to your current task\",\n\t\t\"4. When a skill references relative paths, resolve them against the skill directory\",\n\t\t\"\",\n\t\t\"**Invoking a skill:**\",\n\t\t\"To load a skill, use: `read <location>` where location is the skill's file path\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\tlines.push(\"</available_skills>\");\n\tlines.push(\"\");\n\tlines.push(\"**Smart Skill Selection:**\");\n\tlines.push(\"Before responding to any task, consider if a skill could help. Skills provide domain expertise.\");\n\treturn lines.join(\"\\n\");\n}\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\nexport interface LoadSkillsOptions {\n\tcwd?: string;\n\tagentDir?: string;\n\tskillPaths?: string[];\n\tincludeDefaults?: boolean;\n}\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;\n\tconst resolvedAgentDir = agentDir ?? getAgentDir();\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\tif (includeDefaults) {\n\t\t// Load from all global skill directories\n\t\tfor (const { path, source } of getGlobalSkillPaths()) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(path, source, true));\n\t\t\t}\n\t\t}\n\t\t// Load from all project-level skill directories\n\t\tfor (const { path, source } of getProjectSkillPaths(cwd)) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(path, source, true));\n\t\t\t}\n\t\t}\n\t}\n\tconst userSkillsDir = join(resolvedAgentDir, \"skills\");\n\tconst projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, \"skills\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\treturn {\n\t\tskills: Array.from(skillMap.values()),\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,sBAAsB,GA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AAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3D,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;gBACvD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;oBAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBACxE,CAAC;qBAAM,CAAC;oBACP,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC5C,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YAC5G,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACrF,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IACD,OAAO;QACN,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,WAAW,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,oBAAoB,CAAC;KACzD,CAAC;AAAA,CACF","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/**\n * Get all global skill directories to search.\n * Returns paths in priority order (first found wins).\n */\nfunction getGlobalSkillPaths(): Array<{ path: string; source: string }> {\n\tconst home = homedir();\n\treturn [\n\t\t{ path: join(home, CONFIG_DIR_NAME, \"skills\"), source: \"user\" }, // ~/.openvibe/skills\n\t\t{ path: join(home, \".agents\", \"skills\"), source: \"agents\" }, // ~/.agents/skills (Agent Skills standard)\n\t\t{ path: join(home, \".claude\", \"skills\"), source: \"claude\" }, // ~/.claude/skills (Claude compatibility)\n\t\t{ path: join(home, \".codex\", \"skills\"), source: \"codex\" }, // ~/.codex/skills (OpenAI Codex compatibility)\n\t];\n}\n\n/**\n * Get all project-level skill directories to search.\n * Returns paths in priority order.\n */\nfunction getProjectSkillPaths(cwd: string): Array<{ path: string; source: string }> {\n\treturn [\n\t\t{ path: resolve(cwd, CONFIG_DIR_NAME, \"skills\"), source: \"project\" }, // .openvibe/skills\n\t\t{ path: resolve(cwd, \".agents\", \"skills\"), source: \"project-agents\" }, // .agents/skills\n\t\t{ path: resolve(cwd, \".claude\", \"skills\"), source: \"project-claude\" }, // .claude/skills\n\t];\n}\n\nfunction toPosixPath(p: string): string {\n\treturn p.split(sep).join(\"/\");\n}\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n}\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\treturn errors;\n}\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\nexport interface LoadSkillsFromDirOptions {\n\tdir: string;\n\tsource: string;\n}\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst fullPath = join(dir, entry.name);\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\treturn { skills, diagnostics };\n}\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst lines = [\n\t\t\"\\n\\n# Skills System\",\n\t\t\"\",\n\t\t\"Skills are specialized knowledge files that provide expert guidance for specific tasks.\",\n\t\t\"Each skill contains detailed instructions, best practices, and context for its domain.\",\n\t\t\"\",\n\t\t\"**How to use skills:**\",\n\t\t\"1. Review the available skills below to find one matching your current task\",\n\t\t\"2. Use the `read` tool to load the skill's full content from its location\",\n\t\t\"3. Apply the skill's guidance to your current task\",\n\t\t\"4. When a skill references relative paths, resolve them against the skill directory\",\n\t\t\"\",\n\t\t\"**Invoking a skill:**\",\n\t\t\"To load a skill, use: `read <location>` where location is the skill's file path\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\tlines.push(\"</available_skills>\");\n\tlines.push(\"\");\n\tlines.push(\"**Smart Skill Selection:**\");\n\tlines.push(\"Before responding to any task, consider if a skill could help. Skills provide domain expertise.\");\n\treturn lines.join(\"\\n\");\n}\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\nexport interface LoadSkillsOptions {\n\tcwd?: string;\n\tagentDir?: string;\n\tskillPaths?: string[];\n\tincludeDefaults?: boolean;\n}\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;\n\tconst resolvedAgentDir = agentDir ?? getAgentDir();\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\tif (includeDefaults) {\n\t\t// Load from global skill directories with fallback\n\t\tconst globalPaths = getGlobalSkillPaths();\n\t\tfor (const { path, source } of globalPaths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tconst result = loadSkillsFromDirInternal(path, source, true);\n\t\t\t\taddSkills(result);\n\t\t\t\t// If found skills in this directory, stop checking other global paths\n\t\t\t\tif (result.skills.length > 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Load from project-level skill directories with fallback\n\t\tconst projectPaths = getProjectSkillPaths(cwd);\n\t\tfor (const { path, source } of projectPaths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tconst result = loadSkillsFromDirInternal(path, source, true);\n\t\t\t\taddSkills(result);\n\t\t\t\t// If found skills in this directory, stop checking other project paths\n\t\t\t\tif (result.skills.length > 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tconst userSkillsDir = join(resolvedAgentDir, \"skills\");\n\tconst projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, \"skills\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\treturn {\n\t\tskills: Array.from(skillMap.values()),\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AA4aA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,iBA+MxC","sourcesContent":["import { type ImageContent, supportsXhigh } from \"@boxiaolanya2008/pi-ai\";\nimport chalk from \"chalk\";\nimport fs from \"fs\";\nimport { createInterface } from \"readline\";\nimport { type Args, parseArgs, printHelp } from \"./cli/args.js\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport { processFileArguments } from \"./cli/file-processor.js\";\nimport { listModels } from \"./cli/list-models.js\";\nimport { selectSession } from \"./cli/session-picker.js\";\nimport { APP_NAME, getAgentDir, getModelsPath, VERSION } from \"./config.js\";\nimport { AuthStorage } from \"./core/auth-storage.js\";\nimport { exportFromFile } from \"./core/export-html/index.js\";\nimport type { LoadExtensionsResult } from \"./core/extensions/index.js\";\nimport { KeybindingsManager } from \"./core/keybindings.js\";\nimport { ModelRegistry } from \"./core/model-registry.js\";\nimport { globalMultiGPUExecutor } from \"./core/multi-gpu-executor.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { DefaultResourceLoader } from \"./core/resource-loader.js\";\nimport { type CreateAgentSessionOptions, createAgentSession } from \"./core/sdk.js\";\nimport { SessionManager } from \"./core/session-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { printTimings, time } from \"./core/timings.js\";\nimport { allTools } from \"./core/tools/index.js\";\nimport { runMigrations, showDeprecationWarnings } from \"./migrations.js\";\nimport { InteractiveMode, runPrintMode, runRpcMode } from \"./modes/index.js\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.js\";\n\nfunction debugLog(stage: string, message: string, data?: any) {\n\tconst logLine = `[${new Date().toISOString()}] [${stage}] ${message}${data ? `: ${JSON.stringify(data)}` : \"\"}\\n`;\n\tfs.appendFileSync(\"debug.log\", logLine);\n}\nasync function readPipedStdin(): Promise<string | undefined> {\n\tif (process.stdin.isTTY) {\n\t\treturn undefined;\n\t}\n\treturn new Promise((resolve) => {\n\t\tlet data = \"\";\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\t\tprocess.stdin.on(\"end\", () => {\n\t\t\tresolve(data.trim() || undefined);\n\t\t});\n\t\tprocess.stdin.resume();\n\t});\n}\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\nfunction isTruthyEnvFlag(value: string | undefined): boolean {\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\ntype PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tlocal: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n}\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\nInstall a package and add it to settings.\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https:\n ${APP_NAME} install ssh:\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\nRemove a package and its source from settings.\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\nExample:\n ${APP_NAME} remove npm:@foo/bar\n`);\n\t\t\treturn;\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\nUpdate installed packages.\nIf <source> is provided, only that package is updated.\n`);\n\t\t\treturn;\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [command, ...rest] = args;\n\tif (command !== \"install\" && command !== \"remove\" && command !== \"update\" && command !== \"list\") {\n\t\treturn undefined;\n\t}\n\tlet local = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet source: string | undefined;\n\tfor (const arg of rest) {\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t}\n\t}\n\treturn { command, source, local, help, invalidOption };\n}\nasync function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.install(source!, { local: options.local });\n\t\t\t\tpackageManager.addSourceToSettings(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\t\t\tcase \"remove\": {\n\t\t\t\tawait packageManager.remove(source!, { local: options.local });\n\t\t\t\tconst removed = packageManager.removeSourceFromSettings(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"list\": {\n\t\t\t\tconst globalSettings = settingsManager.getGlobalSettings();\n\t\t\t\tconst projectSettings = settingsManager.getProjectSettings();\n\t\t\t\tconst globalPackages = globalSettings.packages ?? [];\n\t\t\t\tconst projectPackages = projectSettings.packages ?? [];\n\t\t\t\tif (globalPackages.length === 0 && projectPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst formatPackage = (pkg: (typeof globalPackages)[number], scope: \"user\" | \"project\") => {\n\t\t\t\t\tconst source = typeof pkg === \"string\" ? pkg : pkg.source;\n\t\t\t\t\tconst filtered = typeof pkg === \"object\";\n\t\t\t\t\tconst display = filtered ? `${source} (filtered)` : source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tconst path = packageManager.getInstalledPath(source, scope);\n\t\t\t\t\tif (path) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${path}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tif (globalPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of globalPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"user\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (globalPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"project\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"update\":\n\t\t\t\tawait packageManager.update(source);\n\t\t\t\tif (source) {\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${source}`));\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\nasync function prepareInitialMessage(\n\tparsed: Args,\n\tautoResizeImages: boolean,\n): Promise<{\n\tinitialMessage?: string;\n\tinitialImages?: ImageContent[];\n}> {\n\tif (parsed.fileArgs.length === 0) {\n\t\treturn {};\n\t}\n\tconst { text, images } = await processFileArguments(parsed.fileArgs, { autoResizeImages });\n\tlet initialMessage: string;\n\tif (parsed.messages.length > 0) {\n\t\tinitialMessage = text + parsed.messages[0];\n\t\tparsed.messages.shift();\n\t} else {\n\t\tinitialMessage = text;\n\t}\n\treturn {\n\t\tinitialMessage,\n\t\tinitialImages: images.length > 0 ? images : undefined,\n\t};\n}\ntype ResolvedSession =\n\t| { type: \"path\"; path: string }\n\t| { type: \"local\"; path: string }\n\t| { type: \"global\"; path: string; cwd: string }\n\t| { type: \"not_found\"; arg: string };\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: sessionArg };\n\t}\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatches = localSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (localMatches.length >= 1) {\n\t\treturn { type: \"local\", path: localMatches[0].path };\n\t}\n\tconst allSessions = await SessionManager.listAll();\n\tconst globalMatches = allSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (globalMatches.length >= 1) {\n\t\tconst match = globalMatches[0];\n\t\treturn { type: \"global\", path: match.path, cwd: match.cwd };\n\t}\n\treturn { type: \"not_found\", arg: sessionArg };\n}\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\nasync function callSessionDirectoryHook(extensions: LoadExtensionsResult, cwd: string): Promise<string | undefined> {\n\tlet customSessionDir: string | undefined;\n\tfor (const ext of extensions.extensions) {\n\t\tconst handlers = ext.handlers.get(\"session_directory\");\n\t\tif (!handlers || handlers.length === 0) continue;\n\t\tfor (const handler of handlers) {\n\t\t\ttry {\n\t\t\t\tconst event = { type: \"session_directory\" as const, cwd };\n\t\t\t\tconst result = (await handler(event)) as { sessionDir?: string } | undefined;\n\t\t\t\tif (result?.sessionDir) {\n\t\t\t\t\tcustomSessionDir = result.sessionDir;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\tconsole.error(chalk.red(`Extension \"${ext.path}\" session_directory handler failed: ${message}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn customSessionDir;\n}\nasync function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\textensions: LoadExtensionsResult,\n): Promise<SessionManager | undefined> {\n\tif (parsed.noSession) {\n\t\treturn SessionManager.inMemory();\n\t}\n\tlet effectiveSessionDir = parsed.sessionDir;\n\tif (!effectiveSessionDir) {\n\t\teffectiveSessionDir = await callSessionDirectoryHook(extensions, cwd);\n\t}\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, effectiveSessionDir);\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn SessionManager.open(resolved.path, effectiveSessionDir);\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn SessionManager.forkFrom(resolved.path, cwd, effectiveSessionDir);\n\t\t\t}\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, effectiveSessionDir);\n\t}\n\tif (effectiveSessionDir) {\n\t\treturn SessionManager.create(cwd, effectiveSessionDir);\n\t}\n\treturn undefined;\n}\nfunction buildSessionOptions(\n\tparsed: Args,\n\tsessionManager: SessionManager | undefined,\n\t_modelRegistry: ModelRegistry,\n\t_settingsManager: SettingsManager,\n): { options: CreateAgentSessionOptions; cliThinkingFromModel: boolean } {\n\tconst options: CreateAgentSessionOptions = {};\n\tconst cliThinkingFromModel = false;\n\tif (sessionManager) {\n\t\toptions.sessionManager = sessionManager;\n\t}\n\tif (parsed.thinking) {\n\t\toptions.thinkingLevel = parsed.thinking;\n\t}\n\tif (parsed.noTools) {\n\t\tif (parsed.tools && parsed.tools.length > 0) {\n\t\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t\t} else {\n\t\t\toptions.tools = [];\n\t\t}\n\t} else if (parsed.tools) {\n\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t}\n\treturn { options, cliThinkingFromModel };\n}\nasync function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\tprocess.exit(0);\n}\nasync function processFilesInParallel(\n\tfileArgs: string[],\n\tautoResizeImages: boolean,\n): Promise<{ text: string; images: ImageContent[] }> {\n\tconst chunkSize = globalMultiGPUExecutor ? Math.ceil(fileArgs.length / 4) : fileArgs.length;\n\tconst chunks: string[][] = [];\n\tfor (let i = 0; i < fileArgs.length; i += chunkSize) {\n\t\tchunks.push(fileArgs.slice(i, i + chunkSize));\n\t}\n\tconst results = await Promise.all(chunks.map((chunk) => processFileArguments(chunk, { autoResizeImages })));\n\tconst text = results.map((r) => r.text).join(\"\");\n\tconst images = results.flatMap((r) => r.images);\n\treturn { text, images };\n}\nexport async function main(args: string[]) {\n\tdebugLog(\"main\", \"Starting main\", { args, pid: process.pid, platform: process.platform });\n\ttry {\n\t\tconst offlineMode = args.includes(\"--offline\") || isTruthyEnvFlag(process.env.PI_OFFLINE);\n\t\tif (offlineMode) {\n\t\t\tprocess.env.PI_OFFLINE = \"1\";\n\t\t\tprocess.env.PI_SKIP_VERSION_CHECK = \"1\";\n\t\t}\n\t\tif (await handlePackageCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tif (await handleConfigCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tdebugLog(\"main\", \"Running migrations\");\n\t\tconst { deprecationWarnings } = runMigrations(process.cwd());\n\t\tdebugLog(\"main\", \"Parsing args\");\n\t\tconst firstPass = parseArgs(args);\n\t\tdebugLog(\"main\", \"Initializing components\");\n\t\tconst cwd = process.cwd();\n\t\tconst agentDir = getAgentDir();\n\t\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\t\treportSettingsErrors(settingsManager, \"startup\");\n\t\tconst authStorage = AuthStorage.create();\n\t\tconst modelRegistry = new ModelRegistry(authStorage, getModelsPath());\n\t\tdebugLog(\"main\", \"Creating resource loader\");\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalExtensionPaths: firstPass.extensions,\n\t\t\tadditionalSkillPaths: firstPass.skills,\n\t\t\tadditionalPromptTemplatePaths: firstPass.promptTemplates,\n\t\t\tadditionalThemePaths: firstPass.themes,\n\t\t\tnoExtensions: firstPass.noExtensions,\n\t\t\tnoSkills: firstPass.noSkills,\n\t\t\tnoPromptTemplates: firstPass.noPromptTemplates,\n\t\t\tnoThemes: firstPass.noThemes,\n\t\t\tsystemPrompt: firstPass.systemPrompt,\n\t\t\tappendSystemPrompt: firstPass.appendSystemPrompt,\n\t\t});\n\t\tdebugLog(\"main\", \"Reloading resources\");\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t\tdebugLog(\"main\", \"Loading extensions\");\n\t\tconst extensionsResult: LoadExtensionsResult = resourceLoader.getExtensions();\n\t\tfor (const { path, error } of extensionsResult.errors) {\n\t\t\tconsole.error(chalk.red(`Failed to load extension \"${path}\": ${error}`));\n\t\t}\n\t\t// Provider registration removed - models are configured during onboarding only\n\t\tconst extensionFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\t\tfor (const ext of extensionsResult.extensions) {\n\t\t\tfor (const [name, flag] of ext.flags) {\n\t\t\t\textensionFlags.set(name, { type: flag.type });\n\t\t\t}\n\t\t}\n\t\tconst parsed = parseArgs(args, extensionFlags);\n\t\tfor (const [name, value] of parsed.unknownFlags) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t}\n\t\tif (parsed.version) {\n\t\t\tconsole.log(VERSION);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.help) {\n\t\t\tprintHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.listModels !== undefined) {\n\t\t\tconst searchPattern = typeof parsed.listModels === \"string\" ? parsed.listModels : undefined;\n\t\t\tawait listModels(modelRegistry, searchPattern);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode !== \"rpc\") {\n\t\t\tconst stdinContent = await readPipedStdin();\n\t\t\tif (stdinContent !== undefined) {\n\t\t\t\tparsed.print = true;\n\t\t\t\tparsed.messages.unshift(stdinContent);\n\t\t\t}\n\t\t}\n\t\tif (parsed.export) {\n\t\t\tlet result: string;\n\t\t\ttry {\n\t\t\t\tconst outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;\n\t\t\t\tresult = await exportFromFile(parsed.export, outputPath);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Failed to export session\";\n\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.log(`Exported to: ${result}`);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode === \"rpc\" && parsed.fileArgs.length > 0) {\n\t\t\tconsole.error(chalk.red(\"Error: @file arguments are not supported in RPC mode\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tlet initialMessage: string | undefined;\n\t\tlet initialImages: ImageContent[] | undefined;\n\t\tif (parsed.fileArgs.length > 0 && parsed.fileArgs.length > 4) {\n\t\t\tconst result = await processFilesInParallel(parsed.fileArgs, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.text;\n\t\t\tinitialImages = result.images.length > 0 ? result.images : undefined;\n\t\t\tif (parsed.messages.length > 0) {\n\t\t\t\tinitialMessage = initialMessage + parsed.messages[0];\n\t\t\t\tparsed.messages.shift();\n\t\t\t}\n\t\t} else {\n\t\t\tconst result = await prepareInitialMessage(parsed, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.initialMessage;\n\t\t\tinitialImages = result.initialImages;\n\t\t}\n\t\tconst isInteractive = !parsed.print && parsed.mode === undefined;\n\t\tconst mode = parsed.mode || \"text\";\n\t\tinitTheme(settingsManager.getTheme(), isInteractive);\n\t\tif (isInteractive && deprecationWarnings.length > 0) {\n\t\t\tawait showDeprecationWarnings(deprecationWarnings);\n\t\t}\n\t\tlet sessionManager = await createSessionManager(parsed, cwd, extensionsResult);\n\t\tif (parsed.resume) {\n\t\t\tKeybindingsManager.create();\n\t\t\tconst effectiveSessionDir = parsed.sessionDir || (await callSessionDirectoryHook(extensionsResult, cwd));\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, effectiveSessionDir, onProgress),\n\t\t\t\tSessionManager.listAll,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tsessionManager = SessionManager.open(selectedPath, effectiveSessionDir);\n\t\t}\n\t\tconst { options: sessionOptions, cliThinkingFromModel } = buildSessionOptions(\n\t\t\tparsed,\n\t\t\tsessionManager,\n\t\t\tmodelRegistry,\n\t\t\tsettingsManager,\n\t\t);\n\t\tsessionOptions.authStorage = authStorage;\n\t\tsessionOptions.modelRegistry = modelRegistry;\n\t\tsessionOptions.resourceLoader = resourceLoader;\n\t\tif (parsed.apiKey) {\n\t\t\tconsole.error(chalk.red(\"--api-key is deprecated. Please configure your API key during onboarding.\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst { session } = await createAgentSession(sessionOptions);\n\t\tif (!isInteractive && !session.model) {\n\t\t\tconsole.error(chalk.red(\"No model configured.\"));\n\t\t\tconsole.error(chalk.yellow(\"\\nPlease run onboarding to configure your model:\"));\n\t\t\tconsole.error(\" openvibe --onboarding\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst cliThinkingOverride = parsed.thinking !== undefined || cliThinkingFromModel;\n\t\tif (session.model && cliThinkingOverride) {\n\t\t\tlet effectiveThinking = session.thinkingLevel;\n\t\t\tif (!session.model.reasoning) {\n\t\t\t\teffectiveThinking = \"off\";\n\t\t\t} else if (effectiveThinking === \"xhigh\" && !supportsXhigh(session.model)) {\n\t\t\t\teffectiveThinking = \"high\";\n\t\t\t}\n\t\t\tif (effectiveThinking !== session.thinkingLevel) {\n\t\t\t\tsession.setThinkingLevel(effectiveThinking);\n\t\t\t}\n\t\t}\n\t\tdebugLog(\"main\", \"Selecting run mode\", { mode, isInteractive });\n\t\tif (mode === \"rpc\") {\n\t\t\tdebugLog(\"main\", \"Running RPC mode\");\n\t\t\tawait runRpcMode(session);\n\t\t} else if (isInteractive) {\n\t\t\tdebugLog(\"main\", \"Running interactive mode\");\n\t\t\tprintTimings();\n\t\t\tconst mode = new InteractiveMode(session, {\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t\tinitialMessages: parsed.messages,\n\t\t\t\tverbose: parsed.verbose,\n\t\t\t});\n\t\t\tawait mode.run();\n\t\t} else {\n\t\t\tdebugLog(\"main\", \"Running print mode\");\n\t\t\tawait runPrintMode(session, {\n\t\t\t\tmode,\n\t\t\t\tmessages: parsed.messages,\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t});\n\t\t\tstopThemeWatcher();\n\t\t\tif (process.stdout.writableLength > 0) {\n\t\t\t\tawait new Promise<void>((resolve) => process.stdout.once(\"drain\", resolve));\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tdebugLog(\"main\", \"Main completed successfully\");\n\t} catch (error) {\n\t\tdebugLog(\"main\", \"Main crashed\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t\tconsole.error(chalk.red(\"\\n[CRASH] Application crashed:\"));\n\t\tconsole.error(error);\n\t\tfs.appendFileSync(\n\t\t\t\"crash.log\",\n\t\t\t`[${new Date().toISOString()}] Main Crash:\\n${error instanceof Error ? error.stack : String(error)}\\n\\n`,\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AA6aA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmNxC","sourcesContent":["import { type ImageContent, supportsXhigh } from \"@boxiaolanya2008/pi-ai\";\nimport chalk from \"chalk\";\nimport fs from \"fs\";\nimport { createInterface } from \"readline\";\nimport { type Args, parseArgs, printHelp } from \"./cli/args.js\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport { processFileArguments } from \"./cli/file-processor.js\";\nimport { listModels } from \"./cli/list-models.js\";\nimport { selectSession } from \"./cli/session-picker.js\";\nimport { APP_NAME, getAgentDir, getModelsPath, VERSION } from \"./config.js\";\nimport { AuthStorage } from \"./core/auth-storage.js\";\nimport { exportFromFile } from \"./core/export-html/index.js\";\nimport type { LoadExtensionsResult } from \"./core/extensions/index.js\";\nimport { KeybindingsManager } from \"./core/keybindings.js\";\nimport { ModelRegistry } from \"./core/model-registry.js\";\nimport { globalMultiGPUExecutor } from \"./core/multi-gpu-executor.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { DefaultResourceLoader } from \"./core/resource-loader.js\";\nimport { type CreateAgentSessionOptions, createAgentSession } from \"./core/sdk.js\";\nimport { SessionManager } from \"./core/session-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { printTimings, time } from \"./core/timings.js\";\nimport { allTools } from \"./core/tools/index.js\";\nimport { runMigrations, showDeprecationWarnings } from \"./migrations.js\";\nimport { InteractiveMode, runPrintMode, runRpcMode } from \"./modes/index.js\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.js\";\nimport { checkForUpdates } from \"./utils/version-check.js\";\n\nfunction debugLog(stage: string, message: string, data?: any) {\n\tconst logLine = `[${new Date().toISOString()}] [${stage}] ${message}${data ? `: ${JSON.stringify(data)}` : \"\"}\\n`;\n\tfs.appendFileSync(\"debug.log\", logLine);\n}\nasync function readPipedStdin(): Promise<string | undefined> {\n\tif (process.stdin.isTTY) {\n\t\treturn undefined;\n\t}\n\treturn new Promise((resolve) => {\n\t\tlet data = \"\";\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\t\tprocess.stdin.on(\"end\", () => {\n\t\t\tresolve(data.trim() || undefined);\n\t\t});\n\t\tprocess.stdin.resume();\n\t});\n}\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\nfunction isTruthyEnvFlag(value: string | undefined): boolean {\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\ntype PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tlocal: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n}\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\nInstall a package and add it to settings.\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https:\n ${APP_NAME} install ssh:\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\nRemove a package and its source from settings.\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\nExample:\n ${APP_NAME} remove npm:@foo/bar\n`);\n\t\t\treturn;\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\nUpdate installed packages.\nIf <source> is provided, only that package is updated.\n`);\n\t\t\treturn;\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [command, ...rest] = args;\n\tif (command !== \"install\" && command !== \"remove\" && command !== \"update\" && command !== \"list\") {\n\t\treturn undefined;\n\t}\n\tlet local = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet source: string | undefined;\n\tfor (const arg of rest) {\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t}\n\t}\n\treturn { command, source, local, help, invalidOption };\n}\nasync function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.install(source!, { local: options.local });\n\t\t\t\tpackageManager.addSourceToSettings(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\t\t\tcase \"remove\": {\n\t\t\t\tawait packageManager.remove(source!, { local: options.local });\n\t\t\t\tconst removed = packageManager.removeSourceFromSettings(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"list\": {\n\t\t\t\tconst globalSettings = settingsManager.getGlobalSettings();\n\t\t\t\tconst projectSettings = settingsManager.getProjectSettings();\n\t\t\t\tconst globalPackages = globalSettings.packages ?? [];\n\t\t\t\tconst projectPackages = projectSettings.packages ?? [];\n\t\t\t\tif (globalPackages.length === 0 && projectPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst formatPackage = (pkg: (typeof globalPackages)[number], scope: \"user\" | \"project\") => {\n\t\t\t\t\tconst source = typeof pkg === \"string\" ? pkg : pkg.source;\n\t\t\t\t\tconst filtered = typeof pkg === \"object\";\n\t\t\t\t\tconst display = filtered ? `${source} (filtered)` : source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tconst path = packageManager.getInstalledPath(source, scope);\n\t\t\t\t\tif (path) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${path}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tif (globalPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of globalPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"user\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (globalPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"project\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"update\":\n\t\t\t\tawait packageManager.update(source);\n\t\t\t\tif (source) {\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${source}`));\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\nasync function prepareInitialMessage(\n\tparsed: Args,\n\tautoResizeImages: boolean,\n): Promise<{\n\tinitialMessage?: string;\n\tinitialImages?: ImageContent[];\n}> {\n\tif (parsed.fileArgs.length === 0) {\n\t\treturn {};\n\t}\n\tconst { text, images } = await processFileArguments(parsed.fileArgs, { autoResizeImages });\n\tlet initialMessage: string;\n\tif (parsed.messages.length > 0) {\n\t\tinitialMessage = text + parsed.messages[0];\n\t\tparsed.messages.shift();\n\t} else {\n\t\tinitialMessage = text;\n\t}\n\treturn {\n\t\tinitialMessage,\n\t\tinitialImages: images.length > 0 ? images : undefined,\n\t};\n}\ntype ResolvedSession =\n\t| { type: \"path\"; path: string }\n\t| { type: \"local\"; path: string }\n\t| { type: \"global\"; path: string; cwd: string }\n\t| { type: \"not_found\"; arg: string };\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: sessionArg };\n\t}\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatches = localSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (localMatches.length >= 1) {\n\t\treturn { type: \"local\", path: localMatches[0].path };\n\t}\n\tconst allSessions = await SessionManager.listAll();\n\tconst globalMatches = allSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (globalMatches.length >= 1) {\n\t\tconst match = globalMatches[0];\n\t\treturn { type: \"global\", path: match.path, cwd: match.cwd };\n\t}\n\treturn { type: \"not_found\", arg: sessionArg };\n}\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\nasync function callSessionDirectoryHook(extensions: LoadExtensionsResult, cwd: string): Promise<string | undefined> {\n\tlet customSessionDir: string | undefined;\n\tfor (const ext of extensions.extensions) {\n\t\tconst handlers = ext.handlers.get(\"session_directory\");\n\t\tif (!handlers || handlers.length === 0) continue;\n\t\tfor (const handler of handlers) {\n\t\t\ttry {\n\t\t\t\tconst event = { type: \"session_directory\" as const, cwd };\n\t\t\t\tconst result = (await handler(event)) as { sessionDir?: string } | undefined;\n\t\t\t\tif (result?.sessionDir) {\n\t\t\t\t\tcustomSessionDir = result.sessionDir;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\tconsole.error(chalk.red(`Extension \"${ext.path}\" session_directory handler failed: ${message}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn customSessionDir;\n}\nasync function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\textensions: LoadExtensionsResult,\n): Promise<SessionManager | undefined> {\n\tif (parsed.noSession) {\n\t\treturn SessionManager.inMemory();\n\t}\n\tlet effectiveSessionDir = parsed.sessionDir;\n\tif (!effectiveSessionDir) {\n\t\teffectiveSessionDir = await callSessionDirectoryHook(extensions, cwd);\n\t}\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, effectiveSessionDir);\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn SessionManager.open(resolved.path, effectiveSessionDir);\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn SessionManager.forkFrom(resolved.path, cwd, effectiveSessionDir);\n\t\t\t}\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, effectiveSessionDir);\n\t}\n\tif (effectiveSessionDir) {\n\t\treturn SessionManager.create(cwd, effectiveSessionDir);\n\t}\n\treturn undefined;\n}\nfunction buildSessionOptions(\n\tparsed: Args,\n\tsessionManager: SessionManager | undefined,\n\t_modelRegistry: ModelRegistry,\n\t_settingsManager: SettingsManager,\n): { options: CreateAgentSessionOptions; cliThinkingFromModel: boolean } {\n\tconst options: CreateAgentSessionOptions = {};\n\tconst cliThinkingFromModel = false;\n\tif (sessionManager) {\n\t\toptions.sessionManager = sessionManager;\n\t}\n\tif (parsed.thinking) {\n\t\toptions.thinkingLevel = parsed.thinking;\n\t}\n\tif (parsed.noTools) {\n\t\tif (parsed.tools && parsed.tools.length > 0) {\n\t\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t\t} else {\n\t\t\toptions.tools = [];\n\t\t}\n\t} else if (parsed.tools) {\n\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t}\n\treturn { options, cliThinkingFromModel };\n}\nasync function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\tprocess.exit(0);\n}\nasync function processFilesInParallel(\n\tfileArgs: string[],\n\tautoResizeImages: boolean,\n): Promise<{ text: string; images: ImageContent[] }> {\n\tconst chunkSize = globalMultiGPUExecutor ? Math.ceil(fileArgs.length / 4) : fileArgs.length;\n\tconst chunks: string[][] = [];\n\tfor (let i = 0; i < fileArgs.length; i += chunkSize) {\n\t\tchunks.push(fileArgs.slice(i, i + chunkSize));\n\t}\n\tconst results = await Promise.all(chunks.map((chunk) => processFileArguments(chunk, { autoResizeImages })));\n\tconst text = results.map((r) => r.text).join(\"\");\n\tconst images = results.flatMap((r) => r.images);\n\treturn { text, images };\n}\nexport async function main(args: string[]) {\n\tdebugLog(\"main\", \"Starting main\", { args, pid: process.pid, platform: process.platform });\n\ttry {\n\t\tconst offlineMode = args.includes(\"--offline\") || isTruthyEnvFlag(process.env.PI_OFFLINE);\n\t\tif (offlineMode) {\n\t\t\tprocess.env.PI_OFFLINE = \"1\";\n\t\t\tprocess.env.PI_SKIP_VERSION_CHECK = \"1\";\n\t\t}\n\t\t// Check for updates (async, non-blocking)\n\t\tif (!process.env.PI_SKIP_VERSION_CHECK) {\n\t\t\tcheckForUpdates().catch(() => {});\n\t\t}\n\t\tif (await handlePackageCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tif (await handleConfigCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tdebugLog(\"main\", \"Running migrations\");\n\t\tconst { deprecationWarnings } = runMigrations(process.cwd());\n\t\tdebugLog(\"main\", \"Parsing args\");\n\t\tconst firstPass = parseArgs(args);\n\t\tdebugLog(\"main\", \"Initializing components\");\n\t\tconst cwd = process.cwd();\n\t\tconst agentDir = getAgentDir();\n\t\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\t\treportSettingsErrors(settingsManager, \"startup\");\n\t\tconst authStorage = AuthStorage.create();\n\t\tconst modelRegistry = new ModelRegistry(authStorage, getModelsPath());\n\t\tdebugLog(\"main\", \"Creating resource loader\");\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalExtensionPaths: firstPass.extensions,\n\t\t\tadditionalSkillPaths: firstPass.skills,\n\t\t\tadditionalPromptTemplatePaths: firstPass.promptTemplates,\n\t\t\tadditionalThemePaths: firstPass.themes,\n\t\t\tnoExtensions: firstPass.noExtensions,\n\t\t\tnoSkills: firstPass.noSkills,\n\t\t\tnoPromptTemplates: firstPass.noPromptTemplates,\n\t\t\tnoThemes: firstPass.noThemes,\n\t\t\tsystemPrompt: firstPass.systemPrompt,\n\t\t\tappendSystemPrompt: firstPass.appendSystemPrompt,\n\t\t});\n\t\tdebugLog(\"main\", \"Reloading resources\");\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t\tdebugLog(\"main\", \"Loading extensions\");\n\t\tconst extensionsResult: LoadExtensionsResult = resourceLoader.getExtensions();\n\t\tfor (const { path, error } of extensionsResult.errors) {\n\t\t\tconsole.error(chalk.red(`Failed to load extension \"${path}\": ${error}`));\n\t\t}\n\t\t// Provider registration removed - models are configured during onboarding only\n\t\tconst extensionFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\t\tfor (const ext of extensionsResult.extensions) {\n\t\t\tfor (const [name, flag] of ext.flags) {\n\t\t\t\textensionFlags.set(name, { type: flag.type });\n\t\t\t}\n\t\t}\n\t\tconst parsed = parseArgs(args, extensionFlags);\n\t\tfor (const [name, value] of parsed.unknownFlags) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t}\n\t\tif (parsed.version) {\n\t\t\tconsole.log(VERSION);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.help) {\n\t\t\tprintHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.listModels !== undefined) {\n\t\t\tconst searchPattern = typeof parsed.listModels === \"string\" ? parsed.listModels : undefined;\n\t\t\tawait listModels(modelRegistry, searchPattern);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode !== \"rpc\") {\n\t\t\tconst stdinContent = await readPipedStdin();\n\t\t\tif (stdinContent !== undefined) {\n\t\t\t\tparsed.print = true;\n\t\t\t\tparsed.messages.unshift(stdinContent);\n\t\t\t}\n\t\t}\n\t\tif (parsed.export) {\n\t\t\tlet result: string;\n\t\t\ttry {\n\t\t\t\tconst outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;\n\t\t\t\tresult = await exportFromFile(parsed.export, outputPath);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Failed to export session\";\n\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.log(`Exported to: ${result}`);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode === \"rpc\" && parsed.fileArgs.length > 0) {\n\t\t\tconsole.error(chalk.red(\"Error: @file arguments are not supported in RPC mode\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tlet initialMessage: string | undefined;\n\t\tlet initialImages: ImageContent[] | undefined;\n\t\tif (parsed.fileArgs.length > 0 && parsed.fileArgs.length > 4) {\n\t\t\tconst result = await processFilesInParallel(parsed.fileArgs, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.text;\n\t\t\tinitialImages = result.images.length > 0 ? result.images : undefined;\n\t\t\tif (parsed.messages.length > 0) {\n\t\t\t\tinitialMessage = initialMessage + parsed.messages[0];\n\t\t\t\tparsed.messages.shift();\n\t\t\t}\n\t\t} else {\n\t\t\tconst result = await prepareInitialMessage(parsed, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.initialMessage;\n\t\t\tinitialImages = result.initialImages;\n\t\t}\n\t\tconst isInteractive = !parsed.print && parsed.mode === undefined;\n\t\tconst mode = parsed.mode || \"text\";\n\t\tinitTheme(settingsManager.getTheme(), isInteractive);\n\t\tif (isInteractive && deprecationWarnings.length > 0) {\n\t\t\tawait showDeprecationWarnings(deprecationWarnings);\n\t\t}\n\t\tlet sessionManager = await createSessionManager(parsed, cwd, extensionsResult);\n\t\tif (parsed.resume) {\n\t\t\tKeybindingsManager.create();\n\t\t\tconst effectiveSessionDir = parsed.sessionDir || (await callSessionDirectoryHook(extensionsResult, cwd));\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, effectiveSessionDir, onProgress),\n\t\t\t\tSessionManager.listAll,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tsessionManager = SessionManager.open(selectedPath, effectiveSessionDir);\n\t\t}\n\t\tconst { options: sessionOptions, cliThinkingFromModel } = buildSessionOptions(\n\t\t\tparsed,\n\t\t\tsessionManager,\n\t\t\tmodelRegistry,\n\t\t\tsettingsManager,\n\t\t);\n\t\tsessionOptions.authStorage = authStorage;\n\t\tsessionOptions.modelRegistry = modelRegistry;\n\t\tsessionOptions.resourceLoader = resourceLoader;\n\t\tif (parsed.apiKey) {\n\t\t\tconsole.error(chalk.red(\"--api-key is deprecated. Please configure your API key during onboarding.\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst { session } = await createAgentSession(sessionOptions);\n\t\tif (!isInteractive && !session.model) {\n\t\t\tconsole.error(chalk.red(\"No model configured.\"));\n\t\t\tconsole.error(chalk.yellow(\"\\nPlease run onboarding to configure your model:\"));\n\t\t\tconsole.error(\" openvibe --onboarding\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst cliThinkingOverride = parsed.thinking !== undefined || cliThinkingFromModel;\n\t\tif (session.model && cliThinkingOverride) {\n\t\t\tlet effectiveThinking = session.thinkingLevel;\n\t\t\tif (!session.model.reasoning) {\n\t\t\t\teffectiveThinking = \"off\";\n\t\t\t} else if (effectiveThinking === \"xhigh\" && !supportsXhigh(session.model)) {\n\t\t\t\teffectiveThinking = \"high\";\n\t\t\t}\n\t\t\tif (effectiveThinking !== session.thinkingLevel) {\n\t\t\t\tsession.setThinkingLevel(effectiveThinking);\n\t\t\t}\n\t\t}\n\t\tdebugLog(\"main\", \"Selecting run mode\", { mode, isInteractive });\n\t\tif (mode === \"rpc\") {\n\t\t\tdebugLog(\"main\", \"Running RPC mode\");\n\t\t\tawait runRpcMode(session);\n\t\t} else if (isInteractive) {\n\t\t\tdebugLog(\"main\", \"Running interactive mode\");\n\t\t\tprintTimings();\n\t\t\tconst mode = new InteractiveMode(session, {\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t\tinitialMessages: parsed.messages,\n\t\t\t\tverbose: parsed.verbose,\n\t\t\t});\n\t\t\tawait mode.run();\n\t\t} else {\n\t\t\tdebugLog(\"main\", \"Running print mode\");\n\t\t\tawait runPrintMode(session, {\n\t\t\t\tmode,\n\t\t\t\tmessages: parsed.messages,\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t});\n\t\t\tstopThemeWatcher();\n\t\t\tif (process.stdout.writableLength > 0) {\n\t\t\t\tawait new Promise<void>((resolve) => process.stdout.once(\"drain\", resolve));\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tdebugLog(\"main\", \"Main completed successfully\");\n\t} catch (error) {\n\t\tdebugLog(\"main\", \"Main crashed\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t\tconsole.error(chalk.red(\"\\n[CRASH] Application crashed:\"));\n\t\tconsole.error(error);\n\t\tfs.appendFileSync(\n\t\t\t\"crash.log\",\n\t\t\t`[${new Date().toISOString()}] Main Crash:\\n${error instanceof Error ? error.stack : String(error)}\\n\\n`,\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n"]}
|
package/dist/main.js
CHANGED
|
@@ -23,6 +23,7 @@ import { allTools } from "./core/tools/index.js";
|
|
|
23
23
|
import { runMigrations, showDeprecationWarnings } from "./migrations.js";
|
|
24
24
|
import { InteractiveMode, runPrintMode, runRpcMode } from "./modes/index.js";
|
|
25
25
|
import { initTheme, stopThemeWatcher } from "./modes/interactive/theme/theme.js";
|
|
26
|
+
import { checkForUpdates } from "./utils/version-check.js";
|
|
26
27
|
function debugLog(stage, message, data) {
|
|
27
28
|
const logLine = `[${new Date().toISOString()}] [${stage}] ${message}${data ? `: ${JSON.stringify(data)}` : ""}\n`;
|
|
28
29
|
fs.appendFileSync("debug.log", logLine);
|
|
@@ -411,6 +412,10 @@ export async function main(args) {
|
|
|
411
412
|
process.env.PI_OFFLINE = "1";
|
|
412
413
|
process.env.PI_SKIP_VERSION_CHECK = "1";
|
|
413
414
|
}
|
|
415
|
+
// Check for updates (async, non-blocking)
|
|
416
|
+
if (!process.env.PI_SKIP_VERSION_CHECK) {
|
|
417
|
+
checkForUpdates().catch(() => { });
|
|
418
|
+
}
|
|
414
419
|
if (await handlePackageCommand(args)) {
|
|
415
420
|
return;
|
|
416
421
|
}
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-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I,OAAO,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;gBACvC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAC7E,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;QACD,QAAQ,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE;YAChC,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACvD,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,EAAE,CAAC,cAAc,CAChB,WAAW,EACX,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CACxG,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;AAAA,CACD","sourcesContent":["import { type ImageContent, supportsXhigh } from \"@boxiaolanya2008/pi-ai\";\nimport chalk from \"chalk\";\nimport fs from \"fs\";\nimport { createInterface } from \"readline\";\nimport { type Args, parseArgs, printHelp } from \"./cli/args.js\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport { processFileArguments } from \"./cli/file-processor.js\";\nimport { listModels } from \"./cli/list-models.js\";\nimport { selectSession } from \"./cli/session-picker.js\";\nimport { APP_NAME, getAgentDir, getModelsPath, VERSION } from \"./config.js\";\nimport { AuthStorage } from \"./core/auth-storage.js\";\nimport { exportFromFile } from \"./core/export-html/index.js\";\nimport type { LoadExtensionsResult } from \"./core/extensions/index.js\";\nimport { KeybindingsManager } from \"./core/keybindings.js\";\nimport { ModelRegistry } from \"./core/model-registry.js\";\nimport { globalMultiGPUExecutor } from \"./core/multi-gpu-executor.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { DefaultResourceLoader } from \"./core/resource-loader.js\";\nimport { type CreateAgentSessionOptions, createAgentSession } from \"./core/sdk.js\";\nimport { SessionManager } from \"./core/session-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { printTimings, time } from \"./core/timings.js\";\nimport { allTools } from \"./core/tools/index.js\";\nimport { runMigrations, showDeprecationWarnings } from \"./migrations.js\";\nimport { InteractiveMode, runPrintMode, runRpcMode } from \"./modes/index.js\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.js\";\n\nfunction debugLog(stage: string, message: string, data?: any) {\n\tconst logLine = `[${new Date().toISOString()}] [${stage}] ${message}${data ? `: ${JSON.stringify(data)}` : \"\"}\\n`;\n\tfs.appendFileSync(\"debug.log\", logLine);\n}\nasync function readPipedStdin(): Promise<string | undefined> {\n\tif (process.stdin.isTTY) {\n\t\treturn undefined;\n\t}\n\treturn new Promise((resolve) => {\n\t\tlet data = \"\";\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\t\tprocess.stdin.on(\"end\", () => {\n\t\t\tresolve(data.trim() || undefined);\n\t\t});\n\t\tprocess.stdin.resume();\n\t});\n}\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\nfunction isTruthyEnvFlag(value: string | undefined): boolean {\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\ntype PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tlocal: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n}\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\nInstall a package and add it to settings.\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https:\n ${APP_NAME} install ssh:\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\nRemove a package and its source from settings.\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\nExample:\n ${APP_NAME} remove npm:@foo/bar\n`);\n\t\t\treturn;\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\nUpdate installed packages.\nIf <source> is provided, only that package is updated.\n`);\n\t\t\treturn;\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [command, ...rest] = args;\n\tif (command !== \"install\" && command !== \"remove\" && command !== \"update\" && command !== \"list\") {\n\t\treturn undefined;\n\t}\n\tlet local = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet source: string | undefined;\n\tfor (const arg of rest) {\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t}\n\t}\n\treturn { command, source, local, help, invalidOption };\n}\nasync function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.install(source!, { local: options.local });\n\t\t\t\tpackageManager.addSourceToSettings(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\t\t\tcase \"remove\": {\n\t\t\t\tawait packageManager.remove(source!, { local: options.local });\n\t\t\t\tconst removed = packageManager.removeSourceFromSettings(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"list\": {\n\t\t\t\tconst globalSettings = settingsManager.getGlobalSettings();\n\t\t\t\tconst projectSettings = settingsManager.getProjectSettings();\n\t\t\t\tconst globalPackages = globalSettings.packages ?? [];\n\t\t\t\tconst projectPackages = projectSettings.packages ?? [];\n\t\t\t\tif (globalPackages.length === 0 && projectPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst formatPackage = (pkg: (typeof globalPackages)[number], scope: \"user\" | \"project\") => {\n\t\t\t\t\tconst source = typeof pkg === \"string\" ? pkg : pkg.source;\n\t\t\t\t\tconst filtered = typeof pkg === \"object\";\n\t\t\t\t\tconst display = filtered ? `${source} (filtered)` : source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tconst path = packageManager.getInstalledPath(source, scope);\n\t\t\t\t\tif (path) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${path}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tif (globalPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of globalPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"user\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (globalPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"project\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"update\":\n\t\t\t\tawait packageManager.update(source);\n\t\t\t\tif (source) {\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${source}`));\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\nasync function prepareInitialMessage(\n\tparsed: Args,\n\tautoResizeImages: boolean,\n): Promise<{\n\tinitialMessage?: string;\n\tinitialImages?: ImageContent[];\n}> {\n\tif (parsed.fileArgs.length === 0) {\n\t\treturn {};\n\t}\n\tconst { text, images } = await processFileArguments(parsed.fileArgs, { autoResizeImages });\n\tlet initialMessage: string;\n\tif (parsed.messages.length > 0) {\n\t\tinitialMessage = text + parsed.messages[0];\n\t\tparsed.messages.shift();\n\t} else {\n\t\tinitialMessage = text;\n\t}\n\treturn {\n\t\tinitialMessage,\n\t\tinitialImages: images.length > 0 ? images : undefined,\n\t};\n}\ntype ResolvedSession =\n\t| { type: \"path\"; path: string }\n\t| { type: \"local\"; path: string }\n\t| { type: \"global\"; path: string; cwd: string }\n\t| { type: \"not_found\"; arg: string };\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: sessionArg };\n\t}\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatches = localSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (localMatches.length >= 1) {\n\t\treturn { type: \"local\", path: localMatches[0].path };\n\t}\n\tconst allSessions = await SessionManager.listAll();\n\tconst globalMatches = allSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (globalMatches.length >= 1) {\n\t\tconst match = globalMatches[0];\n\t\treturn { type: \"global\", path: match.path, cwd: match.cwd };\n\t}\n\treturn { type: \"not_found\", arg: sessionArg };\n}\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\nasync function callSessionDirectoryHook(extensions: LoadExtensionsResult, cwd: string): Promise<string | undefined> {\n\tlet customSessionDir: string | undefined;\n\tfor (const ext of extensions.extensions) {\n\t\tconst handlers = ext.handlers.get(\"session_directory\");\n\t\tif (!handlers || handlers.length === 0) continue;\n\t\tfor (const handler of handlers) {\n\t\t\ttry {\n\t\t\t\tconst event = { type: \"session_directory\" as const, cwd };\n\t\t\t\tconst result = (await handler(event)) as { sessionDir?: string } | undefined;\n\t\t\t\tif (result?.sessionDir) {\n\t\t\t\t\tcustomSessionDir = result.sessionDir;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\tconsole.error(chalk.red(`Extension \"${ext.path}\" session_directory handler failed: ${message}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn customSessionDir;\n}\nasync function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\textensions: LoadExtensionsResult,\n): Promise<SessionManager | undefined> {\n\tif (parsed.noSession) {\n\t\treturn SessionManager.inMemory();\n\t}\n\tlet effectiveSessionDir = parsed.sessionDir;\n\tif (!effectiveSessionDir) {\n\t\teffectiveSessionDir = await callSessionDirectoryHook(extensions, cwd);\n\t}\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, effectiveSessionDir);\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn SessionManager.open(resolved.path, effectiveSessionDir);\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn SessionManager.forkFrom(resolved.path, cwd, effectiveSessionDir);\n\t\t\t}\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, effectiveSessionDir);\n\t}\n\tif (effectiveSessionDir) {\n\t\treturn SessionManager.create(cwd, effectiveSessionDir);\n\t}\n\treturn undefined;\n}\nfunction buildSessionOptions(\n\tparsed: Args,\n\tsessionManager: SessionManager | undefined,\n\t_modelRegistry: ModelRegistry,\n\t_settingsManager: SettingsManager,\n): { options: CreateAgentSessionOptions; cliThinkingFromModel: boolean } {\n\tconst options: CreateAgentSessionOptions = {};\n\tconst cliThinkingFromModel = false;\n\tif (sessionManager) {\n\t\toptions.sessionManager = sessionManager;\n\t}\n\tif (parsed.thinking) {\n\t\toptions.thinkingLevel = parsed.thinking;\n\t}\n\tif (parsed.noTools) {\n\t\tif (parsed.tools && parsed.tools.length > 0) {\n\t\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t\t} else {\n\t\t\toptions.tools = [];\n\t\t}\n\t} else if (parsed.tools) {\n\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t}\n\treturn { options, cliThinkingFromModel };\n}\nasync function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\tprocess.exit(0);\n}\nasync function processFilesInParallel(\n\tfileArgs: string[],\n\tautoResizeImages: boolean,\n): Promise<{ text: string; images: ImageContent[] }> {\n\tconst chunkSize = globalMultiGPUExecutor ? Math.ceil(fileArgs.length / 4) : fileArgs.length;\n\tconst chunks: string[][] = [];\n\tfor (let i = 0; i < fileArgs.length; i += chunkSize) {\n\t\tchunks.push(fileArgs.slice(i, i + chunkSize));\n\t}\n\tconst results = await Promise.all(chunks.map((chunk) => processFileArguments(chunk, { autoResizeImages })));\n\tconst text = results.map((r) => r.text).join(\"\");\n\tconst images = results.flatMap((r) => r.images);\n\treturn { text, images };\n}\nexport async function main(args: string[]) {\n\tdebugLog(\"main\", \"Starting main\", { args, pid: process.pid, platform: process.platform });\n\ttry {\n\t\tconst offlineMode = args.includes(\"--offline\") || isTruthyEnvFlag(process.env.PI_OFFLINE);\n\t\tif (offlineMode) {\n\t\t\tprocess.env.PI_OFFLINE = \"1\";\n\t\t\tprocess.env.PI_SKIP_VERSION_CHECK = \"1\";\n\t\t}\n\t\tif (await handlePackageCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tif (await handleConfigCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tdebugLog(\"main\", \"Running migrations\");\n\t\tconst { deprecationWarnings } = runMigrations(process.cwd());\n\t\tdebugLog(\"main\", \"Parsing args\");\n\t\tconst firstPass = parseArgs(args);\n\t\tdebugLog(\"main\", \"Initializing components\");\n\t\tconst cwd = process.cwd();\n\t\tconst agentDir = getAgentDir();\n\t\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\t\treportSettingsErrors(settingsManager, \"startup\");\n\t\tconst authStorage = AuthStorage.create();\n\t\tconst modelRegistry = new ModelRegistry(authStorage, getModelsPath());\n\t\tdebugLog(\"main\", \"Creating resource loader\");\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalExtensionPaths: firstPass.extensions,\n\t\t\tadditionalSkillPaths: firstPass.skills,\n\t\t\tadditionalPromptTemplatePaths: firstPass.promptTemplates,\n\t\t\tadditionalThemePaths: firstPass.themes,\n\t\t\tnoExtensions: firstPass.noExtensions,\n\t\t\tnoSkills: firstPass.noSkills,\n\t\t\tnoPromptTemplates: firstPass.noPromptTemplates,\n\t\t\tnoThemes: firstPass.noThemes,\n\t\t\tsystemPrompt: firstPass.systemPrompt,\n\t\t\tappendSystemPrompt: firstPass.appendSystemPrompt,\n\t\t});\n\t\tdebugLog(\"main\", \"Reloading resources\");\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t\tdebugLog(\"main\", \"Loading extensions\");\n\t\tconst extensionsResult: LoadExtensionsResult = resourceLoader.getExtensions();\n\t\tfor (const { path, error } of extensionsResult.errors) {\n\t\t\tconsole.error(chalk.red(`Failed to load extension \"${path}\": ${error}`));\n\t\t}\n\t\t// Provider registration removed - models are configured during onboarding only\n\t\tconst extensionFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\t\tfor (const ext of extensionsResult.extensions) {\n\t\t\tfor (const [name, flag] of ext.flags) {\n\t\t\t\textensionFlags.set(name, { type: flag.type });\n\t\t\t}\n\t\t}\n\t\tconst parsed = parseArgs(args, extensionFlags);\n\t\tfor (const [name, value] of parsed.unknownFlags) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t}\n\t\tif (parsed.version) {\n\t\t\tconsole.log(VERSION);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.help) {\n\t\t\tprintHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.listModels !== undefined) {\n\t\t\tconst searchPattern = typeof parsed.listModels === \"string\" ? parsed.listModels : undefined;\n\t\t\tawait listModels(modelRegistry, searchPattern);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode !== \"rpc\") {\n\t\t\tconst stdinContent = await readPipedStdin();\n\t\t\tif (stdinContent !== undefined) {\n\t\t\t\tparsed.print = true;\n\t\t\t\tparsed.messages.unshift(stdinContent);\n\t\t\t}\n\t\t}\n\t\tif (parsed.export) {\n\t\t\tlet result: string;\n\t\t\ttry {\n\t\t\t\tconst outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;\n\t\t\t\tresult = await exportFromFile(parsed.export, outputPath);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Failed to export session\";\n\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.log(`Exported to: ${result}`);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode === \"rpc\" && parsed.fileArgs.length > 0) {\n\t\t\tconsole.error(chalk.red(\"Error: @file arguments are not supported in RPC mode\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tlet initialMessage: string | undefined;\n\t\tlet initialImages: ImageContent[] | undefined;\n\t\tif (parsed.fileArgs.length > 0 && parsed.fileArgs.length > 4) {\n\t\t\tconst result = await processFilesInParallel(parsed.fileArgs, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.text;\n\t\t\tinitialImages = result.images.length > 0 ? result.images : undefined;\n\t\t\tif (parsed.messages.length > 0) {\n\t\t\t\tinitialMessage = initialMessage + parsed.messages[0];\n\t\t\t\tparsed.messages.shift();\n\t\t\t}\n\t\t} else {\n\t\t\tconst result = await prepareInitialMessage(parsed, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.initialMessage;\n\t\t\tinitialImages = result.initialImages;\n\t\t}\n\t\tconst isInteractive = !parsed.print && parsed.mode === undefined;\n\t\tconst mode = parsed.mode || \"text\";\n\t\tinitTheme(settingsManager.getTheme(), isInteractive);\n\t\tif (isInteractive && deprecationWarnings.length > 0) {\n\t\t\tawait showDeprecationWarnings(deprecationWarnings);\n\t\t}\n\t\tlet sessionManager = await createSessionManager(parsed, cwd, extensionsResult);\n\t\tif (parsed.resume) {\n\t\t\tKeybindingsManager.create();\n\t\t\tconst effectiveSessionDir = parsed.sessionDir || (await callSessionDirectoryHook(extensionsResult, cwd));\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, effectiveSessionDir, onProgress),\n\t\t\t\tSessionManager.listAll,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tsessionManager = SessionManager.open(selectedPath, effectiveSessionDir);\n\t\t}\n\t\tconst { options: sessionOptions, cliThinkingFromModel } = buildSessionOptions(\n\t\t\tparsed,\n\t\t\tsessionManager,\n\t\t\tmodelRegistry,\n\t\t\tsettingsManager,\n\t\t);\n\t\tsessionOptions.authStorage = authStorage;\n\t\tsessionOptions.modelRegistry = modelRegistry;\n\t\tsessionOptions.resourceLoader = resourceLoader;\n\t\tif (parsed.apiKey) {\n\t\t\tconsole.error(chalk.red(\"--api-key is deprecated. Please configure your API key during onboarding.\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst { session } = await createAgentSession(sessionOptions);\n\t\tif (!isInteractive && !session.model) {\n\t\t\tconsole.error(chalk.red(\"No model configured.\"));\n\t\t\tconsole.error(chalk.yellow(\"\\nPlease run onboarding to configure your model:\"));\n\t\t\tconsole.error(\" openvibe --onboarding\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst cliThinkingOverride = parsed.thinking !== undefined || cliThinkingFromModel;\n\t\tif (session.model && cliThinkingOverride) {\n\t\t\tlet effectiveThinking = session.thinkingLevel;\n\t\t\tif (!session.model.reasoning) {\n\t\t\t\teffectiveThinking = \"off\";\n\t\t\t} else if (effectiveThinking === \"xhigh\" && !supportsXhigh(session.model)) {\n\t\t\t\teffectiveThinking = \"high\";\n\t\t\t}\n\t\t\tif (effectiveThinking !== session.thinkingLevel) {\n\t\t\t\tsession.setThinkingLevel(effectiveThinking);\n\t\t\t}\n\t\t}\n\t\tdebugLog(\"main\", \"Selecting run mode\", { mode, isInteractive });\n\t\tif (mode === \"rpc\") {\n\t\t\tdebugLog(\"main\", \"Running RPC mode\");\n\t\t\tawait runRpcMode(session);\n\t\t} else if (isInteractive) {\n\t\t\tdebugLog(\"main\", \"Running interactive mode\");\n\t\t\tprintTimings();\n\t\t\tconst mode = new InteractiveMode(session, {\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t\tinitialMessages: parsed.messages,\n\t\t\t\tverbose: parsed.verbose,\n\t\t\t});\n\t\t\tawait mode.run();\n\t\t} else {\n\t\t\tdebugLog(\"main\", \"Running print mode\");\n\t\t\tawait runPrintMode(session, {\n\t\t\t\tmode,\n\t\t\t\tmessages: parsed.messages,\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t});\n\t\t\tstopThemeWatcher();\n\t\t\tif (process.stdout.writableLength > 0) {\n\t\t\t\tawait new Promise<void>((resolve) => process.stdout.once(\"drain\", resolve));\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tdebugLog(\"main\", \"Main completed successfully\");\n\t} catch (error) {\n\t\tdebugLog(\"main\", \"Main crashed\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t\tconsole.error(chalk.red(\"\\n[CRASH] Application crashed:\"));\n\t\tconsole.error(error);\n\t\tfs.appendFileSync(\n\t\t\t\"crash.log\",\n\t\t\t`[${new Date().toISOString()}] Main Crash:\\n${error instanceof Error ? error.stack : String(error)}\\n\\n`,\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAa,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAA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C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACvD,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,EAAE,CAAC,cAAc,CAChB,WAAW,EACX,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CACxG,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;AAAA,CACD","sourcesContent":["import { type ImageContent, supportsXhigh } from \"@boxiaolanya2008/pi-ai\";\nimport chalk from \"chalk\";\nimport fs from \"fs\";\nimport { createInterface } from \"readline\";\nimport { type Args, parseArgs, printHelp } from \"./cli/args.js\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport { processFileArguments } from \"./cli/file-processor.js\";\nimport { listModels } from \"./cli/list-models.js\";\nimport { selectSession } from \"./cli/session-picker.js\";\nimport { APP_NAME, getAgentDir, getModelsPath, VERSION } from \"./config.js\";\nimport { AuthStorage } from \"./core/auth-storage.js\";\nimport { exportFromFile } from \"./core/export-html/index.js\";\nimport type { LoadExtensionsResult } from \"./core/extensions/index.js\";\nimport { KeybindingsManager } from \"./core/keybindings.js\";\nimport { ModelRegistry } from \"./core/model-registry.js\";\nimport { globalMultiGPUExecutor } from \"./core/multi-gpu-executor.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { DefaultResourceLoader } from \"./core/resource-loader.js\";\nimport { type CreateAgentSessionOptions, createAgentSession } from \"./core/sdk.js\";\nimport { SessionManager } from \"./core/session-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { printTimings, time } from \"./core/timings.js\";\nimport { allTools } from \"./core/tools/index.js\";\nimport { runMigrations, showDeprecationWarnings } from \"./migrations.js\";\nimport { InteractiveMode, runPrintMode, runRpcMode } from \"./modes/index.js\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.js\";\nimport { checkForUpdates } from \"./utils/version-check.js\";\n\nfunction debugLog(stage: string, message: string, data?: any) {\n\tconst logLine = `[${new Date().toISOString()}] [${stage}] ${message}${data ? `: ${JSON.stringify(data)}` : \"\"}\\n`;\n\tfs.appendFileSync(\"debug.log\", logLine);\n}\nasync function readPipedStdin(): Promise<string | undefined> {\n\tif (process.stdin.isTTY) {\n\t\treturn undefined;\n\t}\n\treturn new Promise((resolve) => {\n\t\tlet data = \"\";\n\t\tprocess.stdin.setEncoding(\"utf8\");\n\t\tprocess.stdin.on(\"data\", (chunk) => {\n\t\t\tdata += chunk;\n\t\t});\n\t\tprocess.stdin.on(\"end\", () => {\n\t\t\tresolve(data.trim() || undefined);\n\t\t});\n\t\tprocess.stdin.resume();\n\t});\n}\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\nfunction isTruthyEnvFlag(value: string | undefined): boolean {\n\tif (!value) return false;\n\treturn value === \"1\" || value.toLowerCase() === \"true\" || value.toLowerCase() === \"yes\";\n}\ntype PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tlocal: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n}\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\nInstall a package and add it to settings.\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https:\n ${APP_NAME} install ssh:\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\nRemove a package and its source from settings.\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\nExample:\n ${APP_NAME} remove npm:@foo/bar\n`);\n\t\t\treturn;\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\nUpdate installed packages.\nIf <source> is provided, only that package is updated.\n`);\n\t\t\treturn;\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [command, ...rest] = args;\n\tif (command !== \"install\" && command !== \"remove\" && command !== \"update\" && command !== \"list\") {\n\t\treturn undefined;\n\t}\n\tlet local = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet source: string | undefined;\n\tfor (const arg of rest) {\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t}\n\t}\n\treturn { command, source, local, help, invalidOption };\n}\nasync function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.install(source!, { local: options.local });\n\t\t\t\tpackageManager.addSourceToSettings(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\t\t\tcase \"remove\": {\n\t\t\t\tawait packageManager.remove(source!, { local: options.local });\n\t\t\t\tconst removed = packageManager.removeSourceFromSettings(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"list\": {\n\t\t\t\tconst globalSettings = settingsManager.getGlobalSettings();\n\t\t\t\tconst projectSettings = settingsManager.getProjectSettings();\n\t\t\t\tconst globalPackages = globalSettings.packages ?? [];\n\t\t\t\tconst projectPackages = projectSettings.packages ?? [];\n\t\t\t\tif (globalPackages.length === 0 && projectPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconst formatPackage = (pkg: (typeof globalPackages)[number], scope: \"user\" | \"project\") => {\n\t\t\t\t\tconst source = typeof pkg === \"string\" ? pkg : pkg.source;\n\t\t\t\t\tconst filtered = typeof pkg === \"object\";\n\t\t\t\t\tconst display = filtered ? `${source} (filtered)` : source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tconst path = packageManager.getInstalledPath(source, scope);\n\t\t\t\t\tif (path) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${path}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tif (globalPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of globalPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"user\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (globalPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg, \"project\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase \"update\":\n\t\t\t\tawait packageManager.update(source);\n\t\t\t\tif (source) {\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${source}`));\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\nasync function prepareInitialMessage(\n\tparsed: Args,\n\tautoResizeImages: boolean,\n): Promise<{\n\tinitialMessage?: string;\n\tinitialImages?: ImageContent[];\n}> {\n\tif (parsed.fileArgs.length === 0) {\n\t\treturn {};\n\t}\n\tconst { text, images } = await processFileArguments(parsed.fileArgs, { autoResizeImages });\n\tlet initialMessage: string;\n\tif (parsed.messages.length > 0) {\n\t\tinitialMessage = text + parsed.messages[0];\n\t\tparsed.messages.shift();\n\t} else {\n\t\tinitialMessage = text;\n\t}\n\treturn {\n\t\tinitialMessage,\n\t\tinitialImages: images.length > 0 ? images : undefined,\n\t};\n}\ntype ResolvedSession =\n\t| { type: \"path\"; path: string }\n\t| { type: \"local\"; path: string }\n\t| { type: \"global\"; path: string; cwd: string }\n\t| { type: \"not_found\"; arg: string };\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: sessionArg };\n\t}\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatches = localSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (localMatches.length >= 1) {\n\t\treturn { type: \"local\", path: localMatches[0].path };\n\t}\n\tconst allSessions = await SessionManager.listAll();\n\tconst globalMatches = allSessions.filter((s) => s.id.startsWith(sessionArg));\n\tif (globalMatches.length >= 1) {\n\t\tconst match = globalMatches[0];\n\t\treturn { type: \"global\", path: match.path, cwd: match.cwd };\n\t}\n\treturn { type: \"not_found\", arg: sessionArg };\n}\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\nasync function callSessionDirectoryHook(extensions: LoadExtensionsResult, cwd: string): Promise<string | undefined> {\n\tlet customSessionDir: string | undefined;\n\tfor (const ext of extensions.extensions) {\n\t\tconst handlers = ext.handlers.get(\"session_directory\");\n\t\tif (!handlers || handlers.length === 0) continue;\n\t\tfor (const handler of handlers) {\n\t\t\ttry {\n\t\t\t\tconst event = { type: \"session_directory\" as const, cwd };\n\t\t\t\tconst result = (await handler(event)) as { sessionDir?: string } | undefined;\n\t\t\t\tif (result?.sessionDir) {\n\t\t\t\t\tcustomSessionDir = result.sessionDir;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\t\tconsole.error(chalk.red(`Extension \"${ext.path}\" session_directory handler failed: ${message}`));\n\t\t\t}\n\t\t}\n\t}\n\treturn customSessionDir;\n}\nasync function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\textensions: LoadExtensionsResult,\n): Promise<SessionManager | undefined> {\n\tif (parsed.noSession) {\n\t\treturn SessionManager.inMemory();\n\t}\n\tlet effectiveSessionDir = parsed.sessionDir;\n\tif (!effectiveSessionDir) {\n\t\teffectiveSessionDir = await callSessionDirectoryHook(extensions, cwd);\n\t}\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, effectiveSessionDir);\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn SessionManager.open(resolved.path, effectiveSessionDir);\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn SessionManager.forkFrom(resolved.path, cwd, effectiveSessionDir);\n\t\t\t}\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, effectiveSessionDir);\n\t}\n\tif (effectiveSessionDir) {\n\t\treturn SessionManager.create(cwd, effectiveSessionDir);\n\t}\n\treturn undefined;\n}\nfunction buildSessionOptions(\n\tparsed: Args,\n\tsessionManager: SessionManager | undefined,\n\t_modelRegistry: ModelRegistry,\n\t_settingsManager: SettingsManager,\n): { options: CreateAgentSessionOptions; cliThinkingFromModel: boolean } {\n\tconst options: CreateAgentSessionOptions = {};\n\tconst cliThinkingFromModel = false;\n\tif (sessionManager) {\n\t\toptions.sessionManager = sessionManager;\n\t}\n\tif (parsed.thinking) {\n\t\toptions.thinkingLevel = parsed.thinking;\n\t}\n\tif (parsed.noTools) {\n\t\tif (parsed.tools && parsed.tools.length > 0) {\n\t\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t\t} else {\n\t\t\toptions.tools = [];\n\t\t}\n\t} else if (parsed.tools) {\n\t\toptions.tools = parsed.tools.map((name) => allTools[name]);\n\t}\n\treturn { options, cliThinkingFromModel };\n}\nasync function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\tprocess.exit(0);\n}\nasync function processFilesInParallel(\n\tfileArgs: string[],\n\tautoResizeImages: boolean,\n): Promise<{ text: string; images: ImageContent[] }> {\n\tconst chunkSize = globalMultiGPUExecutor ? Math.ceil(fileArgs.length / 4) : fileArgs.length;\n\tconst chunks: string[][] = [];\n\tfor (let i = 0; i < fileArgs.length; i += chunkSize) {\n\t\tchunks.push(fileArgs.slice(i, i + chunkSize));\n\t}\n\tconst results = await Promise.all(chunks.map((chunk) => processFileArguments(chunk, { autoResizeImages })));\n\tconst text = results.map((r) => r.text).join(\"\");\n\tconst images = results.flatMap((r) => r.images);\n\treturn { text, images };\n}\nexport async function main(args: string[]) {\n\tdebugLog(\"main\", \"Starting main\", { args, pid: process.pid, platform: process.platform });\n\ttry {\n\t\tconst offlineMode = args.includes(\"--offline\") || isTruthyEnvFlag(process.env.PI_OFFLINE);\n\t\tif (offlineMode) {\n\t\t\tprocess.env.PI_OFFLINE = \"1\";\n\t\t\tprocess.env.PI_SKIP_VERSION_CHECK = \"1\";\n\t\t}\n\t\t// Check for updates (async, non-blocking)\n\t\tif (!process.env.PI_SKIP_VERSION_CHECK) {\n\t\t\tcheckForUpdates().catch(() => {});\n\t\t}\n\t\tif (await handlePackageCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tif (await handleConfigCommand(args)) {\n\t\t\treturn;\n\t\t}\n\t\tdebugLog(\"main\", \"Running migrations\");\n\t\tconst { deprecationWarnings } = runMigrations(process.cwd());\n\t\tdebugLog(\"main\", \"Parsing args\");\n\t\tconst firstPass = parseArgs(args);\n\t\tdebugLog(\"main\", \"Initializing components\");\n\t\tconst cwd = process.cwd();\n\t\tconst agentDir = getAgentDir();\n\t\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\t\treportSettingsErrors(settingsManager, \"startup\");\n\t\tconst authStorage = AuthStorage.create();\n\t\tconst modelRegistry = new ModelRegistry(authStorage, getModelsPath());\n\t\tdebugLog(\"main\", \"Creating resource loader\");\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalExtensionPaths: firstPass.extensions,\n\t\t\tadditionalSkillPaths: firstPass.skills,\n\t\t\tadditionalPromptTemplatePaths: firstPass.promptTemplates,\n\t\t\tadditionalThemePaths: firstPass.themes,\n\t\t\tnoExtensions: firstPass.noExtensions,\n\t\t\tnoSkills: firstPass.noSkills,\n\t\t\tnoPromptTemplates: firstPass.noPromptTemplates,\n\t\t\tnoThemes: firstPass.noThemes,\n\t\t\tsystemPrompt: firstPass.systemPrompt,\n\t\t\tappendSystemPrompt: firstPass.appendSystemPrompt,\n\t\t});\n\t\tdebugLog(\"main\", \"Reloading resources\");\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t\tdebugLog(\"main\", \"Loading extensions\");\n\t\tconst extensionsResult: LoadExtensionsResult = resourceLoader.getExtensions();\n\t\tfor (const { path, error } of extensionsResult.errors) {\n\t\t\tconsole.error(chalk.red(`Failed to load extension \"${path}\": ${error}`));\n\t\t}\n\t\t// Provider registration removed - models are configured during onboarding only\n\t\tconst extensionFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\t\tfor (const ext of extensionsResult.extensions) {\n\t\t\tfor (const [name, flag] of ext.flags) {\n\t\t\t\textensionFlags.set(name, { type: flag.type });\n\t\t\t}\n\t\t}\n\t\tconst parsed = parseArgs(args, extensionFlags);\n\t\tfor (const [name, value] of parsed.unknownFlags) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t}\n\t\tif (parsed.version) {\n\t\t\tconsole.log(VERSION);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.help) {\n\t\t\tprintHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.listModels !== undefined) {\n\t\t\tconst searchPattern = typeof parsed.listModels === \"string\" ? parsed.listModels : undefined;\n\t\t\tawait listModels(modelRegistry, searchPattern);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode !== \"rpc\") {\n\t\t\tconst stdinContent = await readPipedStdin();\n\t\t\tif (stdinContent !== undefined) {\n\t\t\t\tparsed.print = true;\n\t\t\t\tparsed.messages.unshift(stdinContent);\n\t\t\t}\n\t\t}\n\t\tif (parsed.export) {\n\t\t\tlet result: string;\n\t\t\ttry {\n\t\t\t\tconst outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;\n\t\t\t\tresult = await exportFromFile(parsed.export, outputPath);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst message = error instanceof Error ? error.message : \"Failed to export session\";\n\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.log(`Exported to: ${result}`);\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (parsed.mode === \"rpc\" && parsed.fileArgs.length > 0) {\n\t\t\tconsole.error(chalk.red(\"Error: @file arguments are not supported in RPC mode\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tlet initialMessage: string | undefined;\n\t\tlet initialImages: ImageContent[] | undefined;\n\t\tif (parsed.fileArgs.length > 0 && parsed.fileArgs.length > 4) {\n\t\t\tconst result = await processFilesInParallel(parsed.fileArgs, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.text;\n\t\t\tinitialImages = result.images.length > 0 ? result.images : undefined;\n\t\t\tif (parsed.messages.length > 0) {\n\t\t\t\tinitialMessage = initialMessage + parsed.messages[0];\n\t\t\t\tparsed.messages.shift();\n\t\t\t}\n\t\t} else {\n\t\t\tconst result = await prepareInitialMessage(parsed, settingsManager.getImageAutoResize());\n\t\t\tinitialMessage = result.initialMessage;\n\t\t\tinitialImages = result.initialImages;\n\t\t}\n\t\tconst isInteractive = !parsed.print && parsed.mode === undefined;\n\t\tconst mode = parsed.mode || \"text\";\n\t\tinitTheme(settingsManager.getTheme(), isInteractive);\n\t\tif (isInteractive && deprecationWarnings.length > 0) {\n\t\t\tawait showDeprecationWarnings(deprecationWarnings);\n\t\t}\n\t\tlet sessionManager = await createSessionManager(parsed, cwd, extensionsResult);\n\t\tif (parsed.resume) {\n\t\t\tKeybindingsManager.create();\n\t\t\tconst effectiveSessionDir = parsed.sessionDir || (await callSessionDirectoryHook(extensionsResult, cwd));\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, effectiveSessionDir, onProgress),\n\t\t\t\tSessionManager.listAll,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tsessionManager = SessionManager.open(selectedPath, effectiveSessionDir);\n\t\t}\n\t\tconst { options: sessionOptions, cliThinkingFromModel } = buildSessionOptions(\n\t\t\tparsed,\n\t\t\tsessionManager,\n\t\t\tmodelRegistry,\n\t\t\tsettingsManager,\n\t\t);\n\t\tsessionOptions.authStorage = authStorage;\n\t\tsessionOptions.modelRegistry = modelRegistry;\n\t\tsessionOptions.resourceLoader = resourceLoader;\n\t\tif (parsed.apiKey) {\n\t\t\tconsole.error(chalk.red(\"--api-key is deprecated. Please configure your API key during onboarding.\"));\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst { session } = await createAgentSession(sessionOptions);\n\t\tif (!isInteractive && !session.model) {\n\t\t\tconsole.error(chalk.red(\"No model configured.\"));\n\t\t\tconsole.error(chalk.yellow(\"\\nPlease run onboarding to configure your model:\"));\n\t\t\tconsole.error(\" openvibe --onboarding\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst cliThinkingOverride = parsed.thinking !== undefined || cliThinkingFromModel;\n\t\tif (session.model && cliThinkingOverride) {\n\t\t\tlet effectiveThinking = session.thinkingLevel;\n\t\t\tif (!session.model.reasoning) {\n\t\t\t\teffectiveThinking = \"off\";\n\t\t\t} else if (effectiveThinking === \"xhigh\" && !supportsXhigh(session.model)) {\n\t\t\t\teffectiveThinking = \"high\";\n\t\t\t}\n\t\t\tif (effectiveThinking !== session.thinkingLevel) {\n\t\t\t\tsession.setThinkingLevel(effectiveThinking);\n\t\t\t}\n\t\t}\n\t\tdebugLog(\"main\", \"Selecting run mode\", { mode, isInteractive });\n\t\tif (mode === \"rpc\") {\n\t\t\tdebugLog(\"main\", \"Running RPC mode\");\n\t\t\tawait runRpcMode(session);\n\t\t} else if (isInteractive) {\n\t\t\tdebugLog(\"main\", \"Running interactive mode\");\n\t\t\tprintTimings();\n\t\t\tconst mode = new InteractiveMode(session, {\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t\tinitialMessages: parsed.messages,\n\t\t\t\tverbose: parsed.verbose,\n\t\t\t});\n\t\t\tawait mode.run();\n\t\t} else {\n\t\t\tdebugLog(\"main\", \"Running print mode\");\n\t\t\tawait runPrintMode(session, {\n\t\t\t\tmode,\n\t\t\t\tmessages: parsed.messages,\n\t\t\t\tinitialMessage,\n\t\t\t\tinitialImages,\n\t\t\t});\n\t\t\tstopThemeWatcher();\n\t\t\tif (process.stdout.writableLength > 0) {\n\t\t\t\tawait new Promise<void>((resolve) => process.stdout.once(\"drain\", resolve));\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tdebugLog(\"main\", \"Main completed successfully\");\n\t} catch (error) {\n\t\tdebugLog(\"main\", \"Main crashed\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tstack: error instanceof Error ? error.stack : undefined,\n\t\t});\n\t\tconsole.error(chalk.red(\"\\n[CRASH] Application crashed:\"));\n\t\tconsole.error(error);\n\t\tfs.appendFileSync(\n\t\t\t\"crash.log\",\n\t\t\t`[${new Date().toISOString()}] Main Crash:\\n${error instanceof Error ? error.stack : String(error)}\\n\\n`,\n\t\t);\n\t\tprocess.exit(1);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-check.d.ts","sourceRoot":"","sources":["../../src/utils/version-check.ts"],"names":[],"mappings":"AAiFA,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAmDrD","sourcesContent":["import chalk from \"chalk\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { join } from \"path\";\n\nconst CACHE_DIR = join(homedir(), \".openvibe\");\nconst CACHE_FILE = join(CACHE_DIR, \"version-check.json\");\nconst CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours\n\ninterface VersionCache {\n\tlastCheck: number;\n\tlatestVersion: string;\n}\n\nfunction getCurrentVersion(): string {\n\t// Read version from package.json\n\ttry {\n\t\tconst pkg = JSON.parse(readFileSync(new URL(\"../../package.json\", import.meta.url), \"utf-8\"));\n\t\treturn pkg.version;\n\t} catch {\n\t\treturn \"0.0.0\";\n\t}\n}\n\nfunction parseVersion(version: string): number[] {\n\treturn version.split(\".\").map((v) => parseInt(v, 10));\n}\n\nfunction isNewer(current: string, latest: string): boolean {\n\tconst currentParts = parseVersion(current);\n\tconst latestParts = parseVersion(latest);\n\n\tfor (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {\n\t\tconst currentPart = currentParts[i] || 0;\n\t\tconst latestPart = latestParts[i] || 0;\n\t\tif (latestPart > currentPart) return true;\n\t\tif (latestPart < currentPart) return false;\n\t}\n\treturn false;\n}\n\nasync function fetchLatestVersion(): Promise<string | null> {\n\ttry {\n\t\tconst controller = new AbortController();\n\t\tconst timeout = setTimeout(() => controller.abort(), 5000);\n\n\t\tconst response = await fetch(\"https://registry.npmjs.org/openvibe\", {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\tclearTimeout(timeout);\n\n\t\tif (!response.ok) return null;\n\n\t\tconst data = (await response.json()) as { \"dist-tags\"?: { latest?: string } };\n\t\treturn data[\"dist-tags\"]?.latest || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction readCache(): VersionCache | null {\n\ttry {\n\t\tif (!existsSync(CACHE_FILE)) return null;\n\t\tconst content = readFileSync(CACHE_FILE, \"utf-8\");\n\t\treturn JSON.parse(content);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction writeCache(cache: VersionCache): void {\n\ttry {\n\t\tif (!existsSync(CACHE_DIR)) {\n\t\t\tmkdirSync(CACHE_DIR, { recursive: true });\n\t\t}\n\t\twriteFileSync(CACHE_FILE, JSON.stringify(cache));\n\t} catch {\n\t\t// Ignore cache write errors\n\t}\n}\n\nexport async function checkForUpdates(): Promise<void> {\n\tconst currentVersion = getCurrentVersion();\n\tconst cache = readCache();\n\tconst now = Date.now();\n\n\tlet latestVersion: string | null;\n\n\t// Use cached version if checked recently\n\tif (cache && now - cache.lastCheck < CHECK_INTERVAL) {\n\t\tlatestVersion = cache.latestVersion;\n\t} else {\n\t\t// Fetch from npm registry\n\t\tlatestVersion = await fetchLatestVersion();\n\t\tif (latestVersion) {\n\t\t\twriteCache({ lastCheck: now, latestVersion });\n\t\t}\n\t}\n\n\tif (latestVersion && isNewer(currentVersion, latestVersion)) {\n\t\tconsole.log();\n\t\tconsole.log(chalk.yellow(\"┌─────────────────────────────────────────────────────────┐\"));\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.bold(\"Update Available\") +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t` Current: ${chalk.gray(currentVersion)}` +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t` Latest: ${chalk.green(latestVersion)}` +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(chalk.yellow(\"│\") + \" \" + chalk.yellow(\"│\"));\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t\" Run \" +\n\t\t\t\tchalk.cyan(\"npm i -g openvibe\") +\n\t\t\t\t\" to update \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(chalk.yellow(\"└─────────────────────────────────────────────────────────┘\"));\n\t\tconsole.log();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
const CACHE_DIR = join(homedir(), ".openvibe");
|
|
6
|
+
const CACHE_FILE = join(CACHE_DIR, "version-check.json");
|
|
7
|
+
const CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
8
|
+
function getCurrentVersion() {
|
|
9
|
+
// Read version from package.json
|
|
10
|
+
try {
|
|
11
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf-8"));
|
|
12
|
+
return pkg.version;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return "0.0.0";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function parseVersion(version) {
|
|
19
|
+
return version.split(".").map((v) => parseInt(v, 10));
|
|
20
|
+
}
|
|
21
|
+
function isNewer(current, latest) {
|
|
22
|
+
const currentParts = parseVersion(current);
|
|
23
|
+
const latestParts = parseVersion(latest);
|
|
24
|
+
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
|
25
|
+
const currentPart = currentParts[i] || 0;
|
|
26
|
+
const latestPart = latestParts[i] || 0;
|
|
27
|
+
if (latestPart > currentPart)
|
|
28
|
+
return true;
|
|
29
|
+
if (latestPart < currentPart)
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
async function fetchLatestVersion() {
|
|
35
|
+
try {
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
38
|
+
const response = await fetch("https://registry.npmjs.org/openvibe", {
|
|
39
|
+
signal: controller.signal,
|
|
40
|
+
});
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
if (!response.ok)
|
|
43
|
+
return null;
|
|
44
|
+
const data = (await response.json());
|
|
45
|
+
return data["dist-tags"]?.latest || null;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function readCache() {
|
|
52
|
+
try {
|
|
53
|
+
if (!existsSync(CACHE_FILE))
|
|
54
|
+
return null;
|
|
55
|
+
const content = readFileSync(CACHE_FILE, "utf-8");
|
|
56
|
+
return JSON.parse(content);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function writeCache(cache) {
|
|
63
|
+
try {
|
|
64
|
+
if (!existsSync(CACHE_DIR)) {
|
|
65
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
writeFileSync(CACHE_FILE, JSON.stringify(cache));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Ignore cache write errors
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export async function checkForUpdates() {
|
|
74
|
+
const currentVersion = getCurrentVersion();
|
|
75
|
+
const cache = readCache();
|
|
76
|
+
const now = Date.now();
|
|
77
|
+
let latestVersion;
|
|
78
|
+
// Use cached version if checked recently
|
|
79
|
+
if (cache && now - cache.lastCheck < CHECK_INTERVAL) {
|
|
80
|
+
latestVersion = cache.latestVersion;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Fetch from npm registry
|
|
84
|
+
latestVersion = await fetchLatestVersion();
|
|
85
|
+
if (latestVersion) {
|
|
86
|
+
writeCache({ lastCheck: now, latestVersion });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (latestVersion && isNewer(currentVersion, latestVersion)) {
|
|
90
|
+
console.log();
|
|
91
|
+
console.log(chalk.yellow("┌─────────────────────────────────────────────────────────┐"));
|
|
92
|
+
console.log(chalk.yellow("│") +
|
|
93
|
+
" " +
|
|
94
|
+
chalk.bold("Update Available") +
|
|
95
|
+
" " +
|
|
96
|
+
chalk.yellow("│"));
|
|
97
|
+
console.log(chalk.yellow("│") +
|
|
98
|
+
` Current: ${chalk.gray(currentVersion)}` +
|
|
99
|
+
" " +
|
|
100
|
+
chalk.yellow("│"));
|
|
101
|
+
console.log(chalk.yellow("│") +
|
|
102
|
+
` Latest: ${chalk.green(latestVersion)}` +
|
|
103
|
+
" " +
|
|
104
|
+
chalk.yellow("│"));
|
|
105
|
+
console.log(chalk.yellow("│") + " " + chalk.yellow("│"));
|
|
106
|
+
console.log(chalk.yellow("│") +
|
|
107
|
+
" Run " +
|
|
108
|
+
chalk.cyan("npm i -g openvibe") +
|
|
109
|
+
" to update " +
|
|
110
|
+
chalk.yellow("│"));
|
|
111
|
+
console.log(chalk.yellow("└─────────────────────────────────────────────────────────┘"));
|
|
112
|
+
console.log();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=version-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-check.js","source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CAAC;YAChB,IAAI;YACJ,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC;YAC9B,2CAA2C;YAC3C,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,CAClB,CAAC;QACF,OAAO,CAAC,GAAG,CACV,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC;YAChB,cAAc,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;YAC1C,2CAA2C;YAC3C,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,CAClB,CAAC;QACF,OAAO,CAAC,GAAG,CACV,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC;YAChB,cAAc,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;YAC1C,4CAA4C;YAC5C,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,CAClB,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,GAAG,4DAA4D,GAAG,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,CAAC,CAAC;QAClH,OAAO,CAAC,GAAG,CACV,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC;YAChB,QAAQ;YACR,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC;YAC/B,iCAAiC;YACjC,KAAK,CAAC,MAAM,CAAC,KAAG,CAAC,CAClB,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,mLAA6D,CAAC,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,EAAE,CAAC;IACf,CAAC;AAAA,CACD","sourcesContent":["import chalk from \"chalk\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { join } from \"path\";\n\nconst CACHE_DIR = join(homedir(), \".openvibe\");\nconst CACHE_FILE = join(CACHE_DIR, \"version-check.json\");\nconst CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours\n\ninterface VersionCache {\n\tlastCheck: number;\n\tlatestVersion: string;\n}\n\nfunction getCurrentVersion(): string {\n\t// Read version from package.json\n\ttry {\n\t\tconst pkg = JSON.parse(readFileSync(new URL(\"../../package.json\", import.meta.url), \"utf-8\"));\n\t\treturn pkg.version;\n\t} catch {\n\t\treturn \"0.0.0\";\n\t}\n}\n\nfunction parseVersion(version: string): number[] {\n\treturn version.split(\".\").map((v) => parseInt(v, 10));\n}\n\nfunction isNewer(current: string, latest: string): boolean {\n\tconst currentParts = parseVersion(current);\n\tconst latestParts = parseVersion(latest);\n\n\tfor (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {\n\t\tconst currentPart = currentParts[i] || 0;\n\t\tconst latestPart = latestParts[i] || 0;\n\t\tif (latestPart > currentPart) return true;\n\t\tif (latestPart < currentPart) return false;\n\t}\n\treturn false;\n}\n\nasync function fetchLatestVersion(): Promise<string | null> {\n\ttry {\n\t\tconst controller = new AbortController();\n\t\tconst timeout = setTimeout(() => controller.abort(), 5000);\n\n\t\tconst response = await fetch(\"https://registry.npmjs.org/openvibe\", {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\tclearTimeout(timeout);\n\n\t\tif (!response.ok) return null;\n\n\t\tconst data = (await response.json()) as { \"dist-tags\"?: { latest?: string } };\n\t\treturn data[\"dist-tags\"]?.latest || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction readCache(): VersionCache | null {\n\ttry {\n\t\tif (!existsSync(CACHE_FILE)) return null;\n\t\tconst content = readFileSync(CACHE_FILE, \"utf-8\");\n\t\treturn JSON.parse(content);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction writeCache(cache: VersionCache): void {\n\ttry {\n\t\tif (!existsSync(CACHE_DIR)) {\n\t\t\tmkdirSync(CACHE_DIR, { recursive: true });\n\t\t}\n\t\twriteFileSync(CACHE_FILE, JSON.stringify(cache));\n\t} catch {\n\t\t// Ignore cache write errors\n\t}\n}\n\nexport async function checkForUpdates(): Promise<void> {\n\tconst currentVersion = getCurrentVersion();\n\tconst cache = readCache();\n\tconst now = Date.now();\n\n\tlet latestVersion: string | null;\n\n\t// Use cached version if checked recently\n\tif (cache && now - cache.lastCheck < CHECK_INTERVAL) {\n\t\tlatestVersion = cache.latestVersion;\n\t} else {\n\t\t// Fetch from npm registry\n\t\tlatestVersion = await fetchLatestVersion();\n\t\tif (latestVersion) {\n\t\t\twriteCache({ lastCheck: now, latestVersion });\n\t\t}\n\t}\n\n\tif (latestVersion && isNewer(currentVersion, latestVersion)) {\n\t\tconsole.log();\n\t\tconsole.log(chalk.yellow(\"┌─────────────────────────────────────────────────────────┐\"));\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.bold(\"Update Available\") +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t` Current: ${chalk.gray(currentVersion)}` +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t` Latest: ${chalk.green(latestVersion)}` +\n\t\t\t\t\" \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(chalk.yellow(\"│\") + \" \" + chalk.yellow(\"│\"));\n\t\tconsole.log(\n\t\t\tchalk.yellow(\"│\") +\n\t\t\t\t\" Run \" +\n\t\t\t\tchalk.cyan(\"npm i -g openvibe\") +\n\t\t\t\t\" to update \" +\n\t\t\t\tchalk.yellow(\"│\"),\n\t\t);\n\t\tconsole.log(chalk.yellow(\"└─────────────────────────────────────────────────────────┘\"));\n\t\tconsole.log();\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openvibe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"description": "OpenVibe - AI Coding Assistant CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@mariozechner/jiti": "^2.6.2",
|
|
44
|
-
"@boxiaolanya2008/pi-agent-core": "^0.
|
|
45
|
-
"@boxiaolanya2008/pi-ai": "^0.
|
|
46
|
-
"@boxiaolanya2008/pi-tui": "^0.
|
|
44
|
+
"@boxiaolanya2008/pi-agent-core": "^0.62.0",
|
|
45
|
+
"@boxiaolanya2008/pi-ai": "^0.62.0",
|
|
46
|
+
"@boxiaolanya2008/pi-tui": "^0.62.0",
|
|
47
47
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
48
48
|
"chalk": "^5.5.0",
|
|
49
49
|
"cli-highlight": "^2.1.11",
|