@akanjs/cli 3.0.0-beta.1 → 3.0.0-beta.11

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 (60) hide show
  1. package/.build-stamp +1 -1
  2. package/TunnelShare-sbsaggmb.js +9 -0
  3. package/{abstractCompactor-mjh5ppsq.js → abstractCompactor-bqh31fk5.js} +2 -1
  4. package/{agent.command-d2gfxfck.js → agent.command-7357vxd8.js} +5 -5
  5. package/{application.command-pj2m7584.js → application.command-pc8mdn3w.js} +10 -10
  6. package/{applicationBuildRunner-kxwbssgn.js → applicationBuildRunner-4f1wrba0.js} +2 -2
  7. package/{applicationReleasePackager-4yasxwv9.js → applicationReleasePackager-jkjmy5ee.js} +1 -1
  8. package/buildBatch.proc.js +2 -2
  9. package/{capacitorApp-36rbr858.js → capacitorApp-hqvsrec4.js} +2 -2
  10. package/{cloud.command-jshwdq22.js → cloud.command-cawrd5nq.js} +12 -11
  11. package/cloud.script-1bmptvw0.js +20 -0
  12. package/commandManifest.json +1 -1
  13. package/{context.command-ez8a0zyz.js → context.command-982b6kdp.js} +14 -13
  14. package/{devTui-40ggmd99.js → devTui-hmteztv3.js} +4 -24
  15. package/{devTuiView-c08ccbat.js → devTuiView-40jvjnyz.js} +1 -1
  16. package/{guideline.command-xmqwx8zm.js → guideline.command-jn0vwszx.js} +4 -3
  17. package/guidelines/agentRule/agentRule.instruction.md +109 -4
  18. package/guidelines/conventions/conventions.instruction.md +19 -0
  19. package/guidelines/fieldRule/fieldRule.instruction.md +1 -0
  20. package/guidelines/transportRule/transportRule.instruction.md +49 -0
  21. package/incrementalBuilder.proc.js +1 -1
  22. package/{index-ktb5njgy.js → index-15r9a10e.js} +2 -2
  23. package/{index-259dsnz3.js → index-1nwxbr2y.js} +2 -2
  24. package/{index-600zhnve.js → index-3pvkjza8.js} +10 -10
  25. package/{index-2tv3fdx4.js → index-5nyznra1.js} +1 -0
  26. package/{index-wt7qrtd4.js → index-7f4dsf9v.js} +1 -1
  27. package/{index-7737gxcp.js → index-8pkvrcv1.js} +3 -3
  28. package/{index-2hq52jq3.js → index-8tfmh0v6.js} +25 -19
  29. package/{index-zry5nz81.js → index-ay8wj00x.js} +23 -14
  30. package/{index-mak3cd28.js → index-b3ae16mg.js} +25 -25
  31. package/index-bw2marpf.js +237 -0
  32. package/{index-rwg2aa4f.js → index-ceph7zqj.js} +3 -3
  33. package/{index-fz5q3gd7.js → index-em4swemt.js} +3 -3
  34. package/{index-8pm30m73.js → index-fr2x3qvv.js} +7 -7
  35. package/index-jcekapz4.js +49 -0
  36. package/{index-gyd220p2.js → index-jwjaf9fy.js} +1 -1
  37. package/{index-4edzf1gr.js → index-kbsach1y.js} +4 -4
  38. package/index-p6pbz9n5.js +25 -0
  39. package/{index-v0qh106m.js → index-r8bd61d9.js} +46 -11
  40. package/{index-ne2qy0nk.js → index-s3fvrydw.js} +3 -3
  41. package/{index-pnqbkf5p.js → index-sh88vtye.js} +1 -1
  42. package/{index-ws5e0j51.js → index-t8gvwcrx.js} +2 -2
  43. package/{index-a64esmtb.js → index-vrwdx0zx.js} +1 -1
  44. package/{index-kn1h7p1x.js → index-yc1keaer.js} +4 -226
  45. package/{index-j9yhg404.js → index-ys7dvdb3.js} +1 -1
  46. package/index.js +20 -19
  47. package/{library.command-nbsky672.js → library.command-1f9h2ex6.js} +3 -3
  48. package/{localRegistry.command-yeq57wjr.js → localRegistry.command-rx758ajg.js} +9 -8
  49. package/{module.command-29vqzrh8.js → module.command-c2eve036.js} +7 -6
  50. package/{package.command-axv0abmn.js → package.command-y2rh4np7.js} +3 -3
  51. package/package.json +2 -2
  52. package/{page.command-vs9s3zrh.js → page.command-e5h29fyt.js} +3 -3
  53. package/{primitive.command-cbxmqbtc.js → primitive.command-c44f7z1s.js} +8 -7
  54. package/{quality.command-gmbs7nws.js → quality.command-5evdd263.js} +2 -2
  55. package/{repair.command-bqsjptsj.js → repair.command-c2amvt74.js} +5 -5
  56. package/{scalar.command-6k1vhe9s.js → scalar.command-xyzerygj.js} +6 -5
  57. package/{subspace.command-fwjfcts7.js → subspace.command-ebfwzypw.js} +92 -12
  58. package/tunnel.command-v6a7at16.js +130 -0
  59. package/{workflow.command-nwpcdc8p.js → workflow.command-t174m6sy.js} +11 -10
  60. package/{workspace.command-8s050m0h.js → workspace.command-bg3eveth.js} +23 -22
