@nextclaw/service 0.6.1 → 0.6.3

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.
@@ -9,9 +9,18 @@ type ProjectCreateCommandOptions = ProjectCommandOptions & {
9
9
  path?: string;
10
10
  template?: "empty" | "knowledge-base";
11
11
  };
12
+ type ProjectRemoveCommandOptions = ProjectCommandOptions & {
13
+ confirm: string;
14
+ };
12
15
  type ProjectWorkCommandOptions = ProjectCommandOptions & {
13
16
  project: string;
14
17
  };
18
+ type ProjectWorkListCommandOptions = ProjectWorkCommandOptions & {
19
+ includeDeleted?: boolean;
20
+ state?: string;
21
+ cursor?: string;
22
+ limit?: string;
23
+ };
15
24
  type ProjectWorkCreateCommandOptions = ProjectWorkCommandOptions & {
16
25
  description?: string;
17
26
  state?: string;
@@ -31,10 +40,8 @@ declare class ProjectCommands {
31
40
  list: (options?: ProjectCommandOptions) => Promise<void>;
32
41
  templates: (options?: ProjectCommandOptions) => Promise<void>;
33
42
  create: (name: string, options?: ProjectCreateCommandOptions) => Promise<void>;
34
- observe: (rootPath: string, options?: ProjectCommandOptions) => Promise<void>;
35
- workList: (options: ProjectWorkCommandOptions & {
36
- includeDeleted?: boolean;
37
- }) => Promise<void>;
43
+ remove: (projectId: string, options: ProjectRemoveCommandOptions) => Promise<void>;
44
+ workList: (options: ProjectWorkListCommandOptions) => Promise<void>;
38
45
  workGet: (workItemId: string, options: ProjectWorkCommandOptions) => Promise<void>;
39
46
  workCreate: (title: string, options: ProjectWorkCreateCommandOptions) => Promise<void>;
40
47
  workUpdate: (workItemId: string, options: ProjectWorkUpdateCommandOptions) => Promise<void>;
@@ -63,7 +70,6 @@ declare class ProjectCommands {
63
70
  migrateTo?: string;
64
71
  }) => Promise<void>;
65
72
  private printCreatedProject;
66
- private printObservationSummary;
67
73
  private api;
68
74
  private workItemPath;
69
75
  private workStatePath;
@@ -72,5 +78,5 @@ declare class ProjectCommands {
72
78
  private withKernel;
73
79
  }
74
80
  //#endregion
75
- export { ProjectCommandOptions, ProjectCommands, ProjectCreateCommandOptions, ProjectWorkCommandOptions, ProjectWorkCreateCommandOptions, ProjectWorkUpdateCommandOptions };
81
+ export { ProjectCommandOptions, ProjectCommands, ProjectCreateCommandOptions, ProjectRemoveCommandOptions, ProjectWorkCommandOptions, ProjectWorkCreateCommandOptions, ProjectWorkListCommandOptions, ProjectWorkUpdateCommandOptions };
76
82
  //# sourceMappingURL=project-command.controller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project-command.controller.d.ts","names":[],"sources":["../../../../src/controllers/commands/project/project-command.controller.ts"],"mappings":";;;;KAeY,qBAAA;EACV,IAAA;AAAA;AAAA,KAGU,2BAAA,GAA8B,qBAAA;EACxC,IAAA;EACA,QAAA;AAAA;AAAA,KAGU,yBAAA,GAA4B,qBAAA;EACtC,OAAA;AAAA;AAAA,KAGU,+BAAA,GAAkC,yBAAA;EAC5C,WAAA;EACA,KAAA;EACA,SAAA;AAAA;AAAA,KAGU,+BAAA,GAAkC,yBAAA;EAC5C,KAAA;EACA,WAAA;EACA,KAAA;EACA,SAAA;EACA,OAAA;AAAA;AAAA,cAGW,eAAA;EAAA,iBAEQ,YAAA;EAAA,iBACA,eAAA;cADA,YAAA,QAAoB,cAAA,EACpB,eAAA,SAAuB,iBAAA;EAU1C,IAAA,GAAc,OAAA,GAAS,qBAAA,KAA6B,OAAA;EAqBpD,SAAA,GAAmB,OAAA,GAAS,qBAAA,KAA6B,OAAA;EAazD,MAAA,GACE,IAAA,UACA,OAAA,GAAS,2BAAA,KACR,OAAA;EAYH,OAAA,GACE,QAAA,UACA,OAAA,GAAS,qBAAA,KACR,OAAA;EAWH,QAAA,GACE,OAAA,EAAS,yBAAA;IAA8B,cAAA;EAAA,MACtC,OAAA;EAYH,OAAA,GACE,UAAA,UACA,OAAA,EAAS,yBAAA,KACR,OAAA;EAaH,UAAA,GACE,KAAA,UACA,OAAA,EAAS,+BAAA,KACR,OAAA;EAeH,UAAA,GACE,UAAA,UACA,OAAA,EAAS,+BAAA,KACR,OAAA;EAoBH,UAAA,GACE,UAAA,UACA,OAAA,EAAS,yBAAA,KACR,OAAA;EAQH,WAAA,GACE,UAAA,UACA,OAAA,EAAS,yBAAA,KACR,OAAA;EAQH,YAAA,GACE,UAAA,UACA,OAAA,EAAS,yBAAA;IAA8B,KAAA;EAAA,MACtC,OAAA;EAeH,gBAAA,GACE,UAAA,UACA,IAAA,UACA,OAAA,EAAS,yBAAA;IAA8B,KAAA;EAAA,MACtC,OAAA;EAcH,kBAAA,GACE,UAAA,UACA,cAAA,UACA,OAAA,EAAS,yBAAA,KACR,OAAA;EASH,aAAA,GAAuB,OAAA,EAAS,yBAAA,KAA4B,OAAA;EAW5D,eAAA,GACE,IAAA,UACA,OAAA,EAAS,yBAAA;IACP,QAAA,EAAU,gBAAA;IACV,QAAA;IACA,OAAA;EAAA,MAED,OAAA;EA0BH,eAAA,GACE,OAAA,UACA,OAAA,EAAS,yBAAA;IACP,IAAA;IACA,QAAA,GAAW,gBAAA;IACX,QAAA;IACA,OAAA;EAAA,MAED,OAAA;EA2BH,eAAA,GACE,OAAA,UACA,OAAA,EAAS,yBAAA;IAA8B,SAAA;EAAA,MACtC,OAAA;EAAA,QAYK,mBAAA;EAAA,QAWA,uBAAA;EAAA,QAWA,GAAA;EAAA,QAYA,YAAA;EAAA,QAGA,aAAA;EAAA,QAGA,SAAA;EAAA,QAGA,iBAAA;EAAA,QAWA,UAAA;AAAA"}
1
+ {"version":3,"file":"project-command.controller.d.ts","names":[],"sources":["../../../../src/controllers/commands/project/project-command.controller.ts"],"mappings":";;;;KAcY,qBAAA;EACV,IAAA;AAAA;AAAA,KAGU,2BAAA,GAA8B,qBAAA;EACxC,IAAA;EACA,QAAA;AAAA;AAAA,KAGU,2BAAA,GAA8B,qBAAA;EACxC,OAAA;AAAA;AAAA,KAGU,yBAAA,GAA4B,qBAAA;EACtC,OAAA;AAAA;AAAA,KAGU,6BAAA,GAAgC,y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yBAAA;IACP,QAAA,EAAU,gBAAA;IACV,QAAA;IACA,OAAA;EAAA,MAED,OAAA;EA0BH,eAAA,GACE,OAAA,UACA,OAAA,EAAS,yBAAA;IACP,IAAA;IACA,QAAA,GAAW,gBAAA;IACX,QAAA;IACA,OAAA;EAAA,MAED,OAAA;EA2BH,eAAA,GACE,OAAA,UACA,OAAA,EAAS,yBAAA;IAA8B,SAAA;EAAA,MACtC,OAAA;EAAA,QAYK,mBAAA;EAAA,QAWA,GAAA;EAAA,QAYA,YAAA;EAAA,QAGA,aAAA;EAAA,QAGA,SAAA;EAAA,QAGA,iBAAA;EAAA,QAWA,UAAA;AAAA"}
@@ -47,21 +47,30 @@ var ProjectCommands = class {
47
47
  this.printCreatedProject(project, Boolean(options.json));
48
48
  });
49
49
  };
