@kindgi/cli 0.1.4 → 0.1.5-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/dist/build/defaults.d.ts +3 -1
- package/dist/build/defaults.d.ts.map +1 -1
- package/dist/build/defaults.js +44 -1
- package/dist/build/defaults.js.map +1 -1
- package/dist/build/java-image.d.ts +31 -0
- package/dist/build/java-image.d.ts.map +1 -0
- package/dist/build/java-image.js +146 -0
- package/dist/build/java-image.js.map +1 -0
- package/dist/build/pack-root.d.ts +1 -31
- package/dist/build/pack-root.d.ts.map +1 -1
- package/dist/build/pack-root.js +22 -2
- package/dist/build/pack-root.js.map +1 -1
- package/dist/build/runners.d.ts +44 -0
- package/dist/build/runners.d.ts.map +1 -1
- package/dist/build/scala-image.d.ts +21 -0
- package/dist/build/scala-image.d.ts.map +1 -0
- package/dist/build/scala-image.js +150 -0
- package/dist/build/scala-image.js.map +1 -0
- package/dist/cli-pin.d.ts +16 -0
- package/dist/cli-pin.d.ts.map +1 -0
- package/dist/cli-pin.js +66 -0
- package/dist/cli-pin.js.map +1 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +9 -8
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/approvals.d.ts.map +1 -1
- package/dist/commands/approvals.js +30 -4
- package/dist/commands/approvals.js.map +1 -1
- package/dist/commands/artifacts.d.ts.map +1 -1
- package/dist/commands/artifacts.js +100 -37
- package/dist/commands/artifacts.js.map +1 -1
- package/dist/commands/auth.js +2 -2
- package/dist/commands/blocks.d.ts.map +1 -1
- package/dist/commands/blocks.js +5 -4
- package/dist/commands/blocks.js.map +1 -1
- package/dist/commands/build.d.ts +10 -2
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +109 -16
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/capabilities.d.ts.map +1 -1
- package/dist/commands/capabilities.js +37 -10
- package/dist/commands/capabilities.js.map +1 -1
- package/dist/commands/console.d.ts +21 -0
- package/dist/commands/console.d.ts.map +1 -0
- package/dist/commands/console.js +87 -0
- package/dist/commands/console.js.map +1 -0
- package/dist/commands/conversations.d.ts.map +1 -1
- package/dist/commands/conversations.js +13 -2
- package/dist/commands/conversations.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +11 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +211 -39
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +14 -2
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +355 -19
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/env-scoped.d.ts +44 -0
- package/dist/commands/env-scoped.d.ts.map +1 -0
- package/dist/commands/env-scoped.js +222 -0
- package/dist/commands/env-scoped.js.map +1 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +85 -123
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/eval-runs.d.ts +9 -0
- package/dist/commands/eval-runs.d.ts.map +1 -1
- package/dist/commands/eval-runs.js +20 -19
- package/dist/commands/eval-runs.js.map +1 -1
- package/dist/commands/eval-suites.d.ts.map +1 -1
- package/dist/commands/eval-suites.js +16 -8
- package/dist/commands/eval-suites.js.map +1 -1
- package/dist/commands/exports.d.ts +3 -0
- package/dist/commands/exports.d.ts.map +1 -0
- package/dist/commands/exports.js +82 -0
- package/dist/commands/exports.js.map +1 -0
- package/dist/commands/feedback.d.ts.map +1 -1
- package/dist/commands/feedback.js +6 -5
- package/dist/commands/feedback.js.map +1 -1
- package/dist/commands/flows.d.ts.map +1 -1
- package/dist/commands/flows.js +2 -1
- package/dist/commands/flows.js.map +1 -1
- package/dist/commands/gate-policies.d.ts.map +1 -1
- package/dist/commands/gate-policies.js +2 -1
- package/dist/commands/gate-policies.js.map +1 -1
- package/dist/commands/guardrails.d.ts.map +1 -1
- package/dist/commands/guardrails.js +3 -2
- package/dist/commands/guardrails.js.map +1 -1
- package/dist/commands/helpers.js +5 -5
- package/dist/commands/helpers.js.map +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +14 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +254 -18
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/judge-classes.d.ts.map +1 -1
- package/dist/commands/judge-classes.js +11 -10
- package/dist/commands/judge-classes.js.map +1 -1
- package/dist/commands/judgments.d.ts.map +1 -1
- package/dist/commands/judgments.js +7 -6
- package/dist/commands/judgments.js.map +1 -1
- package/dist/commands/key.js +4 -4
- package/dist/commands/memory.d.ts.map +1 -1
- package/dist/commands/memory.js +277 -25
- package/dist/commands/memory.js.map +1 -1
- package/dist/commands/people.d.ts +3 -0
- package/dist/commands/people.d.ts.map +1 -0
- package/dist/commands/people.js +166 -0
- package/dist/commands/people.js.map +1 -0
- package/dist/commands/proposals.d.ts.map +1 -1
- package/dist/commands/proposals.js +390 -69
- package/dist/commands/proposals.js.map +1 -1
- package/dist/commands/provenance.d.ts.map +1 -1
- package/dist/commands/provenance.js +6 -7
- package/dist/commands/provenance.js.map +1 -1
- package/dist/commands/providers.d.ts.map +1 -1
- package/dist/commands/providers.js +6 -5
- package/dist/commands/providers.js.map +1 -1
- package/dist/commands/reviewers.d.ts.map +1 -1
- package/dist/commands/reviewers.js +3 -2
- package/dist/commands/reviewers.js.map +1 -1
- package/dist/commands/runs.d.ts.map +1 -1
- package/dist/commands/runs.js +24 -14
- package/dist/commands/runs.js.map +1 -1
- package/dist/commands/schedules.d.ts +3 -0
- package/dist/commands/schedules.d.ts.map +1 -0
- package/dist/commands/schedules.js +275 -0
- package/dist/commands/schedules.js.map +1 -0
- package/dist/commands/secrets.d.ts.map +1 -1
- package/dist/commands/secrets.js +10 -11
- package/dist/commands/secrets.js.map +1 -1
- package/dist/commands/service-accounts.d.ts +3 -0
- package/dist/commands/service-accounts.d.ts.map +1 -0
- package/dist/commands/service-accounts.js +175 -0
- package/dist/commands/service-accounts.js.map +1 -0
- package/dist/commands/skills.d.ts +1 -1
- package/dist/commands/skills.d.ts.map +1 -1
- package/dist/commands/skills.js +11 -4
- package/dist/commands/skills.js.map +1 -1
- package/dist/commands/sso.d.ts +6 -0
- package/dist/commands/sso.d.ts.map +1 -0
- package/dist/commands/sso.js +318 -0
- package/dist/commands/sso.js.map +1 -0
- package/dist/commands/tokens.d.ts +11 -0
- package/dist/commands/tokens.d.ts.map +1 -1
- package/dist/commands/tokens.js +144 -11
- package/dist/commands/tokens.js.map +1 -1
- package/dist/commands/tools.d.ts.map +1 -1
- package/dist/commands/tools.js +4 -3
- package/dist/commands/tools.js.map +1 -1
- package/dist/commands/unwired.d.ts.map +1 -1
- package/dist/commands/unwired.js +1 -30
- package/dist/commands/unwired.js.map +1 -1
- package/dist/commands/upgrade.d.ts +11 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +160 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/context.d.ts +7 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -1
- package/dist/dev/defaults.d.ts +28 -11
- package/dist/dev/defaults.d.ts.map +1 -1
- package/dist/dev/defaults.js +114 -35
- package/dist/dev/defaults.js.map +1 -1
- package/dist/dev/google-credentials.d.ts +50 -0
- package/dist/dev/google-credentials.d.ts.map +1 -0
- package/dist/dev/google-credentials.js +157 -0
- package/dist/dev/google-credentials.js.map +1 -0
- package/dist/dev/java-builder.d.ts +56 -0
- package/dist/dev/java-builder.d.ts.map +1 -0
- package/dist/dev/java-builder.js +204 -0
- package/dist/dev/java-builder.js.map +1 -0
- package/dist/dev/jvm-run-files.d.ts +29 -0
- package/dist/dev/jvm-run-files.d.ts.map +1 -0
- package/dist/dev/jvm-run-files.js +94 -0
- package/dist/dev/jvm-run-files.js.map +1 -0
- package/dist/dev/lines.d.ts +13 -0
- package/dist/dev/lines.d.ts.map +1 -0
- package/dist/dev/lines.js +24 -0
- package/dist/dev/lines.js.map +1 -0
- package/dist/dev/log-view.d.ts +116 -0
- package/dist/dev/log-view.d.ts.map +1 -0
- package/dist/dev/log-view.js +233 -0
- package/dist/dev/log-view.js.map +1 -0
- package/dist/dev/pack-code.d.ts +79 -4
- package/dist/dev/pack-code.d.ts.map +1 -1
- package/dist/dev/pack-code.js +262 -3
- package/dist/dev/pack-code.js.map +1 -1
- package/dist/dev/pack-env.d.ts.map +1 -1
- package/dist/dev/pack-env.js +4 -0
- package/dist/dev/pack-env.js.map +1 -1
- package/dist/dev/pack-service.d.ts +11 -1
- package/dist/dev/pack-service.d.ts.map +1 -1
- package/dist/dev/pack-service.js +56 -20
- package/dist/dev/pack-service.js.map +1 -1
- package/dist/dev/paths.d.ts +6 -0
- package/dist/dev/paths.d.ts.map +1 -1
- package/dist/dev/paths.js +8 -0
- package/dist/dev/paths.js.map +1 -1
- package/dist/dev/project-database.js +1 -1
- package/dist/dev/project-database.js.map +1 -1
- package/dist/dev/runners.d.ts +35 -9
- package/dist/dev/runners.d.ts.map +1 -1
- package/dist/dev/runtime-container.d.ts +10 -2
- package/dist/dev/runtime-container.d.ts.map +1 -1
- package/dist/dev/runtime-container.js +48 -20
- package/dist/dev/runtime-container.js.map +1 -1
- package/dist/dev/runtime-env.d.ts +10 -0
- package/dist/dev/runtime-env.d.ts.map +1 -1
- package/dist/dev/runtime-env.js +8 -4
- package/dist/dev/runtime-env.js.map +1 -1
- package/dist/dev/runtime-image.d.ts +1 -1
- package/dist/dev/runtime-image.d.ts.map +1 -1
- package/dist/dev/runtime-image.js +1 -1
- package/dist/dev/runtime-image.js.map +1 -1
- package/dist/dev/scala-builder.d.ts +72 -0
- package/dist/dev/scala-builder.d.ts.map +1 -0
- package/dist/dev/scala-builder.js +347 -0
- package/dist/dev/scala-builder.js.map +1 -0
- package/dist/env/project-env.d.ts.map +1 -1
- package/dist/env/project-env.js +3 -1
- package/dist/env/project-env.js.map +1 -1
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/init/dependency-specs.d.ts +26 -0
- package/dist/init/dependency-specs.d.ts.map +1 -1
- package/dist/init/dependency-specs.js +38 -0
- package/dist/init/dependency-specs.js.map +1 -1
- package/dist/init/java-augment.d.ts +24 -0
- package/dist/init/java-augment.d.ts.map +1 -0
- package/dist/init/java-augment.js +198 -0
- package/dist/init/java-augment.js.map +1 -0
- package/dist/init/mode-detect.d.ts +2 -2
- package/dist/init/mode-detect.d.ts.map +1 -1
- package/dist/init/mode-detect.js +12 -1
- package/dist/init/mode-detect.js.map +1 -1
- package/dist/init/scala-augment.d.ts +23 -0
- package/dist/init/scala-augment.d.ts.map +1 -0
- package/dist/init/scala-augment.js +213 -0
- package/dist/init/scala-augment.js.map +1 -0
- package/dist/init/template-files.d.ts +40 -2
- package/dist/init/template-files.d.ts.map +1 -1
- package/dist/init/template-files.js +56 -5
- package/dist/init/template-files.js.map +1 -1
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -2
- package/dist/main.js.map +1 -1
- package/dist/open-url.d.ts +15 -0
- package/dist/open-url.d.ts.map +1 -0
- package/dist/open-url.js +41 -0
- package/dist/open-url.js.map +1 -0
- package/dist/package-manager.d.ts +10 -3
- package/dist/package-manager.d.ts.map +1 -1
- package/dist/package-manager.js +19 -1
- package/dist/package-manager.js.map +1 -1
- package/dist/providers/presets/anthropic.json +11 -3
- package/dist/sdk-skills/kindgi-authoring-agents/SKILL.md +26 -2
- package/dist/sdk-skills/kindgi-authoring-flows/SKILL.md +1 -1
- package/dist/sdk-skills/kindgi-authoring-guardrails/SKILL.md +47 -3
- package/dist/sdk-skills/kindgi-authoring-mcp-servers/SKILL.md +7 -5
- package/dist/sdk-skills/kindgi-authoring-providers/SKILL.md +40 -15
- package/dist/sdk-skills/kindgi-authoring-tools/SKILL.md +27 -1
- package/dist/sdk-skills/kindgi-framework-feedback/SKILL.md +5 -4
- package/dist/sdk-skills/kindgi-getting-started/SKILL.md +1 -1
- package/dist/sdk-skills/kindgi-java-authoring-agents/SKILL.md +220 -0
- package/dist/sdk-skills/kindgi-java-authoring-flows/SKILL.md +390 -0
- package/dist/sdk-skills/kindgi-java-authoring-guardrails/SKILL.md +209 -0
- package/dist/sdk-skills/kindgi-java-authoring-tools/SKILL.md +334 -0
- package/dist/sdk-skills/kindgi-java-getting-started/SKILL.md +270 -0
- package/dist/sdk-skills/kindgi-python-authoring-agents/SKILL.md +21 -3
- package/dist/sdk-skills/kindgi-python-authoring-flows/SKILL.md +1 -1
- package/dist/sdk-skills/kindgi-python-authoring-guardrails/SKILL.md +10 -3
- package/dist/sdk-skills/kindgi-python-authoring-tools/SKILL.md +36 -5
- package/dist/sdk-skills/kindgi-python-getting-started/SKILL.md +2 -2
- package/dist/sdk-skills/kindgi-scala-authoring-agents/SKILL.md +217 -0
- package/dist/sdk-skills/kindgi-scala-authoring-flows/SKILL.md +357 -0
- package/dist/sdk-skills/kindgi-scala-authoring-guardrails/SKILL.md +199 -0
- package/dist/sdk-skills/kindgi-scala-authoring-tools/SKILL.md +302 -0
- package/dist/sdk-skills/kindgi-scala-getting-started/SKILL.md +302 -0
- package/dist/templates/java/.mvn/wrapper/maven-wrapper.properties +3 -0
- package/dist/templates/java/AGENTS.md +31 -0
- package/dist/templates/java/README.md.tmpl +69 -0
- package/dist/templates/java/gitignore +9 -0
- package/dist/templates/java/kindgi.config.json.tmpl +8 -0
- package/dist/templates/java/kindgiw +33 -0
- package/dist/templates/java/kindgiw.cmd +28 -0
- package/dist/templates/java/mvnw +295 -0
- package/dist/templates/java/pom.xml.tmpl +65 -0
- package/dist/templates/java/src/main/java/__PACKAGE__/agents/EchoAgent.java.tmpl +27 -0
- package/dist/templates/java/src/main/java/__PACKAGE__/flows/EchoFlow.java.tmpl +18 -0
- package/dist/templates/java/src/main/java/__PACKAGE__/guardrails/ResponseNotEmpty.java.tmpl +28 -0
- package/dist/templates/java/src/main/java/__PACKAGE__/tools/Echo.java.tmpl +22 -0
- package/dist/templates/java/src/main/java/__PACKAGE__/tools/Greet.java.tmpl +23 -0
- package/dist/templates/java/src/test/java/__PACKAGE__/ToolsTest.java.tmpl +30 -0
- package/dist/templates/minimal/README.md.tmpl +6 -12
- package/dist/templates/python/README.md.tmpl +4 -4
- package/dist/templates/sample/README.md.tmpl +5 -11
- package/dist/templates/scala/AGENTS.md +32 -0
- package/dist/templates/scala/README.md.tmpl +75 -0
- package/dist/templates/scala/build.sbt.tmpl +16 -0
- package/dist/templates/scala/gitignore +13 -0
- package/dist/templates/scala/kindgi.config.json.tmpl +8 -0
- package/dist/templates/scala/project/build.properties +1 -0
- package/dist/templates/scala/src/main/scala/__PACKAGE__/agents/EchoAgent.scala.tmpl +23 -0
- package/dist/templates/scala/src/main/scala/__PACKAGE__/flows/EchoFlow.scala.tmpl +16 -0
- package/dist/templates/scala/src/main/scala/__PACKAGE__/guardrails/ResponseNotEmpty.scala.tmpl +21 -0
- package/dist/templates/scala/src/main/scala/__PACKAGE__/tools/Echo.scala.tmpl +16 -0
- package/dist/templates/scala/src/main/scala/__PACKAGE__/tools/Greet.scala.tmpl +17 -0
- package/dist/templates/scala/src/test/scala/__PACKAGE__/ToolsSuite.scala.tmpl +23 -0
- package/package.json +13 -12
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
/**
|
|
4
|
+
* How `kindgi dev` shows logs. The runtime container and the pack service
|
|
5
|
+
* write `@kindgi/log` records as JSON; `kindgi dev` reads them and prints
|
|
6
|
+
* them for a person, each tagged with where it came from:
|
|
7
|
+
*
|
|
8
|
+
* [runtime] 14:02:11.123 INFO [http] GET /v1/runs 200 12ms requestId=…
|
|
9
|
+
* [pack] 14:02:11.130 INFO [pack] tool acme.lookup ok 12ms runId=…
|
|
10
|
+
*
|
|
11
|
+
* Levels are set where the records are written (`KINDGI_LOG_LEVEL` and
|
|
12
|
+
* `KINDGI_LOG_LEVELS` for the runtime, the pack service and the indexer),
|
|
13
|
+
* and checked again here for a source that ignores them.
|
|
14
|
+
* `--log-format=json` writes the records as they came, one per line on
|
|
15
|
+
* stdout, for `| jq`; everything else stays on stderr. `--quiet` keeps
|
|
16
|
+
* errors only. A line that isn't a record (pack code's own output, an
|
|
17
|
+
* older runtime's) is shown as it is.
|
|
18
|
+
*/
|
|
19
|
+
import { LOG_LEVELS, SEVERITY, formatPretty, levelEnabled, levelFor, parseLogLevel, parseLogLevels, } from '@kindgi/log';
|
|
20
|
+
/** Before the flags are read: everything shown, plain. */
|
|
21
|
+
export const DEFAULT_DEV_LOG_VIEW = {
|
|
22
|
+
level: 'info',
|
|
23
|
+
levels: {},
|
|
24
|
+
format: 'pretty',
|
|
25
|
+
color: false,
|
|
26
|
+
quiet: false,
|
|
27
|
+
};
|
|
28
|
+
/** The log flags from the command line, or what's wrong with one. */
|
|
29
|
+
export function parseDevLogFlags(options) {
|
|
30
|
+
let level;
|
|
31
|
+
if (typeof options.level === 'string') {
|
|
32
|
+
level = parseLogLevel(options.level);
|
|
33
|
+
if (level === undefined) {
|
|
34
|
+
return {
|
|
35
|
+
kind: 'error',
|
|
36
|
+
message: `--log-level must be one of ${LOG_LEVELS.join(', ')}, got "${options.level}".`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const levels = {};
|
|
41
|
+
const entries = typeof options.log === 'string' ? [options.log] : Array.isArray(options.log) ? options.log : [];
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const parsed = parseLogLevels(entry);
|
|
44
|
+
if (parsed.kind === 'err')
|
|
45
|
+
return { kind: 'error', message: `--log: ${parsed.message}.` };
|
|
46
|
+
Object.assign(levels, parsed.levels);
|
|
47
|
+
}
|
|
48
|
+
const format = typeof options.format === 'string' ? options.format.trim().toLowerCase() : 'pretty';
|
|
49
|
+
if (format !== 'pretty' && format !== 'json') {
|
|
50
|
+
return {
|
|
51
|
+
kind: 'error',
|
|
52
|
+
message: `--log-format must be pretty or json, got "${String(options.format)}".`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
kind: 'ok',
|
|
57
|
+
value: { ...(level !== undefined && { level }), levels, format, quiet: options.quiet },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The session's view: the flags first, then `KINDGI_LOG_LEVEL` and
|
|
62
|
+
* `KINDGI_LOG_LEVELS` (the shell's, then the env files'), then `info`.
|
|
63
|
+
* `--quiet` is `error` unless `--log-level` says otherwise.
|
|
64
|
+
*/
|
|
65
|
+
export function resolveDevLogView(flags, input) {
|
|
66
|
+
const setting = (name) => {
|
|
67
|
+
const value = input.env[name] ?? input.files[name];
|
|
68
|
+
return value === undefined || value.trim() === '' ? undefined : value;
|
|
69
|
+
};
|
|
70
|
+
let level = flags.level;
|
|
71
|
+
let levels = {};
|
|
72
|
+
if (flags.quiet) {
|
|
73
|
+
level ??= 'error';
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const rawLevel = setting('KINDGI_LOG_LEVEL');
|
|
77
|
+
if (level === undefined && rawLevel !== undefined) {
|
|
78
|
+
level = parseLogLevel(rawLevel);
|
|
79
|
+
if (level === undefined) {
|
|
80
|
+
return {
|
|
81
|
+
kind: 'error',
|
|
82
|
+
message: `KINDGI_LOG_LEVEL must be one of ${LOG_LEVELS.join(', ')}, got "${rawLevel}".`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const rawLevels = setting('KINDGI_LOG_LEVELS');
|
|
87
|
+
if (rawLevels !== undefined) {
|
|
88
|
+
const parsed = parseLogLevels(rawLevels);
|
|
89
|
+
if (parsed.kind === 'err') {
|
|
90
|
+
return { kind: 'error', message: `KINDGI_LOG_LEVELS: ${parsed.message}.` };
|
|
91
|
+
}
|
|
92
|
+
levels = parsed.levels;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const color = flags.format === 'pretty' && input.isTTY && (input.env.NO_COLOR ?? '') === '';
|
|
96
|
+
return {
|
|
97
|
+
kind: 'ok',
|
|
98
|
+
value: {
|
|
99
|
+
level: level ?? 'info',
|
|
100
|
+
levels: { ...levels, ...flags.levels },
|
|
101
|
+
format: flags.format,
|
|
102
|
+
color,
|
|
103
|
+
quiet: flags.quiet,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** The levels a source gets, so it writes only what's shown. */
|
|
108
|
+
export function sourceLogLevels(view) {
|
|
109
|
+
const levels = Object.entries(view.levels)
|
|
110
|
+
.map(([subsystem, level]) => `${subsystem}=${level}`)
|
|
111
|
+
.join(',');
|
|
112
|
+
return {
|
|
113
|
+
KINDGI_LOG_LEVEL: view.level,
|
|
114
|
+
...(levels !== '' && { KINDGI_LOG_LEVELS: levels }),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The levels the runtime gets: the view's, with its `boot` record kept
|
|
119
|
+
* (`boot` at info at least). In JSON the runtime writes its banner as that
|
|
120
|
+
* record, and `kindgi dev` waits for it to know the runtime serves, so a
|
|
121
|
+
* higher level (`--quiet`, `--log-level=warn`) would leave it waiting.
|
|
122
|
+
* Whether the banner is shown is still the view's.
|
|
123
|
+
*/
|
|
124
|
+
export function runtimeLogLevels(view) {
|
|
125
|
+
return shows(view, 'info', 'boot')
|
|
126
|
+
? sourceLogLevels(view)
|
|
127
|
+
: sourceLogLevels({ ...view, levels: { ...view.levels, boot: 'info' } });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The settings a source `kindgi dev` reads gets: the levels shown, as
|
|
131
|
+
* records (the pack service and the indexer; the runtime container adds
|
|
132
|
+
* the format itself, since a runtime you run writes to your terminal).
|
|
133
|
+
*/
|
|
134
|
+
export function sourceLogEnv(view) {
|
|
135
|
+
return { KINDGI_LOG_FORMAT: 'json', ...sourceLogLevels(view) };
|
|
136
|
+
}
|
|
137
|
+
/** A line as a record, when it is one (the five fixed fields, a known level). */
|
|
138
|
+
export function parseRecord(line) {
|
|
139
|
+
if (!line.startsWith('{'))
|
|
140
|
+
return undefined;
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = JSON.parse(line);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
149
|
+
return undefined;
|
|
150
|
+
const r = parsed;
|
|
151
|
+
return typeof r.time === 'string' &&
|
|
152
|
+
typeof r.level === 'string' &&
|
|
153
|
+
LOG_LEVELS.includes(r.level) &&
|
|
154
|
+
typeof r.subsystem === 'string' &&
|
|
155
|
+
typeof r.message === 'string'
|
|
156
|
+
? r
|
|
157
|
+
: undefined;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The runtime's banner, when the record carries it: in JSON the runtime
|
|
161
|
+
* writes its boot lines as one `boot` record with them as `lines`.
|
|
162
|
+
*/
|
|
163
|
+
function bootLines(record) {
|
|
164
|
+
const lines = record.lines;
|
|
165
|
+
return record.subsystem === 'boot' &&
|
|
166
|
+
Array.isArray(lines) &&
|
|
167
|
+
lines.every((l) => typeof l === 'string')
|
|
168
|
+
? lines
|
|
169
|
+
: undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A line as text a person reads, for checks on what a source said and
|
|
173
|
+
* for a failure's last lines: a record pretty (the banner as its lines),
|
|
174
|
+
* anything else as it is.
|
|
175
|
+
*/
|
|
176
|
+
export function textLines(line) {
|
|
177
|
+
const record = parseRecord(line);
|
|
178
|
+
if (record === undefined)
|
|
179
|
+
return [line];
|
|
180
|
+
return bootLines(record) ?? formatPretty(record).split('\n');
|
|
181
|
+
}
|
|
182
|
+
/** Whether the view shows a record at `level` from `subsystem`. */
|
|
183
|
+
export function shows(view, level, subsystem) {
|
|
184
|
+
return levelEnabled(level, levelFor(subsystem, view.levels, view.level));
|
|
185
|
+
}
|
|
186
|
+
/** A record, as `kindgi dev` shows it: `undefined` when its level is filtered out. */
|
|
187
|
+
export function showRecord(source, record, raw, view) {
|
|
188
|
+
if (!shows(view, record.level, record.subsystem))
|
|
189
|
+
return undefined;
|
|
190
|
+
if (view.format === 'json')
|
|
191
|
+
return { stream: 'stdout', lines: [raw] };
|
|
192
|
+
const text = bootLines(record) ?? formatPretty(record, { color: view.color }).split('\n');
|
|
193
|
+
return { stream: 'stderr', lines: text.map((l) => `[${source}] ${l}`) };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A line that isn't a record, as `kindgi dev` shows it: tagged, on
|
|
197
|
+
* stderr. `--quiet` keeps only what a source wrote on stderr.
|
|
198
|
+
*/
|
|
199
|
+
export function showText(source, line, view, stream) {
|
|
200
|
+
if (view.quiet && stream !== 'stderr')
|
|
201
|
+
return undefined;
|
|
202
|
+
return { stream: 'stderr', lines: [`[${source}] ${line}`] };
|
|
203
|
+
}
|
|
204
|
+
/** A line a source wrote, as `kindgi dev` shows it, or `undefined` to leave it out. */
|
|
205
|
+
export function showLine(source, line, view, stream = 'stdout') {
|
|
206
|
+
const record = parseRecord(line);
|
|
207
|
+
return record === undefined
|
|
208
|
+
? showText(source, line, view, stream)
|
|
209
|
+
: showRecord(source, record, line, view);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* What pack code printed while the indexer loaded it: shown at `debug`
|
|
213
|
+
* (subsystem `pack.index`), where it used to be dropped. A record it
|
|
214
|
+
* wrote is shown as any record.
|
|
215
|
+
*/
|
|
216
|
+
export function showIndexerLine(line, view, now = () => new Date()) {
|
|
217
|
+
const record = parseRecord(line);
|
|
218
|
+
if (record !== undefined)
|
|
219
|
+
return showRecord('pack', record, line, view);
|
|
220
|
+
if (!shows(view, 'debug', 'pack.index'))
|
|
221
|
+
return undefined;
|
|
222
|
+
if (view.format === 'json')
|
|
223
|
+
return { stream: 'stderr', lines: [`[pack] ${line}`] };
|
|
224
|
+
const shown = {
|
|
225
|
+
time: now().toISOString(),
|
|
226
|
+
level: 'debug',
|
|
227
|
+
severity: SEVERITY.debug,
|
|
228
|
+
subsystem: 'pack.index',
|
|
229
|
+
message: line,
|
|
230
|
+
};
|
|
231
|
+
return { stream: 'stderr', lines: [`[pack] ${formatPretty(shown, { color: view.color })}`] };
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=log-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-view.js","sourceRoot":"","sources":["../../src/dev/log-view.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,UAAU,EAGV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAkCrB,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC9C,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;CACb,CAAC;AAMF,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,OAKhC;IACC,IAAI,KAA2B,CAAC;IAChC,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACtC,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,8BAA8B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UA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AE,QAAQ,CAAC,KAAK;QACxB,SAAS,EAAE,YAAY;QACvB,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,UAAU,YAAY,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/F,CAAC"}
|
package/dist/dev/pack-code.d.ts
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
import type { PackLanguage } from '@kindgi/handler-runtime';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The pack's code: its language, and how to run it — for Python the
|
|
4
|
+
* interpreter (an argv prefix), for Java the JDK and the build.
|
|
5
|
+
*/
|
|
3
6
|
export type PackCode = {
|
|
4
7
|
readonly language: 'node';
|
|
5
8
|
} | {
|
|
6
9
|
readonly language: 'python';
|
|
7
10
|
readonly python: readonly [string, ...string[]];
|
|
8
|
-
};
|
|
11
|
+
} | JvmPackCode;
|
|
12
|
+
/** A JVM pack's code: Java's (built by Maven) or Scala's (built by sbt). */
|
|
13
|
+
export type JvmPackCode = JavaPackCode | ScalaPackCode;
|
|
14
|
+
/** Whether the pack's code runs on the JVM: kindgi-pack indexes and serves it. */
|
|
15
|
+
export declare function isJvmPackCode(code: PackCode | undefined): code is JvmPackCode;
|
|
16
|
+
/** What every JVM pack's code has: the JDK that runs it, and where its build's files go. */
|
|
17
|
+
interface JvmRuntime {
|
|
18
|
+
/** The JDK's `java`: `<javaHome>/bin/java`, or `java` on `PATH`. */
|
|
19
|
+
readonly java: string;
|
|
20
|
+
/** The JDK's home, passed on as `JAVA_HOME` (the build tool's and the launcher's JDK); absent: `java` on `PATH`. */
|
|
21
|
+
readonly javaHome?: string;
|
|
22
|
+
/** Where the build's files go (`devJvmDir`): the classpath `@argfile`, the launcher. */
|
|
23
|
+
readonly workDir: string;
|
|
24
|
+
}
|
|
25
|
+
/** A Scala pack's code: the JDK that runs it, the sbt that builds it, where the build's files go. */
|
|
26
|
+
export interface ScalaPackCode extends JvmRuntime {
|
|
27
|
+
readonly language: 'scala';
|
|
28
|
+
/** sbt, as an argv prefix: `dev.sbt`, else `sbt` on `PATH`. Builds go through its server (`--client`). */
|
|
29
|
+
readonly sbt: readonly [string, ...string[]];
|
|
30
|
+
/** `SBT_OPTS` from the host, for sbt only (a machine's own proxy or memory settings). */
|
|
31
|
+
readonly sbtEnv?: Readonly<Record<string, string>>;
|
|
32
|
+
}
|
|
33
|
+
/** A Java pack's code: the JDK that runs it, the Maven that builds it, where the build's files go. */
|
|
34
|
+
export interface JavaPackCode extends JvmRuntime {
|
|
35
|
+
readonly language: 'java';
|
|
36
|
+
/** Maven, as an argv prefix: `dev.maven`, else the pack's wrapper (`sh mvnw`), else `mvn`. */
|
|
37
|
+
readonly maven: readonly [string, ...string[]];
|
|
38
|
+
/**
|
|
39
|
+
* `MAVEN_ARGS` and `MAVEN_OPTS` from the host, for Maven only (a machine's
|
|
40
|
+
* own `-s settings.xml`, a proxy): never in the pack's environment.
|
|
41
|
+
*/
|
|
42
|
+
readonly mavenEnv?: Readonly<Record<string, string>>;
|
|
43
|
+
}
|
|
44
|
+
/** The `@argfile` passing a JVM pack's classpath to `java` (written by its builder). */
|
|
45
|
+
export declare function javaArgsFile(code: JvmPackCode): string;
|
|
46
|
+
/** The launcher (`kindgi-pack-java`) extracted from the pack's kindgi-pack jar. */
|
|
47
|
+
export declare function javaLauncher(code: JvmPackCode): string;
|
|
48
|
+
/** The environment a JVM pack's children run with: the pack's, plus its JDK as `JAVA_HOME`. */
|
|
49
|
+
export declare function javaEnv(code: JvmPackCode, env: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
|
|
9
50
|
export declare const NODE_PACK_CODE: PackCode;
|
|
10
51
|
type Outcome<T> = {
|
|
11
52
|
readonly kind: 'ok';
|
|
@@ -23,8 +64,31 @@ type Outcome<T> = {
|
|
|
23
64
|
* 3. `python3` on `PATH`.
|
|
24
65
|
*/
|
|
25
66
|
export declare function resolvePackPython(packDir: string, config: Readonly<Record<string, unknown>> | undefined): Promise<Outcome<readonly [string, ...string[]]>>;
|
|
26
|
-
/**
|
|
27
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The JDK and the Maven that run and build a Java pack:
|
|
69
|
+
*
|
|
70
|
+
* - the JDK: `dev.javaHome` in the config, else `JAVA_HOME`, else `java`
|
|
71
|
+
* on `PATH`;
|
|
72
|
+
* - Maven: `dev.maven` (an argv, such as `["mvn", "-s", "settings.xml"]`),
|
|
73
|
+
* else the pack's wrapper (`mvnw`, run with `sh`), else `mvn` on `PATH`.
|
|
74
|
+
*
|
|
75
|
+
* A Java pack's service starts through a POSIX shell script (the launcher
|
|
76
|
+
* keeps its token out of the JVM's environment): on Windows, `kindgi dev`
|
|
77
|
+
* runs it under WSL.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolvePackJava(packDir: string, config: Readonly<Record<string, unknown>> | undefined, hostEnv: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform): Promise<Outcome<JavaPackCode>>;
|
|
80
|
+
/**
|
|
81
|
+
* The JDK and the sbt that run and build a Scala pack:
|
|
82
|
+
*
|
|
83
|
+
* - the JDK, as for a Java pack: `dev.javaHome`, else `JAVA_HOME`, else
|
|
84
|
+
* `java` on `PATH`;
|
|
85
|
+
* - sbt: `dev.sbt` (an argv, such as `["sbt", "-Dsbt.override.build.repos=true"]`),
|
|
86
|
+
* else `sbt` on `PATH`. Builds go through its server (`sbt --client`),
|
|
87
|
+
* so a save compiles without starting a JVM.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolvePackScala(packDir: string, config: Readonly<Record<string, unknown>> | undefined, hostEnv: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform): Promise<Outcome<ScalaPackCode>>;
|
|
90
|
+
/** The pack code for a language, with the interpreter or the JDK resolved. */
|
|
91
|
+
export declare function resolvePackCode(language: PackLanguage, packDir: string, config: Readonly<Record<string, unknown>> | undefined, hostEnv?: Readonly<Record<string, string | undefined>>): Promise<Outcome<PackCode>>;
|
|
28
92
|
/**
|
|
29
93
|
* Check the pack's Python can run pack code (`import kindgi.pack`), with the
|
|
30
94
|
* pack's environment and from the pack's directory — so a missing
|
|
@@ -32,5 +96,16 @@ export declare function resolvePackCode(language: PackLanguage, packDir: string,
|
|
|
32
96
|
* failure.
|
|
33
97
|
*/
|
|
34
98
|
export declare function checkPackPython(python: readonly [string, ...string[]], env: Readonly<Record<string, string>>, packDir?: string): Promise<Outcome<string>>;
|
|
99
|
+
/** The oldest JDK a JVM pack runs on (kindgi-pack's baseline). */
|
|
100
|
+
export declare const MIN_JAVA_MAJOR = 17;
|
|
101
|
+
/**
|
|
102
|
+
* Check a JVM pack's JDK (17 or later) and its build tool (Maven or sbt)
|
|
103
|
+
* start, with the pack's environment — so a missing JDK or build tool is one
|
|
104
|
+
* clear line at boot instead of a build failure. Whether the pack has
|
|
105
|
+
* kindgi-pack shows at its first build.
|
|
106
|
+
*/
|
|
107
|
+
export declare function checkPackJvm(code: JvmPackCode, env: Readonly<Record<string, string>>, packDir?: string): Promise<Outcome<string>>;
|
|
108
|
+
/** `17.0.6` → 17; `1.8.0_392` → 8. */
|
|
109
|
+
export declare function javaMajor(version: string): number | undefined;
|
|
35
110
|
export {};
|
|
36
111
|
//# sourceMappingURL=pack-code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack-code.d.ts","sourceRoot":"","sources":["../../src/dev/pack-code.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pack-code.d.ts","sourceRoot":"","sources":["../../src/dev/pack-code.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,QAAQ,E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8
8
|
* Node pack service (`@kindgi/handler-runtime`).
|
|
9
9
|
* - python: no bundling, `python -m kindgi.pack index` and
|
|
10
10
|
* `python -m kindgi.pack serve` with the pack's own interpreter.
|
|
11
|
+
* - java: Maven compiles the pack (`java-builder.ts`), then
|
|
12
|
+
* `com.kindgi.pack.Main index` and `… serve` (through the
|
|
13
|
+
* launcher, `kindgi-pack-java`) with the pack's JDK.
|
|
14
|
+
* - scala: sbt compiles the pack through its server (`scala-builder.ts`),
|
|
15
|
+
* then the same as Java: kindgi-pack indexes and serves it.
|
|
11
16
|
*
|
|
12
|
-
*
|
|
17
|
+
* All run under the pack's environment (`devPackEnv`) and behind the same
|
|
13
18
|
* supervisor and front, so the api-server never knows which it is.
|
|
14
19
|
*/
|
|
15
20
|
import { spawn } from 'node:child_process';
|
|
16
21
|
import { access, stat } from 'node:fs/promises';
|
|
17
22
|
import { join } from 'node:path';
|
|
23
|
+
import { devJvmDir } from './paths.js';
|
|
24
|
+
/** Whether the pack's code runs on the JVM: kindgi-pack indexes and serves it. */
|
|
25
|
+
export function isJvmPackCode(code) {
|
|
26
|
+
return code?.language === 'java' || code?.language === 'scala';
|
|
27
|
+
}
|
|
28
|
+
/** The `@argfile` passing a JVM pack's classpath to `java` (written by its builder). */
|
|
29
|
+
export function javaArgsFile(code) {
|
|
30
|
+
return join(code.workDir, 'java.args');
|
|
31
|
+
}
|
|
32
|
+
/** The launcher (`kindgi-pack-java`) extracted from the pack's kindgi-pack jar. */
|
|
33
|
+
export function javaLauncher(code) {
|
|
34
|
+
return join(code.workDir, 'kindgi-pack-java');
|
|
35
|
+
}
|
|
36
|
+
/** The environment a JVM pack's children run with: the pack's, plus its JDK as `JAVA_HOME`. */
|
|
37
|
+
export function javaEnv(code, env) {
|
|
38
|
+
return code.javaHome === undefined ? env : { ...env, JAVA_HOME: code.javaHome };
|
|
39
|
+
}
|
|
18
40
|
export const NODE_PACK_CODE = { language: 'node' };
|
|
19
41
|
/**
|
|
20
42
|
* The interpreter that runs a Python pack:
|
|
@@ -53,10 +75,144 @@ export async function resolvePackPython(packDir, config) {
|
|
|
53
75
|
}
|
|
54
76
|
return { kind: 'ok', value: ['python3'] };
|
|
55
77
|
}
|
|
56
|
-
/**
|
|
57
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The JDK and the Maven that run and build a Java pack:
|
|
80
|
+
*
|
|
81
|
+
* - the JDK: `dev.javaHome` in the config, else `JAVA_HOME`, else `java`
|
|
82
|
+
* on `PATH`;
|
|
83
|
+
* - Maven: `dev.maven` (an argv, such as `["mvn", "-s", "settings.xml"]`),
|
|
84
|
+
* else the pack's wrapper (`mvnw`, run with `sh`), else `mvn` on `PATH`.
|
|
85
|
+
*
|
|
86
|
+
* A Java pack's service starts through a POSIX shell script (the launcher
|
|
87
|
+
* keeps its token out of the JVM's environment): on Windows, `kindgi dev`
|
|
88
|
+
* runs it under WSL.
|
|
89
|
+
*/
|
|
90
|
+
export async function resolvePackJava(packDir, config, hostEnv, platform = process.platform) {
|
|
91
|
+
const runtime = resolveJvmRuntime('java', packDir, config, hostEnv, platform);
|
|
92
|
+
if (runtime.kind === 'err')
|
|
93
|
+
return runtime;
|
|
94
|
+
const configuredMaven = devSettings(config).maven;
|
|
95
|
+
let maven;
|
|
96
|
+
if (configuredMaven !== undefined) {
|
|
97
|
+
const argv = commandArgv(configuredMaven);
|
|
98
|
+
if (argv === undefined) {
|
|
99
|
+
return {
|
|
100
|
+
kind: 'err',
|
|
101
|
+
message: '`dev.maven` must be a command or a non-empty command list (e.g. ["mvn", "-s", "settings.xml"]).',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
maven = argv;
|
|
105
|
+
}
|
|
106
|
+
else if (await isFile(join(packDir, 'mvnw'))) {
|
|
107
|
+
maven = ['sh', join(packDir, 'mvnw')];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
maven = ['mvn'];
|
|
111
|
+
}
|
|
112
|
+
const mavenEnv = {};
|
|
113
|
+
for (const name of ['MAVEN_ARGS', 'MAVEN_OPTS']) {
|
|
114
|
+
const value = hostEnv[name];
|
|
115
|
+
if (value !== undefined && value !== '')
|
|
116
|
+
mavenEnv[name] = value;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
kind: 'ok',
|
|
120
|
+
value: {
|
|
121
|
+
language: 'java',
|
|
122
|
+
...runtime.value,
|
|
123
|
+
maven,
|
|
124
|
+
...(Object.keys(mavenEnv).length > 0 && { mavenEnv }),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The JDK and the sbt that run and build a Scala pack:
|
|
130
|
+
*
|
|
131
|
+
* - the JDK, as for a Java pack: `dev.javaHome`, else `JAVA_HOME`, else
|
|
132
|
+
* `java` on `PATH`;
|
|
133
|
+
* - sbt: `dev.sbt` (an argv, such as `["sbt", "-Dsbt.override.build.repos=true"]`),
|
|
134
|
+
* else `sbt` on `PATH`. Builds go through its server (`sbt --client`),
|
|
135
|
+
* so a save compiles without starting a JVM.
|
|
136
|
+
*/
|
|
137
|
+
export async function resolvePackScala(packDir, config, hostEnv, platform = process.platform) {
|
|
138
|
+
const runtime = resolveJvmRuntime('scala', packDir, config, hostEnv, platform);
|
|
139
|
+
if (runtime.kind === 'err')
|
|
140
|
+
return runtime;
|
|
141
|
+
const configuredSbt = devSettings(config).sbt;
|
|
142
|
+
let sbt = ['sbt'];
|
|
143
|
+
if (configuredSbt !== undefined) {
|
|
144
|
+
const argv = commandArgv(configuredSbt);
|
|
145
|
+
if (argv === undefined) {
|
|
146
|
+
return {
|
|
147
|
+
kind: 'err',
|
|
148
|
+
message: '`dev.sbt` must be a command or a non-empty command list (e.g. ["sbt", "-mem", "2048"]).',
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
sbt = argv;
|
|
152
|
+
}
|
|
153
|
+
const sbtOpts = hostEnv.SBT_OPTS;
|
|
154
|
+
return {
|
|
155
|
+
kind: 'ok',
|
|
156
|
+
value: {
|
|
157
|
+
language: 'scala',
|
|
158
|
+
...runtime.value,
|
|
159
|
+
sbt,
|
|
160
|
+
...(sbtOpts !== undefined && sbtOpts !== '' && { sbtEnv: { SBT_OPTS: sbtOpts } }),
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** A config's `dev` table, or an empty one. */
|
|
165
|
+
function devSettings(config) {
|
|
166
|
+
const dev = config?.dev;
|
|
167
|
+
return dev !== null && typeof dev === 'object' ? dev : {};
|
|
168
|
+
}
|
|
169
|
+
/** A configured command (a string, or a non-empty list of non-empty strings) as an argv; undefined when it's neither. */
|
|
170
|
+
function commandArgv(configured) {
|
|
171
|
+
const argv = typeof configured === 'string' ? [configured] : configured;
|
|
172
|
+
return Array.isArray(argv) &&
|
|
173
|
+
argv.length > 0 &&
|
|
174
|
+
argv.every((part) => typeof part === 'string' && part !== '')
|
|
175
|
+
? argv
|
|
176
|
+
: undefined;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The JDK every JVM pack runs on: `dev.javaHome`, else `JAVA_HOME`, else
|
|
180
|
+
* `java` on `PATH`. A JVM pack's service starts through a POSIX shell script
|
|
181
|
+
* (the launcher keeps its token out of the JVM's environment): on Windows,
|
|
182
|
+
* `kindgi dev` runs it under WSL.
|
|
183
|
+
*/
|
|
184
|
+
function resolveJvmRuntime(language, packDir, config, hostEnv, platform) {
|
|
185
|
+
const name = language === 'java' ? 'Java' : 'Scala';
|
|
186
|
+
if (platform === 'win32') {
|
|
187
|
+
return {
|
|
188
|
+
kind: 'err',
|
|
189
|
+
message: `a ${name} pack's service starts through a POSIX shell script (kindgi-pack-java), so on Windows run kindgi dev under WSL.`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const configuredHome = devSettings(config).javaHome;
|
|
193
|
+
if (configuredHome !== undefined &&
|
|
194
|
+
(typeof configuredHome !== 'string' || configuredHome === '')) {
|
|
195
|
+
return { kind: 'err', message: '`dev.javaHome` must be the path of a JDK (17 or later).' };
|
|
196
|
+
}
|
|
197
|
+
const javaHome = configuredHome ??
|
|
198
|
+
(hostEnv.JAVA_HOME !== undefined && hostEnv.JAVA_HOME !== '' ? hostEnv.JAVA_HOME : undefined);
|
|
199
|
+
return {
|
|
200
|
+
kind: 'ok',
|
|
201
|
+
value: {
|
|
202
|
+
java: javaHome === undefined ? 'java' : join(javaHome, 'bin', 'java'),
|
|
203
|
+
...(javaHome !== undefined && { javaHome }),
|
|
204
|
+
workDir: devJvmDir(packDir, language),
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** The pack code for a language, with the interpreter or the JDK resolved. */
|
|
209
|
+
export async function resolvePackCode(language, packDir, config, hostEnv = process.env) {
|
|
58
210
|
if (language === 'node')
|
|
59
211
|
return { kind: 'ok', value: NODE_PACK_CODE };
|
|
212
|
+
if (language === 'java')
|
|
213
|
+
return resolvePackJava(packDir, config, hostEnv);
|
|
214
|
+
if (language === 'scala')
|
|
215
|
+
return resolvePackScala(packDir, config, hostEnv);
|
|
60
216
|
const python = await resolvePackPython(packDir, config);
|
|
61
217
|
if (python.kind === 'err')
|
|
62
218
|
return python;
|
|
@@ -118,6 +274,109 @@ export async function checkPackPython(python, env, packDir) {
|
|
|
118
274
|
value: `Python ${pythonVersion ?? '?'} · kindgi ${kindgiVersion ?? '?'} (${shown})`,
|
|
119
275
|
};
|
|
120
276
|
}
|
|
277
|
+
/** The oldest JDK a JVM pack runs on (kindgi-pack's baseline). */
|
|
278
|
+
export const MIN_JAVA_MAJOR = 17;
|
|
279
|
+
/**
|
|
280
|
+
* Check a JVM pack's JDK (17 or later) and its build tool (Maven or sbt)
|
|
281
|
+
* start, with the pack's environment — so a missing JDK or build tool is one
|
|
282
|
+
* clear line at boot instead of a build failure. Whether the pack has
|
|
283
|
+
* kindgi-pack shows at its first build.
|
|
284
|
+
*/
|
|
285
|
+
export async function checkPackJvm(code, env, packDir) {
|
|
286
|
+
const childEnv = javaEnv(code, env);
|
|
287
|
+
const jdk = await checkJdk(code, childEnv, packDir);
|
|
288
|
+
if (jdk.kind === 'err')
|
|
289
|
+
return jdk;
|
|
290
|
+
const tool = code.language === 'scala'
|
|
291
|
+
? await checkTool(code.sbt, ['--script-version'], { ...childEnv, ...code.sbtEnv }, packDir, {
|
|
292
|
+
name: 'sbt',
|
|
293
|
+
version: /(\d+\.\d+\.\d+\S*)/,
|
|
294
|
+
setting: 'dev.sbt',
|
|
295
|
+
install: 'Install sbt 1.10 or later (https://www.scala-sbt.org/download),',
|
|
296
|
+
})
|
|
297
|
+
: await checkTool(code.maven, ['--version'], { ...childEnv, ...code.mavenEnv }, packDir, {
|
|
298
|
+
name: 'Maven',
|
|
299
|
+
version: /Apache Maven (\S+)/,
|
|
300
|
+
setting: 'dev.maven',
|
|
301
|
+
install: 'Add the Maven wrapper to the pack (mvn wrapper:wrapper), install Maven 3.9 or later,',
|
|
302
|
+
});
|
|
303
|
+
if (tool.kind === 'err')
|
|
304
|
+
return tool;
|
|
305
|
+
return {
|
|
306
|
+
kind: 'ok',
|
|
307
|
+
value: `Java ${jdk.value} · ${tool.value} (${code.javaHome ?? code.java}; ${(code.language === 'scala' ? code.sbt : code.maven).join(' ')})`,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** The pack's JDK starts and is 17 or later: its version. */
|
|
311
|
+
async function checkJdk(code, env, packDir) {
|
|
312
|
+
const java = await run(code.java, ['-version'], env, packDir);
|
|
313
|
+
if (java.spawnError !== undefined) {
|
|
314
|
+
return {
|
|
315
|
+
kind: 'err',
|
|
316
|
+
message: [
|
|
317
|
+
`the pack's JDK (${code.java}) did not start: ${java.spawnError}`,
|
|
318
|
+
` Install a JDK ${MIN_JAVA_MAJOR} or later (e.g. Eclipse Temurin), and set JAVA_HOME to it,`,
|
|
319
|
+
' or point `dev.javaHome` in kindgi.config.json at one.',
|
|
320
|
+
].join('\n'),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
const version = /version "([^"]+)"/.exec(`${java.stderr}\n${java.stdout}`)?.[1];
|
|
324
|
+
const major = version === undefined ? undefined : javaMajor(version);
|
|
325
|
+
if (version === undefined || major === undefined || major < MIN_JAVA_MAJOR) {
|
|
326
|
+
return {
|
|
327
|
+
kind: 'err',
|
|
328
|
+
message: [
|
|
329
|
+
`the pack's JDK (${code.java}) is ${version ?? 'of an unknown version'}; a ${code.language === 'java' ? 'Java' : 'Scala'} pack needs ${MIN_JAVA_MAJOR} or later.`,
|
|
330
|
+
' Set JAVA_HOME to a newer JDK, or point `dev.javaHome` in kindgi.config.json at one.',
|
|
331
|
+
].join('\n'),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return { kind: 'ok', value: version };
|
|
335
|
+
}
|
|
336
|
+
/** The pack's build tool runs: its name and version (`Maven 3.9.9`, `sbt 1.12.15`). */
|
|
337
|
+
async function checkTool(argv, versionArgs, env, packDir, about) {
|
|
338
|
+
const [program, ...prefix] = argv;
|
|
339
|
+
const result = await run(program, [...prefix, ...versionArgs], env, packDir);
|
|
340
|
+
if (result.spawnError !== undefined || result.code !== 0) {
|
|
341
|
+
const detail = result.spawnError ?? (result.stderr.trim() || result.stdout.trim()).split('\n').pop();
|
|
342
|
+
return {
|
|
343
|
+
kind: 'err',
|
|
344
|
+
message: [
|
|
345
|
+
`the pack's ${about.name} (${argv.join(' ')}) did not run: ${detail ?? ''}`,
|
|
346
|
+
` ${about.install}`,
|
|
347
|
+
` or point \`${about.setting}\` in kindgi.config.json at one.`,
|
|
348
|
+
].join('\n'),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return { kind: 'ok', value: `${about.name} ${about.version.exec(result.stdout)?.[1] ?? '?'}` };
|
|
352
|
+
}
|
|
353
|
+
/** `17.0.6` → 17; `1.8.0_392` → 8. */
|
|
354
|
+
export function javaMajor(version) {
|
|
355
|
+
const parts = version.split(/[.+_-]/);
|
|
356
|
+
const first = Number(parts[0]);
|
|
357
|
+
if (!Number.isInteger(first))
|
|
358
|
+
return undefined;
|
|
359
|
+
return first === 1 ? Number(parts[1]) : first;
|
|
360
|
+
}
|
|
361
|
+
function run(program, args, env, cwd) {
|
|
362
|
+
return new Promise((resolve) => {
|
|
363
|
+
const child = spawn(program, [...args], {
|
|
364
|
+
env,
|
|
365
|
+
...(cwd !== undefined && { cwd }),
|
|
366
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
367
|
+
});
|
|
368
|
+
let out = '';
|
|
369
|
+
let err = '';
|
|
370
|
+
child.stdout.on('data', (chunk) => {
|
|
371
|
+
out += chunk.toString('utf8');
|
|
372
|
+
});
|
|
373
|
+
child.stderr.on('data', (chunk) => {
|
|
374
|
+
err += chunk.toString('utf8');
|
|
375
|
+
});
|
|
376
|
+
child.once('error', (cause) => resolve({ code: null, stdout: out, stderr: err, spawnError: cause.message }));
|
|
377
|
+
child.once('close', (exit) => resolve({ code: exit, stdout: out, stderr: err }));
|
|
378
|
+
});
|
|
379
|
+
}
|
|
121
380
|
async function isFile(path) {
|
|
122
381
|
try {
|
|
123
382
|
return (await stat(path)).isFile();
|