@arcadia-eternity/content-sdk 4.13.0 → 4.14.0
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 +16 -5
- package/dist/appimage-sdk.d.ts +2 -0
- package/dist/appimage-sdk.js +110 -0
- package/dist/author-api.d.ts +6 -1
- package/dist/author-api.js +27 -3
- package/dist/author-environment-install.d.ts +14 -0
- package/dist/author-environment-install.js +104 -0
- package/dist/author-environment-source.d.ts +162 -0
- package/dist/author-environment-source.js +226 -0
- package/dist/author-install.d.ts +22 -0
- package/dist/author-install.js +289 -0
- package/dist/author-reference.d.ts +1 -1
- package/dist/author-reference.js +23 -4
- package/dist/cli.js +56 -23
- package/dist/command-discovery.d.ts +3 -0
- package/dist/command-discovery.js +122 -0
- package/dist/content-query.js +4 -1
- package/dist/content-workspace.d.ts +2 -138
- package/dist/content-workspace.js +6 -6
- package/dist/debug-environment-install.d.ts +15 -0
- package/dist/debug-environment-install.js +130 -0
- package/dist/debug-environments.d.ts +135 -0
- package/dist/debug-environments.js +48 -0
- package/dist/demo.js +22 -8
- package/dist/desktop-cli.d.ts +3 -0
- package/dist/desktop-cli.js +72 -0
- package/dist/desktop-client.d.ts +71 -0
- package/dist/desktop-client.js +162 -0
- package/dist/environment-demo.d.ts +8 -0
- package/dist/environment-demo.js +52 -0
- package/dist/environment-rules.js +38 -19
- package/dist/environment.d.ts +12 -8
- package/dist/environment.js +107 -58
- package/dist/init.d.ts +1 -0
- package/dist/init.js +125 -0
- package/dist/jobs.d.ts +3 -1
- package/dist/jobs.js +34 -15
- package/dist/managed-projects.d.ts +5 -1
- package/dist/managed-projects.js +3 -3
- package/dist/mcp-contracts.d.ts +28 -1
- package/dist/mcp-contracts.js +24 -1
- package/dist/mcp.js +21 -7
- package/dist/official-environment-packages.d.ts +6 -0
- package/dist/official-environment-packages.js +19 -0
- package/dist/official-environments.d.ts +7 -0
- package/dist/official-environments.js +25 -0
- package/dist/pack-project.d.ts +1 -0
- package/dist/pack-project.js +66 -0
- package/dist/package-updates.d.ts +2 -1
- package/dist/package-updates.js +30 -17
- package/dist/prepared-document.d.ts +1 -0
- package/dist/prepared-document.js +5 -13
- package/dist/preview-control.js +24 -1
- package/dist/preview.d.ts +1 -0
- package/dist/preview.js +6 -4
- package/dist/project.d.ts +1 -0
- package/dist/project.js +57 -18
- package/dist/template/README.md +8 -8
- package/dist/template/package.json +2 -2
- package/dist/template/skills/arcadia-content-authoring/SKILL.md +15 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +25 -1
- package/dist/testing.d.ts +3 -4
- package/dist/testing.js +22 -8
- package/dist/workspace-cli.js +6 -4
- package/dist/workspace.d.ts +1 -0
- package/dist/workspace.js +66 -15
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# Arcadia Content SDK
|
|
2
2
|
|
|
3
|
-
`@arcadia-eternity/content-sdk`
|
|
3
|
+
`@arcadia-eternity/content-sdk` provides `arcadia-content` and `arcadia-content-mcp` for creating and debugging content packs and standalone battle environments.
|
|
4
|
+
|
|
5
|
+
Use `arcadia-content init pack frost-pack` to start a content project with TypeScript effects, data and behavior tests. To debug an environment made of existing packages, run:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
arcadia-content init environment singles-cup
|
|
9
|
+
arcadia-content workspace singles-cup check
|
|
10
|
+
arcadia-content workspace singles-cup demo --execute --seed cup-baseline
|
|
11
|
+
arcadia-content workspace singles-cup preview --execute
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The environment's `package.json` records its rules in `arcadiaEnvironment` and its packages in `dependencies`. The static check validates the declaration. Demo and preview prepare the selected content for battle. Stop the interactive preview with Ctrl+C. Coding agents can connect with `arcadia-content-mcp singles-cup --execute`, then read the `authoring` reference. The following scripts are for content packs.
|
|
4
15
|
|
|
5
16
|
```json
|
|
6
17
|
{
|
|
@@ -19,13 +30,13 @@ Commands use the caller's working directory. `check` checks `tsconfig.json` and
|
|
|
19
30
|
|
|
20
31
|
For code packages, `pack` bundles the effect dependency graph into `dist/arcadia-effects.json` and adds `arcadia.effectArtifact` to the staged manifest. Source `package.json` stays unchanged. This author-side compilation parses and bundles code without evaluating module initialization or effect factories. Consumers can prepare the resulting package with `effectPreparation: 'prebuilt-only'`; they do not need to compile author source or install its development dependencies. Plain `npm pack` does not generate this artifact, so use `npm run pack` or `arcadia-content pack` for distribution. Publication of a prebuilt artifact does not grant authority to execute its code.
|
|
21
32
|
|
|
22
|
-
`demo` loads `arcadia.config.mjs`, whose default export selects two project teams with `teams: ['blue', 'orange']`. The template stores their portable configurations in `debug/teams/*.yaml`. It packs the project, installs the artifact in a temporary npm project and runs a deterministic local battle using each player's first skill. It fails on effect errors or if the battle exceeds 40 turns. The configuration and behavioral assertions belong to the content pack.
|
|
33
|
+
In a content pack, `demo` loads `arcadia.config.mjs`, whose default export selects two project teams with `teams: ['blue', 'orange']`. The template stores their portable configurations in `debug/teams/*.yaml`. It packs the project, installs the artifact in a temporary npm project and runs a deterministic local battle using each player's first skill. It fails on effect errors or if the battle exceeds 40 turns. The configuration and behavioral assertions belong to the content pack.
|
|
23
34
|
|
|
24
35
|
`workspace <directory> preview --execute` and MCP `preview_start` capture saved sources, build and install the candidate, and keep a loopback Node host running for the existing full battle client. The first configured player is interactive and the second is AI. The result supplies `preview.endpoint`, `preview.clientPath` and, when `ARCADIA_PREVIEW_CLIENT_URL` is set, `preview.url`. The desktop opens the same candidate in an isolated window. `arcadia-content preview` serves an already built project; stop it with Ctrl+C.
|
|
25
36
|
|
|
26
37
|
Task receipts live in `.arcadia/author-jobs`, outside exports and source revisions. `workspace <directory> job --execute` and `cancel --execute` accept `{ "jobId": "..." }` on stdin; MCP uses `job_get` and `job_cancel`. These operations work across author sessions. A stopped owner becomes `interrupted` on the next query. New candidates never replace older preview processes, failed preparations keep existing previews, and changed source marks old receipts stale. At most four preview processes are retained per session. Leaving the desktop editor clears its context and draft markers while active previews keep their owner alive. Explicit cancellation, forgetting the project, closing a CLI/MCP owner, or quitting the application terminates the corresponding previews and releases temporary files. This journal restores task status, not live processes or battle saves after a host restart.
|
|
27
38
|
|
|
28
|
-
Tests can import `prepareBattleEnvironment`, `prepareContentPack`, `attack`, `nextTurn`, `cancelled` and `runBattle` from `@arcadia-eternity/content-sdk/testing`. `prepareContentPack(root = process.cwd(), { offline
|
|
39
|
+
Tests can import `prepareBattleEnvironment`, `prepareContentPack`, `attack`, `nextTurn`, `cancelled` and `runBattle` from `@arcadia-eternity/content-sdk/testing`. For a content pack, `prepareContentPack(root = process.cwd(), { offline, cache })` loads that config and returns the installed `environment`, `manifest`, packed `files`, `await createBattle(seed)`, `contentFor(battle)`, `await restoreBattle(snapshot)`, `track(battle)` and async `dispose()`. Environment preparation reads and compiles data without evaluating effect code. Each explicit reference battle owns fresh VMs, released by its cleanup. The harness admits code only in the temporary local-development project. It uses the normal npm cache by default; `cache` selects an explicit cache directory. The default pack environment uses offline artifact installation. Standalone environment projects can resolve registry packages on first use. Pass `offline: true` when testing with prepared local materials only.
|
|
29
40
|
|
|
30
41
|
## YAML sharing in author workspaces
|
|
31
42
|
|
|
@@ -76,13 +87,13 @@ The desktop MCP configuration includes an optional `--context-file` path under E
|
|
|
76
87
|
|
|
77
88
|
Cooperating author processes serialize version checks and writes within each project under `.arcadia/author-locks`, outside source revisions. Busy writes fail after bounded waiting; a live writer is never displaced. This coordinates the desktop, CLI and MCP, not arbitrary external editors, and does not make multi-file saves transactional. Context describes unsaved content but does not lock a project: MCP writes update disk, while the desktop retains dirty drafts and their base versions for explicit reconciliation. File-version conflicts remain authoritative even if context has expired. Partial `content_apply` results set `isError` and retain per-file receipts.
|
|
78
89
|
|
|
79
|
-
`author_reference` and `arcadia://authoring/<topic>` provide installed SDK schemas/examples for species, skills, marks, teams, environments, descriptions and effects. Parser schema notes distinguish linked runtime data from source references. The `git` and `release` topics
|
|
90
|
+
`author_reference` and `arcadia://authoring/<topic>` provide installed SDK schemas/examples for species, skills, marks, teams, environments, descriptions and effects. Parser schema notes distinguish linked runtime data from source references. The `authoring` topic provides the installed guide to CLI initialization and environment debugging. The `git` and `release` topics cover source control and content-pack releases. `asset_inspect` returns metadata for a declared resource ID; `includeImage` returns local image bytes up to 2 MiB as standard MCP image content. MIME types follow source filenames via `mime-types`; unknown extensions remain metadata-only. Decoding and display belong to the MCP client: no image dimension parsing, container validation or transcoding is performed, and `imageAvailable` indicates transport eligibility rather than decodability. Remote URLs are metadata only, with no fetching or caching; audio and SWF are not executed.
|
|
80
91
|
|
|
81
92
|
Execution-enabled sessions expose `battle_create`, `battle_read`, `battle_events`, `battle_action`, `battle_reset` and `battle_close`. Supply a running preview `jobId`; creation requires two saved team IDs and a fixed seed. Creation and reset read the latest saved team files and retain their versions in that automation battle. They use the captured candidate rules without rebuilding for team-only changes. These tools never operate on the human preview battle or local team drafts. Mutations require `sessionId` and `expectedRevision`; submit a selection returned by `battle_read`. Events use bounded cursor pagination. A failed engine step returns its revision and diagnosis with `stateCurrent: false`, allowing reset/close while preserving the last valid state. At most four automation battles exist per preview; stopping the preview releases all of them. A stale candidate remains an old-source result.
|
|
82
93
|
|
|
83
94
|
## Project teams and named environments
|
|
84
95
|
|
|
85
|
-
See [the workflow contract](../../docs/guides/project-battle-workflow.md). `prepareContentPack(root, { environmentId, sources, lockRoot, offline, cache })` selects a named environment; omit `environmentId` for the declared-dependencies-only package test. `sources` maps npm names to local source directories. `lockRoot` opts into version-checked npm lock writes to the original project; without it preparation does not mutate project files. The returned harness exposes `loadTeams([firstId, secondId])` and `teamVersions` so automatic cases explicitly select their inputs. Manual drafts and last-selected teams never enter automatic tests.
|
|
96
|
+
See [the workflow contract](../../docs/guides/project-battle-workflow.md). `prepareContentPack(root, { environmentId, sources, lockRoot, offline, cache })` selects a named environment; omit `environmentId` for the declared-dependencies-only package test. `sources` maps npm names to local source directories. `lockRoot` opts into version-checked npm lock writes to the original project; without it preparation does not mutate project files. The returned harness exposes `loadTeams([firstId, secondId])` and `teamVersions` so automatic cases explicitly select their inputs. Manual drafts and last-selected teams never enter automatic tests. For content packs, `config.teams` selects the default teams. Standalone environment projects use their saved `blue` and `orange` teams.
|
|
86
97
|
|
|
87
98
|
Environment schema v2 adds versioned rule data and runtime requirements. Existing v1 files remain readable and are upgraded only on an explicit save. Reference battles and Worker battles apply the same team-size, species uniqueness and content allow/deny rules. Unsupported tiers or capability requirements fail explicitly. Editing returned environment metadata does not change an already prepared candidate's admission policy.
|
|
88
99
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { cp, lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, stat, symlink } from 'node:fs/promises';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { errorCode } from './types.js';
|
|
7
|
+
const within = (root, path) => path === root || path.startsWith(root + sep);
|
|
8
|
+
async function installedPath(path) {
|
|
9
|
+
try {
|
|
10
|
+
return await realpath(path);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (errorCode(error) !== 'ENOENT')
|
|
14
|
+
throw error;
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Linux Desktop stages a relocatable pnpm tree. Copy each reachable physical package
|
|
19
|
+
// once and preserve its actual dependency identities (including aliases and peers).
|
|
20
|
+
async function copySdkModules(modules, output, roots) {
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
async function copyPackage(source) {
|
|
23
|
+
if (!within(modules, source))
|
|
24
|
+
throw new Error('SDK dependency outside the AppImage: ' + source);
|
|
25
|
+
if (seen.has(source))
|
|
26
|
+
return;
|
|
27
|
+
seen.add(source);
|
|
28
|
+
const target = join(output, relative(modules, source));
|
|
29
|
+
await cp(source, target, {
|
|
30
|
+
recursive: true,
|
|
31
|
+
verbatimSymlinks: true,
|
|
32
|
+
filter: file => file !== join(source, 'node_modules'),
|
|
33
|
+
});
|
|
34
|
+
const file = join(source, 'package.json');
|
|
35
|
+
const pkg = JSON.parse(await readFile(file, 'utf8'));
|
|
36
|
+
const loader = createRequire(file);
|
|
37
|
+
for (const name of Object.keys({ ...pkg.dependencies, ...pkg.optionalDependencies, ...pkg.peerDependencies })) {
|
|
38
|
+
if (!/^(?:@[\w.-]+\/)?[\w-][\w.-]*$/.test(name))
|
|
39
|
+
throw new Error('Invalid SDK dependency name: ' + name);
|
|
40
|
+
let dependency;
|
|
41
|
+
for (const directory of loader.resolve.paths(name) ?? []) {
|
|
42
|
+
if (!within(modules, directory))
|
|
43
|
+
continue;
|
|
44
|
+
dependency = await installedPath(join(directory, name));
|
|
45
|
+
if (dependency)
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (!dependency) {
|
|
49
|
+
if (name in (pkg.optionalDependencies ?? {}) || pkg.peerDependenciesMeta?.[name]?.optional)
|
|
50
|
+
continue;
|
|
51
|
+
throw new Error('Bundled SDK dependency missing: ' + name);
|
|
52
|
+
}
|
|
53
|
+
await copyPackage(dependency);
|
|
54
|
+
const link = join(target, 'node_modules', name);
|
|
55
|
+
const resolvedTarget = join(output, relative(modules, dependency));
|
|
56
|
+
if (link === resolvedTarget)
|
|
57
|
+
continue;
|
|
58
|
+
await mkdir(dirname(link), { recursive: true });
|
|
59
|
+
await symlink(relative(dirname(link), resolvedTarget), link);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const root of roots)
|
|
63
|
+
await copyPackage(root);
|
|
64
|
+
}
|
|
65
|
+
/** Connect project links to durable packages only for an SDK loaded from a mounted AppImage. */
|
|
66
|
+
export async function persistentSdkPackages(packages, env = process.env) {
|
|
67
|
+
const { APPDIR, APPIMAGE, XDG_DATA_HOME } = env;
|
|
68
|
+
if (!APPDIR || !isAbsolute(APPDIR) || !APPIMAGE || !isAbsolute(APPIMAGE))
|
|
69
|
+
return packages;
|
|
70
|
+
const sdk = packages['@arcadia-eternity/content-sdk'];
|
|
71
|
+
const modules = await installedPath(join(APPDIR, 'resources/arcadia-server/node_modules'));
|
|
72
|
+
if (!modules || resolve(sdk) !== join(modules, '@arcadia-eternity/content-sdk'))
|
|
73
|
+
return packages;
|
|
74
|
+
const image = await stat(APPIMAGE, { bigint: true });
|
|
75
|
+
const key = createHash('sha256').update([image.dev, image.ino, image.size, image.ctimeNs].join('/')).digest('hex');
|
|
76
|
+
const data = XDG_DATA_HOME && isAbsolute(XDG_DATA_HOME) ? XDG_DATA_HOME : join(homedir(), '.local/share');
|
|
77
|
+
const directory = join(data, 'arcadia-eternity/author-sdks');
|
|
78
|
+
const destination = join(directory, key);
|
|
79
|
+
const durable = Object.fromEntries(Object.entries(packages).map(([name, path]) => [name, join(destination, 'node_modules', relative(modules, path))]));
|
|
80
|
+
try {
|
|
81
|
+
if (!(await lstat(destination)).isDirectory())
|
|
82
|
+
throw new Error('Invalid cached AppImage SDK: ' + destination);
|
|
83
|
+
return durable;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (errorCode(error) !== 'ENOENT')
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
90
|
+
const staging = await mkdtemp(join(directory, '.staging-'));
|
|
91
|
+
try {
|
|
92
|
+
const roots = [...Object.values(packages).map(path => resolve(path))];
|
|
93
|
+
const base = await installedPath(join(modules, '@arcadia-eternity/data-pack-base'));
|
|
94
|
+
if (base)
|
|
95
|
+
roots.push(base);
|
|
96
|
+
await copySdkModules(modules, join(staging, 'node_modules'), roots);
|
|
97
|
+
try {
|
|
98
|
+
await rename(staging, destination);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// Another connection may have published the complete, non-empty directory first.
|
|
102
|
+
if (!['EEXIST', 'ENOTEMPTY'].includes(errorCode(error) ?? ''))
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await rm(staging, { recursive: true, force: true });
|
|
108
|
+
}
|
|
109
|
+
return durable;
|
|
110
|
+
}
|
package/dist/author-api.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { AuthorWorkspace, type WorkspaceOptions } from './workspace.js';
|
|
|
4
4
|
import { AuthorJobs } from './jobs.js';
|
|
5
5
|
import { dependencyReferences } from './content-query.js';
|
|
6
6
|
import { type UnknownRecord } from './types.js';
|
|
7
|
+
import { installAuthorDependencies } from './author-install.js';
|
|
8
|
+
import { installAuthorEnvironment } from './author-environment-install.js';
|
|
9
|
+
export { installAuthorDependencies, installAuthorEnvironment };
|
|
7
10
|
export { authorGit, cloneAuthorRepository } from './author-git.js';
|
|
8
11
|
export { updateAuthorLock, createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
9
12
|
export type DependencyReferenceCatalog = Awaited<ReturnType<typeof dependencyReferences>>;
|
|
@@ -37,6 +40,8 @@ export declare function openAuthorSession(directory: string, options?: AuthorSes
|
|
|
37
40
|
kinds: readonly string[];
|
|
38
41
|
sdkApi: unknown;
|
|
39
42
|
codeExecution: boolean;
|
|
43
|
+
dependencyInstall: boolean;
|
|
44
|
+
environmentInstall: boolean;
|
|
40
45
|
};
|
|
41
46
|
diagnostics: import("./workspace.js").Diagnostic[];
|
|
42
47
|
}>;
|
|
@@ -53,6 +58,6 @@ export declare function openAuthorSession(directory: string, options?: AuthorSes
|
|
|
53
58
|
message: string;
|
|
54
59
|
})[];
|
|
55
60
|
}>;
|
|
56
|
-
call(operation: string, input?: unknown): Promise<unknown>;
|
|
61
|
+
call(operation: string, input?: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
57
62
|
close(): Promise<void>;
|
|
58
63
|
}>;
|
package/dist/author-api.js
CHANGED
|
@@ -9,6 +9,9 @@ import { inspectAsset } from './asset-inspect.js';
|
|
|
9
9
|
import { callPreviewControl } from './preview-control.js';
|
|
10
10
|
import { isRecord } from './types.js';
|
|
11
11
|
import { authorGit } from './author-git.js';
|
|
12
|
+
import { installAuthorDependencies } from './author-install.js';
|
|
13
|
+
import { installAuthorEnvironment } from './author-environment-install.js';
|
|
14
|
+
export { installAuthorDependencies, installAuthorEnvironment };
|
|
12
15
|
export { authorGit, cloneAuthorRepository } from './author-git.js';
|
|
13
16
|
export { updateAuthorLock, createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
14
17
|
export { ContentWorkspace } from './content-workspace.js';
|
|
@@ -31,7 +34,12 @@ export async function openAuthorSession(directory, options = {}) {
|
|
|
31
34
|
name: snapshot.name,
|
|
32
35
|
project: snapshot.project,
|
|
33
36
|
sourceRevision: await workspace.revision(),
|
|
34
|
-
capabilities: {
|
|
37
|
+
capabilities: {
|
|
38
|
+
...snapshot.capabilities,
|
|
39
|
+
codeExecution: !workspace.readOnly && jobs.execute,
|
|
40
|
+
dependencyInstall: !workspace.readOnly,
|
|
41
|
+
environmentInstall: !workspace.readOnly,
|
|
42
|
+
},
|
|
35
43
|
diagnostics: snapshot.diagnostics,
|
|
36
44
|
};
|
|
37
45
|
},
|
|
@@ -41,7 +49,7 @@ export async function openAuthorSession(directory, options = {}) {
|
|
|
41
49
|
async query(input = {}) {
|
|
42
50
|
return queryContent(workspace, input);
|
|
43
51
|
},
|
|
44
|
-
async call(operation, input = {}) {
|
|
52
|
+
async call(operation, input = {}, signal) {
|
|
45
53
|
if (!isRecord(input))
|
|
46
54
|
throw new WorkspaceError('INPUT_INVALID', '操作参数需要对象');
|
|
47
55
|
switch (operation) {
|
|
@@ -104,13 +112,29 @@ export async function openAuthorSession(directory, options = {}) {
|
|
|
104
112
|
return { items: await this.environments.list() };
|
|
105
113
|
case 'environment-save':
|
|
106
114
|
return this.environments.save(input);
|
|
115
|
+
case 'dependency-install': {
|
|
116
|
+
await workspace.assertWritable();
|
|
117
|
+
if (input.offline !== undefined && typeof input.offline !== 'boolean')
|
|
118
|
+
throw new WorkspaceError('INPUT_INVALID', 'offline 需要布尔值');
|
|
119
|
+
return installAuthorDependencies(workspace, {
|
|
120
|
+
expectedVersion: field(input, 'expectedVersion'),
|
|
121
|
+
offline: input.offline,
|
|
122
|
+
signal,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
case 'environment-install':
|
|
126
|
+
await workspace.assertWritable();
|
|
127
|
+
return installAuthorEnvironment(workspace, input, signal);
|
|
128
|
+
case 'team-validate':
|
|
107
129
|
case 'battle': {
|
|
108
|
-
if (workspace.readOnly || !jobs.execute)
|
|
130
|
+
if (operation === 'battle' && (workspace.readOnly || !jobs.execute))
|
|
109
131
|
throw new WorkspaceError('EXECUTION_DISABLED', '自动化对局需要可执行的作者会话。');
|
|
110
132
|
await jobs.refresh();
|
|
111
133
|
const job = jobs.get(field(input, 'jobId'));
|
|
112
134
|
if (job.kind !== 'preview' || job.state !== 'succeeded' || !job.result?.preview?.endpoint)
|
|
113
135
|
throw new WorkspaceError('PREVIEW_NOT_ACTIVE', '此任务没有运行中的试玩候选。');
|
|
136
|
+
if (operation === 'team-validate')
|
|
137
|
+
return callPreviewControl(job.result.preview.endpoint, 'team-validate', { teamId: field(input, 'teamId') });
|
|
114
138
|
const { jobId: _jobId, operation: action, ...args } = input;
|
|
115
139
|
if (typeof action !== 'string')
|
|
116
140
|
throw new WorkspaceError('INPUT_INVALID', '需要战斗操作');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AuthorWorkspace } from './workspace.js';
|
|
2
|
+
export declare function parseAuthorEnvironmentInstall(input: unknown): {
|
|
3
|
+
source: import("./author-environment-source.js").AuthorEnvironmentSource;
|
|
4
|
+
offline: boolean | undefined;
|
|
5
|
+
};
|
|
6
|
+
/** Each distinct archive owns an editable project. A repeated import preserves its author's edits. */
|
|
7
|
+
export declare function installAuthorEnvironment(workspace: AuthorWorkspace, input: unknown, signal?: AbortSignal): Promise<{
|
|
8
|
+
directory: string;
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
integrity: string;
|
|
12
|
+
id: string;
|
|
13
|
+
reused: boolean;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, mkdtemp, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { isAbsolute, join } from 'node:path';
|
|
4
|
+
import { acquireAuthorEnvironment, parseAuthorEnvironmentSource } from './author-environment-source.js';
|
|
5
|
+
import { environmentManifestDocument } from './debug-environments.js';
|
|
6
|
+
import { installAuthorDependencies } from './author-install.js';
|
|
7
|
+
import { copyAuthorSkill } from './project.js';
|
|
8
|
+
import { withSourceLock } from './source-lock.js';
|
|
9
|
+
import { errorCode, isRecord } from './types.js';
|
|
10
|
+
import { AuthorWorkspace } from './workspace.js';
|
|
11
|
+
import { contentError, readJson } from './workspace-materials.js';
|
|
12
|
+
export function parseAuthorEnvironmentInstall(input) {
|
|
13
|
+
if (!isRecord(input) || (input.offline !== undefined && typeof input.offline !== 'boolean'))
|
|
14
|
+
throw contentError('ENVIRONMENT_INSTALL_INVALID');
|
|
15
|
+
return { source: parseAuthorEnvironmentSource(input.source), offline: input.offline };
|
|
16
|
+
}
|
|
17
|
+
async function directory(parent, name) {
|
|
18
|
+
const path = join(parent, name);
|
|
19
|
+
await mkdir(path, { mode: 0o700 }).catch(error => {
|
|
20
|
+
if (errorCode(error) !== 'EEXIST')
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
if (!(await lstat(path)).isDirectory() || (await realpath(path)) !== path)
|
|
24
|
+
throw contentError('MATERIAL_PATH_ESCAPE');
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
async function projectArchive(root, file) {
|
|
28
|
+
if (isAbsolute(file) ||
|
|
29
|
+
/[\\:\p{Cc}]/u.test(file) ||
|
|
30
|
+
file.split('/').some(part => !part || part.startsWith('.') || part.toLowerCase() === 'node_modules'))
|
|
31
|
+
throw contentError('MATERIAL_PATH_ESCAPE', '环境包归档必须是当前项目内的 .tgz 文件');
|
|
32
|
+
const path = join(root, file);
|
|
33
|
+
if ((await realpath(path)) !== path)
|
|
34
|
+
throw contentError('MATERIAL_PATH_ESCAPE');
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
async function alreadyInstalled(path, integrity) {
|
|
38
|
+
const info = await lstat(path).catch(error => {
|
|
39
|
+
if (errorCode(error) !== 'ENOENT')
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
42
|
+
if (!info)
|
|
43
|
+
return false;
|
|
44
|
+
if (!info.isDirectory() || (await realpath(path)) !== path)
|
|
45
|
+
throw contentError('MATERIAL_PATH_ESCAPE');
|
|
46
|
+
const marker = join(path, '.arcadia', 'environment-source.json');
|
|
47
|
+
if ((await realpath(marker)) !== marker)
|
|
48
|
+
throw contentError('ENVIRONMENT_INSTALL_CONFLICT');
|
|
49
|
+
const saved = await readJson(marker, 4096);
|
|
50
|
+
if (!isRecord(saved) || saved.integrity !== integrity)
|
|
51
|
+
throw contentError('ENVIRONMENT_INSTALL_CONFLICT');
|
|
52
|
+
const manifest = await readJson(join(path, 'package.json'));
|
|
53
|
+
if (manifest.arcadia)
|
|
54
|
+
throw contentError('ENVIRONMENT_INSTALL_CONFLICT');
|
|
55
|
+
environmentManifestDocument(manifest);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/** Each distinct archive owns an editable project. A repeated import preserves its author's edits. */
|
|
59
|
+
export async function installAuthorEnvironment(workspace, input, signal) {
|
|
60
|
+
signal?.throwIfAborted();
|
|
61
|
+
const { source, offline } = parseAuthorEnvironmentInstall(input);
|
|
62
|
+
await workspace.assertWritable();
|
|
63
|
+
const capture = source.kind === 'archive' ? { ...source, file: await projectArchive(workspace.root, source.file) } : source;
|
|
64
|
+
const owner = await directory(workspace.root, '.arcadia');
|
|
65
|
+
const projects = await directory(owner, 'installed-environments');
|
|
66
|
+
const cache = source.kind === 'npm'
|
|
67
|
+
? (process.env.npm_config_cache ?? (await directory(owner, 'environment-registry-cache')))
|
|
68
|
+
: undefined;
|
|
69
|
+
const staging = await mkdtemp(join(projects, '.install-'));
|
|
70
|
+
try {
|
|
71
|
+
const acquired = await acquireAuthorEnvironment(capture, join(staging, 'project'), { offline, signal, cache });
|
|
72
|
+
const { name, version, integrity, document } = acquired;
|
|
73
|
+
const path = join(projects, createHash('sha256').update(integrity).digest('hex'));
|
|
74
|
+
const result = { directory: path, name, version, integrity, id: document.id };
|
|
75
|
+
if (await alreadyInstalled(path, integrity))
|
|
76
|
+
return { ...result, reused: true };
|
|
77
|
+
await copyAuthorSkill(acquired.directory);
|
|
78
|
+
await writeFile(join(acquired.directory, '.gitignore'), 'node_modules/\n.arcadia/\n/*.tgz\n');
|
|
79
|
+
const project = await AuthorWorkspace.open(acquired.directory, { watch: false });
|
|
80
|
+
try {
|
|
81
|
+
const manifest = await project.read('package.json');
|
|
82
|
+
await installAuthorDependencies(project, { expectedVersion: manifest.version, offline, signal });
|
|
83
|
+
const metadata = await directory(project.root, '.arcadia');
|
|
84
|
+
await writeFile(join(metadata, 'environment-source.json'), JSON.stringify({ name, version, integrity }) + '\n', {
|
|
85
|
+
flag: 'wx',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await project.close();
|
|
90
|
+
}
|
|
91
|
+
const reused = await withSourceLock(workspace.root, 'environment-install', async () => {
|
|
92
|
+
await workspace.assertWritable();
|
|
93
|
+
if (await alreadyInstalled(path, integrity))
|
|
94
|
+
return true;
|
|
95
|
+
signal?.throwIfAborted();
|
|
96
|
+
await rename(acquired.directory, path);
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
return { ...result, reused };
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await rm(staging, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export type AuthorEnvironmentSource = {
|
|
2
|
+
kind: 'npm';
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'archive';
|
|
7
|
+
file: string;
|
|
8
|
+
};
|
|
9
|
+
type AcquireOptions = {
|
|
10
|
+
offline?: boolean;
|
|
11
|
+
cache?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
clientVersion?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function parseAuthorEnvironmentNpmSpec(spec: string): {
|
|
16
|
+
kind: 'npm';
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function parseAuthorEnvironmentSource(value: unknown): AuthorEnvironmentSource;
|
|
21
|
+
/** Capture the exact archive once. Only data fields and portable project inputs reach the new directory. */
|
|
22
|
+
export declare function acquireAuthorEnvironment(source: AuthorEnvironmentSource, destination: string, options?: AcquireOptions): Promise<{
|
|
23
|
+
directory: string;
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
document: {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
packages: Record<string, string>;
|
|
30
|
+
sources: string[];
|
|
31
|
+
schemaVersion: 2;
|
|
32
|
+
rules: {
|
|
33
|
+
schemaVersion: 1 | 2;
|
|
34
|
+
mechanics?: {
|
|
35
|
+
skillSlots?: {
|
|
36
|
+
normalMax: number;
|
|
37
|
+
climaxMax: number;
|
|
38
|
+
climaxMin?: number | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
individualValueDefault?: number | undefined;
|
|
41
|
+
individualValues?: {
|
|
42
|
+
max: number;
|
|
43
|
+
} | undefined;
|
|
44
|
+
allowFaintSwitch?: boolean | undefined;
|
|
45
|
+
timer?: {
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
turnTimeLimit?: number | undefined;
|
|
48
|
+
totalTimeLimit?: number | undefined;
|
|
49
|
+
animationPauseEnabled?: boolean | undefined;
|
|
50
|
+
maxAnimationDuration?: number | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
teamSelection?: {
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
mode?: "FULL_TEAM" | "TEAM_SELECTION" | "VIEW_ONLY" | undefined;
|
|
55
|
+
minTeamSize?: number | undefined;
|
|
56
|
+
maxTeamSize?: number | undefined;
|
|
57
|
+
allowStarterSelection?: boolean | undefined;
|
|
58
|
+
showOpponentTeam?: boolean | undefined;
|
|
59
|
+
teamInfoVisibility?: "BASIC" | "FULL" | "HIDDEN" | undefined;
|
|
60
|
+
timeLimit?: number | undefined;
|
|
61
|
+
} | undefined;
|
|
62
|
+
inheritance?: {
|
|
63
|
+
eligible: "all" | "off" | "species" | string[];
|
|
64
|
+
pool?: {
|
|
65
|
+
mode: "append" | "fallback" | "replace";
|
|
66
|
+
skills: string[];
|
|
67
|
+
} | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
enhancement?: {
|
|
70
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
71
|
+
minLevel?: number | undefined;
|
|
72
|
+
defaultBranches?: string[] | undefined;
|
|
73
|
+
stages?: string[] | undefined;
|
|
74
|
+
species?: string[] | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
77
|
+
} | undefined;
|
|
78
|
+
skillParameters?: {
|
|
79
|
+
profile?: string | undefined;
|
|
80
|
+
groups?: Record<string, number> | undefined;
|
|
81
|
+
overrides?: {
|
|
82
|
+
skill: string;
|
|
83
|
+
useId: string;
|
|
84
|
+
parameter: string;
|
|
85
|
+
value: number;
|
|
86
|
+
}[] | undefined;
|
|
87
|
+
} | undefined;
|
|
88
|
+
matchups?: {
|
|
89
|
+
table?: string | undefined;
|
|
90
|
+
adjustments?: {
|
|
91
|
+
attack: string;
|
|
92
|
+
defense: string;
|
|
93
|
+
multiplier: number;
|
|
94
|
+
}[] | undefined;
|
|
95
|
+
} | undefined;
|
|
96
|
+
learnsetAdjustments?: {
|
|
97
|
+
species: string;
|
|
98
|
+
source: "inherited" | "normal";
|
|
99
|
+
skill: string;
|
|
100
|
+
action: "add" | "remove";
|
|
101
|
+
level?: number | undefined;
|
|
102
|
+
}[] | undefined;
|
|
103
|
+
tier?: "standard" | undefined;
|
|
104
|
+
allow?: {
|
|
105
|
+
species?: string[] | undefined;
|
|
106
|
+
skills?: string[] | undefined;
|
|
107
|
+
marks?: string[] | undefined;
|
|
108
|
+
} | undefined;
|
|
109
|
+
deny?: {
|
|
110
|
+
species?: string[] | undefined;
|
|
111
|
+
skills?: string[] | undefined;
|
|
112
|
+
marks?: string[] | undefined;
|
|
113
|
+
} | undefined;
|
|
114
|
+
team?: {
|
|
115
|
+
minSize?: number | undefined;
|
|
116
|
+
maxSize?: number | undefined;
|
|
117
|
+
uniqueSpecies?: boolean | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
constraints?: ({
|
|
120
|
+
id: string;
|
|
121
|
+
allOf: {
|
|
122
|
+
kind: "mark" | "skill" | "species";
|
|
123
|
+
ids: string[];
|
|
124
|
+
fromCollections?: string[] | undefined;
|
|
125
|
+
}[];
|
|
126
|
+
kind: "ban";
|
|
127
|
+
scope: "pet" | "team";
|
|
128
|
+
exceptWhen?: {
|
|
129
|
+
kind: "mark" | "skill" | "species";
|
|
130
|
+
ids: string[];
|
|
131
|
+
fromCollections?: string[] | undefined;
|
|
132
|
+
}[] | undefined;
|
|
133
|
+
exceptAny?: {
|
|
134
|
+
kind: "mark" | "skill" | "species";
|
|
135
|
+
ids: string[];
|
|
136
|
+
fromCollections?: string[] | undefined;
|
|
137
|
+
}[][] | undefined;
|
|
138
|
+
} | {
|
|
139
|
+
id: string;
|
|
140
|
+
allOf: {
|
|
141
|
+
kind: "mark" | "skill" | "species";
|
|
142
|
+
ids: string[];
|
|
143
|
+
fromCollections?: string[] | undefined;
|
|
144
|
+
}[];
|
|
145
|
+
kind: "memberLimit";
|
|
146
|
+
max: number;
|
|
147
|
+
})[] | undefined;
|
|
148
|
+
collections?: {
|
|
149
|
+
id: string;
|
|
150
|
+
kind: "mark" | "skill" | "species";
|
|
151
|
+
ids: string[];
|
|
152
|
+
}[] | undefined;
|
|
153
|
+
};
|
|
154
|
+
requires: {
|
|
155
|
+
engine?: string | undefined;
|
|
156
|
+
sdk?: string | undefined;
|
|
157
|
+
capabilities?: string[] | undefined;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
integrity: string;
|
|
161
|
+
}>;
|
|
162
|
+
export {};
|