@craft_eco/craft-mcp 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/bin/craft-mcp.mjs +28 -2
- package/dist-server/game-workflow/project-context.mjs +7 -6
- package/dist-server/game-workflow/project-install.mjs +2 -1
- package/dist-server/integrations/config.mjs +41 -18
- package/dist-server/integrations/connect.mjs +18 -9
- package/dist-server/integrations/connection-handoff.mjs +9 -8
- package/dist-server/integrations/dsh-config.mjs +30 -14
- package/dist-server/integrations/files.mjs +3 -1
- package/dist-server/integrations/fixed-launcher.mjs +1 -0
- package/dist-server/integrations/host-config-scope.mjs +4 -3
- package/dist-server/integrations/hosts.mjs +3 -1
- package/dist-server/integrations/install-source.mjs +44 -0
- package/dist-server/integrations/install.mjs +183 -53
- package/dist-server/integrations/installation-state.mjs +2 -1
- package/dist-server/integrations/instance-skill.mjs +26 -0
- package/dist-server/integrations/instance.mjs +29 -0
- package/dist-server/integrations/launcher-start.mjs +1 -1
- package/dist-server/integrations/login-task-command.mjs +3 -3
- package/dist-server/integrations/opencode-config.mjs +13 -6
- package/dist-server/integrations/project-setup.mjs +46 -18
- package/dist-server/integrations/runtime.mjs +2 -1
- package/dist-server/integrations/uninstall.mjs +160 -0
- package/dist-server/integrations/updates.mjs +57 -28
- package/dist-server/launcher.mjs +18 -2
- package/dist-server/mcp/server.mjs +16 -8
- package/dist-server/mcp/update-session.mjs +34 -12
- package/dist-server/upstream/craft-aigc.mjs +11 -2
- package/dist-server/upstream/draft-audit.mjs +52 -6
- package/package.json +4 -3
- package/resources/craft-create/SKILL.md +2 -0
- package/resources/craft-update/SKILL.md +2 -0
package/dist-server/launcher.mjs
CHANGED
|
@@ -1677,6 +1677,14 @@ function requireForwardVersion(next, previous) {
|
|
|
1677
1677
|
if (comparison === 0 && previous.build_id && next.build_id && previous.build_id !== next.build_id) throw new Error("Craft same-version build replacement refused; publish a new version");
|
|
1678
1678
|
}
|
|
1679
1679
|
|
|
1680
|
+
// dist-server/integrations/instance.mjs
|
|
1681
|
+
function validateServerId(id) {
|
|
1682
|
+
if (typeof id !== "string" || id.length > 32 || !/^craft(?:-[a-z0-9]+(?:-[a-z0-9]+)*)?$/.test(id)) {
|
|
1683
|
+
throw new Error("Invalid Craft instance name; use craft or craft-<lowercase-identifier> (up to 32 characters)");
|
|
1684
|
+
}
|
|
1685
|
+
return id;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1680
1688
|
// dist-server/integrations/hosts.mjs
|
|
1681
1689
|
var hosts = Object.freeze({
|
|
1682
1690
|
codex: { label: "Codex", config: ".codex/config.toml", skills: ".agents/skills", projectSkills: ".agents/skills", format: "toml" },
|
|
@@ -1695,6 +1703,13 @@ var hosts = Object.freeze({
|
|
|
1695
1703
|
qwen: { label: "Qwen Code", config: ".qwen/settings.json", skills: ".qwen/skills", projectSkills: ".qwen/skills", format: "jsonc" }
|
|
1696
1704
|
});
|
|
1697
1705
|
|
|
1706
|
+
// dist-server/integrations/instance-skill.mjs
|
|
1707
|
+
function instanceSkillName(logicalName, serverId = "craft") {
|
|
1708
|
+
validateServerId(serverId);
|
|
1709
|
+
if (!["craft-create", "craft-update"].includes(logicalName)) throw new Error("Unknown Craft entrypoint Skill");
|
|
1710
|
+
return serverId + logicalName.slice("craft".length);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1698
1713
|
// dist-server/integrations/installation-state.mjs
|
|
1699
1714
|
var defaultRegistry = "https://registry.npmjs.org/";
|
|
1700
1715
|
var activationMode = "next_mcp_start";
|
|
@@ -1707,7 +1722,7 @@ function installedSkillEntries(state) {
|
|
|
1707
1722
|
if (state.skills === void 0) return [];
|
|
1708
1723
|
if (!state.skills || typeof state.skills !== "object" || Array.isArray(state.skills) || !state.skills["craft-create"]) throw new Error("Invalid installed Skill destinations");
|
|
1709
1724
|
return Object.entries(state.skills).map(([name, file]) => {
|
|
1710
|
-
if (!Object.hasOwn(managedSkillMarkers, name) || typeof file !== "string" || !path2.isAbsolute(file) || path2.basename(file) !== "SKILL.md" || path2.basename(path2.dirname(file)) !== name) throw new Error("Invalid installed Skill destination");
|
|
1725
|
+
if (!Object.hasOwn(managedSkillMarkers, name) || typeof file !== "string" || !path2.isAbsolute(file) || path2.basename(file) !== "SKILL.md" || path2.basename(path2.dirname(file)) !== instanceSkillName(name, state.server_id)) throw new Error("Invalid installed Skill destination");
|
|
1711
1726
|
return { name, file, marker: managedSkillMarkers[name] };
|
|
1712
1727
|
});
|
|
1713
1728
|
}
|
|
@@ -1787,6 +1802,7 @@ function launcherPath(installationFile) {
|
|
|
1787
1802
|
return installationFile.replace(/\.json$/, "") + ".launcher.mjs";
|
|
1788
1803
|
}
|
|
1789
1804
|
async function verifyLauncher(state, installationFile, connection) {
|
|
1805
|
+
if (connection?.env && (connection.env.CRAFT_SERVER_ID ?? "craft") !== state.server_id) throw new Error("Craft launcher instance differs from its registration");
|
|
1790
1806
|
if (!state.launcher) return { mode: "legacy_versioned_entry" };
|
|
1791
1807
|
const expected = launcherPath(installationFile);
|
|
1792
1808
|
if (state.launcher.schema !== 1 || state.launcher.entry !== expected || !/^[a-f0-9]{64}$/.test(state.launcher.sha256 ?? "")) throw new Error("Invalid Craft fixed launcher identity");
|
|
@@ -1818,7 +1834,7 @@ async function start() {
|
|
|
1818
1834
|
if (state.host === "workbuddy" && state.login_data_dir && process.env.CRAFT_STANDALONE_PROBE !== "1") {
|
|
1819
1835
|
process.env.CLIENT_DATA_DIR ||= state.login_data_dir;
|
|
1820
1836
|
}
|
|
1821
|
-
for (const [key, expected] of Object.entries({ CRAFT_CLIENT_IDE: state.host, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_WEB_URL: state.platform })) {
|
|
1837
|
+
for (const [key, expected] of Object.entries({ CRAFT_CLIENT_IDE: state.host, CRAFT_SERVER_ID: state.server_id, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_WEB_URL: state.platform })) {
|
|
1822
1838
|
if (process.env[key] && process.env[key] !== expected) throw new Error("Craft launcher scope mismatch: " + key);
|
|
1823
1839
|
process.env[key] = expected;
|
|
1824
1840
|
}
|
|
@@ -28,6 +28,7 @@ import { getLoginPage } from './login-page.mjs';
|
|
|
28
28
|
import { loadEngineResources, loadEngineResource } from '../game-workflow/engines.mjs';
|
|
29
29
|
import { takeConnectorToken, ConnectorAuthStore, connectorLoginAction } from '../core/connector-auth.mjs';
|
|
30
30
|
import { clientIde } from '../integrations/hosts.mjs';
|
|
31
|
+
import { validateServerId } from '../integrations/instance.mjs';
|
|
31
32
|
import { currentWork, withWork, guardWork } from '../game-workflow/work-scope.mjs';
|
|
32
33
|
import { mcpProduceLocation } from '../core/production-source.mjs';
|
|
33
34
|
import { ProductionTelemetry } from './production-telemetry.mjs';
|
|
@@ -35,6 +36,7 @@ import { getRuntimeIdentity } from '../integrations/runtime.mjs';
|
|
|
35
36
|
import { UpdateSession } from './update-session.mjs';
|
|
36
37
|
import { registerRuntimeConnection } from '../integrations/runtime-gc.mjs';
|
|
37
38
|
import { readInstallation, sameRuntimeIdentity } from '../integrations/installation-state.mjs';
|
|
39
|
+
import { readProjectInstall, assertProjectInstallConnection } from '../game-workflow/project-install.mjs';
|
|
38
40
|
|
|
39
41
|
// Consume before any project/build subprocess can inherit the credential.
|
|
40
42
|
let connectorToken = takeConnectorToken();
|
|
@@ -51,6 +53,7 @@ if (connectorAuth) {
|
|
|
51
53
|
finally { connectorToken = undefined; }
|
|
52
54
|
}
|
|
53
55
|
const host = clientIde(process.env.CRAFT_CLIENT_IDE);
|
|
56
|
+
const serverId = validateServerId(process.env.CRAFT_SERVER_ID ?? 'craft');
|
|
54
57
|
const configuredMcpHost = process.env.CRAFT_MCP_HOST;
|
|
55
58
|
const { instructions:guide, workflow:bootstrapWorkflow, engines } = await loadEngineResources(resources,host);
|
|
56
59
|
const projects = new Projects(root,state,engines,host,async()=>{
|
|
@@ -58,10 +61,10 @@ const projects = new Projects(root,state,engines,host,async()=>{
|
|
|
58
61
|
// loopback mock server into a project that will be opened on another machine.
|
|
59
62
|
if(new URL(platform.base).protocol!=='https:') return {unavailable:'non_portable_platform'};
|
|
60
63
|
const installationFile=process.env.CRAFT_INSTALLATION_FILE;
|
|
61
|
-
if(!installationFile) return {version,platform:platform.base};
|
|
64
|
+
if(!installationFile) return {version,platform:platform.base,requireKnownChannel:true};
|
|
62
65
|
const installation=await readInstallation(installationFile);
|
|
63
66
|
const canonical=value=>process.platform==='win32'?path.resolve(value).toLowerCase():path.resolve(value);
|
|
64
|
-
if(installation.host!==host || canonical(installation.workspace)!==canonical(root) || new URL(installation.platform).origin!==new URL(platform.base).origin || installation.source.package!==runtimeIdentity.package) {
|
|
67
|
+
if(installation.server_id!==serverId || installation.host!==host || canonical(installation.workspace)!==canonical(root) || new URL(installation.platform).origin!==new URL(platform.base).origin || installation.source.package!==runtimeIdentity.package) {
|
|
65
68
|
throw new Error('Craft installation scope differs from this connection; reconnect before preparing project installation information');
|
|
66
69
|
}
|
|
67
70
|
if(!sameRuntimeIdentity(runtimeIdentity,installation.target)) throw new Error('The installed Craft target differs from this running connection; reconnect and verify the actual runtime before preparing project installation information');
|
|
@@ -85,7 +88,12 @@ let openingLoginPages=0;
|
|
|
85
88
|
const externalUnrealTask = task => !task?.work_id && ['unreal-export','unreal-preview','unreal-upload'].includes(task?.kind);
|
|
86
89
|
async function validateWork(work,{preparing=false}={}) {
|
|
87
90
|
await leases.assert(work.name,work.work_id,{ready:!preparing,context_revision:work.context_revision});
|
|
88
|
-
if(!preparing)
|
|
91
|
+
if(!preparing) {
|
|
92
|
+
const project = await projects.assertRevision(work.name,work.context_revision);
|
|
93
|
+
const manifest = await readProjectInstall(project.project);
|
|
94
|
+
if (manifest) assertProjectInstallConnection(manifest, {engine:project.engine,version,platform:platform.base,
|
|
95
|
+
registry:updates.connectedSource?.registry,channel:updates.connectedSource?.channel,requireKnownChannel:true});
|
|
96
|
+
}
|
|
89
97
|
}
|
|
90
98
|
function runtimeBusy({excludeUpdate=false}={}) {
|
|
91
99
|
const busy={work_count:leases.activeCount,task_count:tasks.activeCount,mutation_count:mutations.size,
|
|
@@ -94,9 +102,9 @@ function runtimeBusy({excludeUpdate=false}={}) {
|
|
|
94
102
|
maintenance_count:Number(Boolean(runtimeMaintenance))};
|
|
95
103
|
return {...busy,can_reconnect:!closing && Object.values(busy).every(count=>count===0)};
|
|
96
104
|
}
|
|
97
|
-
const updates=new UpdateSession({installationFile:process.env.CRAFT_INSTALLATION_FILE,current:runtimeIdentity,projects,host,workspace:root,platform:platform.base,busy:runtimeBusy});
|
|
105
|
+
const updates=new UpdateSession({installationFile:process.env.CRAFT_INSTALLATION_FILE,current:runtimeIdentity,projects,host,serverId,workspace:root,platform:platform.base,busy:runtimeBusy});
|
|
98
106
|
let runtimeConnection;
|
|
99
|
-
if(process.env.CRAFT_INSTALLATION_FILE && !await updates.
|
|
107
|
+
if(process.env.CRAFT_INSTALLATION_FILE && !await updates.connectionIssue()) {
|
|
100
108
|
try { runtimeConnection=await registerRuntimeConnection({installationFile:process.env.CRAFT_INSTALLATION_FILE,current:runtimeIdentity}); }
|
|
101
109
|
catch { process.stderr.write('[craft] Runtime cleanup is unavailable for this connection; MCP remains active.\n'); }
|
|
102
110
|
}
|
|
@@ -187,7 +195,7 @@ const tools = [
|
|
|
187
195
|
// The connection and prepare result use the same maintained workflow; clients may omit initialize instructions from their model context.
|
|
188
196
|
const server = new Server({ name:'craft-local',version },{ capabilities:{ tools:{} },instructions:guide });
|
|
189
197
|
function productionTelemetry() {
|
|
190
|
-
//
|
|
198
|
+
// Initialization supplies clientInfo for hosts identified by handshake name.
|
|
191
199
|
return telemetry ??= new ProductionTelemetry(platform,drafts,mcpProduceLocation(host,{
|
|
192
200
|
configuredHost:configuredMcpHost, clientName:server.getClientVersion()?.name
|
|
193
201
|
}),{ state,workspace:root,version });
|
|
@@ -198,6 +206,7 @@ server.oninitialized=()=>{
|
|
|
198
206
|
// Hosts also initialize short-lived discovery probes. They can close or kill
|
|
199
207
|
// the child immediately after tools/list, so readiness must never start GC.
|
|
200
208
|
connectionReady=updates.connected();
|
|
209
|
+
if (process.env.CRAFT_STANDALONE_PROBE !== '1') productionTelemetry().start();
|
|
201
210
|
};
|
|
202
211
|
server.setRequestHandler(ListToolsRequestSchema,async()=>({ tools }));
|
|
203
212
|
function viewTask(task) {
|
|
@@ -288,7 +297,6 @@ server.setRequestHandler(CallToolRequestSchema,async request=>{
|
|
|
288
297
|
}
|
|
289
298
|
businessResult = await withWork(work,work ? ()=>validateWork(work,{preparing:preparing || definition.name==='craft_task_cancel'}) : undefined,async()=>{
|
|
290
299
|
const production = productionTelemetry();
|
|
291
|
-
if (definition.name !== 'craft_auth_logout' && process.env.CRAFT_STANDALONE_PROBE !== '1') production.start();
|
|
292
300
|
let result;
|
|
293
301
|
if(args.name && (definition.name.startsWith('craft_assets_') || definition.name==='craft_game_upload')) {
|
|
294
302
|
const project=await projects.describe(args.name);
|
|
@@ -392,7 +400,7 @@ server.setRequestHandler(CallToolRequestSchema,async request=>{
|
|
|
392
400
|
environment:args.web_operation===existingScope ? existing : {...managed,scope:'web_build',operation:'managed_project_build'}};
|
|
393
401
|
}
|
|
394
402
|
const updateStatus=await updates.status();
|
|
395
|
-
result = { version, runtime:{...runtimeIdentity,busy:runtimeBusy(),activation:updateStatus.activation??{status:updateStatus.status}},update:updateStatus,host,mcp_produce_location:production.location, workspace:root, workspace_layout:'<workspace>/<name>', platform:platform.base, engine:engine ?? null, supported_engines:supportedEngines,
|
|
403
|
+
result = { version, server_id:serverId, channel:updates.connectedSource?.channel ?? null, runtime:{...runtimeIdentity,busy:runtimeBusy(),activation:updateStatus.activation??{status:updateStatus.status}},update:updateStatus,host,mcp_produce_location:production.location, workspace:root, workspace_layout:'<workspace>/<name>', platform:platform.base, engine:engine ?? null, supported_engines:supportedEngines,
|
|
396
404
|
context_binding:project?.context_binding,project_install:project?.project_install,
|
|
397
405
|
version_status:project?.version_status,pending_hosts:project?.pending_hosts,conflicting_hosts:project?.conflicting_hosts,
|
|
398
406
|
integrity:project?.integrity,preparation:project?.preparation,registration_required:project?.registration_required,occupancy,project_context:project?.project_context,
|
|
@@ -2,18 +2,20 @@ import { compatibleContextContract } from '../engines/catalog.mjs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
6
|
import { loadInstalledEngine } from '../game-workflow/engines.mjs';
|
|
6
7
|
import { readContextLock, checkProjectCompatibility, planContextRelease, assertContextRelease } from '../game-workflow/project-bundles.mjs';
|
|
7
|
-
import { checkForUpdate, readUpdateStatus, readInstallation, confirmActiveInstallation, queryRegistry } from '../integrations/updates.mjs';
|
|
8
|
+
import { checkForUpdate, readUpdateStatus, readInstallation, confirmActiveInstallation, pendingChannelSwitch, queryRegistry } from '../integrations/updates.mjs';
|
|
9
|
+
import { sameRuntimeIdentity } from '../integrations/installation-state.mjs';
|
|
8
10
|
import { connectionHandoff } from '../integrations/connection-handoff.mjs';
|
|
9
11
|
import { readProjectInstall, assertProjectInstallConnection } from '../game-workflow/project-install.mjs';
|
|
10
12
|
|
|
11
13
|
// This connection owns one complete package for its entire lifetime. An
|
|
12
14
|
// installer probe or another connection can never replace its runtime identity.
|
|
13
15
|
export class UpdateSession {
|
|
14
|
-
constructor({installationFile, current, projects, host, workspace, platform, busy,
|
|
16
|
+
constructor({installationFile, current, projects, host, workspace, platform, serverId = 'craft', busy,
|
|
15
17
|
confirmInstallation=confirmActiveInstallation,checkInstallation=checkForUpdate,retryMinMs=250,retryMaxMs=5000}) {
|
|
16
|
-
Object.assign(this,{installationFile,current,projects,host,workspace,platform,busy});
|
|
18
|
+
Object.assign(this,{installationFile,current,projects,host,workspace,platform,serverId,busy});
|
|
17
19
|
Object.assign(this,{confirmInstallation,checkInstallation,retryMinMs,retryMaxMs});
|
|
18
20
|
this.updates=new Set();
|
|
19
21
|
this.inspections=new Set();
|
|
@@ -38,17 +40,31 @@ export class UpdateSession {
|
|
|
38
40
|
// roll back before the process acknowledges a graceful shutdown.
|
|
39
41
|
await Promise.allSettled([...this.updates,...this.inspections]);
|
|
40
42
|
}
|
|
41
|
-
async
|
|
42
|
-
if(!this.installationFile)
|
|
43
|
+
async connectionIssue(handoff) {
|
|
44
|
+
if (!this.installationFile) {
|
|
45
|
+
if (this.serverId === 'craft') return null;
|
|
46
|
+
return {status:'error',code:'installation_scope_mismatch',message:'Named Craft instances require their own installation record',can_continue:false,activation_required:false};
|
|
47
|
+
}
|
|
43
48
|
try {
|
|
44
49
|
const state=await readInstallation(this.installationFile);
|
|
45
50
|
const normalize=value=>{const resolved=path.resolve(value);return process.platform==='win32'?resolved.toLowerCase():resolved;};
|
|
46
|
-
if(state.host!==this.host || normalize(state.workspace)!==normalize(this.workspace) || new URL(state.platform).origin!==new URL(this.platform).origin) throw new Error('Craft installation host, workspace or platform differs from this connection; run install with the intended scope and reconnect');
|
|
51
|
+
if(state.server_id!==this.serverId || state.host!==this.host || normalize(state.workspace)!==normalize(this.workspace) || new URL(state.platform).origin!==new URL(this.platform).origin) throw new Error('Craft installation server, host, workspace or platform differs from this connection; run install with the intended scope and reconnect');
|
|
52
|
+
const switched=pendingChannelSwitch(state,this.current,this.connectedSource);
|
|
53
|
+
if(switched) return this.withHandoff(switched,handoff);
|
|
54
|
+
// Remember the source only when this process actually matches the target.
|
|
55
|
+
// Two tags can point to the same build; that process can keep serving.
|
|
56
|
+
if(sameRuntimeIdentity(this.current,state.target)) {
|
|
57
|
+
if(this.connectedSource && !isDeepStrictEqual(this.connectedSource,state.source)) {
|
|
58
|
+
delete this.last;
|
|
59
|
+
this.receipts.clear();
|
|
60
|
+
}
|
|
61
|
+
this.connectedSource=state.source;
|
|
62
|
+
}
|
|
47
63
|
return null;
|
|
48
64
|
} catch(error) {return {status:'error',code:'installation_scope_mismatch',message:error.message,current:this.current,can_continue:false,activation_required:false};}
|
|
49
65
|
}
|
|
50
66
|
async status() {
|
|
51
|
-
const
|
|
67
|
+
const issue=await this.connectionIssue();if(issue) return issue;
|
|
52
68
|
const verification=this.verificationStatus();if(verification) return verification;
|
|
53
69
|
return this.withHandoff({...await readUpdateStatus({installationFile:this.installationFile,current:this.current}),
|
|
54
70
|
...(this.last ? {last_check:this.last} : {})},{intent:'inspect'});
|
|
@@ -56,7 +72,7 @@ export class UpdateSession {
|
|
|
56
72
|
withHandoff(result,{intent='inspect',name,request_key,excludeUpdate=false}={}) {
|
|
57
73
|
if(!result.reconnect_required || !result.target || ['error','incompatible','migration_required'].includes(result.status)) return result;
|
|
58
74
|
const busy=this.busy?.({excludeUpdate});
|
|
59
|
-
const handoff=connectionHandoff({host:this.host,target:result.target,current:this.current,workspace:this.workspace,platform:this.platform,
|
|
75
|
+
const handoff=connectionHandoff({host:this.host,serverId:this.serverId,channel:result.source?.channel,target:result.target,current:this.current,workspace:this.workspace,platform:this.platform,
|
|
60
76
|
busy,intent,name,requestKey:request_key});
|
|
61
77
|
return {...result,...(busy?{busy}:{}),connection_handoff:handoff,next:handoff.next};
|
|
62
78
|
}
|
|
@@ -103,7 +119,13 @@ export class UpdateSession {
|
|
|
103
119
|
async confirmConnection() {
|
|
104
120
|
try {
|
|
105
121
|
if(!this.installationFile) {this.clearConnectionRetry();delete this.connectionError;return {status:'unmanaged'};}
|
|
106
|
-
const
|
|
122
|
+
const issue=await this.connectionIssue({excludeUpdate:true});
|
|
123
|
+
if(issue) {
|
|
124
|
+
this.clearConnectionRetry();
|
|
125
|
+
if(issue.status==='error') this.connectionError=issue;
|
|
126
|
+
else delete this.connectionError;
|
|
127
|
+
return issue;
|
|
128
|
+
}
|
|
107
129
|
const status=await readUpdateStatus({installationFile:this.installationFile,current:this.current});
|
|
108
130
|
if(status.status==='error') {this.clearConnectionRetry();return this.connectionError=status;}
|
|
109
131
|
if(status.activation?.status!=='active_verified') {
|
|
@@ -148,7 +170,7 @@ export class UpdateSession {
|
|
|
148
170
|
return this.check({name,request_key,intent:mode==='manual'?'update':'auto'});
|
|
149
171
|
}
|
|
150
172
|
async checkCurrent({name,intent='inspect',request_key,advisory=false}={}) {
|
|
151
|
-
const
|
|
173
|
+
const issue=await this.connectionIssue({intent,name,request_key,excludeUpdate:intent!=='inspect'});if(issue) return issue;
|
|
152
174
|
const verification=this.verificationStatus();if(verification) return verification;
|
|
153
175
|
if(name!==undefined) this.projects.file(name);
|
|
154
176
|
if(intent==='resume' && !name) throw new Error('Project name is required when checking a resume');
|
|
@@ -160,7 +182,7 @@ export class UpdateSession {
|
|
|
160
182
|
const source=this.installationFile ? (await readInstallation(this.installationFile)).source : undefined;
|
|
161
183
|
if(source && source.package!==manifest.package_name) throw new Error('Project installation package differs from the current Craft installation');
|
|
162
184
|
assertProjectInstallConnection(manifest,{engine:project.engine,version,platform:this.platform,
|
|
163
|
-
registry:source?.registry,channel:source?.channel});
|
|
185
|
+
registry:source?.registry,channel:source?.channel,requireKnownChannel:true});
|
|
164
186
|
};
|
|
165
187
|
try {
|
|
166
188
|
projectInstall=project ? await readProjectInstall(project.project) : null;
|
|
@@ -186,7 +208,7 @@ export class UpdateSession {
|
|
|
186
208
|
if(lock?.schema>=2 && !compatibleContextContract(lock.compatibility,candidate.bundle.compatibility)) throw new Error('New Craft context is incompatible with this project; keep its engine and migrate explicitly');
|
|
187
209
|
if(lock?.contexts && candidate.host) assertContextRelease(await planContextRelease(candidate.legacyResources,candidate.bundle,lock));
|
|
188
210
|
} : undefined;
|
|
189
|
-
const result=await this.checkInstallation({installationFile:this.installationFile,current:this.current,intent,
|
|
211
|
+
const result=await this.checkInstallation({installationFile:this.installationFile,current:this.current,connectedSource:this.connectedSource,intent,
|
|
190
212
|
...(advisory && {lookup:source=>queryRegistry(source,{timeoutMs:1500})}),
|
|
191
213
|
requestKey:request_key ? `${intent==='create'?'create':`${name??'global'}:${intent}`}:${request_key}` : undefined,projectCompatibility,
|
|
192
214
|
registryReceipt:request_key ? this.receipts.get(request_key) : undefined});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthStore } from '../core/auth-store.mjs';
|
|
2
2
|
import { resolveLibraryUrl } from './library-url.mjs';
|
|
3
3
|
import { externalGameUploadRequest, parseExternalGameUploadReceipt } from '#craft-sdk';
|
|
4
|
-
import { parseDraftAudit } from './draft-audit.mjs';
|
|
4
|
+
import { parseDraftAudit, parseDraftScanFailure } from './draft-audit.mjs';
|
|
5
5
|
import { encodeDraftSource, legacySourceFormat } from './draft-source.mjs';
|
|
6
6
|
import { mcpLocationHeader, validMcpProduceLocation } from '../core/production-source.mjs';
|
|
7
7
|
import { open } from 'node:fs/promises';
|
|
@@ -147,6 +147,12 @@ export class CraftAigc {
|
|
|
147
147
|
10015:'上传请求与云端版本冲突,请检查上传状态后重试',
|
|
148
148
|
30006:'Craft 账号的项目数量已达上限,无法新建云端项目。请在 Craft 网页的项目列表中删除不再需要的项目,腾出名额后再重试同一次上传。',
|
|
149
149
|
};
|
|
150
|
+
const scanFailure = draft && !unreal && data?.code === 10017 ? parseDraftScanFailure(data.data) : undefined;
|
|
151
|
+
if (scanFailure) {
|
|
152
|
+
const {message,reason,path} = scanFailure;
|
|
153
|
+
throw new PlatformError(message,{...detail(false,'upload_security'),
|
|
154
|
+
upload_security:{reason,...(path && !path.includes(token) ? {path} : {})}});
|
|
155
|
+
}
|
|
150
156
|
const unrealError = {
|
|
151
157
|
...draftError,
|
|
152
158
|
10001:'UE 上传参数或 ZIP 不合法,请检查入口、文件结构、大小和摘要,修正后发起新的上传',
|
|
@@ -304,7 +310,10 @@ export class CraftAigc {
|
|
|
304
310
|
let result;
|
|
305
311
|
try {
|
|
306
312
|
result=parseExternalGameUploadReceipt(data,{ uploadId:id,requireUploadPath:kind === 'prepare' });
|
|
307
|
-
if (data.audit !== undefined)
|
|
313
|
+
if (data.audit !== undefined) {
|
|
314
|
+
result.audit = parseDraftAudit(data.audit,result.state);
|
|
315
|
+
if (result.audit.findings?.some(finding=>finding.path.includes(token))) throw new Error('Craft 返回的上传检查路径无效');
|
|
316
|
+
}
|
|
308
317
|
if (data.upload_mode !== undefined) {
|
|
309
318
|
if (!['current_project','new_project'].includes(data.upload_mode)) throw new Error('Invalid external game upload mode');
|
|
310
319
|
result.upload_mode = data.upload_mode;
|
|
@@ -1,5 +1,53 @@
|
|
|
1
|
-
const rules =
|
|
2
|
-
'
|
|
1
|
+
const rules = Object.freeze({
|
|
2
|
+
executable_extension:'文件扩展名属于禁止上传的可执行格式',
|
|
3
|
+
executable_content:'文件内容包含本机可执行文件标记',
|
|
4
|
+
image_format:'图片内容与文件格式不匹配',
|
|
5
|
+
audio_format:'音频内容与文件格式不匹配',
|
|
6
|
+
video_format:'视频内容与文件格式不匹配',
|
|
7
|
+
invalid_text_encoding:'文本编码无效或包含空字节',
|
|
8
|
+
invalid_source:'源码文件结构无效',
|
|
9
|
+
invalid_base64:'二进制附件的 Base64 编码无效',
|
|
10
|
+
sensitive_word:'文件命中服务端内容审核规则',
|
|
11
|
+
embedded_private_key:'文件包含私钥,请移除私钥后重新检查',
|
|
12
|
+
process_execution:'代码包含启动系统进程的行为',
|
|
13
|
+
remote_executable_code:'代码加载外部可执行脚本',
|
|
14
|
+
private_network_request:'代码直接请求私网地址',
|
|
15
|
+
unsafe_code_generation:'代码包含执行字符串或动态生成代码的行为',
|
|
16
|
+
unbounded_network_calls:'代码包含循环或极高频网络请求',
|
|
17
|
+
unscannable_code:'代码无法完成静态检查,请检查编码、语法和文件大小',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const scanFailures = Object.freeze({
|
|
21
|
+
scanner_busy:'扫描器繁忙,请稍后重试同一次上传',
|
|
22
|
+
scanner_timeout:'扫描超时,请稍后重试同一次上传',
|
|
23
|
+
scanner_canceled:'扫描已取消,请重试同一次上传',
|
|
24
|
+
worker_unavailable:'服务端扫描程序不可用,请联系平台维护者',
|
|
25
|
+
runtime_unavailable:'服务端扫描运行环境不可用,请联系平台维护者',
|
|
26
|
+
dependency_unavailable:'服务端扫描依赖不可用,请联系平台维护者',
|
|
27
|
+
input_failed:'扫描器读取输入失败,请重试;持续失败时联系平台维护者',
|
|
28
|
+
process_start_failed:'服务端扫描进程启动失败,请联系平台维护者',
|
|
29
|
+
process_failed:'服务端扫描进程异常退出,请重试;持续失败时联系平台维护者',
|
|
30
|
+
output_limit:'扫描结果超过大小限制,请联系平台维护者',
|
|
31
|
+
invalid_report:'服务端扫描报告无效,请联系平台维护者',
|
|
32
|
+
invalid_finding:'服务端扫描返回了无效问题项,请联系平台维护者',
|
|
33
|
+
invalid_receipt:'服务端扫描回执校验失败,请联系平台维护者',
|
|
34
|
+
scan_failed:'文件扫描执行失败,请重试;持续失败时联系平台维护者',
|
|
35
|
+
internal_error:'服务端安全检查发生内部故障,请联系平台维护者',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function validAuditPath(value) {
|
|
39
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 1024 &&
|
|
40
|
+
!/[\u0000-\u001f\u007f]/u.test(value) && !value.startsWith('/') && !/^[a-z]:/i.test(value) &&
|
|
41
|
+
!value.includes('\\') && !value.split('/').some(p=>!p || p === '.' || p === '..');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function parseDraftScanFailure(value) {
|
|
45
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
46
|
+
value.kind !== 'upload_security_unavailable' || typeof value.reason !== 'string' || !Object.hasOwn(scanFailures,value.reason) ||
|
|
47
|
+
(value.path !== undefined && !validAuditPath(value.path))) return;
|
|
48
|
+
return {reason:value.reason,...(value.path ? {path:value.path} : {}),
|
|
49
|
+
message:'Craft 上传安全检查未完成:' + scanFailures[value.reason] + '。'};
|
|
50
|
+
}
|
|
3
51
|
|
|
4
52
|
// Treat the receipt as untrusted data. Return only the public review fields,
|
|
5
53
|
// never upstream messages, source text or the server's internal audit metadata.
|
|
@@ -14,10 +62,8 @@ export function parseDraftAudit(value, uploadState) {
|
|
|
14
62
|
!['uploaded','draft_ready','expired'].includes(uploadState)) throw new Error('Craft 返回的上传检查状态无效');
|
|
15
63
|
const findings = value.findings ?? [];
|
|
16
64
|
if (!Array.isArray(findings) || findings.length > 32 ||
|
|
17
|
-
findings.some(f=>!f ||
|
|
18
|
-
/[\u0000-\u001f\u007f]/u.test(f.path) || f.path.startsWith('/') || f.path.includes('\\') ||
|
|
19
|
-
f.path.split('/').some(p=>!p || p === '.' || p === '..')) ||
|
|
65
|
+
findings.some(f=>!f || typeof f.rule !== 'string' || !Object.hasOwn(rules,f.rule) || !validAuditPath(f.path)) ||
|
|
20
66
|
((value.state === 'rejected') !== (findings.length > 0))) throw new Error('Craft 返回的上传检查结果无效');
|
|
21
67
|
return { state:value.state,policy_version:value.policy_version,total:value.total,completed:value.completed,
|
|
22
|
-
...(findings.length ? {findings:findings.map(({path,rule})=>({path,rule}))} : {}) };
|
|
68
|
+
...(findings.length ? {findings:findings.map(({path,rule})=>({path,rule,message:rules[rule]}))} : {}) };
|
|
23
69
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craft_eco/craft-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.12.0"
|
|
7
7
|
},
|
|
8
8
|
"craft": {
|
|
9
|
-
"platform": "https://test.craft.qq.com"
|
|
9
|
+
"platform": "https://test.craft.qq.com",
|
|
10
|
+
"source_sha256": "6c6ae5e369d01c0777d6ea217a28c8078cc7ae86cc3c1269284bb6a47a6c395c"
|
|
10
11
|
},
|
|
11
12
|
"scripts": {
|
|
12
13
|
"start": "node bin/craft-mcp.mjs"
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"type": "git",
|
|
31
32
|
"url": "https://git.woa.com/EcoGame/WXUP/WXUPAgent/CraftCli.git"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "72796844a8da386cedc1437683970bb4b938d8ed",
|
|
34
35
|
"bin": {
|
|
35
36
|
"craft-mcp": "bin/craft-mcp.mjs"
|
|
36
37
|
},
|
|
@@ -6,6 +6,8 @@ description: 使用 Craft 创建 2D、3D 游戏或玩法原型,上传已有游
|
|
|
6
6
|
<!-- craft-mcp:bootstrap:v1 -->
|
|
7
7
|
# 使用 Craft 创建或上传游戏
|
|
8
8
|
|
|
9
|
+
本 Skill frontmatter 的 name 去掉末尾的 `-create` 或 `-update` 即为 MCP 服务名。普通请求使用默认服务 `craft`;用户明确选择了其他实例或项目已绑定其渠道时,使用对应入口。首次调用该服务的 `craft_game_info` 核对 server_id、渠道、实际版本和工作区,同次制作、轮询、上传、更新与重连沿用该服务。
|
|
10
|
+
|
|
9
11
|
上传已有游戏、更新原云端项目或发布时,先在当前会话发现 Craft MCP 工具,调用 `craft_game_info(name)` 核对当前目录与配置的工作区。有效 Craft 工程按 `craft_game_prepare(mode="resume")` 恢复。Unreal 网页包按工程的 .uproject 使用 `craft_unreal_upload`,用 `craft_unreal_upload_status` 查询。JS 和 JS3D 工程读取该宿主引擎目录的 `knowledge/Publishing.md`。纯上传走 `craft_game_check(purpose="upload")` 和 `craft_game_upload`。当前工具未提供该检查模式时,先核对版本并按更新指引重连。普通 JS 工程不支持直接导入,报告工具给出的路径和缺项。用户指定 Craft MCP 时,工具受阻就报告具体错误;改用 Computer Use、GM 控制台或网页编辑器上传须另获用户同意。
|
|
10
12
|
|
|
11
13
|
用户要预览 Unreal 游戏、打开网页或获取链接时,先调用 `craft_unreal_preview`,传当前工程或用户指定工程的 `.uproject` 绝对路径。新会话也能按工程找回已导出的包。轮询 `craft_task_status` 并交付链接;如果找不到包,告诉用户需要先导出。
|
|
@@ -6,6 +6,8 @@ description: 检查或更新 Craft MCP,核对当前连接的运行版本,恢
|
|
|
6
6
|
<!-- craft-mcp:update:v1 -->
|
|
7
7
|
# 更新 Craft
|
|
8
8
|
|
|
9
|
+
本 Skill frontmatter 的 name 去掉末尾的 `-create` 或 `-update` 即为 MCP 服务名。普通请求使用默认服务 `craft`;用户明确选择了其他实例或项目已绑定其渠道时,使用对应入口。首次调用该服务的 `craft_game_info` 核对 server_id、渠道、实际版本和工作区,同次制作、轮询、上传、更新与重连沿用该服务。
|
|
10
|
+
|
|
9
11
|
先确认当前聊天能发现并调用 Craft 工具。工具未暴露时,使用宿主实际提供的工具发现机制定位准确工具名;仍在连接中则等待就绪后重试一次。仍不可用或调用失败时,保留更新目标和当前工作,报告原始错误并诊断连接,停止新的准备;不能仅据工具缺失判断未安装或升级失败。用户选择的 Craft 流程不能自行改用造化或其他游戏插件替代。
|
|
10
12
|
|
|
11
13
|
进入 Craft 工作流后,每条用户消息使用新的检查 key。同一轮调用支持 `update_request_key` 的业务工具时传这个 key,工具会顺带检查;本轮仅答疑、编辑本地文件或只用轮询等工具时,补一次只读 `craft_update_check`(request_key=本轮 key,已有工程传 name)。制作时,业务回执的 update_notice 或显式检查返回 update_available=true 且 automatic_update_enabled=true,就用同一 key 调用 `craft_update`(mode=auto,已有工程传 name)。纯查看只检查,未发现更新直接继续。同一目标版本待重连时只提示一次。新建或恢复工作时,prepare 的 request_key 使用本轮 key;该操作重试沿用原 request_key。继续已有工作沿用 work_id。新版在下次启动或用户重连后生效。手动模式仅用于用户明确要求升级。
|