gufi-cli 0.1.47 → 0.1.49

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.
Files changed (2) hide show
  1. package/dist/mcp.js +76 -25
  2. package/package.json +1 -2
package/dist/mcp.js CHANGED
@@ -37,7 +37,14 @@ function canWriteLocal() {
37
37
  }
38
38
  }
39
39
  import { getToken, getRefreshToken, loadConfig, isLoggedIn, getTokenForEnv, getRefreshTokenForEnv, setTokenForEnv, getCredentialsForEnv, getCurrentEnv } from "./lib/config.js";
40
- import { COLUMN_TYPE_NAMES } from "@gufi/column-types";
40
+ // 💜 Valid column types (hardcoded to avoid npm dependency on @gufi/column-types)
41
+ const COLUMN_TYPE_NAMES = [
42
+ "text", "email", "url", "barcode", "signature", "number", "number_int",
43
+ "number_float", "percentage", "date", "time", "created_at", "select",
44
+ "multiselect", "relation", "reversed_relation", "users", "boolean",
45
+ "currency", "phone", "location", "file", "json", "formula", "mirror",
46
+ "custom", "password"
47
+ ];
41
48
  // For ES modules __dirname equivalent
42
49
  const __filename = fileURLToPath(import.meta.url);
43
50
  const __dirname = path.dirname(__filename);
@@ -934,25 +941,9 @@ Examples:
934
941
  },
935
942
  },
936
943
  // ─────────────────────────────────────────────────────────────────────────
937
- // Packages (Marketplace Distribution)
944
+ // 💜 DISABLED: Packages (not actively used, keeping MCP simple)
938
945
  // ─────────────────────────────────────────────────────────────────────────
939
- {
940
- name: "gufi_package",
941
- description: getDesc("gufi_package"),
942
- inputSchema: {
943
- type: "object",
944
- properties: {
945
- action: { type: "string", description: "Action: list, get, create, delete, add_module, remove_module, publish" },
946
- id: { type: "string", description: "Package ID (for get, delete, add_module, remove_module, publish)" },
947
- name: { type: "string", description: "Package name (for create)" },
948
- description: { type: "string", description: "Package description (for create)" },
949
- module_id: { type: "string", description: "Module ID (for add_module, remove_module)" },
950
- company_id: { type: "string", description: "Source company ID (for add_module)" },
951
- env: ENV_PARAM,
952
- },
953
- required: ["action"],
954
- },
955
- },
946
+ // gufi_package → Re-enable when marketplace packages become priority
956
947
  ];
957
948
  // ════════════════════════════════════════════════════════════════════════════
958
949
  // Tool Handlers
@@ -1851,9 +1842,18 @@ const toolHandlers = {
1851
1842
  }
1852
1843
  else {
1853
1844
  // 💜 Web: Save to Claude Workspace BD
1845
+ // Get latest snapshot for version tracking
1846
+ let latestSnapshot;
1847
+ try {
1848
+ const snapshotResp = await apiRequest(`/api/marketplace/views/${viewId}/latest-snapshot`, {}, companyId, true, env);
1849
+ latestSnapshot = snapshotResp.latest_snapshot;
1850
+ }
1851
+ catch {
1852
+ // If endpoint not available, continue without snapshot tracking
1853
+ }
1854
1854
  const saveResponse = await apiRequest(`/api/claude/workspace/view`, {
1855
1855
  method: "POST",
1856
- body: JSON.stringify({ view_id: viewId, files }),
1856
+ body: JSON.stringify({ view_id: viewId, files, snapshot: latestSnapshot, company_id: companyId }),
1857
1857
  }, companyId, true, env);
1858
1858
  const saveResult = saveResponse.data || saveResponse;
1859
1859
  const viewFolder = saveResult?.folder || `views/view_${viewId}`;
@@ -1865,14 +1865,27 @@ const toolHandlers = {
1865
1865
  local_path: `~/workspace/${viewFolder}`,
1866
1866
  storage: "workspace",
1867
1867
  files_count: files.length,
1868
- _hint: `📥 View downloaded to Claude Workspace. Use Read/Edit tools to modify files. Then gufi_view_push({ view_id: ${viewId} }) to upload.`,
1868
+ _hint: `📥 View downloaded to Claude Workspace. Use Read/Edit tools to modify files. Then gufi_view_push({ view_id: ${viewId}, company_id: '${companyId}' }) to upload.`,
1869
1869
  };
1870
1870
  }
1871
1871
  },
