pi-crew 0.1.30 → 0.1.32
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/CHANGELOG.md +9 -0
- package/README.md +80 -27
- package/agents/analyst.md +11 -11
- package/agents/critic.md +11 -11
- package/agents/executor.md +11 -11
- package/agents/explorer.md +11 -11
- package/agents/planner.md +11 -11
- package/agents/reviewer.md +11 -11
- package/agents/security-reviewer.md +11 -11
- package/agents/test-engineer.md +11 -11
- package/agents/verifier.md +11 -11
- package/agents/writer.md +11 -11
- package/docs/architecture.md +173 -164
- package/docs/refactor-tasks-phase3.md +394 -394
- package/docs/refactor-tasks-phase4.md +564 -564
- package/docs/refactor-tasks-phase5.md +402 -402
- package/docs/refactor-tasks-phase6.md +662 -662
- package/docs/research-extension-examples.md +297 -0
- package/docs/research-extension-system.md +324 -0
- package/docs/research-optimization-plan.md +548 -0
- package/docs/research-pi-coding-agent.md +357 -0
- package/docs/resource-formats.md +4 -3
- package/docs/runtime-flow.md +148 -148
- package/docs/source-runtime-refactor-map.md +83 -83
- package/docs/usage.md +3 -3
- package/index.ts +6 -6
- package/package.json +1 -1
- package/schema.json +53 -1
- package/skills/git-master/SKILL.md +24 -19
- package/skills/read-only-explorer/SKILL.md +26 -21
- package/skills/safe-bash/SKILL.md +21 -16
- package/skills/task-packet/SKILL.md +28 -23
- package/skills/verify-evidence/SKILL.md +27 -22
- package/src/agents/agent-serializer.ts +34 -34
- package/src/agents/discover-agents.ts +102 -102
- package/src/config/config.ts +14 -1
- package/src/config/defaults.ts +3 -2
- package/src/extension/cross-extension-rpc.ts +82 -82
- package/src/extension/import-index.ts +4 -3
- package/src/extension/management.ts +2 -2
- package/src/extension/project-init.ts +9 -7
- package/src/extension/register.ts +63 -0
- package/src/extension/registration/artifact-cleanup.ts +15 -14
- package/src/extension/registration/commands.ts +208 -208
- package/src/extension/registration/compaction-guard.ts +125 -0
- package/src/extension/registration/subagent-tools.ts +27 -8
- package/src/extension/registration/team-tool.ts +61 -44
- package/src/extension/result-watcher.ts +98 -98
- package/src/extension/run-import.ts +4 -4
- package/src/extension/run-index.ts +14 -14
- package/src/extension/run-maintenance.ts +24 -24
- package/src/extension/team-tool/api.ts +3 -0
- package/src/extension/team-tool/cancel.ts +31 -31
- package/src/extension/team-tool/doctor.ts +179 -178
- package/src/extension/team-tool/inspect.ts +41 -41
- package/src/extension/team-tool/lifecycle-actions.ts +79 -79
- package/src/extension/team-tool/plan.ts +19 -19
- package/src/extension/team-tool/status.ts +73 -73
- package/src/prompt/prompt-runtime.ts +68 -68
- package/src/runtime/agent-control.ts +64 -64
- package/src/runtime/agent-memory.ts +72 -72
- package/src/runtime/agent-observability.ts +113 -113
- package/src/runtime/async-marker.ts +26 -26
- package/src/runtime/background-runner.ts +53 -53
- package/src/runtime/crew-agent-runtime.ts +58 -58
- package/src/runtime/direct-run.ts +35 -35
- package/src/runtime/foreground-control.ts +82 -82
- package/src/runtime/green-contract.ts +46 -46
- package/src/runtime/group-join.ts +88 -88
- package/src/runtime/live-agent-control.ts +78 -78
- package/src/runtime/live-agent-manager.ts +85 -85
- package/src/runtime/live-control-realtime.ts +36 -36
- package/src/runtime/live-session-runtime.ts +299 -299
- package/src/runtime/manifest-cache.ts +212 -214
- package/src/runtime/model-fallback.ts +261 -261
- package/src/runtime/parallel-research.ts +44 -44
- package/src/runtime/parallel-utils.ts +99 -99
- package/src/runtime/pi-json-output.ts +111 -111
- package/src/runtime/pi-spawn.ts +96 -96
- package/src/runtime/policy-engine.ts +78 -78
- package/src/runtime/post-exit-stdio-guard.ts +86 -86
- package/src/runtime/process-status.ts +56 -56
- package/src/runtime/progress-event-coalescer.ts +43 -43
- package/src/runtime/recovery-recipes.ts +74 -74
- package/src/runtime/role-permission.ts +39 -39
- package/src/runtime/session-usage.ts +79 -79
- package/src/runtime/sidechain-output.ts +28 -28
- package/src/runtime/subagent-manager.ts +29 -2
- package/src/runtime/task-display.ts +38 -38
- package/src/runtime/task-output-context.ts +106 -106
- package/src/runtime/task-packet.ts +84 -84
- package/src/runtime/task-runner/live-executor.ts +98 -98
- package/src/runtime/task-runner/progress.ts +111 -111
- package/src/runtime/task-runner/prompt-builder.ts +72 -72
- package/src/runtime/task-runner/result-utils.ts +14 -14
- package/src/runtime/task-runner/state-helpers.ts +22 -22
- package/src/runtime/worker-heartbeat.ts +21 -21
- package/src/runtime/worker-startup.ts +57 -57
- package/src/schema/config-schema.ts +12 -0
- package/src/schema/team-tool-schema.ts +100 -100
- package/src/state/artifact-store.ts +108 -108
- package/src/state/contracts.ts +105 -105
- package/src/state/jsonl-writer.ts +77 -77
- package/src/state/state-store.ts +8 -9
- package/src/state/task-claims.ts +42 -42
- package/src/state/types.ts +180 -180
- package/src/state/usage.ts +29 -29
- package/src/subagents/async-entry.ts +1 -1
- package/src/subagents/index.ts +3 -3
- package/src/subagents/live/control.ts +1 -1
- package/src/subagents/live/manager.ts +1 -1
- package/src/subagents/live/realtime.ts +1 -1
- package/src/subagents/live/session-runtime.ts +1 -1
- package/src/subagents/manager.ts +1 -1
- package/src/subagents/spawn.ts +1 -1
- package/src/teams/discover-teams.ts +2 -2
- package/src/teams/team-serializer.ts +36 -36
- package/src/types/diff.d.ts +18 -0
- package/src/ui/crew-footer.ts +101 -101
- package/src/ui/crew-select-list.ts +111 -111
- package/src/ui/crew-widget.ts +285 -285
- package/src/ui/dynamic-border.ts +25 -25
- package/src/ui/layout-primitives.ts +106 -106
- package/src/ui/loaders.ts +158 -158
- package/src/ui/mascot.ts +441 -441
- package/src/ui/powerbar-publisher.ts +94 -94
- package/src/ui/render-diff.ts +119 -119
- package/src/ui/run-dashboard.ts +372 -372
- package/src/ui/status-colors.ts +54 -54
- package/src/ui/syntax-highlight.ts +116 -116
- package/src/ui/transcript-viewer.ts +302 -302
- package/src/utils/completion-dedupe.ts +63 -63
- package/src/utils/file-coalescer.ts +84 -84
- package/src/utils/frontmatter.ts +36 -36
- package/src/utils/fs-watch.ts +31 -31
- package/src/utils/git.ts +262 -262
- package/src/utils/ids.ts +12 -12
- package/src/utils/names.ts +26 -26
- package/src/utils/paths.ts +34 -7
- package/src/utils/sleep.ts +32 -32
- package/src/utils/timings.ts +31 -31
- package/src/utils/visual.ts +159 -159
- package/src/workflows/discover-workflows.ts +2 -2
- package/src/workflows/validate-workflow.ts +40 -40
- package/src/worktree/branch-freshness.ts +45 -45
- package/src/worktree/cleanup.ts +71 -69
- package/src/worktree/worktree-manager.ts +3 -1
- package/teams/default.team.md +12 -12
- package/teams/fast-fix.team.md +11 -11
- package/teams/implementation.team.md +18 -18
- package/teams/parallel-research.team.md +14 -14
- package/teams/research.team.md +11 -11
- package/teams/review.team.md +12 -12
- package/workflows/default.workflow.md +29 -29
- package/workflows/fast-fix.workflow.md +22 -22
- package/workflows/implementation.workflow.md +38 -38
- package/workflows/parallel-research.workflow.md +46 -46
- package/workflows/research.workflow.md +22 -22
- package/workflows/review.workflow.md +30 -30
package/src/ui/status-colors.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import type { CrewTheme, CrewThemeColor } from "./theme-adapter.ts";
|
|
2
|
-
|
|
3
|
-
export type RunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "stopped" | "blocked" | (string & {});
|
|
4
|
-
|
|
5
|
-
export function colorForStatus(status: RunStatus): CrewThemeColor {
|
|
6
|
-
switch (status) {
|
|
7
|
-
case "running":
|
|
8
|
-
return "accent";
|
|
9
|
-
case "completed":
|
|
10
|
-
return "success";
|
|
11
|
-
case "failed":
|
|
12
|
-
case "stale":
|
|
13
|
-
return "error";
|
|
14
|
-
case "cancelled":
|
|
15
|
-
case "blocked":
|
|
16
|
-
case "stopped":
|
|
17
|
-
return "warning";
|
|
18
|
-
case "queued":
|
|
19
|
-
default:
|
|
20
|
-
return "dim";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function iconForStatus(status: RunStatus, options?: { runningGlyph?: string }): string {
|
|
25
|
-
const glyph = options?.runningGlyph ?? "▶";
|
|
26
|
-
switch (status) {
|
|
27
|
-
case "completed":
|
|
28
|
-
return "✓";
|
|
29
|
-
case "failed":
|
|
30
|
-
case "stale":
|
|
31
|
-
return "✗";
|
|
32
|
-
case "cancelled":
|
|
33
|
-
case "stopped":
|
|
34
|
-
return "■";
|
|
35
|
-
case "running":
|
|
36
|
-
return glyph;
|
|
37
|
-
case "queued":
|
|
38
|
-
return "◦";
|
|
39
|
-
case "blocked":
|
|
40
|
-
return "⏸";
|
|
41
|
-
default:
|
|
42
|
-
return "·";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function colorForActivity(activityState: string | undefined): CrewThemeColor {
|
|
47
|
-
if (activityState === "needs_attention") return "warning";
|
|
48
|
-
if (activityState === "stale") return "error";
|
|
49
|
-
return "dim";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function applyStatusColor(theme: CrewTheme, status: RunStatus, text: string): string {
|
|
53
|
-
return theme.fg(colorForStatus(status), text);
|
|
54
|
-
}
|
|
1
|
+
import type { CrewTheme, CrewThemeColor } from "./theme-adapter.ts";
|
|
2
|
+
|
|
3
|
+
export type RunStatus = "queued" | "running" | "completed" | "failed" | "cancelled" | "stopped" | "blocked" | (string & {});
|
|
4
|
+
|
|
5
|
+
export function colorForStatus(status: RunStatus): CrewThemeColor {
|
|
6
|
+
switch (status) {
|
|
7
|
+
case "running":
|
|
8
|
+
return "accent";
|
|
9
|
+
case "completed":
|
|
10
|
+
return "success";
|
|
11
|
+
case "failed":
|
|
12
|
+
case "stale":
|
|
13
|
+
return "error";
|
|
14
|
+
case "cancelled":
|
|
15
|
+
case "blocked":
|
|
16
|
+
case "stopped":
|
|
17
|
+
return "warning";
|
|
18
|
+
case "queued":
|
|
19
|
+
default:
|
|
20
|
+
return "dim";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function iconForStatus(status: RunStatus, options?: { runningGlyph?: string }): string {
|
|
25
|
+
const glyph = options?.runningGlyph ?? "▶";
|
|
26
|
+
switch (status) {
|
|
27
|
+
case "completed":
|
|
28
|
+
return "✓";
|
|
29
|
+
case "failed":
|
|
30
|
+
case "stale":
|
|
31
|
+
return "✗";
|
|
32
|
+
case "cancelled":
|
|
33
|
+
case "stopped":
|
|
34
|
+
return "■";
|
|
35
|
+
case "running":
|
|
36
|
+
return glyph;
|
|
37
|
+
case "queued":
|
|
38
|
+
return "◦";
|
|
39
|
+
case "blocked":
|
|
40
|
+
return "⏸";
|
|
41
|
+
default:
|
|
42
|
+
return "·";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function colorForActivity(activityState: string | undefined): CrewThemeColor {
|
|
47
|
+
if (activityState === "needs_attention") return "warning";
|
|
48
|
+
if (activityState === "stale") return "error";
|
|
49
|
+
return "dim";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function applyStatusColor(theme: CrewTheme, status: RunStatus, text: string): string {
|
|
53
|
+
return theme.fg(colorForStatus(status), text);
|
|
54
|
+
}
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import { supportsLanguage, highlight } from "cli-highlight";
|
|
2
|
-
import type { CrewTheme } from "./theme-adapter.ts";
|
|
3
|
-
import { asCrewTheme } from "./theme-adapter.ts";
|
|
4
|
-
|
|
5
|
-
function buildCliTheme(theme: CrewTheme): Record<string, (text: string) => string> {
|
|
6
|
-
return {
|
|
7
|
-
keyword: (text) => theme.fg("syntaxKeyword", text),
|
|
8
|
-
built_in: (text) => theme.fg("syntaxType", text),
|
|
9
|
-
literal: (text) => theme.fg("syntaxNumber", text),
|
|
10
|
-
number: (text) => theme.fg("syntaxNumber", text),
|
|
11
|
-
string: (text) => theme.fg("syntaxString", text),
|
|
12
|
-
comment: (text) => theme.fg("syntaxComment", text),
|
|
13
|
-
function: (text) => theme.fg("syntaxFunction", text),
|
|
14
|
-
title: (text) => theme.fg("syntaxFunction", text),
|
|
15
|
-
class: (text) => theme.fg("syntaxType", text),
|
|
16
|
-
type: (text) => theme.fg("syntaxType", text),
|
|
17
|
-
attr: (text) => theme.fg("syntaxVariable", text),
|
|
18
|
-
variable: (text) => theme.fg("syntaxVariable", text),
|
|
19
|
-
params: (text) => theme.fg("syntaxVariable", text),
|
|
20
|
-
operator: (text) => theme.fg("syntaxOperator", text),
|
|
21
|
-
punctuation: (text) => theme.fg("syntaxPunctuation", text),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function detectLanguageFromPath(filePath: string): string | undefined {
|
|
26
|
-
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
27
|
-
if (!ext) return undefined;
|
|
28
|
-
return languageMap[ext];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const languageMap: Record<string, string> = {
|
|
32
|
-
ts: "typescript",
|
|
33
|
-
tsx: "typescript",
|
|
34
|
-
js: "javascript",
|
|
35
|
-
jsx: "javascript",
|
|
36
|
-
mjs: "javascript",
|
|
37
|
-
cjs: "javascript",
|
|
38
|
-
py: "python",
|
|
39
|
-
md: "markdown",
|
|
40
|
-
markdown: "markdown",
|
|
41
|
-
json: "json",
|
|
42
|
-
yml: "yaml",
|
|
43
|
-
yaml: "yaml",
|
|
44
|
-
toml: "yaml",
|
|
45
|
-
html: "html",
|
|
46
|
-
htm: "html",
|
|
47
|
-
css: "css",
|
|
48
|
-
scss: "scss",
|
|
49
|
-
sass: "sass",
|
|
50
|
-
bash: "bash",
|
|
51
|
-
sh: "bash",
|
|
52
|
-
zsh: "bash",
|
|
53
|
-
fish: "bash",
|
|
54
|
-
ps1: "powershell",
|
|
55
|
-
sql: "sql",
|
|
56
|
-
rust: "rust",
|
|
57
|
-
rb: "ruby",
|
|
58
|
-
go: "go",
|
|
59
|
-
java: "java",
|
|
60
|
-
kt: "kotlin",
|
|
61
|
-
cpp: "cpp",
|
|
62
|
-
cc: "cpp",
|
|
63
|
-
cxx: "cpp",
|
|
64
|
-
hpp: "cpp",
|
|
65
|
-
c: "c",
|
|
66
|
-
h: "c",
|
|
67
|
-
cs: "csharp",
|
|
68
|
-
php: "php",
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export function highlightCode(code: string, language: string | undefined, themeLike: unknown = undefined): string {
|
|
72
|
-
const theme = asCrewTheme(themeLike);
|
|
73
|
-
const validLanguage = language && supportsLanguage(language) ? language : undefined;
|
|
74
|
-
if (!validLanguage) {
|
|
75
|
-
return code
|
|
76
|
-
.split("\n")
|
|
77
|
-
.map((line) => theme.fg("mdCodeBlock", line))
|
|
78
|
-
.join("\n");
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
return highlight(code, {
|
|
82
|
-
language: validLanguage,
|
|
83
|
-
ignoreIllegals: true,
|
|
84
|
-
theme: buildCliTheme(theme),
|
|
85
|
-
}).trimEnd();
|
|
86
|
-
} catch {
|
|
87
|
-
return code
|
|
88
|
-
.split("\n")
|
|
89
|
-
.map((line) => theme.fg("mdCodeBlock", line))
|
|
90
|
-
.join("\n");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function highlightJson(payload: string, themeLike: unknown = undefined): string {
|
|
95
|
-
const theme = asCrewTheme(themeLike);
|
|
96
|
-
try {
|
|
97
|
-
return highlight(payload, {
|
|
98
|
-
language: "json",
|
|
99
|
-
ignoreIllegals: true,
|
|
100
|
-
theme: buildCliTheme(theme),
|
|
101
|
-
}).trimEnd();
|
|
102
|
-
} catch {
|
|
103
|
-
try {
|
|
104
|
-
const parsed = JSON.parse(payload);
|
|
105
|
-
return JSON.stringify(parsed, null, 2)
|
|
106
|
-
.split("\n")
|
|
107
|
-
.map((line) => theme.fg("mdCodeBlock", line))
|
|
108
|
-
.join("\n");
|
|
109
|
-
} catch {
|
|
110
|
-
return payload
|
|
111
|
-
.split("\n")
|
|
112
|
-
.map((line) => theme.fg("mdCodeBlock", line))
|
|
113
|
-
.join("\n");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import { supportsLanguage, highlight } from "cli-highlight";
|
|
2
|
+
import type { CrewTheme } from "./theme-adapter.ts";
|
|
3
|
+
import { asCrewTheme } from "./theme-adapter.ts";
|
|
4
|
+
|
|
5
|
+
function buildCliTheme(theme: CrewTheme): Record<string, (text: string) => string> {
|
|
6
|
+
return {
|
|
7
|
+
keyword: (text) => theme.fg("syntaxKeyword", text),
|
|
8
|
+
built_in: (text) => theme.fg("syntaxType", text),
|
|
9
|
+
literal: (text) => theme.fg("syntaxNumber", text),
|
|
10
|
+
number: (text) => theme.fg("syntaxNumber", text),
|
|
11
|
+
string: (text) => theme.fg("syntaxString", text),
|
|
12
|
+
comment: (text) => theme.fg("syntaxComment", text),
|
|
13
|
+
function: (text) => theme.fg("syntaxFunction", text),
|
|
14
|
+
title: (text) => theme.fg("syntaxFunction", text),
|
|
15
|
+
class: (text) => theme.fg("syntaxType", text),
|
|
16
|
+
type: (text) => theme.fg("syntaxType", text),
|
|
17
|
+
attr: (text) => theme.fg("syntaxVariable", text),
|
|
18
|
+
variable: (text) => theme.fg("syntaxVariable", text),
|
|
19
|
+
params: (text) => theme.fg("syntaxVariable", text),
|
|
20
|
+
operator: (text) => theme.fg("syntaxOperator", text),
|
|
21
|
+
punctuation: (text) => theme.fg("syntaxPunctuation", text),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function detectLanguageFromPath(filePath: string): string | undefined {
|
|
26
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
27
|
+
if (!ext) return undefined;
|
|
28
|
+
return languageMap[ext];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const languageMap: Record<string, string> = {
|
|
32
|
+
ts: "typescript",
|
|
33
|
+
tsx: "typescript",
|
|
34
|
+
js: "javascript",
|
|
35
|
+
jsx: "javascript",
|
|
36
|
+
mjs: "javascript",
|
|
37
|
+
cjs: "javascript",
|
|
38
|
+
py: "python",
|
|
39
|
+
md: "markdown",
|
|
40
|
+
markdown: "markdown",
|
|
41
|
+
json: "json",
|
|
42
|
+
yml: "yaml",
|
|
43
|
+
yaml: "yaml",
|
|
44
|
+
toml: "yaml",
|
|
45
|
+
html: "html",
|
|
46
|
+
htm: "html",
|
|
47
|
+
css: "css",
|
|
48
|
+
scss: "scss",
|
|
49
|
+
sass: "sass",
|
|
50
|
+
bash: "bash",
|
|
51
|
+
sh: "bash",
|
|
52
|
+
zsh: "bash",
|
|
53
|
+
fish: "bash",
|
|
54
|
+
ps1: "powershell",
|
|
55
|
+
sql: "sql",
|
|
56
|
+
rust: "rust",
|
|
57
|
+
rb: "ruby",
|
|
58
|
+
go: "go",
|
|
59
|
+
java: "java",
|
|
60
|
+
kt: "kotlin",
|
|
61
|
+
cpp: "cpp",
|
|
62
|
+
cc: "cpp",
|
|
63
|
+
cxx: "cpp",
|
|
64
|
+
hpp: "cpp",
|
|
65
|
+
c: "c",
|
|
66
|
+
h: "c",
|
|
67
|
+
cs: "csharp",
|
|
68
|
+
php: "php",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function highlightCode(code: string, language: string | undefined, themeLike: unknown = undefined): string {
|
|
72
|
+
const theme = asCrewTheme(themeLike);
|
|
73
|
+
const validLanguage = language && supportsLanguage(language) ? language : undefined;
|
|
74
|
+
if (!validLanguage) {
|
|
75
|
+
return code
|
|
76
|
+
.split("\n")
|
|
77
|
+
.map((line) => theme.fg("mdCodeBlock", line))
|
|
78
|
+
.join("\n");
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return highlight(code, {
|
|
82
|
+
language: validLanguage,
|
|
83
|
+
ignoreIllegals: true,
|
|
84
|
+
theme: buildCliTheme(theme),
|
|
85
|
+
}).trimEnd();
|
|
86
|
+
} catch {
|
|
87
|
+
return code
|
|
88
|
+
.split("\n")
|
|
89
|
+
.map((line) => theme.fg("mdCodeBlock", line))
|
|
90
|
+
.join("\n");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function highlightJson(payload: string, themeLike: unknown = undefined): string {
|
|
95
|
+
const theme = asCrewTheme(themeLike);
|
|
96
|
+
try {
|
|
97
|
+
return highlight(payload, {
|
|
98
|
+
language: "json",
|
|
99
|
+
ignoreIllegals: true,
|
|
100
|
+
theme: buildCliTheme(theme),
|
|
101
|
+
}).trimEnd();
|
|
102
|
+
} catch {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(payload);
|
|
105
|
+
return JSON.stringify(parsed, null, 2)
|
|
106
|
+
.split("\n")
|
|
107
|
+
.map((line) => theme.fg("mdCodeBlock", line))
|
|
108
|
+
.join("\n");
|
|
109
|
+
} catch {
|
|
110
|
+
return payload
|
|
111
|
+
.split("\n")
|
|
112
|
+
.map((line) => theme.fg("mdCodeBlock", line))
|
|
113
|
+
.join("\n");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|