@retasc/cli 1.21.0 → 1.21.1

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/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ release commits and the issues they reference.
6
6
 
7
7
  Dates are the npm publish date. Each entry names the RTSC issue behind it.
8
8
 
9
+ ## 1.21.1 (2026-08-10)
10
+
11
+ - **RTSC-643** — `retasc gate install` keys the gate to **this folder's** project, not the
12
+ machine-wide default. It used to read `defaultProjectPrefix` (stamped by whichever project
13
+ you last ran `retasc init` for), so in a bound folder it could install a commit gate keyed
14
+ to a different project — rejecting every valid commit — while reporting success. It now asks
15
+ the folder's own binding first (`whoami` over the workspace key, or the keystore's cached
16
+ prefix offline; a subdirectory run checks the git toplevel too), prints where the prefix
17
+ came from, warns when the global default disagrees, and only uses the global default when
18
+ the folder is genuinely unbound. Bound-but-unresolvable fails loudly instead of guessing.
19
+
9
20
  ## 1.21.0 (2026-08-07)
10
21
 
11
22
  - **RTSC-527** — the re-import warning dates the last import in **your** timezone. The day
@@ -1,6 +1,81 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { mkdirSync, writeFileSync, existsSync, chmodSync } from "node:fs";
3
3
  import { join, dirname } from "node:path";
4
+ import { resolveMcpConn, readMcpJson, workspacePrefix } from "../lib/claim.js";
5
+ import { claudeLocalRetascEntry } from "../lib/binding.js";
6
+ import { getBinding } from "../lib/keystore.js";
7
+ /** The keystore's stored prefix for the workspace marker at `dir`, if any —
8
+ * the offline fallback when the server can't be asked. Entry selection matches
9
+ * resolveConn: env workspace id first, then claude-local, then the folder
10
+ * marker. The cache answers ONLY for the key the live path would have asked
11
+ * (`b.key === conn.key`) — an env-selected key from a different org must not
12
+ * inherit this folder's cached prefix. */
13
+ function storedPrefix(dir, conn, env = process.env) {
14
+ const entry = claudeLocalRetascEntry(dir) ?? readMcpJson(dir)?.mcpServers?.retasc;
15
+ const wsId = env.RETASC_WORKSPACE || entry?.env?.RETASC_WORKSPACE;
16
+ const b = wsId ? getBinding(String(wsId)) : undefined;
17
+ if (!b || b.key !== conn.key)
18
+ return undefined;
19
+ return typeof b.prefix === "string" && b.prefix ? b.prefix : undefined;
20
+ }
21
+ /** Server/keystore-derived text is validated BEFORE it's printed or trusted
22
+ * (same rule as whoami's control-char strip) — a malformed value is treated
23
+ * as unresolved, never echoed to the terminal. */
24
+ function validPrefix(p) {
25
+ if (typeof p !== "string")
26
+ return undefined;
27
+ const up = p.toUpperCase();
28
+ return PREFIX_RE.test(up) ? up : undefined;
29
+ }
30
+ /** whoami must never hang gate install — same 10s bound as resolveBinding
31
+ * (binding.ts), which bare global fetch does not carry. */
32
+ const fetchWithTimeout = (input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(10_000) });
33
+ /**
34
+ * Resolve the prefix the gate is keyed to, folder-first (RTSC-643). The global
35
+ * `defaultProjectPrefix` is written only by `retasc init` — it's "whatever
36
+ * project you last init-ed", which in a bound folder can be a DIFFERENT
37
+ * workspace's prefix. So the folder's own binding is authoritative (whoami over
38
+ * the workspace's key, or the keystore's cached prefix offline), and the global
39
+ * default is consulted only when the folder is unbound. A bound folder whose
40
+ * prefix can't be resolved fails loudly rather than guessing: a gate keyed to
41
+ * the wrong project rejects every valid commit and ships to CI.
42
+ */
43
+ export async function resolveGatePrefix(opts) {
44
+ // `!== undefined` so `--prefix ""` (an unset shell var) still reaches
45
+ // installGate's validator and fails loudly instead of silently resolving.
46
+ if (opts.flag !== undefined)
47
+ return { prefix: opts.flag.toUpperCase(), source: "--prefix" };
48
+ const cfgDefault = opts.defaultPrefix?.toUpperCase();
49
+ // The gate is written at the git toplevel, so when the cwd (a subdirectory)
50
+ // carries no binding, look at the toplevel too — otherwise a subdir run would
51
+ // silently fall back to the global default behind a false "isn't bound".
52
+ const dirs = opts.dir
53
+ ? [opts.dir]
54
+ : Array.from(new Set([process.cwd(), repoRoot()].filter((d) => !!d)));
55
+ let conn;
56
+ let boundDir = dirs[0];
57
+ for (const d of dirs) {
58
+ const c = resolveMcpConn({ env: opts.env, mcpJson: readMcpJson(d), dir: d });
59
+ if (c.key) {
60
+ conn = c;
61
+ boundDir = d;
62
+ break;
63
+ }
64
+ }
65
+ if (conn) {
66
+ const live = validPrefix(await workspacePrefix(conn, opts.fetchImpl ?? fetchWithTimeout));
67
+ const prefix = live ?? validPrefix(storedPrefix(boundDir, conn, opts.env));
68
+ if (prefix) {
69
+ const source = live ? "workspace binding" : "workspace binding (cached)";
70
+ const shadowed = cfgDefault && cfgDefault !== prefix ? cfgDefault : undefined;
71
+ return shadowed ? { prefix, source, shadowedDefault: shadowed } : { prefix, source };
72
+ }
73
+ throw new Error("this folder is bound, but its project prefix couldn't be resolved (server didn't answer, no cached prefix) — pass --prefix <PREFIX>.");
74
+ }
75
+ if (cfgDefault)
76
+ return { prefix: cfgDefault, source: "global config" };
77
+ throw new Error("no project prefix — pass --prefix <PREFIX>, or bind this folder (`retasc bind`) / run `retasc init` so it's resolved from your project.");
78
+ }
4
79
  // Mirror the server's project-prefix rule (convex/manage.ts PREFIX_RE): 2–10
