@xiangyixie/dsh-superagent 0.12.0 → 0.12.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/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/bin/archive.js +185 -185
- package/bin/doctor.js +84 -84
- package/bin/sync.js +187 -187
- package/bin/workbench.js +98 -98
- package/lib/audit.js +555 -555
- package/lib/cost.js +267 -267
- package/lib/doctor.js +878 -878
- package/lib/guard.js +841 -841
- package/lib/index.js +2031 -2031
- package/lib/inject.js +138 -138
- package/lib/ledger.js +270 -270
- package/lib/memory.js +736 -736
- package/lib/orchestrator.js +3851 -3851
- package/lib/policy.js +739 -739
- package/lib/report.js +1068 -1068
- package/lib/store.js +873 -873
- package/lib/sync.js +456 -456
- package/lib/templates.js +690 -690
- package/lib/watch.js +810 -810
- package/lib/workbench.js +1119 -1119
- package/lib/workspace.js +433 -433
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,18 @@ along with the next code release. A doc-only version leaves `lib/` and `bin/`
|
|
|
8
8
|
byte-identical to the version before it, and the pinned install line in the
|
|
9
9
|
README is updated to the version being released.
|
|
10
10
|
|
|
11
|
+
## 0.12.1 — 2026-11-15
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **Line endings in `bin/` and `lib/`.** Added `.gitattributes` with
|
|
16
|
+
`*.js text eol=lf` for both directories and normalized the tracked files to
|
|
17
|
+
LF. npm rewrites the shebang line of bin scripts during install (CRLF → LF,
|
|
18
|
+
one byte per file), which made `doctor`'s registry checksum comparison report
|
|
19
|
+
a false `Registry match` failure for `bin/*.js` on npm-installed copies. With
|
|
20
|
+
the tarball now shipping LF, installed files match the published package
|
|
21
|
+
byte-for-byte.
|
|
22
|
+
|
|
11
23
|
## 0.12.0 — 2026-11-15
|
|
12
24
|
|
|
13
25
|
### Added
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ filesystem; this is not a sandbox.
|
|
|
25
25
|
in the environment:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.12.
|
|
28
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.12.1
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Then ask the session for a run — a real call, not a sketch:
|
|
@@ -75,7 +75,7 @@ your `PATH`, use `npx @deepseek-ai/dsh@0.2.2-rc.1` instead.
|
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
77
|
# 1. install the plugin into a profile (web, headless, ... whatever you run)
|
|
78
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.12.
|
|
78
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.12.1
|
|
79
79
|
|
|
80
80
|
# 2. confirm the bundle row exists in the merged config
|
|
81
81
|
dsh --profile web --dump-config
|
|
@@ -1186,7 +1186,7 @@ appears to "hang" until the ignored-abort child returns.
|
|
|
1186
1186
|
|
|
1187
1187
|
| What you see | What it means | What to do |
|
|
1188
1188
|
| --- | --- | --- |
|
|
1189
|
-
| `superagent_*` tools do not exist | The bundle row is not mounted, or the host refused to load the plugin. | Run `--dump-config` and check for the `@xiangyixie/dsh-superagent` block; reinstall with `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.12.
|
|
1189
|
+
| `superagent_*` tools do not exist | The bundle row is not mounted, or the host refused to load the plugin. | Run `--dump-config` and check for the `@xiangyixie/dsh-superagent` block; reinstall with `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.12.1` and read the host log for `[dsh-superagent]` lines. |
|
|
1190
1190
|
| `Cannot find module .../lib/control.js` (or `watch.js` / `report.js`) and the plugin never activates | The copy in that profile is incomplete — an `add` that was interrupted leaves a partial extraction. The published package is not the cause: every version ships all twenty-two `lib/` files. | Delete the plugin's directory under the profile's `node_modules` (scoped `@xiangyixie/dsh-superagent`, or unscoped `dsh-superagent` from an older tarball install) and run the same `add` command again, with the version number. Do not copy files in by hand. |
|
|
1191
1191
|
| `[error] the model provider rejected the API key` | The key env var is missing in the process that started the host. | Export `DEEPSEEK_API_KEY` (the default route) or the variable your route names, then restart `dsh`. |
|
|
1192
1192
|
| `MISSING_CREDENTIAL ... no API key for provider route "..."` | The profile's route has no credential in the environment. | Set the env var named for that route and restart. The error line names the route, so use that, not this page. |
|
package/bin/archive.js
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* `dsh-superagent-archive` — prune terminal runs and move one run in or out of
|
|
4
|
-
* the durable store as a self-contained archive.
|
|
5
|
-
*
|
|
6
|
-
* Prune is a dry run unless `--confirm` is given: the command prints every run
|
|
7
|
-
* and byte it would delete first, and it never touches a run that is live or
|
|
8
|
-
* locked by another process.
|
|
9
|
-
*/
|
|
10
|
-
import { createStore, resolveStateRoot } from '../lib/store.js'
|
|
11
|
-
|
|
12
|
-
const USAGE = `Usage: dsh-superagent-archive <command> [options]
|
|
13
|
-
|
|
14
|
-
Commands:
|
|
15
|
-
prune list terminal runs that prune would delete (dry run by default)
|
|
16
|
-
export <run-id> write one run as a self-contained archive
|
|
17
|
-
import <path> read an archive back into the local store
|
|
18
|
-
|
|
19
|
-
Common options:
|
|
20
|
-
--state-dir <path> run state directory (default: $DSH_HOME/state/superagent)
|
|
21
|
-
-h, --help show this message
|
|
22
|
-
|
|
23
|
-
prune options:
|
|
24
|
-
--older-than <days> only runs finished at least this many days ago (required)
|
|
25
|
-
--status <list> only these terminal statuses, comma separated
|
|
26
|
-
--confirm actually delete; without it prune only prints the plan
|
|
27
|
-
|
|
28
|
-
export options:
|
|
29
|
-
--out <path> archive path (default: ./superagent-<run-id>[.json|.html])
|
|
30
|
-
--format <kind> dir (default), bundle (one JSON file), or html (one page)
|
|
31
|
-
|
|
32
|
-
import options:
|
|
33
|
-
(none) an existing local run with the same id makes import fail`
|
|
34
|
-
|
|
35
|
-
/** Format a byte count the way the other CLIs in this package do. */
|
|
36
|
-
function sizeText(value) {
|
|
37
|
-
let size = Number(value)
|
|
38
|
-
if (!Number.isFinite(size) || size < 0) size = 0
|
|
39
|
-
if (size < 1024) return `${Math.round(size)} B`
|
|
40
|
-
const units = ['kB', 'MB', 'GB']
|
|
41
|
-
let unit = 'B'
|
|
42
|
-
for (const next of units) {
|
|
43
|
-
if (size < 1024) break
|
|
44
|
-
size /= 1024
|
|
45
|
-
unit = next
|
|
46
|
-
}
|
|
47
|
-
return `${size >= 100 ? size.toFixed(0) : size.toFixed(1)} ${unit}`
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function fail(message, code = 2) {
|
|
51
|
-
console.error(`${message}\n\n${USAGE}`)
|
|
52
|
-
process.exit(code)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function valueOf(argv, index, flag) {
|
|
56
|
-
const value = argv[index]
|
|
57
|
-
if (value === undefined || value.startsWith('--')) fail(`${flag} needs a value`)
|
|
58
|
-
return value
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function parse(argv) {
|
|
62
|
-
const options = {}
|
|
63
|
-
const positional = []
|
|
64
|
-
for (let index = 0; index < argv.length; index++) {
|
|
65
|
-
const arg = argv[index]
|
|
66
|
-
if (arg === '-h' || arg === '--help') {
|
|
67
|
-
console.log(USAGE)
|
|
68
|
-
process.exit(0)
|
|
69
|
-
} else if (arg === '--state-dir') options.stateDir = valueOf(argv, ++index, '--state-dir')
|
|
70
|
-
else if (arg.startsWith('--state-dir=')) options.stateDir = arg.slice('--state-dir='.length)
|
|
71
|
-
else if (arg === '--older-than') options.olderThan = Number(valueOf(argv, ++index, '--older-than'))
|
|
72
|
-
else if (arg.startsWith('--older-than=')) options.olderThan = Number(arg.slice('--older-than='.length))
|
|
73
|
-
else if (arg === '--status') options.statuses = valueOf(argv, ++index, '--status')
|
|
74
|
-
else if (arg.startsWith('--status=')) options.statuses = arg.slice('--status='.length)
|
|
75
|
-
else if (arg === '--format') options.format = valueOf(argv, ++index, '--format')
|
|
76
|
-
else if (arg.startsWith('--format=')) options.format = arg.slice('--format='.length)
|
|
77
|
-
else if (arg === '--out') options.out = valueOf(argv, ++index, '--out')
|
|
78
|
-
else if (arg.startsWith('--out=')) options.out = arg.slice('--out='.length)
|
|
79
|
-
else if (arg === '--confirm') options.confirm = true
|
|
80
|
-
else if (arg.startsWith('-')) fail(`unknown option: ${arg}`)
|
|
81
|
-
else positional.push(arg)
|
|
82
|
-
}
|
|
83
|
-
return { options, positional }
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function printPlan(store, plan) {
|
|
87
|
-
console.log(`prune plan for ${store.root}`)
|
|
88
|
-
if (plan.candidates.length === 0) {
|
|
89
|
-
console.log(' nothing to delete: no terminal run matches this window and filter')
|
|
90
|
-
} else {
|
|
91
|
-
const width = Math.max(20, ...plan.candidates.map(candidate => candidate.id.length))
|
|
92
|
-
console.log(` ${plan.candidates.length} run(s) qualify, ${plan.files} file(s), ${sizeText(plan.bytes)}:`)
|
|
93
|
-
console.log(` ${'RUN'.padEnd(width)} ${'STATUS'.padEnd(11)} ${'FINISHED'.padEnd(24)} BYTES`)
|
|
94
|
-
for (const candidate of plan.candidates) {
|
|
95
|
-
console.log(
|
|
96
|
-
` ${candidate.id.padEnd(width)} ${candidate.status.padEnd(11)} `
|
|
97
|
-
+ `${String(candidate.finishedAt).padEnd(24)} ${sizeText(candidate.bytes)}`,
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (plan.skipped.length > 0) {
|
|
102
|
-
console.log(` skipped ${plan.skipped.length} run(s) held by another process: `
|
|
103
|
-
+ plan.skipped.map(entry => entry.id).join(', '))
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function prune(options) {
|
|
108
|
-
if (options.olderThan === undefined) fail('prune needs --older-than <days>')
|
|
109
|
-
if (!Number.isFinite(options.olderThan) || options.olderThan <= 0) {
|
|
110
|
-
fail('--older-than must be a positive number of days')
|
|
111
|
-
}
|
|
112
|
-
// No init(): a dry run must not clean stale files either.
|
|
113
|
-
const store = createStore(resolveStateRoot(options.stateDir))
|
|
114
|
-
let plan
|
|
115
|
-
try {
|
|
116
|
-
plan = await store.planPrune({ olderThanDays: options.olderThan, statuses: options.statuses })
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.error(`cannot plan a prune: ${error?.message ?? error}`)
|
|
119
|
-
process.exit(1)
|
|
120
|
-
}
|
|
121
|
-
printPlan(store, plan)
|
|
122
|
-
if (!options.confirm) {
|
|
123
|
-
console.log('')
|
|
124
|
-
console.log(plan.candidates.length === 0
|
|
125
|
-
? 'dry run: nothing deleted.'
|
|
126
|
-
: `dry run: nothing deleted; ${plan.candidates.length} run(s), ${sizeText(plan.bytes)} `
|
|
127
|
-
+ `in ${plan.files} file(s). Re-run with --confirm to delete.`)
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
const result = await store.prune({
|
|
131
|
-
olderThanDays: options.olderThan,
|
|
132
|
-
statuses: options.statuses,
|
|
133
|
-
dryRun: false,
|
|
134
|
-
})
|
|
135
|
-
console.log('')
|
|
136
|
-
console.log(result.removed.length === 0
|
|
137
|
-
? 'deleted nothing: the runs eligible a moment ago are gone or now held'
|
|
138
|
-
: `deleted ${result.removed.length} run(s), ${sizeText(result.deletedBytes)}`)
|
|
139
|
-
for (const failure of result.failed) console.error(` failed to delete ${failure.id}: ${failure.error}`)
|
|
140
|
-
if (result.failed.length > 0) process.exitCode = 1
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function exportRun(options, positional) {
|
|
144
|
-
const runId = positional[0]
|
|
145
|
-
if (!runId) fail('export needs a run id')
|
|
146
|
-
const format = options.format ?? 'dir'
|
|
147
|
-
if (!['dir', 'bundle', 'html'].includes(format)) fail('--format must be dir, bundle, or html')
|
|
148
|
-
const suffix = format === 'dir' ? '' : format === 'html' ? '.html' : '.json'
|
|
149
|
-
const out = options.out ?? `superagent-${runId}${suffix}`
|
|
150
|
-
const store = createStore(resolveStateRoot(options.stateDir))
|
|
151
|
-
let result
|
|
152
|
-
try {
|
|
153
|
-
result = await store.exportRun(runId, out, { format })
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error(`cannot export run ${runId}: ${error?.message ?? error}`)
|
|
156
|
-
process.exit(1)
|
|
157
|
-
}
|
|
158
|
-
console.log(`exported run ${result.runId} to ${result.out} (${result.format}, `
|
|
159
|
-
+ `${result.files.length} file(s), ${sizeText(result.bytes)})`)
|
|
160
|
-
for (const file of result.files) console.log(` ${file.path} ${sizeText(file.bytes)}`)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function importRun(options, positional) {
|
|
164
|
-
const source = positional[0]
|
|
165
|
-
if (!source) fail('import needs an archive path')
|
|
166
|
-
const store = createStore(resolveStateRoot(options.stateDir))
|
|
167
|
-
await store.init()
|
|
168
|
-
let result
|
|
169
|
-
try {
|
|
170
|
-
result = await store.importRun(source)
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error(`cannot import ${source}: ${error?.message ?? error}`)
|
|
173
|
-
process.exit(1)
|
|
174
|
-
}
|
|
175
|
-
console.log(`imported run ${result.run.id} from ${result.format} archive ${result.source}`)
|
|
176
|
-
console.log(` wrote ${result.out}`)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const { options, positional } = parse(process.argv.slice(2))
|
|
180
|
-
const command = positional.shift()
|
|
181
|
-
if (!command) fail('a command is required')
|
|
182
|
-
if (command === 'prune') await prune(options)
|
|
183
|
-
else if (command === 'export') await exportRun(options, positional)
|
|
184
|
-
else if (command === 'import') await importRun(options, positional)
|
|
185
|
-
else fail(`unknown command: ${command}`)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `dsh-superagent-archive` — prune terminal runs and move one run in or out of
|
|
4
|
+
* the durable store as a self-contained archive.
|
|
5
|
+
*
|
|
6
|
+
* Prune is a dry run unless `--confirm` is given: the command prints every run
|
|
7
|
+
* and byte it would delete first, and it never touches a run that is live or
|
|
8
|
+
* locked by another process.
|
|
9
|
+
*/
|
|
10
|
+
import { createStore, resolveStateRoot } from '../lib/store.js'
|
|
11
|
+
|
|
12
|
+
const USAGE = `Usage: dsh-superagent-archive <command> [options]
|
|
13
|
+
|
|
14
|
+
Commands:
|
|
15
|
+
prune list terminal runs that prune would delete (dry run by default)
|
|
16
|
+
export <run-id> write one run as a self-contained archive
|
|
17
|
+
import <path> read an archive back into the local store
|
|
18
|
+
|
|
19
|
+
Common options:
|
|
20
|
+
--state-dir <path> run state directory (default: $DSH_HOME/state/superagent)
|
|
21
|
+
-h, --help show this message
|
|
22
|
+
|
|
23
|
+
prune options:
|
|
24
|
+
--older-than <days> only runs finished at least this many days ago (required)
|
|
25
|
+
--status <list> only these terminal statuses, comma separated
|
|
26
|
+
--confirm actually delete; without it prune only prints the plan
|
|
27
|
+
|
|
28
|
+
export options:
|
|
29
|
+
--out <path> archive path (default: ./superagent-<run-id>[.json|.html])
|
|
30
|
+
--format <kind> dir (default), bundle (one JSON file), or html (one page)
|
|
31
|
+
|
|
32
|
+
import options:
|
|
33
|
+
(none) an existing local run with the same id makes import fail`
|
|
34
|
+
|
|
35
|
+
/** Format a byte count the way the other CLIs in this package do. */
|
|
36
|
+
function sizeText(value) {
|
|
37
|
+
let size = Number(value)
|
|
38
|
+
if (!Number.isFinite(size) || size < 0) size = 0
|
|
39
|
+
if (size < 1024) return `${Math.round(size)} B`
|
|
40
|
+
const units = ['kB', 'MB', 'GB']
|
|
41
|
+
let unit = 'B'
|
|
42
|
+
for (const next of units) {
|
|
43
|
+
if (size < 1024) break
|
|
44
|
+
size /= 1024
|
|
45
|
+
unit = next
|
|
46
|
+
}
|
|
47
|
+
return `${size >= 100 ? size.toFixed(0) : size.toFixed(1)} ${unit}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function fail(message, code = 2) {
|
|
51
|
+
console.error(`${message}\n\n${USAGE}`)
|
|
52
|
+
process.exit(code)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function valueOf(argv, index, flag) {
|
|
56
|
+
const value = argv[index]
|
|
57
|
+
if (value === undefined || value.startsWith('--')) fail(`${flag} needs a value`)
|
|
58
|
+
return value
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parse(argv) {
|
|
62
|
+
const options = {}
|
|
63
|
+
const positional = []
|
|
64
|
+
for (let index = 0; index < argv.length; index++) {
|
|
65
|
+
const arg = argv[index]
|
|
66
|
+
if (arg === '-h' || arg === '--help') {
|
|
67
|
+
console.log(USAGE)
|
|
68
|
+
process.exit(0)
|
|
69
|
+
} else if (arg === '--state-dir') options.stateDir = valueOf(argv, ++index, '--state-dir')
|
|
70
|
+
else if (arg.startsWith('--state-dir=')) options.stateDir = arg.slice('--state-dir='.length)
|
|
71
|
+
else if (arg === '--older-than') options.olderThan = Number(valueOf(argv, ++index, '--older-than'))
|
|
72
|
+
else if (arg.startsWith('--older-than=')) options.olderThan = Number(arg.slice('--older-than='.length))
|
|
73
|
+
else if (arg === '--status') options.statuses = valueOf(argv, ++index, '--status')
|
|
74
|
+
else if (arg.startsWith('--status=')) options.statuses = arg.slice('--status='.length)
|
|
75
|
+
else if (arg === '--format') options.format = valueOf(argv, ++index, '--format')
|
|
76
|
+
else if (arg.startsWith('--format=')) options.format = arg.slice('--format='.length)
|
|
77
|
+
else if (arg === '--out') options.out = valueOf(argv, ++index, '--out')
|
|
78
|
+
else if (arg.startsWith('--out=')) options.out = arg.slice('--out='.length)
|
|
79
|
+
else if (arg === '--confirm') options.confirm = true
|
|
80
|
+
else if (arg.startsWith('-')) fail(`unknown option: ${arg}`)
|
|
81
|
+
else positional.push(arg)
|
|
82
|
+
}
|
|
83
|
+
return { options, positional }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function printPlan(store, plan) {
|
|
87
|
+
console.log(`prune plan for ${store.root}`)
|
|
88
|
+
if (plan.candidates.length === 0) {
|
|
89
|
+
console.log(' nothing to delete: no terminal run matches this window and filter')
|
|
90
|
+
} else {
|
|
91
|
+
const width = Math.max(20, ...plan.candidates.map(candidate => candidate.id.length))
|
|
92
|
+
console.log(` ${plan.candidates.length} run(s) qualify, ${plan.files} file(s), ${sizeText(plan.bytes)}:`)
|
|
93
|
+
console.log(` ${'RUN'.padEnd(width)} ${'STATUS'.padEnd(11)} ${'FINISHED'.padEnd(24)} BYTES`)
|
|
94
|
+
for (const candidate of plan.candidates) {
|
|
95
|
+
console.log(
|
|
96
|
+
` ${candidate.id.padEnd(width)} ${candidate.status.padEnd(11)} `
|
|
97
|
+
+ `${String(candidate.finishedAt).padEnd(24)} ${sizeText(candidate.bytes)}`,
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (plan.skipped.length > 0) {
|
|
102
|
+
console.log(` skipped ${plan.skipped.length} run(s) held by another process: `
|
|
103
|
+
+ plan.skipped.map(entry => entry.id).join(', '))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function prune(options) {
|
|
108
|
+
if (options.olderThan === undefined) fail('prune needs --older-than <days>')
|
|
109
|
+
if (!Number.isFinite(options.olderThan) || options.olderThan <= 0) {
|
|
110
|
+
fail('--older-than must be a positive number of days')
|
|
111
|
+
}
|
|
112
|
+
// No init(): a dry run must not clean stale files either.
|
|
113
|
+
const store = createStore(resolveStateRoot(options.stateDir))
|
|
114
|
+
let plan
|
|
115
|
+
try {
|
|
116
|
+
plan = await store.planPrune({ olderThanDays: options.olderThan, statuses: options.statuses })
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(`cannot plan a prune: ${error?.message ?? error}`)
|
|
119
|
+
process.exit(1)
|
|
120
|
+
}
|
|
121
|
+
printPlan(store, plan)
|
|
122
|
+
if (!options.confirm) {
|
|
123
|
+
console.log('')
|
|
124
|
+
console.log(plan.candidates.length === 0
|
|
125
|
+
? 'dry run: nothing deleted.'
|
|
126
|
+
: `dry run: nothing deleted; ${plan.candidates.length} run(s), ${sizeText(plan.bytes)} `
|
|
127
|
+
+ `in ${plan.files} file(s). Re-run with --confirm to delete.`)
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
const result = await store.prune({
|
|
131
|
+
olderThanDays: options.olderThan,
|
|
132
|
+
statuses: options.statuses,
|
|
133
|
+
dryRun: false,
|
|
134
|
+
})
|
|
135
|
+
console.log('')
|
|
136
|
+
console.log(result.removed.length === 0
|
|
137
|
+
? 'deleted nothing: the runs eligible a moment ago are gone or now held'
|
|
138
|
+
: `deleted ${result.removed.length} run(s), ${sizeText(result.deletedBytes)}`)
|
|
139
|
+
for (const failure of result.failed) console.error(` failed to delete ${failure.id}: ${failure.error}`)
|
|
140
|
+
if (result.failed.length > 0) process.exitCode = 1
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function exportRun(options, positional) {
|
|
144
|
+
const runId = positional[0]
|
|
145
|
+
if (!runId) fail('export needs a run id')
|
|
146
|
+
const format = options.format ?? 'dir'
|
|
147
|
+
if (!['dir', 'bundle', 'html'].includes(format)) fail('--format must be dir, bundle, or html')
|
|
148
|
+
const suffix = format === 'dir' ? '' : format === 'html' ? '.html' : '.json'
|
|
149
|
+
const out = options.out ?? `superagent-${runId}${suffix}`
|
|
150
|
+
const store = createStore(resolveStateRoot(options.stateDir))
|
|
151
|
+
let result
|
|
152
|
+
try {
|
|
153
|
+
result = await store.exportRun(runId, out, { format })
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error(`cannot export run ${runId}: ${error?.message ?? error}`)
|
|
156
|
+
process.exit(1)
|
|
157
|
+
}
|
|
158
|
+
console.log(`exported run ${result.runId} to ${result.out} (${result.format}, `
|
|
159
|
+
+ `${result.files.length} file(s), ${sizeText(result.bytes)})`)
|
|
160
|
+
for (const file of result.files) console.log(` ${file.path} ${sizeText(file.bytes)}`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function importRun(options, positional) {
|
|
164
|
+
const source = positional[0]
|
|
165
|
+
if (!source) fail('import needs an archive path')
|
|
166
|
+
const store = createStore(resolveStateRoot(options.stateDir))
|
|
167
|
+
await store.init()
|
|
168
|
+
let result
|
|
169
|
+
try {
|
|
170
|
+
result = await store.importRun(source)
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error(`cannot import ${source}: ${error?.message ?? error}`)
|
|
173
|
+
process.exit(1)
|
|
174
|
+
}
|
|
175
|
+
console.log(`imported run ${result.run.id} from ${result.format} archive ${result.source}`)
|
|
176
|
+
console.log(` wrote ${result.out}`)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const { options, positional } = parse(process.argv.slice(2))
|
|
180
|
+
const command = positional.shift()
|
|
181
|
+
if (!command) fail('a command is required')
|
|
182
|
+
if (command === 'prune') await prune(options)
|
|
183
|
+
else if (command === 'export') await exportRun(options, positional)
|
|
184
|
+
else if (command === 'import') await importRun(options, positional)
|
|
185
|
+
else fail(`unknown command: ${command}`)
|
package/bin/doctor.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* `dsh-superagent-doctor` — read-only checks for the two ways this package has
|
|
4
|
-
* failed to run after a clean install: a `files` whitelist that dropped an
|
|
5
|
-
* imported module, and a profile copy left half-unpacked by an interrupted
|
|
6
|
-
* install. Prints one block per check and the commands that fix it.
|
|
7
|
-
*/
|
|
8
|
-
import path from 'node:path'
|
|
9
|
-
import { fileURLToPath } from 'node:url'
|
|
10
|
-
import { inferProfileDir, renderReport, runDoctor } from '../lib/doctor.js'
|
|
11
|
-
|
|
12
|
-
const USAGE = `Usage: dsh-superagent-doctor [options]
|
|
13
|
-
|
|
14
|
-
Check that this copy of dsh-superagent can actually run:
|
|
15
|
-
- every file the code imports is shipped by package.json "files" and exists
|
|
16
|
-
- the installed copy matches the version package.json claims
|
|
17
|
-
- the installed files match the published tarball (skipped when offline)
|
|
18
|
-
- the DSH profile mounts the bundle patch and the eleven tools are registered
|
|
19
|
-
- the running Node satisfies "engines"
|
|
20
|
-
|
|
21
|
-
Nothing is installed or modified; the only network access is one public
|
|
22
|
-
tarball for the hash comparison, and --offline removes even that.
|
|
23
|
-
|
|
24
|
-
Options:
|
|
25
|
-
--package <dir> package copy to inspect (default: the copy this runs from)
|
|
26
|
-
--profile <name> DSH profile name, or a full profile directory
|
|
27
|
-
--offline skip the npm registry comparison
|
|
28
|
-
--no-color never emit ANSI colour
|
|
29
|
-
-h, --help show this message
|
|
30
|
-
|
|
31
|
-
Exit code: 0 when no check fails, 1 when one does, 2 on bad usage.`
|
|
32
|
-
|
|
33
|
-
function valueOf(argv, index, flag) {
|
|
34
|
-
const value = argv[index]
|
|
35
|
-
if (value === undefined || value.startsWith('--')) {
|
|
36
|
-
console.error(`${flag} needs a value\n\n${USAGE}`)
|
|
37
|
-
process.exit(2)
|
|
38
|
-
}
|
|
39
|
-
return value
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function parse(argv) {
|
|
43
|
-
const options = {}
|
|
44
|
-
for (let index = 0; index < argv.length; index++) {
|
|
45
|
-
const arg = argv[index]
|
|
46
|
-
if (arg === '--package') options.packageRoot = valueOf(argv, ++index, '--package')
|
|
47
|
-
else if (arg.startsWith('--package=')) options.packageRoot = arg.slice('--package='.length)
|
|
48
|
-
else if (arg === '--profile') options.profile = valueOf(argv, ++index, '--profile')
|
|
49
|
-
else if (arg.startsWith('--profile=')) options.profile = arg.slice('--profile='.length)
|
|
50
|
-
else if (arg === '--offline') options.online = false
|
|
51
|
-
else if (arg === '--no-color') options.color = false
|
|
52
|
-
else if (arg === '-h' || arg === '--help') {
|
|
53
|
-
console.log(USAGE)
|
|
54
|
-
process.exit(0)
|
|
55
|
-
} else {
|
|
56
|
-
console.error(`unknown argument: ${arg}\n\n${USAGE}`)
|
|
57
|
-
process.exit(2)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return options
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const options = parse(process.argv.slice(2))
|
|
64
|
-
// When installed, bin/ lives one level below the package root. Running the
|
|
65
|
-
// checkout from source resolves to the checkout, which is the same idea.
|
|
66
|
-
const defaultRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
67
|
-
const packageRoot = options.packageRoot ? path.resolve(options.packageRoot) : defaultRoot
|
|
68
|
-
|
|
69
|
-
const result = await runDoctor({
|
|
70
|
-
packageRoot,
|
|
71
|
-
// `undefined` means "infer from where this package lives"; only an explicit
|
|
72
|
-
// `--profile` overrides the inference.
|
|
73
|
-
profile: options.profile,
|
|
74
|
-
online: options.online,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
const color = options.color !== false
|
|
78
|
-
&& process.stdout.isTTY
|
|
79
|
-
&& !process.env.NO_COLOR
|
|
80
|
-
console.log(renderReport(result, { color }))
|
|
81
|
-
if (!options.profile && !inferProfileDir(result.targetDir)) {
|
|
82
|
-
console.log('\nnot inside a DSH profile, so only the package itself was checked')
|
|
83
|
-
}
|
|
84
|
-
process.exit(result.ok ? 0 : 1)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `dsh-superagent-doctor` — read-only checks for the two ways this package has
|
|
4
|
+
* failed to run after a clean install: a `files` whitelist that dropped an
|
|
5
|
+
* imported module, and a profile copy left half-unpacked by an interrupted
|
|
6
|
+
* install. Prints one block per check and the commands that fix it.
|
|
7
|
+
*/
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
10
|
+
import { inferProfileDir, renderReport, runDoctor } from '../lib/doctor.js'
|
|
11
|
+
|
|
12
|
+
const USAGE = `Usage: dsh-superagent-doctor [options]
|
|
13
|
+
|
|
14
|
+
Check that this copy of dsh-superagent can actually run:
|
|
15
|
+
- every file the code imports is shipped by package.json "files" and exists
|
|
16
|
+
- the installed copy matches the version package.json claims
|
|
17
|
+
- the installed files match the published tarball (skipped when offline)
|
|
18
|
+
- the DSH profile mounts the bundle patch and the eleven tools are registered
|
|
19
|
+
- the running Node satisfies "engines"
|
|
20
|
+
|
|
21
|
+
Nothing is installed or modified; the only network access is one public
|
|
22
|
+
tarball for the hash comparison, and --offline removes even that.
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--package <dir> package copy to inspect (default: the copy this runs from)
|
|
26
|
+
--profile <name> DSH profile name, or a full profile directory
|
|
27
|
+
--offline skip the npm registry comparison
|
|
28
|
+
--no-color never emit ANSI colour
|
|
29
|
+
-h, --help show this message
|
|
30
|
+
|
|
31
|
+
Exit code: 0 when no check fails, 1 when one does, 2 on bad usage.`
|
|
32
|
+
|
|
33
|
+
function valueOf(argv, index, flag) {
|
|
34
|
+
const value = argv[index]
|
|
35
|
+
if (value === undefined || value.startsWith('--')) {
|
|
36
|
+
console.error(`${flag} needs a value\n\n${USAGE}`)
|
|
37
|
+
process.exit(2)
|
|
38
|
+
}
|
|
39
|
+
return value
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parse(argv) {
|
|
43
|
+
const options = {}
|
|
44
|
+
for (let index = 0; index < argv.length; index++) {
|
|
45
|
+
const arg = argv[index]
|
|
46
|
+
if (arg === '--package') options.packageRoot = valueOf(argv, ++index, '--package')
|
|
47
|
+
else if (arg.startsWith('--package=')) options.packageRoot = arg.slice('--package='.length)
|
|
48
|
+
else if (arg === '--profile') options.profile = valueOf(argv, ++index, '--profile')
|
|
49
|
+
else if (arg.startsWith('--profile=')) options.profile = arg.slice('--profile='.length)
|
|
50
|
+
else if (arg === '--offline') options.online = false
|
|
51
|
+
else if (arg === '--no-color') options.color = false
|
|
52
|
+
else if (arg === '-h' || arg === '--help') {
|
|
53
|
+
console.log(USAGE)
|
|
54
|
+
process.exit(0)
|
|
55
|
+
} else {
|
|
56
|
+
console.error(`unknown argument: ${arg}\n\n${USAGE}`)
|
|
57
|
+
process.exit(2)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return options
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const options = parse(process.argv.slice(2))
|
|
64
|
+
// When installed, bin/ lives one level below the package root. Running the
|
|
65
|
+
// checkout from source resolves to the checkout, which is the same idea.
|
|
66
|
+
const defaultRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
67
|
+
const packageRoot = options.packageRoot ? path.resolve(options.packageRoot) : defaultRoot
|
|
68
|
+
|
|
69
|
+
const result = await runDoctor({
|
|
70
|
+
packageRoot,
|
|
71
|
+
// `undefined` means "infer from where this package lives"; only an explicit
|
|
72
|
+
// `--profile` overrides the inference.
|
|
73
|
+
profile: options.profile,
|
|
74
|
+
online: options.online,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const color = options.color !== false
|
|
78
|
+
&& process.stdout.isTTY
|
|
79
|
+
&& !process.env.NO_COLOR
|
|
80
|
+
console.log(renderReport(result, { color }))
|
|
81
|
+
if (!options.profile && !inferProfileDir(result.targetDir)) {
|
|
82
|
+
console.log('\nnot inside a DSH profile, so only the package itself was checked')
|
|
83
|
+
}
|
|
84
|
+
process.exit(result.ok ? 0 : 1)
|