@arcadia-eternity/content-sdk 4.6.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/author-api.d.ts +12 -2
- package/dist/author-api.js +11 -2
- package/dist/author-git.d.ts +63 -0
- package/dist/author-git.js +324 -0
- package/dist/author-reference.d.ts +15 -1
- package/dist/author-reference.js +20 -1
- package/dist/cli.js +5 -4
- package/dist/content-query.d.ts +15 -1
- package/dist/content-query.js +53 -11
- package/dist/content-workspace.d.ts +423 -3
- package/dist/content-workspace.js +194 -51
- package/dist/debug-environments.d.ts +393 -25
- package/dist/debug-environments.js +3 -42
- package/dist/demo.js +1 -1
- package/dist/effect-declarations.d.ts +14 -0
- package/dist/effect-declarations.js +103 -0
- package/dist/environment-host-base.d.ts +175 -0
- package/dist/environment-host-base.js +86 -0
- package/dist/environment-member-transfer.d.ts +5 -0
- package/dist/environment-member-transfer.js +95 -0
- package/dist/environment-rules.d.ts +728 -3
- package/dist/environment-rules.js +158 -74
- package/dist/environment-sharing.d.ts +51 -0
- package/dist/environment-sharing.js +321 -0
- package/dist/environment.d.ts +2 -0
- package/dist/environment.js +32 -9
- package/dist/jobs.d.ts +5 -0
- package/dist/jobs.js +59 -10
- package/dist/learnsets.d.ts +47 -0
- package/dist/learnsets.js +124 -0
- package/dist/lib/content.d.ts +1 -1
- package/dist/lib/content.js +26 -2
- package/dist/lib/presentation.js +5 -11
- package/dist/managed-projects.d.ts +6 -0
- package/dist/managed-projects.js +137 -45
- package/dist/managed-sources.d.ts +17 -0
- package/dist/managed-sources.js +28 -10
- package/dist/mcp-contracts.d.ts +405 -4
- package/dist/mcp-contracts.js +3 -1
- package/dist/mcp.js +23 -1
- package/dist/pack-project.d.ts +2 -1
- package/dist/pack-project.js +40 -5
- package/dist/prepared-document.d.ts +476 -0
- package/dist/prepared-document.js +47 -0
- package/dist/preview.js +5 -5
- package/dist/project.d.ts +3 -1
- package/dist/project.js +47 -4
- package/dist/rule-composition.d.ts +290 -0
- package/dist/rule-composition.js +267 -0
- package/dist/template/.github/scripts/release-payload.mjs +91 -0
- package/dist/template/.github/scripts/release-test-npm.mjs +27 -0
- package/dist/template/.github/scripts/verify-release.mjs +138 -0
- package/dist/template/.github/workflows/release-pack.yml +77 -0
- package/dist/template/README.md +15 -2
- package/dist/template/gitignore-template +7 -0
- package/dist/template/npm-lock-template.json +2319 -0
- package/dist/template/package.json +4 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +1 -1
- package/dist/template/skills/arcadia-content-git/SKILL.md +14 -0
- package/dist/template/skills/arcadia-content-release/SKILL.md +29 -0
- package/dist/template/test/pack.test.mjs +24 -5
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +26 -7
- package/dist/workspace-cli.js +2 -2
- package/dist/workspace-materials.d.ts +4 -1
- package/dist/workspace-materials.js +8 -2
- package/dist/workspace.d.ts +11 -0
- package/dist/workspace.js +191 -31
- package/package.json +16 -4
- package/release-payload.mjs +91 -0
- package/release-test-npm.mjs +27 -0
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ The desktop MCP configuration includes an optional `--context-file` path under E
|
|
|
76
76
|
|
|
77
77
|
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
78
|
|
|
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. `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.
|
|
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 provide the SDK template’s skills for 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
80
|
|
|
81
81
|
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
82
|
|
|
@@ -92,7 +92,7 @@ Environment schema v2 adds versioned rule data and runtime requirements. Existin
|
|
|
92
92
|
|
|
93
93
|
Workspace files own persistent environment projects and their current installations. Database adapters supply durable retention roots; runtime leases belong to the current owner. Deletion fails closed when retention information is unavailable, and owner shutdown refuses outstanding runtime leases. Server bindings, accounts, grants and running rooms remain separate from these files.
|
|
94
94
|
|
|
95
|
-
`exportEnvironment` requires the current manifest to be prepared and creates a portable environment archive with standard npm locks and material bytes, excluding server and workspace identities. `exportSnapshot` captures workspace identity and every environment project, including pending manifest edits and uninstalled projects for a server backup. `restoreSnapshot` requires an empty, inactive staging workspace: restore preserves workspace identity, clone creates a new workspace identity while keeping environment names. The server backup coordinator validates the corresponding database snapshot before switching the full server directory. These file APIs do not provide a transaction spanning the database and filesystem.
|
|
95
|
+
`exportEnvironment` requires the current manifest to be prepared and creates a portable environment archive with standard npm locks and material bytes, excluding server and workspace identities. Local archives accompany the export. Online dependencies are locked references unless selected for inclusion. Only membership of the official base package is transferred. Import resolves it from the receiving host, including when reading older exports. `exportSnapshot` captures workspace identity and every environment project, including pending manifest edits and uninstalled projects for a server backup. `restoreSnapshot` requires an empty, inactive staging workspace: restore preserves workspace identity, clone creates a new workspace identity while keeping environment names. The server backup coordinator validates the corresponding database snapshot before switching the full server directory. These file APIs do not provide a transaction spanning the database and filesystem.
|
|
96
96
|
|
|
97
97
|
## Repository development
|
|
98
98
|
|
package/dist/author-api.d.ts
CHANGED
|
@@ -2,10 +2,14 @@ import { DebugEnvironments } from './debug-environments.js';
|
|
|
2
2
|
import { ProjectTeams } from './project-teams.js';
|
|
3
3
|
import { AuthorWorkspace, type WorkspaceOptions } from './workspace.js';
|
|
4
4
|
import { AuthorJobs } from './jobs.js';
|
|
5
|
+
import { dependencyReferences } from './content-query.js';
|
|
5
6
|
import { type UnknownRecord } from './types.js';
|
|
6
|
-
export {
|
|
7
|
+
export { authorGit, cloneAuthorRepository } from './author-git.js';
|
|
8
|
+
export { updateAuthorLock, createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
9
|
+
export type DependencyReferenceCatalog = Awaited<ReturnType<typeof dependencyReferences>>;
|
|
7
10
|
export { ContentWorkspace } from './content-workspace.js';
|
|
8
11
|
export { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
12
|
+
export type { AuthorEffectCatalog } from './effect-declarations.js';
|
|
9
13
|
export interface AuthorSessionOptions extends WorkspaceOptions {
|
|
10
14
|
execute?: boolean;
|
|
11
15
|
contextFile?: string;
|
|
@@ -36,12 +40,18 @@ export declare function openAuthorSession(directory: string, options?: AuthorSes
|
|
|
36
40
|
};
|
|
37
41
|
diagnostics: import("./workspace.js").Diagnostic[];
|
|
38
42
|
}>;
|
|
43
|
+
dependencyReferences(locale: string): Promise<{
|
|
44
|
+
items: import("./content-query.js").DependencyReference[];
|
|
45
|
+
diagnostics: string[];
|
|
46
|
+
}>;
|
|
39
47
|
query(input?: UnknownRecord): Promise<{
|
|
40
48
|
total: number;
|
|
41
49
|
offset: number;
|
|
42
50
|
nextOffset: number | null;
|
|
43
51
|
items: unknown[];
|
|
44
|
-
diagnostics: Record<string, unknown>
|
|
52
|
+
diagnostics: (Record<string, unknown> & {
|
|
53
|
+
message: string;
|
|
54
|
+
})[];
|
|
45
55
|
}>;
|
|
46
56
|
call(operation: string, input?: unknown): Promise<unknown>;
|
|
47
57
|
close(): Promise<void>;
|
package/dist/author-api.js
CHANGED
|
@@ -3,12 +3,14 @@ import { ProjectTeams } from './project-teams.js';
|
|
|
3
3
|
import { AuthorWorkspace, WorkspaceError, } from './workspace.js';
|
|
4
4
|
import { readWorkbenchContext } from './workbench-context.js';
|
|
5
5
|
import { AuthorJobs } from './jobs.js';
|
|
6
|
-
import { queryContent } from './content-query.js';
|
|
6
|
+
import { dependencyReferences, queryContent } from './content-query.js';
|
|
7
7
|
import { authorReference } from './author-reference.js';
|
|
8
8
|
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
|
+
export { authorGit, cloneAuthorRepository } from './author-git.js';
|
|
13
|
+
export { updateAuthorLock, createSourceProject, connectDevelopmentSdk, authorConnection } from './project.js';
|
|
12
14
|
export { ContentWorkspace } from './content-workspace.js';
|
|
13
15
|
export { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
14
16
|
/** Shared operations for the desktop, CLI and MCP adapters. */
|
|
@@ -33,6 +35,9 @@ export async function openAuthorSession(directory, options = {}) {
|
|
|
33
35
|
diagnostics: snapshot.diagnostics,
|
|
34
36
|
};
|
|
35
37
|
},
|
|
38
|
+
dependencyReferences(locale) {
|
|
39
|
+
return dependencyReferences(workspace, locale);
|
|
40
|
+
},
|
|
36
41
|
async query(input = {}) {
|
|
37
42
|
return queryContent(workspace, input);
|
|
38
43
|
},
|
|
@@ -50,6 +55,10 @@ export async function openAuthorSession(directory, options = {}) {
|
|
|
50
55
|
return authorReference(input);
|
|
51
56
|
case 'asset-inspect':
|
|
52
57
|
return inspectAsset(workspace, input);
|
|
58
|
+
case 'git-status':
|
|
59
|
+
return authorGit(workspace, { operation: 'status' });
|
|
60
|
+
case 'git-diff':
|
|
61
|
+
return authorGit(workspace, { operation: 'diff', file: input.file, staged: input.staged });
|
|
53
62
|
case 'snapshot':
|
|
54
63
|
return workspace.snapshot();
|
|
55
64
|
case 'read':
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type UnknownRecord } from './types.js';
|
|
2
|
+
import { type AuthorWorkspace } from './workspace.js';
|
|
3
|
+
type GitTokenProvider = (url: string) => Promise<string>;
|
|
4
|
+
export declare function cloneAuthorRepository(directory: string, url: unknown, signal?: AbortSignal, tokenFor?: GitTokenProvider): Promise<void>;
|
|
5
|
+
export declare function authorGit(workspace: AuthorWorkspace, input: UnknownRecord, signal?: AbortSignal, tokenFor?: GitTokenProvider): Promise<string | {
|
|
6
|
+
repository: boolean;
|
|
7
|
+
head: string;
|
|
8
|
+
branch: string | null;
|
|
9
|
+
detached: boolean;
|
|
10
|
+
upstream: string | null;
|
|
11
|
+
hasRemote: boolean;
|
|
12
|
+
tags: string[];
|
|
13
|
+
ahead: number;
|
|
14
|
+
behind: number;
|
|
15
|
+
files: {
|
|
16
|
+
path: string;
|
|
17
|
+
staged: boolean;
|
|
18
|
+
changed: boolean;
|
|
19
|
+
untracked: boolean;
|
|
20
|
+
conflict: boolean;
|
|
21
|
+
}[];
|
|
22
|
+
} | {
|
|
23
|
+
repository: boolean;
|
|
24
|
+
manifestVersion?: undefined;
|
|
25
|
+
packageRepositoryMatches?: undefined;
|
|
26
|
+
head?: undefined;
|
|
27
|
+
tag?: undefined;
|
|
28
|
+
tagged?: undefined;
|
|
29
|
+
filename?: undefined;
|
|
30
|
+
text?: undefined;
|
|
31
|
+
patch?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
repository: string;
|
|
34
|
+
manifestVersion: string;
|
|
35
|
+
packageRepositoryMatches: boolean;
|
|
36
|
+
head: string | undefined;
|
|
37
|
+
tag: string;
|
|
38
|
+
tagged: boolean;
|
|
39
|
+
filename: string;
|
|
40
|
+
text?: undefined;
|
|
41
|
+
patch?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
repository?: undefined;
|
|
44
|
+
manifestVersion?: undefined;
|
|
45
|
+
packageRepositoryMatches?: undefined;
|
|
46
|
+
head?: undefined;
|
|
47
|
+
tag?: undefined;
|
|
48
|
+
tagged?: undefined;
|
|
49
|
+
filename?: undefined;
|
|
50
|
+
text: string;
|
|
51
|
+
patch?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
repository?: undefined;
|
|
54
|
+
manifestVersion?: undefined;
|
|
55
|
+
packageRepositoryMatches?: undefined;
|
|
56
|
+
head?: undefined;
|
|
57
|
+
tag?: undefined;
|
|
58
|
+
tagged?: undefined;
|
|
59
|
+
filename?: undefined;
|
|
60
|
+
text?: undefined;
|
|
61
|
+
patch: string;
|
|
62
|
+
} | null>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { lstat, readdir, realpath } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
import { simpleGit } from 'simple-git';
|
|
4
|
+
import { errorCode } from './types.js';
|
|
5
|
+
import { desktopMetadataNames } from './workspace.js';
|
|
6
|
+
function client(root, signal, disableHooks = true, transportEnv = {}) {
|
|
7
|
+
const env = {
|
|
8
|
+
...(process.env.GIT_SSL_CAINFO ? { GIT_SSL_CAINFO: process.env.GIT_SSL_CAINFO } : {}),
|
|
9
|
+
...transportEnv,
|
|
10
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
11
|
+
GIT_ALLOW_PROTOCOL: 'https',
|
|
12
|
+
GIT_LITERAL_PATHSPECS: '1',
|
|
13
|
+
GIT_CEILING_DIRECTORIES: dirname(root),
|
|
14
|
+
GIT_OPTIONAL_LOCKS: '0',
|
|
15
|
+
};
|
|
16
|
+
return simpleGit({
|
|
17
|
+
baseDir: root,
|
|
18
|
+
strict: true,
|
|
19
|
+
allowEnvironment: Object.keys(env),
|
|
20
|
+
allowConfig: [
|
|
21
|
+
'core.hooksPath',
|
|
22
|
+
'core.fsmonitor',
|
|
23
|
+
'submodule.recurse',
|
|
24
|
+
...(transportEnv.GIT_CONFIG_COUNT
|
|
25
|
+
? ['credential.helper', 'http.followRedirects', transportEnv.GIT_CONFIG_KEY_0]
|
|
26
|
+
: []),
|
|
27
|
+
],
|
|
28
|
+
config: [
|
|
29
|
+
...(disableHooks ? ['core.hooksPath=' + (process.platform === 'win32' ? 'NUL' : '/dev/null')] : []),
|
|
30
|
+
'core.fsmonitor=false',
|
|
31
|
+
'submodule.recurse=false',
|
|
32
|
+
],
|
|
33
|
+
abort: AbortSignal.any([AbortSignal.timeout(60000), ...(signal ? [signal] : [])]),
|
|
34
|
+
}).env({
|
|
35
|
+
...Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^GIT_|^(EDITOR|PAGER)$/i.test(key))),
|
|
36
|
+
...env,
|
|
37
|
+
GCM_INTERACTIVE: 'never',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function httpsRemote(value) {
|
|
41
|
+
if (typeof value !== 'string' || value.length > 2048 || !value.startsWith('https://'))
|
|
42
|
+
throw new Error('请输入 HTTPS 仓库地址');
|
|
43
|
+
const url = new URL(value);
|
|
44
|
+
if (url.username || url.password || url.search || url.hash)
|
|
45
|
+
throw new Error('仓库地址不能包含凭据、查询参数或片段');
|
|
46
|
+
return url.href;
|
|
47
|
+
}
|
|
48
|
+
// The credential is supplied by the desktop for this specific URL and transfer only.
|
|
49
|
+
async function transferClient(root, url, signal, tokenFor) {
|
|
50
|
+
if (!tokenFor)
|
|
51
|
+
return client(root, signal);
|
|
52
|
+
const token = await tokenFor(url);
|
|
53
|
+
const encoded = Buffer.from('x-access-token:' + token).toString('base64');
|
|
54
|
+
return client(root, signal, true, {
|
|
55
|
+
GIT_CONFIG_COUNT: '3',
|
|
56
|
+
GIT_CONFIG_KEY_0: 'http.' + url + '.extraHeader',
|
|
57
|
+
GIT_CONFIG_VALUE_0: 'Authorization: Basic ' + encoded,
|
|
58
|
+
GIT_CONFIG_KEY_1: 'http.followRedirects',
|
|
59
|
+
GIT_CONFIG_VALUE_1: 'false',
|
|
60
|
+
GIT_CONFIG_KEY_2: 'credential.helper',
|
|
61
|
+
GIT_CONFIG_VALUE_2: '',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export async function cloneAuthorRepository(directory, url, signal, tokenFor) {
|
|
65
|
+
const remote = httpsRemote(url);
|
|
66
|
+
const transport = await transferClient(dirname(directory), remote, signal, tokenFor);
|
|
67
|
+
await transport.clone(remote, directory, ['--no-recurse-submodules', ...(tokenFor ? ['--no-checkout'] : [])]);
|
|
68
|
+
if (tokenFor) {
|
|
69
|
+
const local = client(directory, signal);
|
|
70
|
+
if ((await local.branchLocal()).all.length)
|
|
71
|
+
await local.reset(['--hard', 'HEAD']);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// A source project may sit inside a larger repository. Never operate on that parent
|
|
75
|
+
// or follow a gitfile to metadata outside the directory selected by the author.
|
|
76
|
+
async function repository(root, git) {
|
|
77
|
+
const meta = join(root, '.git');
|
|
78
|
+
const entry = await lstat(meta).catch(error => {
|
|
79
|
+
if (errorCode(error) !== 'ENOENT')
|
|
80
|
+
throw error;
|
|
81
|
+
});
|
|
82
|
+
if (!entry)
|
|
83
|
+
return false;
|
|
84
|
+
if (!entry.isDirectory())
|
|
85
|
+
throw new Error('链接工作树请通过外部编辑器管理');
|
|
86
|
+
// Metadata is local state too. A redirected ref, index or object directory can
|
|
87
|
+
// otherwise turn an ordinary commit or fetch into a write outside this root.
|
|
88
|
+
for (const child of await readdir(meta, { withFileTypes: true })) {
|
|
89
|
+
if (child.isSymbolicLink() || child.name === 'commondir')
|
|
90
|
+
throw new Error('Git 元数据包含外部链接,请通过外部编辑器管理');
|
|
91
|
+
}
|
|
92
|
+
for (const directory of ['refs', 'logs', 'objects']) {
|
|
93
|
+
const entries = await readdir(join(meta, directory), { recursive: true, withFileTypes: true }).catch(error => {
|
|
94
|
+
if (errorCode(error) !== 'ENOENT')
|
|
95
|
+
throw error;
|
|
96
|
+
return [];
|
|
97
|
+
});
|
|
98
|
+
if (entries.some(file => file.isSymbolicLink() || (directory === 'objects' && ['alternates', 'http-alternates'].includes(file.name))))
|
|
99
|
+
throw new Error('Git 引用或对象位于项目目录之外');
|
|
100
|
+
}
|
|
101
|
+
const keys = await git.raw([
|
|
102
|
+
'config',
|
|
103
|
+
'--file',
|
|
104
|
+
join(meta, 'config'),
|
|
105
|
+
'--no-includes',
|
|
106
|
+
'--null',
|
|
107
|
+
'--name-only',
|
|
108
|
+
'--list',
|
|
109
|
+
]);
|
|
110
|
+
// Repository-local filters, includes, alternate work trees and command helpers
|
|
111
|
+
// can alter even a status read. Global credential helpers belong to the OS user.
|
|
112
|
+
const supported = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|hookspath|ignorecase|precomposeunicode|autocrlf|symlinks|quotepath)|user\.(?:name|email|signingkey)|branch\..+\.(?:remote|merge|rebase|vscode-merge-base)|remote\.[\w.-]+\.(?:url|fetch|pushurl)|pull\.(?:rebase|ff)|push\.default|gui\.(?:wmstate|geometry))$/i;
|
|
113
|
+
if (keys.split('\0').some(key => key && !supported.test(key)))
|
|
114
|
+
throw new Error('仓库使用自定义 Git 配置,请通过外部编辑器管理');
|
|
115
|
+
if ((await realpath((await git.revparse(['--path-format=absolute', '--git-common-dir'])).trim())) !== meta)
|
|
116
|
+
throw new Error('Git 元数据位于项目目录之外');
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
async function trackingRemote(git, branch) {
|
|
120
|
+
const upstream = branch
|
|
121
|
+
? await git.raw(['for-each-ref', '--format=%(upstream:remotename)%00%(upstream:remoteref)', 'refs/heads/' + branch])
|
|
122
|
+
: '';
|
|
123
|
+
const [tracking, remoteRef] = upstream.trim().split('\0');
|
|
124
|
+
const remotes = (await git.getRemotes(false)).map(item => item.name);
|
|
125
|
+
const target = tracking || (remotes.includes('origin') ? 'origin' : remotes.length === 1 ? remotes[0] : '');
|
|
126
|
+
return { target, remoteRef };
|
|
127
|
+
}
|
|
128
|
+
async function status(git) {
|
|
129
|
+
const state = await git.status(['--no-renames', '--untracked-files=all', '--ignore-submodules=all']);
|
|
130
|
+
const files = state.files.filter(file => file.index !== '?' || !desktopMetadataNames.has(basename(file.path)));
|
|
131
|
+
const head = (await git.raw(['rev-parse', '--revs-only', 'HEAD'])).trim();
|
|
132
|
+
return {
|
|
133
|
+
repository: true,
|
|
134
|
+
head,
|
|
135
|
+
branch: state.current,
|
|
136
|
+
detached: state.detached,
|
|
137
|
+
upstream: state.tracking,
|
|
138
|
+
hasRemote: (await git.getRemotes(false)).length > 0,
|
|
139
|
+
tags: !files.length && head ? (await git.tag(['--points-at', 'HEAD'])).trim().split('\n').filter(Boolean) : [],
|
|
140
|
+
ahead: state.ahead,
|
|
141
|
+
behind: state.behind,
|
|
142
|
+
files: files.map(file => ({
|
|
143
|
+
path: file.path,
|
|
144
|
+
staged: file.index !== ' ' && file.index !== '?',
|
|
145
|
+
changed: file.working_dir !== ' ',
|
|
146
|
+
untracked: file.working_dir === '?',
|
|
147
|
+
conflict: state.conflicted.includes(file.path),
|
|
148
|
+
})),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export async function authorGit(workspace, input, signal, tokenFor) {
|
|
152
|
+
if (typeof input.operation !== 'string')
|
|
153
|
+
throw new Error('不支持的 Git 操作');
|
|
154
|
+
if (input.operation === 'status' || input.operation === 'diff') {
|
|
155
|
+
await workspace.path('package.json');
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
await workspace.assertWritable();
|
|
159
|
+
const git = client(workspace.root, signal);
|
|
160
|
+
const exists = await repository(workspace.root, git);
|
|
161
|
+
if (input.operation === 'status')
|
|
162
|
+
return exists ? status(git) : { repository: false };
|
|
163
|
+
if (!exists) {
|
|
164
|
+
if (input.operation !== 'init')
|
|
165
|
+
throw new Error('请先初始化 Git 仓库');
|
|
166
|
+
await git.init(['--initial-branch=main']);
|
|
167
|
+
return status(git);
|
|
168
|
+
}
|
|
169
|
+
const state = await status(git);
|
|
170
|
+
if (!['diff', 'push-target', 'tag-target', 'github-target'].includes(input.operation)) {
|
|
171
|
+
const hooks = await client(workspace.root, signal, false).getConfig('core.hooksPath');
|
|
172
|
+
const entries = await readdir(join(workspace.root, '.git/hooks')).catch(error => {
|
|
173
|
+
if (errorCode(error) !== 'ENOENT')
|
|
174
|
+
throw error;
|
|
175
|
+
return [];
|
|
176
|
+
});
|
|
177
|
+
if (hooks.value || entries.some(name => !name.endsWith('.sample') && !name.startsWith('.')))
|
|
178
|
+
throw new Error('此仓库已配置 Git 钩子,请通过外部编辑器完成写操作');
|
|
179
|
+
}
|
|
180
|
+
if (input.operation === 'github-target') {
|
|
181
|
+
const { target: remote } = await trackingRemote(git, state.branch);
|
|
182
|
+
if (!/^[\w][\w.-]*$/.test(remote))
|
|
183
|
+
return null;
|
|
184
|
+
const raw = (await git.raw(['remote', 'get-url', '--push', '--all', remote])).trim();
|
|
185
|
+
const match = /^https:\/\/github\.com\/([a-z0-9-]+\/[a-z0-9._-]+?)(?:\.git)?\/?$/i.exec(raw);
|
|
186
|
+
if (!match)
|
|
187
|
+
return null;
|
|
188
|
+
const declared = await workspace.read('package.json');
|
|
189
|
+
const manifest = JSON.parse(declared.text);
|
|
190
|
+
const url = typeof manifest.repository === 'string' ? manifest.repository : manifest.repository?.url;
|
|
191
|
+
const packageRepositoryMatches = typeof url === 'string' && url.replace(/^git\+/, '').replace(/\.git$/, '') === 'https://github.com/' + match[1];
|
|
192
|
+
const tag = 'v' + manifest.version;
|
|
193
|
+
const head = state.head || undefined;
|
|
194
|
+
return {
|
|
195
|
+
repository: match[1],
|
|
196
|
+
manifestVersion: declared.version,
|
|
197
|
+
packageRepositoryMatches,
|
|
198
|
+
head,
|
|
199
|
+
tag,
|
|
200
|
+
tagged: state.tags.includes(tag),
|
|
201
|
+
filename: manifest.name.replace(/^@/, '').replace('/', '-') + '-' + manifest.version + '.tgz',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (input.operation === 'stage-files') {
|
|
205
|
+
if (!Array.isArray(input.files) || !input.files.length || input.files.length > 2000)
|
|
206
|
+
throw new Error('请选择 1–2000 个文件');
|
|
207
|
+
const changed = new Set(state.files.filter(file => file.changed && !file.conflict).map(file => file.path));
|
|
208
|
+
const files = [];
|
|
209
|
+
for (const file of input.files) {
|
|
210
|
+
if (typeof file !== 'string' || !changed.has(file))
|
|
211
|
+
throw new Error('文件状态已改变,请刷新');
|
|
212
|
+
await workspace.path(file, { create: true });
|
|
213
|
+
files.push(file);
|
|
214
|
+
}
|
|
215
|
+
await git.add(['--', ...files]);
|
|
216
|
+
}
|
|
217
|
+
else if (['stage', 'unstage', 'diff'].includes(input.operation)) {
|
|
218
|
+
const row = state.files.find(item => item.path === input.file);
|
|
219
|
+
if (!row)
|
|
220
|
+
throw new Error('文件状态已改变,请刷新');
|
|
221
|
+
await workspace.path(row.path, { create: true });
|
|
222
|
+
if (input.operation === 'diff') {
|
|
223
|
+
if (row.untracked)
|
|
224
|
+
return { text: (await workspace.read(row.path)).text };
|
|
225
|
+
const patch = await git.diff([
|
|
226
|
+
'--no-color',
|
|
227
|
+
'--no-ext-diff',
|
|
228
|
+
'--no-textconv',
|
|
229
|
+
...(input.staged === true ? ['--cached'] : []),
|
|
230
|
+
'--',
|
|
231
|
+
row.path,
|
|
232
|
+
]);
|
|
233
|
+
if (Buffer.byteLength(patch) > 1024 * 1024)
|
|
234
|
+
throw new Error('差异超过 1 MiB,请在外部编辑器查看');
|
|
235
|
+
return { patch };
|
|
236
|
+
}
|
|
237
|
+
if (input.operation === 'stage')
|
|
238
|
+
await git.add(['--', row.path]);
|
|
239
|
+
else
|
|
240
|
+
await git.reset(['--', row.path]);
|
|
241
|
+
}
|
|
242
|
+
else if (input.operation === 'commit') {
|
|
243
|
+
if (workspace.hasDirtyFiles ||
|
|
244
|
+
typeof input.message !== 'string' ||
|
|
245
|
+
!input.message.trim() ||
|
|
246
|
+
input.message.length > 4000 ||
|
|
247
|
+
state.files.some(file => file.conflict))
|
|
248
|
+
throw new Error('请先保存草稿、处理冲突并填写提交说明');
|
|
249
|
+
const identity = input.fallbackIdentity;
|
|
250
|
+
if (identity?.name &&
|
|
251
|
+
identity.email &&
|
|
252
|
+
(!(await git.getConfig('user.name')).value || !(await git.getConfig('user.email')).value)) {
|
|
253
|
+
const commitGit = client(workspace.root, signal, true, {
|
|
254
|
+
GIT_AUTHOR_NAME: identity.name,
|
|
255
|
+
GIT_COMMITTER_NAME: identity.name,
|
|
256
|
+
GIT_AUTHOR_EMAIL: identity.email,
|
|
257
|
+
GIT_COMMITTER_EMAIL: identity.email,
|
|
258
|
+
});
|
|
259
|
+
await commitGit.commit(input.message);
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
await git.commit(input.message);
|
|
263
|
+
}
|
|
264
|
+
else if (input.operation === 'tag') {
|
|
265
|
+
if (state.files.length || workspace.hasDirtyFiles)
|
|
266
|
+
throw new Error('请先保存并提交所有修改');
|
|
267
|
+
if (typeof input.tag !== 'string' || !/^v?[0-9][\w.+-]{0,100}$/.test(input.tag))
|
|
268
|
+
throw new Error('版本标签无效');
|
|
269
|
+
await git.tag(['--', input.tag]);
|
|
270
|
+
}
|
|
271
|
+
else if (input.operation === 'bind') {
|
|
272
|
+
await git.addRemote('origin', httpsRemote(input.url));
|
|
273
|
+
}
|
|
274
|
+
else if (['fetch', 'pull', 'push', 'push-target', 'push-tag', 'tag-target'].includes(input.operation)) {
|
|
275
|
+
if (state.detached || !state.branch)
|
|
276
|
+
throw new Error('请先切换到本地分支');
|
|
277
|
+
const { target, remoteRef } = await trackingRemote(git, state.branch);
|
|
278
|
+
if (!/^[\w][\w.-]*$/.test(target))
|
|
279
|
+
throw new Error('请选择 HTTPS 远端');
|
|
280
|
+
const tagPush = input.operation === 'push-tag' || input.operation === 'tag-target';
|
|
281
|
+
const pushing = tagPush || input.operation === 'push' || input.operation === 'push-target';
|
|
282
|
+
const urls = (await git.raw(['remote', 'get-url', ...(pushing ? ['--push'] : []), '--all', target]))
|
|
283
|
+
.trim()
|
|
284
|
+
.split('\n');
|
|
285
|
+
if (urls.length !== 1)
|
|
286
|
+
throw new Error('多个远端地址请在外部编辑器中管理');
|
|
287
|
+
const url = httpsRemote(urls[0]);
|
|
288
|
+
const ref = remoteRef || 'refs/heads/' + state.branch;
|
|
289
|
+
if (!ref.startsWith('refs/heads/'))
|
|
290
|
+
throw new Error('远端分支无效');
|
|
291
|
+
let pushRef = 'refs/heads/' + state.branch + ':' + ref;
|
|
292
|
+
let destination = url + ' · ' + ref.slice(11);
|
|
293
|
+
if (tagPush) {
|
|
294
|
+
const tag = 'v' + JSON.parse((await workspace.read('package.json')).text).version;
|
|
295
|
+
if (workspace.hasDirtyFiles || !state.tags.includes(tag))
|
|
296
|
+
throw new Error('请先提交修改并创建当前版本标签');
|
|
297
|
+
pushRef = 'refs/tags/' + tag + ':refs/tags/' + tag;
|
|
298
|
+
destination = url + ' · ' + tag;
|
|
299
|
+
}
|
|
300
|
+
if (pushing)
|
|
301
|
+
destination += ' · ' + (await git.revparse([pushRef.split(':')[0]])).trim();
|
|
302
|
+
if (input.operation === 'push-target' || input.operation === 'tag-target')
|
|
303
|
+
return destination;
|
|
304
|
+
if (pushing && input.destination !== destination)
|
|
305
|
+
throw new Error('远端地址或分支已改变,请重新确认推送');
|
|
306
|
+
const transport = await transferClient(workspace.root, url, signal, tokenFor);
|
|
307
|
+
if (pushing) {
|
|
308
|
+
await transport.push(target, pushRef, [...(tagPush ? [] : ['--set-upstream']), '--no-follow-tags']);
|
|
309
|
+
}
|
|
310
|
+
else if (input.operation === 'fetch')
|
|
311
|
+
await transport.fetch(target, '+refs/heads/*:refs/remotes/' + target + '/*', ['--no-tags']);
|
|
312
|
+
else {
|
|
313
|
+
if (workspace.hasDirtyFiles || state.files.length)
|
|
314
|
+
throw new Error('拉取前请先保存草稿并提交修改');
|
|
315
|
+
await transport.fetch(target, ref, ['--no-tags']);
|
|
316
|
+
if (workspace.hasDirtyFiles || (await status(git)).files.length)
|
|
317
|
+
throw new Error('下载期间有修改,请先保存并提交');
|
|
318
|
+
await git.merge(['--ff-only', 'FETCH_HEAD']);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else
|
|
322
|
+
throw new Error('不支持的 Git 操作');
|
|
323
|
+
return status(git);
|
|
324
|
+
}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
export declare const referenceTopics: readonly ['species', 'skills', 'marks', 'team', 'environment', 'descriptions', 'effects'];
|
|
1
|
+
export declare const referenceTopics: readonly ['species', 'skills', 'marks', 'team', 'environment', 'descriptions', 'effects', 'git', 'release'];
|
|
2
2
|
/** Discover installed SDK contracts, without importing a content project's executable effects. */
|
|
3
3
|
export declare function authorReference({ topic }?: {
|
|
4
4
|
topic?: string;
|
|
5
5
|
}): Promise<{
|
|
6
|
+
topic: string;
|
|
7
|
+
title: string;
|
|
8
|
+
source: string;
|
|
9
|
+
instructions: string;
|
|
10
|
+
stage?: undefined;
|
|
11
|
+
schema?: undefined;
|
|
12
|
+
tags?: undefined;
|
|
13
|
+
examples?: undefined;
|
|
14
|
+
notes?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
instructions?: undefined;
|
|
6
17
|
topic: string;
|
|
7
18
|
title: string;
|
|
8
19
|
source: string;
|
|
@@ -17,6 +28,7 @@ export declare function authorReference({ topic }?: {
|
|
|
17
28
|
notes: string[];
|
|
18
29
|
tags?: undefined;
|
|
19
30
|
} | {
|
|
31
|
+
instructions?: undefined;
|
|
20
32
|
topic: string;
|
|
21
33
|
title: string;
|
|
22
34
|
source: string;
|
|
@@ -35,6 +47,7 @@ export declare function authorReference({ topic }?: {
|
|
|
35
47
|
notes: string[];
|
|
36
48
|
tags?: undefined;
|
|
37
49
|
} | {
|
|
50
|
+
instructions?: undefined;
|
|
38
51
|
stage?: undefined;
|
|
39
52
|
schema?: undefined;
|
|
40
53
|
topic: string;
|
|
@@ -47,6 +60,7 @@ export declare function authorReference({ topic }?: {
|
|
|
47
60
|
notes: string[];
|
|
48
61
|
tags?: undefined;
|
|
49
62
|
} | {
|
|
63
|
+
instructions?: undefined;
|
|
50
64
|
stage?: undefined;
|
|
51
65
|
schema?: undefined;
|
|
52
66
|
topic: string;
|
package/dist/author-reference.js
CHANGED
|
@@ -5,7 +5,17 @@ import { teamEnvelopeSchema, portablePetSchema } from './project-teams.js';
|
|
|
5
5
|
import { EnvironmentDocumentSchema } from './debug-environments.js';
|
|
6
6
|
import { WorkspaceError } from './workspace.js';
|
|
7
7
|
import { errorCode } from './types.js';
|
|
8
|
-
export const referenceTopics = [
|
|
8
|
+
export const referenceTopics = [
|
|
9
|
+
'species',
|
|
10
|
+
'skills',
|
|
11
|
+
'marks',
|
|
12
|
+
'team',
|
|
13
|
+
'environment',
|
|
14
|
+
'descriptions',
|
|
15
|
+
'effects',
|
|
16
|
+
'git',
|
|
17
|
+
'release',
|
|
18
|
+
];
|
|
9
19
|
const parserSchemas = {
|
|
10
20
|
species: NativeSpeciesSchema,
|
|
11
21
|
skills: NativeSkillSchema,
|
|
@@ -30,6 +40,15 @@ async function template(file) {
|
|
|
30
40
|
export async function authorReference({ topic } = {}) {
|
|
31
41
|
if (!topic || !referenceTopics.includes(topic))
|
|
32
42
|
throw new WorkspaceError('REFERENCE_UNKNOWN', '请选择有效的作者参考主题');
|
|
43
|
+
if (topic === 'git' || topic === 'release') {
|
|
44
|
+
const source = `skills/arcadia-content-${topic}/SKILL.md`;
|
|
45
|
+
return {
|
|
46
|
+
topic,
|
|
47
|
+
title: topic === 'git' ? '提交与同步内容包' : '发布内容包',
|
|
48
|
+
source,
|
|
49
|
+
instructions: await template(source),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
33
52
|
if (parserSchemas[topic]) {
|
|
34
53
|
return {
|
|
35
54
|
topic,
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ const help = `arcadia-content <command>
|
|
|
11
11
|
rename Change package/project/namespace identities and local references
|
|
12
12
|
demo Run the battle configured in arcadia.config.mjs
|
|
13
13
|
preview Prepare a local candidate for the full battle client; stop with Ctrl+C
|
|
14
|
-
pack
|
|
14
|
+
pack [--release] Build a content archive; --release verifies a distributable in a clean consumer
|
|
15
15
|
setup Install the pinned development SDK and tool
|
|
16
16
|
workspace <directory> <operation> [--execute] Structured author operations
|
|
17
17
|
`;
|
|
@@ -54,7 +54,8 @@ try {
|
|
|
54
54
|
else if (command === 'rename')
|
|
55
55
|
await run(process.execPath, [siblingModulePath('rename'), ...args]);
|
|
56
56
|
else {
|
|
57
|
-
if (!['check', 'build', 'demo', 'preview', 'pack'].includes(command) ||
|
|
57
|
+
if (!['check', 'build', 'demo', 'preview', 'pack'].includes(command) ||
|
|
58
|
+
(args.length && !(command === 'pack' && args.length === 1 && args[0] === '--release')))
|
|
58
59
|
throw new Error(`Unknown command or option.\n${help}`);
|
|
59
60
|
if (command === 'check') {
|
|
60
61
|
await data(true);
|
|
@@ -69,9 +70,9 @@ try {
|
|
|
69
70
|
else {
|
|
70
71
|
await build();
|
|
71
72
|
const { packBuiltProject } = await import('./pack-project.js');
|
|
72
|
-
const packed = await packBuiltProject();
|
|
73
|
+
const packed = await packBuiltProject(process.cwd(), { release: args[0] === '--release' });
|
|
73
74
|
console.log(`Packed ${packed.filename}`);
|
|
74
|
-
console.log(`ARCADIA_RESULT=${JSON.stringify({ filename: packed.filename, integrity: packed.integrity, shasum: packed.shasum, files: packed.files.map((file) => file.path) })}`);
|
|
75
|
+
console.log(`ARCADIA_RESULT=${JSON.stringify({ ...(args[0] === '--release' ? { verifiedRelease: true } : {}), filename: packed.filename, integrity: packed.integrity, shasum: packed.shasum, files: packed.files.map((file) => file.path) })}`);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
}
|
package/dist/content-query.d.ts
CHANGED
|
@@ -19,12 +19,26 @@ export interface QueryOptions {
|
|
|
19
19
|
namespace?: string;
|
|
20
20
|
packageName?: string;
|
|
21
21
|
}
|
|
22
|
+
type QueryDiagnostic = Record<string, unknown> & {
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
export interface DependencyReference {
|
|
26
|
+
projectId: string;
|
|
27
|
+
packageName: string;
|
|
28
|
+
kind: 'skills' | 'marks';
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function dependencyReferences(workspace: AuthorWorkspace, locale: string): Promise<{
|
|
33
|
+
items: DependencyReference[];
|
|
34
|
+
diagnostics: string[];
|
|
35
|
+
}>;
|
|
22
36
|
/** Read-only discovery over disk data. Never loads effects or changes workbench selection/drafts. */
|
|
23
37
|
export declare function queryContent(workspace: AuthorWorkspace, input?: UnknownRecord): Promise<{
|
|
24
38
|
total: number;
|
|
25
39
|
offset: number;
|
|
26
40
|
nextOffset: number | null;
|
|
27
41
|
items: unknown[];
|
|
28
|
-
diagnostics:
|
|
42
|
+
diagnostics: QueryDiagnostic[];
|
|
29
43
|
}>;
|
|
30
44
|
export {};
|