5
80
  // chars, A–Z/0–9, letter-first. The prefix is interpolated into a generated
6
81
  // bash hook and a YAML grep, so validating here keeps a stray value from
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { Command } from "commander";
3
3
  import { VERSION } from "./version.js";
4
4
  import { loadConfig, patchConfig, saveConfig, configPath, isLoggedIn } from "./config.js";
5
5
  import { installMcp, normalizeScope } from "./commands/mcp.js";
6
- import { installGate } from "./commands/gate.js";
6
+ import { installGate, resolveGatePrefix } from "./commands/gate.js";
7
7
  import { claimAction } from "./commands/claim.js";
8
8
  import { bindAction, setupFromToken } from "./commands/bind.js";
9
9
  import { joinAction } from "./commands/join.js";
@@ -491,16 +491,27 @@ const gate = program.command("gate").description("Wire the commit↔issue tracea
491
491
  gate
492
492
  .command("install")
493
493
  .description("Install a prefix-correct commit-msg hook + check-commit-message Action into this repo.")
494
- .option("--prefix <PREFIX>", "Project prefix to enforce (default: your configured project)")
494
+ .option("--prefix <PREFIX>", "Project prefix to enforce (default: this folder's bound project)")
495
495
  .option("--no-hook", "Skip the local commit-msg hook (CI Action only)")
496
496
  .option("--no-action", "Skip the GitHub Action (local hook only)")
497
- .action((opts) => {
497
+ .action(async (opts) => {
498
498
  try {
499
- const prefix = (opts.prefix ?? loadConfig().defaultProjectPrefix)?.toUpperCase();
500
- if (!prefix) {
501
- return fail("no project prefix — pass --prefix <PREFIX>, or run `retasc init`/`login` so it's resolved from your project.");
499
+ // RTSC-643: folder-first the binding is the authoritative identity; the
500
+ // global default (stamped by the last `retasc init`) applies only when the
501
+ // folder is unbound.
502
+ const r = await resolveGatePrefix({
503
+ flag: opts.prefix,
504
+ defaultPrefix: loadConfig().defaultProjectPrefix,
505
+ });
506
+ if (r.source !== "--prefix")
507
+ console.log(`Prefix ${r.prefix} — from ${r.source}.`);
508
+ if (r.source === "global config") {
509
+ console.log(" (This folder isn't bound — `retasc bind` makes the prefix folder-scoped.)");
510
+ }
511
+ if (r.shadowedDefault) {
512
+ console.log(` ⚠ Ignoring global default prefix ${r.shadowedDefault} — this folder's binding wins.`);
502
513
  }
503
- installGate({ prefix, layers: { hook: opts.hook, action: opts.action } });
514
+ installGate({ prefix: r.prefix, layers: { hook: opts.hook, action: opts.action } });
504
515
  }
505
516
  catch (e) {
506
517
  fail(e);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@retasc/cli",
3
- "version": "1.21.0",
4
- "description": "Retasc CLI \u2014 the issue tracker AI agents pull work from. Sign in with GitHub or Google, create projects, mint agent API keys, and wire your agent to the Retasc MCP server in one command.",
3
+ "version": "1.21.1",
4
+ "description": "Retasc CLI the issue tracker AI agents pull work from. Sign in with GitHub or Google, create projects, mint agent API keys, and wire your agent to the Retasc MCP server in one command.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "retasc": "dist/index.js"