From d3a2b9faaec4bbed4554c9fc3169c14cee7d5409 Mon Sep 17 00:00:00 2001 From: Stefano Fiorini Date: Tue, 10 Mar 2026 00:35:25 -0500 Subject: [PATCH] feat: prefer workspace key path for google maps --- docs/google-maps.md | 5 +- ...gle-maps-workspace-key-repo-sync-design.md | 33 +++++++ ...-10-google-maps-workspace-key-repo-sync.md | 92 +++++++++++++++++++ integrations/google-maps/traffic.js | 19 ++-- 4 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md create mode 100644 docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md diff --git a/docs/google-maps.md b/docs/google-maps.md index 20446d3..58d6930 100644 --- a/docs/google-maps.md +++ b/docs/google-maps.md @@ -18,7 +18,10 @@ Google Maps traffic/ETA helper CLI using Geocoding API and Routes API. Preferred: - `GOOGLE_MAPS_API_KEY` environment variable -Fallback key file: +Preferred key file: +- `~/.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt` + +Legacy fallback key file: - `~/.openclaw/credentials/google-maps/apikey.txt` Required Google APIs for the key: diff --git a/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md b/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md new file mode 100644 index 0000000..e4e57fd --- /dev/null +++ b/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md @@ -0,0 +1,33 @@ +# Google Maps Workspace Key Repo Sync Design + +**Problem:** The live local `google-maps` integration was updated to prefer the workspace credential path for the API key, but the repository source copy still points at the legacy path. The docs were partially updated, and the repo needs to be the source of truth again before committing and pushing. + +## Current state + +- Live local integration [traffic.js](/Users/stefano/.openclaw/workspace/integrations/google-maps/traffic.js) prefers: + - `~/.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt` + - with legacy fallback `~/.openclaw/credentials/google-maps/apikey.txt` +- Repo copy [traffic.js](/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/integrations/google-maps/traffic.js) still points only at the legacy path. +- Repo doc [google-maps.md](/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/google-maps.md) now documents the new canonical path and legacy fallback. + +## Approaches considered + +1. Recommended: sync the repo source copy to match the live integration exactly and keep the docs aligned. + - Minimal change. + - Restores source/runtime consistency. + - Safe to commit and push. + +2. Revert the live integration to match the repo. + - Wrong direction because the live behavior is already verified and desired. + +3. Update only docs and leave source drift. + - Not acceptable because the repository would remain misleading. + +## Selected design + +- Update the repo copy of `integrations/google-maps/traffic.js` to match the live integration behavior: + - prefer `~/.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt` + - keep `~/.openclaw/credentials/google-maps/apikey.txt` as legacy fallback +- Keep the repo docs aligned with that behavior. +- Verify the repo copy via code inspection and a live ETA command using the runtime integration. +- Commit only the repo changes and push to `origin/main`. diff --git a/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md b/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md new file mode 100644 index 0000000..9c065e1 --- /dev/null +++ b/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md @@ -0,0 +1,92 @@ +# Google Maps Workspace Key Repo Sync Implementation Plan + +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. + +**Goal:** Sync the `stef-openclaw-skills` repository source and docs with the verified Google Maps workspace-key behavior, then commit and push the change. + +**Architecture:** Apply the same path-resolution change from the live integration to the repo copy, keep the docs aligned, and verify behavior with inspection plus a live ETA command. Commit only the repo files that reflect this feature. + +**Tech Stack:** Node.js CLI, local file path resolution, git + +--- + +### Task 1: Sync repo source copy + +**Files:** +- Modify: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/integrations/google-maps/traffic.js` + +**Step 1: Write the failing check** + +Run: +```bash +sed -n '1,50p' /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/integrations/google-maps/traffic.js +``` +Expected: only the legacy path is present and there is no workspace credential fallback array. + +**Step 2: Write minimal implementation** + +Apply the same path lookup logic as the live local integration: +- prefer `~/.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt` +- keep `~/.openclaw/credentials/google-maps/apikey.txt` as fallback +- keep `GOOGLE_MAPS_API_KEY` support unchanged + +**Step 3: Verify source sync** + +Run: +```bash +sed -n '1,60p' /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/integrations/google-maps/traffic.js +``` +Expected: workspace path is primary and legacy path remains fallback. + +### Task 2: Verify docs alignment + +**Files:** +- Modify or confirm: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/google-maps.md` + +**Step 1: Verify doc text** + +Run: +```bash +sed -n '1,80p' /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/google-maps.md +``` +Expected: docs show workspace key path as preferred and legacy path as fallback. + +### Task 3: Verify behavior and publish + +**Files:** +- Commit: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/integrations/google-maps/traffic.js` +- Commit: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/google-maps.md` +- Commit: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md` +- Commit: `/Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills/docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md` + +**Step 1: Run live verification** + +Run: +```bash +node /Users/stefano/.openclaw/workspace/integrations/google-maps/traffic.js eta --from "DFW Airport" --to "Downtown Dallas" --departAt now +``` +Expected: JSON ETA output succeeds with the workspace key file. + +**Step 2: Inspect git diff** + +Run: +```bash +git -C /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills diff -- integrations/google-maps/traffic.js docs/google-maps.md docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md +``` +Expected: only the intended repo sync changes appear. + +**Step 3: Commit** + +Run: +```bash +git -C /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills add integrations/google-maps/traffic.js docs/google-maps.md docs/plans/2026-03-10-google-maps-workspace-key-repo-sync-design.md docs/plans/2026-03-10-google-maps-workspace-key-repo-sync.md && git -C /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills commit -m "docs: sync google maps workspace key path" +``` +Expected: commit succeeds. + +**Step 4: Push** + +Run: +```bash +git -C /Users/stefano/.openclaw/workspace/projects/stef-openclaw-skills push origin main +``` +Expected: push succeeds. diff --git a/integrations/google-maps/traffic.js b/integrations/google-maps/traffic.js index 5e6874a..ff86626 100755 --- a/integrations/google-maps/traffic.js +++ b/integrations/google-maps/traffic.js @@ -2,7 +2,11 @@ const fs = require('fs'); const path = require('path'); -const DEFAULT_KEY_PATH = path.join(process.env.HOME || '', '.openclaw/credentials/google-maps/apikey.txt'); +const DEFAULT_KEY_PATH = path.join(process.env.HOME || '', '.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt'); +const FALLBACK_KEY_PATHS = [ + DEFAULT_KEY_PATH, + path.join(process.env.HOME || '', '.openclaw/credentials/google-maps/apikey.txt'), +]; function parseArgs(argv) { const out = { _: [] }; @@ -44,11 +48,14 @@ function must(opts, keys) { function readApiKey(opts) { if (process.env.GOOGLE_MAPS_API_KEY) return process.env.GOOGLE_MAPS_API_KEY.trim(); - const p = opts.keyPath || DEFAULT_KEY_PATH; - if (!fs.existsSync(p)) throw new Error(`API key file not found: ${p}`); - const key = fs.readFileSync(p, 'utf8').trim(); - if (!key) throw new Error(`API key file is empty: ${p}`); - return key; + const candidates = opts.keyPath ? [opts.keyPath] : FALLBACK_KEY_PATHS; + for (const p of candidates) { + if (!fs.existsSync(p)) continue; + const key = fs.readFileSync(p, 'utf8').trim(); + if (!key) throw new Error(`API key file is empty: ${p}`); + return key; + } + throw new Error(`API key file not found. Checked: ${candidates.join(', ')}`); } async function geocode(address, key) {