@@ -7,7 +7,7 @@ import {
7
7
  isScannedRootEntry,
8
8
  AppExecutor,
9
9
  LibExecutor
10
- } from "./index-2tv3fdx4.js";
10
+ } from "./index-5nyznra1.js";
11
11
  import {
12
12
  FileSys
13
13
  } from "./index-q0y2jq9j.js";
@@ -19,7 +19,7 @@ import {
19
19
  import {
20
20
  workflowRunArtifactPath,
21
21
  workflowSyncDir
22
- } from "./index-gyd220p2.js";
22
+ } from "./index-jwjaf9fy.js";
23
23
 
24
24
  // pkgs/@akanjs/devkit/akanContext.ts
25
25
  import { readdir } from "fs/promises";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-mak3cd28.js";
5
+ } from "./index-b3ae16mg.js";
6
6
  import {
7
7
  LibExecutor
8
- } from "./index-2tv3fdx4.js";
8
+ } from "./index-5nyznra1.js";
9
9
  import {
10
10
  LibSource,
11
11
  formatLibStatuses
@@ -1,14 +1,14 @@
1
1
  // @bun
2
2
  import {
3
3
  AppExecutor
4
- } from "./index-2tv3fdx4.js";
4
+ } from "./index-5nyznra1.js";
5
5
  import {
6
6
  jsonText,
7
7
  createWorkflowBaselineSummary,
8
8
  buildAkanModuleContextIndex,
9
9
  createWorkflowStepRegistry,
10
10
  toolingRolloutGate
11
- } from "./index-gyd220p2.js";
11
+ } from "./index-jwjaf9fy.js";
12
12
  import {
13
13
  buildResourceList,
14
14
  codexMcpConfigPath,
@@ -19,33 +19,33 @@ import {
19
19
  upsertCodexMcpServerBlock,
20
20
  renderDoctorText,
21
21
  AkanContextAnalyzer
22
- } from "./index-ktb5njgy.js";
22
+ } from "./index-15r9a10e.js";
23
23
  import {
24
24
  CommandContainer,
25
25
  runner,
26
26
  script
27
- } from "./index-mak3cd28.js";
27
+ } from "./index-b3ae16mg.js";
28
28
  import {
29
29
  isPlaceholderAppId2
30
- } from "./index-wt7qrtd4.js";
30
+ } from "./index-7f4dsf9v.js";
31
31
  import {
32
32
  Prompter
33
33
  } from "./index-h7yw2z9n.js";
34
34
  import {
35
35
  RepairRunner
36
- } from "./index-fz5q3gd7.js";
36
+ } from "./index-em4swemt.js";
37
37
  import {
38
38
  WorkflowRunner
39
- } from "./index-7737gxcp.js";
39
+ } from "./index-8pkvrcv1.js";
40
40
  import {
41
41
  ModuleScript
42
- } from "./index-8pm30m73.js";
42
+ } from "./index-fr2x3qvv.js";
43
43
  import {
44
44
  PrimitiveScript
45
- } from "./index-4edzf1gr.js";
45
+ } from "./index-kbsach1y.js";
46
46
  import {
47
47
  ScalarScript
48
- } from "./index-rwg2aa4f.js";
48
+ } from "./index-ceph7zqj.js";
49
49
  import {
50
50
  getMobileTargets
51
51
  } from "./index-47pj3aee.js";
