@chrysb/alphaclaw 0.8.4 → 0.8.5

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.
@@ -1,5 +1,6 @@
1
1
  const childProcess = require("child_process");
2
2
  const fs = require("fs");
3
+ const os = require("os");
3
4
  const path = require("path");
4
5
  const https = require("https");
5
6
  const http = require("http");
@@ -7,6 +8,7 @@ const {
7
8
  kLatestVersionCacheTtlMs,
8
9
  kAlphaclawRegistryUrl,
9
10
  kNpmPackageRoot,
11
+ kOpenclawUpdateCopyTimeoutMs,
10
12
  kRootDir,
11
13
  } = require("./constants");
12
14
 
@@ -114,7 +116,7 @@ const createAlphaclawVersionService = () => {
114
116
  const parent = path.dirname(dir);
115
117
  if (
116
118
  path.basename(parent) === "node_modules" ||
117
- parent.includes("node_modules")
119
+ parent.includes(`${path.sep}node_modules${path.sep}`)
118
120
  ) {
119
121
  dir = parent;
120
122
  continue;
@@ -123,7 +125,11 @@ const createAlphaclawVersionService = () => {
123
125
  if (fs.existsSync(pkgPath)) {
124
126
  try {
125
127
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
126
- if (pkg.dependencies?.["@chrysb/alphaclaw"]) {
128
+ if (
129
+ pkg.dependencies?.["@chrysb/alphaclaw"] ||
130
+ pkg.devDependencies?.["@chrysb/alphaclaw"] ||
131
+ pkg.optionalDependencies?.["@chrysb/alphaclaw"]
132
+ ) {
127
133
  return parent;
128
134
  }
129
135
  } catch {}
@@ -137,19 +143,39 @@ const createAlphaclawVersionService = () => {
137
143
  const installLatestAlphaclaw = () =>
138
144
  new Promise((resolve, reject) => {
139
145
  const installDir = findInstallDir();
146
+ const tmpDir = fs.mkdtempSync(
147
+ path.join(os.tmpdir(), "alphaclaw-update-"),
148
+ );
149
+
150
+ const cleanup = () => {
151
+ try {
152
+ fs.rmSync(tmpDir, { recursive: true, force: true });
153
+ } catch {}
154
+ };
155
+
156
+ fs.writeFileSync(
157
+ path.join(tmpDir, "package.json"),
158
+ JSON.stringify({
159
+ private: true,
160
+ dependencies: { "@chrysb/alphaclaw": "latest" },
161
+ }),
162
+ );
163
+
164
+ const npmEnv = {
165
+ ...process.env,
166
+ npm_config_update_notifier: "false",
167
+ npm_config_fund: "false",
168
+ npm_config_audit: "false",
169
+ };
170
+
140
171
  console.log(
141
- `[alphaclaw] Running: npm install @chrysb/alphaclaw@latest (cwd: ${installDir})`,
172
+ `[alphaclaw] Running: npm install @chrysb/alphaclaw@latest in temp dir (target: ${installDir})`,
142
173
  );
143
174
  childProcess.exec(
144
- "npm install @chrysb/alphaclaw@latest --omit=dev --no-save --save=false --package-lock=false --prefer-online",
175
+ "npm install --omit=dev --prefer-online --package-lock=false",
145
176
  {
146
- cwd: installDir,
147
- env: {
148
- ...process.env,
149
- npm_config_update_notifier: "false",
150
- npm_config_fund: "false",
151
- npm_config_audit: "false",
152
- },
177
+ cwd: tmpDir,
178
+ env: npmEnv,
153
179
  timeout: 180000,
154
180
  },
155
181
  (err, stdout, stderr) => {
@@ -158,6 +184,7 @@ const createAlphaclawVersionService = () => {
158
184
  console.log(
159
185
  `[alphaclaw] alphaclaw install error: ${message.slice(0, 200)}`,
160
186
  );
187
+ cleanup();
161
188
  return reject(
162
189
  new Error(
163
190
  message || "Failed to install @chrysb/alphaclaw@latest",
@@ -169,8 +196,28 @@ const createAlphaclawVersionService = () => {
169
196
  `[alphaclaw] alphaclaw install stdout: ${stdout.trim().slice(0, 300)}`,
170
197
  );
171
198
  }
172
- console.log("[alphaclaw] alphaclaw install completed");
173
- resolve({ stdout: stdout?.trim(), stderr: stderr?.trim() });
199
+
200
+ const src = path.join(tmpDir, "node_modules");
201
+ const dest = path.join(installDir, "node_modules");
202
+ childProcess.exec(
203
+ `cp -af "${src}/." "${dest}/"`,
204
+ { timeout: kOpenclawUpdateCopyTimeoutMs },
205
+ (copyErr) => {
206
+ cleanup();
207
+ if (copyErr) {
208
+ console.log(
209
+ `[alphaclaw] alphaclaw copy error: ${(copyErr.message || "").slice(0, 200)}`,
210
+ );
211
+ return reject(
212
+ new Error(
213
+ `Failed to copy updated AlphaClaw files: ${copyErr.message}`,
214
+ ),
215
+ );
216
+ }
217
+ console.log("[alphaclaw] alphaclaw install completed");
218
+ resolve({ stdout: stdout?.trim(), stderr: stderr?.trim() });
219
+ },
220
+ );
174
221
  },
175
222
  );
176
223
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrysb/alphaclaw",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },