@liwenkai/deepcode 0.4.20 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/install.mjs +17 -60
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -36,8 +36,6 @@ stdout into exactly one object to branch on:
36
36
  | `cost` | object (optional) | `{ usd, cny }` |
37
37
  | `usage` | object (optional) | token counts |
38
38
 
39
- - **Fields are added, never renamed or repurposed**; nothing documented here changes meaning
40
- without a bump of this contract's version, which is `1`.
41
39
  - **Decide by `status`, not the exit code**: a cancelled turn exits `1`, not `124`.
42
40
  - **Never use `-c` in a wrapper** — it means "the latest session in this workspace" and races.
43
41
  Start with `--new` (the default), keep `session_id`, continue with `--resume <id>`.
@@ -45,6 +43,8 @@ stdout into exactly one object to branch on:
45
43
  to approve it, and a retry fails the same way.
46
44
  - **Close stdin when spawning**: an inherited idle pipe costs 2 s on macOS/Linux and hangs on
47
45
  Windows, and `--timeout` does not cover that read.
46
+ - **Headless runs have a finite default**: omitting `--timeout` uses a 900-second wall-clock
47
+ ceiling, so an unattended wrapper cannot run forever by accident.
48
48
 
49
49
  Exit codes: `0` finished / `1` error / `2` usage / `124` timeout / `130` Ctrl-C.
50
50
 