@@ -3576,6 +3576,7 @@ class AppExecutor extends SysExecutor {
3576
3576
  executor: this,
3577
3577
  getPath: (rel) => this.getPath(rel),
3578
3578
  fileExists: (rel) => FileSys.fileExists(this.getPath(rel)),
3579
+ readFile: (rel) => this.readFile(rel),
3579
3580
  writeFile: async (rel, content, opts) => {
3580
3581
  await this.writeFile(rel, content, opts);
3581
3582
  },
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  CommandExecutionError
4
- } from "./index-2tv3fdx4.js";
4
+ } from "./index-5nyznra1.js";
5
5
  import {
6
6
  resolveMobilePath,
7
7
  targetHtmlFilename
@@ -20,13 +20,13 @@ import {
20
20
  renderWorkflowApply,
21
21
  renderWorkflowValidation,
22
22
  renderWorkflowRunArtifact
23
- } from "./index-gyd220p2.js";
23
+ } from "./index-jwjaf9fy.js";
24
24
  import {
25
25
  AkanContextAnalyzer
26
- } from "./index-ktb5njgy.js";
26
+ } from "./index-15r9a10e.js";
27
27
  import {
28
28
  runner
29
- } from "./index-mak3cd28.js";
29
+ } from "./index-b3ae16mg.js";
30
30
 
31
31
  // pkgs/@akanjs/cli/workflow/workflow.runner.ts
32
32
  import { mkdir, readFile, writeFile } from "fs/promises";
@@ -2,19 +2,28 @@
2
2
  import {
3
3
  getDefaultHostConfig,
4
4
  GlobalConfig,
5
- CloudApi,
6
- AiSession
7
- } from "./index-kn1h7p1x.js";
5
+ CloudApi
6
+ } from "./index-bw2marpf.js";
8
7
  import {
9
8
  WorkspaceExecutor,
10
9
  AppExecutor
11
- } from "./index-2tv3fdx4.js";
10
+ } from "./index-5nyznra1.js";
11
+ import {
12
+ AiSession
13
+ } from "./index-yc1keaer.js";
12
14
  import {
13
15
  runner
14
- } from "./index-mak3cd28.js";
16
+ } from "./index-b3ae16mg.js";
15
17
  import {
16
18
  openBrowser
17
- } from "./index-v0qh106m.js";
19
+ } from "./index-r8bd61d9.js";
20
+
21
+ // pkgs/@akanjs/cli/cloud/cloud.runner.ts
22
+ import path from "path";
23
+ import { confirm, input, select } from "@inquirer/prompts";
24
+ import { Logger, sleep } from "akanjs/common";
25
+ import chalk from "chalk";
26
+ import * as QRcode from "qrcode";
18
27
 
19
28
  // pkgs/@akanjs/cli/npmRegistry.ts
20
29
  var defaultNpmRegistry = "https://registry.npmjs.org";
@@ -33,11 +42,6 @@ async function getLatestPackageVersion(packageName, tag = "latest", registryUrl)
33
42
  }
34
43
 
35
44
  // pkgs/@akanjs/cli/cloud/cloud.runner.ts
36
- import path from "path";
37
- import { confirm, input, select } from "@inquirer/prompts";
38
- import { Logger, sleep } from "akanjs/common";
39
- import chalk from "chalk";
40
- import * as QRcode from "qrcode";
41
45
  var addRemoteEnvServerValue = "__addRemoteEnvServer";
42
46
  var removeRemoteEnvServerValue = "__removeRemoteEnvServer";
43
47
 
