@getpawl/setup 1.1.0 → 1.1.2

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/index.js +123 -5
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -4,13 +4,19 @@
4
4
  // src/index.ts
5
5
  var import_node_fs = require("fs");
6
6
  var import_node_path = require("path");
7
- function main() {
7
+ var import_node_child_process = require("child_process");
8
+ var DEFAULT_API_URL = "https://agentmap-api.onrender.com";
9
+ async function main() {
8
10
  const arg = process.argv[2];
9
11
  if (!arg) {
10
12
  printUsage();
11
13
  process.exit(0);
12
14
  }
13
- if (arg === "init") {
15
+ if (arg === "sync") {
16
+ pawlSync(process.argv[3]);
17
+ } else if (arg === "connect") {
18
+ await pawlConnect();
19
+ } else if (arg === "init") {
14
20
  const key = process.argv[3];
15
21
  pawlInit(key);
16
22
  } else {
@@ -20,12 +26,121 @@ function main() {
20
26
  function printUsage() {
21
27
  console.log(`
22
28
  Usage:
23
- pawl init [PROJECT_KEY] Initialize Pawl in this repo
29
+ pawl init Initialize Pawl in this repo
30
+ pawl connect Link this repo to a Pawl project (opens browser)
31
+ pawl sync [--pull] Sync with Pawl dashboard (push by default)
24
32
  pawl-setup <PROJECT_KEY> Legacy setup (still supported)
25
33
 
26
- Get your project key at: https://pawl.dev/settings
34
+ Dashboard: https://pawl.dev
27
35
  `);
28
36
  }
37
+ function pawlSync(flag) {
38
+ const cwd = process.cwd();
39
+ const syncScript = (0, import_node_path.join)(cwd, ".pawl", "sync.sh");
40
+ if (!(0, import_node_fs.existsSync)(syncScript)) {
41
+ console.error("Error: .pawl/sync.sh not found \u2014 run `pawl init` first.");
42
+ process.exit(1);
43
+ }
44
+ const envFile = (0, import_node_path.join)(cwd, ".pawl", ".env");
45
+ if (!(0, import_node_fs.existsSync)(envFile)) {
46
+ console.error("Error: .pawl/.env not found \u2014 run `pawl connect` to link your project.");
47
+ process.exit(1);
48
+ }
49
+ const mode = flag === "--pull" ? "pull" : "push";
50
+ (0, import_node_child_process.execSync)(`.pawl/sync.sh ${mode}`, { stdio: "inherit", cwd });
51
+ }
52
+ function generateCode() {
53
+ const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
54
+ let code = "";
55
+ for (let i = 0; i < 6; i++) {
56
+ code += chars[Math.floor(Math.random() * chars.length)];
57
+ }
58
+ return code;
59
+ }
60
+ function getRepoName() {
61
+ try {
62
+ const remote = (0, import_node_child_process.execSync)("git remote get-url origin", { encoding: "utf-8" }).trim();
63
+ const match = remote.match(/\/([^/]+?)(?:\.git)?$/);
64
+ if (match) return match[1];
65
+ } catch {
66
+ }
67
+ return (0, import_node_path.basename)(process.cwd());
68
+ }
69
+ function openBrowser(url) {
70
+ try {
71
+ const cmd = process.platform === "darwin" ? `open "${url}"` : process.platform === "win32" ? `start "${url}"` : `xdg-open "${url}"`;
72
+ (0, import_node_child_process.execSync)(cmd, { stdio: "ignore" });
73
+ } catch {
74
+ console.log(` Open this URL in your browser:
75
+ ${url}`);
76
+ }
77
+ }
78
+ function sleep(ms) {
79
+ return new Promise((resolve) => setTimeout(resolve, ms));
80
+ }
81
+ async function pollForKey(apiUrl, code) {
82
+ const deadline = Date.now() + 5 * 60 * 1e3;
83
+ const interval = 2e3;
84
+ while (Date.now() < deadline) {
85
+ try {
86
+ const res = await fetch(`${apiUrl}/api/cli/connect/poll?code=${code}`);
87
+ if (!res.ok) {
88
+ await sleep(interval);
89
+ continue;
90
+ }
91
+ const data = await res.json();
92
+ if (data.status === "ready") {
93
+ return {
94
+ apiKey: data.apiKey,
95
+ projectId: data.projectId,
96
+ apiUrl: data.apiUrl
97
+ };
98
+ }
99
+ if (data.status === "expired") {
100
+ return null;
101
+ }
102
+ } catch {
103
+ }
104
+ await sleep(interval);
105
+ }
106
+ return null;
107
+ }
108
+ async function pawlConnect() {
109
+ const cwd = process.cwd();
110
+ if (!(0, import_node_fs.existsSync)((0, import_node_path.join)(cwd, ".pawl"))) {
111
+ console.error("Error: .pawl/ not found \u2014 run `pawl init` first.");
112
+ process.exit(1);
113
+ }
114
+ const apiUrl = DEFAULT_API_URL;
115
+ const code = generateCode();
116
+ const repoName = getRepoName();
117
+ const startRes = await fetch(`${apiUrl}/api/cli/connect/start`, {
118
+ method: "POST",
119
+ headers: { "Content-Type": "application/json" },
120
+ body: JSON.stringify({ code, repoName })
121
+ });
122
+ if (!startRes.ok) {
123
+ console.error("Error: Could not start connect session. Is the API reachable?");
124
+ process.exit(1);
125
+ }
126
+ const connectUrl = `https://agentmap-mimy.onrender.com/connect?code=${code}&repo=${encodeURIComponent(repoName)}`;
127
+ console.log(`
128
+ Opening browser to link "${repoName}" to a Pawl project...
129
+ `);
130
+ openBrowser(connectUrl);
131
+ console.log(" Waiting for you to select a project in the browser...");
132
+ console.log(" (Press Ctrl+C to cancel)\n");
133
+ const result = await pollForKey(apiUrl, code);
134
+ if (!result) {
135
+ console.error(" Session expired or cancelled. Run `pawl connect` to try again.");
136
+ process.exit(1);
137
+ }
138
+ (0, import_node_fs.mkdirSync)((0, import_node_path.join)(cwd, ".pawl"), { recursive: true });
139
+ writePawlEnvFile(cwd, result);
140
+ console.log(" Connected! .pawl/.env written.\n");
141
+ console.log(` Project: ${result.apiUrl}/projects/${result.projectId}`);
142
+ console.log(" Run `pawl sync` to push your first session.\n");
143
+ }
29
144
  function legacySetup(encoded) {
30
145
  let config;
31
146
  try {
@@ -759,4 +874,7 @@ function updateGitignore(cwd) {
759
874
  (0, import_node_fs.writeFileSync)(gitignorePath, newContent, "utf-8");
760
875
  }
761
876
  }
762
- main();
877
+ main().catch((err) => {
878
+ console.error(err.message || err);
879
+ process.exit(1);
880
+ });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@getpawl/setup",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "commonjs",
5
5
  "description": "One-shot setup for Pawl + Claude Code hooks",
6
6
  "bin": {
7
- "pawl": "./dist/index.js",
8
- "pawl-setup": "./dist/index.js"
7
+ "pawl": "dist/index.js",
8
+ "pawl-setup": "dist/index.js"
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsup",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "https://github.com/0xfishbone/agentMap.git",
25
+ "url": "git+https://github.com/0xfishbone/agentMap.git",
26
26
  "directory": "packages/setup"
27
27
  },
28
28
  "devDependencies": {