@hagicode/hagiscript 0.1.5 → 0.1.6-dev.37.1.2e654a6

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -1
  3. package/bin/runtime +16 -0
  4. package/dist/cli.js +2 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/npm-sync-commands.js +2 -0
  7. package/dist/commands/npm-sync-commands.js.map +1 -1
  8. package/dist/commands/runtime-commands.d.ts +2 -0
  9. package/dist/commands/runtime-commands.js +136 -0
  10. package/dist/commands/runtime-commands.js.map +1 -0
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.js +4 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/runtime/command-launch.js +1 -0
  15. package/dist/runtime/command-launch.js.map +1 -1
  16. package/dist/runtime/npm-sync.d.ts +5 -1
  17. package/dist/runtime/npm-sync.js +6 -3
  18. package/dist/runtime/npm-sync.js.map +1 -1
  19. package/dist/runtime/runtime-executor.d.ts +27 -0
  20. package/dist/runtime/runtime-executor.js +86 -0
  21. package/dist/runtime/runtime-executor.js.map +1 -0
  22. package/dist/runtime/runtime-manager.d.ts +68 -0
  23. package/dist/runtime/runtime-manager.js +553 -0
  24. package/dist/runtime/runtime-manager.js.map +1 -0
  25. package/dist/runtime/runtime-manifest.d.ts +63 -0
  26. package/dist/runtime/runtime-manifest.js +231 -0
  27. package/dist/runtime/runtime-manifest.js.map +1 -0
  28. package/dist/runtime/runtime-paths.d.ts +24 -0
  29. package/dist/runtime/runtime-paths.js +62 -0
  30. package/dist/runtime/runtime-paths.js.map +1 -0
  31. package/dist/runtime/runtime-state.d.ts +43 -0
  32. package/dist/runtime/runtime-state.js +82 -0
  33. package/dist/runtime/runtime-state.js.map +1 -0
  34. package/package.json +9 -3
  35. package/runtime/lib/runtime-script-lib.mjs +103 -0
  36. package/runtime/manifest.yaml +122 -0
  37. package/runtime/scripts/configure-code-server.mjs +14 -0
  38. package/runtime/scripts/configure-omniroute.mjs +16 -0
  39. package/runtime/scripts/install-code-server.mjs +32 -0
  40. package/runtime/scripts/install-dotnet.mjs +24 -0
  41. package/runtime/scripts/install-node.mjs +4 -0
  42. package/runtime/scripts/install-npm-packages.mjs +4 -0
  43. package/runtime/scripts/install-omniroute.mjs +34 -0
  44. package/runtime/scripts/remove-npm-packages.mjs +4 -0
  45. package/runtime/scripts/update-npm-packages.mjs +4 -0
  46. package/runtime/scripts/verify-dotnet.mjs +10 -0
  47. package/runtime/scripts/verify-node.mjs +4 -0
  48. package/runtime/templates/code-server-config.yaml +5 -0
  49. package/runtime/templates/omniroute-config.yaml +4 -0