@@ -393,26 +397,28 @@ ${chalk.green("\u27A4")} Authentication Required`));
393
397
  throw new Error(`Failed to upload env archive to remote server "${remoteServer.name}"`, { cause: error });
394
398
  }
395
399
  }
396
- async gatherEnvFiles(workspace) {
400
+ async gatherEnvFiles(workspace, { scope, archivePath = "local/env.tar" } = {}) {
397
401
  const envFilePattern = /^env\.(client|server)\.(?!(type|example)\.ts$).+\.ts$/;
398
- const [appNames, libNames] = await workspace.getExecs();
402
+ const [workspaceAppNames, workspaceLibNames] = await workspace.getExecs();
403
+ const appNames = scope?.apps ?? workspaceAppNames;
404
+ const libNames = scope?.libs ?? workspaceLibNames;
399
405
  const envDirs = [
400
406
  ...appNames.map((appName) => `apps/${appName}/env`),
401
407
  ...libNames.map((libName) => `libs/${libName}/env`)
402
408
  ];
403
409
  const defaultEnvFilePaths = (await Promise.all(envDirs.map(async (envDir) => (await workspace.readdir(envDir)).filter((fileName) => envFilePattern.test(fileName)).map((fileName) => `${envDir}/${fileName}`)))).flat();
404
- await this.#syncSecretGitignore(workspace, appNames);
410
+ await this.#syncSecretGitignore(workspace, workspaceAppNames);
405
411
  const customSecretPaths = await this.#gatherCustomSecretFiles(workspace, appNames);
406
412
  const envFilePaths = [...new Set([...defaultEnvFilePaths, ...customSecretPaths])].sort();
407
413
  await workspace.mkdir("local");
408
- await workspace.remove("local/env.tar");
414
+ await workspace.remove(archivePath);
409
415
  if (envFilePaths.length === 0)
410
- throw new Error("No environment files found to archive");
411
- await workspace.spawn("tar", ["-cf", "local/env.tar", ...envFilePaths], {
416
+ throw new Error(scope ? `No environment files found to archive for ${appNames.join(", ") || "(no apps)"}` : "No environment files found to archive");
417
+ await workspace.spawn("tar", ["-cf", archivePath, ...envFilePaths], {
412
418
  cwd: workspace.workspaceRoot
413
419
  });
414
- Logger.info(`Archived ${envFilePaths.length} environment files to local/env.tar`);
415
- return { files: envFilePaths, path: "local/env.tar" };
420
+ Logger.info(`Archived ${envFilePaths.length} environment files to ${archivePath}`);
421
+ return { files: envFilePaths, path: archivePath };
416
422
  }
417
423
  async#gatherCustomSecretFiles(workspace, appNames) {
418
424
  const secretPaths = await Promise.all(appNames.map(async (appName) => {
@@ -1,28 +1,30 @@
1
1
  // @bun
2
2
  import {
3
3
  GlobalConfig,
4
- CloudApi,
5
- AiSession
6
- } from "./index-kn1h7p1x.js";
4
+ CloudApi
5
+ } from "./index-bw2marpf.js";
7
6
  import {
8
7
  PkgExecutor
9
- } from "./index-2tv3fdx4.js";
8
+ } from "./index-5nyznra1.js";
9
+ import {
10
+ AiSession
11
+ } from "./index-yc1keaer.js";
10
12
  import {
11
13
  script
12
- } from "./index-mak3cd28.js";
14
+ } from "./index-b3ae16mg.js";
13
15
  import {
14
16
  ApplicationScript
15
- } from "./index-v0qh106m.js";
17
+ } from "./index-r8bd61d9.js";
16
18
  import {
17
19
  PackageScript
18
- } from "./index-ws5e0j51.js";
20
+ } from "./index-t8gvwcrx.js";
19
21
  import {
20
22
  CloudRunner
21
- } from "./index-2hq52jq3.js";
23
+ } from "./index-8tfmh0v6.js";
22
24
 
23
25
  // pkgs/@akanjs/cli/cloud/cloud.script.ts
24
26
  import { Logger } from "akanjs/common";
25
- class CloudScript extends script("cloud", [CloudRunner, ApplicationScript, PackageScript]) {
27
+ class CloudScript2 extends script("cloud", [CloudRunner, ApplicationScript, PackageScript]) {
26
28
  async login(workspace, host = GlobalConfig.akanCloudHost) {
27
29
  await this.cloudRunner.login(host, workspace);
28
30
  }
@@ -48,16 +50,23 @@ class CloudScript extends script("cloud", [CloudRunner, ApplicationScript, Packa
48
50
  }
49
51
  await this.cloudRunner.downloadEnvByScp(workspace);
50
52
  }
51
- async uploadEnv(workspace, { host = GlobalConfig.akanCloudHost } = {}) {
52
- const workspaceId = workspace.getWorkspaceId({ allowEmpty: true });
53
- const { path } = await this.cloudRunner.gatherEnvFiles(workspace);
53
+ async uploadEnv(workspace, {
54
+ host = GlobalConfig.akanCloudHost,
55
+ workspaceId = workspace.getWorkspaceId({ allowEmpty: true }),
56
+ scope,
57
+ archivePath
58
+ } = {}) {
59
+ if (scope && !workspaceId)
60
+ throw new Error("A scoped env upload needs a cloud workspace id \u2014 the scp target is workspace-wide.");
61
+ const { files, path } = await this.cloudRunner.gatherEnvFiles(workspace, { scope, archivePath });
54
62
  if (workspaceId) {
55
63
  await this.login(workspace, host);
56
64
  const cloudApi = await CloudApi.fromHost(workspace, host);
57
65
  await this.cloudRunner.uploadEnv(cloudApi, workspaceId, path);
58
- return;
66
+ return { workspaceId, files };
59
67
  }
60
68
  await this.cloudRunner.uploadEnvByScp(workspace, path);
69
+ return { workspaceId: null, files };
61
70
  }
62
71
  async deployAkan(workspace, { test = true, registryUrl } = {}) {
63
72
  const akanPkgs = await this.cloudRunner.getAkanPkgs(workspace);
@@ -80,4 +89,4 @@ class CloudScript extends script("cloud", [CloudRunner, ApplicationScript, Packa
80
89
  }
81
90
  }
82
91
 
83
- export { CloudScript };
92
+ export { CloudScript2 };
@@ -9,7 +9,7 @@ import {
9
9
  LibExecutor,
10
10
  PkgExecutor,
11
11
  ModuleExecutor
12
- } from "./index-2tv3fdx4.js";
12
+ } from "./index-5nyznra1.js";
13
13
  import {
14
14
  getDirname2
15
15
  } from "./index-6wwzs1bc.js";
@@ -59,30 +59,6 @@ var Pkg = createInternalArgToken("Pkg");
59
59
  var Module = createInternalArgToken("Module");
60
60
  var Workspace = createInternalArgToken("Workspace");
61
61
 
62
- // pkgs/@akanjs/devkit/commandDecorators/command.ts
63
- import path2 from "path";
64
- import { Logger } from "akanjs/common";
65
- import chalk2 from "chalk";
66
- import { program } from "commander";
67
-
68
- // pkgs/@akanjs/devkit/appSelectionMemory.ts
69
- import path from "path";
70
- class AppSelectionMemory {
71
- static pathIn(workspaceRoot) {
72
- return path.join(workspaceRoot, "local", ".akan", "lastStart.json");
73
- }
74
- static async read(workspaceRoot) {
75
- const stored = await Bun.file(AppSelectionMemory.pathIn(workspaceRoot)).json().catch(() => null);
76
- const apps = stored?.apps;
77
- return Array.isArray(apps) ? apps.filter((name) => typeof name === "string") : [];
78
- }
79
- static async write(workspaceRoot, apps) {
80
- await FileSys.writeJson(AppSelectionMemory.pathIn(workspaceRoot), { apps }).catch(() => {
81
- return;
82
- });
83
- }
84
- }
85
-
86
62
  // pkgs/@akanjs/devkit/commandDecorators/dependencyBuilder.ts
87
63
  var capitalize = (value) => value.slice(0, 1).toUpperCase() + value.slice(1);
88
64
  var createDependencyKey = (refName, kind) => `${refName}${capitalize(kind)}`;
@@ -160,6 +136,30 @@ var script = (refName, deps = []) => {
160
136
  return ScriptBase;
161
137
  };
162
138
 
139
+ // pkgs/@akanjs/devkit/commandDecorators/command.ts
140
+ import path2 from "path";
141
+ import { Logger } from "akanjs/common";
142
+ import chalk2 from "chalk";
143
+ import { program } from "commander";
144
+
145
+ // pkgs/@akanjs/devkit/appSelectionMemory.ts
146
+ import path from "path";
147
+ class AppSelectionMemory {
148
+ static pathIn(workspaceRoot) {
149
+ return path.join(workspaceRoot, "local", ".akan", "lastStart.json");
150
+ }
151
+ static async read(workspaceRoot) {
152
+ const stored = await Bun.file(AppSelectionMemory.pathIn(workspaceRoot)).json().catch(() => null);
153
+ const apps = stored?.apps;
154
+ return Array.isArray(apps) ? apps.filter((name) => typeof name === "string") : [];
155
+ }
156
+ static async write(workspaceRoot, apps) {
157
+ await FileSys.writeJson(AppSelectionMemory.pathIn(workspaceRoot), { apps }).catch(() => {
158
+ return;
159
+ });
160
+ }
161
+ }
162
+
163
163
  // pkgs/@akanjs/devkit/commandDecorators/helpFormatter.ts
164
164
  import chalk from "chalk";
165
165
  var camelToKebabCase2 = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
@@ -0,0 +1,237 @@
1
+ // @bun
2
+ import {
3
+ FileSys
4
+ } from "./index-q0y2jq9j.js";
5
+
6
+ // pkgs/@akanjs/devkit/cloud/globalConfig.ts
7
+ import { chmod, mkdir } from "fs/promises";
8
+ import dayjs from "dayjs";
9
+
10
+ // pkgs/@akanjs/devkit/cloud/constants.ts
11
+ var basePath = `${Bun.env.HOME ?? Bun.env.USERPROFILE}/.akan`;
12
+ var configPath = `${basePath}/config.json`;
13
+ var getDefaultHostConfig = (host = GlobalConfig.akanCloudHost) => ({ host });
14
+ var defaultAkanGlobalConfig = {
15
+ cloudHost: {},
16
+ remoteEnvServers: {},
17
+ llm: null
18
+ };
19
+
20
+ // pkgs/@akanjs/devkit/cloud/globalConfig.ts
21
+ class GlobalConfig {
22
+ static akanCloudHost = process.env.USE_AKANJS_PKGS === "true" ? `http://localhost:${process.env.CLOUD_HOST_PORT ?? 8283}` : "https://cloud.akanjs.com";
23
+ static async#getAkanGlobalConfig() {
24
+ const exists = await FileSys.fileExists(configPath);
25
+ const akanConfig = exists ? await FileSys.readJson(configPath) : {};
26
+ return {
27
+ ...defaultAkanGlobalConfig,
28
+ ...akanConfig,
29
+ cloudHost: akanConfig.cloudHost ?? defaultAkanGlobalConfig.cloudHost,
30
+ remoteEnvServers: akanConfig.remoteEnvServers ?? defaultAkanGlobalConfig.remoteEnvServers
31
+ };
32
+ }
33
+ static async#setAkanGlobalConfig(akanConfig) {
34
+ await mkdir(basePath, { recursive: true, mode: 448 });
35
+ await Bun.write(configPath, JSON.stringify(akanConfig, null, 2));
36
+ await chmod(configPath, 384);
37
+ }
38
+ static async getHostConfig(host = GlobalConfig.akanCloudHost) {
39
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
40
+ return GlobalConfig.toHostConfig(akanConfig.cloudHost[host] ?? getDefaultHostConfig(host));
41
+ }
42
+ static async setHostConfig(config = getDefaultHostConfig()) {
43
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
44
+ akanConfig.cloudHost[config.host] = GlobalConfig.toHostConfigDto(config);
45
+ await GlobalConfig.#setAkanGlobalConfig(akanConfig);
46
+ }
47
+ static async getLlmConfig() {
48
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
49
+ return akanConfig.llm ?? null;
50
+ }
51
+ static async setLlmConfig(llmConfig) {
52
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
53
+ await GlobalConfig.#setAkanGlobalConfig({ ...akanConfig, llm: llmConfig });
54
+ }
55
+ static async getRemoteEnvServers() {
56
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
57
+ return akanConfig.remoteEnvServers;
58
+ }
59
+ static async setRemoteEnvServer(name, config) {
60
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
61
+ await GlobalConfig.#setAkanGlobalConfig({
62
+ ...akanConfig,
63
+ remoteEnvServers: {
64
+ ...akanConfig.remoteEnvServers,
65
+ [name]: config
66
+ }
67
+ });
68
+ }
69
+ static async removeRemoteEnvServer(name) {
70
+ const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
71
+ const { [name]: _, ...remoteEnvServers } = akanConfig.remoteEnvServers;
72
+ await GlobalConfig.#setAkanGlobalConfig({
73
+ ...akanConfig,
74
+ remoteEnvServers
75
+ });
76
+ }
77
+ static needRefreshToken(accessToken) {
78
+ return !!accessToken?.expiresAt?.isBefore(dayjs().add(1, "hour"));
79
+ }
80
+ static toAccessToken(accessToken) {
81
+ return {
82
+ jwt: accessToken.jwt,
83
+ refreshToken: accessToken.refreshToken ?? null,
84
+ expiresAt: accessToken.expiresAt ? dayjs(accessToken.expiresAt) : null
85
+ };
86
+ }
87
+ static toAccessTokenDto(accessToken) {
88
+ return {
89
+ jwt: accessToken.jwt,
90
+ refreshToken: accessToken.refreshToken ?? null,
91
+ expiresAt: accessToken.expiresAt?.toString() ?? null
92
+ };
93
+ }
94
+ static toHostConfigDto(hostConfig) {
95
+ return {
96
+ host: hostConfig.host,
97
+ auth: {
98
+ accessToken: hostConfig.auth?.accessToken ? GlobalConfig.toAccessTokenDto(hostConfig.auth.accessToken) : undefined,
99
+ self: hostConfig.auth?.self
100
+ }
101
+ };
102
+ }
103
+ static toHostConfig(hostConfigDto) {
104
+ return {
105
+ host: hostConfigDto.host,
106
+ auth: {
107
+ accessToken: hostConfigDto.auth?.accessToken ? GlobalConfig.toAccessToken(hostConfigDto.auth.accessToken) : undefined,
108
+ self: hostConfigDto.auth?.self
109
+ }
110
+ };
111
+ }
112
+ }
113
+
114
+ // pkgs/@akanjs/devkit/cloud/cloudApi.ts
115
+ class HttpClient {
116
+ baseUrl;
117
+ headers = {};
118
+ constructor(baseUrl, headers = {}) {
119
+ this.baseUrl = baseUrl;
120
+ this.headers = headers;
121
+ }
122
+ async get(url, { headers } = {}) {
123
+ const response = await fetch(`${this.baseUrl}${url}`, {
124
+ headers: {
125
+ "Content-Type": "application/json",
126
+ ...this.headers,
127
+ ...headers
128
+ }
129
+ });
130
+ return await response.json();
131
+ }
132
+ async getFile(url, localPath, headers) {
133
+ const response = await fetch(`${this.baseUrl}${url}`, {
134
+ headers: { ...this.headers, ...headers }
135
+ });
136
+ if (!response.ok)
137
+ throw new Error(`Failed to download file: ${response.status} ${response.statusText}`);
138
+ await Bun.write(localPath, response);
139
+ }
140
+ async post(url, data, { headers } = {}) {
141
+ const isFormData = data instanceof FormData;
142
+ const response = await fetch(`${this.baseUrl}${url}`, {
143
+ method: "POST",
144
+ body: isFormData ? data : JSON.stringify(data),
145
+ headers: isFormData ? { ...this.headers, ...headers } : { "Content-Type": "application/json", ...this.headers, ...headers }
146
+ });
147
+ return await response.json();
148
+ }
149
+ setHeaders(headers) {
150
+ Object.assign(this.headers, headers);
151
+ return this;
152
+ }
153
+ }
154
+
155
+ class CloudApi {
156
+ #api;
157
+ #accessToken = null;
158
+ #workspace;
159
+ host;
160
+ url;
161
+ static async fromHost(workspace, host) {
162
+ const hostConfig = await GlobalConfig.getHostConfig(host);
163
+ return new CloudApi(workspace, hostConfig);
164
+ }
165
+ constructor(workspace, hostConfig) {
166
+ this.#workspace = workspace;
167
+ this.#accessToken = hostConfig.auth?.accessToken ?? null;
168
+ this.host = hostConfig.host;
169
+ this.url = `${this.host}/api`;
170
+ this.#api = new HttpClient(this.url);
171
+ if (this.#accessToken && !GlobalConfig.needRefreshToken(this.#accessToken))
172
+ this.#api.setHeaders({
173
+ Authorization: `Bearer ${this.#accessToken.jwt}`
174
+ });
175
+ }
176
+ async uploadEnv(devProjectId, file) {
177
+ const formData = new FormData;
178
+ formData.append("devProjectId", devProjectId);
179
+ formData.append("file", file);
180
+ const data = await this.#api.post(`/uploadEnv/${devProjectId}`, formData);
181
+ return data;
182
+ }
183
+ async downloadEnv(devProjectId) {
184
+ const localPath = `${this.#workspace.workspaceRoot}/local/env.tar`;
185
+ await this.#api.getFile(`/downloadEnv/${devProjectId}`, localPath);
186
+ return localPath;
187
+ }
188
+ async getRemoteAuthToken(remoteId) {
189
+ try {
190
+ const accessToken = await this.#api.get(`/getRemoteAuthToken/${remoteId}`);
191
+ this.#accessToken = GlobalConfig.toAccessToken(accessToken);
192
+ this.#api.setHeaders({
193
+ Authorization: `Bearer ${this.#accessToken.jwt}`
194
+ });
195
+ return this.#accessToken;
196
+ } catch (_) {
197
+ return null;
198
+ }
199
+ }
200
+ async#ensureAccessTokenLive({
201
+ allowUnauthorized = false
202
+ } = {}) {
203
+ if (!this.#accessToken)
204
+ throw new Error("No access token");
205
+ const needRefresh = GlobalConfig.needRefreshToken(this.#accessToken);
206
+ if (!needRefresh)
207
+ return this.#accessToken;
208
+ const refreshToken = this.#accessToken?.refreshToken;
209
+ if (!refreshToken)
210
+ throw new Error("No refresh token");
211
+ return await this.refreshAuthToken(refreshToken);
212
+ }
213
+ async refreshAuthToken(refreshToken) {
214
+ const response = await this.#api.post(`/refreshAuthToken`, { refreshToken });
215
+ this.#accessToken = GlobalConfig.toAccessToken(response);
216
+ this.#api.setHeaders({ Authorization: `Bearer ${this.#accessToken.jwt}` });
217
+ return this.#accessToken;
218
+ }
219
+ async requestTunnel(input) {
220
+ return await this.#api.post(`/requestTunnel`, input);
221
+ }
222
+ async tunnelListInSelf() {
223
+ return await this.#api.get(`/tunnelListInSelf`);
224
+ }
225
+ async revokeTunnel(code) {
226
+ return await this.#api.post(`/revokeTunnel`, { code });
227
+ }
228
+ async getRemoteSelf() {
229
+ try {
230
+ const data = await this.#api.get(`/getRemoteSelf`);
231
+ return data;
232
+ } catch {
233
+ return null;
234
+ }
235
+ }
236
+ }
237
+ export { getDefaultHostConfig, GlobalConfig, CloudApi };
@@ -2,15 +2,15 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-mak3cd28.js";
5
+ } from "./index-b3ae16mg.js";
6
6
  import {
7
7
  generatedFilesForSync,
8
8
  createPassedPrimitiveReport,
9
9
  scalarChangedFiles
10
- } from "./index-gyd220p2.js";
10
+ } from "./index-jwjaf9fy.js";
11
11
  import {
12
12
  AiSession
13
- } from "./index-kn1h7p1x.js";
13
+ } from "./index-yc1keaer.js";
14
14
  import {
15
15
  Prompter
16
16
  } from "./index-h7yw2z9n.js";
