@cbartens/bkit 5.5.1 → 6.0.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/.bkit/README.md +30 -20
- package/.bkit/core/.agents/docs.md +1 -0
- package/.bkit/core/.agents/rules.md +35 -26
- package/.bkit/core/.bkit/README.md +29 -19
- package/.bkit/core/.bkit/authoring.md +117 -0
- package/.bkit/core/.bkit/cloud.md +11 -11
- package/.bkit/core/.bkit/comparison.md +5 -5
- package/.bkit/core/.bkit/install.md +19 -18
- package/.bkit/core/.bkit/jsonl.md +202 -122
- package/.bkit/core/.bkit/lite.md +1 -1
- package/.bkit/core/.bkit/pipeline.md +49 -52
- package/.bkit/core/.bkit/prompts.md +91 -167
- package/.bkit/core/.bkit/providers.md +29 -32
- package/.bkit/core/.bkit/templates.md +12 -11
- package/.bkit/core/.bkit/trackers.md +51 -28
- package/.bkit/core/.bkit/workflows.md +394 -355
- package/.bkit/core/AGENTS.md +16 -22
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-agents.md +19 -43
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-config.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-cost.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-database.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +15 -38
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +11 -35
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +18 -42
- package/.bkit/core/docs/templates/bkit-audit-failures.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-gates.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-issues.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-llm.md +16 -40
- package/.bkit/core/docs/templates/bkit-audit-logs.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-models.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +15 -39
- package/.bkit/core/docs/templates/bkit-audit-repo.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-security.md +13 -37
- package/.bkit/core/docs/templates/bkit-audit-slop.md +14 -38
- package/.bkit/core/docs/templates/bkit-audit-testing.md +12 -36
- package/.bkit/core/docs/templates/bkit-audit-usability.md +16 -40
- package/.bkit/core/docs/templates/bkit-plan.md +97 -226
- package/.bkit/core/engine/checks/after/ci-yml.ts +39 -29
- package/.bkit/core/engine/checks/after/github.ts +95 -17
- package/.bkit/core/engine/checks/after/index.ts +10 -7
- package/.bkit/core/engine/checks/after/suppression.ts +8 -5
- package/.bkit/core/engine/checks/after/tools.ts +46 -91
- package/.bkit/core/engine/checks/before/env.ts +2 -2
- package/.bkit/core/engine/checks/before/files.ts +5 -4
- package/.bkit/core/engine/checks/before/index.ts +18 -1
- package/.bkit/core/engine/checks/before/repo.ts +168 -2
- package/.bkit/core/engine/checks/tips/catalogue.ts +16 -5
- package/.bkit/core/engine/checks/tips/detect.ts +34 -0
- package/.bkit/core/engine/checks/tips/index.ts +6 -6
- package/.bkit/core/engine/cli.ts +20 -53
- package/.bkit/core/engine/commands/analysis.ts +171 -140
- package/.bkit/core/engine/commands/ci/ci.ts +6 -6
- package/.bkit/core/engine/commands/comply.ts +77 -103
- package/.bkit/core/engine/commands/install/doctor.ts +2 -2
- package/.bkit/core/engine/commands/install/install.ts +57 -18
- package/.bkit/core/engine/commands/install/uninstall.ts +65 -28
- package/.bkit/core/engine/commands/land.ts +18 -12
- package/.bkit/core/engine/commands/lib.ts +79 -17
- package/.bkit/core/engine/commands/registry.ts +4 -0
- package/.bkit/core/engine/commands/setup/setup.ts +7 -7
- package/.bkit/core/engine/commands/stats.ts +204 -0
- package/.bkit/core/engine/commands/tips.ts +10 -5
- package/.bkit/core/engine/commands/workflow/branches.ts +741 -62
- package/.bkit/core/engine/commands/workflow/challenge.ts +673 -0
- package/.bkit/core/engine/commands/workflow/context.ts +853 -29
- package/.bkit/core/engine/commands/workflow/counters.ts +267 -84
- package/.bkit/core/engine/commands/workflow/decisions.ts +541 -0
- package/.bkit/core/engine/commands/workflow/disk.ts +2 -2
- package/.bkit/core/engine/commands/workflow/fids.ts +793 -33
- package/.bkit/core/engine/commands/workflow/issues.ts +407 -64
- package/.bkit/core/engine/commands/workflow/ledgers.ts +884 -27
- package/.bkit/core/engine/commands/workflow/locks.ts +26 -2
- package/.bkit/core/engine/commands/workflow/plan-blocks.ts +582 -0
- package/.bkit/core/engine/commands/workflow/plan-versions.ts +21 -0
- package/.bkit/core/engine/commands/workflow/prs.ts +166 -30
- package/.bkit/core/engine/commands/workflow/repo.ts +58 -8
- package/.bkit/core/engine/commands/workflow/roadmap.ts +16 -7
- package/.bkit/core/engine/commands/workflow/run-facts.ts +501 -0
- package/.bkit/core/engine/commands/workflow/runs.ts +179 -49
- package/.bkit/core/engine/commands/workflow/runtime.ts +22 -1
- package/.bkit/core/engine/commands/workflow/status.ts +142 -29
- package/.bkit/core/engine/commands/workflow/step-table.ts +339 -0
- package/.bkit/core/engine/commands/workflow/steps.ts +213 -88
- package/.bkit/core/engine/commands/workflow/summary.ts +398 -0
- package/.bkit/core/engine/commands/workflow/tests.ts +1013 -148
- package/.bkit/core/engine/commands/workflow/tracker.ts +1195 -0
- package/.bkit/core/engine/commands/workflow/workflows.ts +984 -207
- package/.bkit/core/engine/commands/workflow/workstreams.ts +11 -5
- package/.bkit/core/engine/commands/workflow/worktrees.ts +185 -8
- package/.bkit/core/engine/install/manifest.ts +11 -9
- package/.bkit/core/engine/install/modules/cloud.ts +21 -13
- package/.bkit/core/engine/install/modules/core.ts +250 -3
- package/.bkit/core/engine/install/modules/opencode.ts +2 -2
- package/.bkit/core/engine/install/version-file.ts +6 -2
- package/.bkit/core/engine/ledgers/migrate.ts +92 -0
- package/.bkit/core/engine/ledgers/status.ts +92 -15
- package/.bkit/core/engine/ledgers/telemetry.ts +1261 -254
- package/.bkit/core/engine/render/hosts.ts +4 -0
- package/.bkit/core/engine/render/models.ts +12 -0
- package/.bkit/core/engine/shared/branches.ts +4 -1
- package/.bkit/core/engine/shared/egress.ts +7 -0
- package/.bkit/core/engine/shared/json.ts +25 -7
- package/.bkit/core/engine/shared/settings.ts +157 -20
- package/.bkit/core/engine/shared/text.ts +361 -0
- package/.bkit/core/engine/tools/grammar-density.ts +215 -0
- package/.bkit/core/engine/tools/instructions-sources.ts +834 -0
- package/.bkit/core/engine/tools/instructions.ts +1751 -0
- package/.bkit/core/hooks/gateguard-engine.js +24 -23
- package/.bkit/core/hooks/guardrails-shell.js +2 -3
- package/.bkit/core/hooks/guardrails-tiers.js +7 -1
- package/.bkit/core/hooks/readguard-engine.js +2 -2
- package/.bkit/core/prompts/bkit-audit-generate.md +62 -25
- package/.bkit/core/prompts/bkit-build-challenge-1.md +40 -17
- package/.bkit/core/prompts/bkit-build-challenge-2.md +44 -17
- package/.bkit/core/prompts/bkit-build-install-skills.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-convert.md +74 -0
- package/.bkit/core/prompts/bkit-build-plan-current.md +26 -13
- package/.bkit/core/prompts/bkit-build-plan-execute.md +74 -26
- package/.bkit/core/prompts/bkit-build-plan-gaps-remediate.md +64 -23
- package/.bkit/core/prompts/bkit-build-plan-verify.md +57 -33
- package/.bkit/core/prompts/bkit-debug-abort-handover.md +29 -15
- package/.bkit/core/prompts/bkit-debug-failure-diagnose.md +34 -14
- package/.bkit/core/prompts/bkit-debug-failure-remediate.md +34 -17
- package/.bkit/core/prompts/bkit-debug-failure-reproduce.md +26 -13
- package/.bkit/core/prompts/bkit-debug-failure-soak.md +31 -16
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-1.md +21 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-2.md +20 -11
- package/.bkit/core/prompts/bkit-design-brainstorm-ideate-3.md +20 -11
- package/.bkit/core/prompts/bkit-design-generate.md +32 -14
- package/.bkit/core/prompts/bkit-design-organise.md +25 -12
- package/.bkit/core/prompts/bkit-design-review-1.md +31 -15
- package/.bkit/core/prompts/bkit-design-review-2.md +28 -13
- package/.bkit/core/prompts/bkit-design-spike.md +30 -13
- package/.bkit/core/prompts/bkit-design-update.md +33 -19
- package/.bkit/core/prompts/bkit-plan-generate.md +72 -18
- package/.bkit/core/prompts/bkit-plan-review-1.md +50 -27
- package/.bkit/core/prompts/bkit-plan-review-2.md +59 -28
- package/.bkit/core/prompts/bkit-plan-scope-check.md +109 -0
- package/.bkit/core/prompts/bkit-plan-update.md +61 -24
- package/.bkit/core/prompts/bkit-ship-conflict-resolve.md +27 -15
- package/.bkit/core/prompts/bkit-ship-deferred-sweep.md +31 -16
- package/.bkit/core/prompts/bkit-ship-update-docs.md +29 -14
- package/.bkit/core/prompts/bkit-utility-compress-markdown.md +24 -14
- package/.bkit/core/prompts/bkit-utility-update-decisions.md +32 -14
- package/.bkit/core/prompts/bkit-utility-update-deferrals.md +29 -14
- package/.bkit/core/prompts/bkit-utility-update-documentation.md +27 -12
- package/.bkit/core/prompts/bkit-utility-update-failures.md +31 -14
- package/.bkit/core/prompts/bkit-utility-update-knowledge.md +33 -14
- package/.bkit/core/prompts/bkit-utility-update-roadmap.md +38 -17
- package/.bkit/core/prompts/bkit-utility-update-tracker.md +41 -18
- package/.bkit/core/workflows/bkit-auto.md +54 -46
- package/.bkit/core/workflows/bkit-build.md +577 -458
- package/.bkit/core/workflows/bkit-debug.md +348 -333
- package/.bkit/core/workflows/bkit-design.md +201 -237
- package/.bkit/core/workflows/bkit-plan.md +210 -321
- package/.bkit/core/workflows/bkit-ship.md +328 -278
- package/.bkit/shared/.bkit/.env.example +2 -2
- package/.bkit/shared/.claude/settings.json +11 -0
- package/.bkit/shared/.cursor/mcp.json +1 -1
- package/.bkit/shared/.cursor/rules/bkit-rules.mdc +1 -1
- package/.bkit/shared/.gitattributes +1 -1
- package/.bkit/shared/.mcp.json +1 -1
- package/.bkit/shared/.opencode/opencode.json +11 -0
- package/.bkit/shared/CLAUDE.md +2 -2
- package/.bkit/shared/GEMINI.md +2 -2
- package/.bkit/shared/docs/architecture.md +1 -1
- package/.bkit/shared/docs/data-schema.md +1 -1
- package/.bkit/shared/docs/deployments.md +11 -11
- package/.bkit/shared/docs/design.md +1 -1
- package/.bkit/shared/docs/noise.md +1 -1
- package/.bkit/shared/docs/observability.md +2 -2
- package/.bkit/shared/docs/security.md +1 -1
- package/.bkit/shared/docs/setup.md +1 -1
- package/.bkit/shared/docs/technology.md +1 -1
- package/.bkit/shared/docs/testing.md +16 -7
- package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +1 -1
- package/.bkit/templates/.github/ISSUE_TEMPLATE/bkit-change.yml +26 -5
- package/.bkit/templates/.github/workflows/bkit-ci.yml +1 -1
- package/.bkit/templates/.github/workflows/bkit-cloud.yml +21 -19
- package/.bkit/templates/.husky/pre-push +4 -4
- package/.bkit/templates/.prettierignore +7 -0
- package/.bkit/templates/scripts/cleanup/bkit-disk-prune.mjs +1 -1
- package/CHANGELOG.md +112 -0
- package/README.md +50 -35
- package/dist/checks/after/ci-yml.js +39 -28
- package/dist/checks/after/github.js +91 -17
- package/dist/checks/after/index.js +11 -8
- package/dist/checks/after/suppression.js +8 -5
- package/dist/checks/after/tools.js +39 -82
- package/dist/checks/before/env.js +2 -2
- package/dist/checks/before/files.js +5 -3
- package/dist/checks/before/index.js +15 -2
- package/dist/checks/before/repo.js +163 -2
- package/dist/checks/tips/catalogue.js +14 -5
- package/dist/checks/tips/detect.js +32 -0
- package/dist/checks/tips/index.js +4 -4
- package/dist/cli.js +19 -47
- package/dist/commands/analysis.js +109 -100
- package/dist/commands/ci/ci.js +6 -6
- package/dist/commands/comply.js +54 -91
- package/dist/commands/install/doctor.js +2 -2
- package/dist/commands/install/install.js +50 -19
- package/dist/commands/install/uninstall.js +59 -28
- package/dist/commands/land.js +16 -12
- package/dist/commands/lib.js +51 -16
- package/dist/commands/registry.js +4 -0
- package/dist/commands/setup/setup.js +7 -7
- package/dist/commands/stats.js +136 -0
- package/dist/commands/tips.js +7 -3
- package/dist/commands/workflow/branches.js +656 -56
- package/dist/commands/workflow/challenge.js +556 -0
- package/dist/commands/workflow/context.js +709 -30
- package/dist/commands/workflow/counters.js +208 -75
- package/dist/commands/workflow/decisions.js +441 -0
- package/dist/commands/workflow/disk.js +2 -2
- package/dist/commands/workflow/fids.js +689 -33
- package/dist/commands/workflow/issues.js +343 -59
- package/dist/commands/workflow/ledgers.js +762 -27
- package/dist/commands/workflow/locks.js +24 -2
- package/dist/commands/workflow/plan-blocks.js +437 -0
- package/dist/commands/workflow/plan-versions.js +22 -0
- package/dist/commands/workflow/prs.js +142 -32
- package/dist/commands/workflow/repo.js +52 -8
- package/dist/commands/workflow/roadmap.js +9 -7
- package/dist/commands/workflow/run-facts.js +426 -0
- package/dist/commands/workflow/runs.js +144 -43
- package/dist/commands/workflow/runtime.js +12 -1
- package/dist/commands/workflow/status.js +130 -29
- package/dist/commands/workflow/step-table.js +276 -0
- package/dist/commands/workflow/steps.js +171 -80
- package/dist/commands/workflow/summary.js +275 -0
- package/dist/commands/workflow/tests.js +834 -136
- package/dist/commands/workflow/tracker.js +983 -0
- package/dist/commands/workflow/workflows.js +834 -195
- package/dist/commands/workflow/workstreams.js +11 -5
- package/dist/commands/workflow/worktrees.js +147 -9
- package/dist/install/manifest.js +11 -9
- package/dist/install/modules/cloud.js +22 -13
- package/dist/install/modules/core.js +247 -3
- package/dist/install/modules/opencode.js +2 -2
- package/dist/install/version-file.js +6 -2
- package/dist/ledgers/migrate.js +81 -0
- package/dist/ledgers/status.js +61 -8
- package/dist/ledgers/telemetry.js +905 -124
- package/dist/render/hosts.js +4 -0
- package/dist/render/models.js +12 -0
- package/dist/shared/branches.js +3 -1
- package/dist/shared/egress.js +7 -0
- package/dist/shared/json.js +20 -7
- package/dist/shared/settings.js +125 -17
- package/dist/shared/text.js +333 -0
- package/dist/tools/grammar-density.js +183 -0
- package/dist/tools/instructions-sources.js +721 -0
- package/dist/tools/instructions.js +1579 -0
- package/package.json +113 -24
- package/.bkit/core/engine/commands/harvest.ts +0 -459
- package/.bkit/core/engine/tools/wording.ts +0 -748
- package/.bkit/core/prompts/bkit-build-challenge-reconcile.md +0 -69
- package/.bkit/core/prompts/bkit-build-challenge-remediate.md +0 -71
- package/.bkit/core/prompts/bkit-build-challenge-tests.md +0 -74
- package/.bkit/core/prompts/bkit-build-summary.md +0 -94
- package/.bkit/core/prompts/bkit-debug-summary.md +0 -96
- package/.bkit/core/prompts/bkit-design-summary.md +0 -107
- package/.bkit/core/prompts/bkit-plan-complexity-check.md +0 -67
- package/.bkit/core/prompts/bkit-plan-complexity-split.md +0 -88
- package/.bkit/core/prompts/bkit-plan-review-3.md +0 -93
- package/.bkit/core/prompts/bkit-plan-scope-check-1.md +0 -85
- package/.bkit/core/prompts/bkit-plan-scope-check-2.md +0 -85
- package/.bkit/core/prompts/bkit-plan-summary.md +0 -107
- package/.bkit/core/prompts/bkit-ship-summary.md +0 -78
- package/dist/commands/harvest.js +0 -353
- package/dist/tools/wording.js +0 -680
package/dist/render/hosts.js
CHANGED
|
@@ -110,6 +110,7 @@ export function applyOpencodeAgent(content, opencodeModelLookup, effortMap, prov
|
|
|
110
110
|
const description = parsed.get("description") ?? "";
|
|
111
111
|
const effort = parsed.get("effort");
|
|
112
112
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
113
|
+
// autoCompactWindow dropped: no per-agent setting, see providers.md § Context compaction.
|
|
113
114
|
let newFm = "---\n";
|
|
114
115
|
newFm += `mode: subagent\n`;
|
|
115
116
|
newFm += `name: ${name}\n`;
|
|
@@ -195,6 +196,7 @@ export function applyCodexAgent(content, codexModelLookup, effortMap) {
|
|
|
195
196
|
const { afterFm, parsed, name, model } = subagent;
|
|
196
197
|
const body = afterFm.trim();
|
|
197
198
|
const effort = parsed.get("effort");
|
|
199
|
+
// autoCompactWindow dropped: a role file's model_auto_compact_token_limit is discarded (openai/codex core/src/agent/role.rs:37-48).
|
|
198
200
|
let out = "";
|
|
199
201
|
out += tomlString("name", name);
|
|
200
202
|
out += tomlString("description", parsed.get("description") ?? "");
|
|
@@ -358,6 +360,7 @@ export function applyT3(content, modelLookup, effortMap) {
|
|
|
358
360
|
const description = parsed.get("description") ?? "";
|
|
359
361
|
const effort = parsed.get("effort");
|
|
360
362
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
363
|
+
// autoCompactWindow dropped: no per-agent setting, see providers.md § Context compaction.
|
|
361
364
|
let newFm = "---\n";
|
|
362
365
|
newFm += `name: ${name}\n`;
|
|
363
366
|
if (description.includes("\n")) {
|
|
@@ -421,6 +424,7 @@ export function applyAntigravityPrompt(content, modelLookup, effortMap) {
|
|
|
421
424
|
const description = parsed.get("description") ?? "";
|
|
422
425
|
const effort = parsed.get("effort");
|
|
423
426
|
const toolsBlock = extractFrontmatterField(fmBlock, "tools");
|
|
427
|
+
// autoCompactWindow dropped: no per-agent setting, see providers.md § Context compaction.
|
|
424
428
|
let newFm = "---\n";
|
|
425
429
|
newFm += `name: ${name}\n`;
|
|
426
430
|
if (description.includes("\n")) {
|
package/dist/render/models.js
CHANGED
|
@@ -189,6 +189,18 @@ export function applyModelOverrides(lookup, providerKey, overridesPath) {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Override rows (from `overridesPath`) naming no agent in `known`, deduplicated in file
|
|
194
|
+
* order. `applyModelOverrides` skips such rows, so they are reported, not applied.
|
|
195
|
+
*/
|
|
196
|
+
export function unknownModelOverrides(overridesPath, known) {
|
|
197
|
+
const out = [];
|
|
198
|
+
for (const o of parseModelOverrides(overridesPath)) {
|
|
199
|
+
if (!known.has(o.prompt) && !out.includes(o.prompt))
|
|
200
|
+
out.push(o.prompt);
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
192
204
|
// column → (sourceEffort → target)
|
|
193
205
|
/**
|
|
194
206
|
* Program → prompts.md effort-table column header.
|
package/dist/shared/branches.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// this one rule.
|
|
6
6
|
/** The integration branch feature work lands on. */
|
|
7
7
|
export const DEV = "dev";
|
|
8
|
+
/** The release branch: bkit never opens a PR into it or merges into it. */
|
|
9
|
+
export const MAIN = "main";
|
|
8
10
|
/** True for `dev` and `main`: no feature work happens on them, no force-push touches them. */
|
|
9
11
|
export function isSharedBranch(branch) {
|
|
10
|
-
return branch === DEV || branch ===
|
|
12
|
+
return branch === DEV || branch === MAIN;
|
|
11
13
|
}
|
package/dist/shared/egress.js
CHANGED
|
@@ -103,6 +103,13 @@ export const BKIT_EGRESS_SOURCES = [
|
|
|
103
103
|
hosts: ["api.githubcopilot.com"],
|
|
104
104
|
bases: ["githubcopilot.com"],
|
|
105
105
|
},
|
|
106
|
+
// The engine's own tracker calls (`gh api` REST and GraphQL), beside the MCP server.
|
|
107
|
+
{
|
|
108
|
+
id: "tracker-github-api",
|
|
109
|
+
kind: "tracker-mcp",
|
|
110
|
+
hosts: ["api.github.com"],
|
|
111
|
+
bases: ["github.com"],
|
|
112
|
+
},
|
|
106
113
|
{
|
|
107
114
|
id: "mcp-linear",
|
|
108
115
|
kind: "tracker-mcp",
|
package/dist/shared/json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// shared/json.ts — `JSON.parse` without the throw, for consumer-authored input.
|
|
1
|
+
// shared/json.ts — `JSON.parse` and file reads without the throw, for consumer-authored input.
|
|
2
2
|
//
|
|
3
3
|
// Every read of a file bkit does not own (package.json, .mcp.json, settings JSON,
|
|
4
4
|
// .bkit/version) must fail open into a result the caller reports in its own terms,
|
|
@@ -16,15 +16,28 @@ export function parseJson(raw) {
|
|
|
16
16
|
return { ok: false };
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
export function
|
|
21
|
-
let raw;
|
|
19
|
+
/** The file at `file` as UTF-8 text, or `{ ok: false }` when it cannot be read. */
|
|
20
|
+
export function readTextFile(file) {
|
|
22
21
|
try {
|
|
23
|
-
|
|
22
|
+
return { ok: true, text: fs.readFileSync(file, "utf-8") };
|
|
24
23
|
}
|
|
25
24
|
catch {
|
|
26
|
-
// Missing, unreadable or a directory: the result says so,
|
|
25
|
+
// Missing, unreadable or a directory: the result says so, and the caller reports it.
|
|
27
26
|
return { ok: false };
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
}
|
|
29
|
+
/** The entry names of the directory `dir`, or `{ ok: false }` when it cannot be read. */
|
|
30
|
+
export function readDirNames(dir) {
|
|
31
|
+
try {
|
|
32
|
+
return { ok: true, names: fs.readdirSync(dir) };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Missing, unreadable or not a directory: the result says so, and the caller reports it.
|
|
36
|
+
return { ok: false };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** `parseJson` over the file at `file`; `{ ok: false }` also when the file cannot be read. */
|
|
40
|
+
export function readJsonFile(file) {
|
|
41
|
+
const read = readTextFile(file);
|
|
42
|
+
return read.ok ? parseJson(read.text) : { ok: false };
|
|
30
43
|
}
|
package/dist/shared/settings.js
CHANGED
|
@@ -13,6 +13,18 @@ export function parseGithubBoardUrl(url) {
|
|
|
13
13
|
return null;
|
|
14
14
|
return { ownerType: m[1] === "orgs" ? "org" : "user", owner: m[2], number: Number(m[3]) };
|
|
15
15
|
}
|
|
16
|
+
/** Every point a workflow can stop and ask the owner at, as `<workflow>.<point>`. */
|
|
17
|
+
export const ASK_POINTS = [
|
|
18
|
+
"design.grill",
|
|
19
|
+
"build.verify",
|
|
20
|
+
"build.challenge",
|
|
21
|
+
"build.tests",
|
|
22
|
+
"debug.fix",
|
|
23
|
+
"debug.soak",
|
|
24
|
+
"ship.merge",
|
|
25
|
+
];
|
|
26
|
+
/** The limit key a point's block holds. */
|
|
27
|
+
export const limitKey = (point) => point === "design.grill" ? "maxTurns" : "maxAttempts";
|
|
16
28
|
export const CONFIG_DEFAULTS = {
|
|
17
29
|
ciWorkflow: "bkit-ci.yml",
|
|
18
30
|
capstoneJob: "bkit-tests-check",
|
|
@@ -32,6 +44,18 @@ export const CONFIG_DEFAULTS = {
|
|
|
32
44
|
opencodeProvider: null,
|
|
33
45
|
opencodeProviders: [],
|
|
34
46
|
cloudAgents: DEFAULT_CLOUD_AGENTS,
|
|
47
|
+
// `.bkit/workflows.md` § Ask points.
|
|
48
|
+
asks: {
|
|
49
|
+
"design.grill": { ask: true, max: 6 },
|
|
50
|
+
"build.verify": { ask: true, max: 2 },
|
|
51
|
+
"build.challenge": { ask: true, max: 2 },
|
|
52
|
+
"build.tests": { ask: true, max: 2 },
|
|
53
|
+
"debug.fix": { ask: true, max: 2 },
|
|
54
|
+
"debug.soak": { ask: true, max: 2 },
|
|
55
|
+
"ship.merge": { ask: true, max: 2 },
|
|
56
|
+
},
|
|
57
|
+
// Plan caps, `.bkit/workflows.md` § Test-first.
|
|
58
|
+
tasks: { maxPerGroup: 3, maxTestsPerGroup: 15, maxTestsPerTask: 10, maxTestFilesPerTask: 3 },
|
|
35
59
|
depUpdaterOptOut: false,
|
|
36
60
|
issueTrackerExplicit: false,
|
|
37
61
|
cloudAgentsExplicit: false,
|
|
@@ -46,6 +70,75 @@ function trackerStates(raw, defaults) {
|
|
|
46
70
|
review: nonEmptyString(raw.review) ? raw.review.trim() : defaults.review,
|
|
47
71
|
};
|
|
48
72
|
}
|
|
73
|
+
const TASK_CAP_KEYS = Object.keys(CONFIG_DEFAULTS.tasks);
|
|
74
|
+
const validCap = (v) => Number.isInteger(v) && v >= 1;
|
|
75
|
+
/**
|
|
76
|
+
* The keys of a `bkit.workflows.tasks` value that fall back to their default: each set key
|
|
77
|
+
* that is not an integer >= 1, or `["tasks"]` when the value is set but not an object.
|
|
78
|
+
*/
|
|
79
|
+
export function invalidTaskCaps(raw) {
|
|
80
|
+
if (raw === undefined)
|
|
81
|
+
return [];
|
|
82
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
83
|
+
return ["tasks"];
|
|
84
|
+
const set = raw;
|
|
85
|
+
return TASK_CAP_KEYS.filter((k) => set[k] !== undefined && !validCap(set[k]));
|
|
86
|
+
}
|
|
87
|
+
/** `bkit.workflows.tasks` read key by key; a missing or invalid key takes its default. */
|
|
88
|
+
function taskCaps(raw) {
|
|
89
|
+
const set = record(raw);
|
|
90
|
+
const caps = { ...CONFIG_DEFAULTS.tasks };
|
|
91
|
+
for (const k of TASK_CAP_KEYS)
|
|
92
|
+
if (validCap(set[k]))
|
|
93
|
+
caps[k] = set[k];
|
|
94
|
+
return caps;
|
|
95
|
+
}
|
|
96
|
+
/** The `bkit.workflows.<workflow>.<point>` block `workflows` holds for `point`. */
|
|
97
|
+
const askBlock = (workflows, point) => {
|
|
98
|
+
const [workflow, name] = point.split(".");
|
|
99
|
+
const block = workflows[workflow];
|
|
100
|
+
return block !== null && typeof block === "object" && !Array.isArray(block)
|
|
101
|
+
? block[name]
|
|
102
|
+
: undefined;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* The dotted keys under `bkit.workflows` that fall back to their default: each set `ask`
|
|
106
|
+
* that is not a boolean, each set limit that is not an integer >= 1, or the point itself
|
|
107
|
+
* when it is set but not an object.
|
|
108
|
+
*/
|
|
109
|
+
export function invalidAskSettings(workflows) {
|
|
110
|
+
const set = record(workflows);
|
|
111
|
+
const bad = [];
|
|
112
|
+
for (const point of ASK_POINTS) {
|
|
113
|
+
const raw = askBlock(set, point);
|
|
114
|
+
if (raw === undefined)
|
|
115
|
+
continue;
|
|
116
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
117
|
+
bad.push(point);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const block = raw;
|
|
121
|
+
if (block.ask !== undefined && typeof block.ask !== "boolean")
|
|
122
|
+
bad.push(`${point}.ask`);
|
|
123
|
+
const key = limitKey(point);
|
|
124
|
+
if (block[key] !== undefined && !validCap(block[key]))
|
|
125
|
+
bad.push(`${point}.${key}`);
|
|
126
|
+
}
|
|
127
|
+
return bad;
|
|
128
|
+
}
|
|
129
|
+
/** Every ask point read from `bkit.workflows`; a missing or invalid key takes its default. */
|
|
130
|
+
function askSettings(workflows) {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const point of ASK_POINTS) {
|
|
133
|
+
const block = record(askBlock(workflows, point));
|
|
134
|
+
const limit = block[limitKey(point)];
|
|
135
|
+
out[point] = {
|
|
136
|
+
ask: typeof block.ask === "boolean" ? block.ask : CONFIG_DEFAULTS.asks[point].ask,
|
|
137
|
+
max: validCap(limit) ? limit : CONFIG_DEFAULTS.asks[point].max,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
49
142
|
/**
|
|
50
143
|
* Read `package.json` `bkit` from `root` (the main checkout). A missing file,
|
|
51
144
|
* missing key, or wrongly typed value falls back to the default for that key.
|
|
@@ -53,21 +146,30 @@ function trackerStates(raw, defaults) {
|
|
|
53
146
|
export function readBkitConfig(root) {
|
|
54
147
|
// A missing or unparseable package.json takes every default; `bkit check` reports the file.
|
|
55
148
|
const read = readPackageJson(root);
|
|
56
|
-
const bkit = (
|
|
57
|
-
const
|
|
149
|
+
const bkit = record(read.ok ? read.pkg.bkit : undefined);
|
|
150
|
+
const tracker = record(bkit.tracker);
|
|
151
|
+
const cloud = record(bkit.cloud);
|
|
152
|
+
const opencode = record(record(bkit.providers).opencode);
|
|
153
|
+
const testing = record(bkit.testing);
|
|
154
|
+
const workflows = record(bkit.workflows);
|
|
155
|
+
const worktree = record(workflows.worktree);
|
|
58
156
|
const copy = worktree.copy;
|
|
59
|
-
const minFreeGb =
|
|
60
|
-
const lanes =
|
|
61
|
-
const book =
|
|
62
|
-
const provider =
|
|
63
|
-
const providers =
|
|
64
|
-
const github = record(
|
|
65
|
-
const linear = record(
|
|
66
|
-
const jira = record(
|
|
157
|
+
const minFreeGb = workflows.minFreeGb;
|
|
158
|
+
const lanes = testing.shipGate;
|
|
159
|
+
const book = testing.minPushPaths;
|
|
160
|
+
const provider = opencode.default;
|
|
161
|
+
const providers = opencode.installed;
|
|
162
|
+
const github = record(tracker.github);
|
|
163
|
+
const linear = record(tracker.linear);
|
|
164
|
+
const jira = record(tracker.jira);
|
|
67
165
|
const projectUrl = optionalString(github.project);
|
|
68
166
|
return {
|
|
69
|
-
ciWorkflow: nonEmptyString(
|
|
70
|
-
|
|
167
|
+
ciWorkflow: nonEmptyString(testing.ciWorkflow)
|
|
168
|
+
? testing.ciWorkflow
|
|
169
|
+
: CONFIG_DEFAULTS.ciWorkflow,
|
|
170
|
+
capstoneJob: nonEmptyString(testing.ciCapstone)
|
|
171
|
+
? testing.ciCapstone
|
|
172
|
+
: CONFIG_DEFAULTS.capstoneJob,
|
|
71
173
|
worktreeCopy: Array.isArray(copy) && copy.every(nonEmptyString)
|
|
72
174
|
? [...copy]
|
|
73
175
|
: [...CONFIG_DEFAULTS.worktreeCopy],
|
|
@@ -75,7 +177,7 @@ export function readBkitConfig(root) {
|
|
|
75
177
|
diskMinFreeGb: typeof minFreeGb === "number" && Number.isFinite(minFreeGb) && minFreeGb >= 0
|
|
76
178
|
? minFreeGb
|
|
77
179
|
: CONFIG_DEFAULTS.diskMinFreeGb,
|
|
78
|
-
issueTracker: parseIssueTracker(
|
|
180
|
+
issueTracker: parseIssueTracker(tracker.default) ?? CONFIG_DEFAULTS.issueTracker,
|
|
79
181
|
github: {
|
|
80
182
|
project: github.project === false ? false : projectUrl ? parseGithubBoardUrl(projectUrl) : null,
|
|
81
183
|
projectUrl,
|
|
@@ -100,12 +202,18 @@ export function readBkitConfig(root) {
|
|
|
100
202
|
opencodeProviders: Array.isArray(providers)
|
|
101
203
|
? providers.filter((v) => typeof v === "string" && isOpencodeProvider(v))
|
|
102
204
|
: [],
|
|
103
|
-
cloudAgents: parseCloudAgents(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
205
|
+
cloudAgents: parseCloudAgents(cloud.agent) ?? CONFIG_DEFAULTS.cloudAgents,
|
|
206
|
+
asks: askSettings(workflows),
|
|
207
|
+
tasks: taskCaps(workflows.tasks),
|
|
208
|
+
depUpdaterOptOut: record(bkit.dependencies).updater === "none",
|
|
209
|
+
issueTrackerExplicit: tracker.default !== undefined && tracker.default !== "",
|
|
210
|
+
cloudAgentsExplicit: cloud.agent !== undefined && cloud.agent !== "",
|
|
107
211
|
};
|
|
108
212
|
}
|
|
213
|
+
/** The CI workflow file `bkit.testing.ciWorkflow` names, as `.github/workflows/<file>` relative to `root`. */
|
|
214
|
+
export function ciWorkflowPath(root) {
|
|
215
|
+
return `.github/workflows/${readBkitConfig(root).ciWorkflow}`;
|
|
216
|
+
}
|
|
109
217
|
export function trackerScope(cfg) {
|
|
110
218
|
const none = { trackerTeam: null, trackerProject: null, trackerSite: null, trackerBoard: null };
|
|
111
219
|
if (cfg.issueTracker === "github")
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// shared/text.ts — engine output as plain text, and markdown tables that provably keep their data.
|
|
2
|
+
//
|
|
3
|
+
// `renderText` prints a command's output object as `key: value` lines: arrays of flat
|
|
4
|
+
// objects as markdown tables, nested values as indented `key:` blocks. `parseText` reads
|
|
5
|
+
// that text back to the value `--json` prints for the same object. Scalars keep their
|
|
6
|
+
// type: a string that would read as `null`, a boolean, a number, `[]`, `{}` or a quoted
|
|
7
|
+
// string prints inside one pair of double quotes. `markdownTable` escapes `|`,
|
|
8
|
+
// backslashes and line breaks, and prints a missing cell as `MISSING`; a literal
|
|
9
|
+
// `MISSING` value is escaped, so the two stay distinct. `checkedTable` renders an array
|
|
10
|
+
// of flat objects and parses the table back, refusing anything that would not read back
|
|
11
|
+
// as the same typed rows.
|
|
12
|
+
import { parseJson } from "./json.js";
|
|
13
|
+
/** A missing cell. A value equal to it prints escaped as `\—`. */
|
|
14
|
+
export const MISSING = "—";
|
|
15
|
+
const isScalar = (v) => v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
16
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
17
|
+
/** Escape backslashes and line breaks so a value stays on one line. */
|
|
18
|
+
const escapeLine = (s) => s.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
19
|
+
const scalarText = (v) => (v === null ? "null" : String(v));
|
|
20
|
+
const NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
21
|
+
const LITERALS = new Set(["null", "true", "false", "[]", "{}"]);
|
|
22
|
+
const quoted = (s) => s.length >= 2 && s.startsWith('"') && s.endsWith('"');
|
|
23
|
+
/** A scalar as typed text: JSON's spelling for non-strings, a string quoted when it would read as one. */
|
|
24
|
+
function scalarCode(v) {
|
|
25
|
+
if (typeof v === "number")
|
|
26
|
+
return Number.isFinite(v) ? String(v) : "null";
|
|
27
|
+
if (typeof v !== "string")
|
|
28
|
+
return scalarText(v);
|
|
29
|
+
return v === "" || LITERALS.has(v) || NUMBER.test(v) || quoted(v) ? `"${v}"` : v;
|
|
30
|
+
}
|
|
31
|
+
/** Typed text back to its scalar. */
|
|
32
|
+
function readScalar(text) {
|
|
33
|
+
if (quoted(text))
|
|
34
|
+
return text.slice(1, -1);
|
|
35
|
+
if (text === "null")
|
|
36
|
+
return null;
|
|
37
|
+
if (text === "true" || text === "false")
|
|
38
|
+
return text === "true";
|
|
39
|
+
return NUMBER.test(text) ? Number(text) : text;
|
|
40
|
+
}
|
|
41
|
+
function escapeCell(cell) {
|
|
42
|
+
if (cell === undefined)
|
|
43
|
+
return MISSING;
|
|
44
|
+
const text = escapeLine(scalarText(cell)).replace(/\|/g, "\\|");
|
|
45
|
+
return text === MISSING ? `\\${MISSING}` : text;
|
|
46
|
+
}
|
|
47
|
+
const tableLine = (cells) => `| ${cells.join(" | ")} |`;
|
|
48
|
+
/** A markdown table as lines, or nothing when there are no rows. Unpadded. */
|
|
49
|
+
export function markdownTable(head, rows) {
|
|
50
|
+
if (rows.length === 0)
|
|
51
|
+
return [];
|
|
52
|
+
return [
|
|
53
|
+
tableLine(head.map(escapeCell)),
|
|
54
|
+
tableLine(head.map(() => "---")),
|
|
55
|
+
...rows.map((r) => tableLine(head.map((_, i) => escapeCell(r[i])))),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
/** Split one table line into its raw cells; null when it is not `| … |`. */
|
|
59
|
+
function splitLine(line) {
|
|
60
|
+
if (!line.startsWith("| ") || !line.endsWith(" |"))
|
|
61
|
+
return null;
|
|
62
|
+
const body = line.slice(2, -2);
|
|
63
|
+
const cells = [];
|
|
64
|
+
let cell = "";
|
|
65
|
+
for (let i = 0; i < body.length; i++) {
|
|
66
|
+
const ch = body[i];
|
|
67
|
+
if (ch === "\\" && i + 1 < body.length) {
|
|
68
|
+
cell += ch + body[i + 1];
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
else if (ch === "|" && body[i - 1] === " " && body[i + 1] === " ") {
|
|
72
|
+
cells.push(cell.slice(0, -1));
|
|
73
|
+
cell = "";
|
|
74
|
+
i++;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
cell += ch;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
cells.push(cell);
|
|
81
|
+
return cells;
|
|
82
|
+
}
|
|
83
|
+
const UNESCAPE = {
|
|
84
|
+
n: "\n",
|
|
85
|
+
r: "\r",
|
|
86
|
+
"\\": "\\",
|
|
87
|
+
"|": "|",
|
|
88
|
+
[MISSING]: MISSING,
|
|
89
|
+
};
|
|
90
|
+
/** Undo `escapeLine` (plus `\|` and `\—` in a cell); null for a bad escape. */
|
|
91
|
+
function unescape(raw, escapes) {
|
|
92
|
+
let out = "";
|
|
93
|
+
for (let i = 0; i < raw.length; i++) {
|
|
94
|
+
const ch = raw[i];
|
|
95
|
+
if (ch !== "\\") {
|
|
96
|
+
out += ch;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const next = escapes[raw[i + 1] ?? ""];
|
|
100
|
+
if (next === undefined)
|
|
101
|
+
return null;
|
|
102
|
+
out += next;
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
/** One raw cell back to its value; undefined for a missing cell, null for a bad escape. */
|
|
108
|
+
const unescapeCell = (raw) => raw === MISSING ? undefined : unescape(raw, UNESCAPE);
|
|
109
|
+
const LINE_ESCAPES = { n: "\n", r: "\r", "\\": "\\" };
|
|
110
|
+
/** Parse a table `markdownTable` printed; null when the text is not such a table. */
|
|
111
|
+
export function parseMarkdownTable(text) {
|
|
112
|
+
const lines = text.split("\n");
|
|
113
|
+
if (lines.length < 3)
|
|
114
|
+
return null;
|
|
115
|
+
const headCells = splitLine(lines[0]);
|
|
116
|
+
if (!headCells || lines[1] !== tableLine(headCells.map(() => "---")))
|
|
117
|
+
return null;
|
|
118
|
+
const head = [];
|
|
119
|
+
for (const raw of headCells) {
|
|
120
|
+
const name = unescapeCell(raw);
|
|
121
|
+
if (typeof name !== "string")
|
|
122
|
+
return null;
|
|
123
|
+
head.push(name);
|
|
124
|
+
}
|
|
125
|
+
const rows = [];
|
|
126
|
+
for (const line of lines.slice(2)) {
|
|
127
|
+
const cells = splitLine(line);
|
|
128
|
+
if (!cells || cells.length !== head.length)
|
|
129
|
+
return null;
|
|
130
|
+
const row = {};
|
|
131
|
+
for (const [i, raw] of cells.entries()) {
|
|
132
|
+
const value = unescapeCell(raw);
|
|
133
|
+
if (value === null)
|
|
134
|
+
return null;
|
|
135
|
+
if (value !== undefined)
|
|
136
|
+
row[head[i]] = value;
|
|
137
|
+
}
|
|
138
|
+
rows.push(row);
|
|
139
|
+
}
|
|
140
|
+
return { head, rows };
|
|
141
|
+
}
|
|
142
|
+
/** A `checkedTable` table back to its typed rows; null when it is not such a table. */
|
|
143
|
+
function readTable(text) {
|
|
144
|
+
const parsed = parseMarkdownTable(text);
|
|
145
|
+
if (!parsed)
|
|
146
|
+
return null;
|
|
147
|
+
return parsed.rows.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, readScalar(v)])));
|
|
148
|
+
}
|
|
149
|
+
/** Why `value` cannot be a table, or the flat rows it holds. */
|
|
150
|
+
function flatRows(value) {
|
|
151
|
+
if (!Array.isArray(value))
|
|
152
|
+
return { reason: "not an array" };
|
|
153
|
+
if (value.length === 0)
|
|
154
|
+
return { reason: "empty array" };
|
|
155
|
+
for (const [i, item] of value.entries()) {
|
|
156
|
+
if (!isRecord(item))
|
|
157
|
+
return { reason: `item ${i} is not an object` };
|
|
158
|
+
if (Object.keys(item).length === 0)
|
|
159
|
+
return { reason: `item ${i} has no keys` };
|
|
160
|
+
for (const [key, v] of Object.entries(item)) {
|
|
161
|
+
if (!isScalar(v))
|
|
162
|
+
return { reason: `item ${i} key ${key} is nested` };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { rows: value };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* An array of flat objects as a markdown table whose typed parse equals the input rows.
|
|
169
|
+
* Columns are the union of keys in first-seen order. Anything nested, mixed or empty,
|
|
170
|
+
* or a table that would not read back as the same values of the same types, is refused.
|
|
171
|
+
*/
|
|
172
|
+
export function checkedTable(value) {
|
|
173
|
+
const flat = flatRows(value);
|
|
174
|
+
if ("reason" in flat)
|
|
175
|
+
return { ok: false, reason: flat.reason };
|
|
176
|
+
const head = [...new Set(flat.rows.flatMap((r) => Object.keys(r)))];
|
|
177
|
+
const text = markdownTable(head, flat.rows.map((r) => head.map((k) => (Object.hasOwn(r, k) ? scalarCode(r[k]) : undefined)))).join("\n");
|
|
178
|
+
const parsed = parseMarkdownTable(text);
|
|
179
|
+
const rows = readTable(text);
|
|
180
|
+
if (!parsed || !rows)
|
|
181
|
+
return { ok: false, reason: "table does not parse back" };
|
|
182
|
+
const same = parsed.head.length === head.length &&
|
|
183
|
+
parsed.head.every((h, i) => h === head[i]) &&
|
|
184
|
+
rows.length === flat.rows.length &&
|
|
185
|
+
rows.every((row, i) => {
|
|
186
|
+
const want = flat.rows[i];
|
|
187
|
+
const keys = Object.keys(row);
|
|
188
|
+
return keys.length === Object.keys(want).length && keys.every((k) => row[k] === want[k]);
|
|
189
|
+
});
|
|
190
|
+
return same ? { ok: true, text } : { ok: false, reason: "table parses back to different rows" };
|
|
191
|
+
}
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// renderText
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
/** A key as printed: JSON-quoted when it would not read back as a plain key. */
|
|
196
|
+
const keyText = (key) => key === "" || /[:\n\r\\]/.test(key) || /^[-|"\s]/.test(key) || /\s$/.test(key)
|
|
197
|
+
? JSON.stringify(key)
|
|
198
|
+
: key;
|
|
199
|
+
const scalarLine = (v) => escapeLine(scalarCode(v));
|
|
200
|
+
function valueLines(key, value, pad) {
|
|
201
|
+
const head = `${pad}${keyText(key)}:`;
|
|
202
|
+
if (isScalar(value))
|
|
203
|
+
return [`${head} ${scalarLine(value)}`];
|
|
204
|
+
if (Array.isArray(value)) {
|
|
205
|
+
if (value.length === 0)
|
|
206
|
+
return [`${head} []`];
|
|
207
|
+
const table = checkedTable(value);
|
|
208
|
+
if (table.ok)
|
|
209
|
+
return [head, ...table.text.split("\n").map((l) => pad + l)];
|
|
210
|
+
return [head, ...itemLines(value, `${pad} `)];
|
|
211
|
+
}
|
|
212
|
+
if (isRecord(value)) {
|
|
213
|
+
const inner = objectLines(value, `${pad} `);
|
|
214
|
+
return inner.length === 0 ? [`${head} {}`] : [head, ...inner];
|
|
215
|
+
}
|
|
216
|
+
return [`${head} ${String(value)}`];
|
|
217
|
+
}
|
|
218
|
+
function itemLines(items, pad) {
|
|
219
|
+
return items.flatMap((item) => {
|
|
220
|
+
if (item === undefined)
|
|
221
|
+
return [`${pad}- null`];
|
|
222
|
+
if (isScalar(item))
|
|
223
|
+
return [`${pad}- ${scalarLine(item)}`];
|
|
224
|
+
if (Array.isArray(item))
|
|
225
|
+
return item.length === 0 ? [`${pad}- []`] : [`${pad}-`, ...itemLines(item, `${pad} `)];
|
|
226
|
+
if (isRecord(item)) {
|
|
227
|
+
const inner = objectLines(item, `${pad} `);
|
|
228
|
+
return inner.length === 0 ? [`${pad}- {}`] : [`${pad}-`, ...inner];
|
|
229
|
+
}
|
|
230
|
+
return [`${pad}- ${String(item)}`];
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function objectLines(obj, pad) {
|
|
234
|
+
return Object.entries(obj)
|
|
235
|
+
.filter(([, v]) => v !== undefined)
|
|
236
|
+
.flatMap(([k, v]) => valueLines(k, v, pad));
|
|
237
|
+
}
|
|
238
|
+
/** A command's output object as text: one `key: value` line per scalar, blocks for the rest. */
|
|
239
|
+
export function renderText(payload) {
|
|
240
|
+
const lines = objectLines(payload, "");
|
|
241
|
+
return lines.length === 0 ? "" : `${lines.join("\n")}\n`;
|
|
242
|
+
}
|
|
243
|
+
/** No value: the text is not something `renderText` printed. */
|
|
244
|
+
const BAD = Symbol("bad");
|
|
245
|
+
/** The value after `key: `: an empty container or a typed scalar. */
|
|
246
|
+
function inlineValue(raw) {
|
|
247
|
+
if (raw === "[]")
|
|
248
|
+
return [];
|
|
249
|
+
if (raw === "{}")
|
|
250
|
+
return {};
|
|
251
|
+
const text = unescape(raw, LINE_ESCAPES);
|
|
252
|
+
return text === null ? BAD : readScalar(text);
|
|
253
|
+
}
|
|
254
|
+
/** `key:` / `key: value` split into the key and what follows the colon. */
|
|
255
|
+
function keyLine(line) {
|
|
256
|
+
if (line.startsWith('"')) {
|
|
257
|
+
const m = /^"(?:[^"\\]|\\.)*"/.exec(line);
|
|
258
|
+
const key = m ? parseJson(m[0]) : { ok: false };
|
|
259
|
+
if (!m || !key.ok || typeof key.value !== "string")
|
|
260
|
+
return null;
|
|
261
|
+
return { key: key.value, rest: line.slice(m[0].length) };
|
|
262
|
+
}
|
|
263
|
+
const colon = line.indexOf(":");
|
|
264
|
+
return colon <= 0 ? null : { key: line.slice(0, colon), rest: line.slice(colon) };
|
|
265
|
+
}
|
|
266
|
+
const at = (line, pad) => line !== undefined && line.startsWith(pad) && line[pad.length] !== " ";
|
|
267
|
+
/** The block under a `key:` line whose key sits at `pad`. */
|
|
268
|
+
function readBlock(cur, pad) {
|
|
269
|
+
const next = cur.lines[cur.i];
|
|
270
|
+
if (at(next, pad) && next.startsWith(`${pad}| `)) {
|
|
271
|
+
const table = [];
|
|
272
|
+
while (at(cur.lines[cur.i], pad) && cur.lines[cur.i].startsWith(`${pad}| `))
|
|
273
|
+
table.push(cur.lines[cur.i++].slice(pad.length));
|
|
274
|
+
return readTable(table.join("\n")) ?? BAD;
|
|
275
|
+
}
|
|
276
|
+
const inner = `${pad} `;
|
|
277
|
+
if (!at(next, inner))
|
|
278
|
+
return BAD;
|
|
279
|
+
return next.slice(inner.length).startsWith("-") ? readList(cur, inner) : readObject(cur, inner);
|
|
280
|
+
}
|
|
281
|
+
function readObject(cur, pad) {
|
|
282
|
+
const obj = {};
|
|
283
|
+
while (at(cur.lines[cur.i], pad) && !/^[-|]/.test(cur.lines[cur.i].slice(pad.length))) {
|
|
284
|
+
const parsed = keyLine(cur.lines[cur.i++].slice(pad.length));
|
|
285
|
+
if (!parsed)
|
|
286
|
+
return BAD;
|
|
287
|
+
let value;
|
|
288
|
+
if (parsed.rest === ":")
|
|
289
|
+
value = readBlock(cur, pad);
|
|
290
|
+
else if (parsed.rest.startsWith(": "))
|
|
291
|
+
value = inlineValue(parsed.rest.slice(2));
|
|
292
|
+
else
|
|
293
|
+
return BAD;
|
|
294
|
+
if (value === BAD)
|
|
295
|
+
return BAD;
|
|
296
|
+
obj[parsed.key] = value;
|
|
297
|
+
}
|
|
298
|
+
return obj;
|
|
299
|
+
}
|
|
300
|
+
function readList(cur, pad) {
|
|
301
|
+
const items = [];
|
|
302
|
+
while (at(cur.lines[cur.i], pad) && cur.lines[cur.i].slice(pad.length).startsWith("-")) {
|
|
303
|
+
const rest = cur.lines[cur.i++].slice(pad.length + 1);
|
|
304
|
+
let item;
|
|
305
|
+
if (rest.startsWith(" "))
|
|
306
|
+
item = inlineValue(rest.slice(1));
|
|
307
|
+
else if (rest !== "")
|
|
308
|
+
return BAD;
|
|
309
|
+
else {
|
|
310
|
+
const inner = `${pad} `;
|
|
311
|
+
const next = cur.lines[cur.i];
|
|
312
|
+
if (!at(next, inner))
|
|
313
|
+
return BAD;
|
|
314
|
+
item = next.slice(inner.length).startsWith("-")
|
|
315
|
+
? readList(cur, inner)
|
|
316
|
+
: readObject(cur, inner);
|
|
317
|
+
}
|
|
318
|
+
if (item === BAD)
|
|
319
|
+
return BAD;
|
|
320
|
+
items.push(item);
|
|
321
|
+
}
|
|
322
|
+
return items;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Text `renderText` printed, read back to the value `--json` prints for the same
|
|
326
|
+
* object; null when the text is not such output.
|
|
327
|
+
*/
|
|
328
|
+
export function parseText(text) {
|
|
329
|
+
const body = text.endsWith("\n") ? text.slice(0, -1) : text;
|
|
330
|
+
const cur = { lines: body === "" ? [] : body.split("\n"), i: 0 };
|
|
331
|
+
const obj = readObject(cur, "");
|
|
332
|
+
return obj === BAD || cur.i !== cur.lines.length ? null : obj;
|
|
333
|
+
}
|