)]}'
{
  "commit": "4a055c57328b47ebf3b02530b2e9fb723108fde3",
  "tree": "3776a645f6d7a2471989496130ce02ed70e8cf78",
  "parents": [
    "e59a2e151da777fba13a0978c00c16a1ee3b6122"
  ],
  "author": {
    "name": "banksean",
    "email": "banksean@gmail.com",
    "time": "Sat Jun 28 22:15:32 2025 +0000"
  },
  "committer": {
    "name": "banksean",
    "email": "banksean@gmail.com",
    "time": "Sat Jun 28 22:17:30 2025 +0000"
  },
  "message": "sketch: fix MCP server connection error in -unsafe mode by setting SKETCH_PUB_KEY environment variable\n\nFix MCP server connection failure with \u0027no Public-Key\u0027 status 400 error when running sketch -unsafe with skaband integration, by properly setting the SKETCH_PUB_KEY environment variable for MCP authentication placeholder replacement.\n\nProblems Solved:\n\nMCP Authentication Failure:\n- Running sketch -unsafe with skaband connection fails with \u0027MCP server connection failed: MCP server \"sketchdev\": failed to initialize MCP client: transport error: request failed with status 400: no Public-Key\u0027\n- setupAndRunAgent receives pubKey parameter from skaband login but doesn\u0027t set SKETCH_PUB_KEY environment variable\n- MCP placeholder replacement in agent.go expects SKETCH_PUB_KEY environment variable to replace \u0027_sketch_public_key_\u0027 placeholder\n- Empty placeholder replacement results in missing Public-Key header in MCP requests\n\nAuthentication Flow Gap:\n- Container mode sets SKETCH_PUB_KEY from environment in runInContainerMode\n- Unsafe mode obtains pubKey from skabandclient.Login but doesn\u0027t propagate to environment\n- setupAndRunAgent receives pubKey parameter but doesn\u0027t use it for environment variable setup\n- MCP configuration uses \u0027_sketch_public_key_\u0027 placeholder expecting environment variable replacement\n\nSolution Implementation:\n\nEnvironment Variable Setup:\n- Added SKETCH_PUB_KEY environment variable setting in setupAndRunAgent when pubKey is provided\n- Check for non-empty pubKey before setting environment variable to avoid overwriting existing values\n- Environment variable set early in setupAndRunAgent before MCP server initialization\n- Maintains consistent behavior between container and unsafe modes\n\nAuthentication Flow Completion:\n- Container mode: SKETCH_PUB_KEY set from container environment → MCP placeholder replacement\n- Unsafe mode: pubKey from skaband login → SKETCH_PUB_KEY environment variable → MCP placeholder replacement\n- Both modes now have complete authentication flow for MCP server connections\n- MCP requests include proper Public-Key header for skaband authentication\n\nImplementation Details:\n\nCode Changes:\n- Added conditional os.Setenv(\u0027SKETCH_PUB_KEY\u0027, pubKey) in setupAndRunAgent\n- Placement before working directory setup ensures early environment configuration\n- Only sets environment variable when pubKey is non-empty string\n- Preserves existing environment if pubKey is empty to avoid overwrites\n\nTest Coverage:\n- Added TestSetupAndRunAgent_SetsPubKeyEnvVar to verify environment variable setting\n- Added TestSetupAndRunAgent_DoesNotSetEmptyPubKey to verify empty pubKey handling\n- Tests verify environment variable setting and preservation behavior\n- Comprehensive coverage of both positive and negative scenarios\n\nError Resolution:\n- MCP server requests now include proper Public-Key header\n- skaband /api/mcp endpoint receives authentication for session validation\n- Eliminates \u0027no Public-Key\u0027 400 status errors in unsafe mode\n- Maintains existing container mode behavior without changes\n\nFiles Modified:\n- sketch/cmd/sketch/main.go: Added SKETCH_PUB_KEY environment variable setting in setupAndRunAgent\n- sketch/cmd/sketch/main_test.go: Added test coverage for pubKey environment variable behavior\n\nThe fix ensures consistent MCP server authentication across both container and unsafe execution modes by properly propagating the public key from skaband login to the MCP placeholder replacement system.\n\nCo-Authored-By: sketch \u003chello@sketch.dev\u003e\nChange-ID: s2564fc63bdd663a0k\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "637aaabc12422cb3aebc49a92debef88f869c059",
      "old_mode": 33188,
      "old_path": "cmd/sketch/main.go",
      "new_id": "5ca33959aa6d00436bead6cf205f738f61e17a7a",
      "new_mode": 33188,
      "new_path": "cmd/sketch/main.go"
    },
    {
      "type": "modify",
      "old_id": "3ebd05de67fd0b1fc22c11dc3c22e8d718ea2c43",
      "old_mode": 33188,
      "old_path": "cmd/sketch/main_test.go",
      "new_id": "10ca1e08e72681dbbcc0035d2958b63d3bd84eb5",
      "new_mode": 33188,
      "new_path": "cmd/sketch/main_test.go"
    }
  ]
}