@@ -5,13 +5,13 @@ import {
5
5
  writeGeneratedSyncState,
6
6
  createRepairReport,
7
7
  renderRepairReport
8
- } from "./index-gyd220p2.js";
8
+ } from "./index-jwjaf9fy.js";
9
9
  import {
10
10
  AkanContextAnalyzer
11
- } from "./index-ktb5njgy.js";
11
+ } from "./index-15r9a10e.js";
12
12
  import {
13
13
  runner
14
- } from "./index-mak3cd28.js";
14
+ } from "./index-b3ae16mg.js";
15
15
 
16
16
  // pkgs/@akanjs/cli/repair/repair.runner.ts
17
17
  var commandForShell = (command) => command.startsWith("akan ") ? `bun run ${command}` : command;
@@ -2,16 +2,16 @@
2
2
  import {
3
3
  FileSys
4
4
  } from "./index-q0y2jq9j.js";
5
- import {
6
- AiSession
7
- } from "./index-kn1h7p1x.js";
8
5
  import {
9
6
  ModuleExecutor
10
- } from "./index-2tv3fdx4.js";
7
+ } from "./index-5nyznra1.js";
8
+ import {
9
+ AiSession
10
+ } from "./index-yc1keaer.js";
11
11
  import {
12
12
  runner,
13
13
  script
14
- } from "./index-mak3cd28.js";
14
+ } from "./index-b3ae16mg.js";
15
15
  import {
16
16
  sourceFile,
17
17
  moduleSourcePaths,
@@ -19,10 +19,10 @@ import {
19
19
  createPassedPrimitiveReport,
20
20
  bilingualLabelForField,
21
21
  bilingualDescriptionForField
22
- } from "./index-gyd220p2.js";
22
+ } from "./index-jwjaf9fy.js";
23
23
  import {
24
24
  PageScript
25
- } from "./index-pnqbkf5p.js";
25
+ } from "./index-sh88vtye.js";
26
26
  import {
27
27
  Prompter
28
28
  } from "./index-h7yw2z9n.js";