agendex-cli 0.3.1 → 0.4.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/cli.js +139 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2681,15 +2681,31 @@ function getCloudConfig() {
|
|
|
2681
2681
|
async function syncPlan(plan) {
|
|
2682
2682
|
const { token, convexUrl } = getCloudConfig();
|
|
2683
2683
|
const url = `${convexUrl}/api/cli/sync`;
|
|
2684
|
-
|
|
2684
|
+
let activeToken = token;
|
|
2685
|
+
let res = await requestText(url, {
|
|
2685
2686
|
method: "POST",
|
|
2686
2687
|
headers: {
|
|
2687
|
-
Authorization: `Bearer ${
|
|
2688
|
+
Authorization: `Bearer ${activeToken}`,
|
|
2688
2689
|
Connection: "close",
|
|
2689
2690
|
"Content-Type": "application/json"
|
|
2690
2691
|
},
|
|
2691
2692
|
body: JSON.stringify(plan)
|
|
2692
2693
|
});
|
|
2694
|
+
if (res.status === 401) {
|
|
2695
|
+
const refreshed = await refreshStoredToken(activeToken, convexUrl);
|
|
2696
|
+
if (refreshed) {
|
|
2697
|
+
activeToken = refreshed;
|
|
2698
|
+
res = await requestText(url, {
|
|
2699
|
+
method: "POST",
|
|
2700
|
+
headers: {
|
|
2701
|
+
Authorization: `Bearer ${activeToken}`,
|
|
2702
|
+
Connection: "close",
|
|
2703
|
+
"Content-Type": "application/json"
|
|
2704
|
+
},
|
|
2705
|
+
body: JSON.stringify(plan)
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2693
2709
|
if (res.status < 200 || res.status >= 300) {
|
|
2694
2710
|
return { ok: false, error: `${res.status}: ${res.body}` };
|
|
2695
2711
|
}
|
|
@@ -2868,7 +2884,9 @@ async function runWorker() {
|
|
|
2868
2884
|
if (!result.ok) {
|
|
2869
2885
|
if (result.error?.includes("401")) {
|
|
2870
2886
|
console.error("[agendex] session expired. Run `agendex login` to re-authenticate.");
|
|
2871
|
-
|
|
2887
|
+
batch.length = 0;
|
|
2888
|
+
syncQueue.length = 0;
|
|
2889
|
+
break;
|
|
2872
2890
|
}
|
|
2873
2891
|
failedCount++;
|
|
2874
2892
|
console.error(`[agendex] sync failed for "${payload.title}": ${result.error}`);
|
|
@@ -2988,11 +3006,128 @@ async function syncAll() {
|
|
|
2988
3006
|
console.log(`[agendex] Sync complete: ${synced} synced, ${failed} failed`);
|
|
2989
3007
|
}
|
|
2990
3008
|
|
|
3009
|
+
// src/version.ts
|
|
3010
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3011
|
+
import { tmpdir } from "node:os";
|
|
3012
|
+
import { join as join11 } from "node:path";
|
|
3013
|
+
// package.json
|
|
3014
|
+
var package_default = {
|
|
3015
|
+
name: "agendex-cli",
|
|
3016
|
+
version: "0.4.0",
|
|
3017
|
+
description: "Agendex CLI for login, sync, and daemon workflows",
|
|
3018
|
+
homepage: "https://github.com/Tyru5/Agendex#readme",
|
|
3019
|
+
repository: {
|
|
3020
|
+
type: "git",
|
|
3021
|
+
url: "git+https://github.com/Tyru5/Agendex.git",
|
|
3022
|
+
directory: "packages/cli"
|
|
3023
|
+
},
|
|
3024
|
+
bugs: {
|
|
3025
|
+
url: "https://github.com/Tyru5/Agendex/issues"
|
|
3026
|
+
},
|
|
3027
|
+
type: "module",
|
|
3028
|
+
license: "AGPL-3.0-only",
|
|
3029
|
+
bin: {
|
|
3030
|
+
agendex: "./dist/cli.js"
|
|
3031
|
+
},
|
|
3032
|
+
files: [
|
|
3033
|
+
"dist",
|
|
3034
|
+
"README.md",
|
|
3035
|
+
"LICENSE"
|
|
3036
|
+
],
|
|
3037
|
+
publishConfig: {
|
|
3038
|
+
access: "public"
|
|
3039
|
+
},
|
|
3040
|
+
engines: {
|
|
3041
|
+
node: ">=20"
|
|
3042
|
+
},
|
|
3043
|
+
scripts: {
|
|
3044
|
+
build: "node ./scripts/build-release.mjs --dist-only",
|
|
3045
|
+
"build:release": "node ./scripts/build-release.mjs",
|
|
3046
|
+
prepack: "node ./scripts/build-release.mjs --dist-only"
|
|
3047
|
+
},
|
|
3048
|
+
dependencies: {
|
|
3049
|
+
"better-sqlite3": "^12.6.2"
|
|
3050
|
+
},
|
|
3051
|
+
devDependencies: {
|
|
3052
|
+
"@agendex/shared": "workspace:*",
|
|
3053
|
+
"@types/bun": "^1.3.9"
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
|
|
3057
|
+
// src/version.ts
|
|
3058
|
+
var CLI_VERSION = package_default.version;
|
|
3059
|
+
var CACHE_FILE = join11(tmpdir(), ".agendex-update-cache.json");
|
|
3060
|
+
var CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
3061
|
+
function readCache() {
|
|
3062
|
+
try {
|
|
3063
|
+
if (!existsSync7(CACHE_FILE))
|
|
3064
|
+
return null;
|
|
3065
|
+
const { result, ts } = JSON.parse(readFileSync4(CACHE_FILE, "utf8"));
|
|
3066
|
+
if (Date.now() - ts > CACHE_TTL_MS)
|
|
3067
|
+
return null;
|
|
3068
|
+
return result;
|
|
3069
|
+
} catch {
|
|
3070
|
+
return null;
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
function writeCache(result) {
|
|
3074
|
+
try {
|
|
3075
|
+
writeFileSync3(CACHE_FILE, JSON.stringify({ result, ts: Date.now() }));
|
|
3076
|
+
} catch {}
|
|
3077
|
+
}
|
|
3078
|
+
async function checkForUpdate() {
|
|
3079
|
+
const current = CLI_VERSION;
|
|
3080
|
+
const cached = readCache();
|
|
3081
|
+
if (cached)
|
|
3082
|
+
return { ...cached, current };
|
|
3083
|
+
try {
|
|
3084
|
+
const controller = new AbortController;
|
|
3085
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
3086
|
+
const res = await fetch("https://registry.npmjs.org/agendex-cli/latest", {
|
|
3087
|
+
signal: controller.signal
|
|
3088
|
+
});
|
|
3089
|
+
clearTimeout(timeout);
|
|
3090
|
+
if (!res.ok) {
|
|
3091
|
+
return { updateAvailable: false, current, latest: current };
|
|
3092
|
+
}
|
|
3093
|
+
const data = await res.json();
|
|
3094
|
+
const latest = data.version;
|
|
3095
|
+
const result = { updateAvailable: isNewer(latest, current), current, latest };
|
|
3096
|
+
writeCache(result);
|
|
3097
|
+
return result;
|
|
3098
|
+
} catch {
|
|
3099
|
+
return { updateAvailable: false, current, latest: current };
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
function isNewer(latest, current) {
|
|
3103
|
+
const l = latest.split(".").map(Number);
|
|
3104
|
+
const c = current.split(".").map(Number);
|
|
3105
|
+
for (let i = 0;i < Math.max(l.length, c.length); i++) {
|
|
3106
|
+
const lv = l[i] ?? 0;
|
|
3107
|
+
const cv = c[i] ?? 0;
|
|
3108
|
+
if (lv > cv)
|
|
3109
|
+
return true;
|
|
3110
|
+
if (lv < cv)
|
|
3111
|
+
return false;
|
|
3112
|
+
}
|
|
3113
|
+
return false;
|
|
3114
|
+
}
|
|
3115
|
+
|
|
2991
3116
|
// src/cli.ts
|
|
2992
3117
|
var args = process.argv.slice(2);
|
|
2993
3118
|
var command = args[0] ?? "start";
|
|
2994
3119
|
var cliEntry = resolve5(process.argv[1] ?? fileURLToPath2(import.meta.url));
|
|
2995
3120
|
async function main() {
|
|
3121
|
+
const isInternal = args.includes("--daemon") || args.includes("--worker");
|
|
3122
|
+
const isPassthrough = ["stop", "status", "login", "logout", "help", "--help", "-h"].includes(command);
|
|
3123
|
+
if (!isInternal && !isPassthrough) {
|
|
3124
|
+
const { updateAvailable, current, latest } = await checkForUpdate();
|
|
3125
|
+
if (updateAvailable) {
|
|
3126
|
+
writeStderr(`[agendex] update required: v${current} → v${latest}`);
|
|
3127
|
+
writeStderr(`[agendex] run: npm i -g agendex-cli`);
|
|
3128
|
+
return 1;
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
2996
3131
|
switch (command) {
|
|
2997
3132
|
case "start": {
|
|
2998
3133
|
if (args.includes("--daemon")) {
|
|
@@ -3069,6 +3204,7 @@ async function main() {
|
|
|
3069
3204
|
writeStdout(`[agendex] Convex URL: ${config?.convexUrl ?? "not set"}`);
|
|
3070
3205
|
writeStdout(`[agendex] Enabled adapters: ${config?.enabledAdapters.join(", ") || "none"}`);
|
|
3071
3206
|
writeStdout(`[agendex] Daemon: ${running ? `running (PID ${pid})` : "not running"}`);
|
|
3207
|
+
writeStdout(`[agendex] CLI version: ${CLI_VERSION}`);
|
|
3072
3208
|
return 0;
|
|
3073
3209
|
}
|
|
3074
3210
|
case "help":
|