worktrust 0.10.6 → 0.10.7
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/package.json +1 -1
- package/worktrust.mjs +37 -2
package/package.json
CHANGED
package/worktrust.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* WorkTrust on a computer, in one command — like `gh auth login` (2026-10-03).
|
|
4
4
|
*
|
|
5
|
-
* npx worktrust show the plan, ask, approve this computer in the app, couple
|
|
5
|
+
* npx worktrust show the plan, ask, approve this computer in the app, couple (0.10.7: a person's
|
|
6
|
+
* command always runs the newest version, whatever npx had cached);
|
|
6
7
|
* on a computer already coupled: what is coupled here
|
|
7
8
|
* npx worktrust --dry-run show the plan only; nothing is written, nothing is sent
|
|
8
9
|
* npx worktrust --yes no question (for scripts); the computer is still approved in the app
|
|
@@ -73,7 +74,7 @@ const command = args.find((arg, at) => !arg.startsWith("--") && !(at > 0 && VALU
|
|
|
73
74
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
74
75
|
const has = (name) => args.includes(`--${name}`);
|
|
75
76
|
/** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
|
|
76
|
-
const CLI_VERSION = "0.10.
|
|
77
|
+
const CLI_VERSION = "0.10.7";
|
|
77
78
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
78
79
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
79
80
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
@@ -986,6 +987,40 @@ if (agentShell && PERSON_ONLY.has(command)) {
|
|
|
986
987
|
process.exit(3);
|
|
987
988
|
}
|
|
988
989
|
|
|
990
|
+
/**
|
|
991
|
+
* ALWAYS THE NEWEST, WHATEVER WAS TYPED (0.10.7, owner: "npx worktrust should simply be right"). npx runs whatever version
|
|
992
|
+
* it cached, and a person should never need `@latest` or `--prefer-online`. A command a PERSON runs in a terminal asks npm
|
|
993
|
+
* which version is newest (the version string only, nothing of this computer, two seconds at most) and, when this one is
|
|
994
|
+
* older, hands the same command to the newest through npx and steps aside. Offline, npm slow, no terminal (a script, a
|
|
995
|
+
* test), an AI agent's shell: this version runs as it is. The bridge and the hook, which run many times a day from the
|
|
996
|
+
* stable copy, never ask.
|
|
997
|
+
*/
|
|
998
|
+
const RELAY_COMMANDS = new Set(["default", "connect", "update", "history", "status", "disconnect", "preserve", "codex", "antigravity"]);
|
|
999
|
+
const semverNewer = (a, b) => { const x = a.split(".").map(Number), y = b.split(".").map(Number); for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return x[i] > y[i]; return false; };
|
|
1000
|
+
async function newestVersion() {
|
|
1001
|
+
try {
|
|
1002
|
+
const response = await fetch(process.env.WORKTRUST_REGISTRY_URL || "https://registry.npmjs.org/worktrust/latest", { signal: AbortSignal.timeout(2000), headers: { accept: "application/json" } });
|
|
1003
|
+
if (!response.ok) return null;
|
|
1004
|
+
const version = (await response.json())?.version;
|
|
1005
|
+
return typeof version === "string" && /^\d+\.\d+\.\d+$/.test(version) ? version : null;
|
|
1006
|
+
} catch { return null; }
|
|
1007
|
+
}
|
|
1008
|
+
async function relayToNewest() {
|
|
1009
|
+
if (process.env.WORKTRUST_RELAYED === "1" || !RELAY_COMMANDS.has(command) || !process.stdin.isTTY || !process.stdout.isTTY) return;
|
|
1010
|
+
const latest = await newestVersion();
|
|
1011
|
+
if (!latest || !semverNewer(latest, CLI_VERSION)) return;
|
|
1012
|
+
say(` worktrust ${CLI_VERSION} is not the newest: running ${latest} instead.`);
|
|
1013
|
+
const argv = ["--yes", `worktrust@${latest}`, ...args];
|
|
1014
|
+
const env = { ...process.env, WORKTRUST_RELAYED: "1" };
|
|
1015
|
+
// A .cmd shim on Windows needs a shell: one line, each argument quoted for cmd.exe, never an argument list beside it.
|
|
1016
|
+
const quote = (arg) => (/^[\w@%+=:,./\\-]+$/.test(arg) ? arg : `"${String(arg).replace(/"/g, '\\"')}"`);
|
|
1017
|
+
const child = platform() === "win32" ? spawn(["npx", ...argv].map(quote).join(" "), { stdio: "inherit", env, shell: true }) : spawn("npx", argv, { stdio: "inherit", env });
|
|
1018
|
+
const code = await new Promise((done) => { child.on("error", () => done(null)); child.on("close", (exit) => done(exit)); });
|
|
1019
|
+
if (code === null) { say(" The newest could not be started; this version runs instead."); return; }
|
|
1020
|
+
process.exit(code);
|
|
1021
|
+
}
|
|
1022
|
+
await relayToNewest();
|
|
1023
|
+
|
|
989
1024
|
if (command === "default") { if (keyStore.load()) await again(); else await connect(); }
|
|
990
1025
|
else if (command === "mcp") await bridge();
|
|
991
1026
|
else if (command === "hook") await hook();
|