@arcadia-eternity/content-sdk 4.3.4 → 4.4.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.
Files changed (121) hide show
  1. package/README.md +3 -3
  2. package/bin/arcadia-content-mcp.mjs +2 -0
  3. package/bin/arcadia-content.mjs +2 -0
  4. package/dist/asset-inspect.d.ts +30 -0
  5. package/dist/asset-inspect.js +84 -0
  6. package/dist/author-api.d.ts +48 -0
  7. package/dist/author-api.js +128 -0
  8. package/dist/author-reference.d.ts +61 -0
  9. package/dist/author-reference.js +130 -0
  10. package/dist/build-content.d.ts +2 -0
  11. package/dist/build-content.js +29 -0
  12. package/dist/cli.d.ts +2 -0
  13. package/dist/cli.js +81 -0
  14. package/dist/content-query.d.ts +30 -0
  15. package/dist/content-query.js +326 -0
  16. package/dist/content-workspace.d.ts +204 -0
  17. package/dist/content-workspace.js +981 -0
  18. package/dist/debug-environments.d.ts +96 -0
  19. package/dist/debug-environments.js +135 -0
  20. package/dist/demo.d.ts +1 -0
  21. package/dist/demo.js +18 -0
  22. package/dist/effect-build.d.ts +3 -0
  23. package/dist/effect-build.js +44 -0
  24. package/dist/environment-rules.d.ts +7 -0
  25. package/dist/environment-rules.js +94 -0
  26. package/dist/environment.d.ts +48 -0
  27. package/dist/environment.js +184 -0
  28. package/dist/job-journal.d.ts +19 -0
  29. package/dist/job-journal.js +110 -0
  30. package/dist/jobs.d.ts +103 -0
  31. package/dist/jobs.js +626 -0
  32. package/dist/lib/content.d.ts +24 -0
  33. package/dist/lib/content.js +106 -0
  34. package/dist/lib/presentation.d.ts +26 -0
  35. package/dist/lib/presentation.js +252 -0
  36. package/dist/lib/yaml-sharing.d.ts +16 -0
  37. package/dist/lib/yaml-sharing.js +130 -0
  38. package/dist/managed-projects.d.ts +37 -0
  39. package/dist/managed-projects.js +305 -0
  40. package/dist/managed-sources.d.ts +28 -0
  41. package/dist/managed-sources.js +541 -0
  42. package/dist/mcp-contracts.d.ts +420 -0
  43. package/dist/mcp-contracts.js +146 -0
  44. package/dist/mcp.d.ts +2 -0
  45. package/dist/mcp.js +228 -0
  46. package/dist/module-path.d.ts +1 -0
  47. package/dist/module-path.js +8 -0
  48. package/dist/pack-project.d.ts +10 -0
  49. package/dist/pack-project.js +178 -0
  50. package/dist/preview-control.d.ts +17 -0
  51. package/dist/preview-control.js +273 -0
  52. package/dist/preview.d.ts +24 -0
  53. package/dist/preview.js +332 -0
  54. package/dist/project-teams.d.ts +51 -0
  55. package/dist/project-teams.js +106 -0
  56. package/dist/project.d.ts +18 -0
  57. package/dist/project.js +146 -0
  58. package/dist/rename.d.ts +2 -0
  59. package/dist/rename.js +128 -0
  60. package/dist/setup.d.ts +2 -0
  61. package/dist/setup.js +117 -0
  62. package/dist/source-lock.d.ts +9 -0
  63. package/dist/source-lock.js +117 -0
  64. package/dist/template/README.md +2 -0
  65. package/dist/template/docs/presentation.md +3 -3
  66. package/dist/template/package.json +3 -7
  67. package/dist/template/test/pack.test.mjs +10 -7
  68. package/dist/testing.d.ts +58 -0
  69. package/dist/testing.js +205 -0
  70. package/dist/types.d.ts +5 -0
  71. package/dist/types.js +14 -0
  72. package/dist/workbench-context.d.ts +10 -0
  73. package/dist/workbench-context.js +27 -0
  74. package/dist/workspace-cli.d.ts +1 -0
  75. package/dist/workspace-cli.js +66 -0
  76. package/dist/workspace-materials.d.ts +19 -0
  77. package/dist/workspace-materials.js +165 -0
  78. package/dist/workspace.d.ts +190 -0
  79. package/dist/workspace.js +726 -0
  80. package/package.json +34 -27
  81. package/dist/asset-inspect.mjs +0 -67
  82. package/dist/author-api.mjs +0 -112
  83. package/dist/author-reference.mjs +0 -121
  84. package/dist/build-content.mjs +0 -30
  85. package/dist/cli.mjs +0 -76
  86. package/dist/content-query.mjs +0 -283
  87. package/dist/content-workspace.d.mts +0 -161
  88. package/dist/content-workspace.mjs +0 -936
  89. package/dist/debug-environments.mjs +0 -154
  90. package/dist/demo.mjs +0 -22
  91. package/dist/effect-build.d.mts +0 -2
  92. package/dist/effect-build.mjs +0 -46
  93. package/dist/environment-rules.d.mts +0 -5
  94. package/dist/environment-rules.mjs +0 -92
  95. package/dist/environment.mjs +0 -183
  96. package/dist/job-journal.mjs +0 -94
  97. package/dist/jobs.mjs +0 -579
  98. package/dist/lib/content.mjs +0 -95
  99. package/dist/lib/presentation.mjs +0 -240
  100. package/dist/lib/yaml-sharing.mjs +0 -101
  101. package/dist/managed-projects.d.mts +0 -35
  102. package/dist/managed-projects.mjs +0 -303
  103. package/dist/managed-sources.d.mts +0 -19
  104. package/dist/managed-sources.mjs +0 -503
  105. package/dist/mcp-contracts.mjs +0 -153
  106. package/dist/mcp.mjs +0 -369
  107. package/dist/pack-project.mjs +0 -157
  108. package/dist/preview-control.mjs +0 -260
  109. package/dist/preview.mjs +0 -313
  110. package/dist/project-teams.mjs +0 -98
  111. package/dist/project.mjs +0 -140
  112. package/dist/rename.mjs +0 -112
  113. package/dist/setup.mjs +0 -134
  114. package/dist/source-lock.mjs +0 -103
  115. package/dist/testing.mjs +0 -204
  116. package/dist/workbench-context.mjs +0 -18
  117. package/dist/workspace-cli.mjs +0 -60
  118. package/dist/workspace-materials.mjs +0 -153
  119. package/dist/workspace.mjs +0 -684
  120. /package/dist/{index.d.mts → index.d.ts} +0 -0
  121. /package/dist/{index.mjs → index.js} +0 -0