@@ -0,0 +1,231 @@
1
+ import { access, readFile } from "node:fs/promises";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { parse } from "yaml";
5
+ export class RuntimeManifestValidationError extends Error {
6
+ errors;
7
+ constructor(errors) {
8
+ super(`Runtime manifest validation failed: ${errors.join("; ")}`);
9
+ this.name = "RuntimeManifestValidationError";
10
+ this.errors = errors;
11
+ }
12
+ }
13
+ const supportedComponentTypes = new Set([
14
+ "runtime",
15
+ "package",
16
+ "bundled-runtime"
17
+ ]);
18
+ export function getPackageRoot(moduleUrl = import.meta.url) {
19
+ return resolve(dirname(fileURLToPath(moduleUrl)), "..", "..");
20
+ }
21
+ export function getDefaultRuntimeManifestPath(moduleUrl = import.meta.url) {
22
+ return join(getPackageRoot(moduleUrl), "runtime", "manifest.yaml");
23
+ }
24
+ export async function loadRuntimeManifest(options = {}) {
25
+ const manifestPath = resolve(options.manifestPath ?? getDefaultRuntimeManifestPath());
26
+ let parsed;
27
+ try {
28
+ parsed = parse(await readFile(manifestPath, "utf8"));
29
+ }
30
+ catch (error) {
31
+ const message = error instanceof Error ? error.message : String(error);
32
+ throw new RuntimeManifestValidationError([
33
+ `Failed to read runtime manifest ${manifestPath}: ${message}`
34
+ ]);
35
+ }
36
+ const manifest = validateRuntimeManifest(parsed, manifestPath);
37
+ for (const component of manifest.components) {
38
+ await validateRuntimeAssetExists(component.scripts.install);
39
+ for (const candidate of [
40
+ component.scripts.verify,
41
+ component.scripts.configure,
42
+ component.scripts.update,
43
+ component.scripts.remove
44
+ ]) {
45
+ if (!candidate) {
46
+ continue;
47
+ }
48
+ await validateRuntimeAssetExists(candidate);
49
+ }
50
+ }
51
+ return manifest;
52
+ }
53
+ export async function validateRuntimeAssetExists(pathValue) {
54
+ await access(pathValue);
55
+ }
56
+ function validateRuntimeManifest(value, manifestPath) {
57
+ const manifestDir = dirname(manifestPath);
58
+ const errors = [];
59
+ if (!isRecord(value)) {
60
+ throw new RuntimeManifestValidationError(["manifest must be a YAML object"]);
61
+ }
62
+ const runtimeObject = toRecord(value.runtime, "runtime", errors);
63
+ const pathsObject = toRecord(value.paths, "paths", errors);
64
+ const phasesObject = toRecord(value.phases, "phases", errors);
65
+ const componentValues = Array.isArray(value.components) ? value.components : null;
66
+ if (!componentValues) {
67
+ errors.push("components must be an array");
68
+ }
69
+ const runtime = {
70
+ name: readRequiredString(runtimeObject.name, "runtime.name", errors),
71
+ version: readRequiredString(runtimeObject.version, "runtime.version", errors)
72
+ };
73
+ const paths = {
74
+ runtimeRoot: readRequiredString(pathsObject.runtimeRoot, "paths.runtimeRoot", errors),
75
+ bin: readRequiredString(pathsObject.bin, "paths.bin", errors),
76
+ config: readRequiredString(pathsObject.config, "paths.config", errors),
77
+ logs: readRequiredString(pathsObject.logs, "paths.logs", errors),
78
+ data: readRequiredString(pathsObject.data, "paths.data", errors),
79
+ stateFile: readRequiredString(pathsObject.stateFile, "paths.stateFile", errors),
80
+ componentsRoot: readRequiredString(pathsObject.componentsRoot, "paths.componentsRoot", errors),
81
+ npmPrefix: readRequiredString(pathsObject.npmPrefix, "paths.npmPrefix", errors),
82
+ nodeRuntime: readRequiredString(pathsObject.nodeRuntime, "paths.nodeRuntime", errors),
83
+ dotnetRuntime: readRequiredString(pathsObject.dotnetRuntime, "paths.dotnetRuntime", errors),
84
+ vendoredRoot: readRequiredString(pathsObject.vendoredRoot, "paths.vendoredRoot", errors)
85
+ };
86
+ const phases = validateRuntimePhases(phasesObject, errors);
87
+ const components = validateRuntimeComponents(componentValues ?? [], manifestDir, errors);
88
+ const componentMap = new Map();
89
+ for (const component of components) {
90
+ if (componentMap.has(component.name)) {
91
+ errors.push(`components contains duplicate name ${component.name}`);
92
+ continue;
93
+ }
94
+ componentMap.set(component.name, component);
95
+ }
96
+ for (const [phaseName, definition] of Object.entries(phases)) {
97
+ for (const componentName of definition.order) {
98
+ if (!componentMap.has(componentName)) {
99
+ errors.push(`phases.${phaseName}.order references unknown component ${componentName}`);
100
+ }
101
+ }
102
+ }
103
+ if (errors.length > 0) {
104
+ throw new RuntimeManifestValidationError(errors);
105
+ }
106
+ return {
107
+ manifestPath,
108
+ manifestDir,
109
+ runtime,
110
+ components,
111
+ componentMap,
112
+ phases,
113
+ paths
114
+ };
115
+ }
116
+ function validateRuntimePhases(value, errors) {
117
+ return {
118
+ install: validateRuntimePhase(value.install, "install", errors),
119
+ remove: validateRuntimePhase(value.remove, "remove", errors),
120
+ update: validateRuntimePhase(value.update, "update", errors)
121
+ };
122
+ }
123
+ function validateRuntimePhase(value, phaseName, errors) {
124
+ const phaseObject = toRecord(value, `phases.${phaseName}`, errors);
125
+ const orderValue = phaseObject.order;
126
+ const order = Array.isArray(orderValue)
127
+ ? orderValue.filter((item) => typeof item === "string")
128
+ : [];
129
+ if (!Array.isArray(orderValue) || order.length !== orderValue.length || order.length === 0) {
130
+ errors.push(`phases.${phaseName}.order must be a non-empty string array`);
131
+ }
132
+ const reverseValue = phaseObject.reverse;
133
+ if (reverseValue !== undefined && typeof reverseValue !== "boolean") {
134
+ errors.push(`phases.${phaseName}.reverse must be a boolean when provided`);
135
+ }
136
+ return {
137
+ order,
138
+ reverse: reverseValue === true
139
+ };
140
+ }
141
+ function validateRuntimeComponents(values, manifestDir, errors) {
142
+ const components = [];
143
+ for (const [index, value] of values.entries()) {
144
+ const componentObject = toRecord(value, `components[${index}]`, errors);
145
+ const name = readRequiredString(componentObject.name, `components[${index}].name`, errors);
146
+ const rawType = readRequiredString(componentObject.type, `components[${index}].type`, errors);
147
+ if (!supportedComponentTypes.has(rawType)) {
148
+ errors.push(`components[${index}].type must be one of runtime, package, bundled-runtime`);
149
+ }
150
+ const installScript = readResolvedScript(componentObject.installScript, manifestDir, `components[${index}].installScript`, errors);
151
+ const verifyScript = readOptionalResolvedScript(componentObject.verifyScript, manifestDir, `components[${index}].verifyScript`, errors);
152
+ const configureScript = readOptionalResolvedScript(componentObject.configureScript, manifestDir, `components[${index}].configureScript`, errors);
153
+ const updateScript = readOptionalResolvedScript(componentObject.updateScript, manifestDir, `components[${index}].updateScript`, errors);
154
+ const removeScript = readOptionalResolvedScript(componentObject.removeScript, manifestDir, `components[${index}].removeScript`, errors);
155
+ const packageCatalogValue = componentObject.packageCatalog;
156
+ const packageCatalog = Array.isArray(packageCatalogValue)
157
+ ? packageCatalogValue.flatMap((entry, packageIndex) => validateRuntimePackageCatalogEntry(entry, `components[${index}].packageCatalog[${packageIndex}]`, errors))
158
+ : [];
159
+ if (packageCatalogValue !== undefined && !Array.isArray(packageCatalogValue)) {
160
+ errors.push(`components[${index}].packageCatalog must be an array when provided`);
161
+ }
162
+ components.push({
163
+ name,
164
+ type: rawType,
165
+ source: readOptionalString(componentObject.source, `components[${index}].source`, errors),
166
+ version: readOptionalString(componentObject.version, `components[${index}].version`, errors),
167
+ channelVersion: readOptionalString(componentObject.channelVersion, `components[${index}].channelVersion`, errors),
168
+ packageCatalog,
169
+ scripts: {
170
+ install: installScript,
171
+ verify: verifyScript,
172
+ configure: configureScript,
173
+ update: updateScript,
174
+ remove: removeScript
175
+ }
176
+ });
177
+ }
178
+ return components;
179
+ }
180
+ function validateRuntimePackageCatalogEntry(value, label, errors) {
181
+ const entryObject = toRecord(value, label, errors);
182
+ const packageName = readRequiredString(entryObject, `${label}.packageName`, errors);
183
+ const installSpec = readRequiredString(entryObject, `${label}.installSpec`, errors);
184
+ return [
185
+ {
186
+ id: readOptionalString(entryObject.id, `${label}.id`, errors),
187
+ packageName,
188
+ installSpec,
189
+ binName: readOptionalString(entryObject.binName, `${label}.binName`, errors)
190
+ }
191
+ ];
192
+ }
193
+ function toRecord(value, label, errors) {
194
+ if (!isRecord(value)) {
195
+ errors.push(`${label} must be an object`);
196
+ return {};
197
+ }
198
+ return value;
199
+ }
200
+ function readRequiredString(value, label, errors) {
201
+ if (typeof value !== "string" || value.trim().length === 0) {
202
+ errors.push(`${label} must be a non-empty string`);
203
+ return "";
204
+ }
205
+ return value.trim();
206
+ }
207
+ function readOptionalString(value, label, errors) {
208
+ if (value === undefined) {
209
+ return undefined;
210
+ }
211
+ if (typeof value !== "string" || value.trim().length === 0) {
212
+ errors.push(`${label} must be a non-empty string when provided`);
213
+ return undefined;
214
+ }
215
+ return value.trim();
216
+ }
217
+ function readResolvedScript(value, manifestDir, label, errors) {
218
+ const scriptPath = readRequiredString(value, label, errors);
219
+ return scriptPath ? resolveManifestRelativePath(manifestDir, scriptPath) : "";
220
+ }
221
+ function readOptionalResolvedScript(value, manifestDir, label, errors) {
222
+ const scriptPath = readOptionalString(value, label, errors);
223
+ return scriptPath ? resolveManifestRelativePath(manifestDir, scriptPath) : undefined;
224
+ }
225
+ function resolveManifestRelativePath(manifestDir, scriptPath) {
226
+ return resolve(manifestDir, scriptPath);
227
+ }
228
+ function isRecord(value) {
229
+ return typeof value === "object" && value !== null && !Array.isArray(value);
230
+ }
231
+ //# sourceMappingURL=runtime-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-manifest.js","sourceRoot":"","sources":["../../src/runtime/runtime-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD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AAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,2CAA2C,CAAC,CAAA;QAChE,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;AACrB,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAc,EACd,WAAmB,EACnB,KAAa,EACb,MAAgB;IAEhB,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC3D,OAAO,UAAU,CAAC,CAAC,CAAC,2BAA2B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC/E,CAAC;AAED,SAAS,0BAA0B,CACjC,KAAc,EACd,WAAmB,EACnB,KAAa,EACb,MAAgB;IAEhB,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC3D,OAAO,UAAU,CAAC,CAAC,CAAC,2BAA2B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACtF,CAAC;AAED,SAAS,2BAA2B,CAAC,WAAmB,EAAE,UAAkB;IAC1E,OAAO,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;AACzC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { LoadedRuntimeManifest } from "./runtime-manifest.js";
2
+ export declare const defaultRuntimeRoot = "~/.hagicode/runtime";
3
+ export interface ResolvedRuntimePaths {
4
+ root: string;
5
+ bin: string;
6
+ config: string;
7
+ logs: string;
8
+ data: string;
9
+ stateFile: string;
10
+ componentsRoot: string;
11
+ npmPrefix: string;
12
+ nodeRuntime: string;
13
+ dotnetRuntime: string;
14
+ vendoredRoot: string;
15
+ }
16
+ export interface ResolveRuntimePathsOptions {
17
+ runtimeRoot?: string;
18
+ }
19
+ export declare function resolveRuntimePaths(manifest: LoadedRuntimeManifest, options?: ResolveRuntimePathsOptions): ResolvedRuntimePaths;
20
+ export declare function normalizeManagedRoot(value: string): string;
21
+ export declare function resolveManagedPath(pathValue: string, runtimeRoot: string): string;
22
+ export declare function getComponentManagedRoot(paths: ResolvedRuntimePaths, componentName: string): string;
23
+ export declare function getComponentConfigDirectory(paths: ResolvedRuntimePaths, componentName: string): string;
24
+ export declare function isPathInsideRuntimeRoot(runtimeRoot: string, targetPath: string): boolean;
@@ -0,0 +1,62 @@
1
+ import { homedir } from "node:os";
2
+ import { isAbsolute, join, relative, resolve } from "node:path";
3
+ export const defaultRuntimeRoot = "~/.hagicode/runtime";
4
+ export function resolveRuntimePaths(manifest, options = {}) {
5
+ const root = normalizeManagedRoot(options.runtimeRoot ?? manifest.paths.runtimeRoot ?? defaultRuntimeRoot);
6
+ return {
7
+ root,
8
+ bin: resolveManagedPath(manifest.paths.bin, root),
9
+ config: resolveManagedPath(manifest.paths.config, root),
10
+ logs: resolveManagedPath(manifest.paths.logs, root),
11
+ data: resolveManagedPath(manifest.paths.data, root),
12
+ stateFile: resolveManagedPath(manifest.paths.stateFile, root),
13
+ componentsRoot: resolveManagedPath(manifest.paths.componentsRoot, root),
14
+ npmPrefix: resolveManagedPath(manifest.paths.npmPrefix, root),
15
+ nodeRuntime: resolveManagedPath(manifest.paths.nodeRuntime, root),
16
+ dotnetRuntime: resolveManagedPath(manifest.paths.dotnetRuntime, root),
17
+ vendoredRoot: resolveManagedPath(manifest.paths.vendoredRoot, root)
18
+ };
19
+ }
20
+ export function normalizeManagedRoot(value) {
21
+ const trimmed = value.trim();
22
+ if (!trimmed) {
23
+ throw new Error("Managed runtime root must be a non-empty path.");
24
+ }
25
+ return resolve(expandHomeDirectory(trimmed));
26
+ }
27
+ export function resolveManagedPath(pathValue, runtimeRoot) {
28
+ const expanded = expandHomeDirectory(pathValue.trim());
29
+ return isAbsolute(expanded) ? resolve(expanded) : resolve(runtimeRoot, expanded);
30
+ }
31
+ export function getComponentManagedRoot(paths, componentName) {
32
+ switch (componentName) {
33
+ case "node":
34
+ return paths.nodeRuntime;
35
+ case "dotnet":
36
+ return paths.dotnetRuntime;
37
+ case "npm-packages":
38
+ return paths.npmPrefix;
39
+ case "omniroute":
40
+ case "code-server":
41
+ return join(paths.vendoredRoot, componentName);
42
+ default:
43
+ return join(paths.componentsRoot, componentName);
44
+ }
45
+ }
46
+ export function getComponentConfigDirectory(paths, componentName) {
47
+ return join(paths.config, componentName);
48
+ }
49
+ export function isPathInsideRuntimeRoot(runtimeRoot, targetPath) {
50
+ const relativePath = relative(resolve(runtimeRoot), resolve(targetPath));
51
+ return relativePath === "" || (!relativePath.startsWith("..") && !relativePath.startsWith("../"));
52
+ }
53
+ function expandHomeDirectory(value) {
54
+ if (value === "~") {
55
+ return homedir();
56
+ }
57
+ if (value.startsWith("~/")) {
58
+ return join(homedir(), value.slice(2));
59
+ }
60
+ return value;
61
+ }
62
+ //# sourceMappingURL=runtime-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-paths.js","sourceRoot":"","sources":["../../src/runtime/runtime-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAG/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAoBvD,MAAM,UAAU,mBAAmB,CACjC,QAA+B,EAC/B,UAAsC,EAAE;IAExC,MAAM,IAAI,GAAG,oBAAoB,CAC/B,OAAO,CAAC,WAAW,IAAI,QAAQ,CAAC,KAAK,CAAC,WAAW,IAAI,kBAAkB,CACxE,CAAA;IAED,OAAO;QACL,IA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C3B,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { LoadedRuntimeManifest } from "./runtime-manifest.js";
2
+ import type { ResolvedRuntimePaths } from "./runtime-paths.js";
3
+ export type RuntimeComponentStatus = "not-installed" | "installed" | "removed" | "failed";
4
+ export interface RuntimeComponentState {
5
+ name: string;
6
+ type: string;
7
+ status: RuntimeComponentStatus;
8
+ version: string | null;
9
+ managedPaths: string[];
10
+ lastAction: "install" | "remove" | "update" | null;
11
+ lastUpdatedAt: string | null;
12
+ logFile: string | null;
13
+ details?: Record<string, unknown>;
14
+ }
15
+ export interface RuntimeOperationState {
16
+ phase: "install" | "remove" | "update";
17
+ status: "success" | "failed";
18
+ selectedComponents: string[];
19
+ completedComponents: string[];
20
+ startedAt: string;
21
+ finishedAt: string;
22
+ logFile: string | null;
23
+ message?: string;
24
+ }
25
+ export interface RuntimeState {
26
+ schemaVersion: 1;
27
+ runtime: {
28
+ name: string;
29
+ version: string;
30
+ manifestPath: string;
31
+ };
32
+ managedRoot: string;
33
+ managedPaths: ResolvedRuntimePaths;
34
+ components: Record<string, RuntimeComponentState>;
35
+ lastOperation: RuntimeOperationState | null;
36
+ }
37
+ export declare class RuntimeStateError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ export declare function createInitialRuntimeState(manifest: LoadedRuntimeManifest, paths: ResolvedRuntimePaths): RuntimeState;
41
+ export declare function readRuntimeState(statePath: string): Promise<RuntimeState | null>;
42
+ export declare function writeRuntimeState(statePath: string, state: RuntimeState): Promise<void>;
43
+ export declare function mergeRuntimeState(manifest: LoadedRuntimeManifest, paths: ResolvedRuntimePaths, state: RuntimeState | null): RuntimeState;
@@ -0,0 +1,82 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ export class RuntimeStateError extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "RuntimeStateError";
7
+ }
8
+ }
9
+ export function createInitialRuntimeState(manifest, paths) {
10
+ return {
11
+ schemaVersion: 1,
12
+ runtime: {
13
+ name: manifest.runtime.name,
14
+ version: manifest.runtime.version,
15
+ manifestPath: manifest.manifestPath
16
+ },
17
+ managedRoot: paths.root,
18
+ managedPaths: paths,
19
+ components: {},
20
+ lastOperation: null
21
+ };
22
+ }
23
+ export async function readRuntimeState(statePath) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(await readFile(statePath, "utf8"));
27
+ }
28
+ catch (error) {
29
+ if (isMissingFileError(error)) {
30
+ return null;
31
+ }
32
+ const message = error instanceof Error ? error.message : String(error);
33
+ throw new RuntimeStateError(`Failed to read runtime state ${statePath}: ${message}`);
34
+ }
35
+ return validateRuntimeState(parsed, statePath);
36
+ }
37
+ export async function writeRuntimeState(statePath, state) {
38
+ await mkdir(dirname(statePath), { recursive: true });
39
+ await writeFile(statePath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
40
+ }
41
+ export function mergeRuntimeState(manifest, paths, state) {
42
+ const nextState = state ?? createInitialRuntimeState(manifest, paths);
43
+ return {
44
+ ...nextState,
45
+ runtime: {
46
+ name: manifest.runtime.name,
47
+ version: manifest.runtime.version,
48
+ manifestPath: manifest.manifestPath
49
+ },
50
+ managedRoot: paths.root,
51
+ managedPaths: paths,
52
+ components: { ...nextState.components }
53
+ };
54
+ }
55
+ function validateRuntimeState(value, statePath) {
56
+ if (!isRecord(value)) {
57
+ throw new RuntimeStateError(`Runtime state ${statePath} must be a JSON object.`);
58
+ }
59
+ if (value.schemaVersion !== 1) {
60
+ throw new RuntimeStateError(`Runtime state ${statePath} has unsupported schemaVersion ${String(value.schemaVersion)}.`);
61
+ }
62
+ if (!isRecord(value.runtime) || typeof value.runtime.name !== "string" || typeof value.runtime.version !== "string") {
63
+ throw new RuntimeStateError(`Runtime state ${statePath} is missing runtime metadata.`);
64
+ }
65
+ if (!isRecord(value.managedPaths)) {
66
+ throw new RuntimeStateError(`Runtime state ${statePath} is missing managedPaths.`);
67
+ }
68
+ if (!isRecord(value.components)) {
69
+ throw new RuntimeStateError(`Runtime state ${statePath} is missing components.`);
70
+ }
71
+ return value;
72
+ }
73
+ function isRecord(value) {
74
+ return typeof value === "object" && value !== null && !Array.isArray(value);
75
+ }
76
+ function isMissingFileError(error) {
77
+ return (error instanceof Error &&
78
+ "code" in error &&
79
+ typeof error.code === "string" &&
80
+ error.code === "ENOENT");
81
+ }
82
+ //# sourceMappingURL=runtime-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-state.js","sourceRoot":"","sources":["../../src/runtime/runtime-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA8CnC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CACvC,QAA+B,EAC/B,KAA2B;IAE3B,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI;YAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO;YACjC,YAAY,EAAE,QAAQ,CAAC,YAAY;SACpC;QACD,WAAW,EAAE,KAAK,CAAC,IAAI;QACvB,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,EAAE;QACd,aAAa,EAAE,IAAI;KACpB,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,SAAiB;IACtD,IAAI,MAAe,CAAA;IAEnB,IAAI,CAAC;QACH,MAAM,G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K;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,KAAK,CAAC,IAAI,KAAK,QAAQ,CACxB,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@hagicode/hagiscript",
3
- "version": "0.1.5",
3
+ "version": "0.1.6-dev.37.1.2e654a6",
4
4
  "description": "Scoped npm package foundation for Hagiscript language tooling.",
5
+ "license": "MIT",
5
6
  "homepage": "https://github.com/HagiCode-org/hagiscript#readme",
6
7
  "bugs": {
7
8
  "url": "https://github.com/HagiCode-org/hagiscript/issues"
@@ -19,10 +20,13 @@
19
20
  "./package.json": "./package.json"
20
21
  },
21
22
  "bin": {
22
- "hagiscript": "dist/cli.js"
23
+ "hagiscript": "dist/cli.js",
24
+ "hagicode-runtime": "bin/runtime"
23
25
  },
24
26
  "files": [
25
27
  "dist",
28
+ "bin",
29
+ "runtime",
26
30
  "README.md",
27
31
  "README_cn.md"
28
32
  ],
@@ -34,6 +38,7 @@
34
38
  "format:check": "prettier --check .",
35
39
  "lint": "eslint .",
36
40
  "integration:installed-runtime": "node scripts/integration-installed-runtime.mjs",
41
+ "integration:runtime-management": "node scripts/integration-runtime-management.mjs",
37
42
  "pack:check": "node scripts/verify-package.mjs",
38
43
  "publish:check-prereqs": "node scripts/verify-npm-publish-prereqs.mjs",
39
44
  "publish:prepare-dev-version": "node scripts/prepare-dev-version.mjs",
@@ -58,7 +63,8 @@
58
63
  "dependencies": {
59
64
  "commander": "^14.0.1",
60
65
  "execa": "^9.6.1",
61
- "semver": "^7.7.4"
66
+ "semver": "^7.7.4",
67
+ "yaml": "^2.8.4"
62
68
  },
63
69
  "devDependencies": {
64
70
  "@eslint/js": "^9.38.0",
@@ -0,0 +1,103 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises"
2
+ import path from "node:path"
3
+ import process from "node:process"
4
+
5
+ export function readRuntimeScriptContext() {
6
+ return {
7
+ runtimeRoot: requiredEnv("HAGISCRIPT_RUNTIME_ROOT"),
8
+ binDir: requiredEnv("HAGISCRIPT_RUNTIME_BIN_DIR"),
9
+ configDir: requiredEnv("HAGISCRIPT_RUNTIME_CONFIG_DIR"),
10
+ logsDir: requiredEnv("HAGISCRIPT_RUNTIME_LOGS_DIR"),
11
+ dataDir: requiredEnv("HAGISCRIPT_RUNTIME_DATA_DIR"),
12
+ statePath: requiredEnv("HAGISCRIPT_RUNTIME_STATE_PATH"),
13
+ componentName: requiredEnv("HAGISCRIPT_RUNTIME_COMPONENT_NAME"),
14
+ componentType: requiredEnv("HAGISCRIPT_RUNTIME_COMPONENT_TYPE"),
15
+ componentRoot: requiredEnv("HAGISCRIPT_RUNTIME_COMPONENT_ROOT"),
16
+ componentConfigDir: requiredEnv("HAGISCRIPT_RUNTIME_COMPONENT_CONFIG_DIR"),
17
+ templateDir: requiredEnv("HAGISCRIPT_RUNTIME_TEMPLATE_DIR"),
18
+ componentVersion: process.env.HAGISCRIPT_RUNTIME_COMPONENT_VERSION?.trim() || null,
19
+ phase: process.env.HAGISCRIPT_RUNTIME_PHASE?.trim() || "install",
20
+ purge: process.env.HAGISCRIPT_RUNTIME_PURGE === "1"
21
+ }
22
+ }
23
+
24
+ export async function ensureDirectory(directory) {
25
+ await mkdir(directory, { recursive: true })
26
+ }
27
+
28
+ export async function writeJsonFile(filePath, value) {
29
+ await ensureDirectory(path.dirname(filePath))
30
+ await writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8")
31
+ }
32
+
33
+ export async function writeComponentMarker(context, extra = {}) {
34
+ const markerPath = path.join(context.componentRoot, ".hagicode-runtime.json")
35
+ await writeJsonFile(markerPath, {
36
+ component: context.componentName,
37
+ type: context.componentType,
38
+ version: context.componentVersion,
39
+ phase: context.phase,
40
+ runtimeRoot: context.runtimeRoot,
41
+ generatedAt: new Date().toISOString(),
42
+ ...extra
43
+ })
44
+ return markerPath
45
+ }
46
+
47
+ export async function materializeTemplate(templateName, destinationPath, variables) {
48
+ const templatePath = path.join(readRuntimeScriptContext().templateDir, templateName)
49
+ const template = await readFile(templatePath, "utf8")
50
+ let rendered = template
51
+
52
+ for (const [key, value] of Object.entries(variables)) {
53
+ rendered = rendered.replaceAll(`{{${key}}}`, String(value))
54
+ }
55
+
56
+ await ensureDirectory(path.dirname(destinationPath))
57
+ await writeFile(destinationPath, rendered, "utf8")
58
+ return destinationPath
59
+ }
60
+
61
+ export async function writeNodeEntrypoint(filePath, message) {
62
+ await ensureDirectory(path.dirname(filePath))
63
+ await writeFile(
64
+ filePath,
65
+ `#!/usr/bin/env node\nprocess.stdout.write(${JSON.stringify(message)} + "\\n")\n`,
66
+ "utf8"
67
+ )
68
+ return filePath
69
+ }
70
+
71
+ export async function writeCommandWrapper(binDir, commandName, scriptPath) {
72
+ await ensureDirectory(binDir)
73
+
74
+ if (process.platform === "win32") {
75
+ const wrapperPath = path.join(binDir, `${commandName}.cmd`)
76
+ const relativeTarget = path.relative(path.dirname(wrapperPath), scriptPath).replaceAll("/", "\\")
77
+ await writeFile(
78
+ wrapperPath,
79
+ `@echo off\r\nnode "%~dp0\\${relativeTarget}" %*\r\n`,
80
+ "utf8"
81
+ )
82
+ return wrapperPath
83
+ }
84
+
85
+ const wrapperPath = path.join(binDir, commandName)
86
+ const relativeTarget = path.relative(path.dirname(wrapperPath), scriptPath).replaceAll("\\", "/")
87
+ await writeFile(
88
+ wrapperPath,
89
+ `#!/usr/bin/env sh\nexec node "$(dirname "$0")/${relativeTarget}" "$@"\n`,
90
+ "utf8"
91
+ )
92
+ return wrapperPath
93
+ }
94
+
95
+ function requiredEnv(name) {
96
+ const value = process.env[name]?.trim()
97
+
98
+ if (!value) {
99
+ throw new Error(`Missing runtime script environment variable: ${name}`)
100
+ }
101
+
102
+ return value
103
+ }