dsh-crate 0.6.2 → 0.6.4
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/client/client.js +210 -142
- package/lib/discovery-compatibility.js +15 -11
- package/lib/find-plugin.js +33 -30
- package/lib/http.js +20 -1
- package/lib/index.js +42 -4
- package/lib/profile.js +55 -6
- package/lib/routes.js +19 -3
- package/lib/types/discovery-compatibility.d.ts +5 -3
- package/lib/types/find-plugin.d.ts +4 -4
- package/lib/types/http.d.ts +11 -0
- package/lib/types/profile.d.ts +10 -0
- package/package.json +1 -1
|
@@ -233,9 +233,11 @@ function declarationResult(declaration, hostVersion) {
|
|
|
233
233
|
/**
|
|
234
234
|
* Derive the current host verdict from raw manifest facts.
|
|
235
235
|
*
|
|
236
|
-
*
|
|
237
|
-
* host
|
|
238
|
-
*
|
|
236
|
+
* An explicit `engines.dsh` supersedes host peer declarations, matching the
|
|
237
|
+
* host loader. Without one, host peers are conjunctive. Host packages declared
|
|
238
|
+
* as ordinary dependencies remain checked because pnpm can hoist them over the
|
|
239
|
+
* runtime copy. A malformed declaration keeps a passing result unknown, but
|
|
240
|
+
* cannot erase a definite mismatch from another declaration.
|
|
239
241
|
*/
|
|
240
242
|
export function deriveHostCompatibility(facts, hostVersion, hostPackages) {
|
|
241
243
|
if (facts === null) {
|
|
@@ -245,14 +247,16 @@ export function deriveHostCompatibility(facts, hostVersion, hostPackages) {
|
|
|
245
247
|
if (facts.enginesDsh !== null) {
|
|
246
248
|
declarations.push({ kind: 'engine', range: facts.enginesDsh });
|
|
247
249
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
250
|
+
else {
|
|
251
|
+
for (const [name, declared] of Object.entries(facts.peerDependencies)) {
|
|
252
|
+
// Cordis (4.x) and schemastery (3.x) are host packages, but are not on
|
|
253
|
+
// DSH's lockstep 0.x release line and therefore say nothing about the
|
|
254
|
+
// DSH version. `hostPackages` is the local install inventory plus its
|
|
255
|
+
// curated fallback, so future lockstep DSH packages are picked up too.
|
|
256
|
+
if (!hostPackages.has(name) || !/^@deepseek-ai\/dsh(?:-|$)/.test(name))
|
|
257
|
+
continue;
|
|
258
|
+
declarations.push({ kind: 'peer', package: name, range: declared });
|
|
259
|
+
}
|
|
256
260
|
}
|
|
257
261
|
for (const [name, declared] of Object.entries(facts.dependencies ?? {})) {
|
|
258
262
|
// The peer filter above restricts itself to DSH's lockstep line because a
|
package/lib/find-plugin.js
CHANGED
|
@@ -182,10 +182,18 @@ export class FindPluginError extends Error {
|
|
|
182
182
|
this.name = 'FindPluginError';
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
function catalogLine(plugin,
|
|
185
|
+
function catalogLine(plugin, registry, preferZh) {
|
|
186
186
|
const cats = pluginCategories(plugin).map(id => registry.categories[id]?.[preferZh ? 'zh' : 'en'] ?? registry.categories[id]?.en ?? id).join('/');
|
|
187
187
|
const stats = [typeof plugin.downloads === 'number' ? `downloads ${plugin.downloads}` : '', typeof plugin.stars === 'number' ? `stars ${plugin.stars}` : ''].filter(Boolean).join(', ');
|
|
188
|
-
return `${
|
|
188
|
+
return `${plugin.name} [${cats}] ${stats}\n ${describe(plugin, preferZh).slice(0, 400)}`;
|
|
189
|
+
}
|
|
190
|
+
const candidateId = (index) => `p${index + 1}`;
|
|
191
|
+
function candidateLines(candidates, registry, preferZh) {
|
|
192
|
+
return candidates.map(({ plugin }, index) => {
|
|
193
|
+
const source = [plugin.owner, plugin.npm].filter(Boolean).join(' / ');
|
|
194
|
+
const label = source === '' ? '' : ` (${source})`;
|
|
195
|
+
return `[${candidateId(index)}]${label} ${catalogLine(plugin, registry, preferZh)}`;
|
|
196
|
+
});
|
|
189
197
|
}
|
|
190
198
|
/** The instruction and the candidates, as the one message the model reads. */
|
|
191
199
|
export function buildPickPrompt(request, registry, found, have) {
|
|
@@ -197,8 +205,8 @@ export function buildPickPrompt(request, registry, found, have) {
|
|
|
197
205
|
: '';
|
|
198
206
|
const system = [
|
|
199
207
|
'You help a user pick plugins from the DSH plugin crate. Answer ONLY with one JSON object, no prose around it:',
|
|
200
|
-
'{"intro": string, "picks": [{"
|
|
201
|
-
'- picks: the 1 to 5 candidates that best fit what the user actually wants, best first. Use
|
|
208
|
+
'{"intro": string, "picks": [{"id": string, "why": string}]}',
|
|
209
|
+
'- picks: the 1 to 5 candidates that best fit what the user actually wants, best first. Use the candidate IDs (e.g. "p1") exactly as listed. Different entries may share a name. Return [] if none fit.',
|
|
202
210
|
'- why: one short sentence on why it fits THIS request (not a copy of its description).',
|
|
203
211
|
'- intro: one short sentence framing the result, e.g. what you understood they want, or that nothing fits.',
|
|
204
212
|
`- Write intro and why in ${preferZh ? 'Simplified Chinese' : 'the language of the request'}.`,
|
|
@@ -209,7 +217,7 @@ export function buildPickPrompt(request, registry, found, have) {
|
|
|
209
217
|
'', 'Already installed:', ...(have.installed.length === 0 ? ['(none)'] : have.installed.map(plugin => `- ${plugin.name}: ${describe(plugin, preferZh).slice(0, 160)}`)),
|
|
210
218
|
'Favorited:', ...(have.favorited.length === 0 ? ['(none)'] : have.favorited.map(plugin => `- ${plugin.name}: ${describe(plugin, preferZh).slice(0, 160)}`)),
|
|
211
219
|
];
|
|
212
|
-
const user = [`Request: ${request}`, ...mine, '', 'Candidates:', ...found.candidates
|
|
220
|
+
const user = [`Request: ${request}`, ...mine, '', 'Candidates:', ...candidateLines(found.candidates, registry, preferZh)].join('\n');
|
|
213
221
|
return { system, user };
|
|
214
222
|
}
|
|
215
223
|
/** Pull the JSON object out of a model reply (it may wrap it in a code fence). */
|
|
@@ -226,22 +234,22 @@ export function parsePickReply(text, allowed, max = 5) {
|
|
|
226
234
|
}
|
|
227
235
|
if (value === null) {
|
|
228
236
|
// A reply cut off at the token limit (or with a stray character) still
|
|
229
|
-
//
|
|
230
|
-
const found = [...text.matchAll(/"
|
|
237
|
+
// identifies its picks: keep every complete candidate ID in order.
|
|
238
|
+
const found = [...text.matchAll(/"id"\s*:\s*"(p\d+)"(?:\s*,\s*"why"\s*:\s*"((?:[^"\\]|\\.)*)")?/gu)];
|
|
231
239
|
if (found.length === 0)
|
|
232
240
|
throw new Error('the model did not return JSON');
|
|
233
241
|
const intro = /"intro"\s*:\s*"((?:[^"\\]|\\.)*)"/u.exec(text)?.[1] ?? '';
|
|
234
|
-
value = { intro, picks: found.map(match => ({
|
|
242
|
+
value = { intro, picks: found.map(match => ({ id: match[1], why: match[2] ?? '' })) };
|
|
235
243
|
}
|
|
236
244
|
const picks = [];
|
|
237
245
|
const seen = new Set();
|
|
238
246
|
if (Array.isArray(value.picks)) {
|
|
239
247
|
for (const item of value.picks) {
|
|
240
|
-
const
|
|
241
|
-
if (!allowed.has(
|
|
248
|
+
const id = typeof item?.id === 'string' ? item.id.trim() : '';
|
|
249
|
+
if (!allowed.has(id) || seen.has(id))
|
|
242
250
|
continue;
|
|
243
|
-
seen.add(
|
|
244
|
-
picks.push({
|
|
251
|
+
seen.add(id);
|
|
252
|
+
picks.push({ id, why: typeof item?.why === 'string' ? item.why.trim().slice(0, 300) : '' });
|
|
245
253
|
if (picks.length === max)
|
|
246
254
|
break;
|
|
247
255
|
}
|
|
@@ -270,7 +278,7 @@ function toPick(plugin, registry, preferZh, why) {
|
|
|
270
278
|
};
|
|
271
279
|
}
|
|
272
280
|
const hasModel = (llm, selection) => llm !== undefined && selection !== undefined && Boolean(selection.provider) && Boolean(selection.model);
|
|
273
|
-
/** One model call over the candidates;
|
|
281
|
+
/** One model call over the candidates; resolve picks only to the entries offered. */
|
|
274
282
|
async function askForPicks(options) {
|
|
275
283
|
const { selection, prompt } = options;
|
|
276
284
|
let text = '';
|
|
@@ -280,11 +288,7 @@ async function askForPicks(options) {
|
|
|
280
288
|
const stream = options.llm.stream({
|
|
281
289
|
provider: selection.provider,
|
|
282
290
|
model: selection.model,
|
|
283
|
-
//
|
|
284
|
-
// hard can spend the whole budget thinking and answer nothing (seen with
|
|
285
|
-
// DeepSeek at "high"). A selection that names an effort supports
|
|
286
|
-
// efforts, so it can be turned down; one that does not is left alone.
|
|
287
|
-
...(selection.reasoningEffort === undefined ? {} : { reasoningEffort: selection.reasoningEffort === 'off' ? 'off' : 'low' }),
|
|
291
|
+
// Leave sampling and reasoning at the selected model's DSH defaults.
|
|
288
292
|
system: prompt.system,
|
|
289
293
|
messages: [Object.freeze({
|
|
290
294
|
id: randomUUID(), role: 'user',
|
|
@@ -292,7 +296,6 @@ async function askForPicks(options) {
|
|
|
292
296
|
source: { kind: 'plugin:dsh-crate' },
|
|
293
297
|
})],
|
|
294
298
|
maxTokens: options.maxTokens,
|
|
295
|
-
temperature: options.temperature,
|
|
296
299
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
297
300
|
});
|
|
298
301
|
for await (const chunk of stream) {
|
|
@@ -324,9 +327,10 @@ async function askForPicks(options) {
|
|
|
324
327
|
const reason = error instanceof Error ? error.message : String(error);
|
|
325
328
|
throw new FindPluginError('model-failed', `模型这次没有回答(${reason})。请稍后重试,或换一个模型。 / The model did not answer (${reason}). Try again, or switch models.`);
|
|
326
329
|
}
|
|
330
|
+
const byId = new Map(options.candidates.map(({ plugin }, index) => [candidateId(index), plugin]));
|
|
327
331
|
let parsed;
|
|
328
332
|
try {
|
|
329
|
-
const allowed = new Set(
|
|
333
|
+
const allowed = new Set(byId.keys());
|
|
330
334
|
// Out of budget before the answer: the thinking often already holds it.
|
|
331
335
|
parsed = text.trim() === '' && reasoning !== '' ? parsePickReply(reasoning, allowed, options.max) : parsePickReply(text, allowed, options.max);
|
|
332
336
|
}
|
|
@@ -334,8 +338,7 @@ async function askForPicks(options) {
|
|
|
334
338
|
logEvent('warn', 'find-plugin', `unreadable model reply (${String(text.length)} chars, ${String(reasoning.length)} thinking): ${text.slice(0, 300)} … ${text.slice(-200)} | chunks: ${seen.join(' ')}`);
|
|
335
339
|
throw new FindPluginError('model-failed', '模型的回答格式不对,没法整理成结果。请重试一次。 / The model\'s answer was not in the expected shape. Try again.');
|
|
336
340
|
}
|
|
337
|
-
|
|
338
|
-
return { intro: parsed.intro, picks: parsed.picks.map(({ name, why }) => ({ plugin: byName.get(name), why })) };
|
|
341
|
+
return { intro: parsed.intro, picks: parsed.picks.map(({ id, why }) => ({ plugin: byId.get(id), why })) };
|
|
339
342
|
}
|
|
340
343
|
/** Recall, then let the model pick. Throws FindPluginError with a user-facing message. */
|
|
341
344
|
export async function findPlugins(options) {
|
|
@@ -349,11 +352,11 @@ export async function findPlugins(options) {
|
|
|
349
352
|
const found = recall(registry, extractTerms(request), CANDIDATE_LIMIT, new Set((have?.installed ?? []).map(plugin => plugin.name)));
|
|
350
353
|
const answer = await askForPicks({
|
|
351
354
|
llm: llm, selection, prompt: buildPickPrompt(request, registry, found, have), candidates: found.candidates,
|
|
352
|
-
max: 5, maxTokens: 6000,
|
|
355
|
+
max: 5, maxTokens: 6000, ...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
353
356
|
});
|
|
354
357
|
const preferZh = /\p{Script=Han}/u.test(request);
|
|
355
358
|
const picks = answer.picks.map(({ plugin, why }) => toPick(plugin, registry, preferZh, why));
|
|
356
|
-
return { request, intro: answer.intro, picks, model: selection.model, at: new Date().toISOString(), personalized: have !== undefined };
|
|
359
|
+
return { request, intro: answer.intro, picks, model: selection.model, at: new Date().toISOString(), selectionVersion: 2, personalized: have !== undefined };
|
|
357
360
|
}
|
|
358
361
|
// ---------- recommendations from what the user already has ----------
|
|
359
362
|
/** How many candidates a recommendation offers the model. */
|
|
@@ -412,18 +415,18 @@ export function recommendCandidates(registry, seeds, exclude = [], limit = RECOM
|
|
|
412
415
|
export function buildRecommendPrompt(registry, seeds, candidates, preferZh) {
|
|
413
416
|
const system = [
|
|
414
417
|
'You recommend plugins from the DSH plugin crate to one user, based on the plugins they already installed and favorited. Answer ONLY with one JSON object, no prose around it:',
|
|
415
|
-
'{"intro": string, "picks": [{"
|
|
416
|
-
`- picks: ${String(RECOMMEND_MAX - 4)} to ${String(RECOMMEND_MAX)} candidates this user is most likely to want next, best first. Use
|
|
418
|
+
'{"intro": string, "picks": [{"id": string, "why": string}]}',
|
|
419
|
+
`- picks: ${String(RECOMMEND_MAX - 4)} to ${String(RECOMMEND_MAX)} candidates this user is most likely to want next, best first. Use the candidate IDs (e.g. "p1") exactly as listed. Different entries may share a name.`,
|
|
417
420
|
'- Read what they have as a picture of how they use DSH. Prefer plugins that add something they do not have yet, or go well with what they have; skip near-duplicates of plugins they already have.',
|
|
418
421
|
'- Spread the picks over different needs rather than many plugins for one need. A well-used, maintained plugin beats an obscure one when both fit.',
|
|
419
422
|
'- why: one short sentence. intro: one short sentence on what you read from their plugins.',
|
|
420
423
|
`- Write intro and why in ${preferZh ? 'Simplified Chinese' : 'English'}.`,
|
|
421
424
|
].join('\n');
|
|
422
|
-
const list = (plugins) => plugins.length === 0 ? ['(none)'] : plugins.map((plugin, i) => catalogLine(plugin,
|
|
425
|
+
const list = (plugins) => plugins.length === 0 ? ['(none)'] : plugins.map((plugin, i) => `${i + 1}. ${catalogLine(plugin, registry, preferZh)}`);
|
|
423
426
|
const user = [
|
|
424
427
|
'Installed:', ...list(seeds.installed), '',
|
|
425
428
|
'Favorited (not necessarily installed):', ...list(seeds.favorited), '',
|
|
426
|
-
'Candidates:', ...candidates
|
|
429
|
+
'Candidates:', ...candidateLines(candidates, registry, preferZh),
|
|
427
430
|
].join('\n');
|
|
428
431
|
return { system, user };
|
|
429
432
|
}
|
|
@@ -442,10 +445,10 @@ export async function recommendPlugins(options) {
|
|
|
442
445
|
candidates = recommendCandidates(registry, [...seeds.installed, ...seeds.favorited]);
|
|
443
446
|
const answer = await askForPicks({
|
|
444
447
|
llm: llm, selection, prompt: buildRecommendPrompt(registry, seeds, candidates, preferZh), candidates,
|
|
445
|
-
max: RECOMMEND_MAX, maxTokens: 8000,
|
|
448
|
+
max: RECOMMEND_MAX, maxTokens: 8000, ...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
446
449
|
});
|
|
447
450
|
const picks = answer.picks.map(({ plugin, why }) => toPick(plugin, registry, preferZh, why));
|
|
448
|
-
return { request: '', intro: answer.intro, picks, model: selection.model, at: new Date().toISOString() };
|
|
451
|
+
return { request: '', intro: answer.intro, picks, model: selection.model, at: new Date().toISOString(), selectionVersion: 2 };
|
|
449
452
|
}
|
|
450
453
|
/** Plain text of a result, for hosts that draw the command row as text. */
|
|
451
454
|
export function resultText(result) {
|
package/lib/http.js
CHANGED
|
@@ -39,6 +39,23 @@ export function setRequestGateSource(source) {
|
|
|
39
39
|
requestGateSource = source;
|
|
40
40
|
return previous;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The request as `connection.admit` reads it: headers, the socket, and an
|
|
44
|
+
* absolute `url` — what the host's own `webserver/authorize` hands the same
|
|
45
|
+
* check (the incoming request's `url` is only a path).
|
|
46
|
+
*/
|
|
47
|
+
export function admissionFacts(request) {
|
|
48
|
+
const host = request.headers.host ?? 'localhost';
|
|
49
|
+
const scheme = request.socket?.encrypted === true ? 'https' : 'http';
|
|
50
|
+
let url;
|
|
51
|
+
try {
|
|
52
|
+
url = new URL(request.url ?? '/', `${scheme}://${host}`).href;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
url = `${scheme}://localhost/`;
|
|
56
|
+
}
|
|
57
|
+
return { method: request.method ?? 'GET', headers: request.headers, socket: request.socket, url };
|
|
58
|
+
}
|
|
42
59
|
/**
|
|
43
60
|
* Answer the request with the host's rejection, if it has one.
|
|
44
61
|
* @returns true when the request was refused and answered here.
|
|
@@ -61,7 +78,9 @@ export function refuseUnadmitted(request, response) {
|
|
|
61
78
|
sendJson(response, status, {
|
|
62
79
|
error: status === 401
|
|
63
80
|
? '需要先登录 DSH:请重新打开 dsh web 启动时打印的那个网址。 / DSH login required: reopen the URL dsh web printed at startup.'
|
|
64
|
-
:
|
|
81
|
+
: status === 503
|
|
82
|
+
? 'DSH 的登录检查暂时出错,请稍后重试。 / DSH\'s login check failed for now. Try again in a moment.'
|
|
83
|
+
: '这个请求来自不受信任的地址,已拒绝。 / This request came from an untrusted origin and was refused.',
|
|
65
84
|
});
|
|
66
85
|
return true;
|
|
67
86
|
}
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { dirname, isAbsolute } from 'node:path';
|
|
|
7
7
|
import { createDesktopPluginRuntime, setHostPackageManager } from './dsh-cli.js';
|
|
8
8
|
import { createOfficialDesktopRuntime } from './official-desktop.js';
|
|
9
9
|
import { isDshProfileName, profileDir } from './profile.js';
|
|
10
|
-
import { setRequestGateSource, setTrustedHostsSource } from './http.js';
|
|
10
|
+
import { admissionFacts, setRequestGateSource, setTrustedHostsSource } from './http.js';
|
|
11
11
|
import { setLauncherInstallAnchorSource } from './dsh-install.js';
|
|
12
12
|
import { mountMarketRoutes } from './routes.js';
|
|
13
13
|
import { installDesktopMarketSettings, installMarketSettings } from './settings.js';
|
|
@@ -196,14 +196,47 @@ export function useTrustedHosts(ctx) {
|
|
|
196
196
|
}
|
|
197
197
|
return hosts;
|
|
198
198
|
});
|
|
199
|
+
// The gate below calls `connection.admit`, which verifies the browser login
|
|
200
|
+
// through `connection.authentication`. Cordis resolves a service property
|
|
201
|
+
// through the context the service was READ from, not the one that provided
|
|
202
|
+
// it: reading the connection from this plugin's own context — which
|
|
203
|
+
// declares `webServer` and `loader`, never the registry — made `admit`
|
|
204
|
+
// throw `cannot get property "connection.authentication" without inject`.
|
|
205
|
+
// The fence turns any throw into 403, so every route answered 403 for every
|
|
206
|
+
// browser, signed in or not, on every host that replaced `requestRejection`
|
|
207
|
+
// with `admit` (#1299).
|
|
208
|
+
//
|
|
209
|
+
// Declaring the registry is what makes that read legal, and the declared
|
|
210
|
+
// scope is what the call has to be made from. A host that has no registry —
|
|
211
|
+
// every release before `admit` existed — leaves the scope cold, and the
|
|
212
|
+
// source below then reads the connection from here exactly as it always
|
|
213
|
+
// did: `requestRejection` needs no such declaration. A host that has one
|
|
214
|
+
// makes both branches reachable, which is the whole point.
|
|
215
|
+
let gateCtx;
|
|
216
|
+
const gateScope = ctx.inject(['connection', 'connection.authentication'], (loginCtx) => {
|
|
217
|
+
gateCtx = loginCtx;
|
|
218
|
+
return () => { if (gateCtx === loginCtx)
|
|
219
|
+
gateCtx = undefined; };
|
|
220
|
+
});
|
|
199
221
|
// The same service carries the host's request gate (#603): its fence plus
|
|
200
222
|
// its browser login, the check its own API runs. Read per request for the
|
|
201
223
|
// same reason as the authorities above.
|
|
202
224
|
const previousGate = setRequestGateSource(() => {
|
|
203
|
-
const connection = ctx.get('connection');
|
|
225
|
+
const connection = (gateCtx ?? ctx).get('connection');
|
|
204
226
|
const gate = connection?.requestRejection;
|
|
205
|
-
|
|
206
|
-
|
|
227
|
+
if (typeof gate === 'function') {
|
|
228
|
+
return request => gate.call(connection, request);
|
|
229
|
+
}
|
|
230
|
+
// DSH 0.2.3 removed requestRejection for `admit(request)`: the Host/Origin
|
|
231
|
+
// fence, then the registered credential providers, answering `{ peer }` or
|
|
232
|
+
// `{ rejection: status }` (#1289). Without this the gate quietly became a
|
|
233
|
+
// no-op on those hosts.
|
|
234
|
+
const admit = connection?.admit;
|
|
235
|
+
return typeof admit === 'function'
|
|
236
|
+
? (request => {
|
|
237
|
+
const answer = admit.call(connection, admissionFacts(request));
|
|
238
|
+
return typeof answer?.rejection === 'number' ? answer.rejection : answer === undefined ? 403 : undefined;
|
|
239
|
+
})
|
|
207
240
|
: undefined;
|
|
208
241
|
});
|
|
209
242
|
// The setter returns the PREVIOUS source, not a restore closure — the same
|
|
@@ -211,6 +244,11 @@ export function useTrustedHosts(ctx) {
|
|
|
211
244
|
return () => {
|
|
212
245
|
setTrustedHostsSource(previous);
|
|
213
246
|
setRequestGateSource(previousGate);
|
|
247
|
+
// The scoped fiber holds the only declaration that made the gate readable;
|
|
248
|
+
// keeping it alive after the source is pulled back would leave a dependency
|
|
249
|
+
// on a host that may never provide it.
|
|
250
|
+
void Promise.resolve(gateScope.dispose()).catch(() => { });
|
|
251
|
+
gateCtx = undefined;
|
|
214
252
|
};
|
|
215
253
|
}
|
|
216
254
|
/**
|
package/lib/profile.js
CHANGED
|
@@ -780,6 +780,28 @@ export function readLockCommits(profile, explicitDir) {
|
|
|
780
780
|
catch { /* no lockfile — no git installs to report */ }
|
|
781
781
|
return commits;
|
|
782
782
|
}
|
|
783
|
+
/**
|
|
784
|
+
* The repository key and commit an archive tarball URL names, or null for a
|
|
785
|
+
* URL none of the supported hosts serves.
|
|
786
|
+
*
|
|
787
|
+
* The same shapes `readLockCommits` scans for, applied to one URL: a
|
|
788
|
+
* `resolution:` block records the archive it fetched, and that URL is the
|
|
789
|
+
* only place the commit appears in it.
|
|
790
|
+
*/
|
|
791
|
+
function archiveIdentityOf(url) {
|
|
792
|
+
for (const shape of ARCHIVE_COMMIT_SHAPES) {
|
|
793
|
+
// These patterns are global for `matchAll` above; `exec` advances
|
|
794
|
+
// `lastIndex`, so both ends are reset rather than shared.
|
|
795
|
+
shape.lastIndex = 0;
|
|
796
|
+
const m = shape.exec(url);
|
|
797
|
+
shape.lastIndex = 0;
|
|
798
|
+
if (m === null)
|
|
799
|
+
continue;
|
|
800
|
+
const host = m[1].toLowerCase() === 'codeload.github.com' ? 'github.com' : m[1].toLowerCase();
|
|
801
|
+
return { key: `${host}/${archivePath(m[2]).toLowerCase()}`, commit: m[3].toLowerCase() };
|
|
802
|
+
}
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
783
805
|
/**
|
|
784
806
|
* Commit recorded for a non-codeload git resolution (`type: git` in pnpm's
|
|
785
807
|
* lockfile). Matched against the install spec so a Gitea/GitLab URL can
|
|
@@ -790,6 +812,16 @@ export function readLockCommits(profile, explicitDir) {
|
|
|
790
812
|
* when the spec names no subpath while several entries of that remote do,
|
|
791
813
|
* there is no answer rather than the first sibling's commit (#632).
|
|
792
814
|
*
|
|
815
|
+
* A `type: git` block is not the only shape: every host the market supports
|
|
816
|
+
* resolves its install to an archive of that host, whose resolution carries
|
|
817
|
+
* `gitHosted: true`, the commit inside `tarball:` and the subpackage in
|
|
818
|
+
* `path:` — no `commit:` and no `repo:` (#632, #637). Reading only the git
|
|
819
|
+
* block left a monorepo subpackage with no identity of its own, so callers
|
|
820
|
+
* fell back to `readLockCommits`, which keeps one slot per repository: with
|
|
821
|
+
* any sibling still on an older commit, that sibling answered for every
|
|
822
|
+
* subpackage, and an update that really happened was reported as STALE
|
|
823
|
+
* (#1296).
|
|
824
|
+
*
|
|
793
825
|
* The key on both sides of the comparison is `hostedRepoKey`, the identity
|
|
794
826
|
* the rest of the market already compares specs by (#851). This function
|
|
795
827
|
* used to derive its own, and that second spelling lost every install pnpm
|
|
@@ -813,17 +845,34 @@ export function readGitResolutionCommit(profile, spec, explicitDir) {
|
|
|
813
845
|
const body = m[1];
|
|
814
846
|
const commit = /\bcommit:\s*([0-9a-f]{40})\b/i.exec(body);
|
|
815
847
|
const repo = /\brepo:\s*([^\s,}]+)/.exec(body);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (
|
|
848
|
+
let recorded = null;
|
|
849
|
+
let fromArchive = false;
|
|
850
|
+
if (commit !== null && repo !== null) {
|
|
851
|
+
if (hostedRepoKey(repo[1]) === want)
|
|
852
|
+
recorded = commit[1].toLowerCase();
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
const archive = archiveIdentityOf(/\btarball:\s*([^,}]+)/.exec(body)?.[1].trim() ?? '');
|
|
856
|
+
if (archive !== null && archive.key === want) {
|
|
857
|
+
recorded = archive.commit;
|
|
858
|
+
fromArchive = true;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (recorded === null)
|
|
819
862
|
continue;
|
|
820
|
-
const
|
|
863
|
+
const rawPath = /\bpath:\s*([^\s,}]+)/.exec(body)?.[1];
|
|
864
|
+
const entryPath = rawPath === undefined ? null : rawPath.replace(/^\/+|\/+$/g, '').toLowerCase() || null;
|
|
821
865
|
if (wantPath !== null) {
|
|
822
866
|
if (entryPath === wantPath)
|
|
823
|
-
return
|
|
867
|
+
return recorded;
|
|
824
868
|
continue;
|
|
825
869
|
}
|
|
826
|
-
|
|
870
|
+
// An archive entry is one subpackage, named by its `path:`. A spec that
|
|
871
|
+
// names no subpath is that repository's root, not the sibling pnpm
|
|
872
|
+
// happened to list last.
|
|
873
|
+
if (fromArchive && entryPath !== null)
|
|
874
|
+
continue;
|
|
875
|
+
matches.push(recorded);
|
|
827
876
|
}
|
|
828
877
|
}
|
|
829
878
|
catch { /* no lockfile */ }
|
package/lib/routes.js
CHANGED
|
@@ -5233,18 +5233,34 @@ export function mountMarketRoutes(host, config, commandRuntime, agentsLookup, ho
|
|
|
5233
5233
|
}
|
|
5234
5234
|
const state = readMarketState(activeProfileDir);
|
|
5235
5235
|
const id = userCatalogId(entry);
|
|
5236
|
-
|
|
5236
|
+
// A newer pack of the same catalog replaces the older import. The id
|
|
5237
|
+
// follows the content, so without this the old copy keeps winning
|
|
5238
|
+
// ("first source wins") and the new version never shows (#1295).
|
|
5239
|
+
// "Same catalog" means an earlier OFFLINE import with the same label.
|
|
5240
|
+
const labelKey = JSON.stringify(probe.info.label ?? null);
|
|
5241
|
+
const replaced = [];
|
|
5242
|
+
for (const item of state.userCatalogs ?? []) {
|
|
5243
|
+
if (item.id === id || item.file === undefined || !isInsideOfflineRoot(item.file))
|
|
5244
|
+
continue;
|
|
5245
|
+
const older = await probeCatalog({ file: item.file });
|
|
5246
|
+
if (older.registry !== null && labelKey !== 'null' && JSON.stringify(older.info.label ?? null) === labelKey) {
|
|
5247
|
+
replaced.push({ id: item.id, file: item.file });
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5250
|
+
const saved = (state.userCatalogs ?? []).filter(item => item.id !== id && !replaced.some(old => old.id === item.id));
|
|
5237
5251
|
if (saved.length >= MAX_USER_CATALOGS) {
|
|
5238
5252
|
rmSync(extracted.dir, { recursive: true, force: true });
|
|
5239
5253
|
sendJson(response, 400, { ok: false, code: 'limit', limit: MAX_USER_CATALOGS, error: `at most ${String(MAX_USER_CATALOGS)} catalogs / 最多添加 ${String(MAX_USER_CATALOGS)} 个目录` });
|
|
5240
5254
|
return;
|
|
5241
5255
|
}
|
|
5242
5256
|
writeMarketState(activeProfileDir, { ...state, userCatalogs: [...saved, { id, ...entry }] });
|
|
5257
|
+
for (const old of replaced)
|
|
5258
|
+
rmSync(dirname(old.file), { recursive: true, force: true });
|
|
5243
5259
|
refreshMarketState();
|
|
5244
5260
|
forgetCatalog();
|
|
5245
5261
|
invalidateUpdates();
|
|
5246
|
-
logEvent('info', 'offline', `imported bundle ${extracted.id}: ${String(probe.info.count)} plugins, ${String(extracted.files)} files`);
|
|
5247
|
-
sendJson(response, 200, { ok: true, id, count: probe.info.count, label: probe.info.label });
|
|
5262
|
+
logEvent('info', 'offline', `imported bundle ${extracted.id}: ${String(probe.info.count)} plugins, ${String(extracted.files)} files${replaced.length > 0 ? `, replaced ${String(replaced.length)} older import(s)` : ''}`);
|
|
5263
|
+
sendJson(response, 200, { ok: true, id, count: probe.info.count, label: probe.info.label, replaced: replaced.length });
|
|
5248
5264
|
});
|
|
5249
5265
|
}
|
|
5250
5266
|
catch (error) {
|
|
@@ -53,9 +53,11 @@ export declare function manifestFacts(value: unknown): NpmManifestFacts;
|
|
|
53
53
|
/**
|
|
54
54
|
* Derive the current host verdict from raw manifest facts.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
57
|
-
* host
|
|
58
|
-
*
|
|
56
|
+
* An explicit `engines.dsh` supersedes host peer declarations, matching the
|
|
57
|
+
* host loader. Without one, host peers are conjunctive. Host packages declared
|
|
58
|
+
* as ordinary dependencies remain checked because pnpm can hoist them over the
|
|
59
|
+
* runtime copy. A malformed declaration keeps a passing result unknown, but
|
|
60
|
+
* cannot erase a definite mismatch from another declaration.
|
|
59
61
|
*/
|
|
60
62
|
export declare function deriveHostCompatibility(facts: NpmManifestFacts | null, hostVersion: string | null, hostPackages: ReadonlySet<string>): HostCompatibility;
|
|
61
63
|
/**
|
|
@@ -39,6 +39,8 @@ export interface FindResult {
|
|
|
39
39
|
/** Which model answered, for the card's footnote. */
|
|
40
40
|
model: string;
|
|
41
41
|
at: string;
|
|
42
|
+
/** Older saved results lack an exact candidate selection. */
|
|
43
|
+
selectionVersion?: 2;
|
|
42
44
|
/** Whether the user's installed and favorited plugins informed the picks (they allowed it). */
|
|
43
45
|
personalized?: boolean;
|
|
44
46
|
}
|
|
@@ -52,11 +54,9 @@ export interface LlmLike {
|
|
|
52
54
|
stream(options: {
|
|
53
55
|
provider: string;
|
|
54
56
|
model: string;
|
|
55
|
-
reasoningEffort?: string;
|
|
56
57
|
messages: unknown[];
|
|
57
58
|
system?: string;
|
|
58
59
|
maxTokens?: number;
|
|
59
|
-
temperature?: number;
|
|
60
60
|
signal?: AbortSignal;
|
|
61
61
|
}): AsyncIterable<{
|
|
62
62
|
type: string;
|
|
@@ -79,10 +79,10 @@ export declare function buildPickPrompt(request: string, registry: Registry, fou
|
|
|
79
79
|
user: string;
|
|
80
80
|
};
|
|
81
81
|
/** Pull the JSON object out of a model reply (it may wrap it in a code fence). */
|
|
82
|
-
export declare function parsePickReply(text: string, allowed:
|
|
82
|
+
export declare function parsePickReply(text: string, allowed: ReadonlySet<string>, max?: number): {
|
|
83
83
|
intro: string;
|
|
84
84
|
picks: Array<{
|
|
85
|
-
|
|
85
|
+
id: string;
|
|
86
86
|
why: string;
|
|
87
87
|
}>;
|
|
88
88
|
};
|
package/lib/types/http.d.ts
CHANGED
|
@@ -25,6 +25,17 @@ export declare function sendJson(response: ServerResponse, status: number, paylo
|
|
|
25
25
|
export type HostRequestGate = (request: IncomingMessage) => number | undefined;
|
|
26
26
|
/** Point the market at the host's request gate. Returns the previous source. */
|
|
27
27
|
export declare function setRequestGateSource(source: () => HostRequestGate | undefined): () => HostRequestGate | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The request as `connection.admit` reads it: headers, the socket, and an
|
|
30
|
+
* absolute `url` — what the host's own `webserver/authorize` hands the same
|
|
31
|
+
* check (the incoming request's `url` is only a path).
|
|
32
|
+
*/
|
|
33
|
+
export declare function admissionFacts(request: IncomingMessage): {
|
|
34
|
+
method: string;
|
|
35
|
+
headers: IncomingMessage['headers'];
|
|
36
|
+
socket: IncomingMessage['socket'];
|
|
37
|
+
url: string;
|
|
38
|
+
};
|
|
28
39
|
/**
|
|
29
40
|
* Answer the request with the host's rejection, if it has one.
|
|
30
41
|
* @returns true when the request was refused and answered here.
|
package/lib/types/profile.d.ts
CHANGED
|
@@ -256,6 +256,16 @@ export declare function readLockCommits(profile: string, explicitDir?: string):
|
|
|
256
256
|
* when the spec names no subpath while several entries of that remote do,
|
|
257
257
|
* there is no answer rather than the first sibling's commit (#632).
|
|
258
258
|
*
|
|
259
|
+
* A `type: git` block is not the only shape: every host the market supports
|
|
260
|
+
* resolves its install to an archive of that host, whose resolution carries
|
|
261
|
+
* `gitHosted: true`, the commit inside `tarball:` and the subpackage in
|
|
262
|
+
* `path:` — no `commit:` and no `repo:` (#632, #637). Reading only the git
|
|
263
|
+
* block left a monorepo subpackage with no identity of its own, so callers
|
|
264
|
+
* fell back to `readLockCommits`, which keeps one slot per repository: with
|
|
265
|
+
* any sibling still on an older commit, that sibling answered for every
|
|
266
|
+
* subpackage, and an update that really happened was reported as STALE
|
|
267
|
+
* (#1296).
|
|
268
|
+
*
|
|
259
269
|
* The key on both sides of the comparison is `hostedRepoKey`, the identity
|
|
260
270
|
* the rest of the market already compares specs by (#851). This function
|
|
261
271
|
* used to derive its own, and that second spelling lost every install pnpm
|