@@ -61,7 +61,7 @@ Full contract, flags and approval posture: [README](https://github.com/liwenka1/
61
61
 
62
62
  ## Notes
63
63
 
64
- - Requires Node.js >= 18 (for the installer only; the CLI itself is a native binary).
64
+ - Requires Node.js >= 24 (for the installer only; the CLI itself is a native binary).
65
65
  - If your network blocks GitHub, grab a binary from the
66
66
  [releases page](https://github.com/liwenka1/deep-code/releases) manually, or
67
67
  build from source: clone `liwenka1/deep-code` and run
package/install.mjs CHANGED
@@ -13,34 +13,22 @@ import { execFileSync } from 'node:child_process';
13
13
 
14
14
  // ── 配置 ──
15
15
  const REPO = 'liwenka1/deep-code';
16
- // Read the version from package.json rather than trusting `npm_package_version`,
17
- // which is unset under yarn berry / pnpm in some modes and when this script is
18
- // run directly. The old `|| '0.1.0'` fallback silently installed v0.1.0 — and
19
- // v0.1.0's own SHA256SUMS validates it, so a years-old binary installed with a
20
- // green checkmark. There is no sane default here: fail loudly instead.
16
+ // The installed package metadata identifies the release asset to download.
21
17
  const PKG_DIR = path.dirname(fileURLToPath(import.meta.url));
22
18
  const VERSION = readVersion();
23
19
 
24
20
  function readVersion() {
25
- // The package.json next to this script is the source of truth: it is the
26
- // version actually being installed. `npm_package_version` is only a fallback
27
- // for runners that execute the script without writing the file, and must not
28
- // take precedence — if the two ever disagree, the file is right.
29
21
  try {
30
22
  const pkg = JSON.parse(fs.readFileSync(path.join(PKG_DIR, 'package.json'), 'utf8'));
31
- if (pkg.version) return pkg.version;
32
- if (process.env.npm_package_version) return process.env.npm_package_version;
23
+ if (typeof pkg.version === "string" && pkg.version.trim()) return pkg.version;
33
24
  throw new Error('package.json has no "version"');
34
25
  } catch (error) {
35
- if (process.env.npm_package_version) return process.env.npm_package_version;
36
26
  console.error(`❌ deepcode: cannot determine which version to install (${error.message}).`);
37
27
  console.error(' Reinstall with npm, or download a binary from');
38
28
  console.error(` https://github.com/${REPO}/releases`);
39
29
  process.exit(1);
40
30
  }
41
31
  }
42
- // `import.meta.dirname` only exists on Node 20.11+; derive it from the module
43
- // URL so the `engines: node >=18` floor actually works.
44
32
  const BIN_DIR = path.join(PKG_DIR, 'bin');
45
33
  // The real binary sits next to the `deepcode` JS launcher (bin/deepcode), which
46
34
  // spawns it. Distinct names so the download never clobbers the launcher.
@@ -152,21 +140,6 @@ async function main() {
152
140
  // ── 完整性校验 ──
153
141
  // 从同一 release 拉取 SHA256SUMS,比对下载二进制的哈希。
154
142
 
155
- /// Whether verification is mandatory for the version being installed.
156
- ///
157
- /// `SHA256SUMS` has shipped with every release from v0.1.0 on, so from v0.2.0
158
- /// the back-compat allowance buys nothing and costs a lot: treating a missing
159
- /// manifest as "skip" handed anyone who can fail that one request a
160
- /// downgrade-to-no-verification path, and on the already-installed fast path it
161
- /// printed a green "already installed" for a binary of some other version.
162
- function checksumRequired() {
163
- const [major, minor] = String(VERSION)
164
- .split('.')
165
- .map((part) => Number.parseInt(part, 10));
166
- if (!Number.isFinite(major) || !Number.isFinite(minor)) return true;
167
- return major > 0 || minor >= 2;
168
- }
169
-
170
143
  async function verifyChecksum(assetName, binPath) {
171
144
  const sumsUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/SHA256SUMS`;
172
145
  const sumsPath = `${binPath}.SHA256SUMS`;
@@ -174,15 +147,11 @@ async function verifyChecksum(assetName, binPath) {
174
147
  try {
175
148
  await downloadFile(sumsUrl, sumsPath);
176
149
  } catch (error) {
177
- if (checksumRequired()) {
178
- throw new Error(
179
- `cannot verify the download: SHA256SUMS for v${VERSION} is unreachable (${error.message}).\n` +
180
- ' Refusing to install an unverified binary. Check your network/proxy, or\n' +
181
- ` download and verify manually from https://github.com/${REPO}/releases`
182
- );
183
- }
184
- console.warn('⚠️ deepcode: SHA256SUMS not published for this release; skipping checksum verification.');
185
- return;
150
+ throw new Error(
151
+ `cannot verify the download: SHA256SUMS for v${VERSION} is unreachable (${error.message}).\n` +
152
+ ' Refusing to install an unverified binary. Check your network/proxy, or\n' +
153
+ ` download and verify manually from https://github.com/${REPO}/releases`
154
+ );
186
155
  }
187
156
 
188
157
  let expected;
@@ -193,13 +162,9 @@ async function verifyChecksum(assetName, binPath) {
193
162
  }
194
163
 
195
164
  if (!expected) {
196
- if (checksumRequired()) {
197
- throw new Error(
198
- `SHA256SUMS for v${VERSION} has no entry for ${assetName} — refusing to install an unverified binary.`
199
- );
200
- }
201
- console.warn(`⚠️ deepcode: no checksum entry for ${assetName}; skipping verification.`);
202
- return;
165
+ throw new Error(
166
+ `SHA256SUMS for v${VERSION} has no entry for ${assetName} — refusing to install an unverified binary.`
167
+ );
203
168
  }
204
169
 
205
170
  const actual = await sha256OfFile(binPath);
@@ -220,22 +185,16 @@ async function verifyChecksum(assetName, binPath) {
220
185
  console.log('🔒 deepcode: checksum verified.');
221
186
  }
222
187
 
223
- /// Non-throwing variant for the "already installed" fast path.
224
- ///
225
- /// Returns false — i.e. "re-download" — when verification is required but the
226
- /// manifest cannot be fetched or has no entry. It used to `catch { return true }`
227
- /// for *every* failure, so a 404 (wrong VERSION, assets not uploaded yet, an
228
- /// intercepted request) printed "✅ already installed" over whatever binary
229
- /// happened to be sitting there. For pre-0.2.0 versions the old lenient
230
- /// behaviour is kept so an unverifiable-but-present binary is not re-downloaded
231
- /// on every install.
188
+ /// Reuse an installed binary only when its checksum matches. A transient
189
+ /// network outage preserves an existing install; a manifest rejection, missing
190
+ /// entry, or checksum mismatch requests a fresh verified download.
232
191
  async function checksumMatches(assetName, binPath) {
233
192
  const sumsUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/SHA256SUMS`;
234
193
  const sumsPath = `${binPath}.check.SHA256SUMS`;
235
194
  try {
236
195
  await downloadFile(sumsUrl, sumsPath);
237
196
  const expected = parseChecksum(fs.readFileSync(sumsPath, 'utf8'), assetName);
238
- if (!expected) return !checksumRequired();
197
+ if (!expected) return false;
239
198
  return (await sha256OfFile(binPath)) === expected;
240
199
  } catch (error) {
241
200
  // Distinguish "the server answered no" from "could not reach the server".
@@ -248,7 +207,7 @@ async function checksumMatches(assetName, binPath) {
248
207
  const message = String(error?.message ?? error);
249
208
  const serverRejected = message.includes('Binary not found') || message.startsWith('HTTP ');
250
209
  if (serverRejected) {
251
- return !checksumRequired();
210
+ return false;
252
211
  }
253
212
  console.warn(
254
213
  '⚠️ deepcode: could not reach SHA256SUMS to re-verify the installed binary ' +
@@ -351,13 +310,11 @@ function downloadFile(url, dest, redirectsLeft = MAX_DOWNLOAD_REDIRECTS) {
351
310
  // not on the file — without this the promise resolved on the truncated
352
311
  // file's 'finish' and the partial download was treated as a success.
353
312
  response.on('error', (err) => {
354
- file.close();
355
- fs.rmSync(dest, { force: true });
313
+ discardPartial(file, dest);
356
314
  reject(err);
357
315
  });
358
316
  response.on('aborted', () => {
359
- file.close();
360
- fs.rmSync(dest, { force: true });
317
+ discardPartial(file, dest);
361
318
  reject(new Error(`Connection closed before the download finished: ${url}`));
362
319
  });
363
320
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liwenkai/deepcode",
3
- "version": "0.4.20",
3
+ "version": "0.5.1",
4
4
  "description": "AI coding assistant in your terminal — powered by DeepSeek",
5
5
  "bin": {
6
6
  "deepcode": "bin/deepcode"