50
- observe = async (rootPath, options = {}) => {
50
+ remove = async (projectId, options) => {
51
+ if (options.confirm !== projectId) throw new Error(`--confirm must exactly match the project id: ${projectId}`);
51
52
  await this.withKernel(async (kernel) => {
52
- const snapshot = await kernel.projectObservation.observe(rootPath);
53
+ const project = await kernel.projectManager.removeProject(projectId, options.confirm);
53
54
  if (options.json) {
54
- console.log(JSON.stringify(snapshot, null, 2));
55
+ this.printJson(project);
55
56
  return;
56
57
  }
57
- this.printObservationSummary(snapshot);
58
+ console.log(`Removed project "${project.name}" from the project list`);
58
59
  });
59
60
  };
60
61
  workList = async (options) => {
61
- const work = await this.api(`/api/projects/${encodeURIComponent(options.project)}/work${options.includeDeleted ? "?includeDeleted=true" : ""}`);
62
- if (options.json) return this.printJson(work);
62
+ const { cursor, includeDeleted, json, limit: rawLimit, project, state } = options;
63
+ const limit = rawLimit === void 0 ? 20 : Number(rawLimit);
64
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("--limit must be an integer from 1 to 100");
65
+ const query = new URLSearchParams({ limit: String(limit) });
66
+ if (includeDeleted) query.set("includeDeleted", "true");
67
+ if (state) query.set("stateId", state);
68
+ if (cursor) query.set("cursor", cursor);
69
+ const work = await this.api(`/api/projects/${encodeURIComponent(project)}/work?${query.toString()}`);
70
+ if (json) return this.printJson(work);
63
71
  if (!work.items.length) return void console.log("No work items.");
64
72
  for (const item of work.items) console.log(`${item.id}\t${item.state.name}\t${item.attention}\t${item.title}`);
73
+ if (work.nextCursor) console.log(`More work items available. Next cursor: ${work.nextCursor}`);
65
74
  };
66
75
  workGet = async (workItemId, options) => {
67
76
  const item = await this.api(this.workItemPath(options.project, workItemId));
@@ -166,10 +175,6 @@ var ProjectCommands = class {
166
175
  }
167
176
  console.log(`Created project "${project.name}" at ${project.rootPath}`);
168
177
  };
169
- printObservationSummary = (snapshot) => {
170
- console.log(`${snapshot.project.name}\t${snapshot.dataQuality}\t${snapshot.project.rootPath}`);
171
- console.log(`work-items: ${snapshot.workItems.length}, artifacts: ${snapshot.artifacts.length}, signals: ${snapshot.signals.length}, requests: ${snapshot.requests.length}`);
172
- };
173
178
  api = async (path, method = "GET", body) => {
174
179
  return await this.createApiClient().request({
175
180
  path,
@@ -187,6 +192,7 @@ var ProjectCommands = class {
187
192
  withKernel = async (action) => {
188
193
  const kernel = this.createKernel();
189
194
  try {
195
+ await kernel.projectManager.initialize();
190
196
  return await action(kernel);
191
197
  } finally {
192
198
  await kernel.dispose();
@@ -1 +1 @@
1
- {"version":3,"file":"project-command.controller.js","names":[],"sources":["../../../../src/controllers/commands/project/project-command.controller.ts"],"sourcesContent":["import type {\n CreateProjectInput,\n NextclawKernel,\n ProjectRecord,\n ProjectObservationSnapshot,\n ProjectWorkActivityPage,\n ProjectWorkItemDetail,\n ProjectWorkList,\n ProjectWorkState,\n} from \"@nextclaw/kernel\";\nimport {\n resolveLocalUiApiBase,\n UiBridgeApiClient,\n} from \"@nextclaw-service/services/ui/ui-bridge-api.service.js\";\n\nexport type ProjectCommandOptions = {\n json?: boolean;\n};\n\nexport type ProjectCreateCommandOptions = ProjectCommandOptions & {\n path?: string;\n template?: \"empty\" | \"knowledge-base\";\n};\n\nexport type ProjectWorkCommandOptions = ProjectCommandOptions & {\n project: string;\n};\n\nexport type ProjectWorkCreateCommandOptions = ProjectWorkCommandOptions & {\n description?: string;\n state?: string;\n attention?: \"none\" | \"blocked\" | \"awaiting-user\";\n};\n\nexport type ProjectWorkUpdateCommandOptions = ProjectWorkCommandOptions & {\n title?: string;\n description?: string;\n state?: string;\n attention?: \"none\" | \"blocked\" | \"awaiting-user\";\n version?: string;\n};\n\nexport class ProjectCommands {\n constructor(\n private readonly createKernel: () => NextclawKernel,\n private readonly createApiClient: () => UiBridgeApiClient = () => {\n const apiBase = resolveLocalUiApiBase();\n if (!apiBase)\n throw new Error(\n \"NextClaw local service is not running. Project work commands require the running service.\",\n );\n return new UiBridgeApiClient(apiBase);\n },\n ) {}\n\n list = async (options: ProjectCommandOptions = {}): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const projects = await kernel.projectManager.listProjects();\n if (options.json) {\n console.log(\n JSON.stringify({ projects, total: projects.length }, null, 2),\n );\n return;\n }\n if (projects.length === 0) {\n console.log(\"No projects registered.\");\n return;\n }\n for (const project of projects) {\n console.log(\n `${project.name}\\t${project.template ?? \"existing\"}\\t${project.rootPath}`,\n );\n }\n });\n };\n\n templates = async (options: ProjectCommandOptions = {}): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const templates = kernel.projectManager.listTemplates();\n if (options.json) {\n console.log(JSON.stringify({ templates }, null, 2));\n return;\n }\n for (const template of templates) {\n console.log(`${template.id}\\t${template.description}`);\n }\n });\n };\n\n create = async (\n name: string,\n options: ProjectCreateCommandOptions = {},\n ): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const input: CreateProjectInput = {\n name,\n ...(options.path ? { rootPath: options.path } : {}),\n ...(options.template ? { template: options.template } : {}),\n };\n const project = await kernel.projectManager.createProject(input);\n this.printCreatedProject(project, Boolean(options.json));\n });\n };\n\n observe = async (\n rootPath: string,\n options: ProjectCommandOptions = {},\n ): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const snapshot = await kernel.projectObservation.observe(rootPath);\n if (options.json) {\n console.log(JSON.stringify(snapshot, null, 2));\n return;\n }\n this.printObservationSummary(snapshot);\n });\n };\n\n workList = async (\n options: ProjectWorkCommandOptions & { includeDeleted?: boolean },\n ): Promise<void> => {\n const work = await this.api<ProjectWorkList>(\n `/api/projects/${encodeURIComponent(options.project)}/work${options.includeDeleted ? \"?includeDeleted=true\" : \"\"}`,\n );\n if (options.json) return this.printJson(work);\n if (!work.items.length) return void console.log(\"No work items.\");\n for (const item of work.items)\n console.log(\n `${item.id}\\t${item.state.name}\\t${item.attention}\\t${item.title}`,\n );\n };\n\n workGet = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(options.project, workItemId),\n );\n if (options.json) return this.printJson(item);\n console.log(\n `${item.id}\\t${item.state.name}\\t${item.attention}\\t${item.title}`,\n );\n if (item.description) console.log(item.description);\n for (const artifact of item.artifacts)\n console.log(`artifact\\t${artifact.id}\\t${artifact.path}`);\n };\n\n workCreate = async (\n title: string,\n options: ProjectWorkCreateCommandOptions,\n ): Promise<void> => {\n const { attention, description, json, project, state } = options;\n const item = await this.api<ProjectWorkItemDetail>(\n `/api/projects/${encodeURIComponent(project)}/work/items`,\n \"POST\",\n {\n title,\n ...(description ? { description } : {}),\n ...(state ? { stateId: state } : {}),\n ...(attention ? { attention } : {}),\n },\n );\n this.printWorkMutation(\"Created\", item, Boolean(json));\n };\n\n workUpdate = async (\n workItemId: string,\n options: ProjectWorkUpdateCommandOptions,\n ): Promise<void> => {\n const { attention, description, json, project, state, title, version } =\n options;\n const expectedVersion = version === undefined ? undefined : Number(version);\n if (expectedVersion !== undefined && !Number.isInteger(expectedVersion))\n throw new Error(\"--version must be an integer\");\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(project, workItemId),\n \"PATCH\",\n {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(state ? { stateId: state } : {}),\n ...(attention ? { attention } : {}),\n ...(expectedVersion !== undefined ? { expectedVersion } : {}),\n },\n );\n this.printWorkMutation(\"Updated\", item, Boolean(json));\n };\n\n workDelete = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(options.project, workItemId),\n \"DELETE\",\n );\n this.printWorkMutation(\"Deleted\", item, Boolean(options.json));\n };\n\n workRestore = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n `${this.workItemPath(options.project, workItemId)}/restore`,\n \"POST\",\n );\n this.printWorkMutation(\"Restored\", item, Boolean(options.json));\n };\n\n workActivity = async (\n workItemId: string,\n options: ProjectWorkCommandOptions & { limit?: string },\n ): Promise<void> => {\n const { json, limit: limitInput, project } = options;\n const limit = limitInput ? Number(limitInput) : 50;\n if (!Number.isInteger(limit) || limit < 1 || limit > 100)\n throw new Error(\"--limit must be an integer from 1 to 100\");\n const page = await this.api<ProjectWorkActivityPage>(\n `${this.workItemPath(project, workItemId)}/activities?limit=${limit}`,\n );\n if (json) return this.printJson(page);\n for (const activity of page.activities)\n console.log(\n `${activity.createdAt}\\t${activity.type}\\t${activity.actor.kind}`,\n );\n };\n\n workArtifactLink = async (\n workItemId: string,\n path: string,\n options: ProjectWorkCommandOptions & { label?: string },\n ): Promise<void> => {\n const { json, label, project } = options;\n const result = await this.api<unknown>(\n `${this.workItemPath(project, workItemId)}/artifacts`,\n \"POST\",\n {\n path,\n ...(label ? { label } : {}),\n },\n );\n if (json) this.printJson(result);\n else console.log(`Linked artifact ${path}`);\n };\n\n workArtifactUnlink = async (\n workItemId: string,\n artifactLinkId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const result = await this.api<unknown>(\n `${this.workItemPath(options.project, workItemId)}/artifacts/${encodeURIComponent(artifactLinkId)}`,\n \"DELETE\",\n );\n if (options.json) this.printJson(result);\n else console.log(`Unlinked artifact ${artifactLinkId}`);\n };\n\n workStateList = async (options: ProjectWorkCommandOptions): Promise<void> => {\n const states = await this.api<ProjectWorkState[]>(\n `/api/projects/${encodeURIComponent(options.project)}/work/states`,\n );\n if (options.json) return this.printJson(states);\n for (const state of states)\n console.log(\n `${state.id}\\t${state.position}\\t${state.category}\\t${state.isDefault ? \"default\" : \"\"}\\t${state.name}`,\n );\n };\n\n workStateCreate = async (\n name: string,\n options: ProjectWorkCommandOptions & {\n category: ProjectWorkState[\"category\"];\n position?: string;\n default?: boolean;\n },\n ): Promise<void> => {\n const {\n category,\n default: isDefault,\n json,\n position: positionInput,\n project,\n } = options;\n const position =\n positionInput === undefined ? undefined : Number(positionInput);\n if (position !== undefined && !Number.isInteger(position))\n throw new Error(\"--position must be an integer\");\n const state = await this.api<ProjectWorkState>(\n `/api/projects/${encodeURIComponent(project)}/work/states`,\n \"POST\",\n {\n name,\n category,\n ...(position !== undefined ? { position } : {}),\n ...(isDefault ? { isDefault: true } : {}),\n },\n );\n if (json) this.printJson(state);\n else console.log(`Created state ${state.id}\\t${state.name}`);\n };\n\n workStateUpdate = async (\n stateId: string,\n options: ProjectWorkCommandOptions & {\n name?: string;\n category?: ProjectWorkState[\"category\"];\n position?: string;\n default?: boolean;\n },\n ): Promise<void> => {\n const {\n category,\n default: isDefault,\n json,\n name,\n position: positionInput,\n project,\n } = options;\n const position =\n positionInput === undefined ? undefined : Number(positionInput);\n if (position !== undefined && !Number.isInteger(position))\n throw new Error(\"--position must be an integer\");\n const state = await this.api<ProjectWorkState>(\n this.workStatePath(project, stateId),\n \"PATCH\",\n {\n ...(name !== undefined ? { name } : {}),\n ...(category ? { category } : {}),\n ...(position !== undefined ? { position } : {}),\n ...(isDefault ? { isDefault: true } : {}),\n },\n );\n if (json) this.printJson(state);\n else console.log(`Updated state ${state.id}\\t${state.name}`);\n };\n\n workStateDelete = async (\n stateId: string,\n options: ProjectWorkCommandOptions & { migrateTo?: string },\n ): Promise<void> => {\n const result = await this.api<unknown>(\n this.workStatePath(options.project, stateId),\n \"DELETE\",\n {\n migrateToStateId: options.migrateTo ?? null,\n },\n );\n if (options.json) this.printJson(result);\n else console.log(`Deleted state ${stateId}`);\n };\n\n private printCreatedProject = (\n project: ProjectRecord,\n json: boolean,\n ): void => {\n if (json) {\n console.log(JSON.stringify(project, null, 2));\n return;\n }\n console.log(`Created project \"${project.name}\" at ${project.rootPath}`);\n };\n\n private printObservationSummary = (\n snapshot: ProjectObservationSnapshot,\n ): void => {\n console.log(\n `${snapshot.project.name}\\t${snapshot.dataQuality}\\t${snapshot.project.rootPath}`,\n );\n console.log(\n `work-items: ${snapshot.workItems.length}, artifacts: ${snapshot.artifacts.length}, signals: ${snapshot.signals.length}, requests: ${snapshot.requests.length}`,\n );\n };\n\n private api = async <T>(\n path: string,\n method: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\" = \"GET\",\n body?: unknown,\n ): Promise<T> => {\n return await this.createApiClient().request<T>({\n path,\n method,\n ...(body !== undefined ? { body } : {}),\n });\n };\n\n private workItemPath = (projectId: string, workItemId: string): string =>\n `/api/projects/${encodeURIComponent(projectId)}/work/items/${encodeURIComponent(workItemId)}`;\n\n private workStatePath = (projectId: string, stateId: string): string =>\n `/api/projects/${encodeURIComponent(projectId)}/work/states/${encodeURIComponent(stateId)}`;\n\n private printJson = (value: unknown): void =>\n console.log(JSON.stringify(value, null, 2));\n\n private printWorkMutation = (\n verb: string,\n item: ProjectWorkItemDetail,\n json: boolean,\n ): void => {\n if (json) return this.printJson(item);\n console.log(\n `${verb} work item ${item.id}\\t${item.state.name}\\t${item.title}`,\n );\n };\n\n private withKernel = async <T>(\n action: (kernel: NextclawKernel) => Promise<T>,\n ): Promise<T> => {\n const kernel = this.createKernel();\n try {\n return await action(kernel);\n } finally {\n await kernel.dispose();\n }\n };\n}\n"],"mappings":";;AA0CA,IAAa,kBAAb,MAA6B;CAC3B,YACE,cACA,wBAAkE;EAChE,MAAM,UAAU,uBAAuB;AACvC,M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AQ,IAAI,iBAAiB,UAAU;;CAG9C,uBACE,SACA,SACS;AACT,MAAI,MAAM;AACR,WAAQ,IAAI,KAAK,UAAU,SAAS,MAAM,EAAE,CAAC;AAC7C;;AAEF,UAAQ,IAAI,oBAAoB,QAAQ,KAAK,OAAO,QAAQ,WAAW;;CAGzE,2BACE,aACS;AACT,UAAQ,IACN,GAAG,SAAS,QAAQ,KAAK,IAAI,SAAS,YAAY,IAAI,SAAS,QAAQ,WACxE;AACD,UAAQ,IACN,eAAe,SAAS,UAAU,OAAO,eAAe,SAAS,UAAU,OAAO,aAAa,SAAS,QAAQ,OAAO,cAAc,SAAS,SAAS,SACxJ;;CAGH,MAAc,OACZ,MACA,SAA8C,OAC9C,SACe;AACf,SAAO,MAAM,KAAK,iBAAiB,CAAC,QAAW;GAC7C;GACA;GACA,GAAI,SAAS,KAAA,IAAY,EAAE,MAAM,GAAG,EAAE;GACvC,CAAC;;CAGJ,gBAAwB,WAAmB,eACzC,iBAAiB,mBAAmB,UAAU,CAAC,cAAc,mBAAmB,WAAW;CAE7F,iBAAyB,WAAmB,YAC1C,iBAAiB,mBAAmB,UAAU,CAAC,eAAe,mBAAmB,QAAQ;CAE3F,aAAqB,UACnB,QAAQ,IAAI,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC;CAE7C,qBACE,MACA,MACA,SACS;AACT,MAAI,KAAM,QAAO,KAAK,UAAU,KAAK;AACrC,UAAQ,IACN,GAAG,KAAK,aAAa,KAAK,GAAG,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,QAC3D;;CAGH,aAAqB,OACnB,WACe;EACf,MAAM,SAAS,KAAK,cAAc;AAClC,MAAI;AACF,UAAO,MAAM,OAAO,OAAO;YACnB;AACR,SAAM,OAAO,SAAS"}
1
+ {"version":3,"file":"project-command.controller.js","names":[],"sources":["../../../../src/controllers/commands/project/project-command.controller.ts"],"sourcesContent":["import type {\n CreateProjectInput,\n NextclawKernel,\n ProjectRecord,\n ProjectWorkActivityPage,\n ProjectWorkItemDetail,\n ProjectWorkItemPage,\n ProjectWorkState,\n} from \"@nextclaw/kernel\";\nimport {\n resolveLocalUiApiBase,\n UiBridgeApiClient,\n} from \"@nextclaw-service/services/ui/ui-bridge-api.service.js\";\n\nexport type ProjectCommandOptions = {\n json?: boolean;\n};\n\nexport type ProjectCreateCommandOptions = ProjectCommandOptions & {\n path?: string;\n template?: \"empty\" | \"knowledge-base\";\n};\n\nexport type ProjectRemoveCommandOptions = ProjectCommandOptions & {\n confirm: string;\n};\n\nexport type ProjectWorkCommandOptions = ProjectCommandOptions & {\n project: string;\n};\n\nexport type ProjectWorkListCommandOptions = ProjectWorkCommandOptions & {\n includeDeleted?: boolean;\n state?: string;\n cursor?: string;\n limit?: string;\n};\n\nexport type ProjectWorkCreateCommandOptions = ProjectWorkCommandOptions & {\n description?: string;\n state?: string;\n attention?: \"none\" | \"blocked\" | \"awaiting-user\";\n};\n\nexport type ProjectWorkUpdateCommandOptions = ProjectWorkCommandOptions & {\n title?: string;\n description?: string;\n state?: string;\n attention?: \"none\" | \"blocked\" | \"awaiting-user\";\n version?: string;\n};\n\nexport class ProjectCommands {\n constructor(\n private readonly createKernel: () => NextclawKernel,\n private readonly createApiClient: () => UiBridgeApiClient = () => {\n const apiBase = resolveLocalUiApiBase();\n if (!apiBase)\n throw new Error(\n \"NextClaw local service is not running. Project work commands require the running service.\",\n );\n return new UiBridgeApiClient(apiBase);\n },\n ) {}\n\n list = async (options: ProjectCommandOptions = {}): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const projects = await kernel.projectManager.listProjects();\n if (options.json) {\n console.log(\n JSON.stringify({ projects, total: projects.length }, null, 2),\n );\n return;\n }\n if (projects.length === 0) {\n console.log(\"No projects registered.\");\n return;\n }\n for (const project of projects) {\n console.log(\n `${project.name}\\t${project.template ?? \"existing\"}\\t${project.rootPath}`,\n );\n }\n });\n };\n\n templates = async (options: ProjectCommandOptions = {}): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const templates = kernel.projectManager.listTemplates();\n if (options.json) {\n console.log(JSON.stringify({ templates }, null, 2));\n return;\n }\n for (const template of templates) {\n console.log(`${template.id}\\t${template.description}`);\n }\n });\n };\n\n create = async (\n name: string,\n options: ProjectCreateCommandOptions = {},\n ): Promise<void> => {\n await this.withKernel(async (kernel) => {\n const input: CreateProjectInput = {\n name,\n ...(options.path ? { rootPath: options.path } : {}),\n ...(options.template ? { template: options.template } : {}),\n };\n const project = await kernel.projectManager.createProject(input);\n this.printCreatedProject(project, Boolean(options.json));\n });\n };\n\n remove = async (\n projectId: string,\n options: ProjectRemoveCommandOptions,\n ): Promise<void> => {\n if (options.confirm !== projectId) {\n throw new Error(\n `--confirm must exactly match the project id: ${projectId}`,\n );\n }\n await this.withKernel(async (kernel) => {\n const project = await kernel.projectManager.removeProject(\n projectId,\n options.confirm,\n );\n if (options.json) {\n this.printJson(project);\n return;\n }\n console.log(`Removed project \"${project.name}\" from the project list`);\n });\n };\n\n workList = async (options: ProjectWorkListCommandOptions): Promise<void> => {\n const {\n cursor,\n includeDeleted,\n json,\n limit: rawLimit,\n project,\n state,\n } = options;\n const limit = rawLimit === undefined ? 20 : Number(rawLimit);\n if (!Number.isInteger(limit) || limit < 1 || limit > 100)\n throw new Error(\"--limit must be an integer from 1 to 100\");\n const query = new URLSearchParams({ limit: String(limit) });\n if (includeDeleted) query.set(\"includeDeleted\", \"true\");\n if (state) query.set(\"stateId\", state);\n if (cursor) query.set(\"cursor\", cursor);\n const work = await this.api<ProjectWorkItemPage>(\n `/api/projects/${encodeURIComponent(project)}/work?${query.toString()}`,\n );\n if (json) return this.printJson(work);\n if (!work.items.length) return void console.log(\"No work items.\");\n for (const item of work.items)\n console.log(\n `${item.id}\\t${item.state.name}\\t${item.attention}\\t${item.title}`,\n );\n if (work.nextCursor)\n console.log(`More work items available. Next cursor: ${work.nextCursor}`);\n };\n\n workGet = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(options.project, workItemId),\n );\n if (options.json) return this.printJson(item);\n console.log(\n `${item.id}\\t${item.state.name}\\t${item.attention}\\t${item.title}`,\n );\n if (item.description) console.log(item.description);\n for (const artifact of item.artifacts)\n console.log(`artifact\\t${artifact.id}\\t${artifact.path}`);\n };\n\n workCreate = async (\n title: string,\n options: ProjectWorkCreateCommandOptions,\n ): Promise<void> => {\n const { attention, description, json, project, state } = options;\n const item = await this.api<ProjectWorkItemDetail>(\n `/api/projects/${encodeURIComponent(project)}/work/items`,\n \"POST\",\n {\n title,\n ...(description ? { description } : {}),\n ...(state ? { stateId: state } : {}),\n ...(attention ? { attention } : {}),\n },\n );\n this.printWorkMutation(\"Created\", item, Boolean(json));\n };\n\n workUpdate = async (\n workItemId: string,\n options: ProjectWorkUpdateCommandOptions,\n ): Promise<void> => {\n const { attention, description, json, project, state, title, version } =\n options;\n const expectedVersion = version === undefined ? undefined : Number(version);\n if (expectedVersion !== undefined && !Number.isInteger(expectedVersion))\n throw new Error(\"--version must be an integer\");\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(project, workItemId),\n \"PATCH\",\n {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(state ? { stateId: state } : {}),\n ...(attention ? { attention } : {}),\n ...(expectedVersion !== undefined ? { expectedVersion } : {}),\n },\n );\n this.printWorkMutation(\"Updated\", item, Boolean(json));\n };\n\n workDelete = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n this.workItemPath(options.project, workItemId),\n \"DELETE\",\n );\n this.printWorkMutation(\"Deleted\", item, Boolean(options.json));\n };\n\n workRestore = async (\n workItemId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const item = await this.api<ProjectWorkItemDetail>(\n `${this.workItemPath(options.project, workItemId)}/restore`,\n \"POST\",\n );\n this.printWorkMutation(\"Restored\", item, Boolean(options.json));\n };\n\n workActivity = async (\n workItemId: string,\n options: ProjectWorkCommandOptions & { limit?: string },\n ): Promise<void> => {\n const { json, limit: limitInput, project } = options;\n const limit = limitInput ? Number(limitInput) : 50;\n if (!Number.isInteger(limit) || limit < 1 || limit > 100)\n throw new Error(\"--limit must be an integer from 1 to 100\");\n const page = await this.api<ProjectWorkActivityPage>(\n `${this.workItemPath(project, workItemId)}/activities?limit=${limit}`,\n );\n if (json) return this.printJson(page);\n for (const activity of page.activities)\n console.log(\n `${activity.createdAt}\\t${activity.type}\\t${activity.actor.kind}`,\n );\n };\n\n workArtifactLink = async (\n workItemId: string,\n path: string,\n options: ProjectWorkCommandOptions & { label?: string },\n ): Promise<void> => {\n const { json, label, project } = options;\n const result = await this.api<unknown>(\n `${this.workItemPath(project, workItemId)}/artifacts`,\n \"POST\",\n {\n path,\n ...(label ? { label } : {}),\n },\n );\n if (json) this.printJson(result);\n else console.log(`Linked artifact ${path}`);\n };\n\n workArtifactUnlink = async (\n workItemId: string,\n artifactLinkId: string,\n options: ProjectWorkCommandOptions,\n ): Promise<void> => {\n const result = await this.api<unknown>(\n `${this.workItemPath(options.project, workItemId)}/artifacts/${encodeURIComponent(artifactLinkId)}`,\n \"DELETE\",\n );\n if (options.json) this.printJson(result);\n else console.log(`Unlinked artifact ${artifactLinkId}`);\n };\n\n workStateList = async (options: ProjectWorkCommandOptions): Promise<void> => {\n const states = await this.api<ProjectWorkState[]>(\n `/api/projects/${encodeURIComponent(options.project)}/work/states`,\n );\n if (options.json) return this.printJson(states);\n for (const state of states)\n console.log(\n `${state.id}\\t${state.position}\\t${state.category}\\t${state.isDefault ? \"default\" : \"\"}\\t${state.name}`,\n );\n };\n\n workStateCreate = async (\n name: string,\n options: ProjectWorkCommandOptions & {\n category: ProjectWorkState[\"category\"];\n position?: string;\n default?: boolean;\n },\n ): Promise<void> => {\n const {\n category,\n default: isDefault,\n json,\n position: positionInput,\n project,\n } = options;\n const position =\n positionInput === undefined ? undefined : Number(positionInput);\n if (position !== undefined && !Number.isInteger(position))\n throw new Error(\"--position must be an integer\");\n const state = await this.api<ProjectWorkState>(\n `/api/projects/${encodeURIComponent(project)}/work/states`,\n \"POST\",\n {\n name,\n category,\n ...(position !== undefined ? { position } : {}),\n ...(isDefault ? { isDefault: true } : {}),\n },\n );\n if (json) this.printJson(state);\n else console.log(`Created state ${state.id}\\t${state.name}`);\n };\n\n workStateUpdate = async (\n stateId: string,\n options: ProjectWorkCommandOptions & {\n name?: string;\n category?: ProjectWorkState[\"category\"];\n position?: string;\n default?: boolean;\n },\n ): Promise<void> => {\n const {\n category,\n default: isDefault,\n json,\n name,\n position: positionInput,\n project,\n } = options;\n const position =\n positionInput === undefined ? undefined : Number(positionInput);\n if (position !== undefined && !Number.isInteger(position))\n throw new Error(\"--position must be an integer\");\n const state = await this.api<ProjectWorkState>(\n this.workStatePath(project, stateId),\n \"PATCH\",\n {\n ...(name !== undefined ? { name } : {}),\n ...(category ? { category } : {}),\n ...(position !== undefined ? { position } : {}),\n ...(isDefault ? { isDefault: true } : {}),\n },\n );\n if (json) this.printJson(state);\n else console.log(`Updated state ${state.id}\\t${state.name}`);\n };\n\n workStateDelete = async (\n stateId: string,\n options: ProjectWorkCommandOptions & { migrateTo?: string },\n ): Promise<void> => {\n const result = await this.api<unknown>(\n this.workStatePath(options.project, stateId),\n \"DELETE\",\n {\n migrateToStateId: options.migrateTo ?? null,\n },\n );\n if (options.json) this.printJson(result);\n else console.log(`Deleted state ${stateId}`);\n };\n\n private printCreatedProject = (\n project: ProjectRecord,\n json: boolean,\n ): void => {\n if (json) {\n console.log(JSON.stringify(project, null, 2));\n return;\n }\n console.log(`Created project \"${project.name}\" at ${project.rootPath}`);\n };\n\n private api = async <T>(\n path: string,\n method: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\" = \"GET\",\n body?: unknown,\n ): Promise<T> => {\n return await this.createApiClient().request<T>({\n path,\n method,\n ...(body !== undefined ? { body } : {}),\n });\n };\n\n private workItemPath = (projectId: string, workItemId: string): string =>\n `/api/projects/${encodeURIComponent(projectId)}/work/items/${encodeURIComponent(workItemId)}`;\n\n private workStatePath = (projectId: string, stateId: string): string =>\n `/api/projects/${encodeURIComponent(projectId)}/work/states/${encodeURIComponent(stateId)}`;\n\n private printJson = (value: unknown): void =>\n console.log(JSON.stringify(value, null, 2));\n\n private printWorkMutation = (\n verb: string,\n item: ProjectWorkItemDetail,\n json: boolean,\n ): void => {\n if (json) return this.printJson(item);\n console.log(\n `${verb} work item ${item.id}\\t${item.state.name}\\t${item.title}`,\n );\n };\n\n private withKernel = async <T>(\n action: (kernel: NextclawKernel) => Promise<T>,\n ): Promise<T> => {\n const kernel = this.createKernel();\n try {\n await kernel.projectManager.initialize();\n return await action(kernel);\n } finally {\n await kernel.dispose();\n }\n };\n}\n"],"mappings":";;AAoDA,IAAa,kBAAb,MAA6B;CAC3B,YACE,cACA,wBAAkE;EAChE,MAAM,UAAU,uBAAuB;AACvC,MAAI,CAAC,QACH,OAAM,IAAI,MACR,4FACD;AACH,SAAO,IAAI,kBAAkB,QAAQ;IAEvC;AATiB,OAAA,eAAA;AACA,OAAA,kBAAA;;CAUnB,OAAO,OAAO,UAAiC,EAAE,KAAoB;AACnE,QAAM,KAAK,WAAW,OAAO,WAAW;GACtC,MAAM,WAAW,MAAM,OAAO,eAAe,cAAc;AAC3D,OAAI,QAAQ,MAAM;AAChB,YAAQ,IACN,KAAK,UAAU;KAAE;KAAU,OAAO,SAAS;KAAQ,EAAE,MAAM,EAAE,CAC9D;AACD;;AAEF,OAAI,SAAS,WAAW,GAAG;AACzB,YAAQ,IAAI,0BAA0B;AACtC;;AAEF,QAAK,MAAM,WAAW,SACpB,SAAQ,IACN,GAAG,QAAQ,KAAK,IAAI,QAAQ,YAAY,WAAW,IAAI,QAAQ,WAChE;IAEH;;CAGJ,YAAY,OAAO,UAAiC,EAAE,KAAoB;AACxE,QAAM,KAAK,WAAW,OAAO,WAAW;GACtC,MAAM,YAAY,OAAO,eAAe,eAAe;AACvD,OAA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,KAAK,OAAO,QAAQ,WAAW;;CAGzE,MAAc,OACZ,MACA,SAA8C,OAC9C,SACe;AACf,SAAO,MAAM,KAAK,iBAAiB,CAAC,QAAW;GAC7C;GACA;GACA,GAAI,SAAS,KAAA,IAAY,EAAE,MAAM,GAAG,EAAE;GACvC,CAAC;;CAGJ,gBAAwB,WAAmB,eACzC,iBAAiB,mBAAmB,UAAU,CAAC,cAAc,mBAAmB,WAAW;CAE7F,iBAAyB,WAAmB,YAC1C,iBAAiB,mBAAmB,UAAU,CAAC,eAAe,mBAAmB,QAAQ;CAE3F,aAAqB,UACnB,QAAQ,IAAI,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC;CAE7C,qBACE,MACA,MACA,SACS;AACT,MAAI,KAAM,QAAO,KAAK,UAAU,KAAK;AACrC,UAAQ,IACN,GAAG,KAAK,aAAa,KAAK,GAAG,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,QAC3D;;CAGH,aAAqB,OACnB,WACe;EACf,MAAM,SAAS,KAAK,cAAc;AAClC,MAAI;AACF,SAAM,OAAO,eAAe,YAAY;AACxC,UAAO,MAAM,OAAO,OAAO;YACnB;AACR,SAAM,OAAO,SAAS"}
@@ -11,7 +11,7 @@ type RuntimeUpdateManagerOptions = {
11
11
  stateStore: NpmRuntimeUpdateStateStore;
12
12
  bundleService: NpmRuntimeBundleService;
13
13
  updateService: NpmRuntimeUpdateService;
14
- resolveManifestUrl: (channel: NpmRuntimeReleaseChannel) => string | null;
14
+ resolveManifestUrls: (channel: NpmRuntimeReleaseChannel) => string[];
15
15
  launcherVersion?: string;
16
16
  runningVersion?: string;
17
17
  channel: NpmRuntimeReleaseChannel;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-update.manager.d.ts","names":[],"sources":["../../src/managers/runtime-update.manager.ts"],"mappings":";;;;;;;;KAYK,2BAAA;EACH,MAAA,EAAQ,2BAAA;EACR,UAAA,EAAY,0BAAA;EACZ,aAAA,EAAe,uBAAA;EACf,aAAA,EAA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B,OAAA,EAAS,2BAAA;EAQtC,WAAA,QAAkB,cAAA;EAYlB,GAAA,GAAa,OAAA,GAAS,6BAAA,KAAqC,OAAA,CAAQ,cAAA;EAuBnE,cAAA,QAA2B,OAAA,CAAQ,cAAA;EA+BnC,cAAA,GAAwB,UAAA,IAAc,QAAA,EAAU,cAAA,cAA0B,OAAA,CAAQ,cAAA;EAoBlF,qBAAA,QAA4B,cAAA;EAAA,QAkBpB,uBAAA;EAAA,QAWA,oBAAA;EAAA,QAiEA,2BAAA;EAAA,QAgBA,mBAAA;EAAA,QA8BA,6BAAA;AAAA"}
@@ -34,7 +34,7 @@ var RuntimeUpdateManager = class {
34
34
  return this.applyDownloadedUpdate();
35
35
  };
36
36
  checkForUpdate = async () => {
37
- const manifestUrl = this.options.resolveManifestUrl(this.options.channel);
37
+ const manifestUrls = this.options.resolveManifestUrls(this.options.channel);
38
38
  if (!this.options.updateService.hasSignatureVerifier()) return this.toSnapshotFromState(this.options.stateStore.read(), {
39
39
  status: "blocked",
40
40
  installationKind: "npm-runtime-bundle",
@@ -42,7 +42,7 @@ var RuntimeUpdateManager = class {
42
42
  recoveryCommand: "Set NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY or NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH",
43
43
  errorMessage: "Runtime bundle updates require a configured update public key."
44
44
  });
45
- if (!manifestUrl) return this.toSnapshotFromState(this.options.stateStore.read(), {
45
+ if (manifestUrls.length === 0) return this.toSnapshotFromState(this.options.stateStore.read(), {
46
46
  status: "blocked",
47
47
  installationKind: "npm-runtime-bundle",
48
48
  blockReason: "unsupported-installation",
@@ -55,7 +55,7 @@ var RuntimeUpdateManager = class {
55
55
  channel: this.options.channel,
56
56
  lastUpdateCheckAt: checkedAt
57
57
  }));
58
- const availableUpdate = await this.options.updateService.checkForUpdate(manifestUrl, state.currentVersion, state.badVersions);
58
+ const availableUpdate = await this.options.updateService.checkForUpdates(manifestUrls, state.currentVersion, state.badVersions);
59
59
  return this.toSnapshotAfterCheck(availableUpdate, this.options.stateStore.read());
60
60
  };
61
61
  downloadUpdate = async (onProgress) => {
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-update.manager.js","names":[],"sources":["../../src/managers/runtime-update.manager.ts"],"sourcesContent":["import type { UpdateManifest, UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\nimport { getPackageVersion } from \"@nextclaw-service/utils/cli.utils.js\";\nimport {\n isNpmRuntimeBundleComplete,\n type NpmRuntimeBundleService\n} from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeUpdateService, NpmRuntimeAvailableUpdate } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport type { NpmRuntimeReleaseChannel } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport type { NpmRuntimeUpdateState } from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype RuntimeUpdateManagerOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n bundleService: NpmRuntimeBundleService;\n updateService: NpmRuntimeUpdateService;\n resolveManifestUrl: (channel: NpmRuntimeReleaseChannel) => string | null;\n launcherVersion?: string;\n runningVersion?: string;\n channel: NpmRuntimeReleaseChannel;\n now?: () => Date;\n};\n\ntype NpmRuntimeUpdateActionOptions = {\n apply?: boolean;\n applyAfterDownload?: boolean;\n checkOnly?: boolean;\n onProgress?: (progress: UpdateProgress) => void;\n};\n\nexport class RuntimeUpdateManager {\n private readonly launcherVersion: string;\n private readonly runningVersion: string;\n private readonly now: () => Date;\n private availableManifest: UpdateManifest | null = null;\n\n constructor(private readonly options: RuntimeUpdateManagerOptions) {\n this.launcherVersion = options.launcherVersion ?? getPackageVersion();\n this.runningVersion = options.runningVersion ?? getPackageVersion();\n this.now = options.now ?? (() => new Date());\n this.options.layout.ensureLauncherDirs();\n this.syncStateFromCurrentPointer();\n }\n\n getSnapshot = (): UpdateSnapshot => {\n const state = this.options.stateStore.read();\n return this.toSnapshotFromState(state, {\n status: state.downloadedVersion\n ? \"downloaded\"\n : this.requiresRunningVersionRestart(state)\n ? \"restart-required\"\n : \"idle\",\n requiresRestart: this.requiresRunningVersionRestart(state)\n });\n };\n\n run = async (options: NpmRuntimeUpdateActionOptions = {}): Promise<UpdateSnapshot> => {\n if (options.apply) {\n return this.applyDownloadedUpdate();\n }\n\n const applyAfterDownload = options.applyAfterDownload ?? true;\n const checkedSnapshot = await this.checkForUpdate();\n if (options.checkOnly) {\n return checkedSnapshot;\n }\n if (applyAfterDownload && checkedSnapshot.status === \"downloaded\") {\n return this.applyDownloadedUpdate();\n }\n if (checkedSnapshot.status !== \"update-available\") {\n return checkedSnapshot;\n }\n const downloadedSnapshot = await this.downloadUpdate(options.onProgress);\n if (!applyAfterDownload || downloadedSnapshot.status !== \"downloaded\") {\n return downloadedSnapshot;\n }\n return this.applyDownloadedUpdate();\n };\n\n checkForUpdate = async (): Promise<UpdateSnapshot> => {\n const manifestUrl = this.options.resolveManifestUrl(this.options.channel);\n if (!this.options.updateService.hasSignatureVerifier()) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"signature-verification-unavailable\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY or NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH\",\n errorMessage: \"Runtime bundle updates require a configured update public key.\"\n });\n }\n if (!manifestUrl) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_MANIFEST_URL or NEXTCLAW_UPDATE_MANIFEST_BASE_URL\",\n errorMessage: \"Runtime bundle update manifest URL is not configured.\"\n });\n }\n\n const checkedAt = this.now().toISOString();\n const state = this.options.stateStore.update((current) => ({\n ...current,\n channel: this.options.channel,\n lastUpdateCheckAt: checkedAt\n }));\n const availableUpdate = await this.options.updateService.checkForUpdate(manifestUrl, state.currentVersion, state.badVersions);\n return this.toSnapshotAfterCheck(availableUpdate, this.options.stateStore.read());\n };\n\n downloadUpdate = async (onProgress?: (progress: UpdateProgress) => void): Promise<UpdateSnapshot> => {\n const manifest = this.availableManifest ?? await this.ensureAvailableManifest();\n const downloaded = await this.options.updateService.downloadAndInstallUpdate(manifest, onProgress);\n const state = this.options.stateStore.update((current) => ({\n ...current,\n downloadedVersion: downloaded.downloadedVersion,\n downloadedReleaseNotesUrl: downloaded.manifest.releaseNotesUrl\n }));\n await this.options.bundleService.pruneRetainedArtifacts();\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: downloaded.downloadedVersion,\n downloadedVersion: downloaded.downloadedVersion,\n minimumHostVersion: downloaded.manifest.minimumLauncherVersion,\n releaseNotesUrl: downloaded.manifest.releaseNotesUrl,\n canApplyInApp: true,\n requiresRestart: false\n });\n };\n\n applyDownloadedUpdate = (): UpdateSnapshot => {\n const downloadedVersion = this.options.stateStore.read().downloadedVersion?.trim();\n if (!downloadedVersion) {\n throw new Error(\"No downloaded npm runtime update is ready to apply.\");\n }\n this.options.bundleService.activateVersion(downloadedVersion);\n this.availableManifest = null;\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"restart-required\",\n targetVersion: downloadedVersion,\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null,\n canApplyInApp: false,\n requiresRestart: true\n });\n };\n\n private ensureAvailableManifest = async (): Promise<UpdateManifest> => {\n const snapshot = await this.checkForUpdate();\n if (!this.availableManifest) {\n if (snapshot.downloadedVersion) {\n throw new Error(`Version ${snapshot.downloadedVersion} has already been downloaded and is ready to apply.`);\n }\n throw new Error(\"No npm runtime update is currently available.\");\n }\n return this.availableManifest;\n };\n\n private toSnapshotAfterCheck = (\n availableUpdate: NpmRuntimeAvailableUpdate | null,\n state: NpmRuntimeUpdateState\n ): UpdateSnapshot => {\n if (state.downloadedVersion) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : this.availableManifest;\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.latestVersion : state.downloadedVersion,\n minimumHostVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.minimumLauncherVersion : null,\n canApplyInApp: true,\n requiresRestart: false\n });\n }\n if (this.requiresRunningVersionRestart(state)) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : null;\n return this.toSnapshotFromState(state, {\n status: \"restart-required\",\n availableVersion: availableUpdate?.manifest.latestVersion ?? null,\n minimumHostVersion: availableUpdate?.manifest.minimumLauncherVersion ?? null,\n releaseNotesUrl: availableUpdate?.manifest.releaseNotesUrl ?? null,\n canApplyInApp: false,\n requiresRestart: true\n });\n }\n if (!availableUpdate) {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"up-to-date\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null\n });\n }\n if (availableUpdate.kind === \"host-update-required\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"blocked\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n blockReason: \"host-too-old\",\n recoveryCommand: \"npm install -g nextclaw@latest\",\n errorMessage: `NextClaw npm launcher ${this.launcherVersion} is too old for runtime bundle ${availableUpdate.manifest.latestVersion}.`\n });\n }\n if (availableUpdate.kind === \"quarantined-bad-version\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"failed\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n errorMessage: `Version ${availableUpdate.manifest.latestVersion} was quarantined after a failed launch.`\n });\n }\n this.availableManifest = availableUpdate.manifest;\n return this.toSnapshotFromState(state, {\n status: \"update-available\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl\n });\n };\n\n private syncStateFromCurrentPointer = (): void => {\n let currentVersion: string | null = null;\n try {\n const currentBundle = this.options.bundleService.resolveCurrentBundle();\n if (currentBundle && isNpmRuntimeBundleComplete({ bundleDirectory: currentBundle.bundleDirectory })) {\n currentVersion = currentBundle.manifest.runtimeVersion ?? currentBundle.manifest.bundleVersion;\n }\n } catch {\n currentVersion = null;\n }\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion\n }));\n };\n\n private toSnapshotFromState = (\n state: NpmRuntimeUpdateState,\n patch: Partial<UpdateSnapshot> & Pick<UpdateSnapshot, \"status\">\n ): UpdateSnapshot => {\n const hasDownloadedVersion = Boolean(state.downloadedVersion);\n const { status } = patch;\n return {\n installationKind: \"npm-runtime-bundle\",\n channel: state.channel,\n hostVersion: this.launcherVersion,\n currentVersion: this.runningVersion,\n targetVersion: null,\n availableVersion: null,\n downloadedVersion: state.downloadedVersion,\n minimumHostVersion: null,\n releaseNotesUrl: state.downloadedReleaseNotesUrl,\n lastCheckedAt: state.lastUpdateCheckAt,\n progress: null,\n canApplyInApp: hasDownloadedVersion,\n requiresRestart: false,\n blockReason: null,\n recoveryCommand: null,\n errorMessage: null,\n failureStage: null,\n diagnosticCommand: null,\n ...patch,\n status\n };\n };\n\n private requiresRunningVersionRestart = (state: NpmRuntimeUpdateState): boolean => {\n const targetVersion = state.currentVersion?.trim();\n const runningVersion = this.runningVersion.trim();\n return Boolean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H;GACD;;CAGH,iCAAyC,UAA0C;EACjF,MAAM,gBAAgB,MAAM,gBAAgB,MAAM;EAClD,MAAM,iBAAiB,KAAK,eAAe,MAAM;AACjD,SAAO,QAAQ,iBAAiB,kBAAkB,kBAAkB,eAAe"}
1
+ {"version":3,"file":"runtime-update.manager.js","names":[],"sources":["../../src/managers/runtime-update.manager.ts"],"sourcesContent":["import type { UpdateManifest, UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\nimport { getPackageVersion } from \"@nextclaw-service/utils/cli.utils.js\";\nimport {\n isNpmRuntimeBundleComplete,\n type NpmRuntimeBundleService\n} from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeUpdateService, NpmRuntimeAvailableUpdate } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport type { NpmRuntimeReleaseChannel } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport type { NpmRuntimeUpdateState } from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype RuntimeUpdateManagerOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n bundleService: NpmRuntimeBundleService;\n updateService: NpmRuntimeUpdateService;\n resolveManifestUrls: (channel: NpmRuntimeReleaseChannel) => string[];\n launcherVersion?: string;\n runningVersion?: string;\n channel: NpmRuntimeReleaseChannel;\n now?: () => Date;\n};\n\ntype NpmRuntimeUpdateActionOptions = {\n apply?: boolean;\n applyAfterDownload?: boolean;\n checkOnly?: boolean;\n onProgress?: (progress: UpdateProgress) => void;\n};\n\nexport class RuntimeUpdateManager {\n private readonly launcherVersion: string;\n private readonly runningVersion: string;\n private readonly now: () => Date;\n private availableManifest: UpdateManifest | null = null;\n\n constructor(private readonly options: RuntimeUpdateManagerOptions) {\n this.launcherVersion = options.launcherVersion ?? getPackageVersion();\n this.runningVersion = options.runningVersion ?? getPackageVersion();\n this.now = options.now ?? (() => new Date());\n this.options.layout.ensureLauncherDirs();\n this.syncStateFromCurrentPointer();\n }\n\n getSnapshot = (): UpdateSnapshot => {\n const state = this.options.stateStore.read();\n return this.toSnapshotFromState(state, {\n status: state.downloadedVersion\n ? \"downloaded\"\n : this.requiresRunningVersionRestart(state)\n ? \"restart-required\"\n : \"idle\",\n requiresRestart: this.requiresRunningVersionRestart(state)\n });\n };\n\n run = async (options: NpmRuntimeUpdateActionOptions = {}): Promise<UpdateSnapshot> => {\n if (options.apply) {\n return this.applyDownloadedUpdate();\n }\n\n const applyAfterDownload = options.applyAfterDownload ?? true;\n const checkedSnapshot = await this.checkForUpdate();\n if (options.checkOnly) {\n return checkedSnapshot;\n }\n if (applyAfterDownload && checkedSnapshot.status === \"downloaded\") {\n return this.applyDownloadedUpdate();\n }\n if (checkedSnapshot.status !== \"update-available\") {\n return checkedSnapshot;\n }\n const downloadedSnapshot = await this.downloadUpdate(options.onProgress);\n if (!applyAfterDownload || downloadedSnapshot.status !== \"downloaded\") {\n return downloadedSnapshot;\n }\n return this.applyDownloadedUpdate();\n };\n\n checkForUpdate = async (): Promise<UpdateSnapshot> => {\n const manifestUrls = this.options.resolveManifestUrls(this.options.channel);\n if (!this.options.updateService.hasSignatureVerifier()) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"signature-verification-unavailable\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY or NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH\",\n errorMessage: \"Runtime bundle updates require a configured update public key.\"\n });\n }\n if (manifestUrls.length === 0) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_MANIFEST_URL or NEXTCLAW_UPDATE_MANIFEST_BASE_URL\",\n errorMessage: \"Runtime bundle update manifest URL is not configured.\"\n });\n }\n\n const checkedAt = this.now().toISOString();\n const state = this.options.stateStore.update((current) => ({\n ...current,\n channel: this.options.channel,\n lastUpdateCheckAt: checkedAt\n }));\n const availableUpdate = await this.options.updateService.checkForUpdates(manifestUrls, state.currentVersion, state.badVersions);\n return this.toSnapshotAfterCheck(availableUpdate, this.options.stateStore.read());\n };\n\n downloadUpdate = async (onProgress?: (progress: UpdateProgress) => void): Promise<UpdateSnapshot> => {\n const manifest = this.availableManifest ?? await this.ensureAvailableManifest();\n const downloaded = await this.options.updateService.downloadAndInstallUpdate(manifest, onProgress);\n const state = this.options.stateStore.update((current) => ({\n ...current,\n downloadedVersion: downloaded.downloadedVersion,\n downloadedReleaseNotesUrl: downloaded.manifest.releaseNotesUrl\n }));\n await this.options.bundleService.pruneRetainedArtifacts();\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: downloaded.downloadedVersion,\n downloadedVersion: downloaded.downloadedVersion,\n minimumHostVersion: downloaded.manifest.minimumLauncherVersion,\n releaseNotesUrl: downloaded.manifest.releaseNotesUrl,\n canApplyInApp: true,\n requiresRestart: false\n });\n };\n\n applyDownloadedUpdate = (): UpdateSnapshot => {\n const downloadedVersion = this.options.stateStore.read().downloadedVersion?.trim();\n if (!downloadedVersion) {\n throw new Error(\"No downloaded npm runtime update is ready to apply.\");\n }\n this.options.bundleService.activateVersion(downloadedVersion);\n this.availableManifest = null;\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"restart-required\",\n targetVersion: downloadedVersion,\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null,\n canApplyInApp: false,\n requiresRestart: true\n });\n };\n\n private ensureAvailableManifest = async (): Promise<UpdateManifest> => {\n const snapshot = await this.checkForUpdate();\n if (!this.availableManifest) {\n if (snapshot.downloadedVersion) {\n throw new Error(`Version ${snapshot.downloadedVersion} has already been downloaded and is ready to apply.`);\n }\n throw new Error(\"No npm runtime update is currently available.\");\n }\n return this.availableManifest;\n };\n\n private toSnapshotAfterCheck = (\n availableUpdate: NpmRuntimeAvailableUpdate | null,\n state: NpmRuntimeUpdateState\n ): UpdateSnapshot => {\n if (state.downloadedVersion) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : this.availableManifest;\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.latestVersion : state.downloadedVersion,\n minimumHostVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.minimumLauncherVersion : null,\n canApplyInApp: true,\n requiresRestart: false\n });\n }\n if (this.requiresRunningVersionRestart(state)) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : null;\n return this.toSnapshotFromState(state, {\n status: \"restart-required\",\n availableVersion: availableUpdate?.manifest.latestVersion ?? null,\n minimumHostVersion: availableUpdate?.manifest.minimumLauncherVersion ?? null,\n releaseNotesUrl: availableUpdate?.manifest.releaseNotesUrl ?? null,\n canApplyInApp: false,\n requiresRestart: true\n });\n }\n if (!availableUpdate) {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"up-to-date\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null\n });\n }\n if (availableUpdate.kind === \"host-update-required\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"blocked\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n blockReason: \"host-too-old\",\n recoveryCommand: \"npm install -g nextclaw@latest\",\n errorMessage: `NextClaw npm launcher ${this.launcherVersion} is too old for runtime bundle ${availableUpdate.manifest.latestVersion}.`\n });\n }\n if (availableUpdate.kind === \"quarantined-bad-version\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"failed\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n errorMessage: `Version ${availableUpdate.manifest.latestVersion} was quarantined after a failed launch.`\n });\n }\n this.availableManifest = availableUpdate.manifest;\n return this.toSnapshotFromState(state, {\n status: \"update-available\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl\n });\n };\n\n private syncStateFromCurrentPointer = (): void => {\n let currentVersion: string | null = null;\n try {\n const currentBundle = this.options.bundleService.resolveCurrentBundle();\n if (currentBundle && isNpmRuntimeBundleComplete({ bundleDirectory: currentBundle.bundleDirectory })) {\n currentVersion = currentBundle.manifest.runtimeVersion ?? currentBundle.manifest.bundleVersion;\n }\n } catch {\n currentVersion = null;\n }\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion\n }));\n };\n\n private toSnapshotFromState = (\n state: NpmRuntimeUpdateState,\n patch: Partial<UpdateSnapshot> & Pick<UpdateSnapshot, \"status\">\n ): UpdateSnapshot => {\n const hasDownloadedVersion = Boolean(state.downloadedVersion);\n const { status } = patch;\n return {\n installationKind: \"npm-runtime-bundle\",\n channel: state.channel,\n hostVersion: this.launcherVersion,\n currentVersion: this.runningVersion,\n targetVersion: null,\n availableVersion: null,\n downloadedVersion: state.downloadedVersion,\n minimumHostVersion: null,\n releaseNotesUrl: state.downloadedReleaseNotesUrl,\n lastCheckedAt: state.lastUpdateCheckAt,\n progress: null,\n canApplyInApp: hasDownloadedVersion,\n requiresRestart: false,\n blockReason: null,\n recoveryCommand: null,\n errorMessage: null,\n failureStage: null,\n diagnosticCommand: null,\n ...patch,\n status\n };\n };\n\n private requiresRunningVersionRestart = (state: NpmRuntimeUpdateState): boolean => {\n const targetVersion = state.currentVersion?.trim();\n const runningVersion = this.runningVersion.trim();\n return Boolean(targetVersion && runningVersion && targetVersion !== runningVersion);\n };\n}\n"],"mappings":";;;;AA+BA,IAAa,uBAAb,MAAkC;CAChC;CACA;CACA;CACA,oBAAmD;CAEnD,YAAY,SAAuD;AAAtC,OAAA,UAAA;AAC3B,OAAK,kBAAkB,QAAQ,mBAAmB,mBAAmB;AACrE,OAAK,iBAAiB,QAAQ,kBAAkB,mBAAmB;AACnE,OAAK,MAAM,QAAQ,8BAAc,IAAI,MAAM;AAC3C,OAAK,QAAQ,OAAO,oBAAoB;AACxC,OAAK,6BAA6B;;CAGpC,oBAAoC;EAClC,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM;AAC5C,SAAO,KAAK,oBAAoB,OAAO;GACrC,QAAQ,MAAM,oBACV,eACA,KAAK,8BAA8B,MAAM,GACvC,qBACA;GACN,iBAAiB,KAAK,8BAA8B,MAAM;GAC3D,CAAC;;CAGJ,MAAM,OAAO,UAAyC,EAAE,KAA8B;AACpF,MAAI,QAAQ,MACV,QAAO,KAAK,uBAAuB;EAGrC,MAAM,qBAAqB,QAAQ,sBAAsB;EACzD,MAAM,kBAAkB,MAAM,KAAK,gBAAgB;AACnD,MAAI,QAAQ,UACV,QAAO;AAET,MAAI,sBAAsB,gBAAgB,WAAW,aACnD,QAAO,KAAK,uBAAuB;AAErC,MAAI,gBAAgB,WAAW,mBAC7B,QAAO;EAET,MAAM,qBAAqB,MAAM,KAAK,eAAe,QAAQ,WAAW;AACxE,MAAI,CAAC,sBAAsB,mBAAmB,WAAW,aACvD,QAAO;AAET,SAAO,KAAK,uBAAuB;;CAGrC,iBAAiB,YAAqC;EACpD,MAAM,eAAe,KAAK,QAAQ,oBAAoB,KAAK,QAAQ,QAAQ;AAC3E,MAAI,CAAC,KAAK,QAAQ,cAAc,sBAAsB,CACpD,QAAO,KAAK,oBAAoB,KAAK,QAAQ,WAAW,MAAM,EAAE;GAC9D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AiB;GACjB,aAAa;GACb,iBAAiB;GACjB,cAAc;GACd,cAAc;GACd,mBAAmB;GACnB,GAAG;GACH;GACD;;CAGH,iCAAyC,UAA0C;EACjF,MAAM,gBAAgB,MAAM,gBAAgB,MAAM;EAClD,MAAM,iBAAiB,KAAK,eAAe,MAAM;AACjD,SAAO,QAAQ,iBAAiB,kBAAkB,kBAAkB,eAAe"}
@@ -23,7 +23,7 @@ var NpmRuntimeUpdateCommandService = class {
23
23
  const source = new NpmRuntimeUpdateSourceService({ packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath });
24
24
  const launcherVersion = distribution.launcherVersion;
25
25
  const channel = source.resolveChannel(opts.channel, launcherVersion);
26
- const manifestUrl = source.resolveManifestUrl(channel, opts.manifestUrl);
26
+ const manifestUrls = source.resolveManifestUrls(channel, opts.manifestUrl);
27
27
  const layout = new NpmRuntimeBundleLayoutStore();
28
28
  const stateStore = new NpmRuntimeUpdateStateStore(layout.getStatePath(), { defaultChannel: channel });
29
29
  const bundleService = new NpmRuntimeBundleService({
@@ -41,7 +41,7 @@ var NpmRuntimeUpdateCommandService = class {
41
41
  launcherVersion,
42
42
  bundlePublicKey: source.resolveBundlePublicKey() ?? void 0
43
43
  }),
44
- resolveManifestUrl: () => manifestUrl,
44
+ resolveManifestUrls: () => manifestUrls,
45
45
  launcherVersion,
46
46
  channel
47
47
  }).run({
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-command.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-command.service.ts"],"sourcesContent":["import { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport type { UpdateCommandOptions } from \"@nextclaw-service/types/cli.types.js\";\nimport type { UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\n\nexport class NpmRuntimeUpdateCommandService {\n constructor(private readonly env: NodeJS.ProcessEnv = process.env) {}\n\n run = async (opts: UpdateCommandOptions): Promise<UpdateSnapshot> => {\n const snapshot = await this.runManaged(opts);\n if (opts.json) {\n console.log(JSON.stringify(snapshot, null, 2));\n } else {\n this.printSnapshot(snapshot);\n }\n return snapshot;\n };\n\n runManaged = async (opts: UpdateCommandOptions): Promise<UpdateSnapshot> => {\n if (this.env.NEXTCLAW_DESKTOP_COMMAND_SURFACE === \"1\") {\n return this.createDesktopCommandSurfaceBlockedSnapshot(opts);\n }\n\n const downloadOnly = Boolean(opts.downloadOnly || opts.download);\n const distribution = NextclawDistributionService.get();\n const source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath,\n });\n const launcherVersion = distribution.launcherVersion;\n const channel = source.resolveChannel(opts.channel, launcherVersion);\n const manifestUrl = source.resolveManifestUrl(channel, opts.manifestUrl);\n const layout = new NpmRuntimeBundleLayoutStore();\n const stateStore = new NpmRuntimeUpdateStateStore(layout.getStatePath(), {\n defaultChannel: channel\n });\n const bundleService = new NpmRuntimeBundleService({\n layout,\n stateStore,\n launcherVersion\n });\n const updateService = new NpmRuntimeUpdateService({\n layout,\n bundleService,\n launcherVersion,\n bundlePublicKey: source.resolveBundlePublicKey() ?? undefined\n });\n const manager = new RuntimeUpdateManager({\n layout,\n stateStore,\n bundleService,\n updateService,\n resolveManifestUrl: () => manifestUrl,\n launcherVersion,\n channel\n });\n\n return await manager.run({\n apply: Boolean(opts.apply),\n checkOnly: Boolean(opts.check),\n applyAfterDownload: !downloadOnly,\n onProgress: opts.json ? undefined : this.printProgress\n });\n };\n\n private printProgress = (progress: UpdateProgress): void => {\n const percent = progress.percent === null ? \"\" : ` ${progress.percent}%`;\n const total = progress.totalBytes === null ? \"\" : ` / ${progress.totalBytes} bytes`;\n process.stdout.write(`\\rDownloading${percent} (${progress.downloadedBytes} bytes${total})`);\n if (progress.percent === 100) {\n process.stdout.write(\"\\n\");\n }\n };\n\n private printSnapshot = (snapshot: UpdateSnapshot): void => {\n if (snapshot.status === \"blocked\") {\n console.error(`Update blocked: ${snapshot.errorMessage ?? snapshot.blockReason ?? \"unknown reason\"}`);\n if (snapshot.recoveryCommand) {\n console.error(`Recovery: ${snapshot.recoveryCommand}`);\n }\n return;\n }\n if (snapshot.status === \"failed\") {\n console.error(`Update failed: ${snapshot.errorMessage ?? \"unknown error\"}`);\n return;\n }\n if (snapshot.status === \"up-to-date\") {\n console.log(`NextClaw runtime is already up to date (${snapshot.currentVersion ?? snapshot.hostVersion ?? \"unknown\"}).`);\n return;\n }\n if (snapshot.status === \"downloaded\") {\n console.log(`Runtime update downloaded: ${snapshot.downloadedVersion ?? snapshot.availableVersion}`);\n console.log(\"Run `nextclaw update --apply` to switch to the downloaded runtime.\");\n return;\n }\n if (snapshot.status === \"restart-required\") {\n console.log(`Runtime update applied: ${snapshot.targetVersion ?? \"unknown\"}`);\n console.log(\"Restart the running NextClaw service or start a new CLI process to use it.\");\n return;\n }\n if (snapshot.status === \"update-available\") {\n console.log(`Runtime update available: ${snapshot.currentVersion ?? \"none\"} -> ${snapshot.availableVersion}`);\n return;\n }\n console.log(`Update status: ${snapshot.status}`);\n };\n\n private createDesktopCommandSurfaceBlockedSnapshot = (opts: UpdateCommandOptions): UpdateSnapshot => {\n const distribution = NextclawDistributionService.get();\n return {\n status: \"blocked\",\n installationKind: \"desktop-bundle\",\n channel: opts.channel === \"beta\" ? \"beta\" : \"stable\",\n hostVersion: distribution.version,\n currentVersion: distribution.version,\n availableVersion: null,\n downloadedVersion: null,\n minimumHostVersion: null,\n releaseNotesUrl: null,\n lastCheckedAt: new Date().toISOString(),\n progress: null,\n canApplyInApp: false,\n requiresRestart: false,\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Use the desktop update settings or restart NextClaw Desktop to check for desktop updates.\",\n errorMessage: \"The desktop-installed nextclaw command uses the desktop update channel instead of the npm runtime updater.\"\n };\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,iCAAb,MAA4C;CAC1C,YAAY,MAA0C,QAAQ,KAAK;AAAtC,OAAA,MAAA;;CAE7B,MAAM,OAAO,SAAwD;EACnE,MAAM,WAAW,MAAM,KAAK,WAAW,KAAK;AAC5C,MAAI,KAAK,KACP,SAAQ,IAAI,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC;MAE9C,MAAK,cAAc,SAAS;AAE9B,SAAO;;CAGT,aAAa,OAAO,SAAwD;AAC1E,MAAI,KAAK,IAAI,qCAAqC,IAChD,QAAO,KAAK,2CAA2C,KAAK;EAG9D,MAAM,eAAe,QAAQ,KAAK,gBAAgB,KAAK,SAAS;EAChE,MAAM,eAAe,4BAA4B,KAAK;EACtD,MAAM,SAAS,IAAI,8BAA8B,EAC/C,uBAAuB,aAAa,4BACrC,CAAC;EACF,MAAM,kBAAkB,aAAa;EACrC,MAAM,UAAU,OAAO,eAAe,KAAK,SAAS,gBAAgB;EACpE,MAAM,cAAc,OAAO,mBAAmB,SAAS,KAAK,YAAY;EACxE,MAAM,SAAS,IAAI,6BAA6B;EAChD,MAAM,aAAa,IAAI,2BAA2B,OAAO,cAAc,EAAE,EACvE,gBAAgB,SACjB,CAAC;EACF,MAAM,gBAAgB,IAAI,wBAAwB;GAChD;GACA;GACA;GACD,CAAC;AAiBF,SAAO,MAVS,IAAI,qBAAqB;GACvC;GACA;GACA;GACA,eAVoB,IAAI,wBAAwB;IAChD;IACA;IACA;IACA,iBAAiB,OAAO,wBAAwB,IAAI,KAAA;IACrD,CAAC;GAMA,0BAA0B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AGlD,8CAAsD,SAA+C;EACnG,MAAM,eAAe,4BAA4B,KAAK;AACtD,SAAO;GACL,QAAQ;GACR,kBAAkB;GAClB,SAAS,KAAK,YAAY,SAAS,SAAS;GAC5C,aAAa,aAAa;GAC1B,gBAAgB,aAAa;GAC7B,kBAAkB;GAClB,mBAAmB;GACnB,oBAAoB;GACpB,iBAAiB;GACjB,gCAAe,IAAI,MAAM,EAAC,aAAa;GACvC,UAAU;GACV,eAAe;GACf,iBAAiB;GACjB,aAAa;GACb,iBAAiB;GACjB,cAAc;GACf"}
1
+ {"version":3,"file":"npm-runtime-update-command.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-command.service.ts"],"sourcesContent":["import { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport type { UpdateCommandOptions } from \"@nextclaw-service/types/cli.types.js\";\nimport type { UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\n\nexport class NpmRuntimeUpdateCommandService {\n constructor(private readonly env: NodeJS.ProcessEnv = process.env) {}\n\n run = async (opts: UpdateCommandOptions): Promise<UpdateSnapshot> => {\n const snapshot = await this.runManaged(opts);\n if (opts.json) {\n console.log(JSON.stringify(snapshot, null, 2));\n } else {\n this.printSnapshot(snapshot);\n }\n return snapshot;\n };\n\n runManaged = async (opts: UpdateCommandOptions): Promise<UpdateSnapshot> => {\n if (this.env.NEXTCLAW_DESKTOP_COMMAND_SURFACE === \"1\") {\n return this.createDesktopCommandSurfaceBlockedSnapshot(opts);\n }\n\n const downloadOnly = Boolean(opts.downloadOnly || opts.download);\n const distribution = NextclawDistributionService.get();\n const source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath,\n });\n const launcherVersion = distribution.launcherVersion;\n const channel = source.resolveChannel(opts.channel, launcherVersion);\n const manifestUrls = source.resolveManifestUrls(channel, opts.manifestUrl);\n const layout = new NpmRuntimeBundleLayoutStore();\n const stateStore = new NpmRuntimeUpdateStateStore(layout.getStatePath(), {\n defaultChannel: channel\n });\n const bundleService = new NpmRuntimeBundleService({\n layout,\n stateStore,\n launcherVersion\n });\n const updateService = new NpmRuntimeUpdateService({\n layout,\n bundleService,\n launcherVersion,\n bundlePublicKey: source.resolveBundlePublicKey() ?? undefined\n });\n const manager = new RuntimeUpdateManager({\n layout,\n stateStore,\n bundleService,\n updateService,\n resolveManifestUrls: () => manifestUrls,\n launcherVersion,\n channel\n });\n\n return await manager.run({\n apply: Boolean(opts.apply),\n checkOnly: Boolean(opts.check),\n applyAfterDownload: !downloadOnly,\n onProgress: opts.json ? undefined : this.printProgress\n });\n };\n\n private printProgress = (progress: UpdateProgress): void => {\n const percent = progress.percent === null ? \"\" : ` ${progress.percent}%`;\n const total = progress.totalBytes === null ? \"\" : ` / ${progress.totalBytes} bytes`;\n process.stdout.write(`\\rDownloading${percent} (${progress.downloadedBytes} bytes${total})`);\n if (progress.percent === 100) {\n process.stdout.write(\"\\n\");\n }\n };\n\n private printSnapshot = (snapshot: UpdateSnapshot): void => {\n if (snapshot.status === \"blocked\") {\n console.error(`Update blocked: ${snapshot.errorMessage ?? snapshot.blockReason ?? \"unknown reason\"}`);\n if (snapshot.recoveryCommand) {\n console.error(`Recovery: ${snapshot.recoveryCommand}`);\n }\n return;\n }\n if (snapshot.status === \"failed\") {\n console.error(`Update failed: ${snapshot.errorMessage ?? \"unknown error\"}`);\n return;\n }\n if (snapshot.status === \"up-to-date\") {\n console.log(`NextClaw runtime is already up to date (${snapshot.currentVersion ?? snapshot.hostVersion ?? \"unknown\"}).`);\n return;\n }\n if (snapshot.status === \"downloaded\") {\n console.log(`Runtime update downloaded: ${snapshot.downloadedVersion ?? snapshot.availableVersion}`);\n console.log(\"Run `nextclaw update --apply` to switch to the downloaded runtime.\");\n return;\n }\n if (snapshot.status === \"restart-required\") {\n console.log(`Runtime update applied: ${snapshot.targetVersion ?? \"unknown\"}`);\n console.log(\"Restart the running NextClaw service or start a new CLI process to use it.\");\n return;\n }\n if (snapshot.status === \"update-available\") {\n console.log(`Runtime update available: ${snapshot.currentVersion ?? \"none\"} -> ${snapshot.availableVersion}`);\n return;\n }\n console.log(`Update status: ${snapshot.status}`);\n };\n\n private createDesktopCommandSurfaceBlockedSnapshot = (opts: UpdateCommandOptions): UpdateSnapshot => {\n const distribution = NextclawDistributionService.get();\n return {\n status: \"blocked\",\n installationKind: \"desktop-bundle\",\n channel: opts.channel === \"beta\" ? \"beta\" : \"stable\",\n hostVersion: distribution.version,\n currentVersion: distribution.version,\n availableVersion: null,\n downloadedVersion: null,\n minimumHostVersion: null,\n releaseNotesUrl: null,\n lastCheckedAt: new Date().toISOString(),\n progress: null,\n canApplyInApp: false,\n requiresRestart: false,\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Use the desktop update settings or restart NextClaw Desktop to check for desktop updates.\",\n errorMessage: \"The desktop-installed nextclaw command uses the desktop update channel instead of the npm runtime updater.\"\n };\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,iCAAb,MAA4C;CAC1C,YAAY,MAA0C,QAAQ,KAAK;AAAtC,OAAA,MAAA;;CAE7B,MAAM,OAAO,SAAwD;EACnE,MAAM,WAAW,MAAM,KAAK,WAAW,KAAK;AAC5C,MAAI,KAAK,KACP,SAAQ,IAAI,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC;MAE9C,MAAK,cAAc,SAAS;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AACjC,WAAQ,MAAM,mBAAmB,SAAS,gBAAgB,SAAS,eAAe,mBAAmB;AACrG,OAAI,SAAS,gBACX,SAAQ,MAAM,aAAa,SAAS,kBAAkB;AAExD;;AAEF,MAAI,SAAS,WAAW,UAAU;AAChC,WAAQ,MAAM,kBAAkB,SAAS,gBAAgB,kBAAkB;AAC3E;;AAEF,MAAI,SAAS,WAAW,cAAc;AACpC,WAAQ,IAAI,2CAA2C,SAAS,kBAAkB,SAAS,eAAe,UAAU,IAAI;AACxH;;AAEF,MAAI,SAAS,WAAW,cAAc;AACpC,WAAQ,IAAI,8BAA8B,SAAS,qBAAqB,SAAS,mBAAmB;AACpG,WAAQ,IAAI,qEAAqE;AACjF;;AAEF,MAAI,SAAS,WAAW,oBAAoB;AAC1C,WAAQ,IAAI,2BAA2B,SAAS,iBAAiB,YAAY;AAC7E,WAAQ,IAAI,6EAA6E;AACzF;;AAEF,MAAI,SAAS,WAAW,oBAAoB;AAC1C,WAAQ,IAAI,6BAA6B,SAAS,kBAAkB,OAAO,MAAM,SAAS,mBAAmB;AAC7G;;AAEF,UAAQ,IAAI,kBAAkB,SAAS,SAAS;;CAGlD,8CAAsD,SAA+C;EACnG,MAAM,eAAe,4BAA4B,KAAK;AACtD,SAAO;GACL,QAAQ;GACR,kBAAkB;GAClB,SAAS,KAAK,YAAY,SAAS,SAAS;GAC5C,aAAa,aAAa;GAC1B,gBAAgB,aAAa;GAC7B,kBAAkB;GAClB,mBAAmB;GACnB,oBAAoB;GACpB,iBAAiB;GACjB,gCAAe,IAAI,MAAM,EAAC,aAAa;GACvC,UAAU;GACV,eAAe;GACf,iBAAiB;GACjB,aAAa;GACb,iBAAiB;GACjB,cAAc;GACf"}
@@ -225,7 +225,7 @@ var NpmRuntimeUpdateHost = class {
225
225
  stateStore: this.stateStore,
226
226
  bundleService: this.bundleService,
227
227
  updateService: this.updateService,
228
- resolveManifestUrl: (resolvedChannel) => this.source.resolveManifestUrl(resolvedChannel),
228
+ resolveManifestUrls: (resolvedChannel) => this.source.resolveManifestUrls(resolvedChannel),
229
229
  launcherVersion: this.launcherVersion,
230
230
  runningVersion: this.runningVersion,
231
231
  channel
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-host.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"sourcesContent":["import type { Config } from \"@nextclaw/core\";\nimport { getAppLogger, type AppLogger } from \"@nextclaw/core\";\nimport { AUTOMATIC_UPDATE_CHECK_INTERVAL_MS } from \"@nextclaw/kernel\";\nimport {\n eventKeys,\n type EventBus,\n type UpdateFailureStage,\n type UpdateProgress,\n type UpdateSnapshot,\n} from \"@nextclaw/shared\";\nimport type { UiRuntimeUpdateHost } from \"@nextclaw/server\";\nimport { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport { requestManagedServiceRestart } from \"@nextclaw-service/services/ui/service-remote-access.service.js\";\nimport type { ManagedServiceState } from \"@nextclaw-service/stores/managed-service-state.store.js\";\nimport type { RequestRestartParams } from \"@nextclaw-service/types/cli.types.js\";\n\nconst INITIAL_DOWNLOAD_PROGRESS: UpdateProgress = {\n downloadedBytes: 0,\n totalBytes: null,\n percent: null\n};\n\ntype NpmRuntimeUpdateHostDeps = {\n eventBus: EventBus;\n logger?: Pick<AppLogger, \"error\">;\n requestRestart: (params: RequestRestartParams) => Promise<void>;\n uiConfig: Pick<Config[\"ui\"], \"port\">;\n applyRestartMode: NpmRuntimeUpdateApplyRestartMode;\n automaticCheckIntervalMs?: number;\n};\n\nexport type NpmRuntimeUpdateApplyRestartMode =\n | \"managed-service-restart\"\n | \"supervised-process-restart\"\n | \"manual-process-restart\";\n\nexport type NpmRuntimeUpdateApplyRestartResolution = {\n mode: NpmRuntimeUpdateApplyRestartMode;\n source: \"configured-systemd\" | \"legacy-systemd-invocation\" | \"managed-service\" | \"manual-process\";\n};\n\nexport const SUPERVISED_RUNTIME_UPDATE_EXIT_CODE = 75;\n\nexport function resolveNpmRuntimeUpdateApplyRestartMode(options: {\n currentPid: number;\n env: NodeJS.ProcessEnv;\n launchedByLauncher: boolean;\n serviceState: Pick<ManagedServiceState, \"pid\" | \"uiPort\"> | null;\n uiPort: number;\n}): NpmRuntimeUpdateApplyRestartResolution {\n const { currentPid, env, launchedByLauncher, serviceState, uiPort } = options;\n const configuredSupervisor = env.NEXTCLAW_PROCESS_SUPERVISOR?.trim();\n if (configuredSupervisor === \"systemd\") {\n return { mode: \"supervised-process-restart\", source: \"configured-systemd\" };\n }\n if (!configuredSupervisor && env.INVOCATION_ID?.trim()) {\n return { mode: \"supervised-process-restart\", source: \"legacy-systemd-invocation\" };\n }\n if (serviceState?.pid === currentPid) {\n return { mode: \"managed-service-restart\", source: \"managed-service\" };\n }\n if (\n launchedByLauncher\n && typeof serviceState?.uiPort === \"number\"\n && serviceState.uiPort === uiPort\n ) {\n return { mode: \"managed-service-restart\", source: \"managed-service\" };\n }\n return { mode: \"manual-process-restart\", source: \"manual-process\" };\n}\n\nexport class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {\n private readonly source: NpmRuntimeUpdateSourceService;\n private readonly layout: NpmRuntimeBundleLayoutStore;\n private readonly launcherVersion: string;\n private readonly runningVersion: string;\n private readonly stateStore: NpmRuntimeUpdateStateStore;\n private readonly bundleService: NpmRuntimeBundleService;\n private readonly updateService: NpmRuntimeUpdateService;\n private snapshot: UpdateSnapshot;\n private activeTask: Promise<void> | null = null;\n private automaticCheckTimer: ReturnType<typeof setTimeout> | null = null;\n private started = false;\n private readonly logger: Pick<AppLogger, \"error\">;\n\n constructor(private readonly deps: NpmRuntimeUpdateHostDeps) {\n this.logger = deps.logger ?? getAppLogger(\"service.runtime-update\");\n const distribution = NextclawDistributionService.get();\n this.source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath\n });\n this.layout = new NpmRuntimeBundleLayoutStore();\n this.launcherVersion = distribution.launcherVersion;\n this.runningVersion = distribution.version;\n this.stateStore = new NpmRuntimeUpdateStateStore(this.layout.getStatePath(), {\n defaultChannel: this.source.resolveChannel(undefined, this.launcherVersion)\n });\n this.bundleService = new NpmRuntimeBundleService({\n layout: this.layout,\n stateStore: this.stateStore,\n launcherVersion: this.launcherVersion\n });\n this.updateService = new NpmRuntimeUpdateService({\n layout: this.layout,\n bundleService: this.bundleService,\n launcherVersion: this.launcherVersion,\n bundlePublicKey: this.source.resolveBundlePublicKey() ?? undefined\n });\n this.snapshot = this.createManager().getSnapshot();\n }\n\n getState = async (): Promise<UpdateSnapshot> => {\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n downloadUpdate = async (): Promise<UpdateSnapshot> => {\n return this.startDownload();\n };\n\n applyDownloadedUpdate = async (): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n return this.snapshot;\n }\n\n this.setSnapshot({\n ...this.snapshot,\n status: \"applying\",\n progress: null,\n errorMessage: null\n });\n try {\n const snapshot = this.createManager().applyDownloadedUpdate();\n this.setSnapshot(\n this.deps.applyRestartMode === \"manual-process-restart\"\n ? {\n ...snapshot,\n recoveryCommand: \"Restart this NextClaw process to launch the downloaded runtime.\"\n }\n : snapshot,\n );\n if (this.deps.applyRestartMode === \"managed-service-restart\") {\n await requestManagedServiceRestart(this.deps.requestRestart, {\n reason: \"runtime update apply\",\n uiPort: this.deps.uiConfig.port\n });\n } else if (this.deps.applyRestartMode === \"supervised-process-restart\") {\n await this.deps.requestRestart({\n reason: \"runtime update apply\",\n manualMessage: \"Restart the supervised NextClaw process to apply the runtime update.\",\n strategy: \"exit-process\",\n exitCode: SUPERVISED_RUNTIME_UPDATE_EXIT_CODE,\n delayMs: 500,\n silentNotification: true\n });\n }\n return this.snapshot;\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"apply\", error));\n throw error;\n }\n };\n\n updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n await this.activeTask;\n }\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n start = (): void => {\n if (this.started) {\n return;\n }\n this.started = true;\n void this.runAutomaticCheck();\n };\n\n dispose = (): void => {\n this.started = false;\n this.clearAutomaticCheckTimer();\n };\n\n private runAutomaticCheck = async (): Promise<void> => {\n try {\n await this.startCheck();\n } catch (error) {\n this.logger.error(\"automatic runtime update check failed\", {}, error);\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n private get automaticCheckIntervalMs(): number {\n return this.deps.automaticCheckIntervalMs ?? AUTOMATIC_UPDATE_CHECK_INTERVAL_MS;\n }\n\n private scheduleNextAutomaticCheck = (): void => {\n if (!this.started) {\n return;\n }\n this.clearAutomaticCheckTimer();\n this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, this.automaticCheckIntervalMs);\n };\n\n private clearAutomaticCheckTimer = (): void => {\n if (this.automaticCheckTimer) {\n clearTimeout(this.automaticCheckTimer);\n this.automaticCheckTimer = null;\n }\n };\n\n private startCheck = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"checking\",\n progress: null,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n const checkedSnapshot = await this.createManager().checkForUpdate();\n this.setSnapshot(checkedSnapshot);\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"check\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private startDownload = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"downloading\",\n progress: INITIAL_DOWNLOAD_PROGRESS,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n await this.runDownloadTask();\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"download\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private runDownloadTask = async (): Promise<void> => {\n const downloadedSnapshot = await this.createManager().downloadUpdate((progress) => {\n this.setSnapshot({\n ...this.snapshot,\n status: \"downloading\",\n progress,\n errorMessage: null\n });\n });\n this.setSnapshot(downloadedSnapshot);\n };\n\n private createManager = (channel = this.stateStore.read().channel): RuntimeUpdateManager => {\n return new RuntimeUpdateManager({\n layout: this.layout,\n stateStore: this.stateStore,\n bundleService: this.bundleService,\n updateService: this.updateService,\n resolveManifestUrl: (resolvedChannel) => this.source.resolveManifestUrl(resolvedChannel),\n launcherVersion: this.launcherVersion,\n runningVersion: this.runningVersion,\n channel\n });\n };\n\n private toFailedSnapshot = (failureStage: UpdateFailureStage, error: unknown): UpdateSnapshot => {\n const errorMessage = this.describeFailure(error);\n this.logger.error(\"runtime update operation failed\", { failureStage, errorMessage }, error);\n return {\n ...this.createManager().getSnapshot(),\n status: \"failed\",\n progress: null,\n errorMessage,\n failureStage,\n diagnosticCommand: \"nextclaw logs path\"\n };\n };\n\n private describeFailure = (error: unknown): string => {\n const messages: string[] = [];\n let cause = error;\n while (cause instanceof Error && messages.length < 4) {\n const message = cause.message.trim();\n if (message && messages.at(-1) !== message) {\n messages.push(message);\n }\n cause = cause.cause;\n }\n if (messages.length === 0) {\n messages.push(String(error ?? \"Unknown error\"));\n }\n return messages.join(\": \");\n };\n\n private setSnapshot = (snapshot: UpdateSnapshot): UpdateSnapshot => {\n this.snapshot = snapshot;\n this.deps.eventBus.emit(eventKeys.runtimeUpdateSnapshot, snapshot, {\n source: \"backend\"\n });\n return snapshot;\n };\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,4BAA4C;CAChD,iBAAiB;CACjB,YAAY;CACZ,SAAS;CACV;AAqBD,MAAa,sCAAsC;AAEnD,SAAgB,wCAAwC,SAMb;CACzC,MAAM,EAAE,YAAY,KAAK,oBAAoB,cAAc,WAAW;CACtE,MAAM,uBAAuB,IAAI,6BAA6B,MAAM;AACpE,KAAI,yBAAyB,UAC3B,QAAO;EAAE,MAAM;EAA8B,QAAQ;EAAsB;AAE7E,KAAI,CAAC,wBAAwB,IAAI,eAAe,MAAM,CACpD,QAAO;EAAE,MAAM;EAA8B,QAAQ;EAA6B;AAEpF,KAAI,cAAc,QAAQ,WACxB,QAAO;EAAE,MAAM;EAA2B,QAAQ;EAAmB;AAEvE,KACE,sBACG,OAAO,cAAc,WAAW,YAChC,aAAa,WAAW,OAE3B,QAAO;EAAE,MAAM;EAA2B,QAAQ;EAAmB;AAEvE,QAAO;EAAE,MAAM;EAA0B,QAAQ;EAAkB;;AAGrE,IAAa,uBAAb,MAAiE;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,aAA2C;CAC3C,sBAAoE;CACpE,UAAkB;CAClB;CAEA,YAAY,MAAiD;AAAhC,OAAA,OAAA;AAC3B,OAAK,SAAS,KAAK,UAAU,aAAa,yBAAyB;EACnE,MAAM,eAAe,4BAA4B,KAAK;AACtD,OAAK,SAAS,IAAI,8BAA8B,EAC9C,uBAAuB,aAAa,4BACrC,CAAC;AACF,OAAK,SAAS,IAAI,6BAA6B;AAC/C,OAAK,kBAAkB,aAAa;AACpC,OAAK,iBAAiB,aAAa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K,QAAQ;AAExB,WAAQ,MAAM;;AAEhB,MAAI,SAAS,WAAW,EACtB,UAAS,KAAK,OAAO,SAAS,gBAAgB,CAAC;AAEjD,SAAO,SAAS,KAAK,KAAK;;CAG5B,eAAuB,aAA6C;AAClE,OAAK,WAAW;AAChB,OAAK,KAAK,SAAS,KAAK,UAAU,uBAAuB,UAAU,EACjE,QAAQ,WACT,CAAC;AACF,SAAO"}
1
+ {"version":3,"file":"npm-runtime-update-host.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"sourcesContent":["import type { Config } from \"@nextclaw/core\";\nimport { getAppLogger, type AppLogger } from \"@nextclaw/core\";\nimport { AUTOMATIC_UPDATE_CHECK_INTERVAL_MS } from \"@nextclaw/kernel\";\nimport {\n eventKeys,\n type EventBus,\n type UpdateFailureStage,\n type UpdateProgress,\n type UpdateSnapshot,\n} from \"@nextclaw/shared\";\nimport type { UiRuntimeUpdateHost } from \"@nextclaw/server\";\nimport { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport { requestManagedServiceRestart } from \"@nextclaw-service/services/ui/service-remote-access.service.js\";\nimport type { ManagedServiceState } from \"@nextclaw-service/stores/managed-service-state.store.js\";\nimport type { RequestRestartParams } from \"@nextclaw-service/types/cli.types.js\";\n\nconst INITIAL_DOWNLOAD_PROGRESS: UpdateProgress = {\n downloadedBytes: 0,\n totalBytes: null,\n percent: null\n};\n\ntype NpmRuntimeUpdateHostDeps = {\n eventBus: EventBus;\n logger?: Pick<AppLogger, \"error\">;\n requestRestart: (params: RequestRestartParams) => Promise<void>;\n uiConfig: Pick<Config[\"ui\"], \"port\">;\n applyRestartMode: NpmRuntimeUpdateApplyRestartMode;\n automaticCheckIntervalMs?: number;\n};\n\nexport type NpmRuntimeUpdateApplyRestartMode =\n | \"managed-service-restart\"\n | \"supervised-process-restart\"\n | \"manual-process-restart\";\n\nexport type NpmRuntimeUpdateApplyRestartResolution = {\n mode: NpmRuntimeUpdateApplyRestartMode;\n source: \"configured-systemd\" | \"legacy-systemd-invocation\" | \"managed-service\" | \"manual-process\";\n};\n\nexport const SUPERVISED_RUNTIME_UPDATE_EXIT_CODE = 75;\n\nexport function resolveNpmRuntimeUpdateApplyRestartMode(options: {\n currentPid: number;\n env: NodeJS.ProcessEnv;\n launchedByLauncher: boolean;\n serviceState: Pick<ManagedServiceState, \"pid\" | \"uiPort\"> | null;\n uiPort: number;\n}): NpmRuntimeUpdateApplyRestartResolution {\n const { currentPid, env, launchedByLauncher, serviceState, uiPort } = options;\n const configuredSupervisor = env.NEXTCLAW_PROCESS_SUPERVISOR?.trim();\n if (configuredSupervisor === \"systemd\") {\n return { mode: \"supervised-process-restart\", source: \"configured-systemd\" };\n }\n if (!configuredSupervisor && env.INVOCATION_ID?.trim()) {\n return { mode: \"supervised-process-restart\", source: \"legacy-systemd-invocation\" };\n }\n if (serviceState?.pid === currentPid) {\n return { mode: \"managed-service-restart\", source: \"managed-service\" };\n }\n if (\n launchedByLauncher\n && typeof serviceState?.uiPort === \"number\"\n && serviceState.uiPort === uiPort\n ) {\n return { mode: \"managed-service-restart\", source: \"managed-service\" };\n }\n return { mode: \"manual-process-restart\", source: \"manual-process\" };\n}\n\nexport class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {\n private readonly source: NpmRuntimeUpdateSourceService;\n private readonly layout: NpmRuntimeBundleLayoutStore;\n private readonly launcherVersion: string;\n private readonly runningVersion: string;\n private readonly stateStore: NpmRuntimeUpdateStateStore;\n private readonly bundleService: NpmRuntimeBundleService;\n private readonly updateService: NpmRuntimeUpdateService;\n private snapshot: UpdateSnapshot;\n private activeTask: Promise<void> | null = null;\n private automaticCheckTimer: ReturnType<typeof setTimeout> | null = null;\n private started = false;\n private readonly logger: Pick<AppLogger, \"error\">;\n\n constructor(private readonly deps: NpmRuntimeUpdateHostDeps) {\n this.logger = deps.logger ?? getAppLogger(\"service.runtime-update\");\n const distribution = NextclawDistributionService.get();\n this.source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath\n });\n this.layout = new NpmRuntimeBundleLayoutStore();\n this.launcherVersion = distribution.launcherVersion;\n this.runningVersion = distribution.version;\n this.stateStore = new NpmRuntimeUpdateStateStore(this.layout.getStatePath(), {\n defaultChannel: this.source.resolveChannel(undefined, this.launcherVersion)\n });\n this.bundleService = new NpmRuntimeBundleService({\n layout: this.layout,\n stateStore: this.stateStore,\n launcherVersion: this.launcherVersion\n });\n this.updateService = new NpmRuntimeUpdateService({\n layout: this.layout,\n bundleService: this.bundleService,\n launcherVersion: this.launcherVersion,\n bundlePublicKey: this.source.resolveBundlePublicKey() ?? undefined\n });\n this.snapshot = this.createManager().getSnapshot();\n }\n\n getState = async (): Promise<UpdateSnapshot> => {\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n downloadUpdate = async (): Promise<UpdateSnapshot> => {\n return this.startDownload();\n };\n\n applyDownloadedUpdate = async (): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n return this.snapshot;\n }\n\n this.setSnapshot({\n ...this.snapshot,\n status: \"applying\",\n progress: null,\n errorMessage: null\n });\n try {\n const snapshot = this.createManager().applyDownloadedUpdate();\n this.setSnapshot(\n this.deps.applyRestartMode === \"manual-process-restart\"\n ? {\n ...snapshot,\n recoveryCommand: \"Restart this NextClaw process to launch the downloaded runtime.\"\n }\n : snapshot,\n );\n if (this.deps.applyRestartMode === \"managed-service-restart\") {\n await requestManagedServiceRestart(this.deps.requestRestart, {\n reason: \"runtime update apply\",\n uiPort: this.deps.uiConfig.port\n });\n } else if (this.deps.applyRestartMode === \"supervised-process-restart\") {\n await this.deps.requestRestart({\n reason: \"runtime update apply\",\n manualMessage: \"Restart the supervised NextClaw process to apply the runtime update.\",\n strategy: \"exit-process\",\n exitCode: SUPERVISED_RUNTIME_UPDATE_EXIT_CODE,\n delayMs: 500,\n silentNotification: true\n });\n }\n return this.snapshot;\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"apply\", error));\n throw error;\n }\n };\n\n updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n await this.activeTask;\n }\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n start = (): void => {\n if (this.started) {\n return;\n }\n this.started = true;\n void this.runAutomaticCheck();\n };\n\n dispose = (): void => {\n this.started = false;\n this.clearAutomaticCheckTimer();\n };\n\n private runAutomaticCheck = async (): Promise<void> => {\n try {\n await this.startCheck();\n } catch (error) {\n this.logger.error(\"automatic runtime update check failed\", {}, error);\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n private get automaticCheckIntervalMs(): number {\n return this.deps.automaticCheckIntervalMs ?? AUTOMATIC_UPDATE_CHECK_INTERVAL_MS;\n }\n\n private scheduleNextAutomaticCheck = (): void => {\n if (!this.started) {\n return;\n }\n this.clearAutomaticCheckTimer();\n this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, this.automaticCheckIntervalMs);\n };\n\n private clearAutomaticCheckTimer = (): void => {\n if (this.automaticCheckTimer) {\n clearTimeout(this.automaticCheckTimer);\n this.automaticCheckTimer = null;\n }\n };\n\n private startCheck = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"checking\",\n progress: null,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n const checkedSnapshot = await this.createManager().checkForUpdate();\n this.setSnapshot(checkedSnapshot);\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"check\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private startDownload = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"downloading\",\n progress: INITIAL_DOWNLOAD_PROGRESS,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n await this.runDownloadTask();\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"download\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private runDownloadTask = async (): Promise<void> => {\n const downloadedSnapshot = await this.createManager().downloadUpdate((progress) => {\n this.setSnapshot({\n ...this.snapshot,\n status: \"downloading\",\n progress,\n errorMessage: null\n });\n });\n this.setSnapshot(downloadedSnapshot);\n };\n\n private createManager = (channel = this.stateStore.read().channel): RuntimeUpdateManager => {\n return new RuntimeUpdateManager({\n layout: this.layout,\n stateStore: this.stateStore,\n bundleService: this.bundleService,\n updateService: this.updateService,\n resolveManifestUrls: (resolvedChannel) => this.source.resolveManifestUrls(resolvedChannel),\n launcherVersion: this.launcherVersion,\n runningVersion: this.runningVersion,\n channel\n });\n };\n\n private toFailedSnapshot = (failureStage: UpdateFailureStage, error: unknown): UpdateSnapshot => {\n const errorMessage = this.describeFailure(error);\n this.logger.error(\"runtime update operation failed\", { failureStage, errorMessage }, error);\n return {\n ...this.createManager().getSnapshot(),\n status: \"failed\",\n progress: null,\n errorMessage,\n failureStage,\n diagnosticCommand: \"nextclaw logs path\"\n };\n };\n\n private describeFailure = (error: unknown): string => {\n const messages: string[] = [];\n let cause = error;\n while (cause instanceof Error && messages.length < 4) {\n const message = cause.message.trim();\n if (message && messages.at(-1) !== message) {\n messages.push(message);\n }\n cause = cause.cause;\n }\n if (messages.length === 0) {\n messages.push(String(error ?? \"Unknown error\"));\n }\n return messages.join(\": \");\n };\n\n private setSnapshot = (snapshot: UpdateSnapshot): UpdateSnapshot => {\n this.snapshot = snapshot;\n this.deps.eventBus.emit(eventKeys.runtimeUpdateSnapshot, snapshot, {\n source: \"backend\"\n });\n return snapshot;\n };\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,4BAA4C;CAChD,iBAAiB;CACjB,YAAY;CACZ,SAAS;CACV;AAqBD,MAAa,sCAAsC;AAEnD,SAAgB,wCAAwC,SAMb;CACzC,MAAM,EAAE,YAAY,KAAK,oBAAoB,cAAc,WAAW;CACtE,MAAM,uBAAuB,IAAI,6BAA6B,MAAM;AACpE,KAAI,yBAAyB,UAC3B,QAAO;EAAE,MAAM;EAA8B,QAAQ;EAAsB;AAE7E,KAAI,CAAC,wBAAwB,IAAI,eAAe,MAAM,CACpD,QAAO;EAAE,MAAM;EAA8B,QAAQ;EAA6B;AAEpF,KAAI,cAAc,QAAQ,WACxB,QAAO;EAAE,MAAM;EAA2B,QAAQ;EAAmB;AAEvE,KACE,sBACG,OAAO,cAAc,WAAW,YAChC,aAAa,WAAW,OAE3B,QAAO;EAAE,MAAM;EAA2B,QAAQ;EAAmB;AAEvE,QAAO;EAAE,MAAM;EAA0B,QAAQ;EAAkB;;AAGrE,IAAa,uBAAb,MAAiE;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,aAA2C;CAC3C,sBAAoE;CACpE,UAAkB;CAClB;CAEA,YAAY,MAAiD;AAAhC,OAAA,OAAA;AAC3B,OAAK,SAAS,KAAK,UAAU,aAAa,yBAAyB;EACnE,MAAM,eAAe,4BAA4B,KAAK;AACtD,O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AAQ;AACZ,SAAO,iBAAiB,SAAS,SAAS,SAAS,GAAG;GACpD,MAAM,UAAU,MAAM,QAAQ,MAAM;AACpC,OAAI,WAAW,SAAS,GAAG,GAAG,KAAK,QACjC,UAAS,KAAK,QAAQ;AAExB,WAAQ,MAAM;;AAEhB,MAAI,SAAS,WAAW,EACtB,UAAS,KAAK,OAAO,SAAS,gBAAgB,CAAC;AAEjD,SAAO,SAAS,KAAK,KAAK;;CAG5B,eAAuB,aAA6C;AAClE,OAAK,WAAW;AAChB,OAAK,KAAK,SAAS,KAAK,UAAU,uBAAuB,UAAU,EACjE,QAAQ,WACT,CAAC;AACF,SAAO"}
@@ -15,6 +15,7 @@ declare class NpmRuntimeUpdateSourceService {
15
15
  constructor(options?: NpmRuntimeUpdateSourceServiceOptions);
16
16
  resolveChannel: (explicitChannel?: unknown, launcherVersion?: string | null) => NpmRuntimeReleaseChannel;
17
17
  resolveManifestUrl: (channel: NpmRuntimeReleaseChannel, explicitManifestUrl?: unknown) => string | null;
18
+ resolveManifestUrls: (channel: NpmRuntimeReleaseChannel, explicitManifestUrl?: unknown) => string[];
18
19
  resolveBundlePublicKey: () => string | null;
19
20
  }
20
21
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-source.service.d.ts","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-source.service.ts"],"mappings":";KAIY,wBAAA;AAAA,KAIP,oCAAA;EACH,GAAA,GAAM,MAAA,CAAO,UAAA;EACb,QAAA,GAAW,MAAA,CAAO,QAAA;EAClB,IAAA;EACA,qBAAA;AAAA;AAAA,iBAec,oCAAA,CAAqC,eAAA,mBAAkC,wBAAA;AAAA,cAc1E,6BAAA;EAAA,iBACM,GAAA;EAAA,iBACA,QAAA;EAAA,iBACA,IAAA;EAAA,iBACA,qBAAA;cAEL,OAAA,GAAS,oCAAA;EAOrB,cAAA,GAAkB,eAAA,YAA2B,eAAA,qBAAkC,wBAAA;EAO/E,kBAAA,GAAsB,OAAA,EAAS,wBAAA,EAA0B,mBAAA;EASzD,sBAAA;AAAA"}
1
+ {"version":3,"file":"npm-runtime-update-source.service.d.ts","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-source.service.ts"],"mappings":";KAIY,wBAAA;AAAA,KAIP,oCAAA;EACH,GAAA,GAAM,MAAA,CAAO,UAAA;EACb,QAAA,GAAW,MAAA,CAAO,QAAA;EAClB,IAAA;EACA,qBAAA;AAAA;AAAA,iBAec,oCAAA,CAAqC,eAAA,mBAAkC,wBAAA;AAAA,cAc1E,6BAAA;EAAA,iBACM,GAAA;EAAA,iBACA,QAAA;EAAA,iBACA,IAAA;EAAA,iBACA,qBAAA;cAEL,OAAA,GAAS,oCAAA;EAOrB,cAAA,GAAkB,eAAA,YAA2B,eAAA,qBAAkC,wBAAA;EAO/E,kBAAA,GAAsB,OAAA,EAAS,wBAAA,EAA0B,mBAAA;EAIzD,mBAAA,GAAuB,OAAA,EAAS,wBAAA,EAA0B,mBAAA;EAe1D,sBAAA;AAAA"}
@@ -39,10 +39,13 @@ var NpmRuntimeUpdateSourceService = class {
39
39
  return inferDefaultNpmRuntimeReleaseChannel(launcherVersion);
40
40
  };
41
41
  resolveManifestUrl = (channel, explicitManifestUrl) => {
42
+ return this.resolveManifestUrls(channel, explicitManifestUrl)[0] ?? null;
43
+ };
44
+ resolveManifestUrls = (channel, explicitManifestUrl) => {
42
45
  const manifestUrl = normalizeOptionalString(explicitManifestUrl) ?? normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_URL);
43
- if (manifestUrl) return manifestUrl;
46
+ if (manifestUrl) return [manifestUrl];
44
47
  const baseUrl = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_BASE_URL) ?? DEFAULT_NPM_RUNTIME_UPDATE_BASE_URL;
45
- return new URL(`${channel}/manifest-${channel}-${this.platform}-${this.arch}.json`, `${baseUrl.replace(/\/+$/, "")}/`).toString();
48
+ return (channel === "beta" ? ["beta", "stable"] : ["stable"]).map((candidateChannel) => new URL(`${candidateChannel}/manifest-${candidateChannel}-${this.platform}-${this.arch}.json`, `${baseUrl.replace(/\/+$/, "")}/`).toString());
46
49
  };
47
50
  resolveBundlePublicKey = () => {
48
51
  const explicitPublicKey = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY);
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-source.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-source.service.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport type NpmRuntimeReleaseChannel = \"stable\" | \"beta\";\n\nconst DEFAULT_NPM_RUNTIME_UPDATE_BASE_URL = \"https://Peiiii.github.io/nextclaw/npm-runtime-updates\";\n\ntype NpmRuntimeUpdateSourceServiceOptions = {\n env?: NodeJS.ProcessEnv;\n platform?: NodeJS.Platform;\n arch?: string;\n packagedPublicKeyPath?: string;\n};\n\nfunction normalizeOptionalString(value: unknown): string | null {\n if (typeof value !== \"string\") {\n return null;\n }\n const trimmed = value.trim();\n return trimmed ? trimmed : null;\n}\n\nfunction normalizeChannel(value: unknown): NpmRuntimeReleaseChannel {\n return typeof value === \"string\" && value.trim().toLowerCase() === \"beta\" ? \"beta\" : \"stable\";\n}\n\nexport function inferDefaultNpmRuntimeReleaseChannel(launcherVersion?: string | null): NpmRuntimeReleaseChannel {\n return typeof launcherVersion === \"string\" && launcherVersion.toLowerCase().includes(\"-beta\") ? \"beta\" : \"stable\";\n}\n\nfunction resolvePackagedPublicKeyPath(): string {\n const moduleDir = dirname(fileURLToPath(import.meta.url));\n const candidates = [\n resolve(moduleDir, \"..\", \"resources\", \"update-bundle-public.pem\"),\n resolve(moduleDir, \"../../..\", \"resources\", \"update-bundle-public.pem\"),\n resolve(moduleDir, \"../../../..\", \"resources\", \"update-bundle-public.pem\")\n ];\n return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];\n}\n\nexport class NpmRuntimeUpdateSourceService {\n private readonly env: NodeJS.ProcessEnv;\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly packagedPublicKeyPath?: string;\n\n constructor(options: NpmRuntimeUpdateSourceServiceOptions = {}) {\n this.env = options.env ?? process.env;\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.packagedPublicKeyPath = options.packagedPublicKeyPath;\n }\n\n resolveChannel = (explicitChannel?: unknown, launcherVersion?: string | null): NpmRuntimeReleaseChannel => {\n if (explicitChannel !== undefined || this.env.NEXTCLAW_UPDATE_CHANNEL !== undefined) {\n return normalizeChannel(explicitChannel ?? this.env.NEXTCLAW_UPDATE_CHANNEL);\n }\n return inferDefaultNpmRuntimeReleaseChannel(launcherVersion);\n };\n\n resolveManifestUrl = (channel: NpmRuntimeReleaseChannel, explicitManifestUrl?: unknown): string | null => {\n const manifestUrl = normalizeOptionalString(explicitManifestUrl) ?? normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_URL);\n if (manifestUrl) {\n return manifestUrl;\n }\n const baseUrl = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_BASE_URL) ?? DEFAULT_NPM_RUNTIME_UPDATE_BASE_URL;\n return new URL(`${channel}/manifest-${channel}-${this.platform}-${this.arch}.json`, `${baseUrl.replace(/\\/+$/, \"\")}/`).toString();\n };\n\n resolveBundlePublicKey = (): string | null => {\n const explicitPublicKey = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY);\n if (explicitPublicKey) {\n return explicitPublicKey;\n }\n const publicKeyPath = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH);\n if (!publicKeyPath || !existsSync(publicKeyPath)) {\n const packagedPublicKeyPath = this.packagedPublicKeyPath ?? resolvePackagedPublicKeyPath();\n return existsSync(packagedPublicKeyPath) ? readFileSync(packagedPublicKeyPath, \"utf8\").trim() : null;\n }\n return readFileSync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,KAAK,IAAI,kCAAkC,IAAI;AACvF,SAAO,IAAI,IAAI,GAAG,QAAQ,YAAY,QAAQ,GAAG,KAAK,SAAS,GAAG,KAAK,KAAK,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GAAG,CAAC,UAAU;;CAGnI,+BAA8C;EAC5C,MAAM,oBAAoB,wBAAwB,KAAK,IAAI,kCAAkC;AAC7F,MAAI,kBACF,QAAO;EAET,MAAM,gBAAgB,wBAAwB,KAAK,IAAI,uCAAuC;AAC9F,MAAI,CAAC,iBAAiB,CAAC,WAAW,cAAc,EAAE;GAChD,MAAM,wBAAwB,KAAK,yBAAyB,8BAA8B;AAC1F,UAAO,WAAW,sBAAsB,GAAG,aAAa,uBAAuB,OAAO,CAAC,MAAM,GAAG;;AAElG,SAAO,aAAa,eAAe,OAAO,CAAC,MAAM"}
1
+ {"version":3,"file":"npm-runtime-update-source.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-source.service.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport type NpmRuntimeReleaseChannel = \"stable\" | \"beta\";\n\nconst DEFAULT_NPM_RUNTIME_UPDATE_BASE_URL = \"https://Peiiii.github.io/nextclaw/npm-runtime-updates\";\n\ntype NpmRuntimeUpdateSourceServiceOptions = {\n env?: NodeJS.ProcessEnv;\n platform?: NodeJS.Platform;\n arch?: string;\n packagedPublicKeyPath?: string;\n};\n\nfunction normalizeOptionalString(value: unknown): string | null {\n if (typeof value !== \"string\") {\n return null;\n }\n const trimmed = value.trim();\n return trimmed ? trimmed : null;\n}\n\nfunction normalizeChannel(value: unknown): NpmRuntimeReleaseChannel {\n return typeof value === \"string\" && value.trim().toLowerCase() === \"beta\" ? \"beta\" : \"stable\";\n}\n\nexport function inferDefaultNpmRuntimeReleaseChannel(launcherVersion?: string | null): NpmRuntimeReleaseChannel {\n return typeof launcherVersion === \"string\" && launcherVersion.toLowerCase().includes(\"-beta\") ? \"beta\" : \"stable\";\n}\n\nfunction resolvePackagedPublicKeyPath(): string {\n const moduleDir = dirname(fileURLToPath(import.meta.url));\n const candidates = [\n resolve(moduleDir, \"..\", \"resources\", \"update-bundle-public.pem\"),\n resolve(moduleDir, \"../../..\", \"resources\", \"update-bundle-public.pem\"),\n resolve(moduleDir, \"../../../..\", \"resources\", \"update-bundle-public.pem\")\n ];\n return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];\n}\n\nexport class NpmRuntimeUpdateSourceService {\n private readonly env: NodeJS.ProcessEnv;\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly packagedPublicKeyPath?: string;\n\n constructor(options: NpmRuntimeUpdateSourceServiceOptions = {}) {\n this.env = options.env ?? process.env;\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.packagedPublicKeyPath = options.packagedPublicKeyPath;\n }\n\n resolveChannel = (explicitChannel?: unknown, launcherVersion?: string | null): NpmRuntimeReleaseChannel => {\n if (explicitChannel !== undefined || this.env.NEXTCLAW_UPDATE_CHANNEL !== undefined) {\n return normalizeChannel(explicitChannel ?? this.env.NEXTCLAW_UPDATE_CHANNEL);\n }\n return inferDefaultNpmRuntimeReleaseChannel(launcherVersion);\n };\n\n resolveManifestUrl = (channel: NpmRuntimeReleaseChannel, explicitManifestUrl?: unknown): string | null => {\n return this.resolveManifestUrls(channel, explicitManifestUrl)[0] ?? null;\n };\n\n resolveManifestUrls = (channel: NpmRuntimeReleaseChannel, explicitManifestUrl?: unknown): string[] => {\n const manifestUrl = normalizeOptionalString(explicitManifestUrl) ?? normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_URL);\n if (manifestUrl) {\n return [manifestUrl];\n }\n const baseUrl = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_MANIFEST_BASE_URL) ?? DEFAULT_NPM_RUNTIME_UPDATE_BASE_URL;\n const channels: NpmRuntimeReleaseChannel[] = channel === \"beta\" ? [\"beta\", \"stable\"] : [\"stable\"];\n return channels.map((candidateChannel) =>\n new URL(\n `${candidateChannel}/manifest-${candidateChannel}-${this.platform}-${this.arch}.json`,\n `${baseUrl.replace(/\\/+$/, \"\")}/`\n ).toString()\n );\n };\n\n resolveBundlePublicKey = (): string | null => {\n const explicitPublicKey = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY);\n if (explicitPublicKey) {\n return explicitPublicKey;\n }\n const publicKeyPath = normalizeOptionalString(this.env.NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH);\n if (!publicKeyPath || !existsSync(publicKeyPath)) {\n const packagedPublicKeyPath = this.packagedPublicKeyPath ?? resolvePackagedPublicKeyPath();\n return existsSync(packagedPublicKeyPath) ? readFileSync(packagedPublicKeyPath, \"utf8\").trim() : null;\n }\n return readFileSync(publicKeyPath, \"utf8\").trim();\n };\n}\n"],"mappings":";;;;AAMA,MAAM,sCAAsC;AAS5C,SAAS,wBAAwB,OAA+B;AAC9D,KAAI,OAAO,UAAU,SACnB,QAAO;CAET,MAAM,UAAU,MAAM,MAAM;AAC5B,QAAO,UAAU,UAAU;;AAG7B,SAAS,iBAAiB,OAA0C;AAClE,QAAO,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,aAAa,KAAK,SAAS,SAAS;;AAGvF,SAAgB,qCAAqC,iBAA2D;AAC9G,QAAO,OAAO,oBAAoB,YAAY,gBAAgB,aAAa,CAAC,SAAS,QAAQ,GAAG,SAAS;;AAG3G,SAAS,+BAAuC;CAC9C,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;CACzD,MAAM,aAAa;EACjB,QAAQ,WAAW,MAAM,aAAa,2BAA2B;EACjE,QAAQ,WAAW,YAAY,aAAa,2BAA2B;EACvE,QAAQ,WAAW,eAAe,aAAa,2BAA2B;EAC3E;AACD,QAAO,WAAW,MAAM,cAAc,WAAW,UAAU,CAAC,IAAI,WAAW;;AAG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OAAO,CAAC,MAAM"}
@@ -37,6 +37,7 @@ declare class NpmRuntimeUpdateService {
37
37
  constructor(options: NpmRuntimeUpdateServiceOptions);
38
38
  hasSignatureVerifier: () => boolean;
39
39
  checkForUpdate: (manifestUrl: string, currentVersion: string | null, badVersions?: string[]) => Promise<NpmRuntimeAvailableUpdate | null>;
40
+ checkForUpdates: (manifestUrls: string[], currentVersion: string | null, badVersions?: string[]) => Promise<NpmRuntimeAvailableUpdate | null>;
40
41
  downloadAndInstallUpdate: (manifest: UpdateManifest, reportProgress?: NpmRuntimeUpdateProgressReporter) => Promise<NpmRuntimeDownloadedUpdate>;
41
42
  private readArchiveUnixMode;
42
43
  private downloadBundleBytes;
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update.service.d.ts","names":[],"sources":["../../../src/services/runtime/npm-runtime-update.service.ts"],"mappings":";;;;;;KAkBK,SAAA,UAAmB,KAAA;AAAA,KAEnB,8BAAA;EACH,MAAA,EAAQ,2BAAA;EACR,aAAA,EAAe,uBAAA;EACf,eAAA;EACA,eAAA;EACA,SAAA,GAAY,SAAA;EACZ,QAAA,GAAW,MAAA,CAAO,QAAA;EAClB,IAAA;EACA,cAAA,GAAiB,oBAAA;EACjB,GAAA;AAAA;AAAA,KAGU,yBAAA;EACN,IAAA;EAA+B,QAAA,EAAU,cAAA;AAAA;EACzC,IAAA;EAA8B,QAAA,EAAU,cAAA;AAAA;EACxC,IAAA;EAAiC,QAAA,EAAU,cAAA;AAAA;AAAA,cAEpC,uBAAA;EAAA,iBAQkB,OAAA;EAAA,iBAPZ,QAAA;EAAA,iBACA,IAAA;EAAA,iBACA,SAAA;EAAA,iBACA,cAAA;EAAA,iBACA,eAAA;EAAA,iBACA,GAAA;cAEY,OAAA,EAAS,8BAAA;EAStC,oBAAA;EAEA,cAAA,GAAwB,WAAA,UAAqB,cAAA,iBAA+B,WAAA,gBAA6B,OAAA,CAAQ,yBAAA;EAiBjH,wBAAA,GACE,QAAA,EAAU,cAAA,EACV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AcA,mBAAA;EAAA,QAcA,aAAA;EAAA,QAaA,cAAA;EAAA,QAiBA,WAAA;EAAA,QAiBA,iBAAA;EAAA,QA0BA,iBAAA;EAAA,QASA,sBAAA;EAAA,QAYA,cAAA;EAAA,QAYA,oBAAA;EAAA,QAgBA,uBAAA;EAAA,QAWA,qBAAA;AAAA"}
@@ -25,7 +25,16 @@ var NpmRuntimeUpdateService = class {
25
25
  }
26
26
  hasSignatureVerifier = () => Boolean(this.bundlePublicKey);
27
27
  checkForUpdate = async (manifestUrl, currentVersion, badVersions = []) => {
28
- const manifest = await this.fetchManifest(manifestUrl);
28
+ return await this.checkForUpdates([manifestUrl], currentVersion, badVersions);
29
+ };
30
+ checkForUpdates = async (manifestUrls, currentVersion, badVersions = []) => {
31
+ const manifest = (await Promise.all([...new Set(manifestUrls)].map(this.fetchManifest))).reduce((selected, candidate) => {
32
+ if (!selected) return candidate;
33
+ const versionComparison = compareNpmRuntimeVersions(candidate.latestVersion, selected.latestVersion);
34
+ if (versionComparison > 0 || versionComparison === 0 && candidate.channel === "stable") return candidate;
35
+ return selected;
36
+ }, null);
37
+ if (!manifest) return null;
29
38
  if (currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, currentVersion) <= 0) return null;
30
39
  if (!currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, this.options.launcherVersion) < 0) return null;
31
40
  if (compareNpmRuntimeVersions(this.options.launcherVersion, manifest.minimumLauncherVersion) < 0) return {
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update.service.ts"],"sourcesContent":["import { createHash, createPublicKey, verify, type KeyObject } from \"node:crypto\";\nimport { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport JSZip from \"jszip\";\nimport {\n serializeUnsignedUpdateManifest,\n UpdateManifestReader,\n type UpdateManifest\n} from \"@nextclaw/kernel\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { compareNpmRuntimeVersions, type NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type {\n NpmRuntimeDownloadedUpdate,\n NpmRuntimeUpdateProgressReporter\n} from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype FetchLike = typeof fetch;\n\ntype NpmRuntimeUpdateServiceOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n bundleService: NpmRuntimeBundleService;\n launcherVersion: string;\n bundlePublicKey?: string;\n fetchImpl?: FetchLike;\n platform?: NodeJS.Platform;\n arch?: string;\n manifestReader?: UpdateManifestReader;\n now?: () => number;\n};\n\nexport type NpmRuntimeAvailableUpdate =\n | { kind: \"runtime-bundle-update\"; manifest: UpdateManifest }\n | { kind: \"host-update-required\"; manifest: UpdateManifest }\n | { kind: \"quarantined-bad-version\"; manifest: UpdateManifest };\n\nexport class NpmRuntimeUpdateService {\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly fetchImpl: FetchLike;\n private readonly manifestReader: UpdateManifestReader;\n private readonly bundlePublicKey: KeyObject | null;\n private readonly now: () => number;\n\n constructor(private readonly options: NpmRuntimeUpdateServiceOptions) {\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.fetchImpl = options.fetchImpl ?? fetch;\n this.manifestReader = options.manifestReader ?? new UpdateManifestReader();\n this.bundlePublicKey = this.parseBundlePublicKey(options.bundlePublicKey);\n this.now = options.now ?? Date.now;\n }\n\n hasSignatureVerifier = (): boolean => Boolean(this.bundlePublicKey);\n\n checkForUpdate = async (manifestUrl: string, currentVersion: string | null, badVersions: string[] = []): Promise<NpmRuntimeAvailableUpdate | null> => {\n const manifest = await this.fetchManifest(manifestUrl);\n if (currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, currentVersion) <= 0) {\n return null;\n }\n if (!currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, this.options.launcherVersion) < 0) {\n return null;\n }\n if (compareNpmRuntimeVersions(this.options.launcherVersion, manifest.minimumLauncherVersion) < 0) {\n return { kind: \"host-update-required\", manifest };\n }\n if (badVersions.includes(manifest.latestVersion)) {\n return { kind: \"quarantined-bad-version\", manifest };\n }\n return { kind: \"runtime-bundle-update\", manifest };\n };\n\n downloadAndInstallUpdate = async (\n manifest: UpdateManifest,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<NpmRuntimeDownloadedUpdate> => {\n const bytes = await this.downloadBundleBytes(manifest, reportProgress);\n const stagingRoot = join(this.options.layout.getStagingDir(), `download-${manifest.latestVersion}-${this.now()}`);\n await rm(stagingRoot, { recursive: true, force: true });\n mkdirSync(stagingRoot, { recursive: true });\n\n try {\n const zip = await JSZip.loadAsync(bytes);\n const entries = Object.values(zip.files) as JSZip.JSZipObject[];\n await Promise.all(entries.map(async (entry) => {\n const targetPath = resolve(stagingRoot, entry.name);\n const resolvedStagingRoot = resolve(stagingRoot);\n if (targetPath !== resolvedStagingRoot && !targetPath.startsWith(`${resolvedStagingRoot}${sep}`)) {\n throw new Error(`runtime bundle archive contains invalid path: ${entry.name}`);\n }\n if (entry.dir) {\n mkdirSync(targetPath, { recursive: true });\n return;\n }\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, Buffer.from(await entry.async(\"uint8array\")));\n const unixMode = this.readArchiveUnixMode(entry);\n if (unixMode !== null && this.platform !== \"win32\") {\n chmodSync(targetPath, unixMode);\n }\n }));\n const bundleRoot = this.findBundleRoot(stagingRoot);\n const installedBundle = await this.options.bundleService.installFromDirectory(bundleRoot);\n return {\n manifest,\n downloadedVersion: installedBundle.manifest.bundleVersion,\n bundleDirectory: installedBundle.bundleDirectory\n };\n } catch (error) {\n await rm(stagingRoot, { recursive: true, force: true });\n throw error;\n }\n };\n\n private readArchiveUnixMode = (entry: JSZip.JSZipObject): number | null => {\n const rawMode = entry.unixPermissions;\n const parsedMode = typeof rawMode === \"number\"\n ? rawMode\n : typeof rawMode === \"string\"\n ? Number.parseInt(rawMode, 8)\n : Number.NaN;\n if (!Number.isInteger(parsedMode)) {\n return null;\n }\n const permissionBits = parsedMode & 0o777;\n return permissionBits > 0 ? permissionBits : null;\n };\n\n private downloadBundleBytes = async (\n manifest: UpdateManifest,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<Buffer> => {\n const response = await this.fetchBundle(manifest.bundleUrl);\n const bytes = await this.readResponseBytes(response, reportProgress);\n const sha256 = createHash(\"sha256\").update(bytes).digest(\"hex\");\n if (sha256 !== manifest.bundleSha256) {\n throw new Error(`runtime bundle sha256 mismatch: expected ${manifest.bundleSha256} but got ${sha256}`);\n }\n this.assertBundleSignature(manifest, bytes);\n return bytes;\n };\n\n private fetchManifest = async (manifestUrl: string): Promise<UpdateManifest> => {\n if (manifestUrl.startsWith(\"file://\")) {\n const manifest = this.manifestReader.parse(JSON.parse(readFileSync(fileURLToPath(manifestUrl), \"utf8\")), manifestUrl);\n return this.verifyManifest(manifest, manifestUrl);\n }\n const response = await this.fetchImpl(manifestUrl);\n if (!response.ok) {\n throw new Error(`runtime update manifest request failed with status ${response.status}`);\n }\n const manifest = this.manifestReader.parse(await response.json(), manifestUrl);\n return this.verifyManifest(manifest, manifestUrl);\n };\n\n private verifyManifest = (manifest: UpdateManifest, _manifestUrl: string): UpdateManifest => {\n if (manifest.hostKind && manifest.hostKind !== \"npm-runtime-bundle\") {\n throw new Error(`runtime update manifest hostKind mismatch: expected npm-runtime-bundle but got ${manifest.hostKind}`);\n }\n if (manifest.channel !== \"stable\" && manifest.channel !== \"beta\") {\n throw new Error(`runtime update manifest channel is unsupported: ${manifest.channel}`);\n }\n if (manifest.platform !== this.platform) {\n throw new Error(`runtime update manifest platform mismatch: expected ${this.platform} but got ${manifest.platform}`);\n }\n if (manifest.arch !== this.arch) {\n throw new Error(`runtime update manifest arch mismatch: expected ${this.arch} but got ${manifest.arch}`);\n }\n this.assertManifestSignature(manifest);\n return manifest;\n };\n\n private fetchBundle = async (bundleUrl: string): Promise<Response> => {\n if (bundleUrl.startsWith(\"file://\")) {\n const bytes = readFileSync(fileURLToPath(bundleUrl));\n return new Response(bytes, {\n status: 200,\n headers: {\n \"content-length\": String(bytes.byteLength)\n }\n });\n }\n const response = await this.fetchImpl(bundleUrl);\n if (!response.ok) {\n throw new Error(`runtime bundle download failed with status ${response.status}`);\n }\n return response;\n };\n\n private readResponseBytes = async (\n response: Response,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<Buffer> => {\n const totalBytes = this.readContentLength(response);\n if (!response.body) {\n const bytes = Buffer.from(await response.arrayBuffer());\n this.reportDownloadProgress(reportProgress, bytes.byteLength, totalBytes ?? bytes.byteLength);\n return bytes;\n }\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let downloadedBytes = 0;\n this.reportDownloadProgress(reportProgress, downloadedBytes, totalBytes);\n while (true) {\n const next = await reader.read();\n if (next.done) {\n break;\n }\n chunks.push(next.value);\n downloadedBytes += next.value.byteLength;\n this.reportDownloadProgress(reportProgress, downloadedBytes, totalBytes);\n }\n return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));\n };\n\n private readContentLength = (response: Response): number | null => {\n const raw = response.headers.get(\"content-length\");\n if (!raw) {\n return null;\n }\n const parsed = Number(raw);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;\n };\n\n private reportDownloadProgress = (\n reportProgress: NpmRuntimeUpdateProgressReporter | undefined,\n downloadedBytes: number,\n totalBytes: number | null\n ): void => {\n reportProgress?.({\n downloadedBytes,\n totalBytes,\n percent: totalBytes && totalBytes > 0 ? Math.min(100, Math.round((downloadedBytes / totalBytes) * 100)) : null\n });\n };\n\n private findBundleRoot = (stagingRoot: string): string => {\n const directManifestPath = join(stagingRoot, \"manifest.json\");\n if (existsSync(directManifestPath)) {\n return stagingRoot;\n }\n const entries = readDirectoryNames(stagingRoot).filter((entry) => existsSync(join(stagingRoot, entry, \"manifest.json\")));\n if (entries.length === 1) {\n return join(stagingRoot, entries[0]);\n }\n throw new Error(`runtime bundle archive does not contain exactly one manifest root under ${stagingRoot}`);\n };\n\n private parseBundlePublicKey = (publicKey: string | undefined): KeyObject | null => {\n const normalizedKey = publicKey?.trim();\n if (!normalizedKey) {\n return null;\n }\n const pemOrEscapedPem = normalizedKey.replaceAll(\"\\\\n\", \"\\n\");\n if (pemOrEscapedPem.includes(\"BEGIN PUBLIC KEY\")) {\n return createPublicKey(pemOrEscapedPem);\n }\n return createPublicKey({\n key: Buffer.from(normalizedKey, \"base64\"),\n format: \"der\",\n type: \"spki\"\n });\n };\n\n private assertManifestSignature = (manifest: UpdateManifest): void => {\n if (!this.bundlePublicKey) {\n throw new Error(\"runtime update manifest signature verification requires bundlePublicKey\");\n }\n const signature = Buffer.from(manifest.manifestSignature, \"base64\");\n const valid = verify(null, Buffer.from(serializeUnsignedUpdateManifest(manifest)), this.bundlePublicKey, signature);\n if (!valid) {\n throw new Error(`runtime update manifest signature verification failed for ${manifest.latestVersion}`);\n }\n };\n\n private assertBundleSignature = (manifest: UpdateManifest, bytes: Buffer): void => {\n if (!this.bundlePublicKey) {\n throw new Error(\"runtime bundle signature verification requires bundlePublicKey\");\n }\n const signature = Buffer.from(manifest.bundleSignature, \"base64\");\n const valid = verify(null, bytes, this.bundlePublicKey, signature);\n if (!valid) {\n throw new Error(`runtime bundle signature verification failed for ${manifest.latestVersion}`);\n }\n };\n}\n\nfunction readDirectoryNames(directory: string): string[] {\n return readdirSync(directory, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n}\n"],"mappings":";;;;;;;;;AAqCA,IAAa,0BAAb,MAAqC;CACnC;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA0D;AAAzC,OAAA,UAAA;AAC3B,OAAK,WAAW,QAAQ,YAAY,QAAQ;AAC5C,OAAK,OAA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AM;AACvC,MAAI,CAAC,cACH,QAAO;EAET,MAAM,kBAAkB,cAAc,WAAW,OAAO,KAAK;AAC7D,MAAI,gBAAgB,SAAS,mBAAmB,CAC9C,QAAO,gBAAgB,gBAAgB;AAEzC,SAAO,gBAAgB;GACrB,KAAK,OAAO,KAAK,eAAe,SAAS;GACzC,QAAQ;GACR,MAAM;GACP,CAAC;;CAGJ,2BAAmC,aAAmC;AACpE,MAAI,CAAC,KAAK,gBACR,OAAM,IAAI,MAAM,0EAA0E;EAE5F,MAAM,YAAY,OAAO,KAAK,SAAS,mBAAmB,SAAS;AAEnE,MAAI,CADU,OAAO,MAAM,OAAO,KAAK,gCAAgC,SAAS,CAAC,EAAE,KAAK,iBAAiB,UAAU,CAEjH,OAAM,IAAI,MAAM,6DAA6D,SAAS,gBAAgB;;CAI1G,yBAAiC,UAA0B,UAAwB;AACjF,MAAI,CAAC,KAAK,gBACR,OAAM,IAAI,MAAM,iEAAiE;EAEnF,MAAM,YAAY,OAAO,KAAK,SAAS,iBAAiB,SAAS;AAEjE,MAAI,CADU,OAAO,MAAM,OAAO,KAAK,iBAAiB,UAAU,CAEhE,OAAM,IAAI,MAAM,oDAAoD,SAAS,gBAAgB;;;AAKnG,SAAS,mBAAmB,WAA6B;AACvD,QAAO,YAAY,WAAW,EAAE,eAAe,MAAM,CAAC,CACnD,QAAQ,UAAU,MAAM,aAAa,CAAC,CACtC,KAAK,UAAU,MAAM,KAAK"}
1
+ {"version":3,"file":"npm-runtime-update.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update.service.ts"],"sourcesContent":["import { createHash, createPublicKey, verify, type KeyObject } from \"node:crypto\";\nimport { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport JSZip from \"jszip\";\nimport {\n serializeUnsignedUpdateManifest,\n UpdateManifestReader,\n type UpdateManifest\n} from \"@nextclaw/kernel\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { compareNpmRuntimeVersions, type NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type {\n NpmRuntimeDownloadedUpdate,\n NpmRuntimeUpdateProgressReporter\n} from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype FetchLike = typeof fetch;\n\ntype NpmRuntimeUpdateServiceOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n bundleService: NpmRuntimeBundleService;\n launcherVersion: string;\n bundlePublicKey?: string;\n fetchImpl?: FetchLike;\n platform?: NodeJS.Platform;\n arch?: string;\n manifestReader?: UpdateManifestReader;\n now?: () => number;\n};\n\nexport type NpmRuntimeAvailableUpdate =\n | { kind: \"runtime-bundle-update\"; manifest: UpdateManifest }\n | { kind: \"host-update-required\"; manifest: UpdateManifest }\n | { kind: \"quarantined-bad-version\"; manifest: UpdateManifest };\n\nexport class NpmRuntimeUpdateService {\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly fetchImpl: FetchLike;\n private readonly manifestReader: UpdateManifestReader;\n private readonly bundlePublicKey: KeyObject | null;\n private readonly now: () => number;\n\n constructor(private readonly options: NpmRuntimeUpdateServiceOptions) {\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.fetchImpl = options.fetchImpl ?? fetch;\n this.manifestReader = options.manifestReader ?? new UpdateManifestReader();\n this.bundlePublicKey = this.parseBundlePublicKey(options.bundlePublicKey);\n this.now = options.now ?? Date.now;\n }\n\n hasSignatureVerifier = (): boolean => Boolean(this.bundlePublicKey);\n\n checkForUpdate = async (manifestUrl: string, currentVersion: string | null, badVersions: string[] = []): Promise<NpmRuntimeAvailableUpdate | null> => {\n return await this.checkForUpdates([manifestUrl], currentVersion, badVersions);\n };\n\n checkForUpdates = async (manifestUrls: string[], currentVersion: string | null, badVersions: string[] = []): Promise<NpmRuntimeAvailableUpdate | null> => {\n const manifests = await Promise.all([...new Set(manifestUrls)].map(this.fetchManifest));\n const manifest = manifests.reduce<UpdateManifest | null>((selected, candidate) => {\n if (!selected) {\n return candidate;\n }\n const versionComparison = compareNpmRuntimeVersions(candidate.latestVersion, selected.latestVersion);\n if (versionComparison > 0 || (versionComparison === 0 && candidate.channel === \"stable\")) {\n return candidate;\n }\n return selected;\n }, null);\n if (!manifest) {\n return null;\n }\n if (currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, currentVersion) <= 0) {\n return null;\n }\n if (!currentVersion && compareNpmRuntimeVersions(manifest.latestVersion, this.options.launcherVersion) < 0) {\n return null;\n }\n if (compareNpmRuntimeVersions(this.options.launcherVersion, manifest.minimumLauncherVersion) < 0) {\n return { kind: \"host-update-required\", manifest };\n }\n if (badVersions.includes(manifest.latestVersion)) {\n return { kind: \"quarantined-bad-version\", manifest };\n }\n return { kind: \"runtime-bundle-update\", manifest };\n };\n\n downloadAndInstallUpdate = async (\n manifest: UpdateManifest,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<NpmRuntimeDownloadedUpdate> => {\n const bytes = await this.downloadBundleBytes(manifest, reportProgress);\n const stagingRoot = join(this.options.layout.getStagingDir(), `download-${manifest.latestVersion}-${this.now()}`);\n await rm(stagingRoot, { recursive: true, force: true });\n mkdirSync(stagingRoot, { recursive: true });\n\n try {\n const zip = await JSZip.loadAsync(bytes);\n const entries = Object.values(zip.files) as JSZip.JSZipObject[];\n await Promise.all(entries.map(async (entry) => {\n const targetPath = resolve(stagingRoot, entry.name);\n const resolvedStagingRoot = resolve(stagingRoot);\n if (targetPath !== resolvedStagingRoot && !targetPath.startsWith(`${resolvedStagingRoot}${sep}`)) {\n throw new Error(`runtime bundle archive contains invalid path: ${entry.name}`);\n }\n if (entry.dir) {\n mkdirSync(targetPath, { recursive: true });\n return;\n }\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, Buffer.from(await entry.async(\"uint8array\")));\n const unixMode = this.readArchiveUnixMode(entry);\n if (unixMode !== null && this.platform !== \"win32\") {\n chmodSync(targetPath, unixMode);\n }\n }));\n const bundleRoot = this.findBundleRoot(stagingRoot);\n const installedBundle = await this.options.bundleService.installFromDirectory(bundleRoot);\n return {\n manifest,\n downloadedVersion: installedBundle.manifest.bundleVersion,\n bundleDirectory: installedBundle.bundleDirectory\n };\n } catch (error) {\n await rm(stagingRoot, { recursive: true, force: true });\n throw error;\n }\n };\n\n private readArchiveUnixMode = (entry: JSZip.JSZipObject): number | null => {\n const rawMode = entry.unixPermissions;\n const parsedMode = typeof rawMode === \"number\"\n ? rawMode\n : typeof rawMode === \"string\"\n ? Number.parseInt(rawMode, 8)\n : Number.NaN;\n if (!Number.isInteger(parsedMode)) {\n return null;\n }\n const permissionBits = parsedMode & 0o777;\n return permissionBits > 0 ? permissionBits : null;\n };\n\n private downloadBundleBytes = async (\n manifest: UpdateManifest,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<Buffer> => {\n const response = await this.fetchBundle(manifest.bundleUrl);\n const bytes = await this.readResponseBytes(response, reportProgress);\n const sha256 = createHash(\"sha256\").update(bytes).digest(\"hex\");\n if (sha256 !== manifest.bundleSha256) {\n throw new Error(`runtime bundle sha256 mismatch: expected ${manifest.bundleSha256} but got ${sha256}`);\n }\n this.assertBundleSignature(manifest, bytes);\n return bytes;\n };\n\n private fetchManifest = async (manifestUrl: string): Promise<UpdateManifest> => {\n if (manifestUrl.startsWith(\"file://\")) {\n const manifest = this.manifestReader.parse(JSON.parse(readFileSync(fileURLToPath(manifestUrl), \"utf8\")), manifestUrl);\n return this.verifyManifest(manifest, manifestUrl);\n }\n const response = await this.fetchImpl(manifestUrl);\n if (!response.ok) {\n throw new Error(`runtime update manifest request failed with status ${response.status}`);\n }\n const manifest = this.manifestReader.parse(await response.json(), manifestUrl);\n return this.verifyManifest(manifest, manifestUrl);\n };\n\n private verifyManifest = (manifest: UpdateManifest, _manifestUrl: string): UpdateManifest => {\n if (manifest.hostKind && manifest.hostKind !== \"npm-runtime-bundle\") {\n throw new Error(`runtime update manifest hostKind mismatch: expected npm-runtime-bundle but got ${manifest.hostKind}`);\n }\n if (manifest.channel !== \"stable\" && manifest.channel !== \"beta\") {\n throw new Error(`runtime update manifest channel is unsupported: ${manifest.channel}`);\n }\n if (manifest.platform !== this.platform) {\n throw new Error(`runtime update manifest platform mismatch: expected ${this.platform} but got ${manifest.platform}`);\n }\n if (manifest.arch !== this.arch) {\n throw new Error(`runtime update manifest arch mismatch: expected ${this.arch} but got ${manifest.arch}`);\n }\n this.assertManifestSignature(manifest);\n return manifest;\n };\n\n private fetchBundle = async (bundleUrl: string): Promise<Response> => {\n if (bundleUrl.startsWith(\"file://\")) {\n const bytes = readFileSync(fileURLToPath(bundleUrl));\n return new Response(bytes, {\n status: 200,\n headers: {\n \"content-length\": String(bytes.byteLength)\n }\n });\n }\n const response = await this.fetchImpl(bundleUrl);\n if (!response.ok) {\n throw new Error(`runtime bundle download failed with status ${response.status}`);\n }\n return response;\n };\n\n private readResponseBytes = async (\n response: Response,\n reportProgress?: NpmRuntimeUpdateProgressReporter\n ): Promise<Buffer> => {\n const totalBytes = this.readContentLength(response);\n if (!response.body) {\n const bytes = Buffer.from(await response.arrayBuffer());\n this.reportDownloadProgress(reportProgress, bytes.byteLength, totalBytes ?? bytes.byteLength);\n return bytes;\n }\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let downloadedBytes = 0;\n this.reportDownloadProgress(reportProgress, downloadedBytes, totalBytes);\n while (true) {\n const next = await reader.read();\n if (next.done) {\n break;\n }\n chunks.push(next.value);\n downloadedBytes += next.value.byteLength;\n this.reportDownloadProgress(reportProgress, downloadedBytes, totalBytes);\n }\n return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));\n };\n\n private readContentLength = (response: Response): number | null => {\n const raw = response.headers.get(\"content-length\");\n if (!raw) {\n return null;\n }\n const parsed = Number(raw);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;\n };\n\n private reportDownloadProgress = (\n reportProgress: NpmRuntimeUpdateProgressReporter | undefined,\n downloadedBytes: number,\n totalBytes: number | null\n ): void => {\n reportProgress?.({\n downloadedBytes,\n totalBytes,\n percent: totalBytes && totalBytes > 0 ? Math.min(100, Math.round((downloadedBytes / totalBytes) * 100)) : null\n });\n };\n\n private findBundleRoot = (stagingRoot: string): string => {\n const directManifestPath = join(stagingRoot, \"manifest.json\");\n if (existsSync(directManifestPath)) {\n return stagingRoot;\n }\n const entries = readDirectoryNames(stagingRoot).filter((entry) => existsSync(join(stagingRoot, entry, \"manifest.json\")));\n if (entries.length === 1) {\n return join(stagingRoot, entries[0]);\n }\n throw new Error(`runtime bundle archive does not contain exactly one manifest root under ${stagingRoot}`);\n };\n\n private parseBundlePublicKey = (publicKey: string | undefined): KeyObject | null => {\n const normalizedKey = publicKey?.trim();\n if (!normalizedKey) {\n return null;\n }\n const pemOrEscapedPem = normalizedKey.replaceAll(\"\\\\n\", \"\\n\");\n if (pemOrEscapedPem.includes(\"BEGIN PUBLIC KEY\")) {\n return createPublicKey(pemOrEscapedPem);\n }\n return createPublicKey({\n key: Buffer.from(normalizedKey, \"base64\"),\n format: \"der\",\n type: \"spki\"\n });\n };\n\n private assertManifestSignature = (manifest: UpdateManifest): void => {\n if (!this.bundlePublicKey) {\n throw new Error(\"runtime update manifest signature verification requires bundlePublicKey\");\n }\n const signature = Buffer.from(manifest.manifestSignature, \"base64\");\n const valid = verify(null, Buffer.from(serializeUnsignedUpdateManifest(manifest)), this.bundlePublicKey, signature);\n if (!valid) {\n throw new Error(`runtime update manifest signature verification failed for ${manifest.latestVersion}`);\n }\n };\n\n private assertBundleSignature = (manifest: UpdateManifest, bytes: Buffer): void => {\n if (!this.bundlePublicKey) {\n throw new Error(\"runtime bundle signature verification requires bundlePublicKey\");\n }\n const signature = Buffer.from(manifest.bundleSignature, \"base64\");\n const valid = verify(null, bytes, this.bundlePublicKey, signature);\n if (!valid) {\n throw new Error(`runtime bundle signature verification failed for ${manifest.latestVersion}`);\n }\n };\n}\n\nfunction readDirectoryNames(directory: string): string[] {\n return readdirSync(directory, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n}\n"],"mappings":";;;;;;;;;AAqCA,IAAa,0BAAb,MAAqC;CACnC;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA0D;AAAzC,OAAA,UAAA;AAC3B,OAAK,WAAW,QAAQ,YAAY,QAAQ;AAC5C,OAAK,OAAO,QAAQ,QAAQ,QAAQ;AACpC,OAAK,YAAY,QAAQ,aAAa;AACtC,OAAK,iBAAiB,QAAQ,kBAAkB,IAAI,sBAAsB;AAC1E,OAAK,kBAAkB,KAAK,qBAAqB,QAAQ,gBAAgB;AACzE,OAAK,MAAM,QAAQ,OAAO,KAAK;;CAGjC,6BAAsC,QAAQ,KAAK,gBAAgB;CAEnE,iBAAiB,OAAO,aAAqB,gBAA+B,cAAwB,EAAE,KAAgD;AACpJ,SAAO,MAAM,KAAK,gBAAgB,CAAC,YAAY,EAAE,gBAAgB,YAAY;;CAG/E,kBAAkB,OAAO,cAAwB,gBAA+B,cAAwB,EAAE,KAAgD;EAExJ,MAAM,YADY,MAAM,QAAQ,IAAI,CAAC,GAAG,IAAI,IAAI,aAAa,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,EAC5D,QAA+B,UAAU,cAAc;AAChF,OAAI,CAAC,SACH,QAAO;GAET,MAAM,oBAAoB,0BAA0B,UAAU,eAAe,SAAS,cAAc;AACpG,OAAI,oBAAoB,KAAM,sBAAsB,KAAK,UAAU,YAAY,SAC7E,QAAO;AAET,UAAO;KACN,KAAK;AACR,MAAI,CAAC,SACH,QAAO;AAET,MAAI,kBAAkB,0BAA0B,SAAS,eAAe,eAAe,IAAI,EACzF,QAAO;AAET,MAAI,CAAC,kBAAkB,0BAA0B,SAAS,eAAe,KAAK,QAAQ,gBAAgB,GAAG,EACvG,QAAO;AAET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,SAAS,gBAAgB;;CAI1G,yBAAiC,UAA0B,UAAwB;AACjF,MAAI,CAAC,KAAK,gBACR,OAAM,IAAI,MAAM,iEAAiE;EAEnF,MAAM,YAAY,OAAO,KAAK,SAAS,iBAAiB,SAAS;AAEjE,MAAI,CADU,OAAO,MAAM,OAAO,KAAK,iBAAiB,UAAU,CAEhE,OAAM,IAAI,MAAM,oDAAoD,SAAS,gBAAgB;;;AAKnG,SAAS,mBAAmB,WAA6B;AACvD,QAAO,YAAY,WAAW,EAAE,eAAe,MAAM,CAAC,CACnD,QAAQ,UAAU,MAAM,aAAa,CAAC,CACtC,KAAK,UAAU,MAAM,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/service",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "private": false,
5
5
  "description": "NextClaw long-running service host and runtime lifecycle.",
6
6
  "type": "module",
@@ -42,31 +42,31 @@
42
42
  "chokidar": "^3.6.0",
43
43
  "commander": "^12.1.0",
44
44
  "jszip": "^3.10.1",
45
- "@nextclaw/channel-extension-dingtalk": "0.2.42",
46
- "@nextclaw/channel-extension-email": "0.2.42",
47
- "@nextclaw/channel-extension-feishu": "0.2.32",
48
- "@nextclaw/channel-extension-discord": "0.2.42",
49
- "@nextclaw/channel-extension-qq": "0.2.31",
50
- "@nextclaw/channel-extension-slack": "0.2.42",
51
- "@nextclaw/channel-extension-telegram": "0.2.42",
52
- "@nextclaw/channel-extension-wecom": "0.2.42",
53
- "@nextclaw/channel-extension-weixin": "0.2.32",
54
- "@nextclaw/channel-extension-whatsapp": "0.2.42",
55
- "@nextclaw/core": "0.17.16",
56
- "@nextclaw/client-sdk": "0.11.1",
57
- "@nextclaw/kernel": "0.15.1",
58
- "@nextclaw/mcp": "0.3.43",
45
+ "@nextclaw/channel-extension-dingtalk": "0.2.44",
46
+ "@nextclaw/channel-extension-discord": "0.2.44",
47
+ "@nextclaw/channel-extension-slack": "0.2.44",
48
+ "@nextclaw/channel-extension-email": "0.2.44",
49
+ "@nextclaw/channel-extension-telegram": "0.2.44",
50
+ "@nextclaw/channel-extension-feishu": "0.2.33",
51
+ "@nextclaw/channel-extension-qq": "0.2.32",
52
+ "@nextclaw/channel-extension-wecom": "0.2.44",
53
+ "@nextclaw/channel-extension-weixin": "0.2.33",
54
+ "@nextclaw/client-sdk": "0.12.0",
55
+ "@nextclaw/channel-extension-whatsapp": "0.2.44",
56
+ "@nextclaw/core": "0.17.18",
57
+ "@nextclaw/kernel": "0.16.0",
58
+ "@nextclaw/mcp": "0.3.45",
59
59
  "@nextclaw/ncp": "0.10.0",
60
60
  "@nextclaw/ncp-agent-runtime": "0.4.22",
61
- "@nextclaw/ncp-mcp": "0.2.43",
61
+ "@nextclaw/ncp-mcp": "0.2.45",
62
62
  "@nextclaw/ncp-toolkit": "0.6.23",
63
63
  "@nextclaw/nextclaw-ncp-runtime-http-client": "0.3.22",
64
- "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.3.43",
65
- "@nextclaw/remote": "0.3.55",
66
- "@nextclaw/server": "0.22.1",
67
- "@nextclaw/runtime": "0.4.42",
68
- "@nextclaw/shared": "0.5.0",
69
- "@nextclaw/nextclaw-hermes-acp-bridge": "0.3.21"
64
+ "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.3.45",
65
+ "@nextclaw/nextclaw-hermes-acp-bridge": "0.3.21",
66
+ "@nextclaw/remote": "0.3.57",
67
+ "@nextclaw/runtime": "0.4.44",
68
+ "@nextclaw/shared": "0.5.1",
69
+ "@nextclaw/server": "0.23.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/node": "^20.17.6",