@akanjs/cli 3.1.1-rc.14 → 3.1.1-rc.16
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.
- package/.build-stamp +1 -1
- package/{CodeAgent-gtwn7tmb.js → CodeAgent-23ewzxqa.js} +2 -2
- package/{CodeTui-v941fqdh.js → CodeTui-kc99fk78.js} +1 -1
- package/TunnelShare-dk2gw78d.js +14 -0
- package/{agent.command-h82gepwn.js → agent.command-knp5j7bq.js} +5 -5
- package/akanCode.js +2 -2
- package/{application.command-j1reb9p1.js → application.command-bvfd1680.js} +9 -9
- package/{applicationBuildRunner-w20x63mz.js → applicationBuildRunner-4ajaesk1.js} +6 -5
- package/buildBatch.proc.js +5 -5
- package/{cloud.command-zd2mfkm0.js → cloud.command-f2w40fyy.js} +13 -13
- package/cloud.script-2r82sv0f.js +24 -0
- package/{code.command-dyet4xn6.js → code.command-dbhhnahn.js} +6 -6
- package/{context.command-79gxczm4.js → context.command-yswjwv6y.js} +17 -16
- package/context.runner-c3wsh2jw.js +26 -0
- package/{guideline.command-xwkskvky.js → guideline.command-ztx6dkpk.js} +2 -2
- package/guidelines/conventions/conventions.instruction.md +56 -10
- package/incrementalBuilder.proc.js +3 -3
- package/{index-yknrmkmt.js → index-005dqc83.js} +2 -2
- package/{index-qmeh0s05.js → index-00ke4phc.js} +2 -2
- package/{index-hdzjaq7s.js → index-2epb3wgh.js} +2 -2
- package/{index-rshwdv9w.js → index-2p1brf5e.js} +2 -2
- package/{index-wvvwdzfw.js → index-4332q6yj.js} +3 -3
- package/{index-6pzt55w3.js → index-4t4qb8jg.js} +3 -3
- package/{index-7ktk2hnz.js → index-76jwsm3g.js} +2 -2
- package/{index-tzzs52h0.js → index-7ndgffg4.js} +9 -9
- package/{index-1e2955yd.js → index-921cxqrd.js} +3 -1
- package/{index-8jb5ep2e.js → index-97fsvy66.js} +2 -2
- package/{index-pc9ps0hx.js → index-9sa6abze.js} +8 -8
- package/{index-jjd97ya6.js → index-deeskxjh.js} +1 -1
- package/{index-cz9g85xh.js → index-er16p89s.js} +1 -1
- package/{index-ygy8c12j.js → index-gxj80jz7.js} +1 -1
- package/index-hvg3esm0.js +1844 -0
- package/{index-41d3zx66.js → index-k9k18vq9.js} +3 -3
- package/{index-nmy1rana.js → index-m54n0v29.js} +4 -4
- package/index-m5n3ka0p.js +18 -0
- package/{index-brpk7gd8.js → index-m6qgr1rx.js} +7 -7
- package/{index-553xyb55.js → index-m93qg20j.js} +1 -1
- package/{index-4rwfh2de.js → index-mk391h0z.js} +3 -3
- package/{index-ch1sv7ke.js → index-nzfgyw3b.js} +9 -21
- package/{index-2qzzp0c9.js → index-p2pahmsa.js} +3 -3
- package/{index-kbbyzs6j.js → index-qx4r4cj2.js} +2 -2
- package/index-rxse80x6.js +408 -0
- package/{index-kr62ph5a.js → index-s4c2y5gs.js} +2 -2
- package/{index-jtydvvq7.js → index-saj9cx3a.js} +4 -4
- package/index-vgt25eh1.js +615 -0
- package/{index-8rvwgd1r.js → index-vq77g679.js} +1 -1
- package/{index-xeh7m2j5.js → index-xfp4dcnx.js} +1 -1
- package/{index-pqdz7rat.js → index-xjwcp91m.js} +910 -36
- package/{index-7abjzny1.js → index-ysyt782g.js} +33 -37
- package/index.js +22 -22
- package/{library.command-td8t85kb.js → library.command-hmbkcwzw.js} +3 -3
- package/{localRegistry.command-jx9zkmxf.js → localRegistry.command-sq5p4c9x.js} +15 -13
- package/{module.command-j70mqgpp.js → module.command-n4z29zcv.js} +5 -5
- package/{package.command-1b1v6k5v.js → package.command-20025dy3.js} +3 -3
- package/package.json +2 -2
- package/{page.command-m31w2tsz.js → page.command-q8fvpjer.js} +3 -3
- package/{pipeline.command-q7b8wy55.js → pipeline.command-8j97fq88.js} +2 -2
- package/{primitive.command-4zrbhkb9.js → primitive.command-e5y6dqp1.js} +6 -6
- package/{projectTypecheck-synx6qff.js → projectTypecheck-tbdye9k3.js} +1 -1
- package/{quality.command-cy0pgqjz.js → quality.command-168pt5vm.js} +621 -311
- package/{repair.command-98n6zxg7.js → repair.command-dq1gckth.js} +5 -5
- package/{scalar.command-rak5pjk3.js → scalar.command-5vwf152w.js} +4 -4
- package/{subspace.command-ej0rk116.js → subspace.command-182be8vj.js} +8 -8
- package/{tunnel.command-kdx3amrc.js → tunnel.command-bfzj7xkb.js} +7 -7
- package/{workflow.command-gffk9nj9.js → workflow.command-3g53242s.js} +37 -13
- package/workspace.command-h7399jwv.js +260 -0
- package/TunnelShare-26ty9skr.js +0 -14
- package/cloud.script-vdj8ymch.js +0 -24
- package/context.runner-ejag7mhr.js +0 -25
- package/index-y5m4j2w6.js +0 -856
- package/workspace.command-097hv6n1.js +0 -521
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
Exec,
|
|
4
|
-
Workspace,
|
|
5
|
-
runner,
|
|
6
|
-
script,
|
|
7
|
-
command
|
|
8
|
-
} from "./index-qmeh0s05.js";
|
|
9
|
-
import {
|
|
10
|
-
FileSys2
|
|
11
|
-
} from "./index-52w0fvh8.js";
|
|
12
|
-
import {
|
|
13
|
-
extractAgentBlock,
|
|
14
|
-
collectScopeRecipeSources,
|
|
15
|
-
renderScopeAgentBlock,
|
|
16
|
-
Linter,
|
|
17
|
-
WorkspaceExecutor,
|
|
18
|
-
SysExecutor,
|
|
19
|
-
AppExecutor,
|
|
20
|
-
LibExecutor,
|
|
21
|
-
PkgExecutor
|
|
22
|
-
} from "./index-1e2955yd.js";
|
|
23
|
-
import {
|
|
24
|
-
countBlocking,
|
|
25
|
-
formatStyleContract,
|
|
26
|
-
ThemeValidator
|
|
27
|
-
} from "./index-62md4dwy.js";
|
|
28
|
-
import {
|
|
29
|
-
collectRecipeSources2,
|
|
30
|
-
scanRecipes2
|
|
31
|
-
} from "./index-hj6w4ka1.js";
|
|
32
|
-
import"./index-pqdz7rat.js";
|
|
33
|
-
import"./index-kr62ph5a.js";
|
|
34
|
-
import"./index-zzvvc845.js";
|
|
35
|
-
import {
|
|
36
|
-
AgentScript
|
|
37
|
-
} from "./index-6pzt55w3.js";
|
|
38
|
-
import"./index-5nd1wtkv.js";
|
|
39
|
-
import"./index-2qzzp0c9.js";
|
|
40
|
-
import"./index-8rvwgd1r.js";
|
|
41
|
-
import"./index-m9jj544v.js";
|
|
42
|
-
import"./index-yknrmkmt.js";
|
|
43
|
-
import"./index-cz9g85xh.js";
|
|
44
|
-
import {
|
|
45
|
-
LibraryScript
|
|
46
|
-
} from "./index-rshwdv9w.js";
|
|
47
|
-
import {
|
|
48
|
-
ApplicationScript
|
|
49
|
-
} from "./index-tzzs52h0.js";
|
|
50
|
-
import"./index-7md2g9vw.js";
|
|
51
|
-
import"./index-7ktk2hnz.js";
|
|
52
|
-
import"./index-tvehn2sp.js";
|
|
53
|
-
import {
|
|
54
|
-
PackageScript
|
|
55
|
-
} from "./index-hdzjaq7s.js";
|
|
56
|
-
import {
|
|
57
|
-
getNpmRegistryUrl,
|
|
58
|
-
getLatestPackageVersion
|
|
59
|
-
} from "./index-ch1sv7ke.js";
|
|
60
|
-
import {
|
|
61
|
-
CloudScript2
|
|
62
|
-
} from "./index-brpk7gd8.js";
|
|
63
|
-
import"./index-pc9ps0hx.js";
|
|
64
|
-
import"./index-wvvwdzfw.js";
|
|
65
|
-
import"./index-ygy8c12j.js";
|
|
66
|
-
import"./index-nmy1rana.js";
|
|
67
|
-
import"./index-7abjzny1.js";
|
|
68
|
-
import"./index-kbbyzs6j.js";
|
|
69
|
-
import"./index-y5m4j2w6.js";
|
|
70
|
-
import {
|
|
71
|
-
ContextScript
|
|
72
|
-
} from "./index-jtydvvq7.js";
|
|
73
|
-
import"./index-553xyb55.js";
|
|
74
|
-
|
|
75
|
-
// pkgs/@akanjs/cli/workspace/workspace.runner.ts
|
|
76
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
77
|
-
import path from "path";
|
|
78
|
-
|
|
79
|
-
// pkgs/@akanjs/devkit/biomeBase.ts
|
|
80
|
-
var biomeVersion = "2.5.14";
|
|
81
|
-
|
|
82
|
-
// pkgs/@akanjs/cli/workspace/workspace.runner.ts
|
|
83
|
-
import { Ed25519Key } from "akanjs/server/ed25519Key";
|
|
84
|
-
var defaultWorkspacePeerDependencies = new Set([
|
|
85
|
-
"@react-spring/web",
|
|
86
|
-
"@use-gesture/react",
|
|
87
|
-
"chance",
|
|
88
|
-
"react",
|
|
89
|
-
"react-dom",
|
|
90
|
-
"react-icons",
|
|
91
|
-
"react-refresh",
|
|
92
|
-
"react-server-dom-webpack",
|
|
93
|
-
"react-spring",
|
|
94
|
-
"scheduler",
|
|
95
|
-
"tailwind-scrollbar",
|
|
96
|
-
"tailwindcss",
|
|
97
|
-
"typescript"
|
|
98
|
-
]);
|
|
99
|
-
var defaultWorkspaceTypeDependencies = { "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0" };
|
|
100
|
-
var defaultMaxDiagnostics = 200;
|
|
101
|
-
|
|
102
|
-
class WorkspaceRunner extends runner("workspace") {
|
|
103
|
-
async machineKeygen(workspace, out) {
|
|
104
|
-
const file = path.resolve(workspace.workspaceRoot, out);
|
|
105
|
-
const { privatePem, publicKey } = Ed25519Key.generate();
|
|
106
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
107
|
-
try {
|
|
108
|
-
await writeFile(file, privatePem, { mode: 384, flag: "wx" });
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error.code === "EEXIST")
|
|
111
|
-
throw new Error(`${file} exists; machine-keygen never overwrites a key. Name another file.`);
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
return { file, publicKey };
|
|
115
|
-
}
|
|
116
|
-
async generateAgentRules(workspace, { overwrite = false, cursorRules = true } = {}) {
|
|
117
|
-
const [appNames] = await workspace.getExecs();
|
|
118
|
-
const dict = { repoName: workspace.repoName, appName: appNames[0] ?? "app" };
|
|
119
|
-
const templates = [
|
|
120
|
-
[".", "workspaceRoot/AGENTS.md.template"],
|
|
121
|
-
[".", "workspaceRoot/CLAUDE.md.template"],
|
|
122
|
-
...cursorRules ? [[".cursor/rules", "workspaceRoot/.cursor/rules/akan.mdc.template"]] : []
|
|
123
|
-
];
|
|
124
|
-
const created = [];
|
|
125
|
-
for (const [basePath, template] of templates)
|
|
126
|
-
created.push(...await workspace.applyTemplate({ basePath, template, dict, overwrite }));
|
|
127
|
-
return created;
|
|
128
|
-
}
|
|
129
|
-
async createWorkspace(repoName, appName, {
|
|
130
|
-
dirname = ".",
|
|
131
|
-
init = true,
|
|
132
|
-
akanVersion,
|
|
133
|
-
registryUrl,
|
|
134
|
-
owner = ""
|
|
135
|
-
}) {
|
|
136
|
-
const cwdPath = process.cwd();
|
|
137
|
-
const workspaceRoot = path.resolve(cwdPath, dirname, repoName);
|
|
138
|
-
const normalizedRegistryUrl = registryUrl ? getNpmRegistryUrl(registryUrl) : undefined;
|
|
139
|
-
const workspace = WorkspaceExecutor.fromRoot({ workspaceRoot, repoName });
|
|
140
|
-
const templateSpinner = workspace.spinning(`Creating workspace template files in ${workspaceRoot}...`);
|
|
141
|
-
const latestTypesBunVersion = await getLatestPackageVersion("@types/bun", "latest", normalizedRegistryUrl);
|
|
142
|
-
await workspace.applyTemplate({
|
|
143
|
-
basePath: ".",
|
|
144
|
-
template: "workspaceRoot",
|
|
145
|
-
dict: { repoName, appName, serveDomain: "localhost", owner }
|
|
146
|
-
});
|
|
147
|
-
if (normalizedRegistryUrl)
|
|
148
|
-
await workspace.writeFile(".npmrc", `registry=${normalizedRegistryUrl}/
|
|
149
|
-
`);
|
|
150
|
-
templateSpinner.succeed(`Workspace files created in ${workspaceRoot}`);
|
|
151
|
-
const [rootPackageJson, peerDependencies] = await Promise.all([
|
|
152
|
-
workspace.getPackageJson(),
|
|
153
|
-
this.#getAkanPeerDependencies()
|
|
154
|
-
]);
|
|
155
|
-
const { typescript, ...dependencies } = peerDependencies;
|
|
156
|
-
const packageJson = {
|
|
157
|
-
...rootPackageJson,
|
|
158
|
-
dependencies: {
|
|
159
|
-
...rootPackageJson.dependencies,
|
|
160
|
-
...dependencies,
|
|
161
|
-
akanjs: akanVersion
|
|
162
|
-
},
|
|
163
|
-
devDependencies: {
|
|
164
|
-
...rootPackageJson.devDependencies,
|
|
165
|
-
"@biomejs/biome": biomeVersion,
|
|
166
|
-
"@types/bun": latestTypesBunVersion,
|
|
167
|
-
...defaultWorkspaceTypeDependencies,
|
|
168
|
-
"@akanjs/devkit": akanVersion,
|
|
169
|
-
"@akanjs/cli": akanVersion,
|
|
170
|
-
...typescript ? { typescript } : {}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
await workspace.setPackageJson(packageJson);
|
|
174
|
-
if (init) {
|
|
175
|
-
const installSpinner = workspace.spinning("Installing dependencies with bun...");
|
|
176
|
-
await workspace.spawn("bun", ["install"]);
|
|
177
|
-
installSpinner.succeed("Dependencies installed with bun");
|
|
178
|
-
}
|
|
179
|
-
return workspace;
|
|
180
|
-
}
|
|
181
|
-
async#getAkanPeerDependencies() {
|
|
182
|
-
const [packageJson, cliPackageJson] = await Promise.all([this.#getAkanPackageJson(), this.#getCliPackageJson()]);
|
|
183
|
-
const dependencyVersions = {
|
|
184
|
-
...packageJson.dependencies,
|
|
185
|
-
...packageJson.peerDependencies,
|
|
186
|
-
...cliPackageJson.dependencies
|
|
187
|
-
};
|
|
188
|
-
return Object.fromEntries(Object.entries(dependencyVersions).filter(([dependency]) => defaultWorkspacePeerDependencies.has(dependency)));
|
|
189
|
-
}
|
|
190
|
-
async#getCliPackageJson() {
|
|
191
|
-
const found = await this.#findPackageJson("@akanjs/cli", [
|
|
192
|
-
path.join(import.meta.dir, "../package.json"),
|
|
193
|
-
path.join(import.meta.dir, "package.json"),
|
|
194
|
-
path.join(path.dirname(Bun.main), "package.json")
|
|
195
|
-
]);
|
|
196
|
-
return found ?? { name: "@akanjs/cli", version: "0.0.0", description: "@akanjs/cli" };
|
|
197
|
-
}
|
|
198
|
-
async#getAkanPackageJson() {
|
|
199
|
-
const ancestors = [];
|
|
200
|
-
for (let current = import.meta.dir, depth = 0;depth < 6; depth++) {
|
|
201
|
-
ancestors.push(path.join(current, "package.json"));
|
|
202
|
-
if (path.dirname(current) === current)
|
|
203
|
-
break;
|
|
204
|
-
current = path.dirname(current);
|
|
205
|
-
}
|
|
206
|
-
const found = await this.#findPackageJson("akanjs", [
|
|
207
|
-
path.join(import.meta.dir, "../../../akanjs/package.json"),
|
|
208
|
-
path.join(process.cwd(), "pkgs/akanjs/package.json"),
|
|
209
|
-
path.join(path.dirname(Bun.main), "node_modules/akanjs/package.json"),
|
|
210
|
-
...ancestors
|
|
211
|
-
]);
|
|
212
|
-
if (!found)
|
|
213
|
-
throw new Error(`[workspace] failed to locate akanjs package.json from ${import.meta.dir}`);
|
|
214
|
-
return found;
|
|
215
|
-
}
|
|
216
|
-
async#findPackageJson(name, candidates) {
|
|
217
|
-
try {
|
|
218
|
-
candidates.unshift(Bun.resolveSync(`${name}/package.json`, import.meta.dir));
|
|
219
|
-
} catch {}
|
|
220
|
-
for (const packageJsonPath of candidates) {
|
|
221
|
-
if (!await Bun.file(packageJsonPath).exists())
|
|
222
|
-
continue;
|
|
223
|
-
const packageJson = await FileSys2.readJson(packageJsonPath);
|
|
224
|
-
if (packageJson.name === name)
|
|
225
|
-
return packageJson;
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
async lint(exec, workspace, { fix = true, maxDiagnostics = defaultMaxDiagnostics } = {}) {
|
|
230
|
-
const configPath = await WorkspaceRunner.resolveBiomeConfigPath(workspace);
|
|
231
|
-
const [biome, ...biomeArgs] = Linter.biomeCommand(workspace.workspaceRoot);
|
|
232
|
-
await workspace.spawn(biome, [
|
|
233
|
-
...biomeArgs,
|
|
234
|
-
"check",
|
|
235
|
-
...fix ? ["--write"] : [],
|
|
236
|
-
"--no-errors-on-unmatched",
|
|
237
|
-
`--max-diagnostics=${maxDiagnostics > 0 ? maxDiagnostics : "none"}`,
|
|
238
|
-
...configPath ? ["--config-path", configPath] : [],
|
|
239
|
-
exec.cwdPath
|
|
240
|
-
]);
|
|
241
|
-
await this.#enforceStyleContract(exec);
|
|
242
|
-
await this.#enforceRecipeGate(exec);
|
|
243
|
-
await this.#enforceAgentsIndex(exec);
|
|
244
|
-
}
|
|
245
|
-
static async resolveBiomeConfigPath(workspace) {
|
|
246
|
-
for (const fileName of ["biome.json", "biome.jsonc"]) {
|
|
247
|
-
const configPath = path.join(workspace.workspaceRoot, fileName);
|
|
248
|
-
if (await Bun.file(configPath).exists())
|
|
249
|
-
return configPath;
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
async#enforceAgentsIndex(exec) {
|
|
254
|
-
if (!(exec instanceof SysExecutor))
|
|
255
|
-
return;
|
|
256
|
-
const scope = { type: exec.type, name: exec.name };
|
|
257
|
-
const scanInfo = await exec.scan({ write: false });
|
|
258
|
-
const sources = await collectScopeRecipeSources(exec.workspace.workspaceRoot, scope, scanInfo.getScanResult().libDeps);
|
|
259
|
-
const expected = renderScopeAgentBlock(scope, scanRecipes2(sources));
|
|
260
|
-
const existing = await exec.exists("AGENTS.md") ? await exec.readFile("AGENTS.md") : null;
|
|
261
|
-
const actual = existing ? extractAgentBlock(existing) : null;
|
|
262
|
-
if (actual === expected.trim())
|
|
263
|
-
return;
|
|
264
|
-
throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
|
|
265
|
-
}
|
|
266
|
-
async#enforceRecipeGate(exec) {
|
|
267
|
-
const cwdPath = exec.cwdPath;
|
|
268
|
-
if (!cwdPath)
|
|
269
|
-
return;
|
|
270
|
-
const uiDir = path.join(cwdPath, "ui");
|
|
271
|
-
const sources = [
|
|
272
|
-
...await collectRecipeSources2(uiDir, "ui/Recipe"),
|
|
273
|
-
...await collectRecipeSources2(uiDir, "ui/recipe", "recipe")
|
|
274
|
-
];
|
|
275
|
-
if (sources.length === 0)
|
|
276
|
-
return;
|
|
277
|
-
const offenders = scanRecipes2(sources).filter((recipe) => !Object.values(recipe.variants).some((values) => values.length >= 2 || values.length === 1 && values[0] === "true"));
|
|
278
|
-
if (offenders.length === 0)
|
|
279
|
-
return;
|
|
280
|
-
throw new Error(`[recipeGate] variant-less recipe(s): ${[...new Set(offenders.map((recipe) => recipe.name))].join(", ")}
|
|
281
|
-
` + "A look with nothing to pick is not a recipe: promote one that has its own markup to a component, and keep " + "a skin passed into another component's className as a shared class constant.");
|
|
282
|
-
}
|
|
283
|
-
async#enforceStyleContract(exec) {
|
|
284
|
-
const cwdPath = exec.cwdPath;
|
|
285
|
-
if (!cwdPath)
|
|
286
|
-
return;
|
|
287
|
-
const stylesCssPath = path.join(cwdPath, "page", "styles.css");
|
|
288
|
-
if (!await Bun.file(stylesCssPath).exists())
|
|
289
|
-
return;
|
|
290
|
-
const violations = {
|
|
291
|
-
theme: new ThemeValidator().validate(await Bun.file(stylesCssPath).text())
|
|
292
|
-
};
|
|
293
|
-
const blocking = countBlocking(violations);
|
|
294
|
-
if (blocking === 0)
|
|
295
|
-
return;
|
|
296
|
-
throw new Error(`[themeValidator] ${blocking} blocking contrast violation(s):
|
|
297
|
-
${formatStyleContract(violations)}
|
|
298
|
-
|
|
299
|
-
` + "Raise the foreground/background contrast of these theme token values to the WCAG threshold.");
|
|
300
|
-
}
|
|
301
|
-
async writeTopLevelEnv(workspace, devProjectId) {
|
|
302
|
-
await workspace.writeFile(".env", `AKAN_WORKSPACE_ID=${devProjectId}
|
|
303
|
-
|
|
304
|
-
# organization configuration, no need to change
|
|
305
|
-
AKAN_PUBLIC_REPO_NAME=${workspace.repoName}
|
|
306
|
-
|
|
307
|
-
# serve domain, it changes the domain of the server.
|
|
308
|
-
AKAN_PUBLIC_SERVE_DOMAIN=try.akanjs.com
|
|
309
|
-
|
|
310
|
-
# development branch, debug, develop, main, etc. mainly it changes databases.
|
|
311
|
-
AKAN_PUBLIC_ENV=local
|
|
312
|
-
|
|
313
|
-
# local, cloud, edge it changes the connection point of the clients.
|
|
314
|
-
AKAN_PUBLIC_OPERATION_MODE=local
|
|
315
|
-
|
|
316
|
-
# log level, debug, info, warn, error
|
|
317
|
-
AKAN_PUBLIC_LOG_LEVEL=debug
|
|
318
|
-
`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// pkgs/@akanjs/cli/workspace/workspace.script.ts
|
|
323
|
-
import { Logger } from "akanjs/common";
|
|
324
|
-
class WorkspaceScript extends script("workspace", [
|
|
325
|
-
WorkspaceRunner,
|
|
326
|
-
ApplicationScript,
|
|
327
|
-
LibraryScript,
|
|
328
|
-
PackageScript,
|
|
329
|
-
CloudScript2,
|
|
330
|
-
ContextScript,
|
|
331
|
-
AgentScript
|
|
332
|
-
]) {
|
|
333
|
-
async createWorkspace(repoName, appName, {
|
|
334
|
-
dirname = ".",
|
|
335
|
-
installLibs = false,
|
|
336
|
-
init = true,
|
|
337
|
-
registryUrl,
|
|
338
|
-
owner,
|
|
339
|
-
mcpInstall = true,
|
|
340
|
-
agentInstall = true
|
|
341
|
-
}) {
|
|
342
|
-
const akanVersion = await this.packageScript.version(null, { log: false });
|
|
343
|
-
const workspace = await this.workspaceRunner.createWorkspace(repoName, appName, {
|
|
344
|
-
dirname,
|
|
345
|
-
init,
|
|
346
|
-
akanVersion,
|
|
347
|
-
...registryUrl ? { registryUrl } : {},
|
|
348
|
-
...owner ? { owner } : {}
|
|
349
|
-
});
|
|
350
|
-
if (installLibs) {
|
|
351
|
-
await this.libraryScript.installLibrary(workspace, "util");
|
|
352
|
-
await this.libraryScript.installLibrary(workspace, "shared");
|
|
353
|
-
}
|
|
354
|
-
await this.applicationScript.createApplication(appName, workspace, {
|
|
355
|
-
libs: installLibs ? ["util", "shared"] : [],
|
|
356
|
-
sample: true
|
|
357
|
-
});
|
|
358
|
-
await workspace.applyTemplate({
|
|
359
|
-
basePath: `apps/${appName}`,
|
|
360
|
-
template: "appSample",
|
|
361
|
-
dict: { appName },
|
|
362
|
-
options: { libs: installLibs ? ["util", "shared"] : [] }
|
|
363
|
-
});
|
|
364
|
-
if (agentInstall)
|
|
365
|
-
await this.agentScript.agent(workspace, "install", "all", { force: true });
|
|
366
|
-
if (mcpInstall)
|
|
367
|
-
await this.contextScript.mcpInstall(workspace, "all", { force: true });
|
|
368
|
-
const gitSpinner = workspace.spinning("Initializing git repository and commit...");
|
|
369
|
-
try {
|
|
370
|
-
await workspace.commit("Initial commit", { init: true });
|
|
371
|
-
gitSpinner.succeed("Git repository initialized and committed");
|
|
372
|
-
} catch (_) {
|
|
373
|
-
gitSpinner.fail("Git repository initialization failed. It's not fatal, you can commit manually");
|
|
374
|
-
}
|
|
375
|
-
Logger.rawLog(`
|
|
376
|
-
\uD83C\uDF89 Welcome aboard! Workspace created in ${workspace.workspaceRoot}`);
|
|
377
|
-
Logger.rawLog(`\uD83D\uDE80 Run \`cd ${workspace.workspaceRoot} && akan start ${appName}\` to start the development server.`);
|
|
378
|
-
Logger.rawLog(`
|
|
379
|
-
\uD83D\uDC4B Happy coding!`);
|
|
380
|
-
}
|
|
381
|
-
async generateAgentRules(workspace, { overwrite = false, cursorRules = true } = {}) {
|
|
382
|
-
const spinner = workspace.spinning("Generating agent rules...");
|
|
383
|
-
const files = await this.workspaceRunner.generateAgentRules(workspace, { overwrite, cursorRules });
|
|
384
|
-
if (files.some((file) => file.filePath.endsWith("AGENTS.md")))
|
|
385
|
-
await this.agentScript.agent(workspace, "install", "agents-md", { force: overwrite });
|
|
386
|
-
spinner.succeed(`Agent rules ready (${files.length} file${files.length === 1 ? "" : "s"})`);
|
|
387
|
-
}
|
|
388
|
-
async machineKeygen(workspace, out) {
|
|
389
|
-
const { file, publicKey } = await this.workspaceRunner.machineKeygen(workspace, out);
|
|
390
|
-
const access = process.platform === "win32" ? "; Windows gives it the permissions of its folder, so keep it in one only you can read" : " (mode 600)";
|
|
391
|
-
Logger.rawLog(`Wrote the private key to ${file}${access}. Set it as AKAN_MACHINE_PRIVATE_KEY on the server that issues machine tokens; nothing else needs it.`);
|
|
392
|
-
Logger.rawLog(`A server that only verifies them takes the public key:
|
|
393
|
-
AKAN_MACHINE_PUBLIC_KEY=${publicKey}`);
|
|
394
|
-
}
|
|
395
|
-
async lint(exec, workspace, { fix = true, maxDiagnostics } = {}) {
|
|
396
|
-
if (exec instanceof AppExecutor)
|
|
397
|
-
await this.applicationScript.sync(exec);
|
|
398
|
-
else if (exec instanceof LibExecutor)
|
|
399
|
-
await this.libraryScript.syncLibrary(exec);
|
|
400
|
-
const spinner = workspace.spinning(`Linting${fix ? " with fix" : ""}...`);
|
|
401
|
-
try {
|
|
402
|
-
await this.workspaceRunner.lint(exec, workspace, { fix, maxDiagnostics });
|
|
403
|
-
spinner.succeed("Lint completed with no errors");
|
|
404
|
-
} catch (error) {
|
|
405
|
-
spinner.fail("Lint failed with errors");
|
|
406
|
-
throw error;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
async lintAll(workspace, { fix = true, maxDiagnostics } = {}) {
|
|
410
|
-
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
411
|
-
const options = { fix, maxDiagnostics };
|
|
412
|
-
await Promise.all(appNames.map((appName) => this.applicationScript.sync(AppExecutor.from(workspace, appName))));
|
|
413
|
-
await Promise.all(libNames.map((libName) => this.libraryScript.syncLibrary(LibExecutor.from(workspace, libName))));
|
|
414
|
-
await Promise.all([
|
|
415
|
-
...appNames.map((appName) => this.workspaceRunner.lint(AppExecutor.from(workspace, appName), workspace, options)),
|
|
416
|
-
...libNames.map((libName) => this.workspaceRunner.lint(LibExecutor.from(workspace, libName), workspace, options)),
|
|
417
|
-
...pkgNames.filter((pkgName) => pkgName !== "contract").map((pkgName) => this.workspaceRunner.lint(PkgExecutor.from(workspace, pkgName), workspace, options))
|
|
418
|
-
]);
|
|
419
|
-
}
|
|
420
|
-
async syncAll(workspace) {
|
|
421
|
-
const [appNames, libNames] = await workspace.getExecs();
|
|
422
|
-
for (const libName of libNames)
|
|
423
|
-
await this.libraryScript.syncLibrary(LibExecutor.from(workspace, libName));
|
|
424
|
-
for (const appName of appNames)
|
|
425
|
-
await this.applicationScript.sync(AppExecutor.from(workspace, appName));
|
|
426
|
-
}
|
|
427
|
-
async init(devProjectId, workspace, { host } = {}) {
|
|
428
|
-
const [bunfigExists, packageJsonExists, tsconfigExists] = await Promise.all([
|
|
429
|
-
workspace.exists("bunfig.toml"),
|
|
430
|
-
workspace.exists("package.json"),
|
|
431
|
-
workspace.exists("tsconfig.json")
|
|
432
|
-
]);
|
|
433
|
-
const isRoot = bunfigExists && packageJsonExists && tsconfigExists;
|
|
434
|
-
if (!isRoot)
|
|
435
|
-
throw new Error("Current directory is not a root workspace");
|
|
436
|
-
const spinner = workspace.spinning("Initializing workspace...");
|
|
437
|
-
try {
|
|
438
|
-
await this.workspaceRunner.writeTopLevelEnv(workspace, devProjectId);
|
|
439
|
-
await this.cloudScript.downloadEnv(workspace, devProjectId, { host });
|
|
440
|
-
spinner.succeed("Workspace initialized");
|
|
441
|
-
} catch (error) {
|
|
442
|
-
spinner.fail("Workspace initialization failed");
|
|
443
|
-
throw error;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// pkgs/@akanjs/cli/workspace/workspace.command.ts
|
|
449
|
-
var maxDiagnosticsOption = {
|
|
450
|
-
desc: "How many diagnostics Biome prints before truncating (0 for no limit)",
|
|
451
|
-
default: defaultMaxDiagnostics
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
class WorkspaceCommand extends command("workspace", [WorkspaceScript], ({ public: target }) => ({
|
|
455
|
-
createWorkspace: target({ desc: "Create a new Akan.js workspace", runsOnWorkspaceRoot: false }).arg("workspaceName", String, { desc: "what is the name of your organization?" }).option("app", String, { desc: "what is the codename of your first application? (e.g. myapp)" }).option("dir", String, {
|
|
456
|
-
desc: "directory of workspace",
|
|
457
|
-
default: process.env.USE_AKANJS_PKGS === "true" ? "local" : "."
|
|
458
|
-
}).option("libs", Boolean, {
|
|
459
|
-
desc: "Do you want to install shared and util libraries? (admin, user file, etc.)",
|
|
460
|
-
enum: [
|
|
461
|
-
{ label: "No, I want to start with empty workspace (Recommended)", value: false },
|
|
462
|
-
{
|
|
463
|
-
label: "Yes, I want to accelerate development by installing shared and util libraries (for akanjs experts)",
|
|
464
|
-
value: true
|
|
465
|
-
}
|
|
466
|
-
],
|
|
467
|
-
default: false
|
|
468
|
-
}).option("init", Boolean, { desc: "Do you want to initialize the workspace? (Recommended)", default: true }).option("registry", String, {
|
|
469
|
-
desc: "npm registry URL for installing Akan packages",
|
|
470
|
-
default: process.env.AKAN_NPM_REGISTRY ?? "https://registry.npmjs.org"
|
|
471
|
-
}).option("owner", String, { desc: "owner of the workspace", default: process.env.GITHUB_OWNER, nullable: true }).option("mcpInstall", Boolean, {
|
|
472
|
-
desc: "Install the Akan MCP server config for Cursor, Claude Code, and Codex? (Recommended)",
|
|
473
|
-
default: true
|
|
474
|
-
}).option("agentInstall", Boolean, {
|
|
475
|
-
flag: "A",
|
|
476
|
-
desc: "Install Akan agent rules (AGENTS.md, CLAUDE.md, Cursor)? (Recommended)",
|
|
477
|
-
default: true
|
|
478
|
-
}).exec(async function(workspaceName, app, dir, libs, init, registry, owner, mcpInstall, agentInstall) {
|
|
479
|
-
const appName = app || "app";
|
|
480
|
-
await this.workspaceScript.createWorkspace(workspaceName.toLowerCase().replace(/ /g, "-"), appName.toLowerCase().replace(/ /g, "-"), {
|
|
481
|
-
dirname: dir,
|
|
482
|
-
installLibs: libs,
|
|
483
|
-
init,
|
|
484
|
-
owner,
|
|
485
|
-
mcpInstall,
|
|
486
|
-
agentInstall,
|
|
487
|
-
...registry ? { registryUrl: registry } : {}
|
|
488
|
-
});
|
|
489
|
-
}),
|
|
490
|
-
generateAgentRules: target({
|
|
491
|
-
desc: "Generate AGENTS.md, CLAUDE.md, and optional Cursor rules for Akan coding agents"
|
|
492
|
-
}).option("overwrite", Boolean, { desc: "Overwrite existing agent rule files", default: false }).option("cursorRules", Boolean, { desc: "Generate .cursor/rules/akan.mdc", default: true }).with(Workspace).exec(async function(overwrite, cursorRules, workspace) {
|
|
493
|
-
await this.workspaceScript.generateAgentRules(workspace, { overwrite, cursorRules });
|
|
494
|
-
}),
|
|
495
|
-
lint: target({ desc: "Lint and fix code in a specific app/lib/pkg" }).with(Exec).option("fix", Boolean, { default: true }).option("maxDiagnostics", Number, maxDiagnosticsOption).with(Workspace).exec(async function(exec, fix, maxDiagnostics, workspace) {
|
|
496
|
-
await this.workspaceScript.lint(exec, workspace, { fix, maxDiagnostics });
|
|
497
|
-
}),
|
|
498
|
-
lintAll: target({ desc: "Lint and fix code in all apps and libraries" }).option("fix", Boolean, { default: true }).option("maxDiagnostics", Number, maxDiagnosticsOption).with(Workspace).exec(async function(fix, maxDiagnostics, workspace) {
|
|
499
|
-
await this.workspaceScript.lintAll(workspace, { fix, maxDiagnostics });
|
|
500
|
-
}),
|
|
501
|
-
machineKeygen: target({
|
|
502
|
-
desc: "Make an Ed25519 key for machine tokens: write the private key to a file, print the public key"
|
|
503
|
-
}).arg("out", String, {
|
|
504
|
-
desc: "file the private key is written to (mode 600; on Windows, its folder's permissions); an existing one is refused"
|
|
505
|
-
}).with(Workspace).exec(async function(out, workspace) {
|
|
506
|
-
await this.workspaceScript.machineKeygen(workspace, out);
|
|
507
|
-
}),
|
|
508
|
-
syncAll: target({ desc: "Sync dependencies and configuration for all apps and libraries" }).with(Workspace).exec(async function(workspace) {
|
|
509
|
-
await this.workspaceScript.syncAll(workspace);
|
|
510
|
-
}),
|
|
511
|
-
init: target({ desc: "Initialize the workspace", runsOnWorkspaceRoot: false }).arg("devProjectId", String, { desc: "the ID of the workspace" }).option("host", String, {
|
|
512
|
-
desc: "host of the cloud to target (default: cloud.host of the root akan.config.ts, else Akan Cloud)",
|
|
513
|
-
nullable: true
|
|
514
|
-
}).with(Workspace).exec(async function(devProjectId, host, workspace) {
|
|
515
|
-
await this.workspaceScript.init(devProjectId, workspace, { host });
|
|
516
|
-
})
|
|
517
|
-
})) {
|
|
518
|
-
}
|
|
519
|
-
export {
|
|
520
|
-
WorkspaceCommand
|
|
521
|
-
};
|