@akanjs/cli 3.2.0-rc.1 → 3.2.0-rc.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.
- package/.build-stamp +2 -1
- package/{CodeAgent-vmd9k4ak.js → CodeAgent-fk66n37w.js} +3 -3
- package/{CodeTui-zka44v52.js → CodeTui-4rf1mqmv.js} +1 -1
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-44er4e29.js +15 -0
- package/{agent.command-2f657613.js → agent.command-7g9czkkd.js} +20 -19
- package/akanCode.js +3 -3
- package/{application.command-q6skd3am.js → application.command-00spg55s.js} +31 -24
- package/{applicationBuildRunner-sctcmkyx.js → applicationBuildRunner-f4yf0qyc.js} +9 -7
- package/buildBatch.proc.js +7 -6
- package/{cloud.command-7642pks6.js → cloud.command-ab704p0g.js} +24 -25
- package/cloud.script-4p4y0s7e.js +31 -0
- package/{code.command-7s4ndq2k.js → code.command-m6c9xk56.js} +7 -6
- package/{context.command-569z0rqf.js → context.command-hgcgxtdk.js} +20 -19
- package/context.runner-w071gmc3.js +30 -0
- package/{devTui-w38ch13a.js → devTui-h77zrjv5.js} +1 -1
- package/{guideline.command-gnv3e8p8.js → guideline.command-6yz6d4hf.js} +3 -2
- package/guidelines/agentRule/agentRule.instruction.md +4 -3
- package/guidelines/akanApi/akanApi.instruction.md +2 -0
- package/guidelines/conventions/core.md +1 -1
- package/guidelines/conventions/rules/app.md +3 -0
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/errorCodes/errorCodes.instruction.md +140 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +72 -2
- package/guidelines/pageRule/pageRule.instruction.md +5 -0
- package/guidelines/runtimeRule/runtimeRule.instruction.md +5 -1
- package/guidelines/transportRule/transportRule.instruction.md +5 -0
- package/incrementalBuilder.proc.js +8 -7
- package/{index-vkzfk7qt.js → index-097bjwvm.js} +40 -30
- package/{index-93ewzmp6.js → index-23d8gw08.js} +165 -102
- package/{index-p6hjwt2d.js → index-41mfhgq0.js} +72 -26
- package/{index-ktb3wcqz.js → index-4k9nv4m3.js} +71 -81
- package/{index-vr68mxj5.js → index-5jwx4bf2.js} +69 -33
- package/{index-5w9my9qe.js → index-6eptmk8z.js} +30 -20
- package/{index-d4n1wmrz.js → index-6fnrhpn1.js} +8 -4
- package/{index-kpdv34rq.js → index-6qtxs86x.js} +10 -7
- package/{index-ed6ea0qp.js → index-6z57w95f.js} +1 -1
- package/{index-drz9e84d.js → index-7ky4brfy.js} +2 -2
- package/{index-8g7tdsk4.js → index-849qvd7t.js} +58 -29
- package/{index-1q1cjn8s.js → index-9xh4zvw3.js} +94 -53
- package/{index-48d5qsj3.js → index-adj7qmz9.js} +23 -15
- package/{index-fjr4d6yd.js → index-apcr1qgk.js} +458 -304
- package/{index-8ts9774g.js → index-aybfcx58.js} +9 -4
- package/{index-8kczhnmv.js → index-b3pr4ee6.js} +1 -1
- package/{index-23860fej.js → index-b4qq3rq0.js} +23 -8
- package/{index-thckcabc.js → index-bper31wr.js} +24 -6
- package/{index-a8a9ede9.js → index-bxkx0x03.js} +14 -7
- package/{index-0fb3cpbt.js → index-c3r23w24.js} +9 -7
- package/{index-8pb9yvp8.js → index-dfsa009c.js} +148 -31
- package/{index-zpv14wpy.js → index-dsg50er9.js} +3 -3
- package/{index-hqrkqxx2.js → index-e5f6czck.js} +46 -7
- package/{index-sy481q2x.js → index-frvjq1rd.js} +1 -1
- package/{index-abgh0jve.js → index-grt0e6kk.js} +1 -1
- package/{index-e3vmjtph.js → index-hf9nvwam.js} +7 -2
- package/{index-v4p1zye8.js → index-hhagjhkh.js} +7 -7
- package/index-j4yvgfhr.js +70 -0
- package/{index-s2grpzef.js → index-k2r3hmbz.js} +6 -4
- package/{index-7y5yghjg.js → index-nd39rssn.js} +1162 -435
- package/{index-6wpaq392.js → index-p4htjyvk.js} +44 -5
- package/{index-aj3ehkcx.js → index-p54s83sz.js} +1 -1
- package/{index-7xdpww43.js → index-rdx8cyv2.js} +342 -134
- package/{index-sr5da35e.js → index-sq9d0jhj.js} +21 -18
- package/{index-eajbmk10.js → index-t4d0ckde.js} +2 -2
- package/{index-mqntfzv5.js → index-t8h09yjs.js} +7 -2
- package/index-va90m8nd.js +25 -0
- package/{index-rc5fvqj2.js → index-xfv2p7b5.js} +95 -58
- package/{index-w639tvkd.js → index-xgqz3kak.js} +29 -8
- package/{index-9tbgb4d8.js → index-xy70tcv4.js} +1 -1
- package/{index-mmym5xmb.js → index-z43wddce.js} +5 -3
- package/index.js +24 -23
- package/{library.command-1gp5qe3r.js → library.command-kc1zahcg.js} +5 -4
- package/{localRegistry.command-x7jptkd3.js → localRegistry.command-bz2df40m.js} +19 -18
- package/{module.command-4xz9he6h.js → module.command-cchwzz9r.js} +12 -7
- package/{package.command-s7qpnn1g.js → package.command-qcjajpv8.js} +8 -7
- package/package.json +2 -2
- package/{page.command-fan34c49.js → page.command-1t86dx8a.js} +4 -3
- package/{pipeline.command-ph4fnn9w.js → pipeline.command-2xx9z3d0.js} +3 -2
- package/{primitive.command-3fqh8emf.js → primitive.command-mc0x8txr.js} +8 -7
- package/{projectTypecheck-vkb40hjc.js → projectTypecheck-tz497yx7.js} +2 -1
- package/{quality.command-ecj6exsh.js → quality.command-11rayf5c.js} +7 -6
- package/{repair.command-fe9jw719.js → repair.command-8w41vy78.js} +7 -6
- package/{scalar.command-cnvfhk0n.js → scalar.command-rvwh98ny.js} +7 -6
- package/skills/akan-debug/SKILL.md +7 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +10 -1
- package/skills/akan-scaffold/SKILL.md +3 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-qw5ddd6y.js → subspace.command-0970n7kd.js} +9 -8
- package/{tunnel.command-ggj38mqf.js → tunnel.command-bcy0rtmh.js} +8 -7
- package/typecheck.proc.js +5 -2
- package/{verify.command-w9ttxkdz.js → verify.command-ynaztxr2.js} +18 -16
- package/{workflow.command-ss8devj0.js → workflow.command-yp9ajthb.js} +45 -16
- package/{workspace.command-6z2rh8ze.js → workspace.command-e4wfxm86.js} +39 -34
- package/TunnelShare-k3ja4w9x.js +0 -14
- package/cloud.script-1sfseznn.js +0 -30
- package/context.runner-ms8v1rxy.js +0 -29
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
WorkspaceExecutor
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-sq9d0jhj.js";
|
|
5
|
+
import {
|
|
6
|
+
AkanContextAnalyzer
|
|
7
|
+
} from "./index-bper31wr.js";
|
|
5
8
|
import {
|
|
6
9
|
jsonText,
|
|
7
10
|
workflowPlanApproval,
|
|
@@ -27,30 +30,27 @@ import {
|
|
|
27
30
|
renderWorkflowApply,
|
|
28
31
|
renderWorkflowValidation,
|
|
29
32
|
renderWorkflowRunArtifact
|
|
30
|
-
} from "./index-
|
|
31
|
-
import {
|
|
32
|
-
AkanContextAnalyzer
|
|
33
|
-
} from "./index-thckcabc.js";
|
|
33
|
+
} from "./index-dfsa009c.js";
|
|
34
34
|
import {
|
|
35
35
|
CommandContainer,
|
|
36
36
|
runner
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-23d8gw08.js";
|
|
38
38
|
import {
|
|
39
39
|
ModuleScript
|
|
40
|
-
} from "./index-
|
|
40
|
+
} from "./index-aybfcx58.js";
|
|
41
41
|
import {
|
|
42
42
|
PrimitiveScript
|
|
43
|
-
} from "./index-
|
|
43
|
+
} from "./index-adj7qmz9.js";
|
|
44
44
|
import {
|
|
45
45
|
spawnAkan,
|
|
46
46
|
isWorkspaceTarget
|
|
47
|
-
} from "./index-
|
|
47
|
+
} from "./index-c3r23w24.js";
|
|
48
48
|
import {
|
|
49
49
|
ScalarScript
|
|
50
|
-
} from "./index-
|
|
50
|
+
} from "./index-hf9nvwam.js";
|
|
51
51
|
import {
|
|
52
52
|
workflowSpecs
|
|
53
|
-
} from "./index-
|
|
53
|
+
} from "./index-t4d0ckde.js";
|
|
54
54
|
|
|
55
55
|
// pkgs/@akanjs/cli/workflow/workflow.runner.ts
|
|
56
56
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
@@ -271,11 +271,11 @@ class WorkflowRunner extends runner("workflow") {
|
|
|
271
271
|
throw new Error(`Unknown workflow: ${workflow}. Run \`akan workflow list\` to see available workflows.`);
|
|
272
272
|
return format === "json" ? jsonText(spec) : renderWorkflowExplain(spec);
|
|
273
273
|
}
|
|
274
|
-
async plan(workflow, inputs, {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
} = {}) {
|
|
274
|
+
async plan(workflow, inputs, { format = "markdown", ...options } = {}) {
|
|
275
|
+
const plan = await this.planReport(workflow, inputs, options);
|
|
276
|
+
return format === "json" ? jsonText(plan) : renderWorkflowPlan(plan);
|
|
277
|
+
}
|
|
278
|
+
async planReport(workflow, inputs, { out = null, workspace } = {}) {
|
|
279
279
|
const spec = getWorkflowSpec(workflowSpecs, workflow);
|
|
280
280
|
if (!spec)
|
|
281
281
|
throw new Error(`Unknown workflow: ${workflow}. Run \`akan workflow list\` to see available workflows.`);
|
|
@@ -285,54 +285,64 @@ class WorkflowRunner extends runner("workflow") {
|
|
|
285
285
|
await mkdir(path.dirname(outPath), { recursive: true });
|
|
286
286
|
await writeFile(outPath, jsonText(plan));
|
|
287
287
|
}
|
|
288
|
-
return
|
|
288
|
+
return plan;
|
|
289
289
|
}
|
|
290
290
|
async apply(planPath, {
|
|
291
|
-
dryRun = false,
|
|
292
291
|
format = "markdown",
|
|
292
|
+
...options
|
|
293
|
+
} = {}) {
|
|
294
|
+
return renderWorkflowApply(await this.applyReport(planPath, options), format);
|
|
295
|
+
}
|
|
296
|
+
async applyReport(planPath, {
|
|
297
|
+
dryRun = false,
|
|
293
298
|
registry,
|
|
294
299
|
workspace
|
|
295
300
|
} = {}) {
|
|
296
|
-
const
|
|
301
|
+
const recordApplyReport = async (report) => {
|
|
297
302
|
if (!workspace)
|
|
298
|
-
return
|
|
303
|
+
return report;
|
|
299
304
|
const { artifact } = await writeWorkflowRunArtifact(workspace, report);
|
|
300
|
-
return
|
|
305
|
+
return artifact;
|
|
301
306
|
};
|
|
302
307
|
let plan;
|
|
303
308
|
try {
|
|
304
309
|
const parsed = await readJsonFile(planPath);
|
|
305
310
|
if (!isWorkflowPlan(parsed))
|
|
306
|
-
return await
|
|
311
|
+
return await recordApplyReport(failedApplyReport("unknown", "workflow-plan-invalid", `Workflow plan file is invalid: ${planPath}.`));
|
|
307
312
|
plan = parsed;
|
|
308
313
|
} catch (error) {
|
|
309
314
|
const message = `Could not read workflow plan file: ${planPath}. ${error instanceof Error ? error.message : ""}`;
|
|
310
|
-
return await
|
|
315
|
+
return await recordApplyReport(failedApplyReport("unknown", "workflow-plan-read-failed", message.trim()));
|
|
311
316
|
}
|
|
312
317
|
const spec = getWorkflowSpec(workflowSpecs, plan.workflow);
|
|
313
318
|
if (!spec) {
|
|
314
319
|
const message = `Unknown workflow in plan: ${plan.workflow}.`;
|
|
315
|
-
return await
|
|
320
|
+
return await recordApplyReport(failedApplyReport(plan.workflow, "workflow-unknown", message, plan));
|
|
316
321
|
}
|
|
317
322
|
const inputErrors = inputErrorsOf(spec, plan);
|
|
318
323
|
if (inputErrors.length) {
|
|
319
324
|
const message = inputErrors.map((diagnostic) => diagnostic.message).join(" ");
|
|
320
|
-
return await
|
|
325
|
+
return await recordApplyReport(failedApplyReport(plan.workflow, "workflow-plan-inputs-invalid", message, plan));
|
|
321
326
|
}
|
|
322
327
|
const targetErrors = await workflowTargetDiagnostics(workspace ?? WorkspaceExecutor.fromRoot(), spec, plan.inputs);
|
|
323
328
|
if (targetErrors.length)
|
|
324
|
-
return await
|
|
329
|
+
return await recordApplyReport(refusedApplyReport(plan.workflow, targetErrors, { plan, mode: dryRun ? "dry-run" : "apply" }));
|
|
325
330
|
plan = { ...plan, steps: spec.steps, validation: spec.validation };
|
|
326
331
|
if (dryRun)
|
|
327
|
-
return await
|
|
332
|
+
return await recordApplyReport(createDryRunWorkflowApplyReport(plan));
|
|
328
333
|
if (!registry) {
|
|
329
334
|
const message = "Workflow apply requires a step runner registry.";
|
|
330
|
-
return await
|
|
335
|
+
return await recordApplyReport(failedApplyReport(plan.workflow, "workflow-registry-missing", message, plan));
|
|
331
336
|
}
|
|
332
|
-
return await
|
|
337
|
+
return await recordApplyReport(await new WorkflowExecutor(registry, workspace).apply(plan));
|
|
333
338
|
}
|
|
334
339
|
async validate(runIdOrPlan, {
|
|
335
340
|
format = "markdown",
|
|
341
|
+
...options
|
|
342
|
+
}) {
|
|
343
|
+
return renderWorkflowValidation(await this.validateReport(runIdOrPlan, options), format);
|
|
344
|
+
}
|
|
345
|
+
async validateReport(runIdOrPlan, {
|
|
336
346
|
workspace,
|
|
337
347
|
execute,
|
|
338
348
|
includeBaselineDetails = false
|
|
@@ -356,7 +366,7 @@ class WorkflowRunner extends runner("workflow") {
|
|
|
356
366
|
repairActions: loaded.repairActions
|
|
357
367
|
})), includeBaselineDetails);
|
|
358
368
|
await writeWorkflowRunArtifact(workspace, report);
|
|
359
|
-
return
|
|
369
|
+
return report;
|
|
360
370
|
}
|
|
361
371
|
async report(runId, { format = "markdown", workspace }) {
|
|
362
372
|
try {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
CliError
|
|
4
|
+
} from "./index-j4yvgfhr.js";
|
|
2
5
|
import {
|
|
3
6
|
getDirname2,
|
|
4
7
|
FileSys2
|
|
@@ -10,7 +13,7 @@ import {
|
|
|
10
13
|
LibExecutor,
|
|
11
14
|
PkgExecutor,
|
|
12
15
|
ModuleExecutor
|
|
13
|
-
} from "./index-
|
|
16
|
+
} from "./index-sq9d0jhj.js";
|
|
14
17
|
|
|
15
18
|
// pkgs/@akanjs/devkit/commandDecorators/camelToKebabCase.ts
|
|
16
19
|
var camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
@@ -58,6 +61,7 @@ var SysOrOnlyApp = createInternalArgToken("Sys", { onlyApp: true });
|
|
|
58
61
|
var Exec = createInternalArgToken("Exec");
|
|
59
62
|
var Pkg = createInternalArgToken("Pkg");
|
|
60
63
|
var Module = createInternalArgToken("Module");
|
|
64
|
+
var ModuleOrService = createInternalArgToken("Module", { services: true });
|
|
61
65
|
var Workspace = createInternalArgToken("Workspace");
|
|
62
66
|
// pkgs/@akanjs/devkit/commandDecorators/command.ts
|
|
63
67
|
import path3 from "path";
|
|
@@ -160,19 +164,6 @@ var script = (refName, deps = []) => {
|
|
|
160
164
|
return ScriptBase;
|
|
161
165
|
};
|
|
162
166
|
|
|
163
|
-
// pkgs/@akanjs/devkit/commandDecorators/exitCodeError.ts
|
|
164
|
-
class ExitCodeError extends Error {
|
|
165
|
-
exitCode;
|
|
166
|
-
name = "ExitCodeError";
|
|
167
|
-
constructor(message, exitCode) {
|
|
168
|
-
super(message);
|
|
169
|
-
this.exitCode = exitCode;
|
|
170
|
-
}
|
|
171
|
-
static codeOf(error) {
|
|
172
|
-
return error instanceof ExitCodeError ? error.exitCode : null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
167
|
// pkgs/@akanjs/devkit/commandDecorators/helpFormatter.ts
|
|
177
168
|
import chalk from "chalk";
|
|
178
169
|
var formatChoice = (choice) => typeof choice === "object" ? choice.label : choice.toString();
|
|
@@ -358,39 +349,54 @@ class WorkspaceVersionCheck {
|
|
|
358
349
|
|
|
359
350
|
// pkgs/@akanjs/devkit/commandDecorators/command.ts
|
|
360
351
|
var loggedCliErrorObjects = new WeakSet;
|
|
352
|
+
var answeredCliErrors = new WeakSet;
|
|
361
353
|
var loggedCliErrorMessages = new Set;
|
|
362
354
|
var markCliErrorPrinted = (error) => {
|
|
363
|
-
if (typeof error
|
|
364
|
-
|
|
355
|
+
if (typeof error !== "object" || error === null)
|
|
356
|
+
return;
|
|
357
|
+
loggedCliErrorObjects.add(error);
|
|
358
|
+
answeredCliErrors.add(error);
|
|
365
359
|
};
|
|
366
|
-
var
|
|
367
|
-
if (error instanceof Error)
|
|
368
|
-
return error.message || error.name;
|
|
369
|
-
if (typeof error === "string")
|
|
370
|
-
return error.trim() || "Unknown error";
|
|
371
|
-
if (error === null || error === undefined)
|
|
372
|
-
return "Unknown error";
|
|
373
|
-
try {
|
|
374
|
-
const json = JSON.stringify(error);
|
|
375
|
-
if (json)
|
|
376
|
-
return json;
|
|
377
|
-
} catch {
|
|
378
|
-
return String(error);
|
|
379
|
-
}
|
|
380
|
-
return String(error) || "Unknown error";
|
|
381
|
-
};
|
|
382
|
-
var printCliError = (error) => {
|
|
360
|
+
var printCliError = (error, stream = "log") => {
|
|
383
361
|
if (typeof error === "object" && error !== null) {
|
|
384
362
|
if (loggedCliErrorObjects.has(error))
|
|
385
363
|
return;
|
|
386
364
|
loggedCliErrorObjects.add(error);
|
|
387
365
|
}
|
|
388
|
-
const message =
|
|
366
|
+
const message = CliError.messageOf(error);
|
|
389
367
|
if (loggedCliErrorMessages.has(message))
|
|
390
368
|
return;
|
|
391
369
|
loggedCliErrorMessages.add(message);
|
|
392
370
|
Logger.rawLog(`
|
|
393
|
-
${chalk2.red(message)}
|
|
371
|
+
${chalk2.red(message)}`, undefined, stream);
|
|
372
|
+
};
|
|
373
|
+
var asksJson = (argMetas, opt) => argMetas.some((argMeta) => {
|
|
374
|
+
if (argMeta.type !== "Option")
|
|
375
|
+
return false;
|
|
376
|
+
const value = opt[argMeta.name] ?? argMeta.argsOption.default;
|
|
377
|
+
if (argMeta.name === "json")
|
|
378
|
+
return value === true || value === "true";
|
|
379
|
+
return argMeta.name === "format" && value === "json";
|
|
380
|
+
});
|
|
381
|
+
var writeJsonFailure = async (error) => {
|
|
382
|
+
if (typeof error === "object" && error !== null && answeredCliErrors.has(error))
|
|
383
|
+
return;
|
|
384
|
+
const line = `${JSON.stringify(CliError.failureOf(error))}
|
|
385
|
+
`;
|
|
386
|
+
await new Promise((resolve) => process.stdout.write(line, () => resolve()));
|
|
387
|
+
};
|
|
388
|
+
var failureReporterOf = (json, onFailure, failure) => async (error) => {
|
|
389
|
+
if (onFailure)
|
|
390
|
+
await onFailure(error, failure);
|
|
391
|
+
else if (json)
|
|
392
|
+
await writeJsonFailure(error);
|
|
393
|
+
};
|
|
394
|
+
var usageRefusalOf = (error) => {
|
|
395
|
+
if (error.exitCode === 0)
|
|
396
|
+
process.exit(0);
|
|
397
|
+
const refused = new CliError("usage", error.message.replace(/^error: /, ""));
|
|
398
|
+
loggedCliErrorObjects.add(refused);
|
|
399
|
+
return refused;
|
|
394
400
|
};
|
|
395
401
|
var handleOption = (programCommand, argMeta) => {
|
|
396
402
|
const {
|
|
@@ -451,13 +457,14 @@ var assertEnumChoice = (argMeta, value) => {
|
|
|
451
457
|
const choices = normalizeEnumChoices(enumChoices);
|
|
452
458
|
if (choices.some((choice) => String(choice.value) === String(value)))
|
|
453
459
|
return;
|
|
454
|
-
throw new
|
|
460
|
+
throw new CliError("usage", `${argLabelOf(argMeta)} argument '${String(value)}' is invalid. Allowed choices are ${choices.map((choice) => choice.name).join(", ")}.`);
|
|
455
461
|
};
|
|
456
|
-
var assertPromptable = (problem,
|
|
462
|
+
var assertPromptable = (problem, refusal = {}) => {
|
|
457
463
|
if (process.stdin.isTTY)
|
|
458
464
|
return;
|
|
459
|
-
throw
|
|
465
|
+
throw refusalOf(problem, "stdin is not a terminal to prompt on", refusal);
|
|
460
466
|
};
|
|
467
|
+
var refusalOf = (problem, reason, { choices = [], remedy = "pass it on the command line", code = "usage" }) => new CliError(code, `${problem}: ${reason}, so ${remedy}${choices.length ? ` (choices: ${choices.join(", ")})` : ""}.`);
|
|
461
468
|
var inputMessageOf = ({ name, argsOption: { desc, example, ask } }) => ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
462
469
|
var getOptionValue = async (argMeta, opt, context) => {
|
|
463
470
|
const {
|
|
@@ -531,7 +538,7 @@ var assertCurrentDirectoryIsWorkspaceRoot = async () => {
|
|
|
531
538
|
]);
|
|
532
539
|
if (hasPackageJson && hasTsConfig && hasMemberDirs.some(Boolean))
|
|
533
540
|
return;
|
|
534
|
-
throw new
|
|
541
|
+
throw new CliError("usage", [
|
|
535
542
|
"Akan CLI commands must be run from the workspace root.",
|
|
536
543
|
`Current directory: ${cwd}`,
|
|
537
544
|
"Move to the directory that contains package.json, tsconfig.json, and an apps/, libs/ or pkgs/ folder, then run the command again."
|
|
@@ -566,7 +573,7 @@ var getAppsArgumentValue = async (value, workspace, rerun) => {
|
|
|
566
573
|
if (requested.length) {
|
|
567
574
|
const unknown = requested.filter((name) => !appNames.includes(name));
|
|
568
575
|
if (unknown.length)
|
|
569
|
-
throw new
|
|
576
|
+
throw new CliError("unknownTarget", `Unknown app${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}. Available: ${appNames.join(", ")}, all`);
|
|
570
577
|
return [...new Set(requested)].map((name) => AppExecutor.from(workspace, name));
|
|
571
578
|
}
|
|
572
579
|
if (appNames.length === 1 && appNames[0])
|
|
@@ -581,12 +588,26 @@ var getAppsArgumentValue = async (value, workspace, rerun) => {
|
|
|
581
588
|
await AppSelectionMemory.write(workspace.workspaceRoot, picked);
|
|
582
589
|
return picked.map((name) => AppExecutor.from(workspace, name));
|
|
583
590
|
};
|
|
584
|
-
var getInternalArgumentValue = async (argMeta, value, workspace, rerun) => {
|
|
591
|
+
var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destructive = false } = {}) => {
|
|
585
592
|
if (argMeta.type === "Workspace")
|
|
586
593
|
return workspace;
|
|
587
594
|
const sysType = argMeta.type.toLowerCase();
|
|
588
595
|
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
589
596
|
const problemOf = (kind) => value ? `Unknown ${kind} '${value}'` : `Missing ${kind}`;
|
|
597
|
+
const assertAskable = (kind, choices, placeholder) => {
|
|
598
|
+
const refusal = { choices, code: value ? "unknownTarget" : "usage", ...rerunRemedyOf(rerun, placeholder) };
|
|
599
|
+
if (destructive)
|
|
600
|
+
throw refusalOf(problemOf(kind), "this command deletes files and never picks its target", refusal);
|
|
601
|
+
assertPromptable(problemOf(kind), refusal);
|
|
602
|
+
};
|
|
603
|
+
const takeOnly = (kind, names, take) => {
|
|
604
|
+
const [only] = names;
|
|
605
|
+
if (value || destructive || process.stdin.isTTY || names.length !== 1 || !only)
|
|
606
|
+
return null;
|
|
607
|
+
const how = rerun ? `: ${rerun(only)}` : "";
|
|
608
|
+
Logger.rawLog(`No ${kind} named, so this runs on '${only}', the only one in this workspace${how}`, undefined, "error");
|
|
609
|
+
return take(only);
|
|
610
|
+
};
|
|
590
611
|
if (sysType === "sys" || sysType === "exec") {
|
|
591
612
|
const pkgChoices = sysType === "exec" ? pkgNames : [];
|
|
592
613
|
const execOf = (name) => {
|
|
@@ -601,72 +622,83 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun) => {
|
|
|
601
622
|
const found = value ? execOf(value) : null;
|
|
602
623
|
if (found)
|
|
603
624
|
return found;
|
|
604
|
-
if (!value && argMeta.option?.onlyApp && appNames.length === 1 && appNames[0])
|
|
625
|
+
if (!value && !destructive && argMeta.option?.onlyApp && appNames.length === 1 && appNames[0])
|
|
605
626
|
return AppExecutor.from(workspace, appNames[0]);
|
|
606
627
|
const [kind, placeholder] = sysType === "exec" ? ["app, lib or pkg", "<app-lib-or-pkg>"] : ["app or lib", "<app-or-lib>"];
|
|
607
628
|
const choices = [...appNames, ...libNames, ...pkgChoices];
|
|
608
|
-
const only = choices
|
|
609
|
-
if (
|
|
610
|
-
const how = rerun ? `: ${rerun(only.name)}` : "";
|
|
611
|
-
Logger.rawLog(`No ${kind} named, so this runs on '${only.name}', the only one in this workspace${how}`, undefined, "error");
|
|
629
|
+
const only = takeOnly(kind, choices, execOf);
|
|
630
|
+
if (only)
|
|
612
631
|
return only;
|
|
613
|
-
|
|
614
|
-
assertPromptable(problemOf(kind), { choices, ...rerunRemedyOf(rerun, placeholder) });
|
|
632
|
+
assertAskable(kind, choices, placeholder);
|
|
615
633
|
const name = await select({
|
|
616
634
|
message: sysType === "exec" ? `Select the App or Lib or Pkg name` : `Select the App or Lib name`,
|
|
617
635
|
choices
|
|
618
636
|
});
|
|
619
637
|
const picked = execOf(name);
|
|
620
638
|
if (!picked)
|
|
621
|
-
throw new
|
|
639
|
+
throw new CliError("unknownTarget", `Invalid system name: ${name}`);
|
|
622
640
|
return picked;
|
|
623
641
|
} else if (sysType === "app") {
|
|
624
642
|
if (value && appNames.includes(value))
|
|
625
643
|
return AppExecutor.from(workspace, value);
|
|
626
|
-
if (!value && appNames.length === 1 && appNames[0])
|
|
644
|
+
if (!value && !destructive && appNames.length === 1 && appNames[0])
|
|
627
645
|
return AppExecutor.from(workspace, appNames[0]);
|
|
628
|
-
|
|
646
|
+
assertAskable("app", appNames, "<app>");
|
|
629
647
|
const appName = await select({ message: `Select the ${sysType} name`, choices: appNames });
|
|
630
648
|
return AppExecutor.from(workspace, appName);
|
|
631
649
|
} else if (sysType === "lib") {
|
|
632
650
|
if (value && libNames.includes(value))
|
|
633
651
|
return LibExecutor.from(workspace, value);
|
|
634
|
-
|
|
652
|
+
const only = takeOnly("lib", libNames, (name) => LibExecutor.from(workspace, name));
|
|
653
|
+
if (only)
|
|
654
|
+
return only;
|
|
655
|
+
assertAskable("lib", libNames, "<lib>");
|
|
635
656
|
const libName = await select({ message: `Select the ${sysType} name`, choices: libNames });
|
|
636
657
|
return LibExecutor.from(workspace, libName);
|
|
637
658
|
} else if (sysType === "pkg") {
|
|
638
659
|
const pkgs = await workspace.getPkgs();
|
|
639
660
|
if (value && pkgs.includes(value))
|
|
640
661
|
return PkgExecutor.from(workspace, value);
|
|
641
|
-
|
|
662
|
+
const only = takeOnly("pkg", pkgs, (name) => PkgExecutor.from(workspace, name));
|
|
663
|
+
if (only)
|
|
664
|
+
return only;
|
|
665
|
+
assertAskable("pkg", pkgs, "<pkg>");
|
|
642
666
|
const pkgName = await select({ message: `Select the ${sysType} name`, choices: pkgs });
|
|
643
667
|
return PkgExecutor.from(workspace, pkgName);
|
|
644
668
|
} else if (sysType === "module") {
|
|
645
|
-
if (value) {
|
|
646
|
-
const [sysName, moduleName] = value.split(":");
|
|
647
|
-
if (!sysName || !moduleName)
|
|
648
|
-
throw new Error(`Invalid module name: ${value}`);
|
|
649
|
-
if (appNames.includes(sysName)) {
|
|
650
|
-
const app = AppExecutor.from(workspace, sysName);
|
|
651
|
-
const modules = await app.getModules();
|
|
652
|
-
if (modules.includes(moduleName))
|
|
653
|
-
return ModuleExecutor.from(app, moduleName);
|
|
654
|
-
else
|
|
655
|
-
throw new Error(`Invalid module name: ${moduleName}`);
|
|
656
|
-
} else if (libNames.includes(sysName)) {
|
|
657
|
-
const lib = LibExecutor.from(workspace, sysName);
|
|
658
|
-
const modules = await lib.getModules();
|
|
659
|
-
if (modules.includes(moduleName))
|
|
660
|
-
return ModuleExecutor.from(lib, moduleName);
|
|
661
|
-
} else
|
|
662
|
-
throw new Error(`Invalid system name: ${sysName}`);
|
|
663
|
-
}
|
|
664
669
|
const systems = [
|
|
665
670
|
...appNames.map((name) => AppExecutor.from(workspace, name)),
|
|
666
671
|
...libNames.map((name) => LibExecutor.from(workspace, name))
|
|
667
672
|
];
|
|
668
|
-
const
|
|
669
|
-
|
|
673
|
+
const modulesOf = async (sys) => [
|
|
674
|
+
...await sys.getModules(),
|
|
675
|
+
...argMeta.option?.services ? await sys.getServiceModules() : []
|
|
676
|
+
];
|
|
677
|
+
const listModules = async () => (await Promise.all(systems.map(async (sys) => (await modulesOf(sys)).map((m) => `${sys.name}:${m}`)))).flat();
|
|
678
|
+
if (value) {
|
|
679
|
+
const [sysName, moduleName] = value.split(":");
|
|
680
|
+
if (!sysName || !moduleName)
|
|
681
|
+
throw new CliError("usage", `Invalid module name: ${value}`);
|
|
682
|
+
const sys = systems.find((each) => each.name === sysName);
|
|
683
|
+
if (!sys)
|
|
684
|
+
throw new CliError("unknownTarget", `Invalid system name: ${sysName}`);
|
|
685
|
+
if ((await modulesOf(sys)).includes(moduleName))
|
|
686
|
+
return ModuleExecutor.from(sys, moduleName);
|
|
687
|
+
throw refusalOf(problemOf("module"), `${sysName} has no such module`, {
|
|
688
|
+
code: "unknownTarget",
|
|
689
|
+
choices: await listModules(),
|
|
690
|
+
...rerunRemedyOf(rerun, "<sys:module>")
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
const choices = process.stdin.isTTY && !destructive ? [] : await listModules();
|
|
694
|
+
const only = takeOnly("module", choices, (label) => {
|
|
695
|
+
const [sysName, moduleName = ""] = label.split(":");
|
|
696
|
+
const sys = systems.find((each) => each.name === sysName);
|
|
697
|
+
return sys ? ModuleExecutor.from(sys, moduleName) : null;
|
|
698
|
+
});
|
|
699
|
+
if (only)
|
|
700
|
+
return only;
|
|
701
|
+
assertAskable("module", choices, "<sys:module>");
|
|
670
702
|
const { type, name } = await select({
|
|
671
703
|
message: `select the App or Lib name`,
|
|
672
704
|
choices: [
|
|
@@ -675,7 +707,7 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun) => {
|
|
|
675
707
|
]
|
|
676
708
|
});
|
|
677
709
|
const executor = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
|
|
678
|
-
const modules = await executor
|
|
710
|
+
const modules = await modulesOf(executor);
|
|
679
711
|
const moduleName = await select({
|
|
680
712
|
message: `Select the module name`,
|
|
681
713
|
choices: modules.map((name) => ({ name: `${executor.name}:${name}`, value: name }))
|
|
@@ -684,13 +716,33 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun) => {
|
|
|
684
716
|
} else
|
|
685
717
|
throw new Error(`Invalid system type: ${argMeta.type}`);
|
|
686
718
|
};
|
|
719
|
+
var cliFailureOf = () => {
|
|
720
|
+
let failing = false;
|
|
721
|
+
const failure = {
|
|
722
|
+
exitCode: 1,
|
|
723
|
+
usageExitCode: undefined,
|
|
724
|
+
stream: "log",
|
|
725
|
+
report: async (_error) => {},
|
|
726
|
+
exitCodeOf: (error) => {
|
|
727
|
+
const { usageExitCode } = failure;
|
|
728
|
+
if (usageExitCode !== undefined && error instanceof CliError && CliError.usageCodes.includes(error.code))
|
|
729
|
+
return usageExitCode;
|
|
730
|
+
return CliError.exitCodeOf(error) ?? failure.exitCode;
|
|
731
|
+
},
|
|
732
|
+
fail: async (error) => {
|
|
733
|
+
if (failing)
|
|
734
|
+
return;
|
|
735
|
+
failing = true;
|
|
736
|
+
printCliError(error, failure.stream);
|
|
737
|
+
await failure.report(error).catch((reportError) => printCliError(reportError, "error"));
|
|
738
|
+
process.exit(failure.exitCodeOf(error));
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
return failure;
|
|
742
|
+
};
|
|
687
743
|
var runCommands = async (...commands) => {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
process.on("unhandledRejection", (error) => {
|
|
691
|
-
printCliError(error);
|
|
692
|
-
process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
|
|
693
|
-
});
|
|
744
|
+
const failure = cliFailureOf();
|
|
745
|
+
process.on("unhandledRejection", (error) => void failure.fail(error));
|
|
694
746
|
const __dirname2 = getDirname2(import.meta.url);
|
|
695
747
|
const packageJsonCandidates = [`${path3.dirname(Bun.main)}/package.json`, `${__dirname2}/../package.json`];
|
|
696
748
|
let cliPackageJson = null;
|
|
@@ -724,20 +776,16 @@ ${versionWarning}`), undefined, "error");
|
|
|
724
776
|
let programCommand = program.command(commandName, {
|
|
725
777
|
hidden: targetMeta.targetOption.devOnly
|
|
726
778
|
});
|
|
727
|
-
const targetFailureExitCode = targetMeta.targetOption
|
|
728
|
-
const usageExitCode = targetMeta.targetOption.usageExitCode ?? targetFailureExitCode;
|
|
779
|
+
const { failureExitCode: targetFailureExitCode, usageExitCode: targetUsageExitCode } = targetMeta.targetOption;
|
|
729
780
|
const { onFailure } = targetMeta.targetOption;
|
|
730
781
|
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
reportFailure = async (failure) => await onFailure?.(failure, { usage: true, given });
|
|
739
|
-
throw refused;
|
|
740
|
-
});
|
|
782
|
+
programCommand.exitOverride((error) => {
|
|
783
|
+
const refused = usageRefusalOf(error);
|
|
784
|
+
failure.usageExitCode = targetUsageExitCode;
|
|
785
|
+
const given = givenOptionsOf(allArgMetas, programCommand.opts());
|
|
786
|
+
failure.report = failureReporterOf(asksJson(allArgMetas, given), onFailure, { usage: true, given });
|
|
787
|
+
throw refused;
|
|
788
|
+
});
|
|
741
789
|
for (const argMeta of allArgMetas) {
|
|
742
790
|
if (argMeta.type === "Option")
|
|
743
791
|
programCommand = handleOption(programCommand, argMeta);
|
|
@@ -759,12 +807,18 @@ ${versionWarning}`), undefined, "error");
|
|
|
759
807
|
return formatCommandHelp(command, targetMeta.key);
|
|
760
808
|
};
|
|
761
809
|
programCommand.action(async (...args) => {
|
|
762
|
-
|
|
810
|
+
failure.exitCode = targetFailureExitCode ?? 1;
|
|
811
|
+
failure.usageExitCode = targetUsageExitCode;
|
|
763
812
|
if (!targetMeta.targetOption.stdio)
|
|
764
813
|
Logger.rawLog();
|
|
765
814
|
const cmdArgs = args.slice(0, args.length - 2);
|
|
766
815
|
const opt = args[args.length - 2];
|
|
767
|
-
|
|
816
|
+
const json = asksJson(allArgMetas, opt);
|
|
817
|
+
failure.stream = json ? "error" : "log";
|
|
818
|
+
failure.report = failureReporterOf(json, onFailure, {
|
|
819
|
+
usage: false,
|
|
820
|
+
given: givenOptionsOf(allArgMetas, opt)
|
|
821
|
+
});
|
|
768
822
|
const commandArgs = [];
|
|
769
823
|
if (targetMeta.targetOption.runsOnWorkspaceRoot) {
|
|
770
824
|
await assertCurrentDirectoryIsWorkspaceRoot();
|
|
@@ -781,7 +835,7 @@ ${versionWarning}`), undefined, "error");
|
|
|
781
835
|
else if (argMeta.type === "Apps")
|
|
782
836
|
commandArgs[argMeta.idx] = await getAppsArgumentValue(cmdArgs[argMeta.idx], workspace, rerun);
|
|
783
837
|
else
|
|
784
|
-
commandArgs[argMeta.idx] = await getInternalArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace, rerun);
|
|
838
|
+
commandArgs[argMeta.idx] = await getInternalArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace, rerun, { destructive: targetMeta.targetOption.destructive });
|
|
785
839
|
if (commandArgs[argMeta.idx] instanceof AppExecutor)
|
|
786
840
|
process.env.AKAN_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
|
|
787
841
|
else if (Array.isArray(commandArgs[argMeta.idx])) {
|
|
@@ -799,18 +853,17 @@ ${versionWarning}`), undefined, "error");
|
|
|
799
853
|
if (!targetMeta.targetOption.stdio)
|
|
800
854
|
Logger.rawLog();
|
|
801
855
|
} catch (e) {
|
|
802
|
-
printCliError(e);
|
|
856
|
+
printCliError(e, failure.stream);
|
|
803
857
|
throw e;
|
|
804
858
|
}
|
|
805
859
|
});
|
|
806
860
|
}
|
|
807
861
|
}
|
|
808
862
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
await reportFailure(error).catch(printCliError);
|
|
812
|
-
process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
|
|
863
|
+
program.exitOverride((error) => {
|
|
864
|
+
throw usageRefusalOf(error);
|
|
813
865
|
});
|
|
866
|
+
await program.parseAsync(process.argv).catch(failure.fail);
|
|
814
867
|
};
|
|
815
868
|
// pkgs/@akanjs/devkit/commandDecorators/commandBuilder.ts
|
|
816
869
|
var argMetaOf = (type, name, primitive, argsOption, idx) => {
|
|
@@ -888,4 +941,14 @@ function command(refName, depsOrBuilder, builder) {
|
|
|
888
941
|
}
|
|
889
942
|
return CommandBase;
|
|
890
943
|
}
|
|
891
|
-
|
|
944
|
+
// pkgs/@akanjs/devkit/commandDecorators/exitCodeError.ts
|
|
945
|
+
class ExitCodeError extends CliError {
|
|
946
|
+
name = "ExitCodeError";
|
|
947
|
+
constructor(message, exitCode) {
|
|
948
|
+
super(exitCode === 2 ? "refused" : exitCode === 3 ? "checkFailed" : "failed", message, { exitCode });
|
|
949
|
+
}
|
|
950
|
+
static codeOf(error) {
|
|
951
|
+
return CliError.exitCodeOf(error);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
export { camelToKebabCase, getTargetMetas, getTargetCommandNames, App, Apps, Lib, Sys, SysOrOnlyApp, Exec, Pkg, Module, ModuleOrService, Workspace, CommandContainer, runner, script, markCliErrorPrinted, assertPromptable, runCommands, command, ExitCodeError };
|