@getpawl/setup 1.1.0 → 1.1.1
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/dist/index.js +124 -5
- 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
|
-
|
|
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 === "
|
|
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,122 @@ function main() {
|
|
|
20
26
|
function printUsage() {
|
|
21
27
|
console.log(`
|
|
22
28
|
Usage:
|
|
23
|
-
pawl init
|
|
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
|
-
|
|
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 frontendUrl = apiUrl.replace("-api", "").replace(":3001", ":3002");
|
|
127
|
+
const connectUrl = `${frontendUrl}/connect?code=${code}&repo=${encodeURIComponent(repoName)}`;
|
|
128
|
+
console.log(`
|
|
129
|
+
Opening browser to link "${repoName}" to a Pawl project...
|
|
130
|
+
`);
|
|
131
|
+
openBrowser(connectUrl);
|
|
132
|
+
console.log(" Waiting for you to select a project in the browser...");
|
|
133
|
+
console.log(" (Press Ctrl+C to cancel)\n");
|
|
134
|
+
const result = await pollForKey(apiUrl, code);
|
|
135
|
+
if (!result) {
|
|
136
|
+
console.error(" Session expired or cancelled. Run `pawl connect` to try again.");
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.join)(cwd, ".pawl"), { recursive: true });
|
|
140
|
+
writePawlEnvFile(cwd, result);
|
|
141
|
+
console.log(" Connected! .pawl/.env written.\n");
|
|
142
|
+
console.log(` Project: ${result.apiUrl}/projects/${result.projectId}`);
|
|
143
|
+
console.log(" Run `pawl sync` to push your first session.\n");
|
|
144
|
+
}
|
|
29
145
|
function legacySetup(encoded) {
|
|
30
146
|
let config;
|
|
31
147
|
try {
|
|
@@ -759,4 +875,7 @@ function updateGitignore(cwd) {
|
|
|
759
875
|
(0, import_node_fs.writeFileSync)(gitignorePath, newContent, "utf-8");
|
|
760
876
|
}
|
|
761
877
|
}
|
|
762
|
-
main()
|
|
878
|
+
main().catch((err) => {
|
|
879
|
+
console.error(err.message || err);
|
|
880
|
+
process.exit(1);
|
|
881
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpawl/setup",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "One-shot setup for Pawl + Claude Code hooks",
|
|
6
6
|
"bin": {
|
|
7
|
-
"pawl": "
|
|
8
|
-
"pawl-setup": "
|
|
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": {
|