kodingo-cli 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/commands/init.js
CHANGED
|
@@ -253,9 +253,9 @@ function registerInitCommand(program) {
|
|
|
253
253
|
// ── Save config ──────────────────────────────────────────────────────
|
|
254
254
|
const repoRoot = findRepoRoot(process.cwd());
|
|
255
255
|
const apiUrl = API_BASE;
|
|
256
|
-
// preserve existing workspaces
|
|
256
|
+
// preserve existing workspaces, never overwrite global token
|
|
257
257
|
const existingConfig = (0, persistence_config_1.readConfig)();
|
|
258
|
-
(0, persistence_config_1.writeConfig)({ ...existingConfig, mode: "cloud", apiUrl
|
|
258
|
+
(0, persistence_config_1.writeConfig)({ ...existingConfig, mode: "cloud", apiUrl });
|
|
259
259
|
(0, persistence_config_1.writeWorkspaceConfig)(repoRoot, { mode: "cloud", apiUrl, token: selectedProject.token });
|
|
260
260
|
ensureGitignoreEntry(repoRoot, ".kortex/");
|
|
261
261
|
console.log(`✔ Connected. Token saved to ${persistence_config_1.CONFIG_PATH}`);
|
|
@@ -27,6 +27,9 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
27
27
|
const node_path_1 = __importDefault(require("node:path"));
|
|
28
28
|
const node_os_1 = __importDefault(require("node:os"));
|
|
29
29
|
exports.CONFIG_PATH = node_path_1.default.join(node_os_1.default.homedir(), ".kodingo", "config.json");
|
|
30
|
+
function normalizePath(p) {
|
|
31
|
+
return p.replace(/\\/g, '/').toLowerCase();
|
|
32
|
+
}
|
|
30
33
|
function readConfig() {
|
|
31
34
|
if (!node_fs_1.default.existsSync(exports.CONFIG_PATH)) {
|
|
32
35
|
return { mode: "local" };
|
|
@@ -70,11 +73,14 @@ function getPersistence() {
|
|
|
70
73
|
if (config.mode === "cloud") {
|
|
71
74
|
if (!config.apiUrl)
|
|
72
75
|
throw new Error("Cloud mode requires apiUrl in ~/.kodingo/config.json");
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// Try workspace-scoped token first, fall back to global token
|
|
77
|
+
const wsConfig = readWorkspaceConfig(normalizePath(process.cwd()));
|
|
78
|
+
const token = wsConfig?.token ?? config.token ?? "";
|
|
79
|
+
if (!token)
|
|
80
|
+
throw new Error("No project token found. Run `kodingo init` in your project directory first.");
|
|
75
81
|
// Inject into env so cloud-persistence picks them up
|
|
76
|
-
process.env.KODINGO_API_URL = config.apiUrl;
|
|
77
|
-
process.env.KODINGO_API_TOKEN =
|
|
82
|
+
process.env.KODINGO_API_URL = wsConfig?.apiUrl ?? config.apiUrl;
|
|
83
|
+
process.env.KODINGO_API_TOKEN = token;
|
|
78
84
|
return require("../adapters/cloud-adapter/cloud-persistence");
|
|
79
85
|
}
|
|
80
86
|
return require("../adapters/db-adapter/memory-persistence");
|