@nolto/cli 0.19.4 → 0.20.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/dist/index.js +56 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -90,6 +90,9 @@ function mapHttpStatusToCliError(status, opts = {}) {
|
|
|
90
90
|
opts.body
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
+
if (status === 409 && opts.serverError === "project_key_taken") {
|
|
94
|
+
return new CliError(opts.serverMessage ?? "\u3053\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30AD\u30FC\u306F\u65E2\u306B\u4F7F\u308F\u308C\u3066\u3044\u307E\u3059\u3002", 2, void 0, status, opts.serverError, opts.body);
|
|
95
|
+
}
|
|
93
96
|
if (status === 429 && opts.serverError === "rebind_cooldown") {
|
|
94
97
|
return new CliError(
|
|
95
98
|
opts.serverMessage ?? "Rebind cooldown active.",
|
|
@@ -3163,6 +3166,25 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
3163
3166
|
import os3 from "os";
|
|
3164
3167
|
import path17 from "path";
|
|
3165
3168
|
import fs2 from "fs";
|
|
3169
|
+
|
|
3170
|
+
// src/project-key.ts
|
|
3171
|
+
var PROJECT_KEY_RE = /^[A-Z][A-Z0-9]{1,9}$/;
|
|
3172
|
+
var PROJECT_KEY_MAX = 10;
|
|
3173
|
+
function normalizeProjectKey(raw) {
|
|
3174
|
+
return raw.trim().toUpperCase();
|
|
3175
|
+
}
|
|
3176
|
+
function isValidProjectKey(value) {
|
|
3177
|
+
return PROJECT_KEY_RE.test(value);
|
|
3178
|
+
}
|
|
3179
|
+
function suggestProjectKey(name) {
|
|
3180
|
+
const words = name.split(/[^A-Za-z0-9]+/).map((word) => word.replace(/[^A-Za-z0-9]/g, "")).filter((word) => word.length > 0);
|
|
3181
|
+
if (words.length === 0) return "";
|
|
3182
|
+
const raw = words.length >= 2 ? words.slice(0, 6).map((word) => word[0]).join("") : words[0].slice(0, 6);
|
|
3183
|
+
const candidate = raw.toUpperCase().replace(/^[0-9]+/, "").slice(0, PROJECT_KEY_MAX);
|
|
3184
|
+
return isValidProjectKey(candidate) ? candidate : "";
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
// src/commands/init.ts
|
|
3166
3188
|
var __dirname2 = path17.dirname(fileURLToPath2(import.meta.url));
|
|
3167
3189
|
var _require = createRequire(import.meta.url);
|
|
3168
3190
|
function getCliVersion() {
|
|
@@ -3200,6 +3222,11 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
|
|
|
3200
3222
|
if (name.trim().length === 0) {
|
|
3201
3223
|
throw new CliError("Project name is required.", 2);
|
|
3202
3224
|
}
|
|
3225
|
+
const suggestedKey = suggestProjectKey(name);
|
|
3226
|
+
const rawKey = await rl.question(`Project key (2-10 chars, e.g. NF)${suggestedKey ? ` [${suggestedKey}]` : ""}: `);
|
|
3227
|
+
const key = normalizeProjectKey(rawKey) || suggestedKey;
|
|
3228
|
+
if (!key) throw new CliError("Project key is required.", 2);
|
|
3229
|
+
if (!isValidProjectKey(key)) throw new CliError("Project key must start with an uppercase letter and contain 2-10 alphanumeric characters.", 2);
|
|
3203
3230
|
const { orgs } = await http.get("/api/orgs/eligible");
|
|
3204
3231
|
if (orgs.length === 0) {
|
|
3205
3232
|
throw new CliError(`No organization to create the project in. Create one at ${baseUrl.replace(/\/+$/, "")}/orgs/new first.`, 2);
|
|
@@ -3220,7 +3247,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
|
|
|
3220
3247
|
}
|
|
3221
3248
|
const created = await http.post(
|
|
3222
3249
|
"/api/projects",
|
|
3223
|
-
{ name: name.trim(), orgId: organization.id }
|
|
3250
|
+
{ name: name.trim(), key, orgId: organization.id }
|
|
3224
3251
|
);
|
|
3225
3252
|
if (created.project?.id == null) {
|
|
3226
3253
|
throw new CliError("Project API did not return a project id.", 2);
|
|
@@ -3229,7 +3256,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
|
|
|
3229
3256
|
id: created.project.id,
|
|
3230
3257
|
name: created.project.name ?? name.trim()
|
|
3231
3258
|
};
|
|
3232
|
-
process.stdout.write(`Created project ${project.name} (${project.id}) in ${organization.name}
|
|
3259
|
+
process.stdout.write(`Created project ${project.name} [${key}] (${project.id}) in ${organization.name}
|
|
3233
3260
|
`);
|
|
3234
3261
|
return project;
|
|
3235
3262
|
}
|
|
@@ -4555,9 +4582,10 @@ async function checkForUpdate(opts) {
|
|
|
4555
4582
|
} catch {
|
|
4556
4583
|
}
|
|
4557
4584
|
if (typeof cache.checkedAt !== "number" || opts.now - cache.checkedAt > CACHE_TTL_MS) {
|
|
4558
|
-
|
|
4585
|
+
const refresh = refreshCache(cachePath, opts.now, opts.fetchLatest ?? fetchLatestFromRegistry).catch(
|
|
4559
4586
|
() => void 0
|
|
4560
4587
|
);
|
|
4588
|
+
opts.onRefresh?.(refresh);
|
|
4561
4589
|
}
|
|
4562
4590
|
if (typeof cache.latest === "string" && isNewerVersion(cache.latest, opts.current)) {
|
|
4563
4591
|
return cache.latest;
|
|
@@ -5116,6 +5144,8 @@ function printWrite(deps, ctx, action, response, isNew = false, put) {
|
|
|
5116
5144
|
}
|
|
5117
5145
|
async function pull2(deps, opts) {
|
|
5118
5146
|
let ctx;
|
|
5147
|
+
let updateNotice = Promise.resolve("");
|
|
5148
|
+
let updateRefresh = Promise.resolve();
|
|
5119
5149
|
const signal = opts.hook ? AbortSignal.timeout(8e3) : void 0;
|
|
5120
5150
|
try {
|
|
5121
5151
|
const explicitProject = deps.settings.source?.project === "flag" || deps.settings.source?.project === "env";
|
|
@@ -5127,6 +5157,24 @@ async function pull2(deps, opts) {
|
|
|
5127
5157
|
process.stdout.write(hookOutput(opts.hook, "nolto login \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044"));
|
|
5128
5158
|
return;
|
|
5129
5159
|
}
|
|
5160
|
+
if (opts.hook) {
|
|
5161
|
+
updateNotice = checkForUpdate({
|
|
5162
|
+
current: deps.version,
|
|
5163
|
+
configDir: getConfigDir(process.env),
|
|
5164
|
+
env: process.env,
|
|
5165
|
+
now: Date.now(),
|
|
5166
|
+
onRefresh: (pending) => {
|
|
5167
|
+
updateRefresh = new Promise((resolve) => {
|
|
5168
|
+
const timer = setTimeout(resolve, 2e3);
|
|
5169
|
+
void pending.finally(() => {
|
|
5170
|
+
clearTimeout(timer);
|
|
5171
|
+
resolve();
|
|
5172
|
+
});
|
|
5173
|
+
});
|
|
5174
|
+
}
|
|
5175
|
+
}).then((latest2) => latest2 ? `nolto CLI ${latest2} \u304C\u516C\u958B\u3055\u308C\u3066\u3044\u307E\u3059(\u4ECA\u306F ${deps.version})\u3002\`nolto update\` \u3067\u66F4\u65B0\u3067\u304D\u307E\u3059\u3002
|
|
5176
|
+
` : "").catch(() => "");
|
|
5177
|
+
}
|
|
5130
5178
|
ctx = await context2(deps, true);
|
|
5131
5179
|
if (opts.hook && typeof opts.hook === "string" && !["claude", "codex", "gemini"].includes(opts.hook)) throw new CliError("Unknown hook agent", 2);
|
|
5132
5180
|
const scope = opts.scope ? [...new Set(opts.scope.split(",").map((s) => parseScope(s.trim(), scopeHint)))].sort().join(",") : "";
|
|
@@ -5153,7 +5201,7 @@ async function pull2(deps, opts) {
|
|
|
5153
5201
|
const unsafe = await saveMemoryCache(ctx.dir, next.cache, previous, text, reset);
|
|
5154
5202
|
if (unsafe.length && !opts.hook) process.stderr.write(`Warning: \u30AD\u30E3\u30C3\u30B7\u30E5\u306B\u7F6E\u3051\u306A\u3044\u30A8\u30F3\u30C8\u30EA ${unsafe.length} \u4EF6\u3092\u7D22\u5F15\u3068 list \u304B\u3089\u5916\u3057\u305F: ${unsafe.map((e) => `${e.scope}/${oneLine(e.name)}`).join(", ")}
|
|
5155
5203
|
`);
|
|
5156
|
-
if (opts.hook) process.stdout.write(hookOutput(opts.hook, text));
|
|
5204
|
+
if (opts.hook) process.stdout.write(hookOutput(opts.hook, await updateNotice + text));
|
|
5157
5205
|
else printResult(deps.output.mode === "json" ? { cursor, entries: entries.filter((e) => !e.deleted).length } : `pulled memory (${entries.filter((e) => !e.deleted).length} \u4EF6)`, deps.output.mode);
|
|
5158
5206
|
} catch (error) {
|
|
5159
5207
|
if (!opts.hook) throw error;
|
|
@@ -5166,7 +5214,10 @@ ${await memoryIndexText(ctx, deps)}`;
|
|
|
5166
5214
|
} catch {
|
|
5167
5215
|
}
|
|
5168
5216
|
}
|
|
5169
|
-
process.stdout.write(hookOutput(opts.hook, text));
|
|
5217
|
+
process.stdout.write(hookOutput(opts.hook, await updateNotice + text));
|
|
5218
|
+
} finally {
|
|
5219
|
+
await updateNotice;
|
|
5220
|
+
await updateRefresh;
|
|
5170
5221
|
}
|
|
5171
5222
|
}
|
|
5172
5223
|
async function inputText(file) {
|