@xiangyixie/dsh-superagent 0.18.0 → 0.18.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/lib/doctor.js +31 -0
- package/package.json +1 -1
package/lib/doctor.js
CHANGED
|
@@ -132,6 +132,21 @@ export function readRegisteredTools(source) {
|
|
|
132
132
|
return names
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Tools registered straight through `ctx.tools.register(defineTool(...))` carry
|
|
137
|
+
* no gate, so every host session pays for them on every request. Registrations
|
|
138
|
+
* that go through the local `registerTool` wrapper pick up the panel/worker
|
|
139
|
+
* gate; those are not counted as resident.
|
|
140
|
+
*/
|
|
141
|
+
export function readResidentTools(source) {
|
|
142
|
+
const names = []
|
|
143
|
+
for (const chunk of String(source).split(/ctx\.tools\.register\(\s*defineTool\(/).slice(1)) {
|
|
144
|
+
const match = /name:\s*['"]([^'"]+)['"]/.exec(chunk)
|
|
145
|
+
if (match) names.push(match[1])
|
|
146
|
+
}
|
|
147
|
+
return names
|
|
148
|
+
}
|
|
149
|
+
|
|
135
150
|
function parseVersion(value) {
|
|
136
151
|
const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(String(value ?? '').trim())
|
|
137
152
|
return match ? { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]) } : null
|
|
@@ -703,6 +718,21 @@ async function checkTools(packageDir, expected, { profileName, version }) {
|
|
|
703
718
|
].join('\n'))
|
|
704
719
|
}
|
|
705
720
|
|
|
721
|
+
async function checkResidentTools(packageDir) {
|
|
722
|
+
const entry = path.join(packageDir, 'lib', 'index.js')
|
|
723
|
+
let source
|
|
724
|
+
try {
|
|
725
|
+
source = await fsp.readFile(entry, 'utf8')
|
|
726
|
+
} catch {
|
|
727
|
+
return check('resident', 'Resident tools', 'warn', ['cannot read lib/index.js; resident tool count skipped'])
|
|
728
|
+
}
|
|
729
|
+
const resident = readResidentTools(source)
|
|
730
|
+
const detail = [`resident tools: ${resident.length} (threshold 0)`]
|
|
731
|
+
if (resident.length === 0) return check('resident', 'Resident tools', 'pass', detail)
|
|
732
|
+
detail.push(`ungated: ${resident.join(', ')}`)
|
|
733
|
+
return check('resident', 'Resident tools', 'warn', detail, 'register these through registerTool so the panel/worker gate applies')
|
|
734
|
+
}
|
|
735
|
+
|
|
706
736
|
async function checkPatchFile(packageDir, pkg, { profileName }) {
|
|
707
737
|
const patchRel = pkg?.dsh?.bundle?.patch
|
|
708
738
|
if (typeof patchRel !== 'string' || !patchRel.trim()) {
|
|
@@ -853,6 +883,7 @@ export async function runDoctor(options = {}) {
|
|
|
853
883
|
checks.push(check('registry', 'Registry match', registry.status, registry.detail, registry.fix ?? null))
|
|
854
884
|
}
|
|
855
885
|
checks.push(await checkTools(targetDir, options.expectedTools ?? TOOL_NAMES, { profileName, version: targetPkg.version }))
|
|
886
|
+
checks.push(await checkResidentTools(targetDir))
|
|
856
887
|
checks.push(await checkPatchFile(targetDir, targetPkg, { profileName }))
|
|
857
888
|
if (profileDir) {
|
|
858
889
|
checks.push(await checkProfile(profileDir, profileName))
|