@@ -0,0 +1,165 @@
1
+ import { lstat, mkdir, readFile, readdir, realpath, writeFile } from 'node:fs/promises';
2
+ import { dirname, isAbsolute, join, relative } from 'node:path';
3
+ import { errorCode, isRecord } from './types.js';
4
+ export function contentError(code, message = code) {
5
+ return Object.assign(new Error(message), { code });
6
+ }
7
+ const materialRoots = new Set(['package.json', 'package-lock.json', 'node_modules', 'candidates']);
8
+ const forbidden = new Set(['.git', '.env', '.npmrc', '.arcadia', '.bin']);
9
+ function checkedMaterialPath(value) {
10
+ if (typeof value !== 'string' || !value || value.includes('\\') || value.includes('\0') || isAbsolute(value))
11
+ throw contentError('MATERIAL_PATH_INVALID');
12
+ const parts = value.split('/');
13
+ if (parts.some(part => !part ||
14
+ part === '.' ||
15
+ part === '..' ||
16
+ forbidden.has(part) ||
17
+ /[<>:"|?*]/.test(part) ||
18
+ [...part].some(character => (character.codePointAt(0) ?? 0) < 32) ||
19
+ /[. ]$/.test(part) ||
20
+ /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part)) ||
21
+ !materialRoots.has(parts[0]))
22
+ throw contentError('MATERIAL_PATH_INVALID');
23
+ return value;
24
+ }
25
+ /** Capture data bytes only. Symlink targets must remain inside the installed project. */
26
+ export async function materialFiles(root, { signal, maxBytes = 256 * 1024 * 1024, maxFiles = 50000, onRead, } = {}) {
27
+ root = await realpath(root);
28
+ const result = [];
29
+ const captured = [];
30
+ let total = 0;
31
+ async function walk(path, name, ancestors = new Set()) {
32
+ signal?.throwIfAborted();
33
+ const actual = await realpath(path);
34
+ const rel = relative(root, actual);
35
+ if (isAbsolute(rel) || rel === '..' || rel.startsWith('../'))
36
+ throw contentError('MATERIAL_PATH_ESCAPE');
37
+ checkedMaterialPath(rel.split('\\').join('/'));
38
+ const info = await lstat(actual);
39
+ captured.push({ path, actual, size: info.size, mtimeMs: info.mtimeMs, ino: info.ino });
40
+ if (info.isDirectory()) {
41
+ if (ancestors.has(actual))
42
+ throw contentError('MATERIAL_PATH_CYCLE');
43
+ const next = new Set(ancestors).add(actual);
44
+ for (const child of (await readdir(actual)).sort()) {
45
+ if (forbidden.has(child))
46
+ continue;
47
+ await walk(join(actual, child), name ? `${name}/${child}` : child, next);
48
+ }
49
+ const after = await lstat(actual);
50
+ if (info.ino !== after.ino || info.mtimeMs !== after.mtimeMs || info.ctimeMs !== after.ctimeMs)
51
+ throw contentError('MATERIAL_SOURCE_CHANGED');
52
+ onRead?.(actual, after);
53
+ return;
54
+ }
55
+ if (!info.isFile())
56
+ throw contentError('MATERIAL_FILE_INVALID');
57
+ checkedMaterialPath(name);
58
+ total += info.size;
59
+ if (total > maxBytes || result.length >= maxFiles)
60
+ throw contentError('MATERIAL_LIMIT');
61
+ const bytes = await readFile(actual);
62
+ const after = await lstat(actual);
63
+ if (info.size !== bytes.length ||
64
+ info.mtimeMs !== after.mtimeMs ||
65
+ info.ctimeMs !== after.ctimeMs ||
66
+ info.ino !== after.ino)
67
+ throw contentError('MATERIAL_SOURCE_CHANGED');
68
+ onRead?.(actual, after);
69
+ result.push({ path: name, bytes });
70
+ }
71
+ for (const name of materialRoots) {
72
+ try {
73
+ await lstat(join(root, name));
74
+ }
75
+ catch (error) {
76
+ if (errorCode(error) === 'ENOENT' && name !== 'package.json' && name !== 'package-lock.json')
77
+ continue;
78
+ throw error;
79
+ }
80
+ try {
81
+ await walk(join(root, name), name);
82
+ }
83
+ catch (error) {
84
+ if (errorCode(error) === 'ENOENT')
85
+ throw contentError('MATERIAL_SOURCE_CHANGED');
86
+ throw error;
87
+ }
88
+ }
89
+ // Verify the whole captured tree after the last read. This detects membership
90
+ // changes and retargeted links without a separate content-hash protocol.
91
+ for (const entry of captured) {
92
+ signal?.throwIfAborted();
93
+ try {
94
+ if ((await realpath(entry.path)) !== entry.actual)
95
+ throw contentError('MATERIAL_SOURCE_CHANGED');
96
+ const info = await lstat(entry.actual);
97
+ if (entry.size !== info.size || entry.mtimeMs !== info.mtimeMs || entry.ino !== info.ino)
98
+ throw contentError('MATERIAL_SOURCE_CHANGED');
99
+ }
100
+ catch (error) {
101
+ if (errorCode(error) === 'ENOENT')
102
+ throw contentError('MATERIAL_SOURCE_CHANGED');
103
+ throw error;
104
+ }
105
+ }
106
+ return result;
107
+ }
108
+ export async function writeMaterials(root, files, { signal, maxBytes = 256 * 1024 * 1024, maxFiles = 50000, } = {}) {
109
+ if (!Array.isArray(files) || files.length > maxFiles)
110
+ throw contentError('MATERIAL_LIMIT');
111
+ const seen = new Set();
112
+ let total = 0;
113
+ for (const file of files) {
114
+ if (!isRecord(file))
115
+ throw contentError('MATERIAL_PATH_INVALID');
116
+ signal?.throwIfAborted();
117
+ const path = checkedMaterialPath(file.path);
118
+ // Case aliases are rejected even on case-sensitive machines for portable archives.
119
+ const alias = path.toLowerCase();
120
+ if (seen.has(alias))
121
+ throw contentError('MATERIAL_PATH_DUPLICATE');
122
+ seen.add(alias);
123
+ const data = typeof file.data === 'string' ? file.data : undefined;
124
+ if (!Buffer.isBuffer(file.bytes) && data === undefined)
125
+ throw contentError('MATERIAL_ENCODING_INVALID');
126
+ if (!Buffer.isBuffer(file.bytes) &&
127
+ data !== undefined &&
128
+ !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data))
129
+ throw contentError('MATERIAL_ENCODING_INVALID');
130
+ const bytes = Buffer.isBuffer(file.bytes) ? file.bytes : Buffer.from(data, 'base64');
131
+ total += bytes.length;
132
+ if (total > maxBytes)
133
+ throw contentError('MATERIAL_LIMIT');
134
+ await mkdir(dirname(join(root, path)), { recursive: true });
135
+ await writeFile(join(root, path), bytes, { flag: 'wx', mode: 0o600 });
136
+ }
137
+ if (!seen.has('package.json') || !seen.has('package-lock.json'))
138
+ throw contentError('MATERIAL_LOCK_REQUIRED');
139
+ // npm may omit this directory for a valid empty dependency graph. Static npm
140
+ // inspection still expects it, including after a file-only archive round trip.
141
+ await mkdir(join(root, 'node_modules'), { recursive: true });
142
+ const lock = JSON.parse(await readFile(join(root, 'package-lock.json'), 'utf8'));
143
+ if (![2, 3].includes(lock.lockfileVersion) || !lock.packages || typeof lock.packages !== 'object')
144
+ throw contentError('MATERIAL_LOCK_INVALID');
145
+ for (const pkgValue of Object.values(lock.packages)) {
146
+ if (!isRecord(pkgValue))
147
+ throw contentError('MATERIAL_LOCK_INVALID');
148
+ const pkg = pkgValue;
149
+ if (pkg.link === true)
150
+ throw contentError('MATERIAL_LOCK_NOT_PORTABLE');
151
+ if (typeof pkg.resolved === 'string' && /^https?:/.test(pkg.resolved)) {
152
+ const url = new URL(pkg.resolved);
153
+ if (url.username ||
154
+ url.password ||
155
+ [...url.searchParams.keys()].some(key => /token|secret|password|credential|authorization/i.test(key)))
156
+ throw contentError('MATERIAL_LOCK_CREDENTIALS');
157
+ }
158
+ if (typeof pkg.resolved === 'string' && pkg.resolved.startsWith('file:')) {
159
+ const path = pkg.resolved.slice(5);
160
+ if (!path.startsWith('candidates/'))
161
+ throw contentError('MATERIAL_LOCK_NOT_PORTABLE');
162
+ checkedMaterialPath(path);
163
+ }
164
+ }
165
+ }
@@ -0,0 +1,190 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import type { SharedField } from './lib/yaml-sharing.js';
3
+ export interface ManifestArcadia {
4
+ projectId?: string;
5
+ namespace?: string;
6
+ content?: string;
7
+ presentation?: string;
8
+ sdkApi?: string;
9
+ [key: string]: unknown;
10
+ }
11
+ export interface PackageManifest {
12
+ name?: string;
13
+ version?: string;
14
+ arcadia?: ManifestArcadia;
15
+ [key: string]: unknown;
16
+ }
17
+ export interface SourceRecord {
18
+ id: string;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface Diagnostic {
22
+ code: string;
23
+ severity: string;
24
+ message: string;
25
+ file?: string;
26
+ }
27
+ export interface WorkspaceFile {
28
+ file: string;
29
+ size?: number;
30
+ modified?: number;
31
+ error?: string;
32
+ }
33
+ export interface SourceLocation {
34
+ line: number;
35
+ column: number;
36
+ }
37
+ export interface WorkspaceRecord {
38
+ kind: string;
39
+ record: SourceRecord;
40
+ file: string;
41
+ version: string;
42
+ index: number | null;
43
+ sharedFields: SharedField[];
44
+ line?: number;
45
+ column?: number;
46
+ }
47
+ export interface WorkspaceAsset {
48
+ id: string;
49
+ file?: unknown;
50
+ definition: string;
51
+ kind?: unknown;
52
+ name?: unknown;
53
+ size?: number;
54
+ modified?: number;
55
+ error?: string;
56
+ references: Array<{
57
+ file: string;
58
+ kind: string;
59
+ id: string;
60
+ }>;
61
+ }
62
+ export interface WorkspaceLocaleSource {
63
+ file: string;
64
+ version: string;
65
+ language: string;
66
+ namespace: string;
67
+ entries: unknown;
68
+ sharedFields: SharedField[];
69
+ locations?: Record<string, SourceLocation>;
70
+ }
71
+ export interface WorkspaceCapabilities {
72
+ sourceEditing: boolean;
73
+ structuredSaving: boolean;
74
+ localeEditing: boolean;
75
+ yamlSharing: string;
76
+ externalEditor: boolean;
77
+ kinds: readonly string[];
78
+ sdkApi: unknown;
79
+ }
80
+ export interface WorkspaceSnapshot {
81
+ protocolVersion: number;
82
+ root: string;
83
+ project: ManifestArcadia;
84
+ name: string | undefined;
85
+ version: string | undefined;
86
+ records: WorkspaceRecord[];
87
+ files: WorkspaceFile[];
88
+ assets: WorkspaceAsset[];
89
+ locales: Record<string, unknown>;
90
+ localeSources: WorkspaceLocaleSource[];
91
+ diagnostics: Diagnostic[];
92
+ capabilities: WorkspaceCapabilities;
93
+ }
94
+ export interface WorkspaceOptions {
95
+ watch?: boolean;
96
+ readOnly?: boolean;
97
+ published?: boolean;
98
+ }
99
+ export interface WriteInput {
100
+ file: string;
101
+ expectedVersion: string | null;
102
+ text: string;
103
+ }
104
+ export interface RemoveInput {
105
+ file: string;
106
+ expectedVersion: string | null;
107
+ }
108
+ export interface SaveRecordInput {
109
+ file: string;
110
+ expectedVersion: string | null;
111
+ index?: number | null;
112
+ record: unknown;
113
+ }
114
+ export interface WorkspaceChange {
115
+ kind: 'record' | 'locale' | 'create-record';
116
+ file: string;
117
+ expectedVersion?: string | null;
118
+ record?: unknown;
119
+ index?: number | null;
120
+ id?: string;
121
+ }
122
+ export interface SaveChangesInput {
123
+ changes: WorkspaceChange[];
124
+ }
125
+ export interface SaveResult {
126
+ file: string;
127
+ saved: boolean;
128
+ version?: string;
129
+ diagnostic?: Diagnostic;
130
+ }
131
+ export declare class WorkspaceError extends Error {
132
+ code: string;
133
+ file?: string;
134
+ constructor(code: string, message: string, file?: string);
135
+ }
136
+ export declare function diagnostic(error: unknown): Diagnostic;
137
+ /** Ordinary source files are authoritative. No project database or generated-output writes. */
138
+ export declare class AuthorWorkspace extends EventEmitter {
139
+ #private;
140
+ root: string;
141
+ published: boolean;
142
+ readOnly: boolean;
143
+ baseProject?: ManifestArcadia & {
144
+ projectId: string;
145
+ namespace: string;
146
+ };
147
+ constructor(root: string);
148
+ static open(directory: string, { watch, readOnly, published }?: WorkspaceOptions): Promise<AuthorWorkspace>;
149
+ assertWritable(): Promise<void>;
150
+ path(file: string, { create }?: {
151
+ create?: boolean;
152
+ }): Promise<string>;
153
+ read(file: string): Promise<{
154
+ file: string;
155
+ text: string;
156
+ version: string;
157
+ }>;
158
+ files(): Promise<WorkspaceFile[]>;
159
+ revision({ contentOnly, excludeFile, }?: {
160
+ contentOnly?: boolean;
161
+ excludeFile?: string;
162
+ }): Promise<string>;
163
+ snapshot(): Promise<WorkspaceSnapshot>;
164
+ setDirty(file: string, dirty: boolean): void;
165
+ clearDirty(): void;
166
+ asset(file: string): Promise<{
167
+ file: string;
168
+ bytes: Buffer;
169
+ version: string;
170
+ }>;
171
+ write({ file, expectedVersion, text }: WriteInput, { fromForm }?: {
172
+ fromForm?: boolean;
173
+ }): Promise<{
174
+ file: string;
175
+ version: string;
176
+ }>;
177
+ remove({ file, expectedVersion }: RemoveInput): Promise<void>;
178
+ saveRecord({ file, expectedVersion, index, record, }: SaveRecordInput): Promise<{
179
+ file: string;
180
+ version?: string;
181
+ }>;
182
+ /** Prepare the whole review first; commit each source once, reporting partial writes explicitly. */
183
+ saveChanges({ changes }: SaveChangesInput, { fromForm }?: {
184
+ fromForm?: boolean;
185
+ }): Promise<{
186
+ results: SaveResult[];
187
+ complete: boolean;
188
+ }>;
189
+ close(): Promise<void>;
190
+ }