@hasna/switcher 0.1.6 → 0.1.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/README.md CHANGED
@@ -96,6 +96,18 @@ switcher launch claude --provider deepseek --model deepseek-v4-pro
96
96
 
97
97
  `--vault-cli /absolute/path/to/secrets` selects a particular installation. Vault lookup uses `secrets exec` to inject the value into a short-lived receiver, which delivers it over an authenticated loopback connection. Values stay in process memory. The lookup has a 20-second deadline and owns a separate process group; it finishes before the native harness starts. Each lookup reads the vault again. Conflicting Secrets service URL configuration fails explicitly. Vault CLI bindings currently require POSIX; Windows callers can inject provider environment variables.
98
98
 
99
+ If launch reports `vault_exec_permissions`, verify the installed Secrets package against its trusted release artifact before repairing it. Bun 1.3.14's [bin-link installer](https://github.com/oven-sh/bun/blob/bun-v1.3.14/src/install/bin.zig#L731-L735) can change an executable member from mode `0755` to `0777`, including with `--ignore-scripts`. Changing the shell umask does not correct that installer behavior.
100
+
101
+ After validating the package archive against its registry integrity, compute the SHA256 of the executable member **inside that verified archive**. Use that expected digest to finalize the existing binding's installed executable:
102
+
103
+ ```sh
104
+ switcher credentials repair-executable deepseek --sha256 EXPECTED_EXECUTABLE_SHA256
105
+ ```
106
+
107
+ For a fresh installation whose unsafe executable prevents creating a binding, use `switcher credentials repair-executable --vault-cli /absolute/path/to/secrets --sha256 EXPECTED_EXECUTABLE_SHA256` first, then bind normally. Select either a binding reference or an explicit path.
108
+
109
+ The digest is a release-artifact checksum, not a credential. Do not substitute the installed file's own hash: that would trust any altered bytes. Repair checks the exact bytes, file owner/type and every path ancestor, then creates an identical private copy and atomically replaces the writable executable with group/public write permission removed. Cache hardlinks and already-open writers retain the old inode and cannot change the repaired executable. It then runs the ordinary launch checks again. Safe files are unchanged; digest mismatches, unsafe ancestors and unowned files are refused. The command never starts Secrets, contacts the vault, changes bindings, or repairs permissions automatically during launch. Run this explicit step after each affected installation; a later Bun install can reset bin modes again. Reinstall a verified package if its bytes differ.
110
+
99
111
  For provider keys already stored in macOS Keychain, use `--keychain-service SERVICE --keychain-account ACCOUNT` instead of vault options. Bindings contain only references and authorized origins under `~/.hasna/switcher/config/credential-bindings`, in owner-only files. They remain local even when Switcher uses a remote API. A configured binding takes precedence over environment aliases; an unavailable binding never falls back to another account.
100
112
 
101
113
  `credentials list` displays bindings; `credentials remove PRESET_OR_REFERENCE` removes only the locator. Replacement requires explicit removal. Custom credential references require `--origin URL` (repeatable); preset bindings authorize their documented origins by default. `credentials check` reports availability, length and hash, not successful provider authentication. Provider credentials needed by a remote API's catalog discovery must still be configured on that server independently.
package/dist/cli/index.js CHANGED
@@ -499,7 +499,7 @@ function canonicalPolicyJSON(value) {
499
499
  }
500
500
 
501
501
  // src/domain.ts
502
- var VERSION = "0.1.6";
502
+ var VERSION = "0.1.7";
503
503
  var harnessSchema = z3.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
504
504
  var protocolSchema = z3.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
