akanjs 3.3.0 → 3.4.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/common/PipelinePlanSchema.ts +31 -7
  2. package/common/index.ts +6 -0
  3. package/common/pipelinePlan.ts +31 -5
  4. package/index.ts +7 -5
  5. package/package.json +1 -1
  6. package/pipelineConfig.ts +25 -2
  7. package/service/agentLoop/agentLoop.ts +19 -12
  8. package/service/predefinedAdaptor/anthropicTools.ts +8 -2
  9. package/types/common/index.d.ts +1 -1
  10. package/types/common/pipelinePlan.d.ts +35 -6
  11. package/types/index.d.ts +7 -5
  12. package/types/pipelineConfig.d.ts +20 -3
  13. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  14. package/types/service/predefinedAdaptor/anthropicTools.d.ts +1 -0
  15. package/types/vendor/@akanjs/native/packages/cli/src/api-updates.d.ts +149 -0
  16. package/types/vendor/@akanjs/native/packages/cli/src/api.d.ts +16 -162
  17. package/types/vendor/@akanjs/native/packages/cli/src/config.d.ts +3 -2
  18. package/types/vendor/@akanjs/native/packages/cli/src/lib/api-task.d.ts +79 -0
  19. package/types/vendor/@akanjs/native/packages/cli/src/lib/prepare.d.ts +1 -1
  20. package/types/vendor/@akanjs/native/packages/cli/src/lib/publish.d.ts +17 -5
  21. package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +29 -2
  22. package/types/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.d.ts +36 -0
  23. package/types/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.d.ts +15 -0
  24. package/types/vendor/@akanjs/native/packages/core/src/kernel.d.ts +16 -5
  25. package/types/vendor/@akanjs/native/packages/desktop/src/commands.d.ts +81 -0
  26. package/types/vendor/@akanjs/native/packages/desktop/src/deeplinks.d.ts +5 -1
  27. package/types/vendor/@akanjs/native/packages/desktop/src/dispatcher.d.ts +3 -0
  28. package/types/vendor/@akanjs/native/packages/desktop/src/lifecycle.d.ts +8 -1
  29. package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +21 -0
  30. package/types/vendor/@akanjs/native/packages/desktop/src/server.d.ts +1 -0
  31. package/types/vendor/@akanjs/native/plugins/updates/src/desktop.d.ts +4 -4
  32. package/types/vendor/@akanjs/native/plugins/updates/src/reports.d.ts +49 -0
  33. package/types/vendor/@akanjs/native/plugins/updates/src/signer.d.ts +21 -0
  34. package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +55 -3
  35. package/vendor/@akanjs/native/native/desktop/src/lib.rs +209 -54
  36. package/vendor/@akanjs/native/packages/cli/src/api-updates.ts +332 -0
  37. package/vendor/@akanjs/native/packages/cli/src/api.ts +67 -419
  38. package/vendor/@akanjs/native/packages/cli/src/commands/build.ts +4 -1
  39. package/vendor/@akanjs/native/packages/cli/src/config.ts +3 -2
  40. package/vendor/@akanjs/native/packages/cli/src/lib/api-task.ts +223 -0
  41. package/vendor/@akanjs/native/packages/cli/src/lib/prepare.ts +2 -7
  42. package/vendor/@akanjs/native/packages/cli/src/lib/publish.ts +164 -19
  43. package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +90 -3
  44. package/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.ts +195 -43
  45. package/vendor/@akanjs/native/packages/cli/src/platforms/linux-appimage.ts +1 -1
  46. package/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.ts +206 -0
  47. package/vendor/@akanjs/native/packages/cli/src/platforms/linux.ts +5 -1
  48. package/vendor/@akanjs/native/packages/core/src/kernel.ts +21 -6
  49. package/vendor/@akanjs/native/packages/core/vectors/updates.json +2 -1
  50. package/vendor/@akanjs/native/packages/desktop/src/commands.ts +380 -0
  51. package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +20 -3
  52. package/vendor/@akanjs/native/packages/desktop/src/dispatcher.ts +28 -13
  53. package/vendor/@akanjs/native/packages/desktop/src/host.ts +6 -18
  54. package/vendor/@akanjs/native/packages/desktop/src/lifecycle.ts +8 -1
  55. package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +21 -0
  56. package/vendor/@akanjs/native/packages/desktop/src/server.ts +1 -1
  57. package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +90 -164
  58. package/vendor/@akanjs/native/plugins/updates/src/reports.ts +255 -0
  59. package/vendor/@akanjs/native/plugins/updates/src/signer.ts +133 -0
  60. package/vendor/@akanjs/native/plugins/window/native-plugin.json +6 -1
  61. package/vendor/@akanjs/native/plugins/window/src/desktop.ts +20 -4
  62. package/vendor/@akanjs/native/plugins/window/src/index.ts +55 -3
