local lang = jarvis.context.language local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public" local config_path = userprofile .. "\\Documents\\jarvis-projects.json" if not jarvis.fs.exists(config_path) then local sample = string.format([[[ {"name": "jarvis-rust", "path": "%s\\Jarvis\\rust"}, {"name": "jarvis-python", "path": "%s\\Jarvis\\python"}, {"name": "dietpi", "path": "%s\\Desktop\\Dietpi"} ] ]], userprofile, userprofile, userprofile) jarvis.fs.write(config_path, sample) jarvis.system.notify( lang == "ru" and "Проекты" or "Projects", lang == "ru" and "Создан шаблон в Documents/jarvis-projects.json — отредактируй и повтори" or "Template created at Documents/jarvis-projects.json — edit and retry" ) jarvis.system.open(config_path) jarvis.audio.play_not_found() return { chain = false } end local content = jarvis.fs.read(config_path) local entries = {} for name, path in content:gmatch('"name"%s*:%s*"([^"]+)"%s*,%s*"path"%s*:%s*"([^"]+)"') do table.insert(entries, { name = name:lower(), original_name = name, path = path:gsub('\\\\', '\\') }) end if #entries == 0 then jarvis.system.notify("Projects", lang == "ru" and "Проектов в конфиге не нашёл" or "No projects in config") jarvis.audio.play_not_found() return { chain = false } end local phrase = (jarvis.context.phrase or ""):lower() local triggers = { "открой папку проекта", "запусти проект", "открой проект", "проект", "open project", "launch project", "project", "відкрий проект", "запусти проект", } local query = phrase for _, t in ipairs(triggers) do local s, e = string.find(query, t, 1, true) if s == 1 then query = query:sub(e + 1) break end end query = query:gsub("^%s+", ""):gsub("%s+$", "") if query == "" then jarvis.system.notify("Projects", lang == "ru" and "Какой проект?" or "Which project?") jarvis.audio.play_error() return { chain = false } end local match = nil for _, e in ipairs(entries) do if e.name == query then match = e; break end end if not match then for _, e in ipairs(entries) do if string.find(e.name, query, 1, true) or string.find(query, e.name, 1, true) then match = e; break end end end if not match then jarvis.system.notify("Projects", (lang == "ru" and "Не нашёл: " or "Not found: ") .. query) jarvis.audio.play_not_found() return { chain = false } end if not jarvis.fs.exists(match.path) then jarvis.system.notify("Projects", (lang == "ru" and "Путь не существует: " or "Path missing: ") .. match.path) jarvis.audio.play_error() return { chain = false } end local code_check = jarvis.system.exec("where code.cmd") if code_check.success and (code_check.stdout or ""):gsub("[\r\n]+$", "") ~= "" then jarvis.system.exec(string.format('code "%s"', match.path)) else jarvis.system.open(match.path) end jarvis.system.notify( lang == "ru" and "Проект" or "Project", match.original_name .. "\n" .. match.path ) jarvis.log("info", "opened project: " .. match.original_name .. " at " .. match.path) jarvis.audio.play_ok() return { chain = false }