@liwenkai/deepcode 0.4.19 → 0.5.0
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/README.md +32 -1
- package/install.mjs +17 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,37 @@ its SHA-256 checksum. Then run:
|
|
|
18
18
|
deepcode
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## Use it from your code
|
|
22
|
+
|
|
23
|
+
`deepcode -p "<instruction>"` runs one full turn without a terminal and prints the answer on
|
|
24
|
+
stdout — everything diagnostic goes to stderr, so it pipes cleanly. `--output-format json` turns
|
|
25
|
+
stdout into exactly one object to branch on:
|
|
26
|
+
|
|
27
|
+
| field | type | notes |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `status` | string | `finished` / `cancelled` / `timeout` / `error` — branch on this |
|
|
30
|
+
| `result` | string | the answer; empty unless `status` is `finished` |
|
|
31
|
+
| `reasoning` | string | the turn's reasoning text, empty when the model emitted none |
|
|
32
|
+
| `error` | string (optional) | present exactly when `status` is not `finished` |
|
|
33
|
+
| `session_id` | string (optional) | persist it to continue this thread |
|
|
34
|
+
| `denied_approvals` | number | tool calls auto-denied because nobody was there to approve |
|
|
35
|
+
| `duration_ms` | number | wall clock for the turn |
|
|
36
|
+
| `cost` | object (optional) | `{ usd, cny }` |
|
|
37
|
+
| `usage` | object (optional) | token counts |
|
|
38
|
+
|
|
39
|
+
- **Decide by `status`, not the exit code**: a cancelled turn exits `1`, not `124`.
|
|
40
|
+
- **Never use `-c` in a wrapper** — it means "the latest session in this workspace" and races.
|
|
41
|
+
Start with `--new` (the default), keep `session_id`, continue with `--resume <id>`.
|
|
42
|
+
- **`denied_approvals > 0` is not a bad answer**: a tool was refused because no human was there
|
|
43
|
+
to approve it, and a retry fails the same way.
|
|
44
|
+
- **Close stdin when spawning**: an inherited idle pipe costs 2 s on macOS/Linux and hangs on
|
|
45
|
+
Windows, and `--timeout` does not cover that read.
|
|
46
|
+
|
|
47
|
+
Exit codes: `0` finished / `1` error / `2` usage / `124` timeout / `130` Ctrl-C.
|
|
48
|
+
|
|
49
|
+
Full contract, flags and approval posture: [README](https://github.com/liwenka1/deep-code#driving-it-from-another-program)
|
|
50
|
+
(`deepcode --help` lists the flags for the exact version you installed).
|
|
51
|
+
|
|
21
52
|
## Supported platforms
|
|
22
53
|
|
|
23
54
|
| OS | Arch |
|
|
@@ -28,7 +59,7 @@ deepcode
|
|
|
28
59
|
|
|
29
60
|
## Notes
|
|
30
61
|
|
|
31
|
-
- Requires Node.js >=
|
|
62
|
+
- Requires Node.js >= 24 (for the installer only; the CLI itself is a native binary).
|
|
32
63
|
- If your network blocks GitHub, grab a binary from the
|
|
33
64
|
[releases page](https://github.com/liwenka1/deep-code/releases) manually, or
|
|
34
65
|
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
|
-
//
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
///
|
|
224
|
-
///
|
|
225
|
-
///
|
|
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
|
|
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
|
|
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
|
|
355
|
-
fs.rmSync(dest, { force: true });
|
|
313
|
+
discardPartial(file, dest);
|
|
356
314
|
reject(err);
|
|
357
315
|
});
|
|
358
316
|
response.on('aborted', () => {
|
|
359
|
-
file
|
|
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
|
|