@@ -0,0 +1,332 @@
1
+
2
+
3
+ import { mkdirSync, writeFileSync } from "node:fs";
4
+ import { join, resolve } from "node:path";
5
+ import type { AkanNativeConfig } from "./config.ts";
6
+ import {
7
+ AkanNativeError,
8
+ type BuildResult,
9
+ buildIn,
10
+ type TaskOptions,
11
+ task,
12
+ toAkanNativeError,
13
+ } from "./lib/api-task.ts";
14
+ import { makeNativeBoot } from "./lib/boot.ts";
15
+ import { BUNDLE_FILE, compatProblems, readBundleInfo } from "./lib/compat.ts";
16
+ import type { MacosBuild } from "./lib/macossigning.ts";
17
+ import { prepare, type WindowsBuild } from "./lib/prepare.ts";
18
+ import { type Project, projectFromConfig } from "./lib/project.ts";
19
+ import {
20
+ assertServerOfChannel,
21
+ assertSigningKey,
22
+ publishRelease,
23
+ releaseRevocations,
24
+ republishRelease,
25
+ } from "./lib/publish.ts";
26
+ import {
27
+ assertChannel,
28
+ type DesktopArch,
29
+ generateUpdateKey,
30
+ hostArch,
31
+ keyIdOf,
32
+ type UpdateManifest,
33
+ updateKeyPath,
34
+ validateUpdates,
35
+ webManifest,
36
+ writeWebBundle,
37
+ } from "./lib/updates.ts";
38
+ import type { DesktopOs } from "./platforms/desktop.ts";
39
+ import {
40
+ type AppSigner,
41
+ appSigner,
42
+ PACK_TEMPLATE,
43
+ packAppUpdate as packApp,
44
+ readAppArchive,
45
+ } from "./platforms/desktop-update.ts";
46
+ import type { TargetPlatform } from "./platforms/index.ts";
47
+
48
+ /**
49
+ * An unsigned web bundle update (UP-2), for a signer that keeps the key off the build machine. Writes
50
+ * `<out>/files/<sha256>`, `<out>/manifest.template.json` (the manifest with `channel`, `sequence` and `bundle` left
51
+ * empty for the signer) and `<out>/bundle.json` (the native API the bundle needs, UP-3). Prepares the web bundle as a
52
+ * release build does, without building the native app.
53
+ */
54
+ export function packUpdate(
55
+ options: TaskOptions & { platform: "ios" | "android"; out: string },
56
+ ): Promise<{ manifest: UpdateManifest; out: string }> {
57
+ return task(options, async () => {
58
+ const appDir = resolve(options.appDir);
59
+ let project: Project;
60
+ try {
61
+ project = projectFromConfig(options.config, appDir, { resolveFrom: options.resolveFrom });
62
+ } catch (error) {
63
+ throw toAkanNativeError(error, "CONFIG_INVALID");
64
+ }
65
+
66
+ const out = resolve(options.out);
67
+ mkdirSync(out, { recursive: true });
68
+ const ctx = await prepare(project, options.platform, {
69
+ mode: options.mode ?? "production",
70
+ profile: "release",
71
+ skipWebBuild: options.skipWebBuild ?? false,
72
+ outDir: out,
73
+ envFiles: options.envFiles,
74
+ env: options.env,
75
+ api: true,
76
+ }).catch((error) => {
77
+ throw toAkanNativeError(error, "CONFIG_INVALID");
78
+ });
79
+ makeNativeBoot(ctx, options.platform);
80
+ const info = readBundleInfo(join(out, BUNDLE_FILE));
81
+ const manifest = webManifest({
82
+ app: project.config.app,
83
+ platform: options.platform,
84
+ channel: "",
85
+ nativeApi: info.nativeApi.hash,
86
+ sequence: 0,
87
+ bundle: "",
88
+ files: writeWebBundle(out, ctx.webDir, ctx.html, ctx.env),
89
+ });
90
+ writeFileSync(join(out, PACK_TEMPLATE), `${JSON.stringify(manifest, null, 2)}\n`);
91
+ return { manifest, out };
92
+ });
93
+ }
94
+
95
+ export interface AppUpdatePack {
96
+ build: BuildResult;
97
+ /** Holds `app/<tar sha256>.tar.gz`, `app/<from>-<to>.delta.gz` with `previous`, and `manifest.template.json`. */
98
+ out: string;
99
+ /** manifest.template.json: `channel`, `sequence` and `bundle` are the signer's to fill (fillManifest). */
100
+ manifest: UpdateManifest;
101
+ /**
102
+ * Who signed the app's files (not the update key): an installed app signed by a team or a certificate takes only a
103
+ * release signed by the same. null: ad hoc or unsigned, which only an app signed that way takes.
104
+ */
105
+ signer: AppSigner | null;
106
+ }
107
+
108
+ /**
109
+ * An unsigned desktop app update (UP-1), for a signer that keeps the key off the build machine: a release build, its
110
+ * archive as publishUpdate names it, and the manifest with `channel`, `sequence` and `bundle` left empty. The signer
111
+ * fills it (fillManifest), signs its bytes (manifestBytes) and wraps them (updateEnvelope, sealManifest); the envelope
112
+ * goes to `<os>-<arch>/<channel>/app.json` beside `app/`.
113
+ */
114
+ export function packAppUpdate(
115
+ options: TaskOptions & {
116
+ platform: DesktopOs;
117
+ out: string;
118
+ /** The signature a macOS release carries: the installed app's own, or the updater refuses it. No dmg is made. */
119
+ macos?: Pick<MacosBuild, "signing" | "notarize">;
120
+ /** Authenticode for a Windows release's files. No setup program is made. */
121
+ windows?: Pick<WindowsBuild, "signing">;
122
+ /** The CPU of the apps it updates, of the same OS. Default this computer's. */
123
+ arch?: DesktopArch;
124
+ /**
125
+ * The archive of the release the channel has now (`<tar sha256>.tar.gz`, a path or a URL of the feed): the pack
126
+ * then carries the delta from it, and the manifest names it in `patches`.
127
+ */
128
+ previous?: string;
129
+ },
130
+ ): Promise<AppUpdatePack> {
131
+ return task(options, async (warnings) => {
132
+ if (!options.config.updates)
133
+ throw new AkanNativeError("CONFIG_INVALID", "the config has no updates: { url, publicKeys } to pack for");
134
+ const out = resolve(options.out);
135
+ const previous = options.previous
136
+ ? await readAppArchive(options.previous).catch((error) => {
137
+ throw toAkanNativeError(error, "CONFIG_INVALID");
138
+ })
139
+ : undefined;
140
+ const { ctx, artifact, result } = await buildIn(options, "release", options.mode ?? "production", warnings, {
141
+ ...(options.macos ? { macos: { ...options.macos, dmg: false } } : {}),
142
+ ...(options.windows?.signing ? { windows: { signing: options.windows.signing } } : {}),
143
+ ...(options.arch ? { arch: options.arch } : {}),
144
+ });
145
+ mkdirSync(out, { recursive: true });
146
+ const { manifest } = await packApp(ctx, options.platform, artifact, out, previous);
147
+ const signer = await appSigner(options.platform, artifact, ctx.project.config.app.fileName);
148
+ return { build: result, out, manifest, signer };
149
+ });
150
+ }
151
+
152
+ export interface PublishResult {
153
+ build: BuildResult;
154
+ /** `<out>/<os>-<arch>` (desktop) or `<out>/<platform>` (a phone's web bundle): what to upload under updates.url. */
155
+ dir: string;
156
+ bundle: string;
157
+ channel: string;
158
+ files: number;
159
+ /** Bytes of the files the manifest names. */
160
+ size: number;
161
+ }
162
+
163
+ export interface PublishCheckOptions extends Pick<TaskOptions, "appDir" | "config"> {
164
+ platform: Exclude<TargetPlatform, "web">;
165
+ channel?: string;
166
+ out?: string;
167
+ /** Whether the release will carry a server; the config's `desktop.server` by default. */
168
+ server?: boolean;
169
+ /** A desktop release's CPU, which names its feed folder: this computer's by default. */
170
+ arch?: DesktopArch;
171
+ /**
172
+ * keyIds of updates.publicKeys the release starts revoking, beside updates.revokedKeys and what the channel's releases
173
+ * revoke. It is signed with a key listed after every key it revokes.
174
+ */
175
+ revoke?: string[];
176
+ /** A release that revokes a key: apps compare it with their own build instead of the running release. */
177
+ resetSequence?: boolean;
178
+ }
179
+
180
+ /**
181
+ * What publishUpdate() refuses before it builds, without building (CONFIG_INVALID): no updates settings, a channel no
182
+ * app could be configured for, no signing key on this machine or another app's, a desktop release whose server
183
+ * presence is not the channel's previous release's, and a release whose revocations no app would take. For a
184
+ * caller with a long build of its own before publishUpdate.
185
+ */
186
+ export function checkPublishUpdate(options: PublishCheckOptions): { channel: string; out: string } {
187
+ if (!options.config.updates)
188
+ throw new AkanNativeError("CONFIG_INVALID", "the config has no updates: { url, publicKeys } to publish for");
189
+ const channel = options.channel ?? options.config.updates.channel ?? "production";
190
+ const out = resolve(options.out ?? resolve(options.appDir, ".akan", "native", "updates"));
191
+ const problems: string[] = [];
192
+ const updates = validateUpdates(options.config.updates, problems);
193
+ if (!updates || problems.length)
194
+ throw new AkanNativeError("CONFIG_INVALID", "the config's updates are not valid", { problems });
195
+ try {
196
+ if (options.channel !== undefined) assertChannel(options.channel);
197
+ const target = { app: options.config.app, updates };
198
+ assertSigningKey(target);
199
+ releaseRevocations(target, options.platform, out, channel, options, options.arch);
200
+ const server = options.server ?? !!options.config.desktop?.server;
201
+ assertServerOfChannel({ desktop: server ? { server } : {} }, options.platform, out, channel, options.arch);
202
+ } catch (error) {
203
+ throw toAkanNativeError(error, "CONFIG_INVALID");
204
+ }
205
+ return { channel, out };
206
+ }
207
+
208
+ /**
209
+ * A signed release for the updates plugin (UP-1, UP-2): a release build, then its envelope and its files under `out`
210
+ * (default <appDir>/.akan/native/updates), signed with the key updateKeygen() made.
211
+ */
212
+ export function publishUpdate(
213
+ options: TaskOptions & {
214
+ platform: Exclude<TargetPlatform, "web">;
215
+ channel?: string;
216
+ out?: string;
217
+ /** The signature a macOS release carries: the installed app's own, or the updater refuses it. No dmg is made. */
218
+ macos?: Pick<MacosBuild, "signing" | "notarize">;
219
+ /** Authenticode for a Windows release's files. No setup program is made. */
220
+ windows?: Pick<WindowsBuild, "signing">;
221
+ /** A desktop release's CPU, of the same OS: an x64 release from an arm64 machine. Default this computer's. */
222
+ arch?: DesktopArch;
223
+ /** keyIds of updates.publicKeys the release starts revoking (PublishCheckOptions.revoke). */
224
+ revoke?: string[];
225
+ /** A release that revokes a key: apps compare it with their own build instead of the running release. */
226
+ resetSequence?: boolean;
227
+ },
228
+ ): Promise<PublishResult> {
229
+ return task(options, async (warnings) => {
230
+ const { channel, out } = checkPublishUpdate(options);
231
+ const { ctx, artifact, result } = await buildIn(options, "release", options.mode ?? "production", warnings, {
232
+ ...(options.macos ? { macos: { ...options.macos, dmg: false } } : {}),
233
+ ...(options.windows?.signing ? { windows: { signing: options.windows.signing } } : {}),
234
+ ...(options.arch ? { arch: options.arch } : {}),
235
+ });
236
+ const { dir, manifest } = await publishRelease(ctx, options.platform, artifact, out, channel, options).catch(
237
+ (error) => {
238
+ throw toAkanNativeError(error, "CONFIG_INVALID");
239
+ },
240
+ );
241
+ return {
242
+ build: result,
243
+ dir,
244
+ bundle: manifest.bundle,
245
+ channel,
246
+ files: manifest.files.length,
247
+ size: manifest.files.reduce((n, f) => n + f.size, 0),
248
+ };
249
+ });
250
+ }
251
+
252
+ /**
253
+ * Whether a web bundle can run in the binary a store release shipped (UP-3): `shipped` is that build's bundle.json,
254
+ * `bundle` the one `packUpdate` wrote. Anything in `problems` means a new binary.
255
+ */
256
+ export function compareBundles(shipped: string, bundle: string): { compatible: boolean; problems: string[] } {
257
+ const [before, now] = [readBundleInfo(resolve(shipped)), readBundleInfo(resolve(bundle))];
258
+ const problems =
259
+ before.app.id !== now.app.id
260
+ ? [`${shipped} is for ${before.app.id}, the bundle for ${now.app.id}`]
261
+ : compatProblems(before.nativeApi.inputs, now.nativeApi.inputs);
262
+ return { compatible: problems.length === 0, problems };
263
+ }
264
+
265
+ /**
266
+ * The app's update signing key: made once (AKAN_NATIVE_UPDATE_KEY, else ~/.akan/native/keys/<app id>.update.key),
267
+ * then read. `publicKey` goes into the config's `updates.publicKeys`; the key file never leaves the machine. `keyId`
268
+ * is what a revocation names it by (`publishUpdate({ revoke })`, `updates.revokedKeys`).
269
+ */
270
+ export function updateKeygen(options: { config: AkanNativeConfig }): {
271
+ publicKey: string;
272
+ keyId: string;
273
+ keyPath: string;
274
+ created: boolean;
275
+ } {
276
+ const keyPath = updateKeyPath(options.config.app.id);
277
+ const key = generateUpdateKey(keyPath);
278
+ return { ...key, keyId: keyIdOf(key.publicKey), keyPath };
279
+ }
280
+
281
+ export type RepublishResult = Omit<PublishResult, "build"> & {
282
+ /** The bundle id of the release that was signed again. */
283
+ from: string;
284
+ };
285
+
286
+ /**
287
+ * Signs a desktop release publishUpdate wrote under `out` again, as its channel's newest: the same archive under a new
288
+ * sequence and bundle id, with no patch and no build. Apps on any other build take it whole, which is how a release is
289
+ * rolled back by the one who holds the key. Refuses what checkPublishUpdate refuses.
290
+ */
291
+ export function republishUpdate(
292
+ options: Pick<TaskOptions, "appDir" | "config" | "resolveFrom" | "log" | "signal"> & {
293
+ platform: DesktopOs;
294
+ /** The release to sign again: its manifest's `bundle`. */
295
+ bundle: string;
296
+ channel?: string;
297
+ out?: string;
298
+ arch?: DesktopArch;
299
+ revoke?: string[];
300
+ resetSequence?: boolean;
301
+ },
302
+ ): Promise<RepublishResult> {
303
+ return task(options, async () => {
304
+ const { channel, out } = checkPublishUpdate({ ...options, server: undefined });
305
+ let project: Project;
306
+ try {
307
+ project = projectFromConfig(options.config, resolve(options.appDir), { resolveFrom: options.resolveFrom });
308
+ } catch (error) {
309
+ throw toAkanNativeError(error, "CONFIG_INVALID");
310
+ }
311
+ const { platform, bundle, arch = hostArch() } = options;
312
+ const { dir, manifest, from } = await republishRelease(
313
+ project,
314
+ platform,
315
+ bundle,
316
+ out,
317
+ channel,
318
+ options,
319
+ arch,
320
+ ).catch((error) => {
321
+ throw toAkanNativeError(error, "CONFIG_INVALID");
322
+ });
323
+ return {
324
+ dir,
325
+ bundle: manifest.bundle,
326
+ channel,
327
+ files: manifest.files.length,
328
+ size: manifest.files.reduce((n, f) => n + f.size, 0),
329
+ from: from.bundle,
330
+ };
331
+ });
332
+ }