dsh-agent-plugins-market 0.14.0 → 0.14.2
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 +368 -132
- package/client/client.js.map +1 -1
- package/lib/packages/market-catalog/src/application/source-store.js +4 -0
- package/lib/packages/market-catalog/src/scanning/paths.js +31 -10
- package/lib/packages/market-catalog/src/scanning/source-name.js +40 -0
- package/lib/packages/market-mcp/src/application/mcp/mcp-bridge-config.js +13 -6
- package/lib/packages/market-mcp/src/runtime/mcp/bridge/bridge.js +7 -4
- package/lib/packages/market-mcp/src/runtime/mcp/bridge/host-contract.js +18 -5
- package/lib/packages/market-runtime/src/runtime/agents/teammate-role-runtime.js +23 -1
- package/lib/packages/market-runtime/src/runtime/host/extension-progress.js +62 -17
- package/lib/packages/market-runtime/src/runtime/host/extension-runtime.js +46 -4
- package/lib/packages/market-runtime/src/runtime/host/extension-tool-gates.js +20 -5
- package/lib/packages/market-runtime/src/runtime/surfaces/extension-hooks.js +11 -2
- package/lib/types/packages/market-catalog/src/scanning/paths.d.ts +24 -0
- package/lib/types/packages/market-catalog/src/scanning/source-name.d.ts +39 -0
- package/lib/types/packages/market-contracts/src/contracts/market.d.ts +6 -0
- package/lib/types/packages/market-mcp/src/application/mcp/mcp-bridge-config.d.ts +13 -6
- package/lib/types/packages/market-mcp/src/runtime/mcp/bridge/host-contract.d.ts +60 -49
- package/lib/types/packages/market-mcp/src/runtime/mcp/bridge/projection.d.ts +2 -2
- package/lib/types/packages/market-runtime/src/runtime/host/extension-progress.d.ts +14 -5
- package/lib/types/packages/market-runtime/src/runtime/host/extension-runtime.d.ts +21 -4
- package/lib/types/packages/market-runtime/src/runtime/host/extension-tool-gates.d.ts +11 -3
- package/lib/types/packages/market-runtime/src/runtime/surfaces/extension-hooks.d.ts +9 -0
- package/package.json +74 -65
|
@@ -15,6 +15,7 @@ import { repoName } from '../scanning/manifests.js';
|
|
|
15
15
|
import { deriveSourceIdCandidates, expandHome, sanitizeId, sourceCheckoutDir, sourcesDir } from '../scanning/paths.js';
|
|
16
16
|
import { isDirectory, pathExists } from '../scanning/fs-probes.js';
|
|
17
17
|
import { canonicalGitUrl } from '../scanning/scan-resolvers.js';
|
|
18
|
+
import { qualifiedSourceName } from '../scanning/source-name.js';
|
|
18
19
|
import { githubCloneUrl, resolveRegion } from './regions.js';
|
|
19
20
|
import { resolveSourceKind } from '../../../market-contracts/src/model/types.js';
|
|
20
21
|
export class SourceStore {
|
|
@@ -372,8 +373,11 @@ export class SourceStore {
|
|
|
372
373
|
const status = await this.describeCheckout(source);
|
|
373
374
|
const sourceSuites = snapshot.suites.filter(suite => suite.sourceId === source.id);
|
|
374
375
|
const scanNotes = snapshot.scanNotes?.[source.id];
|
|
376
|
+
// A display name only: the id stays the key the state and every resource id use.
|
|
377
|
+
const displayName = qualifiedSourceName(source, sourceSuites);
|
|
375
378
|
rows.push({
|
|
376
379
|
id: source.id,
|
|
380
|
+
...(displayName === undefined ? {} : { displayName }),
|
|
377
381
|
url: source.url,
|
|
378
382
|
...(source.branch === undefined ? {} : { branch: source.branch }),
|
|
379
383
|
...(source.local === true ? { local: true } : {}),
|
|
@@ -164,6 +164,32 @@ function stripSourceSuffix(base) {
|
|
|
164
164
|
const withoutGit = base.endsWith('.git') ? base.slice(0, -4) : base;
|
|
165
165
|
return stripArchiveSuffix(withoutGit);
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* The owner and the repository a remote URL names, or undefined when the URL
|
|
169
|
+
* is a local path.
|
|
170
|
+
*
|
|
171
|
+
* Both the owner-prefixed source id and the qualified display name read this
|
|
172
|
+
* one parse, so the two cannot drift apart over what a URL says.
|
|
173
|
+
*
|
|
174
|
+
* @param url - a git URL or a local path.
|
|
175
|
+
* @returns the owner and repository, or undefined for a local path.
|
|
176
|
+
*/
|
|
177
|
+
export function parseRemoteRepository(url) {
|
|
178
|
+
const trimmed = url.trim().replace(/\/+$/, '');
|
|
179
|
+
const isRemote = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) || /^[\w.-]+@[\w.-]+:/.test(trimmed);
|
|
180
|
+
if (!isRemote)
|
|
181
|
+
return undefined;
|
|
182
|
+
const hostPath = trimmed.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').replace(/^[\w.-]+@([\w.-]+):/, '$1/');
|
|
183
|
+
const segments = hostPath.split(/[/\\]/).filter(Boolean);
|
|
184
|
+
const owner = segments.at(-2);
|
|
185
|
+
const baseSegment = segments.at(-1);
|
|
186
|
+
if (owner === undefined || baseSegment === undefined)
|
|
187
|
+
return undefined;
|
|
188
|
+
const base = stripSourceSuffix(baseSegment);
|
|
189
|
+
if (owner === '' || base === '')
|
|
190
|
+
return undefined;
|
|
191
|
+
return { owner, base };
|
|
192
|
+
}
|
|
167
193
|
/**
|
|
168
194
|
* Derive candidate source ids from a git URL or local path, most preferred
|
|
169
195
|
* first: the sanitized basename, then an owner-prefixed variant (`owner-repo`)
|
|
@@ -175,17 +201,12 @@ export function deriveSourceIdCandidates(url) {
|
|
|
175
201
|
const trimmed = url.trim().replace(/\/+$/, '');
|
|
176
202
|
const base = stripSourceSuffix(trimmed.split(/[/\\]/).at(-1) ?? '');
|
|
177
203
|
const primary = sanitizeId(base);
|
|
178
|
-
const isRemote = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) || /^[\w.-]+@[\w.-]+:/.test(trimmed);
|
|
179
204
|
const candidates = [primary];
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const owner = sanitizeId(ownerSegment);
|
|
186
|
-
if (owner !== '' && owner !== primary)
|
|
187
|
-
candidates.push(`${owner}-${primary}`);
|
|
188
|
-
}
|
|
205
|
+
const remote = parseRemoteRepository(url);
|
|
206
|
+
if (remote !== undefined) {
|
|
207
|
+
const owner = sanitizeId(remote.owner);
|
|
208
|
+
if (owner !== '' && owner !== primary)
|
|
209
|
+
candidates.push(`${owner}-${primary}`);
|
|
189
210
|
}
|
|
190
211
|
return [...new Set(candidates)];
|
|
191
212
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parseRemoteRepository, sanitizeId } from './paths.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a source's suites are skill collections rather than a plugin
|
|
4
|
+
* marketplace.
|
|
5
|
+
*
|
|
6
|
+
* The scanner marks a manifest-less collection with the `skill-collection`
|
|
7
|
+
* layout, so a source whose every suite carries that layout ships skills and
|
|
8
|
+
* nothing else. A source with no suite at all is not one of them: it has
|
|
9
|
+
* nothing to name.
|
|
10
|
+
*/
|
|
11
|
+
export function isSkillsOnlySource(suites) {
|
|
12
|
+
return suites.length > 0 && suites.every(suite => suite.manifest.layout === 'skill-collection');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The name a reader recognizes a source by, or undefined when its id already
|
|
16
|
+
* says which repository it is.
|
|
17
|
+
*
|
|
18
|
+
* @param source - the source as it is persisted; its id is read, never written.
|
|
19
|
+
* @param suites - the suites the source contributed to the snapshot.
|
|
20
|
+
* @returns `owner/repository`, or undefined when the id is already
|
|
21
|
+
* unambiguous or the source is not a remote skills collection.
|
|
22
|
+
*/
|
|
23
|
+
export function qualifiedSourceName(source, suites) {
|
|
24
|
+
// A local directory is named by the reader who chose it; there is no owner to add.
|
|
25
|
+
if (source.local === true)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (!isSkillsOnlySource(suites))
|
|
28
|
+
return undefined;
|
|
29
|
+
const remote = parseRemoteRepository(source.url);
|
|
30
|
+
if (remote === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
// Only plain names are shown: a path segment carrying punctuation is not
|
|
33
|
+
// something to put in front of a slash.
|
|
34
|
+
if (!/^[\w.-]+$/.test(remote.owner) || !/^[\w.-]+$/.test(remote.base))
|
|
35
|
+
return undefined;
|
|
36
|
+
// The id already names the owner (`jeecgboot-skills`): the row is recognizable as it stands.
|
|
37
|
+
if (source.id === `${sanitizeId(remote.owner)}-${sanitizeId(remote.base)}`)
|
|
38
|
+
return undefined;
|
|
39
|
+
return `${remote.owner}/${remote.base}`;
|
|
40
|
+
}
|
|
@@ -11,13 +11,20 @@
|
|
|
11
11
|
/** Default timeout for individual MCP tool calls (ms). */
|
|
12
12
|
export const DEFAULT_TOOL_CALL_TIMEOUT_MS = 60_000;
|
|
13
13
|
/**
|
|
14
|
-
* How long one connection attempt may spend initializing (ms).
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* How long one connection attempt may spend initializing (ms).
|
|
15
|
+
*
|
|
16
|
+
* The budget covers the handshake and the tool listing that follows it: each
|
|
17
|
+
* request in the mount path is capped at this value. It stays deliberately
|
|
18
|
+
* below the MCP SDK's own 60-second request default, which is what a server
|
|
19
|
+
* that never answers would otherwise hold its process, transport and browser
|
|
20
|
+
* leg for - a dead server has to fail visibly instead of hanging. 30 seconds
|
|
21
|
+
* covers a public server's TLS handshake, OAuth discovery and tool listing,
|
|
22
|
+
* and it stays well inside the host's own 60-second tolerance for a single
|
|
23
|
+
* tool call, so mounting a server is never held to a tighter budget than one
|
|
24
|
+
* call against a server that already answered. A genuinely slow server can
|
|
25
|
+
* declare its own `startupTimeoutMs`.
|
|
19
26
|
*/
|
|
20
|
-
export const DEFAULT_STARTUP_TIMEOUT_MS =
|
|
27
|
+
export const DEFAULT_STARTUP_TIMEOUT_MS = 30_000;
|
|
21
28
|
/** Valid `serverName`, kept below the public tool-name budget. */
|
|
22
29
|
export const SERVER_NAME_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
|
|
23
30
|
/**
|
|
@@ -51,16 +51,19 @@ function toToolHost(ctx, serverName) {
|
|
|
51
51
|
ctx.logger?.info?.(message);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
const registry = ctx;
|
|
55
54
|
return {
|
|
56
55
|
logger,
|
|
57
56
|
tools: {
|
|
57
|
+
// The host's registry is reached through its own typed service, so the compiler
|
|
58
|
+
// checks the definition this bridge registers against the contract the host
|
|
59
|
+
// enforces. The service is read at call time because the adapter is built before
|
|
60
|
+
// the mount that provides it.
|
|
58
61
|
register(definition) {
|
|
59
|
-
const
|
|
60
|
-
if (typeof register !== 'function') {
|
|
62
|
+
const registry = ctx.tools;
|
|
63
|
+
if (typeof registry?.register !== 'function') {
|
|
61
64
|
throw new Error('the host context does not expose a tool registry — the "tools" service is required');
|
|
62
65
|
}
|
|
63
|
-
return registerOwnedBridgeTool(ctx, serverName, definition, () => register
|
|
66
|
+
return registerOwnedBridgeTool(ctx, serverName, definition, () => registry.register(definition));
|
|
64
67
|
}
|
|
65
68
|
},
|
|
66
69
|
getService: serviceName => optionalService(ctx, serviceName)
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* The host's tool registration contract, named in one place.
|
|
3
|
+
*
|
|
4
|
+
* The bridge hands its tools to the host's registry, so the shapes it hands over are the
|
|
5
|
+
* host's own. This module used to mirror them by hand — the host's `ToolDefinition`,
|
|
6
|
+
* `ToolExecution` and `ToolExecutionResult` written out field by field — and the mirror
|
|
7
|
+
* drifted: the host's result is a discriminated union whose failure variant carries no
|
|
8
|
+
* `value`, and the host's execution context grew the call identity, the parsed arguments
|
|
9
|
+
* and the step admission. A hand-written copy of a discriminated union is exactly what a
|
|
10
|
+
* compiler cannot check, so the drift surfaced only as a cast at the registration seam.
|
|
11
|
+
*
|
|
12
|
+
* The host's shapes are therefore taken from the host — imported TYPE-ONLY, so the market
|
|
13
|
+
* still loads no second copy of the host runtime — and the compiler now checks the
|
|
14
|
+
* bridge's definitions against the host's real contract instead of against a copy of it.
|
|
15
|
+
*
|
|
16
|
+
* What stays written here is the plugin's own side of the seam: the execution facts the
|
|
17
|
+
* bridge reads, and the `ToolHost` it talks to. Both are consumer shapes rather than
|
|
18
|
+
* copies of the host's, and both are checked against the host where it matters: the
|
|
19
|
+
* definition the bridge registers must satisfy the host's `ToolDefinition`.
|
|
7
20
|
*
|
|
8
21
|
* @module runtime/mcp-client/host-contract
|
|
9
22
|
*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
3
|
import { installModelSelection } from '@deepseek-ai/dsh-agent';
|
|
4
4
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
import { ReasoningEffortId } from '@deepseek-ai/dsh-llm/brand';
|
|
5
6
|
import { foldSubagentDescriptor } from '@deepseek-ai/dsh-subagent';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import { drainContinuableChildIds, registerSubagentProvider } from './subagent-seam.js';
|
|
@@ -30,6 +31,21 @@ function memberIdentity(member, role) {
|
|
|
30
31
|
'</system-reminder>'
|
|
31
32
|
].join('\n');
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The role route as the host's model selection.
|
|
36
|
+
*
|
|
37
|
+
* The route is validated by the plugin's own schema before it reaches this
|
|
38
|
+
* point, so the effort is a non-empty string; the host brands it without
|
|
39
|
+
* validating it again. An absent effort stays absent: the adapter's default
|
|
40
|
+
* applies, and no earlier effort is inherited.
|
|
41
|
+
*/
|
|
42
|
+
function roleSelection(route) {
|
|
43
|
+
return {
|
|
44
|
+
provider: route.provider,
|
|
45
|
+
model: route.model,
|
|
46
|
+
...(route.reasoningEffort === undefined ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) })
|
|
47
|
+
};
|
|
48
|
+
}
|
|
33
49
|
/** Creation and replay keep role data out of task text and never mutate the Lead's route. */
|
|
34
50
|
export class TeammateRoleRuntime {
|
|
35
51
|
ctx;
|
|
@@ -169,9 +185,15 @@ export class TeammateRoleRuntime {
|
|
|
169
185
|
const offRoute = applyRoleRoute(agent, binding.route, message => this.ctx.logger?.warn(message));
|
|
170
186
|
let offModel;
|
|
171
187
|
try {
|
|
172
|
-
|
|
188
|
+
// The host owns the request route now: it reads the selection from the
|
|
189
|
+
// session's durable projection, so the role route is recorded there and
|
|
190
|
+
// survives a resume that a live options write would not. The install
|
|
191
|
+
// keeps the host's switch notice, which reads that same selection.
|
|
192
|
+
offModel = installModelSelection(agent.ctx);
|
|
193
|
+
agent.model.select(roleSelection(binding.route));
|
|
173
194
|
}
|
|
174
195
|
catch (error) {
|
|
196
|
+
offModel?.();
|
|
175
197
|
offRoute();
|
|
176
198
|
offPersona();
|
|
177
199
|
throw error;
|
|
@@ -58,14 +58,28 @@ export function scanExtensionProgress(session) {
|
|
|
58
58
|
* reader guards it with its own disposal flag and owns the injected fiber: a
|
|
59
59
|
* disposed reader never registers again, and an older effect cleanup never
|
|
60
60
|
* clears a newer registration pointer.
|
|
61
|
+
*
|
|
62
|
+
* The host registers asynchronously: the handle arrives after the effect that
|
|
63
|
+
* started it, so the attempt tracks the handle it waits for. A handle that
|
|
64
|
+
* lands after its effect was cleaned up is released rather than kept, and it
|
|
65
|
+
* never passes for a newer registration.
|
|
61
66
|
*/
|
|
62
67
|
export class ExtensionProgressReader {
|
|
63
68
|
ctx;
|
|
64
|
-
|
|
69
|
+
attempt;
|
|
70
|
+
handle;
|
|
65
71
|
injection;
|
|
66
72
|
disposed = false;
|
|
67
|
-
/**
|
|
68
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Settles once the current registration attempt has run; production reads do not await it.
|
|
75
|
+
* @returns the current attempt's settlement, or the injection's when no attempt has started.
|
|
76
|
+
*/
|
|
77
|
+
get ready() {
|
|
78
|
+
const attempt = this.attempt;
|
|
79
|
+
if (!attempt)
|
|
80
|
+
return Promise.resolve(this.injection);
|
|
81
|
+
return attempt.registration.then(() => undefined, () => undefined);
|
|
82
|
+
}
|
|
69
83
|
/**
|
|
70
84
|
* Register the projection for the lifetime of the calling context.
|
|
71
85
|
* @param ctx - context whose fiber owns the registration.
|
|
@@ -78,43 +92,74 @@ export class ExtensionProgressReader {
|
|
|
78
92
|
scoped.effect(() => {
|
|
79
93
|
if (this.disposed)
|
|
80
94
|
return () => { };
|
|
81
|
-
const
|
|
82
|
-
|
|
95
|
+
const registration = scoped.sessionProjections.register(extensionProgressProjection);
|
|
96
|
+
const attempt = { registration, cancelled: false, handle: undefined, release: undefined };
|
|
97
|
+
this.attempt = attempt;
|
|
98
|
+
void registration.then(handle => {
|
|
99
|
+
attempt.handle = handle;
|
|
100
|
+
if (this.disposed || attempt.cancelled || this.attempt !== attempt) {
|
|
101
|
+
// The attempt was given up before its handle arrived: release the
|
|
102
|
+
// handle instead of keeping a registration nobody owns.
|
|
103
|
+
attempt.handle = undefined;
|
|
104
|
+
void handle.dispose();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.handle = handle;
|
|
108
|
+
}, () => {
|
|
109
|
+
// A registration that fails leaves the reader on its log-scan fallback.
|
|
110
|
+
});
|
|
83
111
|
return () => {
|
|
84
112
|
// Identity guard: a cleanup for an older registration must not clear a newer one.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
attempt.cancelled = true;
|
|
114
|
+
if (this.attempt === attempt)
|
|
115
|
+
this.attempt = undefined;
|
|
116
|
+
const handle = attempt.handle;
|
|
117
|
+
attempt.handle = undefined;
|
|
118
|
+
if (handle) {
|
|
119
|
+
if (this.handle === handle)
|
|
120
|
+
this.handle = undefined;
|
|
121
|
+
attempt.release = handle.dispose();
|
|
122
|
+
}
|
|
88
123
|
};
|
|
89
124
|
}, 'dsh-agent-plugins-market: extension progress projection');
|
|
90
125
|
});
|
|
91
|
-
this.ready = Promise.resolve(this.injection);
|
|
92
126
|
}
|
|
93
127
|
/** True while this plugin's projection is registered in the live registry. */
|
|
94
128
|
get registered() {
|
|
95
|
-
return this.
|
|
129
|
+
return this.handle !== undefined;
|
|
96
130
|
}
|
|
97
131
|
/**
|
|
98
132
|
* Whether one session carries authored progress.
|
|
99
133
|
* @param session - session to answer for.
|
|
100
|
-
* @returns the folded answer, or the log scan
|
|
134
|
+
* @returns the folded answer, or the log scan while no handle has landed.
|
|
101
135
|
*/
|
|
102
136
|
read(session) {
|
|
103
|
-
const state = this.
|
|
104
|
-
return state
|
|
137
|
+
const state = this.handle?.stateOf(session);
|
|
138
|
+
return state ? state.started : scanExtensionProgress(session);
|
|
105
139
|
}
|
|
106
140
|
/**
|
|
107
141
|
* Unregister the projection and release the injected fiber, so a registry that
|
|
108
142
|
* arrives or cycles later cannot register this reader again.
|
|
109
|
-
* @returns after the injected fiber has unloaded.
|
|
143
|
+
* @returns after the projection is released and the injected fiber has unloaded.
|
|
110
144
|
*/
|
|
111
145
|
async dispose() {
|
|
112
146
|
this.disposed = true;
|
|
113
|
-
const
|
|
114
|
-
this.
|
|
115
|
-
|
|
147
|
+
const attempt = this.attempt;
|
|
148
|
+
this.attempt = undefined;
|
|
149
|
+
if (attempt) {
|
|
150
|
+
attempt.cancelled = true;
|
|
151
|
+
const handle = attempt.handle;
|
|
152
|
+
attempt.handle = undefined;
|
|
153
|
+
if (handle) {
|
|
154
|
+
if (this.handle === handle)
|
|
155
|
+
this.handle = undefined;
|
|
156
|
+
attempt.release = handle.dispose();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
this.handle = undefined;
|
|
116
160
|
const injection = this.injection;
|
|
117
161
|
this.injection = undefined;
|
|
118
162
|
await injection?.dispose();
|
|
163
|
+
await attempt?.release;
|
|
119
164
|
}
|
|
120
165
|
}
|
|
@@ -113,14 +113,23 @@ export class ExtensionRuntime {
|
|
|
113
113
|
/**
|
|
114
114
|
* Why one agent's managed capabilities are denied right now, if they are.
|
|
115
115
|
*
|
|
116
|
-
* A stale agent
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* A stale agent, a session that has not published its selection yet and a
|
|
117
|
+
* withdrawn resource produce the same model-facing failure, so the status
|
|
118
|
+
* surface needs the difference: the first two are transient, the third is
|
|
119
|
+
* not.
|
|
119
120
|
* @param agent - the agent to describe.
|
|
120
121
|
* @returns the reason one of its capabilities is denied, or undefined.
|
|
121
122
|
*/
|
|
122
123
|
denialReason(agent) {
|
|
123
|
-
|
|
124
|
+
if (this.stale.has(agent))
|
|
125
|
+
return 'extension-inventory-pending';
|
|
126
|
+
// A session that has no selection yet denies every managed capability while
|
|
127
|
+
// it attaches. The denial is transient, so the model is told to retry
|
|
128
|
+
// rather than to ask the user to enable a resource the user already chose.
|
|
129
|
+
const status = this.state.status(agent);
|
|
130
|
+
if (!status.ready && status.error === undefined)
|
|
131
|
+
return 'extension-selection-pending';
|
|
132
|
+
return undefined;
|
|
124
133
|
}
|
|
125
134
|
allows(agent, resourceId, suiteId) {
|
|
126
135
|
if (this.stale.has(agent))
|
|
@@ -416,7 +425,40 @@ export class ExtensionRuntime {
|
|
|
416
425
|
extensionWorkspace(agent);
|
|
417
426
|
return agent;
|
|
418
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* The selection a child session starts from.
|
|
430
|
+
*
|
|
431
|
+
* A child session has no panel of its own: nobody chooses its resources, so a
|
|
432
|
+
* capture that invents an authorization the parent never gave is a guess, and
|
|
433
|
+
* the gate then denies what the parent's own session granted. The parent's
|
|
434
|
+
* committed selection is the answer, and the fork path already treats it as
|
|
435
|
+
* the child's own: a forked child's log carries the parent's committed
|
|
436
|
+
* binding, which the session state commits as the child's revision 1.
|
|
437
|
+
*
|
|
438
|
+
* @param agent - the child agent.
|
|
439
|
+
* @returns the parent's committed selection, or undefined when there is no
|
|
440
|
+
* live parent or the parent has no selection of its own.
|
|
441
|
+
*/
|
|
442
|
+
inheritedSelection(agent) {
|
|
443
|
+
const parentSession = agent.session.header.parentSession;
|
|
444
|
+
if (parentSession === undefined)
|
|
445
|
+
return undefined;
|
|
446
|
+
const parent = this.ctx.agents.get(parentSession);
|
|
447
|
+
if (parent === undefined)
|
|
448
|
+
return undefined;
|
|
449
|
+
try {
|
|
450
|
+
return this.state.read(parent)?.selection;
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
419
456
|
async initialSelection(agent, source) {
|
|
457
|
+
// A child session follows the session that started it. The workspace
|
|
458
|
+
// default is the answer for a session nobody chose anything for.
|
|
459
|
+
const inherited = this.inheritedSelection(agent);
|
|
460
|
+
if (inherited !== undefined)
|
|
461
|
+
return inherited;
|
|
420
462
|
const workspace = extensionWorkspace(agent);
|
|
421
463
|
const resources = await this.refreshInventory(agent);
|
|
422
464
|
const library = await this.store.read(workspace);
|
|
@@ -11,6 +11,15 @@ const DISABLED_SUFFIX = ' — unavailable in this session. Do not retry unchange
|
|
|
11
11
|
* two causes are distinguishable wherever the reason is read.
|
|
12
12
|
*/
|
|
13
13
|
const PENDING_SUFFIX = ' — extension-inventory-pending: this resource is temporarily unavailable while the catalog is re-read. It returns automatically; retry after a moment.';
|
|
14
|
+
/**
|
|
15
|
+
* The suffix a session gets while its own selection is still being published.
|
|
16
|
+
*
|
|
17
|
+
* The session has not chosen anything yet, so the capability is not withdrawn:
|
|
18
|
+
* telling the model to ask the user to enable a resource the user already
|
|
19
|
+
* enabled would be wrong advice, and it makes a temporary absence look
|
|
20
|
+
* permanent.
|
|
21
|
+
*/
|
|
22
|
+
const SELECTION_PENDING_SUFFIX = " — extension-selection-pending: this session's resources are still being prepared. It returns automatically; retry after a moment.";
|
|
14
23
|
const INVALID_FILE_PATH_SUFFIX = ' — pass the file_path string of the target file, for example "src/index.ts".';
|
|
15
24
|
const NO_PROVIDER_SUFFIX = ' — no mounted LSP provider serves this extension. If required, ask the user to configure one.';
|
|
16
25
|
const AMBIGUOUS_PROVIDER_SUFFIX = ' — more than one mounted LSP provider serves this extension. Ask the user to resolve the configuration to exactly one mounted provider before retrying.';
|
|
@@ -61,13 +70,19 @@ export function attachExtensionToolGates(agent, ownership, policy) {
|
|
|
61
70
|
}
|
|
62
71
|
};
|
|
63
72
|
/** Why this session's managed capabilities are denied, when the cause is transient. */
|
|
64
|
-
const
|
|
73
|
+
const denialSuffix = () => {
|
|
74
|
+
let reason;
|
|
65
75
|
try {
|
|
66
|
-
|
|
76
|
+
reason = policy.denialReason?.(agent);
|
|
67
77
|
}
|
|
68
78
|
catch {
|
|
69
|
-
|
|
79
|
+
reason = undefined;
|
|
70
80
|
}
|
|
81
|
+
if (reason === 'extension-inventory-pending')
|
|
82
|
+
return PENDING_SUFFIX;
|
|
83
|
+
if (reason === 'extension-selection-pending')
|
|
84
|
+
return SELECTION_PENDING_SUFFIX;
|
|
85
|
+
return DISABLED_SUFFIX;
|
|
71
86
|
};
|
|
72
87
|
const releaseGuard = tools.guard(exec => {
|
|
73
88
|
if (exec.agent !== agent)
|
|
@@ -75,7 +90,7 @@ export function attachExtensionToolGates(agent, ownership, policy) {
|
|
|
75
90
|
const definition = tools.get(exec.name, agent);
|
|
76
91
|
const owned = ownership.mcpTools().find(entry => entry.definition === definition);
|
|
77
92
|
if (owned !== undefined && !allows(owned))
|
|
78
|
-
return 'extension-resource-disabled: ' + owned.resourceId + (
|
|
93
|
+
return 'extension-resource-disabled: ' + owned.resourceId + denialSuffix();
|
|
79
94
|
if (exec.name !== 'lsp' || !ownership.ownsLspTool() || definition !== tools.get('lsp'))
|
|
80
95
|
return undefined;
|
|
81
96
|
const args = exec.arguments;
|
|
@@ -88,7 +103,7 @@ export function attachExtensionToolGates(agent, ownership, policy) {
|
|
|
88
103
|
if (providers.length > 1)
|
|
89
104
|
return 'extension-lsp-route-unavailable: ' + extension + AMBIGUOUS_PROVIDER_SUFFIX;
|
|
90
105
|
const provider = providers[0];
|
|
91
|
-
return allows(provider) ? undefined : 'extension-resource-disabled: ' + provider.resourceId + (
|
|
106
|
+
return allows(provider) ? undefined : 'extension-resource-disabled: ' + provider.resourceId + denialSuffix();
|
|
92
107
|
});
|
|
93
108
|
const releaseListener = agent.ctx.on('tools/change', refresh);
|
|
94
109
|
try {
|
|
@@ -519,9 +519,18 @@ export class ExtensionHooks {
|
|
|
519
519
|
this.runs.track(run);
|
|
520
520
|
return run;
|
|
521
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* The turn the current open turn is in.
|
|
524
|
+
*
|
|
525
|
+
* The registry-level read of the host's `turnBoundary` projection is
|
|
526
|
+
* deprecated, so the boundary comes from the agent registry's own typed
|
|
527
|
+
* accessor. The answer is the one it always was: no open turn means no turn,
|
|
528
|
+
* not turn zero. The projection reports `lastTurn` as 0 before the first
|
|
529
|
+
* turn, so the open-turn check is what keeps that zero out of the answer.
|
|
530
|
+
*/
|
|
522
531
|
lastTurn() {
|
|
523
|
-
const boundary = this.ctx.
|
|
524
|
-
return boundary
|
|
532
|
+
const boundary = this.ctx.agents.turnBoundaryOf(this.agent.session);
|
|
533
|
+
return boundary.openTurnStartSeq == null ? undefined : boundary.lastTurn;
|
|
525
534
|
}
|
|
526
535
|
/** Fold one point's hooks into the single decision its caller applies. */
|
|
527
536
|
async runPoint(point, query, payload, subject, turn, signal, options = {}) {
|
|
@@ -93,6 +93,30 @@ export declare function isWithinUnder(flavor: PathFlavor, root: string, candidat
|
|
|
93
93
|
export declare function isWithin(root: string, candidate: string): boolean;
|
|
94
94
|
/** Sanitize a plugin or server id into `[a-z0-9-]` (lowercased). */
|
|
95
95
|
export declare function sanitizeId(raw: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* The owner and the repository a remote URL names.
|
|
98
|
+
*
|
|
99
|
+
* The owner is the directory above the repository (`jeecgboot` for
|
|
100
|
+
* `github.com/jeecgboot/skills`); the repository keeps its own name without a
|
|
101
|
+
* `.git` or archive suffix.
|
|
102
|
+
*/
|
|
103
|
+
export interface RemoteRepository {
|
|
104
|
+
/** The directory the repository sits in. */
|
|
105
|
+
owner: string;
|
|
106
|
+
/** The repository's own name. */
|
|
107
|
+
base: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The owner and the repository a remote URL names, or undefined when the URL
|
|
111
|
+
* is a local path.
|
|
112
|
+
*
|
|
113
|
+
* Both the owner-prefixed source id and the qualified display name read this
|
|
114
|
+
* one parse, so the two cannot drift apart over what a URL says.
|
|
115
|
+
*
|
|
116
|
+
* @param url - a git URL or a local path.
|
|
117
|
+
* @returns the owner and repository, or undefined for a local path.
|
|
118
|
+
*/
|
|
119
|
+
export declare function parseRemoteRepository(url: string): RemoteRepository | undefined;
|
|
96
120
|
/**
|
|
97
121
|
* Derive candidate source ids from a git URL or local path, most preferred
|
|
98
122
|
* first: the sanitized basename, then an owner-prefixed variant (`owner-repo`)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The name a source is known by.
|
|
3
|
+
*
|
|
4
|
+
* A source id is a stable key, not a label: it is derived from the URL's
|
|
5
|
+
* basename, so two repositories called `skills` from different owners collide
|
|
6
|
+
* and the second one is stored as `skills-2`. Neither id says where the
|
|
7
|
+
* content came from, and a bare `skills` says nothing at all.
|
|
8
|
+
*
|
|
9
|
+
* The qualified name answers with the path the repository actually lives at
|
|
10
|
+
* (`jeecgboot/skills`). It is a display name only: the id, the persisted state
|
|
11
|
+
* and every `market:<sourceId>/<suiteId>` resource id stay exactly as they
|
|
12
|
+
* are, because a name a reader recognizes is worth less than a key that does
|
|
13
|
+
* not move.
|
|
14
|
+
*/
|
|
15
|
+
import type { Suite } from '../../../market-contracts/src/model/types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Whether a source's suites are skill collections rather than a plugin
|
|
18
|
+
* marketplace.
|
|
19
|
+
*
|
|
20
|
+
* The scanner marks a manifest-less collection with the `skill-collection`
|
|
21
|
+
* layout, so a source whose every suite carries that layout ships skills and
|
|
22
|
+
* nothing else. A source with no suite at all is not one of them: it has
|
|
23
|
+
* nothing to name.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isSkillsOnlySource(suites: readonly Suite[]): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The name a reader recognizes a source by, or undefined when its id already
|
|
28
|
+
* says which repository it is.
|
|
29
|
+
*
|
|
30
|
+
* @param source - the source as it is persisted; its id is read, never written.
|
|
31
|
+
* @param suites - the suites the source contributed to the snapshot.
|
|
32
|
+
* @returns `owner/repository`, or undefined when the id is already
|
|
33
|
+
* unambiguous or the source is not a remote skills collection.
|
|
34
|
+
*/
|
|
35
|
+
export declare function qualifiedSourceName(source: {
|
|
36
|
+
id: string;
|
|
37
|
+
url: string;
|
|
38
|
+
local?: boolean;
|
|
39
|
+
}, suites: readonly Suite[]): string | undefined;
|
|
@@ -197,6 +197,12 @@ export interface UnmanagedSource {
|
|
|
197
197
|
/** A configured source row returned to the market client. */
|
|
198
198
|
export interface SourceOverview {
|
|
199
199
|
id: string;
|
|
200
|
+
/**
|
|
201
|
+
* The name a reader recognizes this source by, when the id alone does not say
|
|
202
|
+
* which repository it is (`jeecgboot/skills` for a source stored as `skills`).
|
|
203
|
+
* Absent when the id already carries the owner or the source is not remote.
|
|
204
|
+
*/
|
|
205
|
+
displayName?: string;
|
|
200
206
|
url: string;
|
|
201
207
|
branch?: string;
|
|
202
208
|
local?: boolean;
|
|
@@ -23,13 +23,20 @@ import type { McpServerPolicy } from '../../../../market-contracts/src/model/typ
|
|
|
23
23
|
/** Default timeout for individual MCP tool calls (ms). */
|
|
24
24
|
export declare const DEFAULT_TOOL_CALL_TIMEOUT_MS = 60000;
|
|
25
25
|
/**
|
|
26
|
-
* How long one connection attempt may spend initializing (ms).
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* How long one connection attempt may spend initializing (ms).
|
|
27
|
+
*
|
|
28
|
+
* The budget covers the handshake and the tool listing that follows it: each
|
|
29
|
+
* request in the mount path is capped at this value. It stays deliberately
|
|
30
|
+
* below the MCP SDK's own 60-second request default, which is what a server
|
|
31
|
+
* that never answers would otherwise hold its process, transport and browser
|
|
32
|
+
* leg for - a dead server has to fail visibly instead of hanging. 30 seconds
|
|
33
|
+
* covers a public server's TLS handshake, OAuth discovery and tool listing,
|
|
34
|
+
* and it stays well inside the host's own 60-second tolerance for a single
|
|
35
|
+
* tool call, so mounting a server is never held to a tighter budget than one
|
|
36
|
+
* call against a server that already answered. A genuinely slow server can
|
|
37
|
+
* declare its own `startupTimeoutMs`.
|
|
31
38
|
*/
|
|
32
|
-
export declare const DEFAULT_STARTUP_TIMEOUT_MS =
|
|
39
|
+
export declare const DEFAULT_STARTUP_TIMEOUT_MS = 30000;
|
|
33
40
|
/** Valid `serverName`, kept below the public tool-name budget. */
|
|
34
41
|
export declare const SERVER_NAME_PATTERN: RegExp;
|
|
35
42
|
/**
|