1872
1872
  async gufi_view_push(params) {
1873
1873
  const viewId = params.view_id;
1874
+ let companyId = params.company_id;
1874
1875
  const env = params.env;
1875
1876
  const useLocal = canWriteLocal();
1877
+ // 💜 Try to get company_id from view metadata if not provided
1878
+ if (!companyId && viewId && useLocal) {
1879
+ const metaPath = path.join(LOCAL_VIEWS_DIR, `view_${viewId}`, ".gufi-view.json");
1880
+ if (fs.existsSync(metaPath)) {
1881
+ try {
1882
+ const meta = JSON.parse(fs.readFileSync(metaPath, "utf-8"));
1883
+ if (meta.company_id)
1884
+ companyId = String(meta.company_id);
1885
+ }
1886
+ catch { /* ignore */ }
1887
+ }
1888
+ }
1876
1889
  if (!viewId) {
1877
1890
  throw new Error("view_id is required");
1878
1891
  }
@@ -1926,13 +1939,26 @@ const toolHandlers = {
1926
1939
  }
1927
1940
  else {
1928
1941
  // 💜 Web: Read from Claude Workspace BD
1929
- const workspaceResponse = await apiRequest(`/api/claude/workspace/view/${viewId}/files`, {}, undefined, true, env);
1942
+ const workspaceResponse = await apiRequest(`/api/claude/workspace/view/${viewId}/files`, {}, companyId, true, env);
1930
1943
  files = workspaceResponse.data || workspaceResponse || [];
1944
+ // 💜 Also read metadata for version tracking
1945
+ try {
1946
+ const metaResponse = await apiRequest(`/api/claude/workspace/view/${viewId}/meta`, {}, companyId, true, env);
1947
+ // sendData wraps response in { data: [...] } format
1948
+ const meta = metaResponse.data?.[0] || metaResponse;
1949
+ lastPulledSnapshot = meta.lastPulledSnapshot;
1950
+ if (!companyId && meta.company_id) {
1951
+ companyId = String(meta.company_id);
1952
+ }
1953
+ }
1954
+ catch {
1955
+ // Metadata not found - view wasn't pulled through workspace
1956
+ }
1931
1957
  }
1932
1958
  // 💜 VERSION CHECK: Always verify before push (don't rely on backend alone)
1933
1959
  // This prevents overwriting changes from other developers
1934
1960
  try {
1935
- const snapshotResp = await apiRequest(`/api/marketplace/views/${viewId}/latest-snapshot`, {}, undefined, true, env);
1961
+ const snapshotResp = await apiRequest(`/api/marketplace/views/${viewId}/latest-snapshot`, {}, companyId, true, env);
1936
1962
  const serverSnapshot = snapshotResp.latest_snapshot;
1937
1963
  // If server has versions but we don't have a local snapshot → conflict
1938
1964
  // (means we pulled with an old CLI that didn't track versions)
@@ -1974,7 +2000,7 @@ const toolHandlers = {
1974
2000
  result = await apiRequest(`/api/marketplace/views/${viewId}/files/bulk`, {
1975
2001
  method: "POST",
1976
2002
  body: JSON.stringify({ files, message: params.message, sync: true, lastPulledSnapshot }),
1977
- }, undefined, true, env);
2003
+ }, companyId, true, env);
1978
2004
  }
1979
2005
  catch (err) {
1980
2006
  // 💜 Handle version conflict from backend
@@ -2008,11 +2034,36 @@ const toolHandlers = {
2008
2034
  }
2009
2035
  // Get view info for package
2010
2036
  let packageInfo = null;
2011
- const viewResponse = await apiRequest(`/api/marketplace/views/${viewId}`, {}, undefined, true, env);
2037
+ const viewResponse = await apiRequest(`/api/marketplace/views/${viewId}`, {}, companyId, true, env);
2012
2038
  const view = viewResponse.data || viewResponse;
2013
2039
  if (view?.package_id) {
2014
2040
  packageInfo = { id: view.package_id, publish_cmd: `gufi package:publish ${view.package_id}` };
2015
2041
  }
2042
+ // 💜 Extract and save publicAutomations from core/automations.ts
2043
+ const automationsFile = files.find(f => f.file_path === '/core/automations.ts' || f.file_path === 'core/automations.ts');
2044
+ if (automationsFile && view?.company_id && view?.entity_id) {
2045
+ try {
2046
+ // Parse publicAutomations from the file content
2047
+ const content = automationsFile.content;
2048
+ const publicMatch = content.match(/export\s+const\s+publicAutomations\s*=\s*\[([\s\S]*?)\]/);
2049
+ if (publicMatch) {
2050
+ // Extract string values from the array
2051
+ const arrContent = publicMatch[1];
2052
+ const publicAutomations = [...arrContent.matchAll(/['"]([^'"]+)['"]/g)].map(m => m[1]);
2053
+ if (publicAutomations.length > 0) {
2054
+ // Update entity config with publicAutomations
2055
+ await apiRequest(`/api/entities/${view.entity_id}/config`, {
2056
+ method: "PATCH",
2057
+ body: JSON.stringify({ publicAutomations }),
2058
+ }, String(view.company_id), true, env);
2059
+ }
2060
+ }
2061
+ }
2062
+ catch (err) {
2063
+ // Non-fatal: log but continue
2064
+ console.error("Warning: Could not update publicAutomations:", err);
2065
+ }
2066
+ }
2016
2067
  // Build response
2017
2068
  const response = {
2018
2069
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gufi-cli",
3
- "version": "0.1.47",
3
+ "version": "0.1.49",
4
4
  "description": "CLI for developing Gufi Marketplace views locally with Claude Code",
5
5
  "bin": {
6
6
  "gufi": "./bin/gufi.js"
@@ -22,7 +22,6 @@
22
22
  "start": "node bin/gufi.js"
23
23
  },
24
24
  "dependencies": {
25
- "@gufi/column-types": "file:../../libs/column-types",
26
25
  "@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
27
26
  "@types/prompts": "^2.4.9",
28
27
  "@types/ws": "^8.18.1",