505
505
  var idSchema = z3.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -2178,7 +2178,7 @@ var openapi_default = {
2178
2178
  openapi: "3.0.3",
2179
2179
  info: {
2180
2180
  title: "Switcher API",
2181
- version: "0.1.6",
2181
+ version: "0.1.7",
2182
2182
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
2183
2183
  },
2184
2184
  security: [
@@ -10571,7 +10571,7 @@ async function ensureLaunchProfile(client, provider, harness, model3, modelPolic
10571
10571
  // src/credentials.ts
10572
10572
  import { z as z6 } from "zod";
10573
10573
  import { constants as constants5 } from "fs";
10574
- import { open as open3, readdir as readdir5, unlink, link, lstat as lstat4, access as access3, stat as stat5, realpath as realpath6, readlink } from "fs/promises";
10574
+ import { open as open3, readdir as readdir5, unlink, link, lstat as lstat4, access as access3, stat as stat5, realpath as realpath6, readlink, rename as rename2 } from "fs/promises";
10575
10575
  import { join as join13, isAbsolute as isAbsolute12, dirname as dirname8, parse as pathParts, resolve as resolvePath, sep as sep2 } from "path";
10576
10576
  import { createHash as createHash10, randomUUID as randomUUID5 } from "crypto";
10577
10577
  import { execFile as execFile3, spawn as spawn2 } from "child_process";
@@ -10723,7 +10723,7 @@ function credentialReference(selector) {
10723
10723
  throw new Fault(400, "credential_reference_required", "Use the explicit SWITCHER_PROVIDER_ reference for this provider.");
10724
10724
  return parse2(reference, name);
10725
10725
  }
10726
- async function validateVaultExecutable(path) {
10726
+ async function inspectVaultExecutable(path, permitWritableFile = false) {
10727
10727
  let info, resolved;
10728
10728
  try {
10729
10729
  resolved = await realpath6(path);
@@ -10734,8 +10734,8 @@ async function validateVaultExecutable(path) {
10734
10734
  } catch {
10735
10735
  throw new Fault(422, "vault_exec_unavailable", "The configured secrets CLI must be an installed executable file. Use --vault-cli with its absolute path.");
10736
10736
  }
10737
- if (process.platform !== "win32" && (info.mode & 18 || info.uid !== 0 && info.uid !== process.getuid?.()))
10738
- throw new Fault(422, "vault_exec_permissions", "The secrets executable must be owned by this user or root and not writable by other users. Remove group/public write permission from its resolved file or choose a trusted installation.");
10737
+ if (process.platform !== "win32" && (!permitWritableFile && info.mode & 18 || info.uid !== 0 && info.uid !== process.getuid?.()))
10738
+ throw new Fault(422, "vault_exec_permissions", "The secrets executable must be owned by this user or root and not writable by other users. Choose a trusted installation, or use credentials repair-executable REFERENCE --sha256 EXPECTED with the executable digest from a verified package artifact. Launch never repairs permissions automatically.");
10739
10739
  if (process.platform !== "win32") {
10740
10740
  const seen = new Set;
10741
10741
  const inspect = async (candidate) => {
@@ -10750,7 +10750,8 @@ async function validateVaultExecutable(path) {
10750
10750
  if (seen.size > 256)
10751
10751
  throw new Fault(422, "vault_exec_permissions", "The secrets executable path has too many symlink components.");
10752
10752
  const entry = await lstat4(prefix);
10753
- if (entry.uid !== 0 && entry.uid !== process.getuid?.() || !entry.isSymbolicLink() && entry.mode & 18)
10753
+ const permittedFile = permitWritableFile && prefix === resolved && entry.isFile();
10754
+ if (entry.uid !== 0 && entry.uid !== process.getuid?.() || !entry.isSymbolicLink() && !permittedFile && entry.mode & 18)
10754
10755
  throw new Fault(422, "vault_exec_permissions", "The secrets executable and its ancestor directories must not be replaceable by other users. Choose an installation owned by this user or root without group/public write permissions.");
10755
10756
  if (entry.isSymbolicLink())
10756
10757
  await inspect(resolvePath(dirname8(prefix), await readlink(prefix)));
@@ -10767,6 +10768,88 @@ async function validateVaultExecutable(path) {
10767
10768
  }
10768
10769
  return resolved;
10769
10770
  }
10771
+ async function validateVaultExecutable(path) {
10772
+ return inspectVaultExecutable(path);
10773
+ }
10774
+ async function repairVaultExecutablePermissions(path, expectedSha256) {
10775
+ if (!/^[a-f0-9]{64}$/.test(expectedSha256))
10776
+ throw new Fault(400, "invalid_request", "--sha256 requires the SHA256 of the executable member from a verified package artifact.");
10777
+ if (!isAbsolute12(path) || path.length > 4096 || /[\x00-\x1f\x7f]/.test(path))
10778
+ throw new Fault(400, "invalid_request", "Secrets executable must be an absolute path without control characters.");
10779
+ if (process.platform === "win32")
10780
+ throw new Fault(422, "vault_exec_repair_unsafe", "Executable permission repair requires POSIX file permissions.");
10781
+ const resolved = await inspectVaultExecutable(path, true);
10782
+ const file = await open3(resolved, constants5.O_RDONLY | constants5.O_NOFOLLOW | constants5.O_NONBLOCK);
10783
+ const unsafe = () => new Fault(422, "vault_exec_repair_unsafe", "Executable ownership, type, links or contents changed; no trusted repair can be confirmed.");
10784
+ let temporary;
10785
+ try {
10786
+ const before = await file.stat();
10787
+ const limit = 256 * 1024 * 1024;
10788
+ if (!before.isFile() || before.uid !== process.getuid?.() || before.size > limit || before.mode & 3584)
10789
+ throw unsafe();
10790
+ const sameFile = (info) => info.dev === before.dev && info.ino === before.ino && info.size === before.size && info.uid === before.uid && info.nlink === before.nlink && info.mode === before.mode && info.mtimeMs === before.mtimeMs && info.ctimeMs === before.ctimeMs;
10791
+ const hash2 = async (target) => {
10792
+ const digest = createHash10("sha256");
10793
+ const buffer = Buffer.alloc(1024 * 1024);
10794
+ let position = 0;
10795
+ while (true) {
10796
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, position);
10797
+ if (!bytesRead)
10798
+ break;
10799
+ position += bytesRead;
10800
+ if (position > limit)
10801
+ throw unsafe();
10802
+ const bytes = buffer.subarray(0, bytesRead);
10803
+ digest.update(bytes);
10804
+ if (target)
10805
+ await target.writeFile(bytes);
10806
+ }
10807
+ if (position !== before.size || !sameFile(await file.stat()))
10808
+ throw unsafe();
10809
+ if (digest.digest("hex") !== expectedSha256)
10810
+ throw new Fault(422, "vault_exec_digest_mismatch", "Installed executable differs from the trusted artifact digest. Reinstall the verified package; no credential was accessed.");
10811
+ };
10812
+ await hash2();
10813
+ const mode = before.mode & 511 & ~18;
10814
+ const changed = mode !== (before.mode & 511);
10815
+ if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat4(resolved)))
10816
+ throw unsafe();
10817
+ if (!changed) {
10818
+ await validateVaultExecutable(path);
10819
+ return { changed, mode: mode.toString(8).padStart(4, "0"), sha256: expectedSha256 };
10820
+ }
10821
+ temporary = join13(dirname8(resolved), `.switcher-repair-${randomUUID5()}`);
10822
+ const replacement = await open3(temporary, "wx", 384);
10823
+ try {
10824
+ await hash2(replacement);
10825
+ await replacement.chmod(mode);
10826
+ await replacement.sync();
10827
+ const ready = await replacement.stat();
10828
+ if (!ready.isFile() || ready.nlink !== 1 || ready.uid !== before.uid || ready.size !== before.size)
10829
+ throw unsafe();
10830
+ if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat4(resolved)))
10831
+ throw unsafe();
10832
+ await rename2(temporary, resolved);
10833
+ temporary = undefined;
10834
+ const installed = await lstat4(resolved);
10835
+ if (installed.dev !== ready.dev || installed.ino !== ready.ino || await validateVaultExecutable(path) !== resolved)
10836
+ throw unsafe();
10837
+ const directory = await open3(dirname8(resolved), constants5.O_RDONLY | constants5.O_DIRECTORY | constants5.O_NOFOLLOW);
10838
+ try {
10839
+ await directory.sync();
10840
+ } finally {
10841
+ await directory.close();
10842
+ }
10843
+ } finally {
10844
+ await replacement.close();
10845
+ }
10846
+ return { changed, mode: mode.toString(8).padStart(4, "0"), sha256: expectedSha256 };
10847
+ } finally {
10848
+ await file.close();
10849
+ if (temporary)
10850
+ await unlink(temporary);
10851
+ }
10852
+ }
10770
10853
  function bindingTarget(selector, override, allowedOrigins) {
10771
10854
  if (selector.startsWith("SWITCHER_PROVIDER_")) {
10772
10855
  if (override)
@@ -11034,6 +11117,8 @@ var HELP = `switcher \u2014 launch a coding harness with a provider and its mode
11034
11117
  [--vault-cli PATH] [--vault-account ACCOUNT | --vault-operator env]
11035
11118
  switcher credentials bind PRESET --keychain-service SERVICE --keychain-account ACCOUNT
11036
11119
  switcher credentials list|check|remove [PRESET_OR_REFERENCE]
11120
+ switcher credentials repair-executable PRESET_OR_REFERENCE --sha256 EXPECTED
11121
+ switcher credentials repair-executable --vault-cli PATH --sha256 EXPECTED
11037
11122
  switcher doctor
11038
11123
 
11039
11124
  HARNESS: claude, codex, grok, opencode, opencode2, pi, omp, dsh, cline, hermes, prime-agent, gemini, aider, kilo
@@ -11049,6 +11134,8 @@ Vault bindings use the installed secrets CLI and its canonical Contracts URL/key
11049
11134
  by default. --vault-account pins a Keychain account; --vault-operator env requires
11050
11135
  per-process HASNA_SECRETS_API_KEY. Explicit operators also require --vault-url.
11051
11136
  --file accepts a JSON object including id; raw credentials are never accepted.
11137
+ Executable repair requires the digest of its member in a verified package artifact.
11138
+ It replaces writable installed bytes with an identical protected copy; it does not contact the vault.
11052
11139
  Fireworks discovery requires --catalog-account-id (or an explicit --catalog-url).
11053
11140
  --json outputs machine-readable records (also the default for data commands).
11054
11141
  switcher --version | --help
@@ -11093,6 +11180,7 @@ async function main(args = process.argv.slice(2)) {
11093
11180
  version: { type: "string" },
11094
11181
  json: { type: "boolean" },
11095
11182
  url: { type: "string" },
11183
+ sha256: { type: "string" },
11096
11184
  protocol: { type: "string" },
11097
11185
  preset: { type: "string" },
11098
11186
  name: { type: "string" },
@@ -11149,7 +11237,23 @@ async function main(args = process.argv.slice(2)) {
11149
11237
  const modelAddition = addingModel ? parse2(modelSchema, { id: positionals[3], name: values2.name ?? positionals[3], expiresOn: values2["expires-on"] }) : undefined;
11150
11238
  const credentialFlags = ["vault-key", "vault-url", "vault-cli", "vault-account", "vault-operator", "keychain-service", "keychain-account", "origin"];
11151
11239
  const credentials = new CredentialResolver;
11240
+ if (values2.sha256 !== undefined && !(command === "credentials" && action2 === "repair-executable"))
11241
+ throw new Fault(400, "conflicting_options", "--sha256 belongs to credentials repair-executable.");
11152
11242
  if (command === "credentials") {
11243
+ if (action2 === "repair-executable") {
11244
+ const explicitPath = values2["vault-cli"];
11245
+ if (Boolean(id2) === (explicitPath !== undefined) || positionals.length !== (id2 ? 3 : 2) || nativeArgs.length || Object.keys(values2).some((name) => !["sha256", "json", "vault-cli"].includes(name)) || !/^[a-f0-9]{64}$/.test(values2.sha256 ?? ""))
11246
+ throw new Fault(400, "invalid_request", "Use credentials repair-executable PRESET_OR_REFERENCE (or --vault-cli PATH) --sha256 EXPECTED, with the executable digest from a verified package artifact.");
11247
+ let executable = explicitPath;
11248
+ if (id2) {
11249
+ const binding = await credentials.bindings.get(credentialReference(id2));
11250
+ if (!binding || binding.source.kind !== "vault")
11251
+ throw new Fault(422, "vault_binding_required", "Choose an existing vault credential binding to repair its configured executable.");
11252
+ executable = binding.source.executable;
11253
+ }
11254
+ output(await repairVaultExecutablePermissions(executable, values2.sha256));
11255
+ return;
11256
+ }
11153
11257
  const bindingFlags = [...credentialFlags, "credential-env"];
11154
11258
  if (nativeArgs.length || positionals.length > 3 || Object.keys(values2).some((name) => name !== "json" && !bindingFlags.includes(name)))
11155
11259
  throw new Fault(400, "conflicting_options", "Credentials accepts only binding options; no API, profile or harness settings.");
@@ -211,6 +211,18 @@ export declare class CredentialBindings {
211
211
  }
212
212
  export declare function credentialReference(selector: string): string;
213
213
  export declare function validateVaultExecutable(path: string): Promise<string>;
214
+ /** Explicit install finalization. The caller supplies a digest from a verified
215
+ * artifact, never a digest computed from the currently installed executable.
216
+ * No credential is resolved and the executable is never started. */
217
+ export declare function repairVaultExecutablePermissions(path: string, expectedSha256: string): Promise<{
218
+ changed: false;
219
+ mode: string;
220
+ sha256: string;
221
+ } | {
222
+ changed: true;
223
+ mode: string;
224
+ sha256: string;
225
+ }>;
214
226
  export declare function bindingTarget(selector: string, override?: string, allowedOrigins?: string[]): {
215
227
  credentialEnv: string;
216
228
  origins: string[];
package/dist/domain.d.ts CHANGED
@@ -3,7 +3,7 @@ import { type RoutingEvent } from "./model-policy-schema";
3
3
  export { modelPolicySchema, routingEventSchema, routingEventsSchema } from "./model-policy-schema";
4
4
  export type { ModelPolicy, RoutingEvent } from "./model-policy-schema";
5
5
  export type { AuthStyle } from "./auth";
6
- export declare const VERSION = "0.1.6";
6
+ export declare const VERSION = "0.1.7";
7
7
  export declare const harnessSchema: z.ZodEnum<["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]>;
8
8
  export declare const protocolSchema: z.ZodEnum<["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]>;
9
9
  export declare const idSchema: z.ZodString;
package/dist/mcp/index.js CHANGED
@@ -55,7 +55,7 @@ var routingEventSchema = z.object({
55
55
  var routingEventsSchema = z.array(routingEventSchema).max(1000);
56
56
 
57
57
  // src/domain.ts
58
- var VERSION = "0.1.6";
58
+ var VERSION = "0.1.7";
59
59
  var harnessSchema = z2.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
60
60
  var protocolSchema = z2.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
61
61
  var idSchema = z2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -62,7 +62,7 @@ function canonicalPolicyJSON(value) {
62
62
  }
63
63
 
64
64
  // src/domain.ts
65
- var VERSION = "0.1.6";
65
+ var VERSION = "0.1.7";
66
66
  var harnessSchema = z2.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
67
67
  var protocolSchema = z2.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
68
68
  var idSchema = z2.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
@@ -830,7 +830,7 @@ var openapi_default = {
830
830
  openapi: "3.0.3",
831
831
  info: {
832
832
  title: "Switcher API",
833
- version: "0.1.6",
833
+ version: "0.1.7",
834
834
  description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
835
835
  },
836
836
  security: [
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.0.3",
3
3
  "info": {
4
4
  "title": "Switcher API",
5
- "version": "0.1.6",
5
+ "version": "0.1.7",
6
6
  "description": "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7
7
  },
8
8
  "security": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
6
6
  "license": "Apache-2.0",