@agentdocumentformat/cli 0.7.2
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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/adf.mjs +162 -0
- package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
- package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
- package/dist/chunks/App-L5L37JI5.mjs +16747 -0
- package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
- package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
- package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
- package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
- package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
- package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
- package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
- package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
- package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
- package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
- package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
- package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
- package/dist/chunks/build-QF5W473T.mjs +60 -0
- package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
- package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
- package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
- package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
- package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
- package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
- package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
- package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
- package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
- package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
- package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
- package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
- package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
- package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
- package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
- package/dist/chunks/chunk-776TSXEP.mjs +43 -0
- package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
- package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
- package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
- package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
- package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
- package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
- package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
- package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
- package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
- package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
- package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
- package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
- package/dist/chunks/chunk-G426FACA.mjs +49 -0
- package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
- package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
- package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
- package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
- package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
- package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
- package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
- package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
- package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
- package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
- package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
- package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
- package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
- package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
- package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
- package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
- package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
- package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
- package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
- package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
- package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
- package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
- package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
- package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
- package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
- package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
- package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
- package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
- package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
- package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
- package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
- package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
- package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
- package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
- package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
- package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
- package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
- package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
- package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
- package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
- package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
- package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
- package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
- package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
- package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
- package/dist/chunks/environment-NX277MQG.mjs +15 -0
- package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
- package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
- package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
- package/dist/chunks/open-OTQDGDH5.mjs +36 -0
- package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
- package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
- package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
- package/dist/chunks/screen-54BUTYCW.mjs +27 -0
- package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
- package/dist/chunks/store-WR7TZJZS.mjs +32 -0
- package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
- package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
- package/dist/chunks/theme-NORU4J74.mjs +20 -0
- package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
- package/dist/chunks/token-6G3HCMNX.mjs +54 -0
- package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
- package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
- package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
- package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
- package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
- package/package.json +53 -0
- package/resources/wasm/coreutils.LICENSE +18 -0
- package/resources/wasm/coreutils.wasm +0 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
|
|
8
|
+
// src/main/tools/shell/parser/tokenizer.ts
|
|
9
|
+
function parseBracedExpansion(content) {
|
|
10
|
+
let m = content.match(/^([A-Za-z_][A-Za-z0-9_]*|\?)/);
|
|
11
|
+
if (!m) return { name: content };
|
|
12
|
+
let name = m[1], rest = content.slice(name.length);
|
|
13
|
+
if (!rest) return { name };
|
|
14
|
+
let opMatch = rest.match(/^(:?[-=?+])/) ?? rest.match(/^(##|%%|[#%/^,])/);
|
|
15
|
+
return opMatch ? { name, op: opMatch[1], word: rest.slice(opMatch[1].length) } : { name: content };
|
|
16
|
+
}
|
|
17
|
+
function tokenize(input) {
|
|
18
|
+
let tokens = [], i = 0, len = input.length, lastEnd = -1, heredocMarkers = [], heredocPending = !1;
|
|
19
|
+
for (; i < len; ) {
|
|
20
|
+
let startPos = i, ch = input[i];
|
|
21
|
+
if (ch === " " || ch === " ") {
|
|
22
|
+
i++;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (ch === "#") {
|
|
26
|
+
for (; i < len && input[i] !== `
|
|
27
|
+
`; ) i++;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (ch === `
|
|
31
|
+
`) {
|
|
32
|
+
if (heredocPending && heredocMarkers.length > 0) {
|
|
33
|
+
let marker = heredocMarkers.shift(), bodyStart = i + 1, endPattern = `
|
|
34
|
+
` + marker, bodyEnd = input.indexOf(endPattern, bodyStart);
|
|
35
|
+
if (bodyEnd === -1) {
|
|
36
|
+
let altEnd = input.indexOf(marker, bodyStart);
|
|
37
|
+
altEnd !== -1 && (altEnd === bodyStart || input[altEnd - 1] === `
|
|
38
|
+
`) ? (bodyEnd = altEnd - 1, tokens.push({ type: "heredoc_body", value: input.slice(bodyStart, bodyEnd < bodyStart ? bodyStart : bodyEnd) }), i = altEnd + marker.length) : (tokens.push({ type: "heredoc_body", value: input.slice(bodyStart) }), i = len);
|
|
39
|
+
} else
|
|
40
|
+
tokens.push({ type: "heredoc_body", value: input.slice(bodyStart, bodyEnd) }), i = bodyEnd + endPattern.length;
|
|
41
|
+
heredocMarkers.length === 0 && (heredocPending = !1);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let last = tokens[tokens.length - 1];
|
|
45
|
+
tokens.length > 0 && last.type !== "semi" && last.type !== "amp" && tokens.push({ type: "semi", value: ";" }), i++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (i + 1 < len) {
|
|
49
|
+
let two = input[i] + input[i + 1];
|
|
50
|
+
if (two === "&&") {
|
|
51
|
+
tokens.push({ type: "and", value: "&&" }), i += 2;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (two === "||") {
|
|
55
|
+
tokens.push({ type: "or", value: "||" }), i += 2;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (two === ">>") {
|
|
59
|
+
tokens.push({ type: "redirect_append", value: ">>", ...startPos === lastEnd ? { glued: !0 } : {} }), i += 2;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (two === "<<") {
|
|
63
|
+
for (i += 2; i < len && (input[i] === " " || input[i] === " "); ) i++;
|
|
64
|
+
let quoteChar = "";
|
|
65
|
+
i < len && (input[i] === "'" || input[i] === '"') && (quoteChar = input[i], i++);
|
|
66
|
+
let tag = "";
|
|
67
|
+
for (; i < len && input[i] !== " " && input[i] !== " " && input[i] !== `
|
|
68
|
+
` && input[i] !== quoteChar; )
|
|
69
|
+
tag += input[i], i++;
|
|
70
|
+
quoteChar && i < len && input[i] === quoteChar && i++, tokens.push({ type: "heredoc_marker", value: tag, ...quoteChar ? { quoted: !0 } : {} }), heredocMarkers.push(tag), heredocPending = !0;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (ch === "|") {
|
|
75
|
+
tokens.push({ type: "pipe", value: "|" }), i++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (ch === ">") {
|
|
79
|
+
tokens.push({ type: "redirect_out", value: ">", ...startPos === lastEnd ? { glued: !0 } : {} }), i++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (ch === "<") {
|
|
83
|
+
tokens.push({ type: "redirect_in", value: "<", ...startPos === lastEnd ? { glued: !0 } : {} }), i++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ch === ";") {
|
|
87
|
+
tokens.push({ type: "semi", value: ";" }), i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (ch === "&") {
|
|
91
|
+
let prev = tokens[tokens.length - 1];
|
|
92
|
+
if (i + 1 < len && /[0-9]/.test(input[i + 1]) && prev && (prev.type === "redirect_out" || prev.type === "redirect_append" || prev.type === "redirect_in")) {
|
|
93
|
+
i++;
|
|
94
|
+
let fd = "";
|
|
95
|
+
for (; i < len && /[0-9]/.test(input[i]); )
|
|
96
|
+
fd += input[i], i++;
|
|
97
|
+
tokens.push({ type: "redirect_dup", value: fd });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
tokens.push({ type: "amp", value: "&" }), i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (ch === "$" && i + 1 < len && input[i + 1] === "(") {
|
|
104
|
+
i += 2;
|
|
105
|
+
let depth = 1, inner = "";
|
|
106
|
+
for (; i < len && depth > 0; ) {
|
|
107
|
+
if (input[i] === "(") depth++;
|
|
108
|
+
else if (input[i] === ")" && (depth--, depth === 0))
|
|
109
|
+
break;
|
|
110
|
+
inner += input[i], i++;
|
|
111
|
+
}
|
|
112
|
+
i < len && i++, tokens.push({ type: "substitution", value: inner, ...startPos === lastEnd ? { glued: !0 } : {} }), lastEnd = i;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (ch === "$" && i + 1 < len) {
|
|
116
|
+
let glued = startPos === lastEnd ? { glued: !0 } : {};
|
|
117
|
+
if (i++, input[i] === "{") {
|
|
118
|
+
i++;
|
|
119
|
+
let content = "";
|
|
120
|
+
for (; i < len && input[i] !== "}"; )
|
|
121
|
+
content += input[i], i++;
|
|
122
|
+
i < len && i++;
|
|
123
|
+
let exp = parseBracedExpansion(content);
|
|
124
|
+
tokens.push({
|
|
125
|
+
type: "variable",
|
|
126
|
+
value: exp.name,
|
|
127
|
+
...exp.op !== void 0 ? { op: exp.op, word: exp.word ?? "" } : {},
|
|
128
|
+
...glued
|
|
129
|
+
});
|
|
130
|
+
} else if (input[i] === "?")
|
|
131
|
+
i++, tokens.push({ type: "variable", value: "?", ...glued });
|
|
132
|
+
else {
|
|
133
|
+
let name = "";
|
|
134
|
+
for (; i < len && /[a-zA-Z0-9_]/.test(input[i]); )
|
|
135
|
+
name += input[i], i++;
|
|
136
|
+
name ? tokens.push({ type: "variable", value: name, ...glued }) : tokens.push({ type: "word", value: "$", ...glued });
|
|
137
|
+
}
|
|
138
|
+
lastEnd = i;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (ch === "'") {
|
|
142
|
+
i++;
|
|
143
|
+
let val = "";
|
|
144
|
+
for (; i < len && input[i] !== "'"; )
|
|
145
|
+
val += input[i], i++;
|
|
146
|
+
i < len && i++, tokens.push({ type: "single_quoted", value: val, ...startPos === lastEnd ? { glued: !0 } : {} }), lastEnd = i;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (ch === '"') {
|
|
150
|
+
i++;
|
|
151
|
+
let raw = "";
|
|
152
|
+
for (; i < len && input[i] !== '"'; )
|
|
153
|
+
if (input[i] === "\\" && i + 1 < len) {
|
|
154
|
+
let next = input[i + 1];
|
|
155
|
+
next === '"' || next === "\\" || next === "$" || next === "`" ? raw += next : raw += "\\" + next, i += 2;
|
|
156
|
+
} else
|
|
157
|
+
raw += input[i], i++;
|
|
158
|
+
i < len && i++, tokens.push({ type: "double_quoted", value: raw, raw, ...startPos === lastEnd ? { glued: !0 } : {} }), lastEnd = i;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (ch === "\\" && i + 1 < len) {
|
|
162
|
+
if (i++, input[i] === `
|
|
163
|
+
`) {
|
|
164
|
+
i++;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
tokens.push({ type: "word", value: input[i], ...startPos === lastEnd ? { glued: !0 } : {} }), i++, lastEnd = i;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
let word = "";
|
|
171
|
+
for (; i < len && input[i] !== " " && input[i] !== " " && input[i] !== `
|
|
172
|
+
` && input[i] !== "|" && input[i] !== ">" && input[i] !== "<" && input[i] !== ";" && input[i] !== "&" && input[i] !== "$" && input[i] !== '"' && input[i] !== "'" && input[i] !== "#" && input[i] !== "(" && input[i] !== ")"; )
|
|
173
|
+
input[i] === "\\" && i + 1 < len ? (word += input[i + 1], i += 2) : (word += input[i], i++);
|
|
174
|
+
word && (tokens.push({ type: "word", value: word, ...startPos === lastEnd ? { glued: !0 } : {} }), lastEnd = i), i === startPos && i++;
|
|
175
|
+
}
|
|
176
|
+
for (; tokens.length > 0 && tokens[tokens.length - 1].type === "semi"; )
|
|
177
|
+
tokens.pop();
|
|
178
|
+
return tokens.push({ type: "eof", value: "" }), tokens;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/main/tools/shell/parser/parser.ts
|
|
182
|
+
var ParseError = class extends Error {
|
|
183
|
+
constructor(msg) {
|
|
184
|
+
super(msg), this.name = "ParseError";
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
function classifyRedirectTarget(path) {
|
|
188
|
+
let normalized = path.replace(/^\.\//, "").replace(/^\//, "");
|
|
189
|
+
return normalized === "dev/null" ? "null" : normalized === "dev/stdout" ? "stdout" : normalized === "dev/stderr" ? "stderr" : null;
|
|
190
|
+
}
|
|
191
|
+
function unsupportedDevTargetMessage(special) {
|
|
192
|
+
return special === "stdout" ? "redirect to /dev/stdout is not supported in adf_shell; use 2>&1 to merge stderr into stdout" : "redirect to /dev/stderr is not supported in adf_shell; use >&2 to send stdout to stderr";
|
|
193
|
+
}
|
|
194
|
+
function staticStringOf(arg) {
|
|
195
|
+
switch (arg.type) {
|
|
196
|
+
case "literal":
|
|
197
|
+
return arg.value;
|
|
198
|
+
case "quoted": {
|
|
199
|
+
let out = "";
|
|
200
|
+
for (let part of arg.parts) {
|
|
201
|
+
let s = staticStringOf(part);
|
|
202
|
+
if (s === null) return null;
|
|
203
|
+
out += s;
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
default:
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var Parser = class _Parser {
|
|
212
|
+
tokens;
|
|
213
|
+
pos;
|
|
214
|
+
constructor(tokens) {
|
|
215
|
+
this.tokens = tokens, this.pos = 0;
|
|
216
|
+
}
|
|
217
|
+
peek() {
|
|
218
|
+
return this.tokens[this.pos] ?? { type: "eof", value: "" };
|
|
219
|
+
}
|
|
220
|
+
advance() {
|
|
221
|
+
let t = this.tokens[this.pos];
|
|
222
|
+
return this.pos++, t;
|
|
223
|
+
}
|
|
224
|
+
expect(type) {
|
|
225
|
+
let t = this.peek();
|
|
226
|
+
if (t.type !== type)
|
|
227
|
+
throw new ParseError(`Expected ${type}, got ${t.type} ("${t.value}")`);
|
|
228
|
+
return this.advance();
|
|
229
|
+
}
|
|
230
|
+
isChainOp(t) {
|
|
231
|
+
return t.type === "and" || t.type === "or" || t.type === "semi" || t.type === "amp";
|
|
232
|
+
}
|
|
233
|
+
isRedirect(t) {
|
|
234
|
+
return t.type === "redirect_out" || t.type === "redirect_append" || t.type === "redirect_in";
|
|
235
|
+
}
|
|
236
|
+
isArg(t) {
|
|
237
|
+
return t.type === "word" || t.type === "single_quoted" || t.type === "double_quoted" || t.type === "variable" || t.type === "substitution";
|
|
238
|
+
}
|
|
239
|
+
/** Validate a ${VAR<op>word} operator — only default expansion is supported */
|
|
240
|
+
checkExpansionOp(name, op) {
|
|
241
|
+
if (op !== "-" && op !== ":-")
|
|
242
|
+
throw new ParseError(
|
|
243
|
+
`\${${name}${op}...}: only \${VAR-default} and \${VAR:-default} expansion is supported in adf_shell`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
/** Parse a token into an ArgumentNode */
|
|
247
|
+
parseArg(t) {
|
|
248
|
+
switch (t.type) {
|
|
249
|
+
case "word":
|
|
250
|
+
return { type: "literal", value: t.value };
|
|
251
|
+
case "variable":
|
|
252
|
+
return t.op !== void 0 ? (this.checkExpansionOp(t.value, t.op), { type: "variable", name: t.value, op: t.op, word: t.word ?? "" }) : { type: "variable", name: t.value };
|
|
253
|
+
case "substitution":
|
|
254
|
+
return { type: "substitution", pipeline: this.parseSubstitution(t.value) };
|
|
255
|
+
case "single_quoted":
|
|
256
|
+
return { type: "quoted", quote: "single", parts: [{ type: "literal", value: t.value }] };
|
|
257
|
+
case "double_quoted":
|
|
258
|
+
return { type: "quoted", quote: "double", parts: this.parseDoubleQuoted(t.value) };
|
|
259
|
+
default:
|
|
260
|
+
throw new ParseError(`Unexpected token type ${t.type} in argument position`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** Parse a maximal run of GLUED word-like tokens starting at `first` into
|
|
264
|
+
* ONE argument. Bash treats adjacent unspaced segments as a single word
|
|
265
|
+
* (`gate_exit=$?`, `"pre"$VAR"post"`, `x$?y`) — emitting them as separate
|
|
266
|
+
* args split what the user wrote as one. All-literal runs collapse back to
|
|
267
|
+
* a single literal so unquoted glob characters still expand. */
|
|
268
|
+
parseGluedWord(first) {
|
|
269
|
+
let parts = [this.parseArg(first)];
|
|
270
|
+
for (; this.peek().glued && this.isArg(this.peek()); )
|
|
271
|
+
parts.push(this.parseArg(this.advance()));
|
|
272
|
+
return parts.length === 1 ? parts[0] : parts.every((p) => p.type === "literal") ? { type: "literal", value: parts.map((p) => p.value).join("") } : { type: "quoted", quote: "double", parts };
|
|
273
|
+
}
|
|
274
|
+
/** Parse the content of a double-quoted string into parts (literal + variable + substitution) */
|
|
275
|
+
parseDoubleQuoted(raw) {
|
|
276
|
+
let parts = [], i = 0, literal = "";
|
|
277
|
+
for (; i < raw.length; )
|
|
278
|
+
if (raw[i] === "$" && i + 1 < raw.length)
|
|
279
|
+
if (literal && (parts.push({ type: "literal", value: literal }), literal = ""), raw[i + 1] === "(") {
|
|
280
|
+
i += 2;
|
|
281
|
+
let depth = 1, inner = "";
|
|
282
|
+
for (; i < raw.length && depth > 0; ) {
|
|
283
|
+
if (raw[i] === "(") depth++;
|
|
284
|
+
else if (raw[i] === ")" && (depth--, depth === 0))
|
|
285
|
+
break;
|
|
286
|
+
inner += raw[i], i++;
|
|
287
|
+
}
|
|
288
|
+
i < raw.length && i++, parts.push({ type: "substitution", pipeline: this.parseSubstitution(inner) });
|
|
289
|
+
} else if (raw[i + 1] === "{") {
|
|
290
|
+
i += 2;
|
|
291
|
+
let content = "";
|
|
292
|
+
for (; i < raw.length && raw[i] !== "}"; )
|
|
293
|
+
content += raw[i], i++;
|
|
294
|
+
i < raw.length && i++;
|
|
295
|
+
let exp = parseBracedExpansion(content);
|
|
296
|
+
exp.op !== void 0 ? (this.checkExpansionOp(exp.name, exp.op), parts.push({ type: "variable", name: exp.name, op: exp.op, word: exp.word ?? "" })) : parts.push({ type: "variable", name: exp.name });
|
|
297
|
+
} else if (raw[i + 1] === "?")
|
|
298
|
+
i += 2, parts.push({ type: "variable", name: "?" });
|
|
299
|
+
else {
|
|
300
|
+
i++;
|
|
301
|
+
let name = "";
|
|
302
|
+
for (; i < raw.length && /[a-zA-Z0-9_]/.test(raw[i]); )
|
|
303
|
+
name += raw[i], i++;
|
|
304
|
+
name ? parts.push({ type: "variable", name }) : literal += "$";
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
literal += raw[i], i++;
|
|
308
|
+
return literal && parts.push({ type: "literal", value: literal }), parts.length > 0 ? parts : [{ type: "literal", value: "" }];
|
|
309
|
+
}
|
|
310
|
+
/** Parse a command substitution string into a PipelineNode */
|
|
311
|
+
parseSubstitution(inner) {
|
|
312
|
+
if (inner.startsWith("(") && inner.trimEnd().endsWith(")"))
|
|
313
|
+
throw new ParseError(
|
|
314
|
+
"arithmetic expansion $(( )) is not supported in adf_shell \u2014 use jq or a .js script"
|
|
315
|
+
);
|
|
316
|
+
let subTokens = tokenize(inner), node = new _Parser(subTokens).parseShell();
|
|
317
|
+
return node.kind === "pipeline" ? node : node.left;
|
|
318
|
+
}
|
|
319
|
+
// --- Grammar rules ---
|
|
320
|
+
parseShell() {
|
|
321
|
+
if (this.peek().type === "eof")
|
|
322
|
+
return { kind: "pipeline", stages: [] };
|
|
323
|
+
let node = this.parseChain(), rest = this.peek();
|
|
324
|
+
if (rest.type !== "eof")
|
|
325
|
+
throw new ParseError(`unexpected ${rest.type}${rest.value ? ` ("${rest.value}")` : ""} \u2014 the rest of the command was not understood`);
|
|
326
|
+
return node;
|
|
327
|
+
}
|
|
328
|
+
parseChain() {
|
|
329
|
+
let left = this.parsePipeline();
|
|
330
|
+
for (; this.isChainOp(this.peek()); ) {
|
|
331
|
+
let opToken = this.advance();
|
|
332
|
+
if (opToken.type === "amp")
|
|
333
|
+
throw new ParseError(
|
|
334
|
+
"background execution (&) is not supported in adf_shell; commands run in the foreground \u2014 remove the & or use && or ;"
|
|
335
|
+
);
|
|
336
|
+
let operator = opToken.value === "&&" ? "&&" : opToken.value === "||" ? "||" : ";";
|
|
337
|
+
if (operator !== ";")
|
|
338
|
+
for (; this.peek().type === "semi"; ) this.advance();
|
|
339
|
+
if (this.peek().type === "eof") return left;
|
|
340
|
+
let right = this.parseChain();
|
|
341
|
+
left = { kind: "chain", left, operator, right };
|
|
342
|
+
}
|
|
343
|
+
return left;
|
|
344
|
+
}
|
|
345
|
+
parsePipeline() {
|
|
346
|
+
let stages = [this.parseCommand()];
|
|
347
|
+
for (; this.peek().type === "pipe"; ) {
|
|
348
|
+
for (this.advance(); this.peek().type === "semi"; ) this.advance();
|
|
349
|
+
stages.push(this.parseCommand());
|
|
350
|
+
}
|
|
351
|
+
return { kind: "pipeline", stages };
|
|
352
|
+
}
|
|
353
|
+
parseCommand() {
|
|
354
|
+
let assignments = [];
|
|
355
|
+
for (; this.peek().type === "word" && /^[A-Za-z_][A-Za-z0-9_]*=/.test(this.peek().value); ) {
|
|
356
|
+
let tok = this.advance(), eq = tok.value.indexOf("="), parts = [], rest = tok.value.slice(eq + 1);
|
|
357
|
+
for (rest && parts.push({ type: "literal", value: rest }); this.peek().glued && this.isArg(this.peek()); )
|
|
358
|
+
parts.push(this.parseArg(this.advance()));
|
|
359
|
+
assignments.push({ name: tok.value.slice(0, eq), value: parts });
|
|
360
|
+
}
|
|
361
|
+
let nameToken = this.peek();
|
|
362
|
+
if (!this.isArg(nameToken) && nameToken.type !== "heredoc_marker") {
|
|
363
|
+
if (assignments.length > 0)
|
|
364
|
+
return { kind: "command", name: "", args: [], redirects: [], assignments };
|
|
365
|
+
throw new ParseError(`Expected command name, got ${nameToken.type} ("${nameToken.value}")`);
|
|
366
|
+
}
|
|
367
|
+
this.advance();
|
|
368
|
+
let name = nameToken.value, args = [], redirects = [], heredoc;
|
|
369
|
+
for (; this.peek().type !== "eof"; ) {
|
|
370
|
+
let t = this.peek();
|
|
371
|
+
if (t.type === "pipe" || this.isChainOp(t)) break;
|
|
372
|
+
if (this.isRedirect(t)) {
|
|
373
|
+
let fdNum = t.type === "redirect_in" ? 0 : 1;
|
|
374
|
+
if (t.glued && args.length > 0) {
|
|
375
|
+
let lastArg = args[args.length - 1];
|
|
376
|
+
lastArg.type === "literal" && /^[0-9]$/.test(lastArg.value) && (fdNum = parseInt(lastArg.value, 10), args.pop());
|
|
377
|
+
}
|
|
378
|
+
this.advance();
|
|
379
|
+
let targetToken = this.peek();
|
|
380
|
+
if (targetToken.type === "redirect_dup") {
|
|
381
|
+
this.advance(), t.type !== "redirect_in" && redirects.push({ type: "dup", fd: fdNum, targetFd: parseInt(targetToken.value, 10) });
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (!this.isArg(targetToken))
|
|
385
|
+
throw new ParseError(`Expected redirect target, got ${targetToken.type}`);
|
|
386
|
+
this.advance();
|
|
387
|
+
let targetArg = this.parseGluedWord(targetToken), staticTarget = staticStringOf(targetArg);
|
|
388
|
+
if (staticTarget !== null) {
|
|
389
|
+
let special = classifyRedirectTarget(staticTarget);
|
|
390
|
+
if (special === "null") {
|
|
391
|
+
redirects.push({ type: "discard", fd: fdNum });
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (special)
|
|
395
|
+
throw new ParseError(unsupportedDevTargetMessage(special));
|
|
396
|
+
}
|
|
397
|
+
let rType = t.type === "redirect_in" ? "in" : t.type === "redirect_append" ? "append" : "out", targetProp = staticTarget !== null ? { target: staticTarget } : { targetNode: targetArg };
|
|
398
|
+
rType === "in" ? redirects.push({ type: "in", ...targetProp }) : redirects.push({ type: rType, ...targetProp, ...fdNum !== 1 ? { fd: fdNum } : {} });
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (t.type === "heredoc_marker") {
|
|
402
|
+
if (t.value === "")
|
|
403
|
+
throw new ParseError("heredoc needs a tag: use `<< EOF` (or `<< 'EOF'` to keep the body literal) and end the body with EOF on its own line");
|
|
404
|
+
this.advance();
|
|
405
|
+
let bodyToken = this.peek(), quoted = t.quoted ? { quoted: !0 } : {};
|
|
406
|
+
bodyToken.type === "heredoc_body" ? (this.advance(), heredoc = { tag: t.value, content: bodyToken.value, ...quoted }) : heredoc = { tag: t.value, content: "", ...quoted };
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (this.isArg(t)) {
|
|
410
|
+
args.push(this.parseGluedWord(this.advance()));
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
kind: "command",
|
|
417
|
+
name,
|
|
418
|
+
args,
|
|
419
|
+
redirects,
|
|
420
|
+
heredoc,
|
|
421
|
+
...assignments.length > 0 ? { assignments } : {}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
function parse(input) {
|
|
426
|
+
let tokens = tokenize(input);
|
|
427
|
+
return new Parser(tokens).parseShell();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export {
|
|
431
|
+
parseBracedExpansion,
|
|
432
|
+
ParseError,
|
|
433
|
+
classifyRedirectTarget,
|
|
434
|
+
unsupportedDevTargetMessage,
|
|
435
|
+
parse
|
|
436
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
ID3v2Parser
|
|
9
|
+
} from "./chunk-XYTWGHFS.mjs";
|
|
10
|
+
import {
|
|
11
|
+
ID3v1Parser
|
|
12
|
+
} from "./chunk-VAUOM3IN.mjs";
|
|
13
|
+
import {
|
|
14
|
+
ID3v2Header
|
|
15
|
+
} from "./chunk-DXWDD5XJ.mjs";
|
|
16
|
+
import {
|
|
17
|
+
EndOfStreamError
|
|
18
|
+
} from "./chunk-HBUENVQL.mjs";
|
|
19
|
+
import {
|
|
20
|
+
BasicParser
|
|
21
|
+
} from "./chunk-I2HJYHFT.mjs";
|
|
22
|
+
import {
|
|
23
|
+
require_src
|
|
24
|
+
} from "./chunk-AUYKRQPJ.mjs";
|
|
25
|
+
import {
|
|
26
|
+
__toESM
|
|
27
|
+
} from "./chunk-M2RX3S2T.mjs";
|
|
28
|
+
|
|
29
|
+
// node_modules/music-metadata/lib/id3v2/AbstractID3Parser.js
|
|
30
|
+
var import_debug = __toESM(require_src(), 1);
|
|
31
|
+
var debug = (0, import_debug.default)("music-metadata:parser:ID3"), AbstractID3Parser = class extends BasicParser {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments), this.id3parser = new ID3v2Parser();
|
|
34
|
+
}
|
|
35
|
+
static async startsWithID3v2Header(tokenizer) {
|
|
36
|
+
return (await tokenizer.peekToken(ID3v2Header)).fileIdentifier === "ID3";
|
|
37
|
+
}
|
|
38
|
+
async parse() {
|
|
39
|
+
try {
|
|
40
|
+
await this.parseID3v2();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (err instanceof EndOfStreamError)
|
|
43
|
+
debug("End-of-stream");
|
|
44
|
+
else
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
finalize() {
|
|
49
|
+
}
|
|
50
|
+
async parseID3v2() {
|
|
51
|
+
await this.tryReadId3v2Headers(), debug("End of ID3v2 header, go to MPEG-parser: pos=%s", this.tokenizer.position), await this.postId3v2Parse(), this.options.skipPostHeaders && this.metadata.hasAny() ? this.finalize() : (await new ID3v1Parser(this.metadata, this.tokenizer, this.options).parse(), this.finalize());
|
|
52
|
+
}
|
|
53
|
+
async tryReadId3v2Headers() {
|
|
54
|
+
if ((await this.tokenizer.peekToken(ID3v2Header)).fileIdentifier === "ID3")
|
|
55
|
+
return debug("Found ID3v2 header, pos=%s", this.tokenizer.position), await this.id3parser.parse(this.metadata, this.tokenizer, this.options), this.tryReadId3v2Headers();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
AbstractID3Parser
|
|
61
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createRequire as __adfCreateRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __adfFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __adfDirname } from 'node:path';
|
|
4
|
+
const require = __adfCreateRequire(import.meta.url);
|
|
5
|
+
const __filename = __adfFileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __adfDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
__commonJS
|
|
9
|
+
} from "./chunk-M2RX3S2T.mjs";
|
|
10
|
+
|
|
11
|
+
// node_modules/fast-deep-equal/index.js
|
|
12
|
+
var require_fast_deep_equal = __commonJS({
|
|
13
|
+
"node_modules/fast-deep-equal/index.js"(exports, module) {
|
|
14
|
+
"use strict";
|
|
15
|
+
module.exports = function equal(a, b) {
|
|
16
|
+
if (a === b) return !0;
|
|
17
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
18
|
+
if (a.constructor !== b.constructor) return !1;
|
|
19
|
+
var length, i, keys;
|
|
20
|
+
if (Array.isArray(a)) {
|
|
21
|
+
if (length = a.length, length != b.length) return !1;
|
|
22
|
+
for (i = length; i-- !== 0; )
|
|
23
|
+
if (!equal(a[i], b[i])) return !1;
|
|
24
|
+
return !0;
|
|
25
|
+
}
|
|
26
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
27
|
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
28
|
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
29
|
+
if (keys = Object.keys(a), length = keys.length, length !== Object.keys(b).length) return !1;
|
|
30
|
+
for (i = length; i-- !== 0; )
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return !1;
|
|
32
|
+
for (i = length; i-- !== 0; ) {
|
|
33
|
+
var key = keys[i];
|
|
34
|
+
if (!equal(a[key], b[key])) return !1;
|
|
35
|
+
}
|
|
36
|
+
return !0;
|
|
37
|
+
}
|
|
38
|
+
return a !== a && b !== b;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
require_fast_deep_equal
|
|
45
|
+
};
|