@t2000/cli 0.22.2 → 0.22.4

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 CHANGED
@@ -133,10 +133,14 @@ async function clearSession() {
133
133
  async function resolvePin(opts) {
134
134
  const envPin = getPinFromEnv();
135
135
  if (envPin) return envPin;
136
- const sessionPin = await readSession();
137
- if (sessionPin) return sessionPin;
136
+ if (!opts?.skipSession) {
137
+ const sessionPin = await readSession();
138
+ if (sessionPin) return sessionPin;
139
+ }
138
140
  const pin = opts?.confirm ? await askPinConfirm() : await askPin();
139
- await saveSession(pin);
141
+ if (!opts?.skipSession) {
142
+ await saveSession(pin);
143
+ }
140
144
  return pin;
141
145
  }
142
146
 
@@ -1540,12 +1544,34 @@ function registerLock(program2) {
1540
1544
  });
1541
1545
  program2.command("unlock").description("Unlock agent \u2014 resume operations").action(async () => {
1542
1546
  try {
1543
- const pin = await resolvePin();
1544
- if (!pin) {
1545
- throw new Error("PIN required to unlock agent");
1546
- }
1547
1547
  const { T2000: T200027 } = await import("@t2000/sdk");
1548
- await T200027.create({ pin });
1548
+ const MAX_ATTEMPTS2 = 3;
1549
+ let pin;
1550
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS2; attempt++) {
1551
+ pin = await resolvePin({ skipSession: true });
1552
+ if (!pin) {
1553
+ throw new Error("PIN required to unlock agent");
1554
+ }
1555
+ try {
1556
+ await T200027.create({ pin });
1557
+ break;
1558
+ } catch (error) {
1559
+ const msg = error instanceof Error ? error.message : "";
1560
+ if (msg.includes("Invalid PIN")) {
1561
+ const remaining = MAX_ATTEMPTS2 - attempt;
1562
+ if (remaining > 0) {
1563
+ printError(`Invalid PIN. ${remaining} attempt${remaining > 1 ? "s" : ""} remaining.`);
1564
+ pin = void 0;
1565
+ continue;
1566
+ }
1567
+ printError("Invalid PIN. No attempts remaining.");
1568
+ return;
1569
+ }
1570
+ throw error;
1571
+ }
1572
+ }
1573
+ if (!pin) return;
1574
+ await saveSession(pin);
1549
1575
  const enforcer = new SafeguardEnforcer3(CONFIG_DIR4);
1550
1576
  enforcer.load();
1551
1577
  enforcer.unlock();
@@ -2037,7 +2063,7 @@ function registerMcp(program2) {
2037
2063
  mcp.command("start", { isDefault: true }).description("Start MCP server (stdio transport)").option("--key <path>", "Key file path").action(async (opts) => {
2038
2064
  let mod;
2039
2065
  try {
2040
- mod = await import("./dist-6ELHCFGI.js");
2066
+ mod = await import("./dist-72NNY4EV.js");
2041
2067
  } catch {
2042
2068
  console.error(
2043
2069
  "MCP server not installed. Run:\n npm install -g @t2000/mcp"