poe-code 3.0.143 → 3.0.145
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/dist/cli/commands/pipeline.js +15 -1
- package/dist/cli/commands/pipeline.js.map +1 -1
- package/dist/cli/commands/spawn.js +3 -3
- package/dist/cli/commands/spawn.js.map +1 -1
- package/dist/index.js +3650 -316
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code.js +27 -33
- package/dist/providers/claude-code.js.map +4 -4
- package/dist/providers/codex.js +27 -33
- package/dist/providers/codex.js.map +4 -4
- package/dist/providers/kimi.js +27 -33
- package/dist/providers/kimi.js.map +4 -4
- package/dist/providers/opencode.js +27 -33
- package/dist/providers/opencode.js.map +4 -4
- package/dist/workflow-templates/fix-vulnerabilities.caller.yml +18 -0
- package/dist/workflow-templates/fix-vulnerabilities.ejected.yml +36 -0
- package/dist/workflow-templates/github-issue-comment-created.caller.yml +25 -0
- package/dist/workflow-templates/github-issue-comment-created.ejected.yml +155 -0
- package/dist/workflow-templates/github-issue-opened.caller.yml +20 -0
- package/dist/workflow-templates/github-issue-opened.ejected.yml +42 -0
- package/dist/workflow-templates/github-pull-request-opened.caller.yml +19 -0
- package/dist/workflow-templates/github-pull-request-opened.ejected.yml +37 -0
- package/dist/workflow-templates/github-pull-request-synchronized.caller.yml +17 -0
- package/dist/workflow-templates/github-pull-request-synchronized.ejected.yml +35 -0
- package/dist/workflow-templates/update-dependencies.caller.yml +17 -0
- package/dist/workflow-templates/update-dependencies.ejected.yml +35 -0
- package/dist/workflow-templates/update-documentation.caller.yml +17 -0
- package/dist/workflow-templates/update-documentation.ejected.yml +36 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3337,9 +3337,16 @@ var init_colors = __esm({
|
|
|
3337
3337
|
});
|
|
3338
3338
|
|
|
3339
3339
|
// packages/design-system/src/tokens/spacing.ts
|
|
3340
|
+
var spacing;
|
|
3340
3341
|
var init_spacing = __esm({
|
|
3341
3342
|
"packages/design-system/src/tokens/spacing.ts"() {
|
|
3342
3343
|
"use strict";
|
|
3344
|
+
spacing = {
|
|
3345
|
+
sm: 1,
|
|
3346
|
+
md: 2,
|
|
3347
|
+
lg: 4,
|
|
3348
|
+
xl: 8
|
|
3349
|
+
};
|
|
3343
3350
|
}
|
|
3344
3351
|
});
|
|
3345
3352
|
|
|
@@ -3436,7 +3443,7 @@ function detectThemeFromEnv(env) {
|
|
|
3436
3443
|
return void 0;
|
|
3437
3444
|
}
|
|
3438
3445
|
function resolveThemeName(env = process.env) {
|
|
3439
|
-
const raw = env.POE_CODE_THEME?.toLowerCase();
|
|
3446
|
+
const raw = (env.POE_CODE_THEME ?? env.POE_THEME)?.toLowerCase();
|
|
3440
3447
|
if (raw === "light" || raw === "dark") {
|
|
3441
3448
|
return raw;
|
|
3442
3449
|
}
|
|
@@ -3834,131 +3841,3428 @@ function formatCommand(name, description) {
|
|
|
3834
3841
|
const paddedName = name.padEnd(widths.helpColumn);
|
|
3835
3842
|
return ` ${text.command(paddedName)} ${description}`;
|
|
3836
3843
|
}
|
|
3837
|
-
function formatOption(flags, description) {
|
|
3838
|
-
const paddedFlags = flags.padEnd(widths.helpColumn);
|
|
3839
|
-
return ` ${text.option(paddedFlags)} ${description}`;
|
|
3844
|
+
function formatOption(flags, description) {
|
|
3845
|
+
const paddedFlags = flags.padEnd(widths.helpColumn);
|
|
3846
|
+
return ` ${text.option(paddedFlags)} ${description}`;
|
|
3847
|
+
}
|
|
3848
|
+
function formatCommandList(commands) {
|
|
3849
|
+
return commands.map((cmd) => formatCommand(cmd.name, cmd.description)).join("\n");
|
|
3850
|
+
}
|
|
3851
|
+
function formatOptionList(options) {
|
|
3852
|
+
return options.map((opt) => formatOption(opt.flags, opt.description)).join("\n");
|
|
3853
|
+
}
|
|
3854
|
+
var init_help_formatter = __esm({
|
|
3855
|
+
"packages/design-system/src/components/help-formatter.ts"() {
|
|
3856
|
+
"use strict";
|
|
3857
|
+
init_text();
|
|
3858
|
+
init_widths();
|
|
3859
|
+
}
|
|
3860
|
+
});
|
|
3861
|
+
|
|
3862
|
+
// packages/design-system/src/components/command-errors.ts
|
|
3863
|
+
function formatCommandNotFound(input) {
|
|
3864
|
+
const unknown = input.unknownCommand.length > 0 ? input.unknownCommand : "<command>";
|
|
3865
|
+
return {
|
|
3866
|
+
label: `${typography.bold("Unknown command:")} ${text.command(unknown)}`,
|
|
3867
|
+
hint: `${text.muted("Run")} ${text.usageCommand(input.helpCommand)} ${text.muted("for available commands.")}`
|
|
3868
|
+
};
|
|
3869
|
+
}
|
|
3870
|
+
function formatCommandNotFoundPanel(input) {
|
|
3871
|
+
const message2 = formatCommandNotFound({
|
|
3872
|
+
unknownCommand: input.unknownCommand,
|
|
3873
|
+
helpCommand: input.helpCommand
|
|
3874
|
+
});
|
|
3875
|
+
return {
|
|
3876
|
+
title: input.title ?? "command not found",
|
|
3877
|
+
label: message2.label,
|
|
3878
|
+
footer: message2.hint
|
|
3879
|
+
};
|
|
3880
|
+
}
|
|
3881
|
+
var init_command_errors = __esm({
|
|
3882
|
+
"packages/design-system/src/components/command-errors.ts"() {
|
|
3883
|
+
"use strict";
|
|
3884
|
+
init_typography();
|
|
3885
|
+
init_text();
|
|
3886
|
+
}
|
|
3887
|
+
});
|
|
3888
|
+
|
|
3889
|
+
// packages/design-system/src/components/table.ts
|
|
3890
|
+
import { Table } from "console-table-printer";
|
|
3891
|
+
function renderTableTerminal(options) {
|
|
3892
|
+
const { theme, columns, rows } = options;
|
|
3893
|
+
const table = new Table({
|
|
3894
|
+
style: {
|
|
3895
|
+
headerTop: {
|
|
3896
|
+
left: theme.muted("\u250C"),
|
|
3897
|
+
mid: theme.muted("\u252C"),
|
|
3898
|
+
right: theme.muted("\u2510"),
|
|
3899
|
+
other: theme.muted("\u2500")
|
|
3900
|
+
},
|
|
3901
|
+
headerBottom: {
|
|
3902
|
+
left: theme.muted("\u251C"),
|
|
3903
|
+
mid: theme.muted("\u253C"),
|
|
3904
|
+
right: theme.muted("\u2524"),
|
|
3905
|
+
other: theme.muted("\u2500")
|
|
3906
|
+
},
|
|
3907
|
+
tableBottom: {
|
|
3908
|
+
left: theme.muted("\u2514"),
|
|
3909
|
+
mid: theme.muted("\u2534"),
|
|
3910
|
+
right: theme.muted("\u2518"),
|
|
3911
|
+
other: theme.muted("\u2500")
|
|
3912
|
+
},
|
|
3913
|
+
vertical: theme.muted("\u2502"),
|
|
3914
|
+
rowSeparator: {
|
|
3915
|
+
left: theme.muted("\u251C"),
|
|
3916
|
+
mid: theme.muted("\u253C"),
|
|
3917
|
+
right: theme.muted("\u2524"),
|
|
3918
|
+
other: theme.muted("\u2500")
|
|
3919
|
+
}
|
|
3920
|
+
},
|
|
3921
|
+
columns: columns.map((col) => ({
|
|
3922
|
+
name: col.name,
|
|
3923
|
+
title: theme.header(col.title),
|
|
3924
|
+
alignment: col.alignment,
|
|
3925
|
+
maxLen: col.maxLen
|
|
3926
|
+
}))
|
|
3927
|
+
});
|
|
3928
|
+
for (const row of rows) {
|
|
3929
|
+
table.addRow(row);
|
|
3930
|
+
}
|
|
3931
|
+
return table.render();
|
|
3932
|
+
}
|
|
3933
|
+
function renderTableMarkdown(options) {
|
|
3934
|
+
const { columns, rows } = options;
|
|
3935
|
+
const header = `| ${columns.map((c) => c.title).join(" | ")} |`;
|
|
3936
|
+
const separator = `| ${columns.map((c) => c.alignment === "right" ? "---:" : ":---").join(" | ")} |`;
|
|
3937
|
+
const dataRows = rows.map(
|
|
3938
|
+
(row) => `| ${columns.map((c) => stripAnsi2(row[c.name] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`
|
|
3939
|
+
);
|
|
3940
|
+
return [header, separator, ...dataRows].join("\n");
|
|
3941
|
+
}
|
|
3942
|
+
function renderTableJson(options) {
|
|
3943
|
+
const { columns, rows } = options;
|
|
3944
|
+
const cleaned = rows.map((row) => {
|
|
3945
|
+
const obj = {};
|
|
3946
|
+
for (const col of columns) {
|
|
3947
|
+
obj[col.name] = stripAnsi2(row[col.name] ?? "");
|
|
3948
|
+
}
|
|
3949
|
+
return obj;
|
|
3950
|
+
});
|
|
3951
|
+
return JSON.stringify(cleaned, null, 2);
|
|
3952
|
+
}
|
|
3953
|
+
function renderTable(options) {
|
|
3954
|
+
const format = resolveOutputFormat();
|
|
3955
|
+
switch (format) {
|
|
3956
|
+
case "markdown":
|
|
3957
|
+
return renderTableMarkdown(options);
|
|
3958
|
+
case "json":
|
|
3959
|
+
return renderTableJson(options);
|
|
3960
|
+
default:
|
|
3961
|
+
return renderTableTerminal(options);
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
var init_table = __esm({
|
|
3965
|
+
"packages/design-system/src/components/table.ts"() {
|
|
3966
|
+
"use strict";
|
|
3967
|
+
init_output_format();
|
|
3968
|
+
init_strip_ansi();
|
|
3969
|
+
}
|
|
3970
|
+
});
|
|
3971
|
+
|
|
3972
|
+
// packages/design-system/src/terminal-markdown/parser/frontmatter.ts
|
|
3973
|
+
function extractFrontmatter(markdown) {
|
|
3974
|
+
const content = stripBom(markdown);
|
|
3975
|
+
if (!startsWithFrontmatterFence(content)) {
|
|
3976
|
+
return { body: markdown };
|
|
3977
|
+
}
|
|
3978
|
+
const openingLine = readLine(content, 0);
|
|
3979
|
+
let position = openingLine.nextPosition;
|
|
3980
|
+
let closingFenceStart;
|
|
3981
|
+
let closingFenceNextPosition;
|
|
3982
|
+
while (position <= content.length) {
|
|
3983
|
+
const line = readLine(content, position);
|
|
3984
|
+
if (line.text === "---") {
|
|
3985
|
+
closingFenceStart = line.start;
|
|
3986
|
+
closingFenceNextPosition = line.nextPosition;
|
|
3987
|
+
break;
|
|
3988
|
+
}
|
|
3989
|
+
if (line.nextPosition >= content.length) {
|
|
3990
|
+
break;
|
|
3991
|
+
}
|
|
3992
|
+
position = line.nextPosition;
|
|
3993
|
+
}
|
|
3994
|
+
if (closingFenceStart === void 0 || closingFenceNextPosition === void 0) {
|
|
3995
|
+
return { body: markdown };
|
|
3996
|
+
}
|
|
3997
|
+
const rawFrontmatter = sliceFrontmatterBlock(
|
|
3998
|
+
content,
|
|
3999
|
+
openingLine.nextPosition,
|
|
4000
|
+
closingFenceStart
|
|
4001
|
+
);
|
|
4002
|
+
const frontmatter = parseFrontmatterBlock(rawFrontmatter);
|
|
4003
|
+
return {
|
|
4004
|
+
frontmatter,
|
|
4005
|
+
body: content.slice(closingFenceNextPosition)
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
function parseFrontmatterBlock(yamlBlock) {
|
|
4009
|
+
if (yamlBlock.length === 0) {
|
|
4010
|
+
return {};
|
|
4011
|
+
}
|
|
4012
|
+
try {
|
|
4013
|
+
return new YamlSubsetParser(yamlBlock).parse();
|
|
4014
|
+
} catch (error2) {
|
|
4015
|
+
if (error2 instanceof FrontmatterParseError) {
|
|
4016
|
+
return { raw: yamlBlock };
|
|
4017
|
+
}
|
|
4018
|
+
throw error2;
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
function tokenizeYamlBlock(yamlBlock) {
|
|
4022
|
+
const lines = yamlBlock.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
|
|
4023
|
+
return lines.map((line) => {
|
|
4024
|
+
let indent = 0;
|
|
4025
|
+
while (indent < line.length && line[indent] === " ") {
|
|
4026
|
+
indent += 1;
|
|
4027
|
+
}
|
|
4028
|
+
for (let index = 0; index < indent; index += 1) {
|
|
4029
|
+
if (line[index] === " ") {
|
|
4030
|
+
throw new FrontmatterParseError("Tabs are not supported in frontmatter indentation.");
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
if (indent < line.length && line[indent] === " ") {
|
|
4034
|
+
throw new FrontmatterParseError("Tabs are not supported in frontmatter indentation.");
|
|
4035
|
+
}
|
|
4036
|
+
return {
|
|
4037
|
+
indent,
|
|
4038
|
+
content: line.slice(indent)
|
|
4039
|
+
};
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
function parseKeyValue(content) {
|
|
4043
|
+
const separator = findUnquotedMappingSeparator(content);
|
|
4044
|
+
if (separator === -1) {
|
|
4045
|
+
return null;
|
|
4046
|
+
}
|
|
4047
|
+
const key = trimAsciiWhitespace(content.slice(0, separator));
|
|
4048
|
+
if (key.length === 0) {
|
|
4049
|
+
return null;
|
|
4050
|
+
}
|
|
4051
|
+
const rawValue = trimAsciiWhitespaceStart(content.slice(separator + 1));
|
|
4052
|
+
return rawValue.length === 0 ? { key } : { key, value: rawValue };
|
|
4053
|
+
}
|
|
4054
|
+
function parseArrayItem(content) {
|
|
4055
|
+
if (!isArrayItem(content)) {
|
|
4056
|
+
return null;
|
|
4057
|
+
}
|
|
4058
|
+
return trimAsciiWhitespaceStart(content.slice(1));
|
|
4059
|
+
}
|
|
4060
|
+
function isArrayItem(content) {
|
|
4061
|
+
if (!content.startsWith("-")) {
|
|
4062
|
+
return false;
|
|
4063
|
+
}
|
|
4064
|
+
if (content.length === 1) {
|
|
4065
|
+
return true;
|
|
4066
|
+
}
|
|
4067
|
+
const nextCharacter = content[1];
|
|
4068
|
+
return nextCharacter === " " || nextCharacter === " ";
|
|
4069
|
+
}
|
|
4070
|
+
function parseScalar(value) {
|
|
4071
|
+
if (value.length === 0) {
|
|
4072
|
+
return "";
|
|
4073
|
+
}
|
|
4074
|
+
if (isQuoted(value, "'")) {
|
|
4075
|
+
return value.slice(1, -1).replaceAll("''", "'");
|
|
4076
|
+
}
|
|
4077
|
+
if (isQuoted(value, '"')) {
|
|
4078
|
+
return parseDoubleQuotedString(value.slice(1, -1));
|
|
4079
|
+
}
|
|
4080
|
+
if (value === "true") {
|
|
4081
|
+
return true;
|
|
4082
|
+
}
|
|
4083
|
+
if (value === "false") {
|
|
4084
|
+
return false;
|
|
4085
|
+
}
|
|
4086
|
+
if (value === "null") {
|
|
4087
|
+
return null;
|
|
4088
|
+
}
|
|
4089
|
+
if (isNumberLiteral(value)) {
|
|
4090
|
+
return Number(value);
|
|
4091
|
+
}
|
|
4092
|
+
if (hasUnquotedMappingSeparator(value)) {
|
|
4093
|
+
throw new FrontmatterParseError(
|
|
4094
|
+
"Unquoted mapping separators are not supported in scalar values."
|
|
4095
|
+
);
|
|
4096
|
+
}
|
|
4097
|
+
return value;
|
|
4098
|
+
}
|
|
4099
|
+
function parseDoubleQuotedString(value) {
|
|
4100
|
+
let result = "";
|
|
4101
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
4102
|
+
const character = value[index];
|
|
4103
|
+
if (character !== "\\") {
|
|
4104
|
+
result += character;
|
|
4105
|
+
continue;
|
|
4106
|
+
}
|
|
4107
|
+
index += 1;
|
|
4108
|
+
if (index >= value.length) {
|
|
4109
|
+
result += "\\";
|
|
4110
|
+
break;
|
|
4111
|
+
}
|
|
4112
|
+
const escaped = value[index];
|
|
4113
|
+
if (escaped === "n") {
|
|
4114
|
+
result += "\n";
|
|
4115
|
+
continue;
|
|
4116
|
+
}
|
|
4117
|
+
if (escaped === "r") {
|
|
4118
|
+
result += "\r";
|
|
4119
|
+
continue;
|
|
4120
|
+
}
|
|
4121
|
+
if (escaped === "t") {
|
|
4122
|
+
result += " ";
|
|
4123
|
+
continue;
|
|
4124
|
+
}
|
|
4125
|
+
if (escaped === "b") {
|
|
4126
|
+
result += "\b";
|
|
4127
|
+
continue;
|
|
4128
|
+
}
|
|
4129
|
+
if (escaped === "f") {
|
|
4130
|
+
result += "\f";
|
|
4131
|
+
continue;
|
|
4132
|
+
}
|
|
4133
|
+
if (escaped === '"' || escaped === "\\" || escaped === "/") {
|
|
4134
|
+
result += escaped;
|
|
4135
|
+
continue;
|
|
4136
|
+
}
|
|
4137
|
+
if (escaped === "u") {
|
|
4138
|
+
const codePoint = value.slice(index + 1, index + 5);
|
|
4139
|
+
if (codePoint.length === 4 && isHexadecimal(codePoint)) {
|
|
4140
|
+
result += String.fromCodePoint(Number.parseInt(codePoint, 16));
|
|
4141
|
+
index += 4;
|
|
4142
|
+
continue;
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
result += `\\${escaped}`;
|
|
4146
|
+
}
|
|
4147
|
+
return result;
|
|
4148
|
+
}
|
|
4149
|
+
function isQuoted(value, quote) {
|
|
4150
|
+
return value.length >= 2 && value[0] === quote && value[value.length - 1] === quote;
|
|
4151
|
+
}
|
|
4152
|
+
function isNumberLiteral(value) {
|
|
4153
|
+
let index = 0;
|
|
4154
|
+
let hasDigits = false;
|
|
4155
|
+
let hasDecimal = false;
|
|
4156
|
+
if (value[index] === "-" || value[index] === "+") {
|
|
4157
|
+
index += 1;
|
|
4158
|
+
}
|
|
4159
|
+
while (index < value.length) {
|
|
4160
|
+
const character = value[index];
|
|
4161
|
+
if (character >= "0" && character <= "9") {
|
|
4162
|
+
hasDigits = true;
|
|
4163
|
+
index += 1;
|
|
4164
|
+
continue;
|
|
4165
|
+
}
|
|
4166
|
+
if (character === "." && !hasDecimal) {
|
|
4167
|
+
hasDecimal = true;
|
|
4168
|
+
index += 1;
|
|
4169
|
+
continue;
|
|
4170
|
+
}
|
|
4171
|
+
return false;
|
|
4172
|
+
}
|
|
4173
|
+
return hasDigits;
|
|
4174
|
+
}
|
|
4175
|
+
function hasUnquotedMappingSeparator(value) {
|
|
4176
|
+
return findUnquotedMappingSeparator(value) !== -1;
|
|
4177
|
+
}
|
|
4178
|
+
function findUnquotedMappingSeparator(value) {
|
|
4179
|
+
let quote = null;
|
|
4180
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
4181
|
+
const character = value[index];
|
|
4182
|
+
if (quote !== null) {
|
|
4183
|
+
if (character === "\\" && quote === '"') {
|
|
4184
|
+
index += 1;
|
|
4185
|
+
continue;
|
|
4186
|
+
}
|
|
4187
|
+
if (character === quote) {
|
|
4188
|
+
quote = null;
|
|
4189
|
+
}
|
|
4190
|
+
continue;
|
|
4191
|
+
}
|
|
4192
|
+
if (character === "'" || character === '"') {
|
|
4193
|
+
quote = character;
|
|
4194
|
+
continue;
|
|
4195
|
+
}
|
|
4196
|
+
if (character !== ":") {
|
|
4197
|
+
continue;
|
|
4198
|
+
}
|
|
4199
|
+
const nextCharacter = value[index + 1];
|
|
4200
|
+
if (nextCharacter === void 0 || nextCharacter === " " || nextCharacter === " ") {
|
|
4201
|
+
return index;
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
return -1;
|
|
4205
|
+
}
|
|
4206
|
+
function sliceFrontmatterBlock(content, start, end) {
|
|
4207
|
+
let sliceEnd = end;
|
|
4208
|
+
if (sliceEnd > start && content[sliceEnd - 1] === "\n") {
|
|
4209
|
+
sliceEnd -= 1;
|
|
4210
|
+
if (sliceEnd > start && content[sliceEnd - 1] === "\r") {
|
|
4211
|
+
sliceEnd -= 1;
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
return content.slice(start, sliceEnd);
|
|
4215
|
+
}
|
|
4216
|
+
function startsWithFrontmatterFence(value) {
|
|
4217
|
+
return value.startsWith("---\n") || value.startsWith("---\r\n");
|
|
4218
|
+
}
|
|
4219
|
+
function stripBom(value) {
|
|
4220
|
+
return value.startsWith("\uFEFF") ? value.slice(1) : value;
|
|
4221
|
+
}
|
|
4222
|
+
function readLine(input, position) {
|
|
4223
|
+
let end = position;
|
|
4224
|
+
while (end < input.length && input[end] !== "\n" && input[end] !== "\r") {
|
|
4225
|
+
end += 1;
|
|
4226
|
+
}
|
|
4227
|
+
let nextPosition = end;
|
|
4228
|
+
if (input[nextPosition] === "\r" && input[nextPosition + 1] === "\n") {
|
|
4229
|
+
nextPosition += 2;
|
|
4230
|
+
} else if (input[nextPosition] === "\n" || input[nextPosition] === "\r") {
|
|
4231
|
+
nextPosition += 1;
|
|
4232
|
+
}
|
|
4233
|
+
return {
|
|
4234
|
+
text: input.slice(position, end),
|
|
4235
|
+
start: position,
|
|
4236
|
+
nextPosition
|
|
4237
|
+
};
|
|
4238
|
+
}
|
|
4239
|
+
function trimAsciiWhitespace(value) {
|
|
4240
|
+
return trimAsciiWhitespaceEnd(trimAsciiWhitespaceStart(value));
|
|
4241
|
+
}
|
|
4242
|
+
function trimAsciiWhitespaceStart(value) {
|
|
4243
|
+
let start = 0;
|
|
4244
|
+
while (start < value.length && (value[start] === " " || value[start] === " ")) {
|
|
4245
|
+
start += 1;
|
|
4246
|
+
}
|
|
4247
|
+
return value.slice(start);
|
|
4248
|
+
}
|
|
4249
|
+
function trimAsciiWhitespaceEnd(value) {
|
|
4250
|
+
let end = value.length;
|
|
4251
|
+
while (end > 0 && (value[end - 1] === " " || value[end - 1] === " ")) {
|
|
4252
|
+
end -= 1;
|
|
4253
|
+
}
|
|
4254
|
+
return value.slice(0, end);
|
|
4255
|
+
}
|
|
4256
|
+
function hasOwn(record, key) {
|
|
4257
|
+
return Object.prototype.hasOwnProperty.call(record, key);
|
|
4258
|
+
}
|
|
4259
|
+
function isHexadecimal(value) {
|
|
4260
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
4261
|
+
const character = value[index];
|
|
4262
|
+
if (character >= "0" && character <= "9" || character >= "a" && character <= "f" || character >= "A" && character <= "F") {
|
|
4263
|
+
continue;
|
|
4264
|
+
}
|
|
4265
|
+
return false;
|
|
4266
|
+
}
|
|
4267
|
+
return true;
|
|
4268
|
+
}
|
|
4269
|
+
var FrontmatterParseError, YamlSubsetParser;
|
|
4270
|
+
var init_frontmatter = __esm({
|
|
4271
|
+
"packages/design-system/src/terminal-markdown/parser/frontmatter.ts"() {
|
|
4272
|
+
"use strict";
|
|
4273
|
+
FrontmatterParseError = class extends Error {
|
|
4274
|
+
};
|
|
4275
|
+
YamlSubsetParser = class {
|
|
4276
|
+
lines;
|
|
4277
|
+
position = 0;
|
|
4278
|
+
constructor(yamlBlock) {
|
|
4279
|
+
this.lines = tokenizeYamlBlock(yamlBlock);
|
|
4280
|
+
}
|
|
4281
|
+
parse() {
|
|
4282
|
+
this.skipBlankLines();
|
|
4283
|
+
if (this.position >= this.lines.length) {
|
|
4284
|
+
return {};
|
|
4285
|
+
}
|
|
4286
|
+
return this.parseObject(0);
|
|
4287
|
+
}
|
|
4288
|
+
parseObject(expectedIndent) {
|
|
4289
|
+
const result = {};
|
|
4290
|
+
while (true) {
|
|
4291
|
+
this.skipBlankLines();
|
|
4292
|
+
const line = this.lines[this.position];
|
|
4293
|
+
if (line === void 0) {
|
|
4294
|
+
break;
|
|
4295
|
+
}
|
|
4296
|
+
if (line.indent < expectedIndent) {
|
|
4297
|
+
break;
|
|
4298
|
+
}
|
|
4299
|
+
if (line.indent !== expectedIndent || isArrayItem(line.content)) {
|
|
4300
|
+
throw new FrontmatterParseError("Invalid object indentation.");
|
|
4301
|
+
}
|
|
4302
|
+
const entry = parseKeyValue(line.content);
|
|
4303
|
+
if (entry === null || hasOwn(result, entry.key)) {
|
|
4304
|
+
throw new FrontmatterParseError("Invalid mapping entry.");
|
|
4305
|
+
}
|
|
4306
|
+
this.position += 1;
|
|
4307
|
+
result[entry.key] = this.readEntryValue(entry, expectedIndent);
|
|
4308
|
+
}
|
|
4309
|
+
return result;
|
|
4310
|
+
}
|
|
4311
|
+
parseArray(expectedIndent) {
|
|
4312
|
+
const result = [];
|
|
4313
|
+
while (true) {
|
|
4314
|
+
this.skipBlankLines();
|
|
4315
|
+
const line = this.lines[this.position];
|
|
4316
|
+
if (line === void 0) {
|
|
4317
|
+
break;
|
|
4318
|
+
}
|
|
4319
|
+
if (line.indent < expectedIndent) {
|
|
4320
|
+
break;
|
|
4321
|
+
}
|
|
4322
|
+
if (line.indent !== expectedIndent) {
|
|
4323
|
+
throw new FrontmatterParseError("Invalid array indentation.");
|
|
4324
|
+
}
|
|
4325
|
+
const item = parseArrayItem(line.content);
|
|
4326
|
+
if (item === null) {
|
|
4327
|
+
throw new FrontmatterParseError("Invalid array item.");
|
|
4328
|
+
}
|
|
4329
|
+
this.position += 1;
|
|
4330
|
+
if (item.length > 0) {
|
|
4331
|
+
result.push(parseScalar(item));
|
|
4332
|
+
continue;
|
|
4333
|
+
}
|
|
4334
|
+
const nestedLine = this.peekMeaningfulLine();
|
|
4335
|
+
if (nestedLine === void 0 || nestedLine.indent <= expectedIndent) {
|
|
4336
|
+
result.push(null);
|
|
4337
|
+
continue;
|
|
4338
|
+
}
|
|
4339
|
+
result.push(
|
|
4340
|
+
isArrayItem(nestedLine.content) ? this.parseArray(nestedLine.indent) : this.parseObject(nestedLine.indent)
|
|
4341
|
+
);
|
|
4342
|
+
}
|
|
4343
|
+
return result;
|
|
4344
|
+
}
|
|
4345
|
+
readEntryValue(entry, currentIndent) {
|
|
4346
|
+
if (entry.value !== void 0) {
|
|
4347
|
+
return parseScalar(entry.value);
|
|
4348
|
+
}
|
|
4349
|
+
const nestedLine = this.peekMeaningfulLine();
|
|
4350
|
+
if (nestedLine === void 0 || nestedLine.indent <= currentIndent) {
|
|
4351
|
+
return null;
|
|
4352
|
+
}
|
|
4353
|
+
return isArrayItem(nestedLine.content) ? this.parseArray(nestedLine.indent) : this.parseObject(nestedLine.indent);
|
|
4354
|
+
}
|
|
4355
|
+
peekMeaningfulLine() {
|
|
4356
|
+
let index = this.position;
|
|
4357
|
+
while (index < this.lines.length) {
|
|
4358
|
+
const line = this.lines[index];
|
|
4359
|
+
if (line.content.length > 0) {
|
|
4360
|
+
return line;
|
|
4361
|
+
}
|
|
4362
|
+
index += 1;
|
|
4363
|
+
}
|
|
4364
|
+
return void 0;
|
|
4365
|
+
}
|
|
4366
|
+
skipBlankLines() {
|
|
4367
|
+
while (this.position < this.lines.length && this.lines[this.position].content.length === 0) {
|
|
4368
|
+
this.position += 1;
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
});
|
|
4374
|
+
|
|
4375
|
+
// packages/design-system/src/terminal-markdown/parser/inline.ts
|
|
4376
|
+
function parseInline(raw, options = {}) {
|
|
4377
|
+
const nodes = [];
|
|
4378
|
+
const delimiters = [];
|
|
4379
|
+
const footnoteLabels = options.footnoteLabels;
|
|
4380
|
+
const allowLiteralAutolinks = options.allowLiteralAutolinks ?? true;
|
|
4381
|
+
let textBuffer = "";
|
|
4382
|
+
let index = 0;
|
|
4383
|
+
const flushText = () => {
|
|
4384
|
+
if (textBuffer.length === 0) {
|
|
4385
|
+
return;
|
|
4386
|
+
}
|
|
4387
|
+
nodes.push({ type: "text", value: textBuffer });
|
|
4388
|
+
textBuffer = "";
|
|
4389
|
+
};
|
|
4390
|
+
while (index < raw.length) {
|
|
4391
|
+
const char = raw[index];
|
|
4392
|
+
if (char === "\\" && index + 1 < raw.length && isEscapable(raw[index + 1])) {
|
|
4393
|
+
textBuffer += raw[index + 1];
|
|
4394
|
+
index += 2;
|
|
4395
|
+
continue;
|
|
4396
|
+
}
|
|
4397
|
+
if (char === "`") {
|
|
4398
|
+
const code = parseInlineCode(raw, index);
|
|
4399
|
+
if (code !== null) {
|
|
4400
|
+
flushText();
|
|
4401
|
+
nodes.push(code.node);
|
|
4402
|
+
index = code.end;
|
|
4403
|
+
continue;
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
if (char === "!" && index + 1 < raw.length && raw[index + 1] === "[") {
|
|
4407
|
+
const image = parseImage(raw, index);
|
|
4408
|
+
if (image !== null) {
|
|
4409
|
+
flushText();
|
|
4410
|
+
nodes.push(image.node);
|
|
4411
|
+
index = image.end;
|
|
4412
|
+
continue;
|
|
4413
|
+
}
|
|
4414
|
+
}
|
|
4415
|
+
if (char === "[") {
|
|
4416
|
+
const footnoteReference = parseFootnoteReference(raw, index, footnoteLabels);
|
|
4417
|
+
if (footnoteReference !== null) {
|
|
4418
|
+
flushText();
|
|
4419
|
+
nodes.push(footnoteReference.node);
|
|
4420
|
+
index = footnoteReference.end;
|
|
4421
|
+
continue;
|
|
4422
|
+
}
|
|
4423
|
+
const link = parseLink(raw, index, footnoteLabels);
|
|
4424
|
+
if (link !== null) {
|
|
4425
|
+
flushText();
|
|
4426
|
+
nodes.push(link.node);
|
|
4427
|
+
index = link.end;
|
|
4428
|
+
continue;
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
if (char === "<") {
|
|
4432
|
+
const autolink = parseAutolink(raw, index);
|
|
4433
|
+
if (autolink !== null) {
|
|
4434
|
+
flushText();
|
|
4435
|
+
nodes.push(autolink.node);
|
|
4436
|
+
index = autolink.end;
|
|
4437
|
+
continue;
|
|
4438
|
+
}
|
|
4439
|
+
const html = parseInlineHtmlTag(raw, index);
|
|
4440
|
+
if (html !== null) {
|
|
4441
|
+
flushText();
|
|
4442
|
+
nodes.push(html.node);
|
|
4443
|
+
index = html.end;
|
|
4444
|
+
continue;
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
if (char === "\n") {
|
|
4448
|
+
if (textBuffer.endsWith("\\")) {
|
|
4449
|
+
textBuffer = textBuffer.slice(0, -1);
|
|
4450
|
+
flushText();
|
|
4451
|
+
nodes.push({ type: "break" });
|
|
4452
|
+
index += 1;
|
|
4453
|
+
continue;
|
|
4454
|
+
}
|
|
4455
|
+
const trailingSpaceStart = findTrailingHardBreakSpaceStart(textBuffer);
|
|
4456
|
+
if (trailingSpaceStart !== -1) {
|
|
4457
|
+
textBuffer = textBuffer.slice(0, trailingSpaceStart);
|
|
4458
|
+
flushText();
|
|
4459
|
+
nodes.push({ type: "break" });
|
|
4460
|
+
index += 1;
|
|
4461
|
+
continue;
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
if (allowLiteralAutolinks) {
|
|
4465
|
+
const literalAutolink = parseLiteralAutolink(raw, index);
|
|
4466
|
+
if (literalAutolink !== null) {
|
|
4467
|
+
flushText();
|
|
4468
|
+
nodes.push(literalAutolink.node);
|
|
4469
|
+
index = literalAutolink.end;
|
|
4470
|
+
continue;
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
if (char === "*" || char === "_" || char === "~") {
|
|
4474
|
+
const delimiter = parseDelimiter(raw, index, char);
|
|
4475
|
+
if (delimiter !== null) {
|
|
4476
|
+
flushText();
|
|
4477
|
+
const node = {
|
|
4478
|
+
type: "text",
|
|
4479
|
+
value: raw.slice(index, index + delimiter.length)
|
|
4480
|
+
};
|
|
4481
|
+
nodes.push(node);
|
|
4482
|
+
delimiters.push({
|
|
4483
|
+
...delimiter,
|
|
4484
|
+
node,
|
|
4485
|
+
position: nodes.length - 1
|
|
4486
|
+
});
|
|
4487
|
+
index += delimiter.length;
|
|
4488
|
+
continue;
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
textBuffer += char;
|
|
4492
|
+
index += 1;
|
|
4493
|
+
}
|
|
4494
|
+
flushText();
|
|
4495
|
+
if (delimiters.length === 0) {
|
|
4496
|
+
return normalizeInlineNodes(nodes);
|
|
4497
|
+
}
|
|
4498
|
+
const pairs = matchDelimiterPairs(delimiters);
|
|
4499
|
+
if (pairs.length === 0) {
|
|
4500
|
+
return normalizeInlineNodes(nodes);
|
|
4501
|
+
}
|
|
4502
|
+
return buildInlineNodes(nodes, delimiters, pairs);
|
|
4503
|
+
}
|
|
4504
|
+
function parseDelimiter(input, start, marker) {
|
|
4505
|
+
const length = readRunLength(input, start, marker);
|
|
4506
|
+
const before = start === 0 ? null : input[start - 1];
|
|
4507
|
+
const after = start + length >= input.length ? null : input[start + length];
|
|
4508
|
+
const leftFlanking = !isDelimiterWhitespace(after) && (!isDelimiterPunctuation(after) || isDelimiterWhitespace(before) || isDelimiterPunctuation(before));
|
|
4509
|
+
const rightFlanking = !isDelimiterWhitespace(before) && (!isDelimiterPunctuation(before) || isDelimiterWhitespace(after) || isDelimiterPunctuation(after));
|
|
4510
|
+
if (marker === "~") {
|
|
4511
|
+
if (length < 2) {
|
|
4512
|
+
return null;
|
|
4513
|
+
}
|
|
4514
|
+
return {
|
|
4515
|
+
marker,
|
|
4516
|
+
length,
|
|
4517
|
+
canOpen: leftFlanking,
|
|
4518
|
+
canClose: rightFlanking
|
|
4519
|
+
};
|
|
4520
|
+
}
|
|
4521
|
+
if (marker === "_") {
|
|
4522
|
+
return {
|
|
4523
|
+
marker,
|
|
4524
|
+
length,
|
|
4525
|
+
canOpen: leftFlanking && (!rightFlanking || isDelimiterPunctuation(before)),
|
|
4526
|
+
canClose: rightFlanking && (!leftFlanking || isDelimiterPunctuation(after))
|
|
4527
|
+
};
|
|
4528
|
+
}
|
|
4529
|
+
return {
|
|
4530
|
+
marker,
|
|
4531
|
+
length,
|
|
4532
|
+
canOpen: leftFlanking,
|
|
4533
|
+
canClose: rightFlanking
|
|
4534
|
+
};
|
|
4535
|
+
}
|
|
4536
|
+
function matchDelimiterPairs(delimiters) {
|
|
4537
|
+
const pairs = [];
|
|
4538
|
+
const previous = delimiters.map((_2, index) => index - 1);
|
|
4539
|
+
const next = delimiters.map((_2, index) => index + 1 < delimiters.length ? index + 1 : -1);
|
|
4540
|
+
const active = delimiters.map(() => true);
|
|
4541
|
+
let sequence = 0;
|
|
4542
|
+
let closerIndex = 0;
|
|
4543
|
+
const unlinkDelimiter = (index) => {
|
|
4544
|
+
if (!active[index]) {
|
|
4545
|
+
return;
|
|
4546
|
+
}
|
|
4547
|
+
const previousIndex = previous[index];
|
|
4548
|
+
const nextIndex = next[index];
|
|
4549
|
+
if (previousIndex !== -1) {
|
|
4550
|
+
next[previousIndex] = nextIndex;
|
|
4551
|
+
}
|
|
4552
|
+
if (nextIndex !== -1) {
|
|
4553
|
+
previous[nextIndex] = previousIndex;
|
|
4554
|
+
}
|
|
4555
|
+
active[index] = false;
|
|
4556
|
+
};
|
|
4557
|
+
const pruneDelimiter = (index) => {
|
|
4558
|
+
const delimiter = delimiters[index];
|
|
4559
|
+
if (delimiter.length === 0) {
|
|
4560
|
+
unlinkDelimiter(index);
|
|
4561
|
+
return;
|
|
4562
|
+
}
|
|
4563
|
+
if (delimiter.marker === "~" && delimiter.length < 2) {
|
|
4564
|
+
delimiter.canOpen = false;
|
|
4565
|
+
delimiter.canClose = false;
|
|
4566
|
+
unlinkDelimiter(index);
|
|
4567
|
+
}
|
|
4568
|
+
};
|
|
4569
|
+
while (closerIndex !== -1) {
|
|
4570
|
+
const closer = delimiters[closerIndex];
|
|
4571
|
+
if (!closer.canClose || closer.length === 0) {
|
|
4572
|
+
closerIndex = next[closerIndex];
|
|
4573
|
+
continue;
|
|
4574
|
+
}
|
|
4575
|
+
const openerIndex = findMatchingOpener(delimiters, previous, closerIndex);
|
|
4576
|
+
if (openerIndex === null) {
|
|
4577
|
+
const nextCloserIndex = next[closerIndex];
|
|
4578
|
+
if (!closer.canOpen) {
|
|
4579
|
+
unlinkDelimiter(closerIndex);
|
|
4580
|
+
}
|
|
4581
|
+
closerIndex = nextCloserIndex;
|
|
4582
|
+
continue;
|
|
4583
|
+
}
|
|
4584
|
+
const opener = delimiters[openerIndex];
|
|
4585
|
+
const pairLength = getPairLength(opener, closer);
|
|
4586
|
+
if (pairLength === 0 || opener.position + 1 >= closer.position) {
|
|
4587
|
+
closerIndex = next[closerIndex];
|
|
4588
|
+
continue;
|
|
4589
|
+
}
|
|
4590
|
+
pairs.push({
|
|
4591
|
+
opener,
|
|
4592
|
+
closer,
|
|
4593
|
+
kind: getPairKind(opener.marker, pairLength),
|
|
4594
|
+
sequence
|
|
4595
|
+
});
|
|
4596
|
+
opener.length -= pairLength;
|
|
4597
|
+
closer.length -= pairLength;
|
|
4598
|
+
let trappedIndex = next[openerIndex];
|
|
4599
|
+
while (trappedIndex !== -1 && trappedIndex !== closerIndex) {
|
|
4600
|
+
const nextTrappedIndex = next[trappedIndex];
|
|
4601
|
+
unlinkDelimiter(trappedIndex);
|
|
4602
|
+
trappedIndex = nextTrappedIndex;
|
|
4603
|
+
}
|
|
4604
|
+
pruneDelimiter(openerIndex);
|
|
4605
|
+
pruneDelimiter(closerIndex);
|
|
4606
|
+
if (!active[closerIndex] || !closer.canClose || closer.length === 0) {
|
|
4607
|
+
closerIndex = next[closerIndex];
|
|
4608
|
+
}
|
|
4609
|
+
sequence += 1;
|
|
4610
|
+
}
|
|
4611
|
+
return pairs;
|
|
4612
|
+
}
|
|
4613
|
+
function findMatchingOpener(delimiters, previous, closerIndex) {
|
|
4614
|
+
const closer = delimiters[closerIndex];
|
|
4615
|
+
let openerIndex = previous[closerIndex];
|
|
4616
|
+
while (openerIndex !== -1) {
|
|
4617
|
+
const opener = delimiters[openerIndex];
|
|
4618
|
+
if (opener.marker === closer.marker && opener.canOpen && opener.length > 0 && !violatesMultipleOfThreeRule(opener, closer)) {
|
|
4619
|
+
return openerIndex;
|
|
4620
|
+
}
|
|
4621
|
+
openerIndex = previous[openerIndex];
|
|
4622
|
+
}
|
|
4623
|
+
return null;
|
|
4624
|
+
}
|
|
4625
|
+
function violatesMultipleOfThreeRule(opener, closer) {
|
|
4626
|
+
if (opener.marker === "~") {
|
|
4627
|
+
return false;
|
|
4628
|
+
}
|
|
4629
|
+
if (!opener.canClose || !closer.canOpen) {
|
|
4630
|
+
return false;
|
|
4631
|
+
}
|
|
4632
|
+
return (opener.length + closer.length) % 3 === 0 && (opener.length % 3 !== 0 || closer.length % 3 !== 0);
|
|
4633
|
+
}
|
|
4634
|
+
function getPairLength(opener, closer) {
|
|
4635
|
+
if (opener.marker === "~") {
|
|
4636
|
+
return opener.length >= 2 && closer.length >= 2 ? 2 : 0;
|
|
4637
|
+
}
|
|
4638
|
+
return opener.length >= 2 && closer.length >= 2 ? 2 : 1;
|
|
4639
|
+
}
|
|
4640
|
+
function getPairKind(marker, pairLength) {
|
|
4641
|
+
if (marker === "~") {
|
|
4642
|
+
return "strikethrough";
|
|
4643
|
+
}
|
|
4644
|
+
return pairLength === 2 ? "strong" : "emphasis";
|
|
4645
|
+
}
|
|
4646
|
+
function buildInlineNodes(nodes, delimiters, pairs) {
|
|
4647
|
+
const delimiterEntries = /* @__PURE__ */ new Map();
|
|
4648
|
+
for (const delimiter of delimiters) {
|
|
4649
|
+
delimiterEntries.set(delimiter.node, {
|
|
4650
|
+
delimiter,
|
|
4651
|
+
opens: [],
|
|
4652
|
+
closes: []
|
|
4653
|
+
});
|
|
4654
|
+
}
|
|
4655
|
+
for (const pair of pairs) {
|
|
4656
|
+
delimiterEntries.get(pair.opener.node)?.opens.push(pair);
|
|
4657
|
+
delimiterEntries.get(pair.closer.node)?.closes.push(pair);
|
|
4658
|
+
}
|
|
4659
|
+
const root = [];
|
|
4660
|
+
const stack = [{ children: root }];
|
|
4661
|
+
const appendNode = (node) => {
|
|
4662
|
+
stack[stack.length - 1]?.children.push(node);
|
|
4663
|
+
};
|
|
4664
|
+
for (const node of nodes) {
|
|
4665
|
+
if (node.type !== "text") {
|
|
4666
|
+
appendNode(node);
|
|
4667
|
+
continue;
|
|
4668
|
+
}
|
|
4669
|
+
const delimiterEntry = delimiterEntries.get(node);
|
|
4670
|
+
if (delimiterEntry === void 0) {
|
|
4671
|
+
appendNode(node);
|
|
4672
|
+
continue;
|
|
4673
|
+
}
|
|
4674
|
+
delimiterEntry.closes.sort((left, right) => left.sequence - right.sequence);
|
|
4675
|
+
for (const pair of delimiterEntry.closes) {
|
|
4676
|
+
const current = stack[stack.length - 1];
|
|
4677
|
+
if (current?.pair === pair) {
|
|
4678
|
+
stack.pop();
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
if (delimiterEntry.delimiter.length > 0) {
|
|
4682
|
+
appendNode({
|
|
4683
|
+
type: "text",
|
|
4684
|
+
value: delimiterEntry.delimiter.marker.repeat(delimiterEntry.delimiter.length)
|
|
4685
|
+
});
|
|
4686
|
+
}
|
|
4687
|
+
delimiterEntry.opens.sort((left, right) => right.sequence - left.sequence);
|
|
4688
|
+
for (const pair of delimiterEntry.opens) {
|
|
4689
|
+
const wrapper = createDelimiterNode(pair.kind);
|
|
4690
|
+
appendNode(wrapper);
|
|
4691
|
+
stack.push({ pair, children: wrapper.children });
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
return normalizeInlineNodes(root);
|
|
4695
|
+
}
|
|
4696
|
+
function createDelimiterNode(kind) {
|
|
4697
|
+
return { type: kind, children: [] };
|
|
4698
|
+
}
|
|
4699
|
+
function normalizeInlineNodes(nodes) {
|
|
4700
|
+
const normalized = [];
|
|
4701
|
+
for (const node of nodes) {
|
|
4702
|
+
const nextNode = normalizeInlineNode(node);
|
|
4703
|
+
if (nextNode === null) {
|
|
4704
|
+
continue;
|
|
4705
|
+
}
|
|
4706
|
+
const previousNode = normalized[normalized.length - 1];
|
|
4707
|
+
if (previousNode?.type === "text" && nextNode.type === "text") {
|
|
4708
|
+
previousNode.value += nextNode.value;
|
|
4709
|
+
continue;
|
|
4710
|
+
}
|
|
4711
|
+
normalized.push(nextNode);
|
|
4712
|
+
}
|
|
4713
|
+
return normalized;
|
|
4714
|
+
}
|
|
4715
|
+
function normalizeInlineNode(node) {
|
|
4716
|
+
if (node.type === "text") {
|
|
4717
|
+
return node.value.length === 0 ? null : node;
|
|
4718
|
+
}
|
|
4719
|
+
if (node.type === "emphasis" || node.type === "strong" || node.type === "strikethrough" || node.type === "link") {
|
|
4720
|
+
return { ...node, children: normalizeInlineNodes(node.children) };
|
|
4721
|
+
}
|
|
4722
|
+
return node;
|
|
4723
|
+
}
|
|
4724
|
+
function parseInlineCode(input, start) {
|
|
4725
|
+
const fenceLength = readRunLength(input, start, "`");
|
|
4726
|
+
let index = start + fenceLength;
|
|
4727
|
+
while (index < input.length) {
|
|
4728
|
+
if (input[index] !== "`") {
|
|
4729
|
+
index += 1;
|
|
4730
|
+
continue;
|
|
4731
|
+
}
|
|
4732
|
+
const closingFenceLength = readRunLength(input, index, "`");
|
|
4733
|
+
if (closingFenceLength === fenceLength) {
|
|
4734
|
+
return {
|
|
4735
|
+
node: {
|
|
4736
|
+
type: "inlineCode",
|
|
4737
|
+
value: input.slice(start + fenceLength, index)
|
|
4738
|
+
},
|
|
4739
|
+
end: index + fenceLength
|
|
4740
|
+
};
|
|
4741
|
+
}
|
|
4742
|
+
index += closingFenceLength;
|
|
4743
|
+
}
|
|
4744
|
+
return null;
|
|
4745
|
+
}
|
|
4746
|
+
function parseLink(input, start, footnoteLabels) {
|
|
4747
|
+
const label = parseBracketedLabel(input, start);
|
|
4748
|
+
if (label === null || label.end >= input.length || input[label.end] !== "(") {
|
|
4749
|
+
return null;
|
|
4750
|
+
}
|
|
4751
|
+
const destination = parseLinkDestination(input, label.end);
|
|
4752
|
+
if (destination === null) {
|
|
4753
|
+
return null;
|
|
4754
|
+
}
|
|
4755
|
+
return {
|
|
4756
|
+
node: {
|
|
4757
|
+
type: "link",
|
|
4758
|
+
url: destination.url,
|
|
4759
|
+
...destination.title === void 0 ? {} : { title: destination.title },
|
|
4760
|
+
children: parseInline(label.value, {
|
|
4761
|
+
footnoteLabels,
|
|
4762
|
+
allowLiteralAutolinks: false
|
|
4763
|
+
})
|
|
4764
|
+
},
|
|
4765
|
+
end: destination.end
|
|
4766
|
+
};
|
|
4767
|
+
}
|
|
4768
|
+
function parseImage(input, start) {
|
|
4769
|
+
const label = parseBracketedLabel(input, start + 1);
|
|
4770
|
+
if (label === null || label.end >= input.length || input[label.end] !== "(") {
|
|
4771
|
+
return null;
|
|
4772
|
+
}
|
|
4773
|
+
const destination = parseLinkDestination(input, label.end);
|
|
4774
|
+
if (destination === null) {
|
|
4775
|
+
return null;
|
|
4776
|
+
}
|
|
4777
|
+
return {
|
|
4778
|
+
node: {
|
|
4779
|
+
type: "image",
|
|
4780
|
+
url: destination.url,
|
|
4781
|
+
alt: decodeEscapes(label.value),
|
|
4782
|
+
...destination.title === void 0 ? {} : { title: destination.title }
|
|
4783
|
+
},
|
|
4784
|
+
end: destination.end
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
function parseBracketedLabel(input, start) {
|
|
4788
|
+
if (start >= input.length || input[start] !== "[") {
|
|
4789
|
+
return null;
|
|
4790
|
+
}
|
|
4791
|
+
let depth = 1;
|
|
4792
|
+
let index = start + 1;
|
|
4793
|
+
while (index < input.length) {
|
|
4794
|
+
const char = input[index];
|
|
4795
|
+
if (char === "\\" && index + 1 < input.length) {
|
|
4796
|
+
index += 2;
|
|
4797
|
+
continue;
|
|
4798
|
+
}
|
|
4799
|
+
if (char === "`") {
|
|
4800
|
+
const code = parseInlineCode(input, index);
|
|
4801
|
+
if (code !== null) {
|
|
4802
|
+
index = code.end;
|
|
4803
|
+
continue;
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
if (char === "[") {
|
|
4807
|
+
depth += 1;
|
|
4808
|
+
index += 1;
|
|
4809
|
+
continue;
|
|
4810
|
+
}
|
|
4811
|
+
if (char === "]") {
|
|
4812
|
+
depth -= 1;
|
|
4813
|
+
if (depth === 0) {
|
|
4814
|
+
return {
|
|
4815
|
+
value: input.slice(start + 1, index),
|
|
4816
|
+
end: index + 1
|
|
4817
|
+
};
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
index += 1;
|
|
4821
|
+
}
|
|
4822
|
+
return null;
|
|
4823
|
+
}
|
|
4824
|
+
function parseLinkDestination(input, openParenIndex) {
|
|
4825
|
+
let depth = 1;
|
|
4826
|
+
let quote = null;
|
|
4827
|
+
let index = openParenIndex + 1;
|
|
4828
|
+
while (index < input.length) {
|
|
4829
|
+
const char = input[index];
|
|
4830
|
+
if (quote !== null) {
|
|
4831
|
+
if (char === "\\" && index + 1 < input.length) {
|
|
4832
|
+
index += 2;
|
|
4833
|
+
continue;
|
|
4834
|
+
}
|
|
4835
|
+
if (char === quote) {
|
|
4836
|
+
quote = null;
|
|
4837
|
+
}
|
|
4838
|
+
index += 1;
|
|
4839
|
+
continue;
|
|
4840
|
+
}
|
|
4841
|
+
if (char === "\\" && index + 1 < input.length && isEscapable(input[index + 1])) {
|
|
4842
|
+
index += 2;
|
|
4843
|
+
continue;
|
|
4844
|
+
}
|
|
4845
|
+
if (char === '"' || char === "'") {
|
|
4846
|
+
quote = char;
|
|
4847
|
+
index += 1;
|
|
4848
|
+
continue;
|
|
4849
|
+
}
|
|
4850
|
+
if (char === "(") {
|
|
4851
|
+
depth += 1;
|
|
4852
|
+
index += 1;
|
|
4853
|
+
continue;
|
|
4854
|
+
}
|
|
4855
|
+
if (char === ")") {
|
|
4856
|
+
depth -= 1;
|
|
4857
|
+
if (depth === 0) {
|
|
4858
|
+
const content = input.slice(openParenIndex + 1, index);
|
|
4859
|
+
const parsed = parseLinkDestinationContent(content);
|
|
4860
|
+
return {
|
|
4861
|
+
...parsed,
|
|
4862
|
+
end: index + 1
|
|
4863
|
+
};
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4866
|
+
index += 1;
|
|
4867
|
+
}
|
|
4868
|
+
return null;
|
|
4869
|
+
}
|
|
4870
|
+
function parseLinkDestinationContent(content) {
|
|
4871
|
+
const trimmedEnd = trimAsciiWhitespaceEndIndex(content);
|
|
4872
|
+
if (trimmedEnd === 0) {
|
|
4873
|
+
return { url: "" };
|
|
4874
|
+
}
|
|
4875
|
+
const quote = content[trimmedEnd - 1];
|
|
4876
|
+
if (quote === '"' || quote === "'") {
|
|
4877
|
+
const titleStart = findTrailingQuotedSegmentStart(content, trimmedEnd, quote);
|
|
4878
|
+
if (titleStart !== -1) {
|
|
4879
|
+
let separatorStart = titleStart;
|
|
4880
|
+
while (separatorStart > 0 && isAsciiWhitespace(content[separatorStart - 1])) {
|
|
4881
|
+
separatorStart -= 1;
|
|
4882
|
+
}
|
|
4883
|
+
if (separatorStart < titleStart) {
|
|
4884
|
+
return {
|
|
4885
|
+
url: decodeEscapes(trimAsciiWhitespace2(content.slice(0, separatorStart))),
|
|
4886
|
+
title: decodeEscapes(content.slice(titleStart + 1, trimmedEnd - 1))
|
|
4887
|
+
};
|
|
4888
|
+
}
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
return { url: decodeEscapes(trimAsciiWhitespace2(content.slice(0, trimmedEnd))) };
|
|
4892
|
+
}
|
|
4893
|
+
function findTrailingQuotedSegmentStart(content, end, quote) {
|
|
4894
|
+
let index = end - 2;
|
|
4895
|
+
while (index >= 0) {
|
|
4896
|
+
if (content[index] === quote && !isEscaped(content, index)) {
|
|
4897
|
+
return index;
|
|
4898
|
+
}
|
|
4899
|
+
index -= 1;
|
|
4900
|
+
}
|
|
4901
|
+
return -1;
|
|
4902
|
+
}
|
|
4903
|
+
function parseAutolink(input, start) {
|
|
4904
|
+
let index = start + 1;
|
|
4905
|
+
while (index < input.length && input[index] !== ">") {
|
|
4906
|
+
const char = input[index];
|
|
4907
|
+
if (char === "<" || char === "\n" || char === " " || char === " ") {
|
|
4908
|
+
return null;
|
|
4909
|
+
}
|
|
4910
|
+
index += 1;
|
|
4911
|
+
}
|
|
4912
|
+
if (index >= input.length || index === start + 1) {
|
|
4913
|
+
return null;
|
|
4914
|
+
}
|
|
4915
|
+
const url = input.slice(start + 1, index);
|
|
4916
|
+
if (!isAutolinkUrl(url)) {
|
|
4917
|
+
return null;
|
|
4918
|
+
}
|
|
4919
|
+
return {
|
|
4920
|
+
node: {
|
|
4921
|
+
type: "link",
|
|
4922
|
+
url,
|
|
4923
|
+
children: [{ type: "text", value: url }]
|
|
4924
|
+
},
|
|
4925
|
+
end: index + 1
|
|
4926
|
+
};
|
|
4927
|
+
}
|
|
4928
|
+
function parseFootnoteReference(input, start, footnoteLabels) {
|
|
4929
|
+
if (footnoteLabels === void 0 || start + 3 >= input.length || input[start] !== "[" || input[start + 1] !== "^") {
|
|
4930
|
+
return null;
|
|
4931
|
+
}
|
|
4932
|
+
let labelEnd = start + 2;
|
|
4933
|
+
while (labelEnd < input.length && input[labelEnd] !== "]") {
|
|
4934
|
+
if (!isFootnoteLabelChar(input[labelEnd])) {
|
|
4935
|
+
return null;
|
|
4936
|
+
}
|
|
4937
|
+
labelEnd += 1;
|
|
4938
|
+
}
|
|
4939
|
+
if (labelEnd === start + 2 || labelEnd >= input.length) {
|
|
4940
|
+
return null;
|
|
4941
|
+
}
|
|
4942
|
+
const label = input.slice(start + 2, labelEnd);
|
|
4943
|
+
if (!footnoteLabels.has(label)) {
|
|
4944
|
+
return null;
|
|
4945
|
+
}
|
|
4946
|
+
return {
|
|
4947
|
+
node: { type: "footnoteReference", label },
|
|
4948
|
+
end: labelEnd + 1
|
|
4949
|
+
};
|
|
4950
|
+
}
|
|
4951
|
+
function parseLiteralAutolink(input, start) {
|
|
4952
|
+
if (!isLiteralAutolinkBoundaryBefore(input, start)) {
|
|
4953
|
+
return null;
|
|
4954
|
+
}
|
|
4955
|
+
const urlLiteral = parseLiteralUrlAutolink(input, start);
|
|
4956
|
+
if (urlLiteral !== null) {
|
|
4957
|
+
return createLiteralAutolinkNode(urlLiteral.text, urlLiteral.url, urlLiteral.end);
|
|
4958
|
+
}
|
|
4959
|
+
const wwwLiteral = parseLiteralWwwAutolink(input, start);
|
|
4960
|
+
if (wwwLiteral !== null) {
|
|
4961
|
+
return createLiteralAutolinkNode(wwwLiteral.text, `http://${wwwLiteral.text}`, wwwLiteral.end);
|
|
4962
|
+
}
|
|
4963
|
+
const emailLiteral = parseLiteralEmailAutolink(input, start);
|
|
4964
|
+
if (emailLiteral !== null) {
|
|
4965
|
+
return createLiteralAutolinkNode(
|
|
4966
|
+
emailLiteral.text,
|
|
4967
|
+
`mailto:${emailLiteral.text}`,
|
|
4968
|
+
emailLiteral.end
|
|
4969
|
+
);
|
|
4970
|
+
}
|
|
4971
|
+
return null;
|
|
4972
|
+
}
|
|
4973
|
+
function createLiteralAutolinkNode(text4, url, end) {
|
|
4974
|
+
return {
|
|
4975
|
+
node: {
|
|
4976
|
+
type: "link",
|
|
4977
|
+
url,
|
|
4978
|
+
children: [{ type: "text", value: text4 }]
|
|
4979
|
+
},
|
|
4980
|
+
end
|
|
4981
|
+
};
|
|
4982
|
+
}
|
|
4983
|
+
function parseLiteralUrlAutolink(input, start) {
|
|
4984
|
+
const hasHttp = input.startsWith("http://", start);
|
|
4985
|
+
const hasHttps = input.startsWith("https://", start);
|
|
4986
|
+
if (!hasHttp && !hasHttps) {
|
|
4987
|
+
return null;
|
|
4988
|
+
}
|
|
4989
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
4990
|
+
const text4 = trimLiteralAutolinkText(input.slice(start, end));
|
|
4991
|
+
const prefixLength = hasHttps ? "https://".length : "http://".length;
|
|
4992
|
+
if (text4.length <= prefixLength) {
|
|
4993
|
+
return null;
|
|
4994
|
+
}
|
|
4995
|
+
return { text: text4, url: text4, end: start + text4.length };
|
|
4996
|
+
}
|
|
4997
|
+
function parseLiteralWwwAutolink(input, start) {
|
|
4998
|
+
if (!input.startsWith("www.", start)) {
|
|
4999
|
+
return null;
|
|
5000
|
+
}
|
|
5001
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
5002
|
+
const text4 = trimLiteralAutolinkText(input.slice(start, end));
|
|
5003
|
+
if (!hasDotAfterPrefix(text4, 4)) {
|
|
5004
|
+
return null;
|
|
5005
|
+
}
|
|
5006
|
+
return { text: text4, end: start + text4.length };
|
|
5007
|
+
}
|
|
5008
|
+
function parseLiteralEmailAutolink(input, start) {
|
|
5009
|
+
if (!isEmailLocalPartChar(input[start] ?? "")) {
|
|
5010
|
+
return null;
|
|
5011
|
+
}
|
|
5012
|
+
const end = scanLiteralAutolinkEnd(input, start);
|
|
5013
|
+
const text4 = trimLiteralAutolinkText(input.slice(start, end));
|
|
5014
|
+
if (!isValidLiteralEmail(text4)) {
|
|
5015
|
+
return null;
|
|
5016
|
+
}
|
|
5017
|
+
return { text: text4, end: start + text4.length };
|
|
5018
|
+
}
|
|
5019
|
+
function parseInlineHtmlTag(input, start) {
|
|
5020
|
+
if (input[start] !== "<") {
|
|
5021
|
+
return null;
|
|
5022
|
+
}
|
|
5023
|
+
let index = start + 1;
|
|
5024
|
+
let closing = false;
|
|
5025
|
+
if (index < input.length && input[index] === "/") {
|
|
5026
|
+
closing = true;
|
|
5027
|
+
index += 1;
|
|
5028
|
+
}
|
|
5029
|
+
if (index >= input.length || !isAsciiLetter(input[index])) {
|
|
5030
|
+
return null;
|
|
5031
|
+
}
|
|
5032
|
+
index += 1;
|
|
5033
|
+
while (index < input.length && isHtmlTagNameChar(input[index])) {
|
|
5034
|
+
index += 1;
|
|
5035
|
+
}
|
|
5036
|
+
const tagName = input.slice(start + (closing ? 2 : 1), index).toLowerCase();
|
|
5037
|
+
if (!INLINE_HTML_TAGS.has(tagName)) {
|
|
5038
|
+
return null;
|
|
5039
|
+
}
|
|
5040
|
+
if (closing) {
|
|
5041
|
+
index = skipHtmlWhitespace(input, index);
|
|
5042
|
+
if (index >= input.length || input[index] !== ">") {
|
|
5043
|
+
return null;
|
|
5044
|
+
}
|
|
5045
|
+
return {
|
|
5046
|
+
node: { type: "html", value: input.slice(start, index + 1) },
|
|
5047
|
+
end: index + 1
|
|
5048
|
+
};
|
|
5049
|
+
}
|
|
5050
|
+
while (index < input.length) {
|
|
5051
|
+
index = skipHtmlWhitespace(input, index);
|
|
5052
|
+
if (index >= input.length) {
|
|
5053
|
+
return null;
|
|
5054
|
+
}
|
|
5055
|
+
if (input[index] === ">") {
|
|
5056
|
+
return {
|
|
5057
|
+
node: { type: "html", value: input.slice(start, index + 1) },
|
|
5058
|
+
end: index + 1
|
|
5059
|
+
};
|
|
5060
|
+
}
|
|
5061
|
+
if (input[index] === "/") {
|
|
5062
|
+
const selfClosingEnd = skipHtmlWhitespace(input, index + 1);
|
|
5063
|
+
if (selfClosingEnd >= input.length || input[selfClosingEnd] !== ">") {
|
|
5064
|
+
return null;
|
|
5065
|
+
}
|
|
5066
|
+
return {
|
|
5067
|
+
node: { type: "html", value: input.slice(start, selfClosingEnd + 1) },
|
|
5068
|
+
end: selfClosingEnd + 1
|
|
5069
|
+
};
|
|
5070
|
+
}
|
|
5071
|
+
if (!isHtmlAttributeNameStartChar(input[index])) {
|
|
5072
|
+
return null;
|
|
5073
|
+
}
|
|
5074
|
+
index += 1;
|
|
5075
|
+
while (index < input.length && isHtmlAttributeNameChar(input[index])) {
|
|
5076
|
+
index += 1;
|
|
5077
|
+
}
|
|
5078
|
+
index = skipHtmlWhitespace(input, index);
|
|
5079
|
+
if (index >= input.length || input[index] !== "=") {
|
|
5080
|
+
continue;
|
|
5081
|
+
}
|
|
5082
|
+
index = skipHtmlWhitespace(input, index + 1);
|
|
5083
|
+
if (index >= input.length) {
|
|
5084
|
+
return null;
|
|
5085
|
+
}
|
|
5086
|
+
const quote = input[index];
|
|
5087
|
+
if (quote === '"' || quote === "'") {
|
|
5088
|
+
index += 1;
|
|
5089
|
+
while (index < input.length && input[index] !== quote) {
|
|
5090
|
+
index += 1;
|
|
5091
|
+
}
|
|
5092
|
+
if (index >= input.length) {
|
|
5093
|
+
return null;
|
|
5094
|
+
}
|
|
5095
|
+
index += 1;
|
|
5096
|
+
continue;
|
|
5097
|
+
}
|
|
5098
|
+
while (index < input.length && !isHtmlWhitespace(input[index]) && input[index] !== ">") {
|
|
5099
|
+
const char = input[index];
|
|
5100
|
+
if (char === '"' || char === "'" || char === "<" || char === "=" || char === "`") {
|
|
5101
|
+
return null;
|
|
5102
|
+
}
|
|
5103
|
+
index += 1;
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
return null;
|
|
5107
|
+
}
|
|
5108
|
+
function decodeEscapes(value) {
|
|
5109
|
+
let result = "";
|
|
5110
|
+
let index = 0;
|
|
5111
|
+
while (index < value.length) {
|
|
5112
|
+
if (value[index] === "\\" && index + 1 < value.length && isEscapable(value[index + 1])) {
|
|
5113
|
+
result += value[index + 1];
|
|
5114
|
+
index += 2;
|
|
5115
|
+
continue;
|
|
5116
|
+
}
|
|
5117
|
+
result += value[index];
|
|
5118
|
+
index += 1;
|
|
5119
|
+
}
|
|
5120
|
+
return result;
|
|
5121
|
+
}
|
|
5122
|
+
function findTrailingHardBreakSpaceStart(value) {
|
|
5123
|
+
let start = value.length;
|
|
5124
|
+
while (start > 0 && (value[start - 1] === " " || value[start - 1] === " ")) {
|
|
5125
|
+
start -= 1;
|
|
5126
|
+
}
|
|
5127
|
+
return value.length - start >= 2 ? start : -1;
|
|
5128
|
+
}
|
|
5129
|
+
function readRunLength(input, start, char) {
|
|
5130
|
+
let index = start;
|
|
5131
|
+
while (index < input.length && input[index] === char) {
|
|
5132
|
+
index += 1;
|
|
5133
|
+
}
|
|
5134
|
+
return index - start;
|
|
5135
|
+
}
|
|
5136
|
+
function trimAsciiWhitespace2(value) {
|
|
5137
|
+
const start = trimAsciiWhitespaceStartIndex(value);
|
|
5138
|
+
const end = trimAsciiWhitespaceEndIndex(value);
|
|
5139
|
+
return value.slice(start, end);
|
|
5140
|
+
}
|
|
5141
|
+
function trimAsciiWhitespaceStartIndex(value) {
|
|
5142
|
+
let index = 0;
|
|
5143
|
+
while (index < value.length && isAsciiWhitespace(value[index])) {
|
|
5144
|
+
index += 1;
|
|
5145
|
+
}
|
|
5146
|
+
return index;
|
|
5147
|
+
}
|
|
5148
|
+
function trimAsciiWhitespaceEndIndex(value) {
|
|
5149
|
+
let index = value.length;
|
|
5150
|
+
while (index > 0 && isAsciiWhitespace(value[index - 1])) {
|
|
5151
|
+
index -= 1;
|
|
5152
|
+
}
|
|
5153
|
+
return index;
|
|
5154
|
+
}
|
|
5155
|
+
function isAutolinkUrl(value) {
|
|
5156
|
+
if (value.length < 3 || !isAsciiLetter(value[0])) {
|
|
5157
|
+
return false;
|
|
5158
|
+
}
|
|
5159
|
+
let index = 1;
|
|
5160
|
+
while (index < value.length) {
|
|
5161
|
+
const char = value[index];
|
|
5162
|
+
if (char === ":") {
|
|
5163
|
+
return index >= 2;
|
|
5164
|
+
}
|
|
5165
|
+
if (!isAsciiLetter(char) && !isDigit(char) && char !== "+" && char !== "." && char !== "-") {
|
|
5166
|
+
return false;
|
|
5167
|
+
}
|
|
5168
|
+
index += 1;
|
|
5169
|
+
}
|
|
5170
|
+
return false;
|
|
5171
|
+
}
|
|
5172
|
+
function scanLiteralAutolinkEnd(input, start) {
|
|
5173
|
+
let index = start;
|
|
5174
|
+
while (index < input.length) {
|
|
5175
|
+
const char = input[index];
|
|
5176
|
+
if (char === "\n" || isAsciiWhitespace(char) || char === "<") {
|
|
5177
|
+
break;
|
|
5178
|
+
}
|
|
5179
|
+
index += 1;
|
|
5180
|
+
}
|
|
5181
|
+
return index;
|
|
5182
|
+
}
|
|
5183
|
+
function trimLiteralAutolinkText(value) {
|
|
5184
|
+
let end = value.length;
|
|
5185
|
+
while (end > 0) {
|
|
5186
|
+
const lastChar = value[end - 1];
|
|
5187
|
+
if (lastChar === "." || lastChar === "," || lastChar === ":" || lastChar === ";" || lastChar === "!" || lastChar === "?") {
|
|
5188
|
+
end -= 1;
|
|
5189
|
+
continue;
|
|
5190
|
+
}
|
|
5191
|
+
if (lastChar === ")" && hasMoreClosersThanOpeners(value.slice(0, end), "(", ")") || lastChar === "]" && hasMoreClosersThanOpeners(value.slice(0, end), "[", "]") || lastChar === "}" && hasMoreClosersThanOpeners(value.slice(0, end), "{", "}")) {
|
|
5192
|
+
end -= 1;
|
|
5193
|
+
continue;
|
|
5194
|
+
}
|
|
5195
|
+
break;
|
|
5196
|
+
}
|
|
5197
|
+
return value.slice(0, end);
|
|
5198
|
+
}
|
|
5199
|
+
function hasMoreClosersThanOpeners(value, opener, closer) {
|
|
5200
|
+
let balance = 0;
|
|
5201
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
5202
|
+
if (value[index] === opener) {
|
|
5203
|
+
balance += 1;
|
|
5204
|
+
continue;
|
|
5205
|
+
}
|
|
5206
|
+
if (value[index] === closer) {
|
|
5207
|
+
balance -= 1;
|
|
5208
|
+
}
|
|
5209
|
+
}
|
|
5210
|
+
return balance < 0;
|
|
5211
|
+
}
|
|
5212
|
+
function isLiteralAutolinkBoundaryBefore(input, start) {
|
|
5213
|
+
if (start === 0) {
|
|
5214
|
+
return true;
|
|
5215
|
+
}
|
|
5216
|
+
const previous = input[start - 1];
|
|
5217
|
+
if (previous === "(" && start >= 2 && input[start - 2] === "]") {
|
|
5218
|
+
return false;
|
|
5219
|
+
}
|
|
5220
|
+
return !isAsciiLetter(previous) && !isDigit(previous) && previous !== "_" && previous !== "." && previous !== "+" && previous !== "-" && previous !== "@" && previous !== "/";
|
|
5221
|
+
}
|
|
5222
|
+
function hasDotAfterPrefix(value, prefixLength) {
|
|
5223
|
+
if (value.length <= prefixLength) {
|
|
5224
|
+
return false;
|
|
5225
|
+
}
|
|
5226
|
+
for (let index = prefixLength; index < value.length; index += 1) {
|
|
5227
|
+
if (value[index] === ".") {
|
|
5228
|
+
return true;
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
return false;
|
|
5232
|
+
}
|
|
5233
|
+
function isValidLiteralEmail(value) {
|
|
5234
|
+
const atIndex = value.indexOf("@");
|
|
5235
|
+
if (atIndex <= 0 || atIndex === value.length - 1 || value.indexOf("@", atIndex + 1) !== -1) {
|
|
5236
|
+
return false;
|
|
5237
|
+
}
|
|
5238
|
+
const localPart = value.slice(0, atIndex);
|
|
5239
|
+
const domain = value.slice(atIndex + 1);
|
|
5240
|
+
if (domain[0] === "." || domain[domain.length - 1] === "." || !hasDotAfterPrefix(domain, 0)) {
|
|
5241
|
+
return false;
|
|
5242
|
+
}
|
|
5243
|
+
for (let index = 0; index < localPart.length; index += 1) {
|
|
5244
|
+
if (!isEmailLocalPartChar(localPart[index])) {
|
|
5245
|
+
return false;
|
|
5246
|
+
}
|
|
5247
|
+
}
|
|
5248
|
+
for (let index = 0; index < domain.length; index += 1) {
|
|
5249
|
+
if (!isEmailDomainChar(domain[index])) {
|
|
5250
|
+
return false;
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
return true;
|
|
5254
|
+
}
|
|
5255
|
+
function isEscaped(value, index) {
|
|
5256
|
+
let slashCount = 0;
|
|
5257
|
+
let cursor = index - 1;
|
|
5258
|
+
while (cursor >= 0 && value[cursor] === "\\") {
|
|
5259
|
+
slashCount += 1;
|
|
5260
|
+
cursor -= 1;
|
|
5261
|
+
}
|
|
5262
|
+
return slashCount % 2 === 1;
|
|
5263
|
+
}
|
|
5264
|
+
function skipHtmlWhitespace(value, start) {
|
|
5265
|
+
let index = start;
|
|
5266
|
+
while (index < value.length && isHtmlWhitespace(value[index])) {
|
|
5267
|
+
index += 1;
|
|
5268
|
+
}
|
|
5269
|
+
return index;
|
|
5270
|
+
}
|
|
5271
|
+
function isEscapable(value) {
|
|
5272
|
+
return value === "!" || value === '"' || value === "#" || value === "$" || value === "%" || value === "&" || value === "'" || value === "(" || value === ")" || value === "*" || value === "+" || value === "," || value === "-" || value === "." || value === "/" || value === ":" || value === ";" || value === "<" || value === "=" || value === ">" || value === "?" || value === "@" || value === "[" || value === "\\" || value === "]" || value === "^" || value === "_" || value === "`" || value === "{" || value === "|" || value === "}" || value === "~";
|
|
5273
|
+
}
|
|
5274
|
+
function isAsciiWhitespace(value) {
|
|
5275
|
+
return value === " " || value === " ";
|
|
5276
|
+
}
|
|
5277
|
+
function isDelimiterWhitespace(value) {
|
|
5278
|
+
return value === null || /\s/u.test(value);
|
|
5279
|
+
}
|
|
5280
|
+
function isDelimiterPunctuation(value) {
|
|
5281
|
+
return value !== null && /[\p{P}\p{S}]/u.test(value);
|
|
5282
|
+
}
|
|
5283
|
+
function isHtmlWhitespace(value) {
|
|
5284
|
+
return value === " " || value === " ";
|
|
5285
|
+
}
|
|
5286
|
+
function isAsciiLetter(value) {
|
|
5287
|
+
return value >= "a" && value <= "z" || value >= "A" && value <= "Z";
|
|
5288
|
+
}
|
|
5289
|
+
function isDigit(value) {
|
|
5290
|
+
return value >= "0" && value <= "9";
|
|
5291
|
+
}
|
|
5292
|
+
function isEmailLocalPartChar(value) {
|
|
5293
|
+
return isAsciiLetter(value) || isDigit(value) || value === "." || value === "_" || value === "%" || value === "+" || value === "-";
|
|
5294
|
+
}
|
|
5295
|
+
function isEmailDomainChar(value) {
|
|
5296
|
+
return isAsciiLetter(value) || isDigit(value) || value === "." || value === "-";
|
|
5297
|
+
}
|
|
5298
|
+
function isFootnoteLabelChar(value) {
|
|
5299
|
+
return isAsciiLetter(value) || isDigit(value) || value === "-" || value === "_";
|
|
5300
|
+
}
|
|
5301
|
+
function isHtmlTagNameChar(value) {
|
|
5302
|
+
return isAsciiLetter(value) || isDigit(value) || value === "-";
|
|
5303
|
+
}
|
|
5304
|
+
function isHtmlAttributeNameStartChar(value) {
|
|
5305
|
+
return isAsciiLetter(value) || value === ":" || value === "_";
|
|
5306
|
+
}
|
|
5307
|
+
function isHtmlAttributeNameChar(value) {
|
|
5308
|
+
return isHtmlAttributeNameStartChar(value) || isDigit(value) || value === "-" || value === ".";
|
|
5309
|
+
}
|
|
5310
|
+
var INLINE_HTML_TAGS;
|
|
5311
|
+
var init_inline = __esm({
|
|
5312
|
+
"packages/design-system/src/terminal-markdown/parser/inline.ts"() {
|
|
5313
|
+
"use strict";
|
|
5314
|
+
INLINE_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
5315
|
+
"a",
|
|
5316
|
+
"abbr",
|
|
5317
|
+
"address",
|
|
5318
|
+
"article",
|
|
5319
|
+
"aside",
|
|
5320
|
+
"b",
|
|
5321
|
+
"base",
|
|
5322
|
+
"basefont",
|
|
5323
|
+
"bdi",
|
|
5324
|
+
"bdo",
|
|
5325
|
+
"blockquote",
|
|
5326
|
+
"body",
|
|
5327
|
+
"br",
|
|
5328
|
+
"button",
|
|
5329
|
+
"caption",
|
|
5330
|
+
"center",
|
|
5331
|
+
"cite",
|
|
5332
|
+
"code",
|
|
5333
|
+
"col",
|
|
5334
|
+
"colgroup",
|
|
5335
|
+
"data",
|
|
5336
|
+
"dd",
|
|
5337
|
+
"del",
|
|
5338
|
+
"details",
|
|
5339
|
+
"dfn",
|
|
5340
|
+
"dialog",
|
|
5341
|
+
"div",
|
|
5342
|
+
"dl",
|
|
5343
|
+
"dt",
|
|
5344
|
+
"em",
|
|
5345
|
+
"fieldset",
|
|
5346
|
+
"figcaption",
|
|
5347
|
+
"figure",
|
|
5348
|
+
"footer",
|
|
5349
|
+
"form",
|
|
5350
|
+
"h1",
|
|
5351
|
+
"h2",
|
|
5352
|
+
"h3",
|
|
5353
|
+
"h4",
|
|
5354
|
+
"h5",
|
|
5355
|
+
"h6",
|
|
5356
|
+
"head",
|
|
5357
|
+
"header",
|
|
5358
|
+
"hr",
|
|
5359
|
+
"html",
|
|
5360
|
+
"i",
|
|
5361
|
+
"img",
|
|
5362
|
+
"input",
|
|
5363
|
+
"ins",
|
|
5364
|
+
"kbd",
|
|
5365
|
+
"label",
|
|
5366
|
+
"legend",
|
|
5367
|
+
"li",
|
|
5368
|
+
"link",
|
|
5369
|
+
"main",
|
|
5370
|
+
"mark",
|
|
5371
|
+
"menu",
|
|
5372
|
+
"nav",
|
|
5373
|
+
"ol",
|
|
5374
|
+
"option",
|
|
5375
|
+
"p",
|
|
5376
|
+
"param",
|
|
5377
|
+
"pre",
|
|
5378
|
+
"q",
|
|
5379
|
+
"rp",
|
|
5380
|
+
"rt",
|
|
5381
|
+
"rtc",
|
|
5382
|
+
"ruby",
|
|
5383
|
+
"s",
|
|
5384
|
+
"samp",
|
|
5385
|
+
"search",
|
|
5386
|
+
"section",
|
|
5387
|
+
"small",
|
|
5388
|
+
"span",
|
|
5389
|
+
"strong",
|
|
5390
|
+
"sub",
|
|
5391
|
+
"summary",
|
|
5392
|
+
"sup",
|
|
5393
|
+
"table",
|
|
5394
|
+
"tbody",
|
|
5395
|
+
"td",
|
|
5396
|
+
"tfoot",
|
|
5397
|
+
"th",
|
|
5398
|
+
"thead",
|
|
5399
|
+
"time",
|
|
5400
|
+
"title",
|
|
5401
|
+
"tr",
|
|
5402
|
+
"u",
|
|
5403
|
+
"ul",
|
|
5404
|
+
"var",
|
|
5405
|
+
"wbr"
|
|
5406
|
+
]);
|
|
5407
|
+
}
|
|
5408
|
+
});
|
|
5409
|
+
|
|
5410
|
+
// packages/design-system/src/terminal-markdown/parser/block.ts
|
|
5411
|
+
function parseBlockDocument(input) {
|
|
5412
|
+
const { frontmatter, body } = extractFrontmatter(input);
|
|
5413
|
+
const children = applyInlineParsing(
|
|
5414
|
+
parseBlocksWithOptions(body, { preferListToThematicBreak: false })
|
|
5415
|
+
);
|
|
5416
|
+
return frontmatter === void 0 ? { children } : { frontmatter, children };
|
|
5417
|
+
}
|
|
5418
|
+
function parseBlocksWithOptions(input, options) {
|
|
5419
|
+
const state = {
|
|
5420
|
+
input: stripBom2(input),
|
|
5421
|
+
position: 0,
|
|
5422
|
+
preferListToThematicBreak: options.preferListToThematicBreak
|
|
5423
|
+
};
|
|
5424
|
+
const blocks = [];
|
|
5425
|
+
const rules = createBlockRules(state.preferListToThematicBreak);
|
|
5426
|
+
while (state.position < state.input.length) {
|
|
5427
|
+
const line = readLine2(state.input, state.position);
|
|
5428
|
+
if (isBlankLine(line.text)) {
|
|
5429
|
+
state.position = line.nextPosition;
|
|
5430
|
+
continue;
|
|
5431
|
+
}
|
|
5432
|
+
let matchedNode = null;
|
|
5433
|
+
for (const rule of rules) {
|
|
5434
|
+
matchedNode = rule(state);
|
|
5435
|
+
if (matchedNode !== null) {
|
|
5436
|
+
blocks.push(matchedNode);
|
|
5437
|
+
break;
|
|
5438
|
+
}
|
|
5439
|
+
}
|
|
5440
|
+
if (matchedNode !== null) {
|
|
5441
|
+
continue;
|
|
5442
|
+
}
|
|
5443
|
+
blocks.push(parseParagraph(state));
|
|
5444
|
+
}
|
|
5445
|
+
return blocks;
|
|
5446
|
+
}
|
|
5447
|
+
function applyInlineParsing(nodes) {
|
|
5448
|
+
const footnoteLabels = collectFootnoteLabels(nodes);
|
|
5449
|
+
return nodes.map((node) => applyInlineParsingToNode(node, footnoteLabels));
|
|
5450
|
+
}
|
|
5451
|
+
function collectFootnoteLabels(nodes) {
|
|
5452
|
+
const labels = /* @__PURE__ */ new Set();
|
|
5453
|
+
for (const node of nodes) {
|
|
5454
|
+
collectFootnoteLabelsFromNode(node, labels);
|
|
5455
|
+
}
|
|
5456
|
+
return labels;
|
|
5457
|
+
}
|
|
5458
|
+
function collectFootnoteLabelsFromNode(node, labels) {
|
|
5459
|
+
if (node.type === "footnoteDefinition") {
|
|
5460
|
+
labels.add(node.label);
|
|
5461
|
+
}
|
|
5462
|
+
if (hasBlockChildren(node)) {
|
|
5463
|
+
for (const child of node.children) {
|
|
5464
|
+
collectFootnoteLabelsFromNode(child, labels);
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5467
|
+
}
|
|
5468
|
+
function applyInlineParsingToNode(node, footnoteLabels) {
|
|
5469
|
+
if (node.type === "paragraph" || node.type === "heading" || node.type === "tableCell") {
|
|
5470
|
+
return {
|
|
5471
|
+
...node,
|
|
5472
|
+
children: applyInlineParsingToTextChildren(node.children, footnoteLabels)
|
|
5473
|
+
};
|
|
5474
|
+
}
|
|
5475
|
+
if (hasBlockChildren(node)) {
|
|
5476
|
+
return {
|
|
5477
|
+
...node,
|
|
5478
|
+
children: node.children.map((child) => applyInlineParsingToNode(child, footnoteLabels))
|
|
5479
|
+
};
|
|
5480
|
+
}
|
|
5481
|
+
return node;
|
|
5482
|
+
}
|
|
5483
|
+
function applyInlineParsingToTextChildren(children, footnoteLabels) {
|
|
5484
|
+
let rawText = "";
|
|
5485
|
+
for (const child of children) {
|
|
5486
|
+
if (child.type !== "text") {
|
|
5487
|
+
return children;
|
|
5488
|
+
}
|
|
5489
|
+
rawText += child.value;
|
|
5490
|
+
}
|
|
5491
|
+
return parseInline(rawText, { footnoteLabels });
|
|
5492
|
+
}
|
|
5493
|
+
function hasBlockChildren(node) {
|
|
5494
|
+
return node.type === "root" || node.type === "blockquote" || node.type === "list" || node.type === "listItem" || node.type === "table" || node.type === "tableRow" || node.type === "alert" || node.type === "footnoteDefinition";
|
|
5495
|
+
}
|
|
5496
|
+
function createBlockRules(preferListToThematicBreak) {
|
|
5497
|
+
const middleRules = preferListToThematicBreak ? [parseAlert, parseBlockquote, parseList, parseHtmlBlock, parseThematicBreak] : [parseThematicBreak, parseAlert, parseBlockquote, parseList, parseHtmlBlock];
|
|
5498
|
+
return [
|
|
5499
|
+
parseFencedCodeBlock,
|
|
5500
|
+
parseAtxHeading,
|
|
5501
|
+
...middleRules,
|
|
5502
|
+
parseTable,
|
|
5503
|
+
parseFootnoteDefinition,
|
|
5504
|
+
parseSetextHeading
|
|
5505
|
+
];
|
|
5506
|
+
}
|
|
5507
|
+
function parseFencedCodeBlock(state) {
|
|
5508
|
+
const openingLine = readLine2(state.input, state.position);
|
|
5509
|
+
const fence = parseOpeningFence(openingLine.text);
|
|
5510
|
+
if (fence === null) {
|
|
5511
|
+
return null;
|
|
5512
|
+
}
|
|
5513
|
+
state.position = openingLine.nextPosition;
|
|
5514
|
+
const contentLines = [];
|
|
5515
|
+
while (state.position < state.input.length) {
|
|
5516
|
+
const line = readLine2(state.input, state.position);
|
|
5517
|
+
if (isClosingFence(line.text, fence)) {
|
|
5518
|
+
state.position = line.nextPosition;
|
|
5519
|
+
return createCodeNode(fence, contentLines);
|
|
5520
|
+
}
|
|
5521
|
+
contentLines.push(line.text);
|
|
5522
|
+
state.position = line.nextPosition;
|
|
5523
|
+
}
|
|
5524
|
+
return createCodeNode(fence, contentLines);
|
|
5525
|
+
}
|
|
5526
|
+
function parseAtxHeading(state) {
|
|
5527
|
+
const line = readLine2(state.input, state.position);
|
|
5528
|
+
const heading = parseAtxHeadingLine(line.text);
|
|
5529
|
+
if (heading === null) {
|
|
5530
|
+
return null;
|
|
5531
|
+
}
|
|
5532
|
+
state.position = line.nextPosition;
|
|
5533
|
+
return {
|
|
5534
|
+
type: "heading",
|
|
5535
|
+
depth: heading.depth,
|
|
5536
|
+
children: createTextChildren(heading.text)
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
function parseThematicBreak(state) {
|
|
5540
|
+
const line = readLine2(state.input, state.position);
|
|
5541
|
+
if (!isThematicBreakLine(line.text)) {
|
|
5542
|
+
return null;
|
|
5543
|
+
}
|
|
5544
|
+
state.position = line.nextPosition;
|
|
5545
|
+
return { type: "thematicBreak" };
|
|
5546
|
+
}
|
|
5547
|
+
function parseSetextHeading(state) {
|
|
5548
|
+
const contentLine = readLine2(state.input, state.position);
|
|
5549
|
+
if (isBlankLine(contentLine.text)) {
|
|
5550
|
+
return null;
|
|
5551
|
+
}
|
|
5552
|
+
if (contentLine.nextPosition >= state.input.length) {
|
|
5553
|
+
return null;
|
|
5554
|
+
}
|
|
5555
|
+
const underlineLine = readLine2(state.input, contentLine.nextPosition);
|
|
5556
|
+
const depth = parseSetextUnderline(underlineLine.text);
|
|
5557
|
+
if (depth === null) {
|
|
5558
|
+
return null;
|
|
5559
|
+
}
|
|
5560
|
+
state.position = underlineLine.nextPosition;
|
|
5561
|
+
return {
|
|
5562
|
+
type: "heading",
|
|
5563
|
+
depth,
|
|
5564
|
+
children: createTextChildren(trimAsciiWhitespace3(contentLine.text))
|
|
5565
|
+
};
|
|
5566
|
+
}
|
|
5567
|
+
function parseBlockquote(state) {
|
|
5568
|
+
const firstLine = readLine2(state.input, state.position);
|
|
5569
|
+
if (stripBlockquoteMarker(firstLine.text) === null) {
|
|
5570
|
+
return null;
|
|
5571
|
+
}
|
|
5572
|
+
const contentLines = [];
|
|
5573
|
+
while (state.position < state.input.length) {
|
|
5574
|
+
const line = readLine2(state.input, state.position);
|
|
5575
|
+
const content = stripBlockquoteMarker(line.text);
|
|
5576
|
+
if (content === null) {
|
|
5577
|
+
break;
|
|
5578
|
+
}
|
|
5579
|
+
contentLines.push(content);
|
|
5580
|
+
state.position = line.nextPosition;
|
|
5581
|
+
}
|
|
5582
|
+
return {
|
|
5583
|
+
type: "blockquote",
|
|
5584
|
+
children: parseBlocksWithOptions(contentLines.join("\n"), {
|
|
5585
|
+
preferListToThematicBreak: state.preferListToThematicBreak
|
|
5586
|
+
})
|
|
5587
|
+
};
|
|
5588
|
+
}
|
|
5589
|
+
function parseAlert(state) {
|
|
5590
|
+
const firstLine = readLine2(state.input, state.position);
|
|
5591
|
+
const firstLineContent = stripBlockquoteMarker(firstLine.text);
|
|
5592
|
+
if (firstLineContent === null) {
|
|
5593
|
+
return null;
|
|
5594
|
+
}
|
|
5595
|
+
const alertMarker = parseAlertMarker(firstLineContent);
|
|
5596
|
+
if (alertMarker === null) {
|
|
5597
|
+
return null;
|
|
5598
|
+
}
|
|
5599
|
+
state.position = firstLine.nextPosition;
|
|
5600
|
+
const contentLines = alertMarker.content.length === 0 ? [] : [alertMarker.content];
|
|
5601
|
+
while (state.position < state.input.length) {
|
|
5602
|
+
const line = readLine2(state.input, state.position);
|
|
5603
|
+
const content = stripBlockquoteMarker(line.text);
|
|
5604
|
+
if (content === null) {
|
|
5605
|
+
break;
|
|
5606
|
+
}
|
|
5607
|
+
contentLines.push(content);
|
|
5608
|
+
state.position = line.nextPosition;
|
|
5609
|
+
}
|
|
5610
|
+
return {
|
|
5611
|
+
type: "alert",
|
|
5612
|
+
kind: alertMarker.kind,
|
|
5613
|
+
children: parseBlocksWithOptions(contentLines.join("\n"), {
|
|
5614
|
+
preferListToThematicBreak: state.preferListToThematicBreak
|
|
5615
|
+
})
|
|
5616
|
+
};
|
|
5617
|
+
}
|
|
5618
|
+
function parseList(state) {
|
|
5619
|
+
const firstLine = readLine2(state.input, state.position);
|
|
5620
|
+
const firstMarker = parseListMarker(firstLine.text);
|
|
5621
|
+
if (firstMarker === null) {
|
|
5622
|
+
return null;
|
|
5623
|
+
}
|
|
5624
|
+
const children = [];
|
|
5625
|
+
const ordered = firstMarker.ordered;
|
|
5626
|
+
const start = firstMarker.start;
|
|
5627
|
+
const indent = firstMarker.indent;
|
|
5628
|
+
while (state.position < state.input.length) {
|
|
5629
|
+
const item = parseListItem(state, {
|
|
5630
|
+
ordered,
|
|
5631
|
+
indent,
|
|
5632
|
+
preferListToThematicBreak: true
|
|
5633
|
+
});
|
|
5634
|
+
if (item === null) {
|
|
5635
|
+
break;
|
|
5636
|
+
}
|
|
5637
|
+
children.push(item);
|
|
5638
|
+
}
|
|
5639
|
+
return {
|
|
5640
|
+
type: "list",
|
|
5641
|
+
ordered,
|
|
5642
|
+
...ordered && start !== void 0 ? { start } : {},
|
|
5643
|
+
children
|
|
5644
|
+
};
|
|
5645
|
+
}
|
|
5646
|
+
function parseTable(state) {
|
|
5647
|
+
const table = parseTableAt(state.input, state.position, state.preferListToThematicBreak);
|
|
5648
|
+
if (table === null) {
|
|
5649
|
+
return null;
|
|
5650
|
+
}
|
|
5651
|
+
state.position = table.nextPosition;
|
|
5652
|
+
return {
|
|
5653
|
+
type: "table",
|
|
5654
|
+
align: table.align,
|
|
5655
|
+
children: [
|
|
5656
|
+
createTableRowNode(table.headerCells),
|
|
5657
|
+
...table.rows.map((row) => createTableRowNode(row))
|
|
5658
|
+
]
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
function parseHtmlBlock(state) {
|
|
5662
|
+
const firstLine = readLine2(state.input, state.position);
|
|
5663
|
+
const openingTag = parseBlockHtmlTagStart(firstLine.text);
|
|
5664
|
+
if (openingTag === null) {
|
|
5665
|
+
return null;
|
|
5666
|
+
}
|
|
5667
|
+
state.position = firstLine.nextPosition;
|
|
5668
|
+
const lines = [firstLine.text];
|
|
5669
|
+
const isSelfContained = openingTag.closing || openingTag.selfClosing || VOID_BLOCK_HTML_TAGS.has(openingTag.tagName) || containsClosingHtmlTag(firstLine.text, openingTag.tagName, openingTag.tagEnd);
|
|
5670
|
+
if (!isSelfContained) {
|
|
5671
|
+
while (state.position < state.input.length) {
|
|
5672
|
+
const line = readLine2(state.input, state.position);
|
|
5673
|
+
lines.push(line.text);
|
|
5674
|
+
state.position = line.nextPosition;
|
|
5675
|
+
if (containsClosingHtmlTag(line.text, openingTag.tagName)) {
|
|
5676
|
+
break;
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
}
|
|
5680
|
+
return { type: "html", value: lines.join("\n") };
|
|
5681
|
+
}
|
|
5682
|
+
function parseFootnoteDefinition(state) {
|
|
5683
|
+
const firstLine = readLine2(state.input, state.position);
|
|
5684
|
+
const definition = parseFootnoteDefinitionMarker(firstLine.text);
|
|
5685
|
+
if (definition === null) {
|
|
5686
|
+
return null;
|
|
5687
|
+
}
|
|
5688
|
+
state.position = firstLine.nextPosition;
|
|
5689
|
+
const continuationLines = [];
|
|
5690
|
+
const pendingBlankLines = [];
|
|
5691
|
+
while (state.position < state.input.length) {
|
|
5692
|
+
const line = readLine2(state.input, state.position);
|
|
5693
|
+
if (isBlankLine(line.text)) {
|
|
5694
|
+
pendingBlankLines.push("");
|
|
5695
|
+
state.position = line.nextPosition;
|
|
5696
|
+
continue;
|
|
5697
|
+
}
|
|
5698
|
+
const strippedLine = stripIndent(line.text, 4);
|
|
5699
|
+
if (strippedLine === null) {
|
|
5700
|
+
break;
|
|
5701
|
+
}
|
|
5702
|
+
state.position = line.nextPosition;
|
|
5703
|
+
continuationLines.push(...pendingBlankLines, strippedLine);
|
|
5704
|
+
pendingBlankLines.length = 0;
|
|
5705
|
+
}
|
|
5706
|
+
return {
|
|
5707
|
+
type: "footnoteDefinition",
|
|
5708
|
+
label: definition.label,
|
|
5709
|
+
children: parseListItemChildren(
|
|
5710
|
+
firstLine.text.slice(definition.contentStart),
|
|
5711
|
+
continuationLines,
|
|
5712
|
+
state.preferListToThematicBreak
|
|
5713
|
+
)
|
|
5714
|
+
};
|
|
5715
|
+
}
|
|
5716
|
+
function parseParagraph(state) {
|
|
5717
|
+
const lines = [];
|
|
5718
|
+
while (state.position < state.input.length) {
|
|
5719
|
+
const line = readLine2(state.input, state.position);
|
|
5720
|
+
if (isBlankLine(line.text)) {
|
|
5721
|
+
break;
|
|
5722
|
+
}
|
|
5723
|
+
if (lines.length > 0 && startsBlockAt(state.input, state.position, state.preferListToThematicBreak)) {
|
|
5724
|
+
break;
|
|
5725
|
+
}
|
|
5726
|
+
lines.push(line.text);
|
|
5727
|
+
state.position = line.nextPosition;
|
|
5728
|
+
}
|
|
5729
|
+
return {
|
|
5730
|
+
type: "paragraph",
|
|
5731
|
+
children: [{ type: "text", value: lines.join("\n") }]
|
|
5732
|
+
};
|
|
5733
|
+
}
|
|
5734
|
+
function createCodeNode(fence, contentLines) {
|
|
5735
|
+
return {
|
|
5736
|
+
type: "code",
|
|
5737
|
+
...fence.lang === void 0 ? {} : { lang: fence.lang },
|
|
5738
|
+
...fence.meta === void 0 ? {} : { meta: fence.meta },
|
|
5739
|
+
value: contentLines.join("\n")
|
|
5740
|
+
};
|
|
5741
|
+
}
|
|
5742
|
+
function createTextChildren(value) {
|
|
5743
|
+
return value.length === 0 ? [] : [{ type: "text", value }];
|
|
5744
|
+
}
|
|
5745
|
+
function createTableRowNode(values) {
|
|
5746
|
+
return {
|
|
5747
|
+
type: "tableRow",
|
|
5748
|
+
children: values.map((value) => ({
|
|
5749
|
+
type: "tableCell",
|
|
5750
|
+
children: createTextChildren(value)
|
|
5751
|
+
}))
|
|
5752
|
+
};
|
|
5753
|
+
}
|
|
5754
|
+
function startsBlockAt(input, position, preferListToThematicBreak) {
|
|
5755
|
+
const line = readLine2(input, position);
|
|
5756
|
+
if (startsSimpleBlock(line.text, preferListToThematicBreak)) {
|
|
5757
|
+
return true;
|
|
5758
|
+
}
|
|
5759
|
+
if (line.nextPosition >= input.length) {
|
|
5760
|
+
return false;
|
|
5761
|
+
}
|
|
5762
|
+
const nextLine = readLine2(input, line.nextPosition);
|
|
5763
|
+
return parseTableHeaderAndSeparator(line.text, nextLine.text) !== null;
|
|
5764
|
+
}
|
|
5765
|
+
function startsBlockInLines(lines, lineIndex, preferListToThematicBreak) {
|
|
5766
|
+
const line = lines[lineIndex];
|
|
5767
|
+
if (startsSimpleBlock(line, preferListToThematicBreak)) {
|
|
5768
|
+
return true;
|
|
5769
|
+
}
|
|
5770
|
+
return lineIndex + 1 < lines.length && parseTableHeaderAndSeparator(line, lines[lineIndex + 1]) !== null;
|
|
5771
|
+
}
|
|
5772
|
+
function startsSimpleBlock(line, preferListToThematicBreak) {
|
|
5773
|
+
if (parseOpeningFence(line) !== null || parseAtxHeadingLine(line) !== null || parseBlockHtmlTagStart(line) !== null || parseFootnoteDefinitionMarker(line) !== null) {
|
|
5774
|
+
return true;
|
|
5775
|
+
}
|
|
5776
|
+
if (stripBlockquoteMarker(line) !== null) {
|
|
5777
|
+
return true;
|
|
5778
|
+
}
|
|
5779
|
+
if (preferListToThematicBreak) {
|
|
5780
|
+
return parseListMarker(line) !== null || isThematicBreakLine(line);
|
|
5781
|
+
}
|
|
5782
|
+
return isThematicBreakLine(line) || parseListMarker(line) !== null;
|
|
5783
|
+
}
|
|
5784
|
+
function parseOpeningFence(line) {
|
|
5785
|
+
const fenceStart = skipLeadingBlockIndent(line);
|
|
5786
|
+
if (fenceStart === -1 || fenceStart >= line.length) {
|
|
5787
|
+
return null;
|
|
5788
|
+
}
|
|
5789
|
+
const char = line[fenceStart];
|
|
5790
|
+
if (char !== "`" && char !== "~") {
|
|
5791
|
+
return null;
|
|
5792
|
+
}
|
|
5793
|
+
let fenceEnd = fenceStart;
|
|
5794
|
+
while (fenceEnd < line.length && line[fenceEnd] === char) {
|
|
5795
|
+
fenceEnd += 1;
|
|
5796
|
+
}
|
|
5797
|
+
const fenceLength = fenceEnd - fenceStart;
|
|
5798
|
+
if (fenceLength < 3) {
|
|
5799
|
+
return null;
|
|
5800
|
+
}
|
|
5801
|
+
const info2 = trimAsciiWhitespace3(line.slice(fenceEnd));
|
|
5802
|
+
if (info2.length === 0) {
|
|
5803
|
+
return { char, length: fenceLength };
|
|
5804
|
+
}
|
|
5805
|
+
const languageEnd = findWhitespaceIndex(info2);
|
|
5806
|
+
const lang = languageEnd === -1 ? info2 : info2.slice(0, languageEnd);
|
|
5807
|
+
const meta = languageEnd === -1 ? void 0 : trimAsciiWhitespaceStart2(info2.slice(languageEnd));
|
|
5808
|
+
return {
|
|
5809
|
+
char,
|
|
5810
|
+
length: fenceLength,
|
|
5811
|
+
lang,
|
|
5812
|
+
...meta === void 0 || meta.length === 0 ? {} : { meta }
|
|
5813
|
+
};
|
|
5814
|
+
}
|
|
5815
|
+
function parseAtxHeadingLine(line) {
|
|
5816
|
+
const markerStart = skipLeadingBlockIndent(line);
|
|
5817
|
+
if (markerStart === -1 || markerStart >= line.length || line[markerStart] !== "#") {
|
|
5818
|
+
return null;
|
|
5819
|
+
}
|
|
5820
|
+
let markerEnd = markerStart;
|
|
5821
|
+
while (markerEnd < line.length && line[markerEnd] === "#") {
|
|
5822
|
+
markerEnd += 1;
|
|
5823
|
+
}
|
|
5824
|
+
const depth = markerEnd - markerStart;
|
|
5825
|
+
if (depth < 1 || depth > 6) {
|
|
5826
|
+
return null;
|
|
5827
|
+
}
|
|
5828
|
+
if (markerEnd < line.length && line[markerEnd] !== " " && line[markerEnd] !== " ") {
|
|
5829
|
+
return null;
|
|
5830
|
+
}
|
|
5831
|
+
const rawContent = trimAsciiWhitespaceStart2(line.slice(markerEnd));
|
|
5832
|
+
return {
|
|
5833
|
+
depth,
|
|
5834
|
+
text: stripClosingHeadingSequence(rawContent)
|
|
5835
|
+
};
|
|
5836
|
+
}
|
|
5837
|
+
function stripClosingHeadingSequence(value) {
|
|
5838
|
+
const trimmedValue = trimAsciiWhitespaceEnd2(value);
|
|
5839
|
+
if (trimmedValue.length === 0) {
|
|
5840
|
+
return "";
|
|
5841
|
+
}
|
|
5842
|
+
let hashStart = trimmedValue.length;
|
|
5843
|
+
while (hashStart > 0 && trimmedValue[hashStart - 1] === "#") {
|
|
5844
|
+
hashStart -= 1;
|
|
5845
|
+
}
|
|
5846
|
+
if (hashStart === trimmedValue.length) {
|
|
5847
|
+
return trimmedValue;
|
|
5848
|
+
}
|
|
5849
|
+
if (hashStart === 0) {
|
|
5850
|
+
return "";
|
|
5851
|
+
}
|
|
5852
|
+
const prefixEnd = hashStart - 1;
|
|
5853
|
+
if (trimmedValue[prefixEnd] !== " " && trimmedValue[prefixEnd] !== " ") {
|
|
5854
|
+
return trimmedValue;
|
|
5855
|
+
}
|
|
5856
|
+
return trimAsciiWhitespaceEnd2(trimmedValue.slice(0, prefixEnd));
|
|
5857
|
+
}
|
|
5858
|
+
function isClosingFence(line, fence) {
|
|
5859
|
+
const fenceStart = skipLeadingBlockIndent(line);
|
|
5860
|
+
if (fenceStart === -1 || fenceStart >= line.length) {
|
|
5861
|
+
return false;
|
|
5862
|
+
}
|
|
5863
|
+
let index = fenceStart;
|
|
5864
|
+
while (index < line.length && line[index] === fence.char) {
|
|
5865
|
+
index += 1;
|
|
5866
|
+
}
|
|
5867
|
+
if (index - fenceStart < fence.length) {
|
|
5868
|
+
return false;
|
|
5869
|
+
}
|
|
5870
|
+
if (fenceStart === index) {
|
|
5871
|
+
return false;
|
|
5872
|
+
}
|
|
5873
|
+
for (let restIndex = index; restIndex < line.length; restIndex += 1) {
|
|
5874
|
+
const char = line[restIndex];
|
|
5875
|
+
if (char !== " " && char !== " ") {
|
|
5876
|
+
return false;
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5879
|
+
return true;
|
|
5880
|
+
}
|
|
5881
|
+
function isThematicBreakLine(line) {
|
|
5882
|
+
const start = skipLeadingBlockIndent(line);
|
|
5883
|
+
if (start === -1 || start >= line.length) {
|
|
5884
|
+
return false;
|
|
5885
|
+
}
|
|
5886
|
+
const marker = line[start];
|
|
5887
|
+
if (marker !== "-" && marker !== "*" && marker !== "_") {
|
|
5888
|
+
return false;
|
|
5889
|
+
}
|
|
5890
|
+
let markerCount = 0;
|
|
5891
|
+
for (let index = start; index < line.length; index += 1) {
|
|
5892
|
+
const char = line[index];
|
|
5893
|
+
if (char === marker) {
|
|
5894
|
+
markerCount += 1;
|
|
5895
|
+
continue;
|
|
5896
|
+
}
|
|
5897
|
+
if (char === " " || char === " ") {
|
|
5898
|
+
continue;
|
|
5899
|
+
}
|
|
5900
|
+
return false;
|
|
5901
|
+
}
|
|
5902
|
+
return markerCount >= 3;
|
|
5903
|
+
}
|
|
5904
|
+
function parseSetextUnderline(line) {
|
|
5905
|
+
const start = skipLeadingBlockIndent(line);
|
|
5906
|
+
if (start === -1 || start >= line.length) {
|
|
5907
|
+
return null;
|
|
5908
|
+
}
|
|
5909
|
+
const marker = line[start];
|
|
5910
|
+
if (marker !== "=" && marker !== "-") {
|
|
5911
|
+
return null;
|
|
5912
|
+
}
|
|
5913
|
+
let index = start;
|
|
5914
|
+
while (index < line.length && line[index] === marker) {
|
|
5915
|
+
index += 1;
|
|
5916
|
+
}
|
|
5917
|
+
const markerCount = index - start;
|
|
5918
|
+
if (markerCount === 0) {
|
|
5919
|
+
return null;
|
|
5920
|
+
}
|
|
5921
|
+
for (; index < line.length; index += 1) {
|
|
5922
|
+
const char = line[index];
|
|
5923
|
+
if (char !== " " && char !== " ") {
|
|
5924
|
+
return null;
|
|
5925
|
+
}
|
|
5926
|
+
}
|
|
5927
|
+
return marker === "=" ? 1 : 2;
|
|
5928
|
+
}
|
|
5929
|
+
function parseTableAt(input, position, preferListToThematicBreak) {
|
|
5930
|
+
const headerLine = readLine2(input, position);
|
|
5931
|
+
if (parseListMarker(headerLine.text) !== null || stripBlockquoteMarker(headerLine.text) !== null) {
|
|
5932
|
+
return null;
|
|
5933
|
+
}
|
|
5934
|
+
if (headerLine.nextPosition >= input.length) {
|
|
5935
|
+
return null;
|
|
5936
|
+
}
|
|
5937
|
+
const separatorLine = readLine2(input, headerLine.nextPosition);
|
|
5938
|
+
const header = parseTableHeaderAndSeparator(headerLine.text, separatorLine.text);
|
|
5939
|
+
if (header === null) {
|
|
5940
|
+
return null;
|
|
5941
|
+
}
|
|
5942
|
+
const rows = [];
|
|
5943
|
+
let nextPosition = separatorLine.nextPosition;
|
|
5944
|
+
while (nextPosition < input.length) {
|
|
5945
|
+
const rowLine = readLine2(input, nextPosition);
|
|
5946
|
+
if (isBlankLine(rowLine.text)) {
|
|
5947
|
+
break;
|
|
5948
|
+
}
|
|
5949
|
+
if (startsSimpleBlock(rowLine.text, preferListToThematicBreak)) {
|
|
5950
|
+
break;
|
|
5951
|
+
}
|
|
5952
|
+
const cells = parsePipeTableCells(rowLine.text);
|
|
5953
|
+
if (cells === null) {
|
|
5954
|
+
break;
|
|
5955
|
+
}
|
|
5956
|
+
rows.push(normalizeTableCells(cells, header.headerCells.length));
|
|
5957
|
+
nextPosition = rowLine.nextPosition;
|
|
5958
|
+
}
|
|
5959
|
+
return {
|
|
5960
|
+
align: header.align,
|
|
5961
|
+
headerCells: header.headerCells,
|
|
5962
|
+
rows,
|
|
5963
|
+
nextPosition
|
|
5964
|
+
};
|
|
5965
|
+
}
|
|
5966
|
+
function parseTableHeaderAndSeparator(headerLine, separatorLine) {
|
|
5967
|
+
const headerCells = parsePipeTableCells(headerLine);
|
|
5968
|
+
if (headerCells === null || headerCells.length === 0) {
|
|
5969
|
+
return null;
|
|
5970
|
+
}
|
|
5971
|
+
const align = parsePipeTableSeparator(separatorLine);
|
|
5972
|
+
if (align === null || align.length !== headerCells.length) {
|
|
5973
|
+
return null;
|
|
5974
|
+
}
|
|
5975
|
+
return { align, headerCells };
|
|
5976
|
+
}
|
|
5977
|
+
function parsePipeTableCells(line) {
|
|
5978
|
+
const start = skipLeadingBlockIndent(line);
|
|
5979
|
+
if (start === -1 || start >= line.length) {
|
|
5980
|
+
return null;
|
|
5981
|
+
}
|
|
5982
|
+
const content = trimAsciiWhitespaceEnd2(line.slice(start));
|
|
5983
|
+
let hasPipe = false;
|
|
5984
|
+
const cells = [];
|
|
5985
|
+
let cell = "";
|
|
5986
|
+
let index = 0;
|
|
5987
|
+
while (index < content.length) {
|
|
5988
|
+
const char = content[index];
|
|
5989
|
+
if (char === "\\" && index + 1 < content.length && content[index + 1] === "|") {
|
|
5990
|
+
cell += "|";
|
|
5991
|
+
index += 2;
|
|
5992
|
+
continue;
|
|
5993
|
+
}
|
|
5994
|
+
if (char === "|") {
|
|
5995
|
+
cells.push(trimAsciiWhitespace3(cell));
|
|
5996
|
+
cell = "";
|
|
5997
|
+
hasPipe = true;
|
|
5998
|
+
index += 1;
|
|
5999
|
+
continue;
|
|
6000
|
+
}
|
|
6001
|
+
cell += char;
|
|
6002
|
+
index += 1;
|
|
6003
|
+
}
|
|
6004
|
+
if (!hasPipe) {
|
|
6005
|
+
return null;
|
|
6006
|
+
}
|
|
6007
|
+
cells.push(trimAsciiWhitespace3(cell));
|
|
6008
|
+
if (content[0] === "|") {
|
|
6009
|
+
cells.shift();
|
|
6010
|
+
}
|
|
6011
|
+
if (content[content.length - 1] === "|") {
|
|
6012
|
+
cells.pop();
|
|
6013
|
+
}
|
|
6014
|
+
return cells.length === 0 ? null : cells;
|
|
6015
|
+
}
|
|
6016
|
+
function parsePipeTableSeparator(line) {
|
|
6017
|
+
const cells = parsePipeTableCells(line);
|
|
6018
|
+
if (cells === null || cells.length === 0) {
|
|
6019
|
+
return null;
|
|
6020
|
+
}
|
|
6021
|
+
const alignments = [];
|
|
6022
|
+
for (const cell of cells) {
|
|
6023
|
+
const alignment = parseTableAlignmentCell(cell);
|
|
6024
|
+
if (alignment === void 0) {
|
|
6025
|
+
return null;
|
|
6026
|
+
}
|
|
6027
|
+
alignments.push(alignment);
|
|
6028
|
+
}
|
|
6029
|
+
return alignments;
|
|
6030
|
+
}
|
|
6031
|
+
function parseTableAlignmentCell(value) {
|
|
6032
|
+
if (value.length === 0) {
|
|
6033
|
+
return void 0;
|
|
6034
|
+
}
|
|
6035
|
+
const hasLeadingColon = value[0] === ":";
|
|
6036
|
+
const hasTrailingColon = value[value.length - 1] === ":";
|
|
6037
|
+
const dashStart = hasLeadingColon ? 1 : 0;
|
|
6038
|
+
const dashEnd = hasTrailingColon ? value.length - 1 : value.length;
|
|
6039
|
+
if (dashEnd - dashStart < 3) {
|
|
6040
|
+
return void 0;
|
|
6041
|
+
}
|
|
6042
|
+
for (let index = dashStart; index < dashEnd; index += 1) {
|
|
6043
|
+
if (value[index] !== "-") {
|
|
6044
|
+
return void 0;
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
6047
|
+
if (hasLeadingColon && hasTrailingColon) {
|
|
6048
|
+
return "center";
|
|
6049
|
+
}
|
|
6050
|
+
if (hasLeadingColon) {
|
|
6051
|
+
return "left";
|
|
6052
|
+
}
|
|
6053
|
+
if (hasTrailingColon) {
|
|
6054
|
+
return "right";
|
|
6055
|
+
}
|
|
6056
|
+
return null;
|
|
6057
|
+
}
|
|
6058
|
+
function normalizeTableCells(cells, columnCount) {
|
|
6059
|
+
if (cells.length === columnCount) {
|
|
6060
|
+
return cells;
|
|
6061
|
+
}
|
|
6062
|
+
if (cells.length > columnCount) {
|
|
6063
|
+
return cells.slice(0, columnCount);
|
|
6064
|
+
}
|
|
6065
|
+
return [...cells, ...Array.from({ length: columnCount - cells.length }, () => "")];
|
|
6066
|
+
}
|
|
6067
|
+
function stripBlockquoteMarker(line) {
|
|
6068
|
+
const markerStart = skipLeadingBlockIndent(line);
|
|
6069
|
+
if (markerStart === -1 || markerStart >= line.length || line[markerStart] !== ">") {
|
|
6070
|
+
return null;
|
|
6071
|
+
}
|
|
6072
|
+
let contentStart = markerStart + 1;
|
|
6073
|
+
if (contentStart < line.length && (line[contentStart] === " " || line[contentStart] === " ")) {
|
|
6074
|
+
contentStart += 1;
|
|
6075
|
+
}
|
|
6076
|
+
return line.slice(contentStart);
|
|
6077
|
+
}
|
|
6078
|
+
function parseAlertMarker(content) {
|
|
6079
|
+
const endOfKind = content.indexOf("]");
|
|
6080
|
+
if (content.length === 0 || !content.startsWith("[!") || endOfKind === -1) {
|
|
6081
|
+
return null;
|
|
6082
|
+
}
|
|
6083
|
+
const kind = content.slice(2, endOfKind);
|
|
6084
|
+
if (!isAlertKind(kind)) {
|
|
6085
|
+
return null;
|
|
6086
|
+
}
|
|
6087
|
+
return {
|
|
6088
|
+
kind,
|
|
6089
|
+
content: trimAsciiWhitespaceStart2(content.slice(endOfKind + 1))
|
|
6090
|
+
};
|
|
6091
|
+
}
|
|
6092
|
+
function parseFootnoteDefinitionMarker(line) {
|
|
6093
|
+
const markerStart = skipLeadingBlockIndent(line);
|
|
6094
|
+
if (markerStart === -1 || markerStart + 3 >= line.length || line[markerStart] !== "[" || line[markerStart + 1] !== "^") {
|
|
6095
|
+
return null;
|
|
6096
|
+
}
|
|
6097
|
+
let labelEnd = markerStart + 2;
|
|
6098
|
+
while (labelEnd < line.length && line[labelEnd] !== "]") {
|
|
6099
|
+
if (!isFootnoteLabelChar2(line[labelEnd])) {
|
|
6100
|
+
return null;
|
|
6101
|
+
}
|
|
6102
|
+
labelEnd += 1;
|
|
6103
|
+
}
|
|
6104
|
+
if (labelEnd === markerStart + 2 || labelEnd + 1 >= line.length || line[labelEnd + 1] !== ":") {
|
|
6105
|
+
return null;
|
|
6106
|
+
}
|
|
6107
|
+
let contentStart = labelEnd + 2;
|
|
6108
|
+
while (contentStart < line.length && (line[contentStart] === " " || line[contentStart] === " ")) {
|
|
6109
|
+
contentStart += 1;
|
|
6110
|
+
}
|
|
6111
|
+
return {
|
|
6112
|
+
label: line.slice(markerStart + 2, labelEnd),
|
|
6113
|
+
contentStart
|
|
6114
|
+
};
|
|
6115
|
+
}
|
|
6116
|
+
function parseBlockHtmlTagStart(line) {
|
|
6117
|
+
const start = skipLeadingBlockIndent(line);
|
|
6118
|
+
if (start === -1 || start >= line.length || line[start] !== "<") {
|
|
6119
|
+
return null;
|
|
6120
|
+
}
|
|
6121
|
+
let index = start + 1;
|
|
6122
|
+
let closing = false;
|
|
6123
|
+
if (index < line.length && line[index] === "/") {
|
|
6124
|
+
closing = true;
|
|
6125
|
+
index += 1;
|
|
6126
|
+
}
|
|
6127
|
+
if (index >= line.length || !isAsciiLetter2(line[index])) {
|
|
6128
|
+
return null;
|
|
6129
|
+
}
|
|
6130
|
+
const tagNameStart = index;
|
|
6131
|
+
while (index < line.length && isHtmlTagNameChar2(line[index])) {
|
|
6132
|
+
index += 1;
|
|
6133
|
+
}
|
|
6134
|
+
const tagName = line.slice(tagNameStart, index).toLowerCase();
|
|
6135
|
+
if (!BLOCK_HTML_TAGS.has(tagName)) {
|
|
6136
|
+
return null;
|
|
6137
|
+
}
|
|
6138
|
+
if (closing) {
|
|
6139
|
+
index = skipHtmlWhitespace2(line, index);
|
|
6140
|
+
if (index >= line.length || line[index] !== ">") {
|
|
6141
|
+
return null;
|
|
6142
|
+
}
|
|
6143
|
+
return {
|
|
6144
|
+
tagName,
|
|
6145
|
+
tagEnd: index + 1,
|
|
6146
|
+
closing: true,
|
|
6147
|
+
selfClosing: false
|
|
6148
|
+
};
|
|
6149
|
+
}
|
|
6150
|
+
while (index < line.length) {
|
|
6151
|
+
index = skipHtmlWhitespace2(line, index);
|
|
6152
|
+
if (index >= line.length) {
|
|
6153
|
+
return null;
|
|
6154
|
+
}
|
|
6155
|
+
if (line[index] === ">") {
|
|
6156
|
+
return {
|
|
6157
|
+
tagName,
|
|
6158
|
+
tagEnd: index + 1,
|
|
6159
|
+
closing: false,
|
|
6160
|
+
selfClosing: false
|
|
6161
|
+
};
|
|
6162
|
+
}
|
|
6163
|
+
if (line[index] === "/") {
|
|
6164
|
+
const selfClosingStart = skipHtmlWhitespace2(line, index + 1);
|
|
6165
|
+
if (selfClosingStart >= line.length || line[selfClosingStart] !== ">") {
|
|
6166
|
+
return null;
|
|
6167
|
+
}
|
|
6168
|
+
return {
|
|
6169
|
+
tagName,
|
|
6170
|
+
tagEnd: selfClosingStart + 1,
|
|
6171
|
+
closing: false,
|
|
6172
|
+
selfClosing: true
|
|
6173
|
+
};
|
|
6174
|
+
}
|
|
6175
|
+
if (!isHtmlAttributeNameStartChar2(line[index])) {
|
|
6176
|
+
return null;
|
|
6177
|
+
}
|
|
6178
|
+
index += 1;
|
|
6179
|
+
while (index < line.length && isHtmlAttributeNameChar2(line[index])) {
|
|
6180
|
+
index += 1;
|
|
6181
|
+
}
|
|
6182
|
+
index = skipHtmlWhitespace2(line, index);
|
|
6183
|
+
if (index >= line.length || line[index] !== "=") {
|
|
6184
|
+
continue;
|
|
6185
|
+
}
|
|
6186
|
+
index = skipHtmlWhitespace2(line, index + 1);
|
|
6187
|
+
if (index >= line.length) {
|
|
6188
|
+
return null;
|
|
6189
|
+
}
|
|
6190
|
+
const quote = line[index];
|
|
6191
|
+
if (quote === '"' || quote === "'") {
|
|
6192
|
+
index += 1;
|
|
6193
|
+
while (index < line.length && line[index] !== quote) {
|
|
6194
|
+
index += 1;
|
|
6195
|
+
}
|
|
6196
|
+
if (index >= line.length) {
|
|
6197
|
+
return null;
|
|
6198
|
+
}
|
|
6199
|
+
index += 1;
|
|
6200
|
+
continue;
|
|
6201
|
+
}
|
|
6202
|
+
while (index < line.length && !isHtmlWhitespace2(line[index]) && line[index] !== ">") {
|
|
6203
|
+
const char = line[index];
|
|
6204
|
+
if (char === '"' || char === "'" || char === "<" || char === "=" || char === "`") {
|
|
6205
|
+
return null;
|
|
6206
|
+
}
|
|
6207
|
+
index += 1;
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
return null;
|
|
6211
|
+
}
|
|
6212
|
+
function containsClosingHtmlTag(line, tagName, fromIndex = 0) {
|
|
6213
|
+
const lowerLine = line.toLowerCase();
|
|
6214
|
+
const needle = `</${tagName}`;
|
|
6215
|
+
let searchIndex = fromIndex;
|
|
6216
|
+
while (searchIndex < lowerLine.length) {
|
|
6217
|
+
const matchIndex = lowerLine.indexOf(needle, searchIndex);
|
|
6218
|
+
if (matchIndex === -1) {
|
|
6219
|
+
return false;
|
|
6220
|
+
}
|
|
6221
|
+
let endIndex = matchIndex + needle.length;
|
|
6222
|
+
while (endIndex < lowerLine.length && isHtmlWhitespace2(lowerLine[endIndex])) {
|
|
6223
|
+
endIndex += 1;
|
|
6224
|
+
}
|
|
6225
|
+
if (endIndex < lowerLine.length && lowerLine[endIndex] === ">") {
|
|
6226
|
+
return true;
|
|
6227
|
+
}
|
|
6228
|
+
searchIndex = matchIndex + 1;
|
|
6229
|
+
}
|
|
6230
|
+
return false;
|
|
6231
|
+
}
|
|
6232
|
+
function parseListMarker(line) {
|
|
6233
|
+
const markerStart = skipLeadingBlockIndent(line);
|
|
6234
|
+
if (markerStart === -1 || markerStart >= line.length) {
|
|
6235
|
+
return null;
|
|
6236
|
+
}
|
|
6237
|
+
const marker = line[markerStart];
|
|
6238
|
+
if (marker === "-" || marker === "+" || marker === "*") {
|
|
6239
|
+
return parseBulletListMarker(line, markerStart);
|
|
6240
|
+
}
|
|
6241
|
+
if (isDigit2(marker)) {
|
|
6242
|
+
return parseOrderedListMarker(line, markerStart);
|
|
6243
|
+
}
|
|
6244
|
+
return null;
|
|
6245
|
+
}
|
|
6246
|
+
function parseBulletListMarker(line, markerStart) {
|
|
6247
|
+
const contentStart = parseContentStart(line, markerStart + 1);
|
|
6248
|
+
if (contentStart === null) {
|
|
6249
|
+
return null;
|
|
6250
|
+
}
|
|
6251
|
+
return {
|
|
6252
|
+
ordered: false,
|
|
6253
|
+
indent: measureColumns(line.slice(0, markerStart)),
|
|
6254
|
+
contentIndent: measureColumns(line.slice(0, contentStart)),
|
|
6255
|
+
contentStart
|
|
6256
|
+
};
|
|
6257
|
+
}
|
|
6258
|
+
function parseOrderedListMarker(line, markerStart) {
|
|
6259
|
+
let markerEnd = markerStart;
|
|
6260
|
+
while (markerEnd < line.length && isDigit2(line[markerEnd])) {
|
|
6261
|
+
markerEnd += 1;
|
|
6262
|
+
}
|
|
6263
|
+
if (markerEnd >= line.length || line[markerEnd] !== "." && line[markerEnd] !== ")") {
|
|
6264
|
+
return null;
|
|
6265
|
+
}
|
|
6266
|
+
const contentStart = parseContentStart(line, markerEnd + 1);
|
|
6267
|
+
if (contentStart === null) {
|
|
6268
|
+
return null;
|
|
6269
|
+
}
|
|
6270
|
+
return {
|
|
6271
|
+
ordered: true,
|
|
6272
|
+
start: Number.parseInt(line.slice(markerStart, markerEnd), 10),
|
|
6273
|
+
indent: measureColumns(line.slice(0, markerStart)),
|
|
6274
|
+
contentIndent: measureColumns(line.slice(0, contentStart)),
|
|
6275
|
+
contentStart
|
|
6276
|
+
};
|
|
6277
|
+
}
|
|
6278
|
+
function parseContentStart(line, afterMarker) {
|
|
6279
|
+
if (afterMarker >= line.length) {
|
|
6280
|
+
return afterMarker;
|
|
6281
|
+
}
|
|
6282
|
+
if (line[afterMarker] !== " " && line[afterMarker] !== " ") {
|
|
6283
|
+
return null;
|
|
6284
|
+
}
|
|
6285
|
+
let pos = afterMarker;
|
|
6286
|
+
while (pos < line.length && (line[pos] === " " || line[pos] === " ")) {
|
|
6287
|
+
pos += 1;
|
|
6288
|
+
}
|
|
6289
|
+
return pos;
|
|
6290
|
+
}
|
|
6291
|
+
function readLine2(input, position) {
|
|
6292
|
+
let index = position;
|
|
6293
|
+
while (index < input.length) {
|
|
6294
|
+
const char = input[index];
|
|
6295
|
+
if (char === "\n" || char === "\r") {
|
|
6296
|
+
break;
|
|
6297
|
+
}
|
|
6298
|
+
index += 1;
|
|
6299
|
+
}
|
|
6300
|
+
const text4 = input.slice(position, index);
|
|
6301
|
+
if (index >= input.length) {
|
|
6302
|
+
return { text: text4, nextPosition: input.length };
|
|
6303
|
+
}
|
|
6304
|
+
if (input[index] === "\r" && input[index + 1] === "\n") {
|
|
6305
|
+
return { text: text4, nextPosition: index + 2 };
|
|
6306
|
+
}
|
|
6307
|
+
return { text: text4, nextPosition: index + 1 };
|
|
6308
|
+
}
|
|
6309
|
+
function isBlankLine(line) {
|
|
6310
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
6311
|
+
const char = line[index];
|
|
6312
|
+
if (char !== " " && char !== " ") {
|
|
6313
|
+
return false;
|
|
6314
|
+
}
|
|
6315
|
+
}
|
|
6316
|
+
return true;
|
|
6317
|
+
}
|
|
6318
|
+
function skipLeadingBlockIndent(line) {
|
|
6319
|
+
const leadingWhitespace = readLeadingWhitespace(line);
|
|
6320
|
+
if (leadingWhitespace.columns > 3) {
|
|
6321
|
+
return -1;
|
|
6322
|
+
}
|
|
6323
|
+
return leadingWhitespace.offset;
|
|
6324
|
+
}
|
|
6325
|
+
function trimAsciiWhitespace3(value) {
|
|
6326
|
+
return trimAsciiWhitespaceEnd2(trimAsciiWhitespaceStart2(value));
|
|
6327
|
+
}
|
|
6328
|
+
function trimAsciiWhitespaceStart2(value) {
|
|
6329
|
+
let start = 0;
|
|
6330
|
+
while (start < value.length) {
|
|
6331
|
+
const char = value[start];
|
|
6332
|
+
if (char !== " " && char !== " ") {
|
|
6333
|
+
break;
|
|
6334
|
+
}
|
|
6335
|
+
start += 1;
|
|
6336
|
+
}
|
|
6337
|
+
return value.slice(start);
|
|
6338
|
+
}
|
|
6339
|
+
function trimAsciiWhitespaceEnd2(value) {
|
|
6340
|
+
let end = value.length;
|
|
6341
|
+
while (end > 0) {
|
|
6342
|
+
const char = value[end - 1];
|
|
6343
|
+
if (char !== " " && char !== " ") {
|
|
6344
|
+
break;
|
|
6345
|
+
}
|
|
6346
|
+
end -= 1;
|
|
6347
|
+
}
|
|
6348
|
+
return value.slice(0, end);
|
|
6349
|
+
}
|
|
6350
|
+
function findWhitespaceIndex(value) {
|
|
6351
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
6352
|
+
const char = value[index];
|
|
6353
|
+
if (char === " " || char === " ") {
|
|
6354
|
+
return index;
|
|
6355
|
+
}
|
|
6356
|
+
}
|
|
6357
|
+
return -1;
|
|
6358
|
+
}
|
|
6359
|
+
function skipHtmlWhitespace2(line, start) {
|
|
6360
|
+
let index = start;
|
|
6361
|
+
while (index < line.length && isHtmlWhitespace2(line[index])) {
|
|
6362
|
+
index += 1;
|
|
6363
|
+
}
|
|
6364
|
+
return index;
|
|
6365
|
+
}
|
|
6366
|
+
function isDigit2(value) {
|
|
6367
|
+
return value >= "0" && value <= "9";
|
|
6368
|
+
}
|
|
6369
|
+
function isAsciiLetter2(value) {
|
|
6370
|
+
return value >= "a" && value <= "z" || value >= "A" && value <= "Z";
|
|
6371
|
+
}
|
|
6372
|
+
function isHtmlTagNameChar2(value) {
|
|
6373
|
+
return isAsciiLetter2(value) || isDigit2(value) || value === "-";
|
|
6374
|
+
}
|
|
6375
|
+
function isHtmlAttributeNameStartChar2(value) {
|
|
6376
|
+
return isAsciiLetter2(value) || value === ":" || value === "_";
|
|
6377
|
+
}
|
|
6378
|
+
function isHtmlAttributeNameChar2(value) {
|
|
6379
|
+
return isHtmlAttributeNameStartChar2(value) || isDigit2(value) || value === "-" || value === ".";
|
|
6380
|
+
}
|
|
6381
|
+
function isHtmlWhitespace2(value) {
|
|
6382
|
+
return value === " " || value === " ";
|
|
6383
|
+
}
|
|
6384
|
+
function isFootnoteLabelChar2(value) {
|
|
6385
|
+
return isAsciiLetter2(value) || isDigit2(value) || value === "-" || value === "_";
|
|
6386
|
+
}
|
|
6387
|
+
function isAlertKind(value) {
|
|
6388
|
+
return value === "NOTE" || value === "TIP" || value === "IMPORTANT" || value === "WARNING" || value === "CAUTION";
|
|
6389
|
+
}
|
|
6390
|
+
function stripBom2(input) {
|
|
6391
|
+
return input[0] === "\uFEFF" ? input.slice(1) : input;
|
|
6392
|
+
}
|
|
6393
|
+
function parseListItem(state, list) {
|
|
6394
|
+
const firstLine = readLine2(state.input, state.position);
|
|
6395
|
+
const marker = parseListMarker(firstLine.text);
|
|
6396
|
+
if (marker === null || marker.ordered !== list.ordered || marker.indent !== list.indent) {
|
|
6397
|
+
return null;
|
|
6398
|
+
}
|
|
6399
|
+
state.position = firstLine.nextPosition;
|
|
6400
|
+
let firstLineContent = firstLine.text.slice(marker.contentStart);
|
|
6401
|
+
let checked;
|
|
6402
|
+
const taskMarker = parseTaskMarker(firstLineContent);
|
|
6403
|
+
if (taskMarker !== null) {
|
|
6404
|
+
checked = taskMarker.checked;
|
|
6405
|
+
firstLineContent = taskMarker.content;
|
|
6406
|
+
}
|
|
6407
|
+
const continuationLines = [];
|
|
6408
|
+
const pendingBlankLines = [];
|
|
6409
|
+
while (state.position < state.input.length) {
|
|
6410
|
+
const line = readLine2(state.input, state.position);
|
|
6411
|
+
if (isBlankLine(line.text)) {
|
|
6412
|
+
pendingBlankLines.push("");
|
|
6413
|
+
state.position = line.nextPosition;
|
|
6414
|
+
continue;
|
|
6415
|
+
}
|
|
6416
|
+
const nextMarker = parseListMarker(line.text);
|
|
6417
|
+
if (nextMarker !== null && nextMarker.ordered === list.ordered && nextMarker.indent === list.indent) {
|
|
6418
|
+
break;
|
|
6419
|
+
}
|
|
6420
|
+
const strippedLine = stripIndent(line.text, marker.contentIndent);
|
|
6421
|
+
if (strippedLine === null) {
|
|
6422
|
+
break;
|
|
6423
|
+
}
|
|
6424
|
+
state.position = line.nextPosition;
|
|
6425
|
+
continuationLines.push(...pendingBlankLines, strippedLine);
|
|
6426
|
+
pendingBlankLines.length = 0;
|
|
6427
|
+
}
|
|
6428
|
+
const children = parseListItemChildren(
|
|
6429
|
+
firstLineContent,
|
|
6430
|
+
continuationLines,
|
|
6431
|
+
list.preferListToThematicBreak
|
|
6432
|
+
);
|
|
6433
|
+
return {
|
|
6434
|
+
type: "listItem",
|
|
6435
|
+
...checked === void 0 ? {} : { checked },
|
|
6436
|
+
children
|
|
6437
|
+
};
|
|
6438
|
+
}
|
|
6439
|
+
function parseListItemChildren(firstLineContent, continuationLines, preferListToThematicBreak) {
|
|
6440
|
+
const blocks = [];
|
|
6441
|
+
let paragraphLines = firstLineContent.length === 0 ? [] : [firstLineContent];
|
|
6442
|
+
let lineIndex = 0;
|
|
6443
|
+
while (lineIndex < continuationLines.length) {
|
|
6444
|
+
const line = continuationLines[lineIndex];
|
|
6445
|
+
if (isBlankLine(line)) {
|
|
6446
|
+
if (paragraphLines.length > 0) {
|
|
6447
|
+
blocks.push(createParagraphNode(paragraphLines));
|
|
6448
|
+
paragraphLines = [];
|
|
6449
|
+
}
|
|
6450
|
+
lineIndex += 1;
|
|
6451
|
+
continue;
|
|
6452
|
+
}
|
|
6453
|
+
if (startsBlockInLines(continuationLines, lineIndex, preferListToThematicBreak)) {
|
|
6454
|
+
if (paragraphLines.length > 0) {
|
|
6455
|
+
blocks.push(createParagraphNode(paragraphLines));
|
|
6456
|
+
}
|
|
6457
|
+
blocks.push(
|
|
6458
|
+
...parseBlocksWithOptions(continuationLines.slice(lineIndex).join("\n"), {
|
|
6459
|
+
preferListToThematicBreak
|
|
6460
|
+
})
|
|
6461
|
+
);
|
|
6462
|
+
return blocks;
|
|
6463
|
+
}
|
|
6464
|
+
paragraphLines.push(line);
|
|
6465
|
+
lineIndex += 1;
|
|
6466
|
+
}
|
|
6467
|
+
if (paragraphLines.length > 0) {
|
|
6468
|
+
blocks.push(createParagraphNode(paragraphLines));
|
|
6469
|
+
}
|
|
6470
|
+
return blocks;
|
|
6471
|
+
}
|
|
6472
|
+
function createParagraphNode(lines) {
|
|
6473
|
+
return {
|
|
6474
|
+
type: "paragraph",
|
|
6475
|
+
children: [{ type: "text", value: lines.join("\n") }]
|
|
6476
|
+
};
|
|
6477
|
+
}
|
|
6478
|
+
function parseTaskMarker(content) {
|
|
6479
|
+
if (content.length < 3 || content[0] !== "[" || content[2] !== "]") {
|
|
6480
|
+
return null;
|
|
6481
|
+
}
|
|
6482
|
+
const marker = content[1];
|
|
6483
|
+
if (marker !== " " && marker !== "x" && marker !== "X") {
|
|
6484
|
+
return null;
|
|
6485
|
+
}
|
|
6486
|
+
if (content.length > 3 && content[3] !== " " && content[3] !== " ") {
|
|
6487
|
+
return null;
|
|
6488
|
+
}
|
|
6489
|
+
return {
|
|
6490
|
+
checked: marker === "x" || marker === "X",
|
|
6491
|
+
content: trimAsciiWhitespaceStart2(content.slice(3))
|
|
6492
|
+
};
|
|
6493
|
+
}
|
|
6494
|
+
function stripIndent(line, columns) {
|
|
6495
|
+
const leadingWhitespace = readLeadingWhitespace(line);
|
|
6496
|
+
if (leadingWhitespace.columns < columns) {
|
|
6497
|
+
return null;
|
|
6498
|
+
}
|
|
6499
|
+
return leadingWhitespace.normalized.slice(columns) + line.slice(leadingWhitespace.offset);
|
|
6500
|
+
}
|
|
6501
|
+
function readLeadingWhitespace(line) {
|
|
6502
|
+
let columns = 0;
|
|
6503
|
+
let offset = 0;
|
|
6504
|
+
let normalized = "";
|
|
6505
|
+
while (offset < line.length) {
|
|
6506
|
+
const char = line[offset];
|
|
6507
|
+
if (char === " ") {
|
|
6508
|
+
columns += 1;
|
|
6509
|
+
normalized += " ";
|
|
6510
|
+
offset += 1;
|
|
6511
|
+
continue;
|
|
6512
|
+
}
|
|
6513
|
+
if (char === " ") {
|
|
6514
|
+
columns += 4;
|
|
6515
|
+
normalized += " ";
|
|
6516
|
+
offset += 1;
|
|
6517
|
+
continue;
|
|
6518
|
+
}
|
|
6519
|
+
break;
|
|
6520
|
+
}
|
|
6521
|
+
return { columns, offset, normalized };
|
|
6522
|
+
}
|
|
6523
|
+
function measureColumns(value) {
|
|
6524
|
+
let columns = 0;
|
|
6525
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
6526
|
+
columns += value[index] === " " ? 4 : 1;
|
|
6527
|
+
}
|
|
6528
|
+
return columns;
|
|
6529
|
+
}
|
|
6530
|
+
var BLOCK_HTML_TAGS, VOID_BLOCK_HTML_TAGS;
|
|
6531
|
+
var init_block = __esm({
|
|
6532
|
+
"packages/design-system/src/terminal-markdown/parser/block.ts"() {
|
|
6533
|
+
"use strict";
|
|
6534
|
+
init_frontmatter();
|
|
6535
|
+
init_inline();
|
|
6536
|
+
BLOCK_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
6537
|
+
"address",
|
|
6538
|
+
"article",
|
|
6539
|
+
"aside",
|
|
6540
|
+
"base",
|
|
6541
|
+
"basefont",
|
|
6542
|
+
"blockquote",
|
|
6543
|
+
"body",
|
|
6544
|
+
"caption",
|
|
6545
|
+
"center",
|
|
6546
|
+
"col",
|
|
6547
|
+
"colgroup",
|
|
6548
|
+
"dd",
|
|
6549
|
+
"details",
|
|
6550
|
+
"dialog",
|
|
6551
|
+
"dir",
|
|
6552
|
+
"div",
|
|
6553
|
+
"dl",
|
|
6554
|
+
"dt",
|
|
6555
|
+
"fieldset",
|
|
6556
|
+
"figcaption",
|
|
6557
|
+
"figure",
|
|
6558
|
+
"footer",
|
|
6559
|
+
"form",
|
|
6560
|
+
"frame",
|
|
6561
|
+
"frameset",
|
|
6562
|
+
"h1",
|
|
6563
|
+
"h2",
|
|
6564
|
+
"h3",
|
|
6565
|
+
"h4",
|
|
6566
|
+
"h5",
|
|
6567
|
+
"h6",
|
|
6568
|
+
"head",
|
|
6569
|
+
"header",
|
|
6570
|
+
"hr",
|
|
6571
|
+
"html",
|
|
6572
|
+
"iframe",
|
|
6573
|
+
"legend",
|
|
6574
|
+
"li",
|
|
6575
|
+
"link",
|
|
6576
|
+
"main",
|
|
6577
|
+
"menu",
|
|
6578
|
+
"menuitem",
|
|
6579
|
+
"nav",
|
|
6580
|
+
"noframes",
|
|
6581
|
+
"ol",
|
|
6582
|
+
"optgroup",
|
|
6583
|
+
"option",
|
|
6584
|
+
"p",
|
|
6585
|
+
"param",
|
|
6586
|
+
"search",
|
|
6587
|
+
"section",
|
|
6588
|
+
"summary",
|
|
6589
|
+
"table",
|
|
6590
|
+
"tbody",
|
|
6591
|
+
"td",
|
|
6592
|
+
"tfoot",
|
|
6593
|
+
"th",
|
|
6594
|
+
"thead",
|
|
6595
|
+
"title",
|
|
6596
|
+
"tr",
|
|
6597
|
+
"track",
|
|
6598
|
+
"ul"
|
|
6599
|
+
]);
|
|
6600
|
+
VOID_BLOCK_HTML_TAGS = /* @__PURE__ */ new Set(["base", "basefont", "col", "hr", "link", "param", "track"]);
|
|
6601
|
+
}
|
|
6602
|
+
});
|
|
6603
|
+
|
|
6604
|
+
// packages/design-system/src/terminal-markdown/parser.ts
|
|
6605
|
+
function parse4(markdown) {
|
|
6606
|
+
const { frontmatter, children } = parseBlockDocument(markdown);
|
|
6607
|
+
return {
|
|
6608
|
+
...frontmatter === void 0 ? {} : { frontmatter },
|
|
6609
|
+
ast: {
|
|
6610
|
+
type: "root",
|
|
6611
|
+
children: frontmatter === void 0 ? children : [{ type: "frontmatter", data: frontmatter }, ...children]
|
|
6612
|
+
}
|
|
6613
|
+
};
|
|
6614
|
+
}
|
|
6615
|
+
var init_parser = __esm({
|
|
6616
|
+
"packages/design-system/src/terminal-markdown/parser.ts"() {
|
|
6617
|
+
"use strict";
|
|
6618
|
+
init_block();
|
|
6619
|
+
}
|
|
6620
|
+
});
|
|
6621
|
+
|
|
6622
|
+
// packages/design-system/src/terminal-markdown/renderer.ts
|
|
6623
|
+
function render(ast, options = {}) {
|
|
6624
|
+
const width = Math.max(1, options.width ?? process.stdout.columns ?? widths.maxLine);
|
|
6625
|
+
const context = {
|
|
6626
|
+
width,
|
|
6627
|
+
showFrontmatter: options.showFrontmatter ?? false,
|
|
6628
|
+
theme: getTheme(),
|
|
6629
|
+
footnotes: ast.type === "root" ? createFootnoteState(ast.children) : void 0
|
|
6630
|
+
};
|
|
6631
|
+
return renderNode(ast, context);
|
|
6632
|
+
}
|
|
6633
|
+
function renderNode(node, context) {
|
|
6634
|
+
switch (node.type) {
|
|
6635
|
+
case "root":
|
|
6636
|
+
return renderRoot(node, context);
|
|
6637
|
+
case "heading":
|
|
6638
|
+
return renderHeading(node, context);
|
|
6639
|
+
case "paragraph":
|
|
6640
|
+
return renderParagraph(node, context);
|
|
6641
|
+
case "blockquote":
|
|
6642
|
+
return renderBlockquote(node, context);
|
|
6643
|
+
case "alert":
|
|
6644
|
+
return renderAlert(node, context);
|
|
6645
|
+
case "code":
|
|
6646
|
+
return renderCodeBlock(node, context);
|
|
6647
|
+
case "list":
|
|
6648
|
+
return renderList(node, context);
|
|
6649
|
+
case "table":
|
|
6650
|
+
return renderTable2(node, context);
|
|
6651
|
+
case "html":
|
|
6652
|
+
return renderHtml(node, context);
|
|
6653
|
+
case "text":
|
|
6654
|
+
case "strong":
|
|
6655
|
+
case "emphasis":
|
|
6656
|
+
case "strikethrough":
|
|
6657
|
+
case "inlineCode":
|
|
6658
|
+
case "link":
|
|
6659
|
+
case "image":
|
|
6660
|
+
case "break":
|
|
6661
|
+
case "footnoteReference":
|
|
6662
|
+
return renderInline([node], context).join("\n");
|
|
6663
|
+
case "thematicBreak":
|
|
6664
|
+
return `${context.theme.divider(lineChar.repeat(context.width))}
|
|
6665
|
+
|
|
6666
|
+
`;
|
|
6667
|
+
case "frontmatter":
|
|
6668
|
+
return context.showFrontmatter ? renderFrontmatter(node.data, context) : "";
|
|
6669
|
+
case "footnoteDefinition":
|
|
6670
|
+
return "";
|
|
6671
|
+
default:
|
|
6672
|
+
return "children" in node ? renderChildren(node.children, context) : "";
|
|
6673
|
+
}
|
|
6674
|
+
}
|
|
6675
|
+
function renderRoot(node, context) {
|
|
6676
|
+
const mainOutput = renderChildren(
|
|
6677
|
+
node.children.filter((child) => child.type !== "footnoteDefinition"),
|
|
6678
|
+
context
|
|
6679
|
+
);
|
|
6680
|
+
const footnotesOutput = renderReferencedFootnotes(context);
|
|
6681
|
+
return `${mainOutput}${footnotesOutput}`;
|
|
6682
|
+
}
|
|
6683
|
+
function renderChildren(children, context) {
|
|
6684
|
+
return children.map((child) => renderNode(child, context)).join("");
|
|
6685
|
+
}
|
|
6686
|
+
function renderParagraph(node, context) {
|
|
6687
|
+
const lines = renderInline(node.children, context);
|
|
6688
|
+
if (lines.length === 0) {
|
|
6689
|
+
return "";
|
|
6690
|
+
}
|
|
6691
|
+
return `${lines.join("\n")}
|
|
6692
|
+
|
|
6693
|
+
`;
|
|
6694
|
+
}
|
|
6695
|
+
function renderHeading(node, context) {
|
|
6696
|
+
const lines = renderInline(node.children, context);
|
|
6697
|
+
if (lines.length === 0) {
|
|
6698
|
+
return "";
|
|
6699
|
+
}
|
|
6700
|
+
const styledLines = lines.map((line) => styleHeading(line, node.depth, context));
|
|
6701
|
+
if (node.depth === 1) {
|
|
6702
|
+
const underlineWidth = Math.max(...lines.map((line) => stripAnsi2(line).length));
|
|
6703
|
+
return `${styledLines.join("\n")}
|
|
6704
|
+
${context.theme.header(lineChar.repeat(underlineWidth))}
|
|
6705
|
+
|
|
6706
|
+
`;
|
|
6707
|
+
}
|
|
6708
|
+
return `${styledLines.join("\n")}
|
|
6709
|
+
|
|
6710
|
+
`;
|
|
6711
|
+
}
|
|
6712
|
+
function renderBlockquote(node, context) {
|
|
6713
|
+
const prefix = `${symbols.bar} `;
|
|
6714
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, prefix));
|
|
6715
|
+
if (body.length === 0) {
|
|
6716
|
+
return `${symbols.bar}
|
|
6717
|
+
|
|
6718
|
+
`;
|
|
6719
|
+
}
|
|
6720
|
+
const lines = body.split("\n").map((line) => line.length > 0 ? `${prefix}${typography.dim(line)}` : symbols.bar);
|
|
6721
|
+
return `${lines.join("\n")}
|
|
6722
|
+
|
|
6723
|
+
`;
|
|
6724
|
+
}
|
|
6725
|
+
function renderAlert(node, context) {
|
|
6726
|
+
const prefix = `${symbols.bar} `;
|
|
6727
|
+
const labelLine = `${prefix}${formatAlertLabel(node.kind, context)}`;
|
|
6728
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, prefix));
|
|
6729
|
+
if (body.length === 0) {
|
|
6730
|
+
return `${labelLine}
|
|
6731
|
+
|
|
6732
|
+
`;
|
|
6733
|
+
}
|
|
6734
|
+
const lines = body.split("\n").map((line) => line.length > 0 ? `${prefix}${line}` : symbols.bar);
|
|
6735
|
+
return `${labelLine}
|
|
6736
|
+
${lines.join("\n")}
|
|
6737
|
+
|
|
6738
|
+
`;
|
|
6739
|
+
}
|
|
6740
|
+
function renderCodeBlock(node, context) {
|
|
6741
|
+
const indent = " ".repeat(spacing.sm);
|
|
6742
|
+
const lines = node.value.split("\n");
|
|
6743
|
+
const longestLine = lines.reduce((max, line) => Math.max(max, line.length), 0);
|
|
6744
|
+
const borderWidth = Math.max(3, Math.min(context.width - indent.length, longestLine));
|
|
6745
|
+
const border = context.theme.muted(`${indent}${lineChar.repeat(borderWidth)}`);
|
|
6746
|
+
const content = lines.map((line) => `${indent}${line}`).join("\n");
|
|
6747
|
+
return `${border}
|
|
6748
|
+
${content}
|
|
6749
|
+
${border}
|
|
6750
|
+
|
|
6751
|
+
`;
|
|
6752
|
+
}
|
|
6753
|
+
function renderList(node, context) {
|
|
6754
|
+
const items = node.children.map((child, index) => {
|
|
6755
|
+
if (child.type !== "listItem") {
|
|
6756
|
+
return renderNode(child, context).trimEnd();
|
|
6757
|
+
}
|
|
6758
|
+
return renderListItem(child, node, index, context);
|
|
6759
|
+
}).filter((item) => item.length > 0);
|
|
6760
|
+
if (items.length === 0) {
|
|
6761
|
+
return "";
|
|
6762
|
+
}
|
|
6763
|
+
return `${items.join("\n")}
|
|
6764
|
+
|
|
6765
|
+
`;
|
|
6766
|
+
}
|
|
6767
|
+
function renderTable2(node, context) {
|
|
6768
|
+
const rows = node.children.filter((child) => child.type === "tableRow");
|
|
6769
|
+
if (rows.length === 0) {
|
|
6770
|
+
return "";
|
|
6771
|
+
}
|
|
6772
|
+
const columnCount = Math.max(node.align.length, ...rows.map((row) => row.children.length));
|
|
6773
|
+
if (columnCount === 0) {
|
|
6774
|
+
return "";
|
|
6775
|
+
}
|
|
6776
|
+
const renderedRows = rows.map(
|
|
6777
|
+
(row) => Array.from({ length: columnCount }, (_2, columnIndex) => {
|
|
6778
|
+
const cell = row.children[columnIndex];
|
|
6779
|
+
return cell?.type === "tableCell" ? renderTableCell(cell, context) : "";
|
|
6780
|
+
})
|
|
6781
|
+
);
|
|
6782
|
+
const columnWidths = Array.from(
|
|
6783
|
+
{ length: columnCount },
|
|
6784
|
+
(_2, columnIndex) => Math.max(...renderedRows.map((row) => stripAnsi2(row[columnIndex] ?? "").length), 0)
|
|
6785
|
+
);
|
|
6786
|
+
if (getRenderedTableWidth(columnWidths) > context.width) {
|
|
6787
|
+
return renderStackedTable(rows, columnCount, context);
|
|
6788
|
+
}
|
|
6789
|
+
const lines = renderedRows.map(
|
|
6790
|
+
(row, rowIndex) => row.map(
|
|
6791
|
+
(cell, columnIndex) => alignTableCell(
|
|
6792
|
+
rowIndex === 0 ? context.theme.header(typography.bold(cell)) : cell,
|
|
6793
|
+
columnWidths[columnIndex] ?? 0,
|
|
6794
|
+
node.align[columnIndex] ?? null
|
|
6795
|
+
)
|
|
6796
|
+
)
|
|
6797
|
+
);
|
|
6798
|
+
const outputLines = lines.map((row, rowIndex) => {
|
|
6799
|
+
const line = `${symbols.bar}${row.map((cell) => `${" ".repeat(spacing.sm)}${cell}${" ".repeat(spacing.sm)}`).join(symbols.bar)}${symbols.bar}`;
|
|
6800
|
+
if (rowIndex !== 0 || lines.length === 1) {
|
|
6801
|
+
return line;
|
|
6802
|
+
}
|
|
6803
|
+
const divider = context.theme.muted(
|
|
6804
|
+
`\u251C${columnWidths.map((width) => lineChar.repeat(width + spacing.sm * 2)).join("\u253C")}\u2524`
|
|
6805
|
+
);
|
|
6806
|
+
return `${line}
|
|
6807
|
+
${divider}`;
|
|
6808
|
+
});
|
|
6809
|
+
return `${outputLines.join("\n")}
|
|
6810
|
+
|
|
6811
|
+
`;
|
|
6812
|
+
}
|
|
6813
|
+
function renderStackedTable(rows, columnCount, context) {
|
|
6814
|
+
const headerRow = rows[0];
|
|
6815
|
+
if (headerRow === void 0) {
|
|
6816
|
+
return "";
|
|
6817
|
+
}
|
|
6818
|
+
const dataRows = rows.slice(1);
|
|
6819
|
+
if (dataRows.length === 0) {
|
|
6820
|
+
const headerLines = Array.from(
|
|
6821
|
+
{ length: columnCount },
|
|
6822
|
+
(_2, columnIndex) => tokenizeText(getStackedTableLabel(headerRow.children[columnIndex], columnIndex, context), [typography.bold])
|
|
6823
|
+
).flatMap((tokens) => wrapTokens(tokens, context.width));
|
|
6824
|
+
return headerLines.length === 0 ? "" : `${headerLines.join("\n")}
|
|
6825
|
+
|
|
6826
|
+
`;
|
|
6827
|
+
}
|
|
6828
|
+
const blocks = dataRows.map(
|
|
6829
|
+
(row) => Array.from(
|
|
6830
|
+
{ length: columnCount },
|
|
6831
|
+
(_2, columnIndex) => renderStackedTableField(headerRow.children[columnIndex], row.children[columnIndex], columnIndex, context)
|
|
6832
|
+
).filter((field) => field.length > 0).join("\n")
|
|
6833
|
+
).filter((block) => block.length > 0);
|
|
6834
|
+
return blocks.length === 0 ? "" : `${blocks.join("\n\n")}
|
|
6835
|
+
|
|
6836
|
+
`;
|
|
6837
|
+
}
|
|
6838
|
+
function renderListItem(node, list, index, context) {
|
|
6839
|
+
const marker = getListMarker(node, list, index);
|
|
6840
|
+
const indent = " ".repeat(spacing.sm);
|
|
6841
|
+
const firstPrefix = `${indent}${marker} `;
|
|
6842
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, firstPrefix));
|
|
6843
|
+
const continuationPrefix = `${indent}${" ".repeat(marker.length + 1)}`;
|
|
6844
|
+
if (body.length === 0) {
|
|
6845
|
+
return firstPrefix.trimEnd();
|
|
6846
|
+
}
|
|
6847
|
+
return prefixBlock(body, firstPrefix, continuationPrefix);
|
|
6848
|
+
}
|
|
6849
|
+
function styleHeading(value, depth, context) {
|
|
6850
|
+
if (depth <= 2) {
|
|
6851
|
+
return context.theme.header(typography.bold(value));
|
|
6852
|
+
}
|
|
6853
|
+
if (depth <= 4) {
|
|
6854
|
+
return typography.bold(value);
|
|
6855
|
+
}
|
|
6856
|
+
return context.theme.muted(typography.bold(value));
|
|
6857
|
+
}
|
|
6858
|
+
function renderFrontmatter(data, context) {
|
|
6859
|
+
const entries = Object.entries(data);
|
|
6860
|
+
if (entries.length === 0) {
|
|
6861
|
+
return "";
|
|
6862
|
+
}
|
|
6863
|
+
const lines = entries.flatMap(
|
|
6864
|
+
([key, value]) => wrapText(`${key}: ${formatFrontmatterValue(value)}`, context.width).map(
|
|
6865
|
+
(line) => typography.dim(line)
|
|
6866
|
+
)
|
|
6867
|
+
);
|
|
6868
|
+
return `${lines.join("\n")}
|
|
6869
|
+
|
|
6870
|
+
`;
|
|
6871
|
+
}
|
|
6872
|
+
function formatFrontmatterValue(value) {
|
|
6873
|
+
if (value === null) {
|
|
6874
|
+
return "null";
|
|
6875
|
+
}
|
|
6876
|
+
if (typeof value === "string") {
|
|
6877
|
+
return value;
|
|
6878
|
+
}
|
|
6879
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
6880
|
+
return String(value);
|
|
6881
|
+
}
|
|
6882
|
+
return JSON.stringify(value);
|
|
6883
|
+
}
|
|
6884
|
+
function renderHtml(node, context) {
|
|
6885
|
+
const value = stripHtmlTags(node.value).trim();
|
|
6886
|
+
if (value.length === 0) {
|
|
6887
|
+
return "";
|
|
6888
|
+
}
|
|
6889
|
+
const lines = wrapText(value, context.width);
|
|
6890
|
+
if (lines.length === 0) {
|
|
6891
|
+
return "";
|
|
6892
|
+
}
|
|
6893
|
+
return `${lines.join("\n")}
|
|
6894
|
+
|
|
6895
|
+
`;
|
|
6896
|
+
}
|
|
6897
|
+
function renderBlockChildren(children, context) {
|
|
6898
|
+
const renderedChildren = children.map((child) => ({
|
|
6899
|
+
type: child.type,
|
|
6900
|
+
value: renderNode(child, context).trimEnd()
|
|
6901
|
+
})).filter((child) => child.value.length > 0);
|
|
6902
|
+
if (renderedChildren.length === 0) {
|
|
6903
|
+
return "";
|
|
6904
|
+
}
|
|
6905
|
+
let output = renderedChildren[0].value;
|
|
6906
|
+
for (let index = 1; index < renderedChildren.length; index += 1) {
|
|
6907
|
+
const previous = renderedChildren[index - 1];
|
|
6908
|
+
const current = renderedChildren[index];
|
|
6909
|
+
const separator = previous.type === "paragraph" && current.type === "list" ? "\n" : "\n\n";
|
|
6910
|
+
output += `${separator}${current.value}`;
|
|
6911
|
+
}
|
|
6912
|
+
return output;
|
|
6913
|
+
}
|
|
6914
|
+
function renderReferencedFootnotes(context) {
|
|
6915
|
+
const footnotes = context.footnotes;
|
|
6916
|
+
if (footnotes === void 0 || footnotes.labelsInOrder.length === 0) {
|
|
6917
|
+
return "";
|
|
6918
|
+
}
|
|
6919
|
+
const rendered = [];
|
|
6920
|
+
for (let index = 0; index < footnotes.labelsInOrder.length; index += 1) {
|
|
6921
|
+
const label = footnotes.labelsInOrder[index];
|
|
6922
|
+
const definition = footnotes.definitions.get(label);
|
|
6923
|
+
const number = footnotes.numbers.get(label);
|
|
6924
|
+
if (definition !== void 0 && number !== void 0) {
|
|
6925
|
+
rendered.push(renderFootnoteDefinition(definition, number, context));
|
|
6926
|
+
}
|
|
6927
|
+
}
|
|
6928
|
+
if (rendered.length === 0) {
|
|
6929
|
+
return "";
|
|
6930
|
+
}
|
|
6931
|
+
return `${rendered.join("\n")}
|
|
6932
|
+
|
|
6933
|
+
`;
|
|
6934
|
+
}
|
|
6935
|
+
function renderFootnoteDefinition(node, number, context) {
|
|
6936
|
+
const marker = typography.dim(`[${number}]`);
|
|
6937
|
+
const firstPrefix = `${" ".repeat(spacing.sm)}${marker} `;
|
|
6938
|
+
const continuationPrefix = `${" ".repeat(spacing.sm + stripAnsi2(`[${number}] `).length)}`;
|
|
6939
|
+
const body = renderBlockChildren(node.children, reduceWidth(context, firstPrefix));
|
|
6940
|
+
if (body.length === 0) {
|
|
6941
|
+
return firstPrefix.trimEnd();
|
|
6942
|
+
}
|
|
6943
|
+
return prefixBlock(body, firstPrefix, continuationPrefix);
|
|
6944
|
+
}
|
|
6945
|
+
function getListMarker(node, list, index) {
|
|
6946
|
+
if (node.checked === true) {
|
|
6947
|
+
return symbols.active;
|
|
6948
|
+
}
|
|
6949
|
+
if (node.checked === false) {
|
|
6950
|
+
return symbols.inactive;
|
|
6951
|
+
}
|
|
6952
|
+
if (list.ordered) {
|
|
6953
|
+
return `${(list.start ?? 1) + index}.`;
|
|
6954
|
+
}
|
|
6955
|
+
return "\u2022";
|
|
6956
|
+
}
|
|
6957
|
+
function prefixBlock(rendered, firstPrefix, restPrefix) {
|
|
6958
|
+
return rendered.split("\n").map((line, index) => {
|
|
6959
|
+
const prefix = index === 0 ? firstPrefix : restPrefix;
|
|
6960
|
+
return line.length > 0 ? `${prefix}${line}` : prefix.trimEnd();
|
|
6961
|
+
}).join("\n");
|
|
6962
|
+
}
|
|
6963
|
+
function reduceWidth(context, prefix) {
|
|
6964
|
+
return {
|
|
6965
|
+
...context,
|
|
6966
|
+
width: Math.max(1, context.width - stripAnsi2(prefix).length)
|
|
6967
|
+
};
|
|
6968
|
+
}
|
|
6969
|
+
function renderInline(nodes, context) {
|
|
6970
|
+
const tokens = tokenizeInline(nodes, context);
|
|
6971
|
+
return wrapTokens(tokens, context.width);
|
|
6972
|
+
}
|
|
6973
|
+
function tokenizeInline(nodes, context) {
|
|
6974
|
+
const tokens = [];
|
|
6975
|
+
for (const node of nodes) {
|
|
6976
|
+
collectInlineTokens(node, [], context, tokens);
|
|
6977
|
+
}
|
|
6978
|
+
return tokens;
|
|
6979
|
+
}
|
|
6980
|
+
function collectInlineTokens(node, formatters, context, tokens) {
|
|
6981
|
+
switch (node.type) {
|
|
6982
|
+
case "text":
|
|
6983
|
+
tokens.push(...tokenizeText(node.value, formatters));
|
|
6984
|
+
return;
|
|
6985
|
+
case "strong":
|
|
6986
|
+
collectChildren(node.children, [...formatters, typography.bold], context, tokens);
|
|
6987
|
+
return;
|
|
6988
|
+
case "emphasis":
|
|
6989
|
+
collectChildren(node.children, [...formatters, typography.italic], context, tokens);
|
|
6990
|
+
return;
|
|
6991
|
+
case "strikethrough":
|
|
6992
|
+
collectChildren(node.children, [...formatters, typography.strikethrough], context, tokens);
|
|
6993
|
+
return;
|
|
6994
|
+
case "inlineCode":
|
|
6995
|
+
tokens.push(...tokenizeText(node.value, [...formatters, context.theme.accent]));
|
|
6996
|
+
return;
|
|
6997
|
+
case "link":
|
|
6998
|
+
collectLinkTokens(node, formatters, context, tokens);
|
|
6999
|
+
return;
|
|
7000
|
+
case "image":
|
|
7001
|
+
tokens.push(createWordToken(formatImagePlaceholder(node.alt), [...formatters, context.theme.muted]));
|
|
7002
|
+
return;
|
|
7003
|
+
case "footnoteReference": {
|
|
7004
|
+
const footnoteNumber = resolveFootnoteNumber(node.label, context);
|
|
7005
|
+
if (footnoteNumber !== null) {
|
|
7006
|
+
tokens.push(createWordToken(`[${footnoteNumber}]`, [...formatters, typography.dim]));
|
|
7007
|
+
}
|
|
7008
|
+
return;
|
|
7009
|
+
}
|
|
7010
|
+
case "html": {
|
|
7011
|
+
const value = stripHtmlTags(node.value);
|
|
7012
|
+
if (value.length > 0) {
|
|
7013
|
+
tokens.push(...tokenizeText(value, formatters));
|
|
7014
|
+
}
|
|
7015
|
+
return;
|
|
7016
|
+
}
|
|
7017
|
+
case "break":
|
|
7018
|
+
tokens.push({ type: "break" });
|
|
7019
|
+
return;
|
|
7020
|
+
default:
|
|
7021
|
+
if ("children" in node) {
|
|
7022
|
+
collectChildren(node.children, formatters, context, tokens);
|
|
7023
|
+
}
|
|
7024
|
+
}
|
|
7025
|
+
}
|
|
7026
|
+
function collectChildren(children, formatters, context, tokens) {
|
|
7027
|
+
for (const child of children) {
|
|
7028
|
+
collectInlineTokens(child, formatters, context, tokens);
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
function collectLinkTokens(node, formatters, context, tokens) {
|
|
7032
|
+
if (isAutolink(node)) {
|
|
7033
|
+
tokens.push(createWordToken(node.url, [...formatters, context.theme.accent]));
|
|
7034
|
+
return;
|
|
7035
|
+
}
|
|
7036
|
+
const childTokens = [];
|
|
7037
|
+
collectChildren(node.children, formatters, context, childTokens);
|
|
7038
|
+
const trimmedChildTokens = trimTrailingSpaces(childTokens);
|
|
7039
|
+
tokens.push(...trimmedChildTokens);
|
|
7040
|
+
if (trimmedChildTokens.some((token) => token.type === "word")) {
|
|
7041
|
+
tokens.push({ type: "space", value: " " });
|
|
7042
|
+
}
|
|
7043
|
+
tokens.push(createWordToken(`(${node.url})`, [...formatters, context.theme.accent]));
|
|
7044
|
+
}
|
|
7045
|
+
function isAutolink(node) {
|
|
7046
|
+
if (node.children.length !== 1 || node.children[0]?.type !== "text") {
|
|
7047
|
+
return false;
|
|
7048
|
+
}
|
|
7049
|
+
const label = node.children[0].value;
|
|
7050
|
+
return label === node.url || node.url.startsWith("http://") && label === node.url.slice("http://".length) || node.url.startsWith("mailto:") && label === node.url.slice("mailto:".length);
|
|
7051
|
+
}
|
|
7052
|
+
function formatImagePlaceholder(alt) {
|
|
7053
|
+
return alt.length > 0 ? `[image: ${alt}]` : "[image]";
|
|
7054
|
+
}
|
|
7055
|
+
function createWordToken(value, formatters) {
|
|
7056
|
+
return { type: "word", value, formatters };
|
|
7057
|
+
}
|
|
7058
|
+
function trimTrailingSpaces(tokens) {
|
|
7059
|
+
let end = tokens.length;
|
|
7060
|
+
while (end > 0 && tokens[end - 1]?.type === "space") {
|
|
7061
|
+
end -= 1;
|
|
7062
|
+
}
|
|
7063
|
+
return tokens.slice(0, end);
|
|
7064
|
+
}
|
|
7065
|
+
function tokenizeText(value, formatters) {
|
|
7066
|
+
const lines = value.split("\n");
|
|
7067
|
+
return lines.flatMap((line, lineIndex) => {
|
|
7068
|
+
const pieces = line.split(/([ \t]+)/).filter((piece) => piece.length > 0).map(
|
|
7069
|
+
(piece) => /^[ \t]+$/.test(piece) ? { type: "space", value: piece } : { type: "word", value: piece, formatters }
|
|
7070
|
+
);
|
|
7071
|
+
return lineIndex < lines.length - 1 ? [...pieces, { type: "break" }] : pieces;
|
|
7072
|
+
});
|
|
7073
|
+
}
|
|
7074
|
+
function wrapTokens(tokens, width) {
|
|
7075
|
+
const lines = [];
|
|
7076
|
+
let currentLine = "";
|
|
7077
|
+
let currentWidth = 0;
|
|
7078
|
+
let pendingSpace = "";
|
|
7079
|
+
const flushLine = () => {
|
|
7080
|
+
lines.push(currentLine);
|
|
7081
|
+
currentLine = "";
|
|
7082
|
+
currentWidth = 0;
|
|
7083
|
+
pendingSpace = "";
|
|
7084
|
+
};
|
|
7085
|
+
for (const token of tokens) {
|
|
7086
|
+
if (token.type === "break") {
|
|
7087
|
+
flushLine();
|
|
7088
|
+
continue;
|
|
7089
|
+
}
|
|
7090
|
+
if (token.type === "space") {
|
|
7091
|
+
if (currentWidth > 0) {
|
|
7092
|
+
pendingSpace += token.value;
|
|
7093
|
+
}
|
|
7094
|
+
continue;
|
|
7095
|
+
}
|
|
7096
|
+
const chunks = splitWord(token.value, width);
|
|
7097
|
+
for (let index = 0; index < chunks.length; index++) {
|
|
7098
|
+
const chunk = chunks[index];
|
|
7099
|
+
const gap = index === 0 ? pendingSpace : "";
|
|
7100
|
+
const gapWidth = gap.length;
|
|
7101
|
+
if (currentWidth > 0 && currentWidth + chunk.length + gapWidth > width) {
|
|
7102
|
+
flushLine();
|
|
7103
|
+
}
|
|
7104
|
+
if (currentWidth > 0 && gapWidth > 0) {
|
|
7105
|
+
currentLine += gap;
|
|
7106
|
+
currentWidth += gapWidth;
|
|
7107
|
+
}
|
|
7108
|
+
currentLine += applyFormatters(chunk, token.formatters);
|
|
7109
|
+
currentWidth += chunk.length;
|
|
7110
|
+
pendingSpace = "";
|
|
7111
|
+
if (index < chunks.length - 1) {
|
|
7112
|
+
flushLine();
|
|
7113
|
+
}
|
|
7114
|
+
}
|
|
7115
|
+
}
|
|
7116
|
+
if (currentLine.length > 0) {
|
|
7117
|
+
lines.push(currentLine);
|
|
7118
|
+
}
|
|
7119
|
+
return lines;
|
|
7120
|
+
}
|
|
7121
|
+
function splitWord(value, width) {
|
|
7122
|
+
if (value.length <= width) {
|
|
7123
|
+
return [value];
|
|
7124
|
+
}
|
|
7125
|
+
const chunks = [];
|
|
7126
|
+
for (let index = 0; index < value.length; index += width) {
|
|
7127
|
+
chunks.push(value.slice(index, index + width));
|
|
7128
|
+
}
|
|
7129
|
+
return chunks;
|
|
3840
7130
|
}
|
|
3841
|
-
function
|
|
3842
|
-
return
|
|
7131
|
+
function applyFormatters(value, formatters) {
|
|
7132
|
+
return formatters.reduce((text4, formatter) => formatter(text4), value);
|
|
3843
7133
|
}
|
|
3844
|
-
function
|
|
3845
|
-
|
|
7134
|
+
function wrapText(value, width) {
|
|
7135
|
+
const tokens = tokenizeText(value, []);
|
|
7136
|
+
return wrapTokens(tokens, Math.max(1, width));
|
|
3846
7137
|
}
|
|
3847
|
-
|
|
3848
|
-
"packages/design-system/src/components/help-formatter.ts"() {
|
|
3849
|
-
"use strict";
|
|
3850
|
-
init_text();
|
|
3851
|
-
init_widths();
|
|
3852
|
-
}
|
|
3853
|
-
});
|
|
3854
|
-
|
|
3855
|
-
// packages/design-system/src/components/command-errors.ts
|
|
3856
|
-
function formatCommandNotFound(input) {
|
|
3857
|
-
const unknown = input.unknownCommand.length > 0 ? input.unknownCommand : "<command>";
|
|
7138
|
+
function createFootnoteState(children) {
|
|
3858
7139
|
return {
|
|
3859
|
-
|
|
3860
|
-
|
|
7140
|
+
definitions: new Map(
|
|
7141
|
+
children.flatMap(
|
|
7142
|
+
(child) => child.type === "footnoteDefinition" ? [[child.label, child]] : []
|
|
7143
|
+
)
|
|
7144
|
+
),
|
|
7145
|
+
labelsInOrder: [],
|
|
7146
|
+
numbers: /* @__PURE__ */ new Map()
|
|
3861
7147
|
};
|
|
3862
7148
|
}
|
|
3863
|
-
function
|
|
3864
|
-
const
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
}
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
7149
|
+
function resolveFootnoteNumber(label, context) {
|
|
7150
|
+
const footnotes = context.footnotes;
|
|
7151
|
+
if (footnotes === void 0 || !footnotes.definitions.has(label)) {
|
|
7152
|
+
return null;
|
|
7153
|
+
}
|
|
7154
|
+
const existing = footnotes.numbers.get(label);
|
|
7155
|
+
if (existing !== void 0) {
|
|
7156
|
+
return existing;
|
|
7157
|
+
}
|
|
7158
|
+
const number = footnotes.numbers.size + 1;
|
|
7159
|
+
footnotes.numbers.set(label, number);
|
|
7160
|
+
footnotes.labelsInOrder.push(label);
|
|
7161
|
+
return number;
|
|
3873
7162
|
}
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
7163
|
+
function formatAlertLabel(kind, context) {
|
|
7164
|
+
switch (kind) {
|
|
7165
|
+
case "NOTE":
|
|
7166
|
+
return context.theme.info("Note");
|
|
7167
|
+
case "TIP":
|
|
7168
|
+
return context.theme.success("Tip");
|
|
7169
|
+
case "IMPORTANT":
|
|
7170
|
+
return context.theme.info("Important");
|
|
7171
|
+
case "WARNING":
|
|
7172
|
+
return context.theme.warning("Warning");
|
|
7173
|
+
case "CAUTION":
|
|
7174
|
+
return context.theme.error("Caution");
|
|
7175
|
+
}
|
|
7176
|
+
}
|
|
7177
|
+
function renderTableCell(node, context) {
|
|
7178
|
+
return wrapTokens(tokenizeInline(node.children, context), Number.MAX_SAFE_INTEGER).join(" ");
|
|
7179
|
+
}
|
|
7180
|
+
function renderStackedTableField(headerCell, cell, columnIndex, context) {
|
|
7181
|
+
const tokens = [
|
|
7182
|
+
...tokenizeText(getStackedTableLabel(headerCell, columnIndex, context), [typography.bold]),
|
|
7183
|
+
createWordToken(":", [typography.bold]),
|
|
7184
|
+
{ type: "space", value: " " },
|
|
7185
|
+
...getStackedTableValueTokens(cell, context)
|
|
7186
|
+
];
|
|
7187
|
+
return wrapTokens(tokens, context.width).join("\n");
|
|
7188
|
+
}
|
|
7189
|
+
function getStackedTableLabel(headerCell, columnIndex, context) {
|
|
7190
|
+
if (headerCell?.type !== "tableCell") {
|
|
7191
|
+
return `Column ${columnIndex + 1}`;
|
|
3879
7192
|
}
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
const table = new Table({
|
|
3887
|
-
style: {
|
|
3888
|
-
headerTop: {
|
|
3889
|
-
left: theme.muted("\u250C"),
|
|
3890
|
-
mid: theme.muted("\u252C"),
|
|
3891
|
-
right: theme.muted("\u2510"),
|
|
3892
|
-
other: theme.muted("\u2500")
|
|
3893
|
-
},
|
|
3894
|
-
headerBottom: {
|
|
3895
|
-
left: theme.muted("\u251C"),
|
|
3896
|
-
mid: theme.muted("\u253C"),
|
|
3897
|
-
right: theme.muted("\u2524"),
|
|
3898
|
-
other: theme.muted("\u2500")
|
|
3899
|
-
},
|
|
3900
|
-
tableBottom: {
|
|
3901
|
-
left: theme.muted("\u2514"),
|
|
3902
|
-
mid: theme.muted("\u2534"),
|
|
3903
|
-
right: theme.muted("\u2518"),
|
|
3904
|
-
other: theme.muted("\u2500")
|
|
3905
|
-
},
|
|
3906
|
-
vertical: theme.muted("\u2502"),
|
|
3907
|
-
rowSeparator: {
|
|
3908
|
-
left: theme.muted("\u251C"),
|
|
3909
|
-
mid: theme.muted("\u253C"),
|
|
3910
|
-
right: theme.muted("\u2524"),
|
|
3911
|
-
other: theme.muted("\u2500")
|
|
3912
|
-
}
|
|
3913
|
-
},
|
|
3914
|
-
columns: columns.map((col) => ({
|
|
3915
|
-
name: col.name,
|
|
3916
|
-
title: theme.header(col.title),
|
|
3917
|
-
alignment: col.alignment,
|
|
3918
|
-
maxLen: col.maxLen
|
|
3919
|
-
}))
|
|
3920
|
-
});
|
|
3921
|
-
for (const row of rows) {
|
|
3922
|
-
table.addRow(row);
|
|
7193
|
+
const label = stripAnsi2(renderTableCell(headerCell, context)).trim();
|
|
7194
|
+
return label.length > 0 ? label : `Column ${columnIndex + 1}`;
|
|
7195
|
+
}
|
|
7196
|
+
function getStackedTableValueTokens(cell, context) {
|
|
7197
|
+
if (cell?.type !== "tableCell") {
|
|
7198
|
+
return [createWordToken("\u2014", [context.theme.muted])];
|
|
3923
7199
|
}
|
|
3924
|
-
|
|
7200
|
+
const tokens = trimTrailingSpaces(tokenizeInline(cell.children, context));
|
|
7201
|
+
return tokens.length > 0 ? tokens : [createWordToken("\u2014", [context.theme.muted])];
|
|
3925
7202
|
}
|
|
3926
|
-
function
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
const dataRows = rows.map(
|
|
3931
|
-
(row) => `| ${columns.map((c2) => stripAnsi2(row[c2.name] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`
|
|
7203
|
+
function getRenderedTableWidth(columnWidths) {
|
|
7204
|
+
return columnWidths.reduce(
|
|
7205
|
+
(totalWidth, width) => totalWidth + width + spacing.sm * 2,
|
|
7206
|
+
columnWidths.length + 1
|
|
3932
7207
|
);
|
|
3933
|
-
return [header, separator, ...dataRows].join("\n");
|
|
3934
7208
|
}
|
|
3935
|
-
function
|
|
3936
|
-
const
|
|
3937
|
-
const
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
7209
|
+
function alignTableCell(value, width, align) {
|
|
7210
|
+
const visibleWidth = stripAnsi2(value).length;
|
|
7211
|
+
const extraSpace = Math.max(0, width - visibleWidth);
|
|
7212
|
+
if (align === "right") {
|
|
7213
|
+
return `${" ".repeat(extraSpace)}${value}`;
|
|
7214
|
+
}
|
|
7215
|
+
if (align === "center") {
|
|
7216
|
+
const leftPadding = Math.floor(extraSpace / 2);
|
|
7217
|
+
const rightPadding = extraSpace - leftPadding;
|
|
7218
|
+
return `${" ".repeat(leftPadding)}${value}${" ".repeat(rightPadding)}`;
|
|
7219
|
+
}
|
|
7220
|
+
return `${value}${" ".repeat(extraSpace)}`;
|
|
3945
7221
|
}
|
|
3946
|
-
function
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
7222
|
+
function stripHtmlTags(value) {
|
|
7223
|
+
let output = "";
|
|
7224
|
+
let inTag = false;
|
|
7225
|
+
for (const char of value) {
|
|
7226
|
+
if (char === "<") {
|
|
7227
|
+
inTag = true;
|
|
7228
|
+
continue;
|
|
7229
|
+
}
|
|
7230
|
+
if (char === ">" && inTag) {
|
|
7231
|
+
inTag = false;
|
|
7232
|
+
continue;
|
|
7233
|
+
}
|
|
7234
|
+
if (!inTag) {
|
|
7235
|
+
output += char;
|
|
7236
|
+
}
|
|
3955
7237
|
}
|
|
7238
|
+
return output;
|
|
3956
7239
|
}
|
|
3957
|
-
var
|
|
3958
|
-
|
|
7240
|
+
var lineChar;
|
|
7241
|
+
var init_renderer = __esm({
|
|
7242
|
+
"packages/design-system/src/terminal-markdown/renderer.ts"() {
|
|
3959
7243
|
"use strict";
|
|
3960
|
-
|
|
7244
|
+
init_symbols();
|
|
7245
|
+
init_theme_detect();
|
|
3961
7246
|
init_strip_ansi();
|
|
7247
|
+
init_spacing();
|
|
7248
|
+
init_typography();
|
|
7249
|
+
init_widths();
|
|
7250
|
+
lineChar = "\u2500";
|
|
7251
|
+
}
|
|
7252
|
+
});
|
|
7253
|
+
|
|
7254
|
+
// packages/design-system/src/terminal-markdown/index.ts
|
|
7255
|
+
function renderMarkdown(markdown, options) {
|
|
7256
|
+
const { ast } = parse4(markdown);
|
|
7257
|
+
return render(ast, options);
|
|
7258
|
+
}
|
|
7259
|
+
var init_terminal_markdown = __esm({
|
|
7260
|
+
"packages/design-system/src/terminal-markdown/index.ts"() {
|
|
7261
|
+
"use strict";
|
|
7262
|
+
init_parser();
|
|
7263
|
+
init_renderer();
|
|
7264
|
+
init_parser();
|
|
7265
|
+
init_renderer();
|
|
3962
7266
|
}
|
|
3963
7267
|
});
|
|
3964
7268
|
|
|
@@ -3991,10 +7295,11 @@ function renderAgentMessage(text4) {
|
|
|
3991
7295
|
return;
|
|
3992
7296
|
}
|
|
3993
7297
|
if (format === "json") {
|
|
3994
|
-
writeLine(JSON.stringify({
|
|
7298
|
+
writeLine(JSON.stringify({ event: "agent_message", text: text4 }));
|
|
3995
7299
|
return;
|
|
3996
7300
|
}
|
|
3997
|
-
|
|
7301
|
+
const rendered = renderMarkdown(text4).trimEnd();
|
|
7302
|
+
writeLine(`${AGENT_PREFIX}${rendered}`);
|
|
3998
7303
|
}
|
|
3999
7304
|
function renderToolStart(kind, title) {
|
|
4000
7305
|
const format = resolveOutputFormat();
|
|
@@ -4003,7 +7308,7 @@ function renderToolStart(kind, title) {
|
|
|
4003
7308
|
return;
|
|
4004
7309
|
}
|
|
4005
7310
|
if (format === "json") {
|
|
4006
|
-
writeLine(JSON.stringify({
|
|
7311
|
+
writeLine(JSON.stringify({ event: "tool_start", kind, title }));
|
|
4007
7312
|
return;
|
|
4008
7313
|
}
|
|
4009
7314
|
const color = colorForKind(kind);
|
|
@@ -4016,7 +7321,7 @@ function renderToolComplete(kind) {
|
|
|
4016
7321
|
return;
|
|
4017
7322
|
}
|
|
4018
7323
|
if (format === "json") {
|
|
4019
|
-
writeLine(JSON.stringify({
|
|
7324
|
+
writeLine(JSON.stringify({ event: "tool_complete", kind }));
|
|
4020
7325
|
return;
|
|
4021
7326
|
}
|
|
4022
7327
|
const color = colorForKind(kind);
|
|
@@ -4029,7 +7334,7 @@ function renderReasoning(text4) {
|
|
|
4029
7334
|
return;
|
|
4030
7335
|
}
|
|
4031
7336
|
if (format === "json") {
|
|
4032
|
-
writeLine(JSON.stringify({
|
|
7337
|
+
writeLine(JSON.stringify({ event: "reasoning", text: text4 }));
|
|
4033
7338
|
return;
|
|
4034
7339
|
}
|
|
4035
7340
|
writeLine(chalk8.dim(` \u2713 ${truncate(text4, 80)}`));
|
|
@@ -4048,10 +7353,10 @@ function renderUsage(tokens) {
|
|
|
4048
7353
|
if (format === "json") {
|
|
4049
7354
|
writeLine(
|
|
4050
7355
|
JSON.stringify({
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
7356
|
+
event: "usage",
|
|
7357
|
+
inputTokens: tokens.input,
|
|
7358
|
+
outputTokens: tokens.output,
|
|
7359
|
+
cachedTokens: tokens.cached ?? 0,
|
|
4055
7360
|
costUsd: tokens.costUsd ?? 0
|
|
4056
7361
|
})
|
|
4057
7362
|
);
|
|
@@ -4066,7 +7371,7 @@ function renderError(message2) {
|
|
|
4066
7371
|
return;
|
|
4067
7372
|
}
|
|
4068
7373
|
if (format === "json") {
|
|
4069
|
-
writeLine(JSON.stringify({
|
|
7374
|
+
writeLine(JSON.stringify({ event: "error", message: message2 }));
|
|
4070
7375
|
return;
|
|
4071
7376
|
}
|
|
4072
7377
|
writeLine(chalk8.red(`\u2717 ${message2}`));
|
|
@@ -4076,6 +7381,7 @@ var init_components = __esm({
|
|
|
4076
7381
|
"packages/design-system/src/acp/components.ts"() {
|
|
4077
7382
|
"use strict";
|
|
4078
7383
|
init_output_format();
|
|
7384
|
+
init_terminal_markdown();
|
|
4079
7385
|
KIND_COLORS = {
|
|
4080
7386
|
exec: (text4) => chalk8.yellow(text4),
|
|
4081
7387
|
edit: (text4) => chalk8.magenta(text4),
|
|
@@ -4105,42 +7411,6 @@ var init_acp = __esm({
|
|
|
4105
7411
|
}
|
|
4106
7412
|
});
|
|
4107
7413
|
|
|
4108
|
-
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
4109
|
-
var init_utils = __esm({
|
|
4110
|
-
"node_modules/fast-string-truncated-width/dist/utils.js"() {
|
|
4111
|
-
}
|
|
4112
|
-
});
|
|
4113
|
-
|
|
4114
|
-
// node_modules/fast-string-truncated-width/dist/index.js
|
|
4115
|
-
var EMOJI_RE, MODIFIER_RE;
|
|
4116
|
-
var init_dist = __esm({
|
|
4117
|
-
"node_modules/fast-string-truncated-width/dist/index.js"() {
|
|
4118
|
-
init_utils();
|
|
4119
|
-
EMOJI_RE = new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*", "yu");
|
|
4120
|
-
MODIFIER_RE = new RegExp("\\p{M}+", "gu");
|
|
4121
|
-
}
|
|
4122
|
-
});
|
|
4123
|
-
|
|
4124
|
-
// node_modules/fast-string-width/dist/index.js
|
|
4125
|
-
var init_dist2 = __esm({
|
|
4126
|
-
"node_modules/fast-string-width/dist/index.js"() {
|
|
4127
|
-
init_dist();
|
|
4128
|
-
}
|
|
4129
|
-
});
|
|
4130
|
-
|
|
4131
|
-
// node_modules/fast-wrap-ansi/lib/main.js
|
|
4132
|
-
var ANSI_ESCAPE_BELL, ANSI_CSI, ANSI_OSC, ANSI_ESCAPE_LINK, GROUP_REGEX;
|
|
4133
|
-
var init_main = __esm({
|
|
4134
|
-
"node_modules/fast-wrap-ansi/lib/main.js"() {
|
|
4135
|
-
init_dist2();
|
|
4136
|
-
ANSI_ESCAPE_BELL = "\x07";
|
|
4137
|
-
ANSI_CSI = "[";
|
|
4138
|
-
ANSI_OSC = "]";
|
|
4139
|
-
ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
4140
|
-
GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
4141
|
-
}
|
|
4142
|
-
});
|
|
4143
|
-
|
|
4144
7414
|
// node_modules/sisteransi/src/index.js
|
|
4145
7415
|
var require_src = __commonJS({
|
|
4146
7416
|
"node_modules/sisteransi/src/index.js"(exports, module) {
|
|
@@ -4149,16 +7419,16 @@ var require_src = __commonJS({
|
|
|
4149
7419
|
var CSI = `${ESC}[`;
|
|
4150
7420
|
var beep = "\x07";
|
|
4151
7421
|
var cursor = {
|
|
4152
|
-
to(x,
|
|
4153
|
-
if (!
|
|
4154
|
-
return `${CSI}${
|
|
7422
|
+
to(x, y) {
|
|
7423
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
7424
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
4155
7425
|
},
|
|
4156
|
-
move(x,
|
|
7426
|
+
move(x, y) {
|
|
4157
7427
|
let ret = "";
|
|
4158
7428
|
if (x < 0) ret += `${CSI}${-x}D`;
|
|
4159
7429
|
else if (x > 0) ret += `${CSI}${x}C`;
|
|
4160
|
-
if (
|
|
4161
|
-
else if (
|
|
7430
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
7431
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
4162
7432
|
return ret;
|
|
4163
7433
|
},
|
|
4164
7434
|
up: (count = 1) => `${CSI}${count}A`,
|
|
@@ -4198,24 +7468,30 @@ var require_src = __commonJS({
|
|
|
4198
7468
|
});
|
|
4199
7469
|
|
|
4200
7470
|
// node_modules/@clack/core/dist/index.mjs
|
|
4201
|
-
import {
|
|
4202
|
-
import
|
|
4203
|
-
import
|
|
4204
|
-
import
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
var
|
|
4210
|
-
var init_dist3 = __esm({
|
|
7471
|
+
import { stdout as R, stdin as q } from "node:process";
|
|
7472
|
+
import * as k from "node:readline";
|
|
7473
|
+
import ot from "node:readline";
|
|
7474
|
+
import { ReadStream as J } from "node:tty";
|
|
7475
|
+
function Ct(t) {
|
|
7476
|
+
return t === z;
|
|
7477
|
+
}
|
|
7478
|
+
var import_sisteransi, P, ct, pt, ft, j, Q, dt, U, et, At, _, bt, z;
|
|
7479
|
+
var init_dist = __esm({
|
|
4211
7480
|
"node_modules/@clack/core/dist/index.mjs"() {
|
|
4212
|
-
init_main();
|
|
4213
7481
|
import_sisteransi = __toESM(require_src(), 1);
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
7482
|
+
P = new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*", "yu");
|
|
7483
|
+
ct = new RegExp("\\p{M}+", "gu");
|
|
7484
|
+
pt = { limit: 1 / 0, ellipsis: "" };
|
|
7485
|
+
ft = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
|
|
7486
|
+
j = "\x07";
|
|
7487
|
+
Q = "[";
|
|
7488
|
+
dt = "]";
|
|
7489
|
+
U = `${dt}8;;`;
|
|
7490
|
+
et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
|
|
7491
|
+
At = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
7492
|
+
_ = { actions: new Set(At), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
|
|
7493
|
+
bt = globalThis.process.platform.startsWith("win");
|
|
7494
|
+
z = /* @__PURE__ */ Symbol("clack:cancel");
|
|
4219
7495
|
}
|
|
4220
7496
|
});
|
|
4221
7497
|
|
|
@@ -4232,7 +7508,7 @@ function cancel(msg = "") {
|
|
|
4232
7508
|
var init_cancel = __esm({
|
|
4233
7509
|
"packages/design-system/src/prompts/primitives/cancel.ts"() {
|
|
4234
7510
|
"use strict";
|
|
4235
|
-
|
|
7511
|
+
init_dist();
|
|
4236
7512
|
init_output_format();
|
|
4237
7513
|
}
|
|
4238
7514
|
});
|
|
@@ -4605,6 +7881,7 @@ var init_src5 = __esm({
|
|
|
4605
7881
|
init_theme();
|
|
4606
7882
|
init_static();
|
|
4607
7883
|
init_static();
|
|
7884
|
+
init_terminal_markdown();
|
|
4608
7885
|
init_theme_detect();
|
|
4609
7886
|
init_output_format();
|
|
4610
7887
|
}
|
|
@@ -4696,7 +7973,7 @@ async function renderAcpStream(events) {
|
|
|
4696
7973
|
}
|
|
4697
7974
|
flushAll();
|
|
4698
7975
|
}
|
|
4699
|
-
var
|
|
7976
|
+
var init_renderer2 = __esm({
|
|
4700
7977
|
"packages/agent-spawn/src/acp/renderer.ts"() {
|
|
4701
7978
|
"use strict";
|
|
4702
7979
|
init_src5();
|
|
@@ -4718,7 +7995,7 @@ function extractThreadId(value) {
|
|
|
4718
7995
|
const maybeThreadId = isNonEmptyString(obj.thread_id) && obj.thread_id || isNonEmptyString(obj.threadId) && obj.threadId || isNonEmptyString(obj.threadID) && obj.threadID || isNonEmptyString(obj.session_id) && obj.session_id || isNonEmptyString(obj.sessionId) && obj.sessionId || isNonEmptyString(obj.sessionID) && obj.sessionID;
|
|
4719
7996
|
return maybeThreadId || void 0;
|
|
4720
7997
|
}
|
|
4721
|
-
var
|
|
7998
|
+
var init_utils = __esm({
|
|
4722
7999
|
"packages/agent-spawn/src/adapters/utils.ts"() {
|
|
4723
8000
|
"use strict";
|
|
4724
8001
|
}
|
|
@@ -4835,7 +8112,7 @@ var TOOL_KIND_MAP, TITLE_KEYS;
|
|
|
4835
8112
|
var init_claude = __esm({
|
|
4836
8113
|
"packages/agent-spawn/src/adapters/claude.ts"() {
|
|
4837
8114
|
"use strict";
|
|
4838
|
-
|
|
8115
|
+
init_utils();
|
|
4839
8116
|
TOOL_KIND_MAP = {
|
|
4840
8117
|
Read: "read",
|
|
4841
8118
|
Write: "edit",
|
|
@@ -4897,7 +8174,8 @@ async function* adaptCodex(lines) {
|
|
|
4897
8174
|
continue;
|
|
4898
8175
|
}
|
|
4899
8176
|
if (eventType === "turn.failed") {
|
|
4900
|
-
|
|
8177
|
+
const message2 = extractErrorMessage(event) ?? "Turn failed";
|
|
8178
|
+
yield { event: "error", message: message2 };
|
|
4901
8179
|
continue;
|
|
4902
8180
|
}
|
|
4903
8181
|
const item = event.item ?? null;
|
|
@@ -4955,10 +8233,21 @@ async function* adaptCodex(lines) {
|
|
|
4955
8233
|
}
|
|
4956
8234
|
}
|
|
4957
8235
|
}
|
|
8236
|
+
function extractErrorMessage(event) {
|
|
8237
|
+
if (isNonEmptyString(event.message)) return event.message;
|
|
8238
|
+
const error2 = event.error;
|
|
8239
|
+
if (isNonEmptyString(error2)) return error2;
|
|
8240
|
+
if (typeof error2 === "object" && error2 !== null) {
|
|
8241
|
+
const errorObj = error2;
|
|
8242
|
+
if (isNonEmptyString(errorObj.message)) return errorObj.message;
|
|
8243
|
+
}
|
|
8244
|
+
if (isNonEmptyString(event.reason)) return event.reason;
|
|
8245
|
+
return void 0;
|
|
8246
|
+
}
|
|
4958
8247
|
var init_codex3 = __esm({
|
|
4959
8248
|
"packages/agent-spawn/src/adapters/codex.ts"() {
|
|
4960
8249
|
"use strict";
|
|
4961
|
-
|
|
8250
|
+
init_utils();
|
|
4962
8251
|
}
|
|
4963
8252
|
});
|
|
4964
8253
|
|
|
@@ -4998,7 +8287,7 @@ async function* adaptKimi(lines) {
|
|
|
4998
8287
|
var init_kimi3 = __esm({
|
|
4999
8288
|
"packages/agent-spawn/src/adapters/kimi.ts"() {
|
|
5000
8289
|
"use strict";
|
|
5001
|
-
|
|
8290
|
+
init_utils();
|
|
5002
8291
|
}
|
|
5003
8292
|
});
|
|
5004
8293
|
|
|
@@ -5033,7 +8322,7 @@ async function* adaptNative(lines) {
|
|
|
5033
8322
|
var init_native = __esm({
|
|
5034
8323
|
"packages/agent-spawn/src/adapters/native.ts"() {
|
|
5035
8324
|
"use strict";
|
|
5036
|
-
|
|
8325
|
+
init_utils();
|
|
5037
8326
|
}
|
|
5038
8327
|
});
|
|
5039
8328
|
|
|
@@ -5149,7 +8438,7 @@ async function* adaptOpenCode(lines) {
|
|
|
5149
8438
|
var init_opencode3 = __esm({
|
|
5150
8439
|
"packages/agent-spawn/src/adapters/opencode.ts"() {
|
|
5151
8440
|
"use strict";
|
|
5152
|
-
|
|
8441
|
+
init_utils();
|
|
5153
8442
|
}
|
|
5154
8443
|
});
|
|
5155
8444
|
|
|
@@ -5396,7 +8685,7 @@ var init_types2 = __esm({
|
|
|
5396
8685
|
function isObjectRecord2(value) {
|
|
5397
8686
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5398
8687
|
}
|
|
5399
|
-
function
|
|
8688
|
+
function hasOwn2(value, property) {
|
|
5400
8689
|
return Object.prototype.hasOwnProperty.call(value, property);
|
|
5401
8690
|
}
|
|
5402
8691
|
function isRequestId(value) {
|
|
@@ -5427,7 +8716,7 @@ function isJsonRpcErrorObject(value) {
|
|
|
5427
8716
|
if (!isAcpErrorCode(value.code) || typeof value.message !== "string") {
|
|
5428
8717
|
return false;
|
|
5429
8718
|
}
|
|
5430
|
-
return value.data === void 0 ||
|
|
8719
|
+
return value.data === void 0 || hasOwn2(value, "data");
|
|
5431
8720
|
}
|
|
5432
8721
|
function toResponseError(error2) {
|
|
5433
8722
|
return new AcpError(error2.code, error2.message, error2.data);
|
|
@@ -5525,8 +8814,8 @@ function parseJsonRpcMessage(line) {
|
|
|
5525
8814
|
error: invalidRequest()
|
|
5526
8815
|
};
|
|
5527
8816
|
}
|
|
5528
|
-
const hasMethod =
|
|
5529
|
-
const hasId =
|
|
8817
|
+
const hasMethod = hasOwn2(parsed, "method");
|
|
8818
|
+
const hasId = hasOwn2(parsed, "id");
|
|
5530
8819
|
if (hasMethod) {
|
|
5531
8820
|
if (typeof parsed.method !== "string") {
|
|
5532
8821
|
return {
|
|
@@ -5548,7 +8837,7 @@ function parseJsonRpcMessage(line) {
|
|
|
5548
8837
|
id: parsed.id,
|
|
5549
8838
|
method: parsed.method
|
|
5550
8839
|
};
|
|
5551
|
-
if (
|
|
8840
|
+
if (hasOwn2(parsed, "params")) {
|
|
5552
8841
|
request.params = parsed.params;
|
|
5553
8842
|
}
|
|
5554
8843
|
return { type: "request", message: request };
|
|
@@ -5557,7 +8846,7 @@ function parseJsonRpcMessage(line) {
|
|
|
5557
8846
|
jsonrpc: "2.0",
|
|
5558
8847
|
method: parsed.method
|
|
5559
8848
|
};
|
|
5560
|
-
if (
|
|
8849
|
+
if (hasOwn2(parsed, "params")) {
|
|
5561
8850
|
notification.params = parsed.params;
|
|
5562
8851
|
}
|
|
5563
8852
|
return {
|
|
@@ -5572,8 +8861,8 @@ function parseJsonRpcMessage(line) {
|
|
|
5572
8861
|
error: invalidRequest()
|
|
5573
8862
|
};
|
|
5574
8863
|
}
|
|
5575
|
-
const hasResult =
|
|
5576
|
-
const hasError =
|
|
8864
|
+
const hasResult = hasOwn2(parsed, "result");
|
|
8865
|
+
const hasError = hasOwn2(parsed, "error");
|
|
5577
8866
|
if (hasResult === hasError) {
|
|
5578
8867
|
return {
|
|
5579
8868
|
type: "invalid",
|
|
@@ -7151,8 +10440,8 @@ function normalizeAgent(agent2) {
|
|
|
7151
10440
|
const code = char.charCodeAt(0);
|
|
7152
10441
|
const isLower = code >= 97 && code <= 122;
|
|
7153
10442
|
const isUpper = code >= 65 && code <= 90;
|
|
7154
|
-
const
|
|
7155
|
-
if (isLower || isUpper ||
|
|
10443
|
+
const isDigit3 = code >= 48 && code <= 57;
|
|
10444
|
+
if (isLower || isUpper || isDigit3 || char === "-" || char === "_") {
|
|
7156
10445
|
normalized += char;
|
|
7157
10446
|
} else {
|
|
7158
10447
|
normalized += "-";
|
|
@@ -7263,7 +10552,7 @@ var init_src7 = __esm({
|
|
|
7263
10552
|
init_spawn();
|
|
7264
10553
|
init_spawn();
|
|
7265
10554
|
init_spawn_interactive();
|
|
7266
|
-
|
|
10555
|
+
init_renderer2();
|
|
7267
10556
|
init_spawn2();
|
|
7268
10557
|
init_spawn_acp();
|
|
7269
10558
|
init_line_reader();
|
|
@@ -8647,7 +11936,7 @@ var init_errors = __esm({
|
|
|
8647
11936
|
|
|
8648
11937
|
// src/cli/logger.ts
|
|
8649
11938
|
import chalk18 from "chalk";
|
|
8650
|
-
function
|
|
11939
|
+
function wrapText2(text4, maxWidth) {
|
|
8651
11940
|
const words = text4.split(" ");
|
|
8652
11941
|
const lines = [];
|
|
8653
11942
|
let currentLine = "";
|
|
@@ -8813,7 +12102,7 @@ function createLoggerFactory(emitter, theme) {
|
|
|
8813
12102
|
return;
|
|
8814
12103
|
}
|
|
8815
12104
|
const maxWidth = Math.min(process.stdout.columns || 80, 80) - 6;
|
|
8816
|
-
const wrapped = steps.map((step) =>
|
|
12105
|
+
const wrapped = steps.map((step) => wrapText2(step, maxWidth)).join("\n");
|
|
8817
12106
|
note(wrapped, "Next steps.");
|
|
8818
12107
|
},
|
|
8819
12108
|
feedback(label, url) {
|
|
@@ -9764,7 +13053,7 @@ function createAbortError4() {
|
|
|
9764
13053
|
error2.name = "AbortError";
|
|
9765
13054
|
return error2;
|
|
9766
13055
|
}
|
|
9767
|
-
var
|
|
13056
|
+
var init_utils2 = __esm({
|
|
9768
13057
|
"packages/pipeline/src/utils.ts"() {
|
|
9769
13058
|
"use strict";
|
|
9770
13059
|
}
|
|
@@ -9772,7 +13061,7 @@ var init_utils3 = __esm({
|
|
|
9772
13061
|
|
|
9773
13062
|
// packages/pipeline/src/config/loader.ts
|
|
9774
13063
|
import path14 from "node:path";
|
|
9775
|
-
import { parse as
|
|
13064
|
+
import { parse as parse5 } from "yaml";
|
|
9776
13065
|
function asStepMode(value) {
|
|
9777
13066
|
if (value === void 0 || value === null) {
|
|
9778
13067
|
return "yolo";
|
|
@@ -9784,7 +13073,7 @@ function asStepMode(value) {
|
|
|
9784
13073
|
}
|
|
9785
13074
|
function parseYamlDocument(filePath, content) {
|
|
9786
13075
|
try {
|
|
9787
|
-
return
|
|
13076
|
+
return parse5(content);
|
|
9788
13077
|
} catch (error2) {
|
|
9789
13078
|
const message2 = error2 instanceof Error ? error2.message : String(error2);
|
|
9790
13079
|
throw new Error(`Invalid pipeline step config YAML in "${filePath}": ${message2}`);
|
|
@@ -9890,12 +13179,12 @@ async function loadResolvedSteps(options) {
|
|
|
9890
13179
|
var init_loader = __esm({
|
|
9891
13180
|
"packages/pipeline/src/config/loader.ts"() {
|
|
9892
13181
|
"use strict";
|
|
9893
|
-
|
|
13182
|
+
init_utils2();
|
|
9894
13183
|
}
|
|
9895
13184
|
});
|
|
9896
13185
|
|
|
9897
13186
|
// packages/pipeline/src/plan/parser.ts
|
|
9898
|
-
import { parse as
|
|
13187
|
+
import { parse as parse6 } from "yaml";
|
|
9899
13188
|
function asRequiredString(value, field) {
|
|
9900
13189
|
if (typeof value === "string" && value.length > 0) {
|
|
9901
13190
|
return value;
|
|
@@ -9979,7 +13268,7 @@ function parseMcpConfig(value) {
|
|
|
9979
13268
|
function parsePlan(yamlContent, options = {}) {
|
|
9980
13269
|
let document;
|
|
9981
13270
|
try {
|
|
9982
|
-
document =
|
|
13271
|
+
document = parse6(yamlContent);
|
|
9983
13272
|
} catch (error2) {
|
|
9984
13273
|
const message2 = error2 instanceof Error ? error2.message : String(error2);
|
|
9985
13274
|
throw new Error(`Invalid plan YAML: ${message2}`);
|
|
@@ -10033,10 +13322,10 @@ function parsePlan(yamlContent, options = {}) {
|
|
|
10033
13322
|
...mcp !== void 0 ? { mcp } : {}
|
|
10034
13323
|
};
|
|
10035
13324
|
}
|
|
10036
|
-
var
|
|
13325
|
+
var init_parser2 = __esm({
|
|
10037
13326
|
"packages/pipeline/src/plan/parser.ts"() {
|
|
10038
13327
|
"use strict";
|
|
10039
|
-
|
|
13328
|
+
init_utils2();
|
|
10040
13329
|
}
|
|
10041
13330
|
});
|
|
10042
13331
|
|
|
@@ -10212,8 +13501,8 @@ var init_discovery = __esm({
|
|
|
10212
13501
|
"packages/pipeline/src/plan/discovery.ts"() {
|
|
10213
13502
|
"use strict";
|
|
10214
13503
|
init_loader();
|
|
10215
|
-
|
|
10216
|
-
|
|
13504
|
+
init_parser2();
|
|
13505
|
+
init_utils2();
|
|
10217
13506
|
}
|
|
10218
13507
|
});
|
|
10219
13508
|
|
|
@@ -10658,6 +13947,30 @@ async function runPipeline(options) {
|
|
|
10658
13947
|
};
|
|
10659
13948
|
}
|
|
10660
13949
|
if (selection.kind === "blocked") {
|
|
13950
|
+
const retry = options.onBlocked ? await options.onBlocked({
|
|
13951
|
+
taskId: selection.task.id,
|
|
13952
|
+
...selection.stepName ? { stepName: selection.stepName } : {}
|
|
13953
|
+
}) : false;
|
|
13954
|
+
if (retry) {
|
|
13955
|
+
await writeTaskStatus({
|
|
13956
|
+
fs: fs3,
|
|
13957
|
+
planPath: absolutePlanPath,
|
|
13958
|
+
taskId: selection.task.id,
|
|
13959
|
+
...selection.stepName ? { stepName: selection.stepName } : {},
|
|
13960
|
+
status: "open"
|
|
13961
|
+
});
|
|
13962
|
+
if (lastGoodPlan) {
|
|
13963
|
+
const cachedTask = lastGoodPlan.tasks.find((t) => t.id === selection.task.id);
|
|
13964
|
+
if (cachedTask) {
|
|
13965
|
+
if (selection.stepName && typeof cachedTask.status === "object") {
|
|
13966
|
+
cachedTask.status[selection.stepName] = "open";
|
|
13967
|
+
} else {
|
|
13968
|
+
cachedTask.status = "open";
|
|
13969
|
+
}
|
|
13970
|
+
}
|
|
13971
|
+
}
|
|
13972
|
+
continue;
|
|
13973
|
+
}
|
|
10661
13974
|
return {
|
|
10662
13975
|
stopReason: "failed",
|
|
10663
13976
|
planPath,
|
|
@@ -10791,10 +14104,10 @@ var init_pipeline = __esm({
|
|
|
10791
14104
|
init_loader();
|
|
10792
14105
|
init_lock();
|
|
10793
14106
|
init_discovery();
|
|
10794
|
-
|
|
14107
|
+
init_parser2();
|
|
10795
14108
|
init_writer();
|
|
10796
14109
|
init_runner();
|
|
10797
|
-
|
|
14110
|
+
init_utils2();
|
|
10798
14111
|
}
|
|
10799
14112
|
});
|
|
10800
14113
|
|
|
@@ -10804,7 +14117,7 @@ var init_src10 = __esm({
|
|
|
10804
14117
|
"use strict";
|
|
10805
14118
|
init_loader();
|
|
10806
14119
|
init_discovery();
|
|
10807
|
-
|
|
14120
|
+
init_parser2();
|
|
10808
14121
|
init_writer();
|
|
10809
14122
|
init_runner();
|
|
10810
14123
|
init_pipeline();
|
|
@@ -12446,7 +15759,7 @@ var init_src12 = __esm({
|
|
|
12446
15759
|
});
|
|
12447
15760
|
|
|
12448
15761
|
// packages/ralph/src/frontmatter/frontmatter.ts
|
|
12449
|
-
import { parse as
|
|
15762
|
+
import { parse as parse7, stringify } from "yaml";
|
|
12450
15763
|
function parseFrontmatter(content) {
|
|
12451
15764
|
if (!content.startsWith(`${FENCE}
|
|
12452
15765
|
`)) {
|
|
@@ -12466,7 +15779,7 @@ ${FENCE}
|
|
|
12466
15779
|
}
|
|
12467
15780
|
const yamlBlock = content.slice(FENCE.length + 1, closingIndex);
|
|
12468
15781
|
const body = content.slice(closingIndex + FENCE.length + 2);
|
|
12469
|
-
const parsed =
|
|
15782
|
+
const parsed = parse7(yamlBlock);
|
|
12470
15783
|
return {
|
|
12471
15784
|
data: parseFrontmatterData(parsed),
|
|
12472
15785
|
body
|
|
@@ -12561,7 +15874,7 @@ function isRecord4(value) {
|
|
|
12561
15874
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12562
15875
|
}
|
|
12563
15876
|
var FENCE, DEFAULT_STATUS;
|
|
12564
|
-
var
|
|
15877
|
+
var init_frontmatter2 = __esm({
|
|
12565
15878
|
"packages/ralph/src/frontmatter/frontmatter.ts"() {
|
|
12566
15879
|
"use strict";
|
|
12567
15880
|
FENCE = "---";
|
|
@@ -12663,6 +15976,18 @@ var init_discovery2 = __esm({
|
|
|
12663
15976
|
}
|
|
12664
15977
|
});
|
|
12665
15978
|
|
|
15979
|
+
// packages/ralph/src/variables/variables.ts
|
|
15980
|
+
function interpolateVariables(template, variables) {
|
|
15981
|
+
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, name) => {
|
|
15982
|
+
return name in variables ? variables[name] : match;
|
|
15983
|
+
});
|
|
15984
|
+
}
|
|
15985
|
+
var init_variables = __esm({
|
|
15986
|
+
"packages/ralph/src/variables/variables.ts"() {
|
|
15987
|
+
"use strict";
|
|
15988
|
+
}
|
|
15989
|
+
});
|
|
15990
|
+
|
|
12666
15991
|
// packages/ralph/src/run/ralph.ts
|
|
12667
15992
|
import path24 from "node:path";
|
|
12668
15993
|
import * as fsPromises6 from "node:fs/promises";
|
|
@@ -12682,13 +16007,16 @@ async function runRalph(options) {
|
|
|
12682
16007
|
options.homeDir
|
|
12683
16008
|
);
|
|
12684
16009
|
const rawContent = await fs3.readFile(absoluteDocPath, "utf8");
|
|
12685
|
-
const { data: frontmatter, body:
|
|
16010
|
+
const { data: frontmatter, body: rawBody } = parseFrontmatter(rawContent);
|
|
16011
|
+
const prompt = interpolateVariables(rawBody, {
|
|
16012
|
+
current_file: absoluteDocPath
|
|
16013
|
+
});
|
|
12686
16014
|
const startTime = Date.now();
|
|
12687
16015
|
let iterationsCompleted = 0;
|
|
12688
16016
|
await updateFrontmatter(
|
|
12689
16017
|
fs3,
|
|
12690
16018
|
absoluteDocPath,
|
|
12691
|
-
|
|
16019
|
+
rawBody,
|
|
12692
16020
|
frontmatter,
|
|
12693
16021
|
"in_progress",
|
|
12694
16022
|
0
|
|
@@ -12698,7 +16026,7 @@ async function runRalph(options) {
|
|
|
12698
16026
|
await updateFrontmatter(
|
|
12699
16027
|
fs3,
|
|
12700
16028
|
absoluteDocPath,
|
|
12701
|
-
|
|
16029
|
+
rawBody,
|
|
12702
16030
|
frontmatter,
|
|
12703
16031
|
status,
|
|
12704
16032
|
iterationsCompleted
|
|
@@ -12740,7 +16068,7 @@ async function runRalph(options) {
|
|
|
12740
16068
|
await updateFrontmatter(
|
|
12741
16069
|
fs3,
|
|
12742
16070
|
absoluteDocPath,
|
|
12743
|
-
|
|
16071
|
+
rawBody,
|
|
12744
16072
|
frontmatter,
|
|
12745
16073
|
"in_progress",
|
|
12746
16074
|
iterationsCompleted
|
|
@@ -12850,7 +16178,8 @@ var init_ralph = __esm({
|
|
|
12850
16178
|
"packages/ralph/src/run/ralph.ts"() {
|
|
12851
16179
|
"use strict";
|
|
12852
16180
|
init_src2();
|
|
12853
|
-
|
|
16181
|
+
init_frontmatter2();
|
|
16182
|
+
init_variables();
|
|
12854
16183
|
}
|
|
12855
16184
|
});
|
|
12856
16185
|
|
|
@@ -12858,9 +16187,10 @@ var init_ralph = __esm({
|
|
|
12858
16187
|
var init_src13 = __esm({
|
|
12859
16188
|
"packages/ralph/src/index.ts"() {
|
|
12860
16189
|
"use strict";
|
|
12861
|
-
|
|
16190
|
+
init_frontmatter2();
|
|
12862
16191
|
init_discovery2();
|
|
12863
16192
|
init_ralph();
|
|
16193
|
+
init_variables();
|
|
12864
16194
|
}
|
|
12865
16195
|
});
|
|
12866
16196
|
|
|
@@ -13005,7 +16335,7 @@ function parseNonNegativeInteger2(value) {
|
|
|
13005
16335
|
function isRecord5(value) {
|
|
13006
16336
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13007
16337
|
}
|
|
13008
|
-
var
|
|
16338
|
+
var init_frontmatter3 = __esm({
|
|
13009
16339
|
"packages/experiment-loop/src/frontmatter/frontmatter.ts"() {
|
|
13010
16340
|
"use strict";
|
|
13011
16341
|
}
|
|
@@ -13059,8 +16389,6 @@ var init_journal = __esm({
|
|
|
13059
16389
|
this.journalPath = journalPath;
|
|
13060
16390
|
this.fs = fs3;
|
|
13061
16391
|
}
|
|
13062
|
-
journalPath;
|
|
13063
|
-
fs;
|
|
13064
16392
|
async init() {
|
|
13065
16393
|
await this.fs.mkdir(dirname2(this.journalPath), { recursive: true });
|
|
13066
16394
|
try {
|
|
@@ -13217,7 +16545,7 @@ var init_git = __esm({
|
|
|
13217
16545
|
import path25 from "node:path";
|
|
13218
16546
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
13219
16547
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13220
|
-
import { parse as
|
|
16548
|
+
import { parse as parse8 } from "yaml";
|
|
13221
16549
|
function isRecord6(value) {
|
|
13222
16550
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13223
16551
|
}
|
|
@@ -13234,7 +16562,7 @@ async function readOptionalFile2(fs3, filePath) {
|
|
|
13234
16562
|
function parseRunConfigDocument(filePath, content) {
|
|
13235
16563
|
let document;
|
|
13236
16564
|
try {
|
|
13237
|
-
document =
|
|
16565
|
+
document = parse8(content);
|
|
13238
16566
|
} catch (error2) {
|
|
13239
16567
|
const message2 = error2 instanceof Error ? error2.message : String(error2);
|
|
13240
16568
|
throw new Error(`Invalid experiment run config YAML in "${filePath}": ${message2}`);
|
|
@@ -13593,7 +16921,7 @@ async function runExperimentLoop(options) {
|
|
|
13593
16921
|
var init_loop = __esm({
|
|
13594
16922
|
"packages/experiment-loop/src/run/loop.ts"() {
|
|
13595
16923
|
"use strict";
|
|
13596
|
-
|
|
16924
|
+
init_frontmatter3();
|
|
13597
16925
|
init_git();
|
|
13598
16926
|
init_journal();
|
|
13599
16927
|
init_evaluator();
|
|
@@ -13607,7 +16935,7 @@ var init_src14 = __esm({
|
|
|
13607
16935
|
"packages/experiment-loop/src/index.ts"() {
|
|
13608
16936
|
"use strict";
|
|
13609
16937
|
init_types3();
|
|
13610
|
-
|
|
16938
|
+
init_frontmatter3();
|
|
13611
16939
|
init_journal();
|
|
13612
16940
|
init_evaluator();
|
|
13613
16941
|
init_git();
|
|
@@ -13864,7 +17192,7 @@ var init_client_instance = __esm({
|
|
|
13864
17192
|
});
|
|
13865
17193
|
|
|
13866
17194
|
// packages/github-workflows/src/frontmatter.ts
|
|
13867
|
-
import { parse as
|
|
17195
|
+
import { parse as parse9 } from "yaml";
|
|
13868
17196
|
function parseFrontmatter2(markdown) {
|
|
13869
17197
|
const content = markdown.startsWith("\uFEFF") ? markdown.slice(1) : markdown;
|
|
13870
17198
|
const openingLineBreak = readOpeningLineBreak(content);
|
|
@@ -13931,7 +17259,7 @@ function parseYamlFrontmatter(yamlBlock) {
|
|
|
13931
17259
|
const normalizedYamlBlock = yamlBlock.includes("\r") ? yamlBlock.replaceAll("\r\n", "\n").replaceAll("\r", "") : yamlBlock;
|
|
13932
17260
|
let parsed;
|
|
13933
17261
|
try {
|
|
13934
|
-
parsed =
|
|
17262
|
+
parsed = parse9(normalizedYamlBlock);
|
|
13935
17263
|
} catch (error2) {
|
|
13936
17264
|
const message2 = error2 instanceof Error ? error2.message : "Unknown YAML parse error";
|
|
13937
17265
|
throw new Error(`Invalid YAML frontmatter: ${message2}`);
|
|
@@ -13947,7 +17275,7 @@ function parseYamlFrontmatter(yamlBlock) {
|
|
|
13947
17275
|
function isRecord8(value) {
|
|
13948
17276
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13949
17277
|
}
|
|
13950
|
-
var
|
|
17278
|
+
var init_frontmatter4 = __esm({
|
|
13951
17279
|
"packages/github-workflows/src/frontmatter.ts"() {
|
|
13952
17280
|
"use strict";
|
|
13953
17281
|
}
|
|
@@ -14138,7 +17466,7 @@ var VALID_AUTHOR_ASSOCIATIONS;
|
|
|
14138
17466
|
var init_discover = __esm({
|
|
14139
17467
|
"packages/github-workflows/src/discover.ts"() {
|
|
14140
17468
|
"use strict";
|
|
14141
|
-
|
|
17469
|
+
init_frontmatter4();
|
|
14142
17470
|
VALID_AUTHOR_ASSOCIATIONS = /* @__PURE__ */ new Set([
|
|
14143
17471
|
"COLLABORATOR",
|
|
14144
17472
|
"CONTRIBUTOR",
|
|
@@ -14162,11 +17490,11 @@ function assertValidEnumValues(values) {
|
|
|
14162
17490
|
throw new Error("Enum schema values must be unique");
|
|
14163
17491
|
}
|
|
14164
17492
|
}
|
|
14165
|
-
var
|
|
17493
|
+
var S;
|
|
14166
17494
|
var init_src15 = __esm({
|
|
14167
17495
|
"packages/cmdkit-schema/src/index.ts"() {
|
|
14168
17496
|
"use strict";
|
|
14169
|
-
|
|
17497
|
+
S = {
|
|
14170
17498
|
String(options = {}) {
|
|
14171
17499
|
return {
|
|
14172
17500
|
kind: "string",
|
|
@@ -14931,7 +18259,7 @@ async function selectAutomationName(message2, automations) {
|
|
|
14931
18259
|
message: message2,
|
|
14932
18260
|
options: automations.map((a) => ({ label: a.label ?? formatLabel(a.name), value: a.name }))
|
|
14933
18261
|
});
|
|
14934
|
-
if (
|
|
18262
|
+
if (Ct(selected)) {
|
|
14935
18263
|
cancel("Operation cancelled.");
|
|
14936
18264
|
throw new UserError("Operation cancelled.");
|
|
14937
18265
|
}
|
|
@@ -14972,12 +18300,12 @@ var init_commands = __esm({
|
|
|
14972
18300
|
name: "run",
|
|
14973
18301
|
description: "Run a GitHub automation.",
|
|
14974
18302
|
positional: ["name"],
|
|
14975
|
-
params:
|
|
14976
|
-
name:
|
|
14977
|
-
agent:
|
|
14978
|
-
model:
|
|
14979
|
-
mode:
|
|
14980
|
-
cwd:
|
|
18303
|
+
params: S.Object({
|
|
18304
|
+
name: S.Optional(S.String()),
|
|
18305
|
+
agent: S.Optional(S.String()),
|
|
18306
|
+
model: S.Optional(S.String()),
|
|
18307
|
+
mode: S.Optional(S.Enum(["yolo", "edit", "read"])),
|
|
18308
|
+
cwd: S.Optional(S.String())
|
|
14981
18309
|
}),
|
|
14982
18310
|
secrets: {
|
|
14983
18311
|
poeApiKey: { env: "POE_API_KEY" },
|
|
@@ -15057,13 +18385,13 @@ var init_commands = __esm({
|
|
|
15057
18385
|
listCommand = defineCommand({
|
|
15058
18386
|
name: "list",
|
|
15059
18387
|
description: "List available automations.",
|
|
15060
|
-
params:
|
|
18388
|
+
params: S.Object({}),
|
|
15061
18389
|
scope: ["cli", "sdk"],
|
|
15062
18390
|
handler: async () => discoverAutomations(await resolveBuiltInPromptsDir(), ...projectPromptDirs(resolveCwd())),
|
|
15063
18391
|
render: {
|
|
15064
|
-
rich: (automations, { logger: logger2, renderTable:
|
|
18392
|
+
rich: (automations, { logger: logger2, renderTable: renderTable3, getTheme: getTheme2 }) => {
|
|
15065
18393
|
logger2.message(
|
|
15066
|
-
|
|
18394
|
+
renderTable3({
|
|
15067
18395
|
theme: getTheme2(),
|
|
15068
18396
|
columns: [
|
|
15069
18397
|
{ name: "name", title: "Name", alignment: "left", maxLen: 40 },
|
|
@@ -15085,21 +18413,21 @@ var init_commands = __esm({
|
|
|
15085
18413
|
name: "install",
|
|
15086
18414
|
description: "Install an automation workflow into the current repo.",
|
|
15087
18415
|
positional: ["name"],
|
|
15088
|
-
params:
|
|
15089
|
-
name:
|
|
18416
|
+
params: S.Object({
|
|
18417
|
+
name: S.Enum(installableAutomations, {
|
|
15090
18418
|
description: "Pick a GitHub workflow to install",
|
|
15091
18419
|
loadOptions: async () => {
|
|
15092
18420
|
const automations = await discoverAutomations(await resolveBuiltInPromptsDir());
|
|
15093
18421
|
return automations.map((a) => ({ label: a.label ?? formatLabel(a.name), value: a.name }));
|
|
15094
18422
|
}
|
|
15095
18423
|
}),
|
|
15096
|
-
eject:
|
|
18424
|
+
eject: S.Optional(S.Boolean())
|
|
15097
18425
|
}),
|
|
15098
18426
|
scope: ["cli"],
|
|
15099
18427
|
handler: async ({ params }) => {
|
|
15100
18428
|
const name = params.name;
|
|
15101
18429
|
const isEject = params.eject === true;
|
|
15102
|
-
const variant = "ejected";
|
|
18430
|
+
const variant = isEject ? "ejected" : "caller";
|
|
15103
18431
|
const cwd = resolveCwd();
|
|
15104
18432
|
const localAutomationName = isEject ? `poe-code-${name}` : name;
|
|
15105
18433
|
const promptPath = isEject ? path28.join(projectWorkflowDir(cwd), `${localAutomationName}.md`) : void 0;
|
|
@@ -15140,8 +18468,8 @@ var init_commands = __esm({
|
|
|
15140
18468
|
name: "uninstall",
|
|
15141
18469
|
description: "Remove an installed automation workflow from the current repo.",
|
|
15142
18470
|
positional: ["name"],
|
|
15143
|
-
params:
|
|
15144
|
-
name:
|
|
18471
|
+
params: S.Object({
|
|
18472
|
+
name: S.Enum(installableAutomations, {
|
|
15145
18473
|
description: "Pick a GitHub workflow to uninstall",
|
|
15146
18474
|
loadOptions: async () => {
|
|
15147
18475
|
const automations = await discoverAutomations(await resolveBuiltInPromptsDir());
|
|
@@ -15175,8 +18503,8 @@ var init_commands = __esm({
|
|
|
15175
18503
|
name: "require-user-allow",
|
|
15176
18504
|
description: "Fail when COMMENT_AUTHOR_ASSOCIATION is not allowed by the automation frontmatter.",
|
|
15177
18505
|
positional: ["name"],
|
|
15178
|
-
params:
|
|
15179
|
-
name:
|
|
18506
|
+
params: S.Object({
|
|
18507
|
+
name: S.String()
|
|
15180
18508
|
}),
|
|
15181
18509
|
scope: ["cli"],
|
|
15182
18510
|
handler: async ({ params, env }) => {
|
|
@@ -15189,8 +18517,8 @@ var init_commands = __esm({
|
|
|
15189
18517
|
name: "require-comment-prefix",
|
|
15190
18518
|
description: "Fail when COMMENT_BODY does not start with the automation prefix frontmatter.",
|
|
15191
18519
|
positional: ["name"],
|
|
15192
|
-
params:
|
|
15193
|
-
name:
|
|
18520
|
+
params: S.Object({
|
|
18521
|
+
name: S.String()
|
|
15194
18522
|
}),
|
|
15195
18523
|
scope: ["cli"],
|
|
15196
18524
|
handler: async ({ params, env }) => {
|
|
@@ -15203,8 +18531,8 @@ var init_commands = __esm({
|
|
|
15203
18531
|
name: "prepare",
|
|
15204
18532
|
description: "Install and configure the agent required by a workflow automation.",
|
|
15205
18533
|
positional: ["name"],
|
|
15206
|
-
params:
|
|
15207
|
-
name:
|
|
18534
|
+
params: S.Object({
|
|
18535
|
+
name: S.String()
|
|
15208
18536
|
}),
|
|
15209
18537
|
scope: ["cli"],
|
|
15210
18538
|
handler: async ({ params }) => {
|
|
@@ -15224,8 +18552,8 @@ var init_commands = __esm({
|
|
|
15224
18552
|
name: "prompt-preview",
|
|
15225
18553
|
description: "Preview the resolved prompt for an automation.",
|
|
15226
18554
|
positional: ["name"],
|
|
15227
|
-
params:
|
|
15228
|
-
name:
|
|
18555
|
+
params: S.Object({
|
|
18556
|
+
name: S.String()
|
|
15229
18557
|
}),
|
|
15230
18558
|
scope: ["cli", "sdk"],
|
|
15231
18559
|
handler: async ({ params, env }) => {
|
|
@@ -15265,7 +18593,7 @@ var init_commands = __esm({
|
|
|
15265
18593
|
var init_src17 = __esm({
|
|
15266
18594
|
"packages/github-workflows/src/index.ts"() {
|
|
15267
18595
|
"use strict";
|
|
15268
|
-
|
|
18596
|
+
init_frontmatter4();
|
|
15269
18597
|
init_discover();
|
|
15270
18598
|
init_commands();
|
|
15271
18599
|
init_check_user_allow();
|
|
@@ -18018,7 +21346,7 @@ async function* readLines3(stream) {
|
|
|
18018
21346
|
function isObjectRecord4(value) {
|
|
18019
21347
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18020
21348
|
}
|
|
18021
|
-
function
|
|
21349
|
+
function hasOwn3(value, property) {
|
|
18022
21350
|
return Object.prototype.hasOwnProperty.call(value, property);
|
|
18023
21351
|
}
|
|
18024
21352
|
function isRequestId2(value) {
|
|
@@ -18043,7 +21371,7 @@ function isJsonRpcErrorObject2(value) {
|
|
|
18043
21371
|
if (typeof value.code !== "number" || typeof value.message !== "string") {
|
|
18044
21372
|
return false;
|
|
18045
21373
|
}
|
|
18046
|
-
return value.data === void 0 ||
|
|
21374
|
+
return value.data === void 0 || hasOwn3(value, "data");
|
|
18047
21375
|
}
|
|
18048
21376
|
function parseJsonRpcPayload(parsed) {
|
|
18049
21377
|
if (!isObjectRecord4(parsed)) {
|
|
@@ -18061,8 +21389,8 @@ function parseJsonRpcPayload(parsed) {
|
|
|
18061
21389
|
error: invalidRequest2()
|
|
18062
21390
|
};
|
|
18063
21391
|
}
|
|
18064
|
-
const hasMethod =
|
|
18065
|
-
const hasId =
|
|
21392
|
+
const hasMethod = hasOwn3(parsed, "method");
|
|
21393
|
+
const hasId = hasOwn3(parsed, "id");
|
|
18066
21394
|
if (hasMethod) {
|
|
18067
21395
|
if (typeof parsed.method !== "string") {
|
|
18068
21396
|
return {
|
|
@@ -18084,7 +21412,7 @@ function parseJsonRpcPayload(parsed) {
|
|
|
18084
21412
|
id: parsed.id,
|
|
18085
21413
|
method: parsed.method
|
|
18086
21414
|
};
|
|
18087
|
-
if (
|
|
21415
|
+
if (hasOwn3(parsed, "params")) {
|
|
18088
21416
|
request.params = parsed.params;
|
|
18089
21417
|
}
|
|
18090
21418
|
return {
|
|
@@ -18096,7 +21424,7 @@ function parseJsonRpcPayload(parsed) {
|
|
|
18096
21424
|
jsonrpc: "2.0",
|
|
18097
21425
|
method: parsed.method
|
|
18098
21426
|
};
|
|
18099
|
-
if (
|
|
21427
|
+
if (hasOwn3(parsed, "params")) {
|
|
18100
21428
|
notification.params = parsed.params;
|
|
18101
21429
|
}
|
|
18102
21430
|
return {
|
|
@@ -18111,8 +21439,8 @@ function parseJsonRpcPayload(parsed) {
|
|
|
18111
21439
|
error: invalidRequest2()
|
|
18112
21440
|
};
|
|
18113
21441
|
}
|
|
18114
|
-
const hasResult =
|
|
18115
|
-
const hasError =
|
|
21442
|
+
const hasResult = hasOwn3(parsed, "result");
|
|
21443
|
+
const hasError = hasOwn3(parsed, "error");
|
|
18116
21444
|
if (hasResult === hasError) {
|
|
18117
21445
|
return {
|
|
18118
21446
|
type: "invalid",
|
|
@@ -18256,7 +21584,7 @@ var init_internal = __esm({
|
|
|
18256
21584
|
if (onLog === void 0 || !isObjectRecord4(params) || !isLogLevel(params.level)) {
|
|
18257
21585
|
return;
|
|
18258
21586
|
}
|
|
18259
|
-
if (!
|
|
21587
|
+
if (!hasOwn3(params, "data")) {
|
|
18260
21588
|
return;
|
|
18261
21589
|
}
|
|
18262
21590
|
const message2 = {
|
|
@@ -20177,7 +23505,7 @@ function renderResult(command, result, output, primitives, write2 = (chunk) => {
|
|
|
20177
23505
|
`);
|
|
20178
23506
|
}
|
|
20179
23507
|
}
|
|
20180
|
-
var
|
|
23508
|
+
var init_renderer3 = __esm({
|
|
20181
23509
|
"packages/cmdkit/src/renderer.ts"() {
|
|
20182
23510
|
"use strict";
|
|
20183
23511
|
}
|
|
@@ -20470,7 +23798,7 @@ function resolveHelpOutput(argv) {
|
|
|
20470
23798
|
}
|
|
20471
23799
|
}
|
|
20472
23800
|
}
|
|
20473
|
-
return
|
|
23801
|
+
return "rich";
|
|
20474
23802
|
}
|
|
20475
23803
|
function isNodeVisibleInScope(node, scope) {
|
|
20476
23804
|
if (node.kind === "command") {
|
|
@@ -20768,7 +24096,7 @@ async function promptForField(field) {
|
|
|
20768
24096
|
options,
|
|
20769
24097
|
initialValue: field.hasDefault ? field.defaultValue : void 0
|
|
20770
24098
|
});
|
|
20771
|
-
if (
|
|
24099
|
+
if (Ct(selected)) {
|
|
20772
24100
|
cancel("Operation cancelled.");
|
|
20773
24101
|
throw new UserError("Operation cancelled.");
|
|
20774
24102
|
}
|
|
@@ -20779,7 +24107,7 @@ async function promptForField(field) {
|
|
|
20779
24107
|
message: field.displayPath,
|
|
20780
24108
|
initialValue: field.hasDefault ? Boolean(field.defaultValue) : void 0
|
|
20781
24109
|
});
|
|
20782
|
-
if (
|
|
24110
|
+
if (Ct(selected)) {
|
|
20783
24111
|
cancel("Operation cancelled.");
|
|
20784
24112
|
throw new UserError("Operation cancelled.");
|
|
20785
24113
|
}
|
|
@@ -20789,7 +24117,7 @@ async function promptForField(field) {
|
|
|
20789
24117
|
message: field.displayPath,
|
|
20790
24118
|
initialValue: field.hasDefault && field.defaultValue !== void 0 ? formatResolvedValue(field.defaultValue) : void 0
|
|
20791
24119
|
});
|
|
20792
|
-
if (
|
|
24120
|
+
if (Ct(entered)) {
|
|
20793
24121
|
cancel("Operation cancelled.");
|
|
20794
24122
|
throw new UserError("Operation cancelled.");
|
|
20795
24123
|
}
|
|
@@ -20808,7 +24136,7 @@ function resolveOutput(globalFlags) {
|
|
|
20808
24136
|
if (globalFlags.output !== void 0) {
|
|
20809
24137
|
return globalFlags.output;
|
|
20810
24138
|
}
|
|
20811
|
-
return
|
|
24139
|
+
return "rich";
|
|
20812
24140
|
}
|
|
20813
24141
|
function toDesignSystemOutput(output) {
|
|
20814
24142
|
if (output === "md") {
|
|
@@ -21352,7 +24680,7 @@ async function executeCommand(state, services, requirementOptions) {
|
|
|
21352
24680
|
message: "Proceed?",
|
|
21353
24681
|
initialValue: true
|
|
21354
24682
|
});
|
|
21355
|
-
if (
|
|
24683
|
+
if (Ct(proceed)) {
|
|
21356
24684
|
cancel("Operation cancelled.");
|
|
21357
24685
|
throw new UserError("Operation cancelled.");
|
|
21358
24686
|
}
|
|
@@ -21437,7 +24765,7 @@ var init_cli = __esm({
|
|
|
21437
24765
|
"use strict";
|
|
21438
24766
|
init_src5();
|
|
21439
24767
|
init_src16();
|
|
21440
|
-
|
|
24768
|
+
init_renderer3();
|
|
21441
24769
|
RESERVED_SERVICE_NAMES = /* @__PURE__ */ new Set(["params", "secrets", "fetch", "fs", "env", "progress"]);
|
|
21442
24770
|
HELP_FLAGS = /* @__PURE__ */ new Set(["--help", "-h"]);
|
|
21443
24771
|
GLOBAL_LONG_OPTION_FLAGS = /* @__PURE__ */ new Set(["--preset", "--yes", "--output", "--verbose"]);
|
|
@@ -21561,7 +24889,7 @@ function createCliContainer(dependencies) {
|
|
|
21561
24889
|
checkAuth: async (apiKey) => await checkAuth({ apiKey }) !== null,
|
|
21562
24890
|
confirm: async (message2) => {
|
|
21563
24891
|
const result = await confirm2({ message: message2 });
|
|
21564
|
-
if (
|
|
24892
|
+
if (Ct(result)) {
|
|
21565
24893
|
cancel("Operation cancelled.");
|
|
21566
24894
|
throw new OperationCancelledError();
|
|
21567
24895
|
}
|
|
@@ -22243,11 +25571,11 @@ function registerSpawnCommand(program, container, options = {}) {
|
|
|
22243
25571
|
if (shouldEmitUiOutput) {
|
|
22244
25572
|
const trimmedStdout = final.stdout.trim();
|
|
22245
25573
|
if (trimmedStdout) {
|
|
22246
|
-
resources.logger.info(trimmedStdout);
|
|
25574
|
+
resources.logger.info(renderMarkdown(trimmedStdout).trimEnd());
|
|
22247
25575
|
} else {
|
|
22248
25576
|
const trimmedStderr = final.stderr.trim();
|
|
22249
25577
|
if (trimmedStderr) {
|
|
22250
|
-
resources.logger.info(trimmedStderr);
|
|
25578
|
+
resources.logger.info(renderMarkdown(trimmedStderr).trimEnd());
|
|
22251
25579
|
} else {
|
|
22252
25580
|
resources.logger.info(`${adapter.label} spawn completed.`);
|
|
22253
25581
|
}
|
|
@@ -22289,7 +25617,7 @@ async function confirmUnconfiguredService(container, service, label, flags) {
|
|
|
22289
25617
|
const shouldProceed = await confirm2({
|
|
22290
25618
|
message: `${label} is not configured via poe. Do you want to proceed?`
|
|
22291
25619
|
});
|
|
22292
|
-
if (
|
|
25620
|
+
if (Ct(shouldProceed)) {
|
|
22293
25621
|
throw new OperationCancelledError();
|
|
22294
25622
|
}
|
|
22295
25623
|
return shouldProceed === true;
|
|
@@ -23021,7 +26349,7 @@ function registerUtilsCommand(program, container) {
|
|
|
23021
26349
|
const utils = program.command("utils").description("Utility commands for inspecting and managing poe-code.");
|
|
23022
26350
|
registerConfigCommand(utils, container);
|
|
23023
26351
|
}
|
|
23024
|
-
var
|
|
26352
|
+
var init_utils3 = __esm({
|
|
23025
26353
|
"src/cli/commands/utils.ts"() {
|
|
23026
26354
|
"use strict";
|
|
23027
26355
|
init_config4();
|
|
@@ -23717,8 +27045,6 @@ var init_image = __esm({
|
|
|
23717
27045
|
this.base64Data = base64Data;
|
|
23718
27046
|
this.mimeType = mimeType;
|
|
23719
27047
|
}
|
|
23720
|
-
base64Data;
|
|
23721
|
-
mimeType;
|
|
23722
27048
|
static async fromUrl(url) {
|
|
23723
27049
|
const response = await fetch(url);
|
|
23724
27050
|
if (!response.ok) {
|
|
@@ -23793,8 +27119,6 @@ var init_audio = __esm({
|
|
|
23793
27119
|
this.base64Data = base64Data;
|
|
23794
27120
|
this.mimeType = mimeType;
|
|
23795
27121
|
}
|
|
23796
|
-
base64Data;
|
|
23797
|
-
mimeType;
|
|
23798
27122
|
static async fromUrl(url) {
|
|
23799
27123
|
const response = await fetch(url);
|
|
23800
27124
|
if (!response.ok) {
|
|
@@ -23865,10 +27189,6 @@ var init_file = __esm({
|
|
|
23865
27189
|
this.isText = isText;
|
|
23866
27190
|
this.name = name;
|
|
23867
27191
|
}
|
|
23868
|
-
data;
|
|
23869
|
-
mimeType;
|
|
23870
|
-
isText;
|
|
23871
|
-
name;
|
|
23872
27192
|
static async fromUrl(url) {
|
|
23873
27193
|
const response = await fetch(url);
|
|
23874
27194
|
if (!response.ok) {
|
|
@@ -25014,7 +28334,7 @@ function registerMcpCommand(program, container) {
|
|
|
25014
28334
|
message: "Select agent to configure:",
|
|
25015
28335
|
options: supportedAgents.map((a) => ({ value: a, label: a }))
|
|
25016
28336
|
});
|
|
25017
|
-
if (
|
|
28337
|
+
if (Ct(selected)) {
|
|
25018
28338
|
cancel("Operation cancelled");
|
|
25019
28339
|
return;
|
|
25020
28340
|
}
|
|
@@ -25367,7 +28687,7 @@ function registerSkillCommand(program, container) {
|
|
|
25367
28687
|
message: "Select agent to configure:",
|
|
25368
28688
|
options: supportedAgents2.map((a) => ({ value: a, label: a }))
|
|
25369
28689
|
});
|
|
25370
|
-
if (
|
|
28690
|
+
if (Ct(selected)) {
|
|
25371
28691
|
cancel("Operation cancelled");
|
|
25372
28692
|
return;
|
|
25373
28693
|
}
|
|
@@ -25400,7 +28720,7 @@ function registerSkillCommand(program, container) {
|
|
|
25400
28720
|
{ value: "local", label: "Local" }
|
|
25401
28721
|
]
|
|
25402
28722
|
});
|
|
25403
|
-
if (
|
|
28723
|
+
if (Ct(selected)) {
|
|
25404
28724
|
cancel("Operation cancelled");
|
|
25405
28725
|
return;
|
|
25406
28726
|
}
|
|
@@ -25446,7 +28766,7 @@ function registerSkillCommand(program, container) {
|
|
|
25446
28766
|
message: "Select agent to unconfigure:",
|
|
25447
28767
|
options: supportedAgents2.map((a) => ({ value: a, label: a }))
|
|
25448
28768
|
});
|
|
25449
|
-
if (
|
|
28769
|
+
if (Ct(selected)) {
|
|
25450
28770
|
cancel("Operation cancelled");
|
|
25451
28771
|
return;
|
|
25452
28772
|
}
|
|
@@ -25476,7 +28796,7 @@ function registerSkillCommand(program, container) {
|
|
|
25476
28796
|
{ value: "local", label: "Local" }
|
|
25477
28797
|
]
|
|
25478
28798
|
});
|
|
25479
|
-
if (
|
|
28799
|
+
if (Ct(selected)) {
|
|
25480
28800
|
cancel("Operation cancelled");
|
|
25481
28801
|
return;
|
|
25482
28802
|
}
|
|
@@ -25839,7 +29159,7 @@ function registerUsageCommand(program, container) {
|
|
|
25839
29159
|
startingAfter = result.data[result.data.length - 1].query_id;
|
|
25840
29160
|
if (maxPages === void 0) {
|
|
25841
29161
|
const shouldContinue = await confirm2({ message: "Load more?" });
|
|
25842
|
-
if (
|
|
29162
|
+
if (Ct(shouldContinue)) {
|
|
25843
29163
|
throw new OperationCancelledError();
|
|
25844
29164
|
}
|
|
25845
29165
|
if (!shouldContinue) {
|
|
@@ -26354,7 +29674,7 @@ function registerPipelineCommand(program, container) {
|
|
|
26354
29674
|
label: value
|
|
26355
29675
|
}))
|
|
26356
29676
|
});
|
|
26357
|
-
if (
|
|
29677
|
+
if (Ct(selected)) {
|
|
26358
29678
|
cancel("Pipeline run cancelled.");
|
|
26359
29679
|
return;
|
|
26360
29680
|
}
|
|
@@ -26371,6 +29691,20 @@ function registerPipelineCommand(program, container) {
|
|
|
26371
29691
|
...options.plan ? { plan: options.plan } : {},
|
|
26372
29692
|
...resolveMaxRuns(options.maxRuns) != null ? { maxRuns: resolveMaxRuns(options.maxRuns) } : {},
|
|
26373
29693
|
assumeYes: flags.assumeYes,
|
|
29694
|
+
async onBlocked({ taskId, stepName }) {
|
|
29695
|
+
if (flags.assumeYes) {
|
|
29696
|
+
return true;
|
|
29697
|
+
}
|
|
29698
|
+
const label = stepName ? `${taskId} (${stepName})` : taskId;
|
|
29699
|
+
const result2 = await confirm2({
|
|
29700
|
+
message: `Previous run failed at ${label}. Retry?`,
|
|
29701
|
+
initialValue: true
|
|
29702
|
+
});
|
|
29703
|
+
if (Ct(result2)) {
|
|
29704
|
+
return false;
|
|
29705
|
+
}
|
|
29706
|
+
return result2 === true;
|
|
29707
|
+
},
|
|
26374
29708
|
onPlanReloadError(error2) {
|
|
26375
29709
|
resources.logger.warn(`Plan reload failed, using last good state: ${error2.message}`);
|
|
26376
29710
|
},
|
|
@@ -26386,7 +29720,7 @@ function registerPipelineCommand(program, container) {
|
|
|
26386
29720
|
},
|
|
26387
29721
|
selectPlan: async (input) => {
|
|
26388
29722
|
const selected = await select2(input);
|
|
26389
|
-
if (
|
|
29723
|
+
if (Ct(selected)) {
|
|
26390
29724
|
cancel("Pipeline run cancelled.");
|
|
26391
29725
|
return null;
|
|
26392
29726
|
}
|
|
@@ -26394,7 +29728,7 @@ function registerPipelineCommand(program, container) {
|
|
|
26394
29728
|
},
|
|
26395
29729
|
promptForPath: async (input) => {
|
|
26396
29730
|
const value = await text3(input);
|
|
26397
|
-
if (
|
|
29731
|
+
if (Ct(value)) {
|
|
26398
29732
|
cancel("Pipeline run cancelled.");
|
|
26399
29733
|
return null;
|
|
26400
29734
|
}
|
|
@@ -26574,7 +29908,7 @@ function registerPipelineCommand(program, container) {
|
|
|
26574
29908
|
label: value
|
|
26575
29909
|
}))
|
|
26576
29910
|
});
|
|
26577
|
-
if (
|
|
29911
|
+
if (Ct(selected)) {
|
|
26578
29912
|
cancel("Pipeline install cancelled.");
|
|
26579
29913
|
return;
|
|
26580
29914
|
}
|
|
@@ -26600,7 +29934,7 @@ function registerPipelineCommand(program, container) {
|
|
|
26600
29934
|
{ value: "global", label: "Global" }
|
|
26601
29935
|
]
|
|
26602
29936
|
});
|
|
26603
|
-
if (
|
|
29937
|
+
if (Ct(selected)) {
|
|
26604
29938
|
cancel("Pipeline install cancelled.");
|
|
26605
29939
|
return;
|
|
26606
29940
|
}
|
|
@@ -26798,7 +30132,7 @@ async function resolveDocPath(options) {
|
|
|
26798
30132
|
value: doc.path
|
|
26799
30133
|
}))
|
|
26800
30134
|
});
|
|
26801
|
-
if (
|
|
30135
|
+
if (Ct(selected)) {
|
|
26802
30136
|
cancel("Ralph run cancelled.");
|
|
26803
30137
|
return null;
|
|
26804
30138
|
}
|
|
@@ -26842,7 +30176,7 @@ async function promptForAgent(program) {
|
|
|
26842
30176
|
value: config.agentId
|
|
26843
30177
|
}))
|
|
26844
30178
|
});
|
|
26845
|
-
if (
|
|
30179
|
+
if (Ct(selected)) {
|
|
26846
30180
|
cancel("Ralph run cancelled.");
|
|
26847
30181
|
return null;
|
|
26848
30182
|
}
|
|
@@ -26879,7 +30213,7 @@ async function resolveRunIterations(options) {
|
|
|
26879
30213
|
const entered = await text3({
|
|
26880
30214
|
message: "How many Ralph iterations should run?"
|
|
26881
30215
|
});
|
|
26882
|
-
if (
|
|
30216
|
+
if (Ct(entered)) {
|
|
26883
30217
|
cancel("Ralph run cancelled.");
|
|
26884
30218
|
return null;
|
|
26885
30219
|
}
|
|
@@ -26909,7 +30243,7 @@ async function resolveInitIterations(options) {
|
|
|
26909
30243
|
const entered = await text3({
|
|
26910
30244
|
message: "How many Ralph iterations should run?"
|
|
26911
30245
|
});
|
|
26912
|
-
if (
|
|
30246
|
+
if (Ct(entered)) {
|
|
26913
30247
|
cancel("Ralph init cancelled.");
|
|
26914
30248
|
return null;
|
|
26915
30249
|
}
|
|
@@ -27275,7 +30609,7 @@ async function resolveDocPath2(options) {
|
|
|
27275
30609
|
value: doc.path
|
|
27276
30610
|
}))
|
|
27277
30611
|
});
|
|
27278
|
-
if (
|
|
30612
|
+
if (Ct(selected)) {
|
|
27279
30613
|
cancel(options.cancelMessage);
|
|
27280
30614
|
return null;
|
|
27281
30615
|
}
|
|
@@ -27305,7 +30639,7 @@ async function promptForAgent2(program) {
|
|
|
27305
30639
|
value: config.agentId
|
|
27306
30640
|
}))
|
|
27307
30641
|
});
|
|
27308
|
-
if (
|
|
30642
|
+
if (Ct(selected)) {
|
|
27309
30643
|
cancel("Experiment run cancelled.");
|
|
27310
30644
|
return null;
|
|
27311
30645
|
}
|
|
@@ -27588,7 +30922,7 @@ function registerExperimentCommand(program, container) {
|
|
|
27588
30922
|
label: value
|
|
27589
30923
|
}))
|
|
27590
30924
|
});
|
|
27591
|
-
if (
|
|
30925
|
+
if (Ct(selected)) {
|
|
27592
30926
|
cancel("Experiment install cancelled.");
|
|
27593
30927
|
return;
|
|
27594
30928
|
}
|
|
@@ -27614,7 +30948,7 @@ function registerExperimentCommand(program, container) {
|
|
|
27614
30948
|
{ value: "global", label: "Global" }
|
|
27615
30949
|
]
|
|
27616
30950
|
});
|
|
27617
|
-
if (
|
|
30951
|
+
if (Ct(selected)) {
|
|
27618
30952
|
cancel("Experiment install cancelled.");
|
|
27619
30953
|
return;
|
|
27620
30954
|
}
|
|
@@ -27868,7 +31202,7 @@ async function resolveProcessId(value) {
|
|
|
27868
31202
|
const entered = await text3({
|
|
27869
31203
|
message: "Process ID"
|
|
27870
31204
|
});
|
|
27871
|
-
if (
|
|
31205
|
+
if (Ct(entered)) {
|
|
27872
31206
|
cancel("Launch start cancelled.");
|
|
27873
31207
|
return null;
|
|
27874
31208
|
}
|
|
@@ -27885,7 +31219,7 @@ async function resolveCommandParts(commandArgs) {
|
|
|
27885
31219
|
const entered = await text3({
|
|
27886
31220
|
message: "Command to run"
|
|
27887
31221
|
});
|
|
27888
|
-
if (
|
|
31222
|
+
if (Ct(entered)) {
|
|
27889
31223
|
cancel("Launch start cancelled.");
|
|
27890
31224
|
return null;
|
|
27891
31225
|
}
|
|
@@ -27909,7 +31243,7 @@ async function resolveRuntime(options) {
|
|
|
27909
31243
|
{ label: "docker", value: "docker" }
|
|
27910
31244
|
]
|
|
27911
31245
|
});
|
|
27912
|
-
if (
|
|
31246
|
+
if (Ct(selected)) {
|
|
27913
31247
|
cancel("Launch start cancelled.");
|
|
27914
31248
|
return null;
|
|
27915
31249
|
}
|
|
@@ -27922,7 +31256,7 @@ async function resolveDockerImage(value) {
|
|
|
27922
31256
|
const entered = await text3({
|
|
27923
31257
|
message: "Docker image"
|
|
27924
31258
|
});
|
|
27925
|
-
if (
|
|
31259
|
+
if (Ct(entered)) {
|
|
27926
31260
|
cancel("Launch start cancelled.");
|
|
27927
31261
|
return null;
|
|
27928
31262
|
}
|
|
@@ -27947,7 +31281,7 @@ async function resolveRestart(restart, assumeYes) {
|
|
|
27947
31281
|
{ label: "always", value: "always" }
|
|
27948
31282
|
]
|
|
27949
31283
|
});
|
|
27950
|
-
if (
|
|
31284
|
+
if (Ct(selected)) {
|
|
27951
31285
|
cancel("Launch start cancelled.");
|
|
27952
31286
|
return null;
|
|
27953
31287
|
}
|
|
@@ -28125,7 +31459,7 @@ var init_package = __esm({
|
|
|
28125
31459
|
"package.json"() {
|
|
28126
31460
|
package_default = {
|
|
28127
31461
|
name: "poe-code",
|
|
28128
|
-
version: "3.0.
|
|
31462
|
+
version: "3.0.145",
|
|
28129
31463
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
28130
31464
|
type: "module",
|
|
28131
31465
|
main: "./dist/index.js",
|
|
@@ -28675,7 +32009,7 @@ var init_program = __esm({
|
|
|
28675
32009
|
init_login();
|
|
28676
32010
|
init_logout();
|
|
28677
32011
|
init_auth();
|
|
28678
|
-
|
|
32012
|
+
init_utils3();
|
|
28679
32013
|
init_install();
|
|
28680
32014
|
init_unconfigure();
|
|
28681
32015
|
init_test();
|
|
@@ -28716,7 +32050,7 @@ function createPromptRunner(adapter = {
|
|
|
28716
32050
|
text: text3,
|
|
28717
32051
|
password: password2,
|
|
28718
32052
|
select: select2,
|
|
28719
|
-
isCancel:
|
|
32053
|
+
isCancel: Ct,
|
|
28720
32054
|
cancel
|
|
28721
32055
|
}) {
|
|
28722
32056
|
const runPrompt = async (descriptor) => {
|