@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,110 @@
1
+ import { mkdir, readdir, readFile, rm, lstat } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import writeFileAtomic from 'write-file-atomic';
4
+ import { errorCode, isRecord } from './types.js';
5
+ const idPattern = /^[a-f0-9-]{36}$/;
6
+ /** Local task receipts and cancellation requests are never part of a content package. */
7
+ export class JobJournal {
8
+ directory;
9
+ #last = new Map();
10
+ constructor(root) {
11
+ this.directory = join(root, '.arcadia', 'author-jobs');
12
+ }
13
+ file(id, suffix = 'json') {
14
+ if (!idPattern.test(id))
15
+ throw new Error('TASK_INVALID');
16
+ return join(this.directory, `${id}.${suffix}`);
17
+ }
18
+ async save(job, live) {
19
+ const text = JSON.stringify({ pid: process.pid, live, job });
20
+ if (this.#last.get(job.jobId) === text)
21
+ return;
22
+ await mkdir(this.directory, { recursive: true });
23
+ await writeFileAtomic(this.file(job.jobId), text, { mode: 0o600 });
24
+ this.#last.set(job.jobId, text);
25
+ }
26
+ async read() {
27
+ let names;
28
+ try {
29
+ names = await readdir(this.directory);
30
+ }
31
+ catch (error) {
32
+ if (errorCode(error) === 'ENOENT')
33
+ return [];
34
+ throw error;
35
+ }
36
+ const records = [];
37
+ for (const name of names.filter(name => idPattern.test(name.slice(0, -5)) && name.endsWith('.json'))) {
38
+ const file = join(this.directory, name);
39
+ let info;
40
+ try {
41
+ info = await lstat(file);
42
+ }
43
+ catch (error) {
44
+ if (errorCode(error) === 'ENOENT')
45
+ continue;
46
+ throw error;
47
+ }
48
+ if (!info.isFile() || info.isSymbolicLink() || info.size > 2 * 1024 * 1024)
49
+ continue;
50
+ let receipt;
51
+ try {
52
+ receipt = JSON.parse(await readFile(file, 'utf8'));
53
+ }
54
+ catch (error) {
55
+ if (error instanceof SyntaxError || errorCode(error) === 'ENOENT')
56
+ continue;
57
+ throw error;
58
+ }
59
+ if (!isRecord(receipt) || !isRecord(receipt.job))
60
+ continue;
61
+ const job = receipt.job;
62
+ if (typeof job.jobId !== 'string' ||
63
+ `${job.jobId}.json` !== name ||
64
+ typeof receipt.pid !== 'number' ||
65
+ !Number.isInteger(receipt.pid) ||
66
+ receipt.pid <= 0 ||
67
+ !Array.isArray(job.diagnostics))
68
+ continue;
69
+ const live = receipt.live === true;
70
+ const state = typeof job.state === 'string' ? job.state : '';
71
+ if (live || ['queued', 'running'].includes(state)) {
72
+ try {
73
+ process.kill(receipt.pid, 0);
74
+ }
75
+ catch (error) {
76
+ if (errorCode(error) === 'ESRCH') {
77
+ job.state = 'interrupted';
78
+ job.diagnostics.push({
79
+ code: 'TASK_INTERRUPTED',
80
+ message: '任务宿主已退出;请重新运行。源项目和已安装版本保留。',
81
+ });
82
+ }
83
+ }
84
+ }
85
+ records.push({ pid: receipt.pid, live, job: job });
86
+ }
87
+ const ordered = records.sort((a, b) => (a.job.createdAt ?? 0) - (b.job.createdAt ?? 0));
88
+ const active = (receipt) => receipt.live || ['queued', 'running'].includes(receipt.job.state);
89
+ const history = new Set(ordered.filter(receipt => !active(receipt)).slice(-30));
90
+ return ordered.filter(receipt => active(receipt) || history.has(receipt));
91
+ }
92
+ async requestCancel(id) {
93
+ await writeFileAtomic(this.file(id, 'cancel'), '', { mode: 0o600 });
94
+ }
95
+ async cancelled(id) {
96
+ try {
97
+ await lstat(this.file(id, 'cancel'));
98
+ return true;
99
+ }
100
+ catch (error) {
101
+ if (errorCode(error) === 'ENOENT')
102
+ return false;
103
+ throw error;
104
+ }
105
+ }
106
+ async remove(id) {
107
+ await Promise.all(['json', 'cancel'].map(suffix => rm(this.file(id, suffix), { force: true })));
108
+ this.#last.delete(id);
109
+ }
110
+ }
package/dist/jobs.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { AuthorWorkspace } from './workspace.js';
2
+ interface JobDiagnostic {
3
+ code: string;
4
+ severity?: string;
5
+ message: string;
6
+ file?: string;
7
+ line?: number;
8
+ column?: number;
9
+ }
10
+ interface JobResult {
11
+ preview?: {
12
+ endpoint: string;
13
+ clientPath: string;
14
+ url?: string;
15
+ };
16
+ environmentLock?: {
17
+ file: string;
18
+ version: string;
19
+ };
20
+ sourceRevisions?: Record<string, string>;
21
+ files?: unknown[];
22
+ [key: string]: unknown;
23
+ }
24
+ export interface Job {
25
+ jobId: string;
26
+ kind: string;
27
+ sourceRevision: string;
28
+ contentRevision: string;
29
+ environmentId: string;
30
+ preparationRevision: string;
31
+ state: string;
32
+ phase: string;
33
+ stale: boolean;
34
+ output: string;
35
+ outputCursor: number;
36
+ diagnostics: JobDiagnostic[];
37
+ createdAt: number;
38
+ finishedAt?: string;
39
+ result?: JobResult;
40
+ }
41
+ /** Fixed author commands; no renderer or MCP-provided executable strings. */
42
+ export declare class AuthorJobs {
43
+ #private;
44
+ workspace: AuthorWorkspace;
45
+ execute: boolean;
46
+ env: Record<string, string>;
47
+ executable: string;
48
+ constructor(workspace: AuthorWorkspace, { execute, env, executable, }?: {
49
+ execute?: boolean;
50
+ env?: NodeJS.ProcessEnv;
51
+ executable?: string;
52
+ });
53
+ get closed(): boolean;
54
+ get hasLivePreviews(): boolean;
55
+ initialize(): Promise<void>;
56
+ refresh(): Promise<void>;
57
+ start({ kind, sourceRevision, environmentId, }: {
58
+ kind: string;
59
+ sourceRevision?: string;
60
+ environmentId?: string;
61
+ }): Promise<Job>;
62
+ get(jobId: string): Job;
63
+ list(): Job[];
64
+ /** Compact task discovery; listing never switches or replaces a desktop preview. */
65
+ queryJobs({ offset, limit, state, kind, }?: {
66
+ offset?: number;
67
+ limit?: number;
68
+ state?: string;
69
+ kind?: string;
70
+ }): Promise<{
71
+ total: number;
72
+ offset: number;
73
+ nextOffset: number | null;
74
+ items: Record<string, unknown>[];
75
+ }>;
76
+ /** Wait for changes without repeatedly hashing every project file. */
77
+ queryJob({ jobId, waitMs, afterCursor, includeOutput, limit, }: {
78
+ jobId: string;
79
+ waitMs?: number;
80
+ afterCursor?: number;
81
+ includeOutput?: boolean;
82
+ limit?: number;
83
+ }): Promise<Record<string, unknown>>;
84
+ readJobOutput({ jobId, cursor, limit }: {
85
+ jobId: string;
86
+ cursor?: number;
87
+ limit?: number;
88
+ }): Promise<{
89
+ jobId: string;
90
+ text: string;
91
+ cursor: number;
92
+ nextCursor: number;
93
+ endCursor: number;
94
+ truncated: boolean;
95
+ hasMore: boolean;
96
+ unit: string;
97
+ }>;
98
+ cancel(jobId: string): Job | Promise<Job>;
99
+ /** Stop previews owned by this host and wait for their processes and temporary files to be released. */
100
+ stopPreviews(): Promise<void>;
101
+ close(): Promise<void>;
102
+ }
103
+ export {};