just-bash 2.12.2 → 2.12.4
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/bin/chunks/awk2-RGDNV4HO.js +2 -0
- package/dist/bin/chunks/{base64-YXBFJFHG.js → base64-43M2R3GA.js} +1 -1
- package/dist/bin/{shell/chunks/cat-3J7U3HHI.js → chunks/cat-XZIJZXKP.js} +1 -1
- package/dist/bin/chunks/chunk-4C4F4EKM.js +2 -0
- package/dist/bin/{shell/chunks/chunk-MZKPWGID.js → chunks/chunk-54G6AE72.js} +23 -23
- package/dist/bin/chunks/chunk-55QIFSKH.js +36 -0
- package/dist/bin/chunks/chunk-6MF2IYQX.js +10 -0
- package/dist/bin/{shell/chunks/chunk-NEQEZ32M.js → chunks/chunk-CGE2EHYP.js} +3 -3
- package/dist/bin/chunks/chunk-DGFDVZ4N.js +21 -0
- package/dist/bin/chunks/chunk-EO5AH4U7.js +5 -0
- package/dist/bin/chunks/{chunk-2SIXTZCJ.js → chunk-EZS766DD.js} +4 -4
- package/dist/bin/{shell/chunks/chunk-THLAHQXV.js → chunks/chunk-FA2CHD73.js} +1 -1
- package/dist/bin/chunks/{chunk-BARKRZDC.js → chunk-GOJZHH3L.js} +1 -1
- package/dist/bin/chunks/{chunk-435ZOZCY.js → chunk-J4WYAO5Q.js} +1 -1
- package/dist/bin/chunks/chunk-LHN3LRVT.js +100 -0
- package/dist/bin/chunks/chunk-MRP4ZCD7.js +6 -0
- package/dist/bin/chunks/{chunk-JNPUO56K.js → chunk-NDP6L74Z.js} +1 -1
- package/dist/bin/chunks/chunk-PWZZGTFL.js +13 -0
- package/dist/bin/chunks/{chunk-3NVWSLHI.js → chunk-Q3FNZYGG.js} +99 -99
- package/dist/bin/{shell/chunks/chunk-7SWOLTCR.js → chunks/chunk-Q4WHWGOT.js} +1 -1
- package/dist/bin/chunks/chunk-SY2WM5RM.js +14 -0
- package/dist/bin/chunks/chunk-SYG3IW7P.js +2 -0
- package/dist/bin/chunks/chunk-SYL34GE7.js +21 -0
- package/dist/bin/chunks/{chunk-DREQRXNN.js → chunk-V5YFCVCZ.js} +1 -1
- package/dist/bin/chunks/chunk-V7VIJQD6.js +6 -0
- package/dist/bin/chunks/chunk-WMYKQURM.js +2 -0
- package/dist/bin/chunks/chunk-WO4B7WUT.js +2 -0
- package/dist/bin/{shell/chunks/chunk-5U7Q4GUC.js → chunks/chunk-WWZVR5NN.js} +4 -4
- package/dist/bin/chunks/{cut-HDHQDWRG.js → cut-5EY2XPXX.js} +1 -1
- package/dist/bin/chunks/expr-VEFRBJT4.js +2 -0
- package/dist/bin/chunks/flag-coverage-K6IBGWAC.js +2 -0
- package/dist/bin/chunks/{gzip-RQ5RIFJV.js → gzip-LHOO65AN.js} +1 -1
- package/dist/bin/chunks/jq-VBB2XIZS.js +2 -0
- package/dist/bin/chunks/ln-BEOFQJNP.js +2 -0
- package/dist/bin/chunks/python3-JX5PXXTX.js +17 -0
- package/dist/bin/chunks/sed-BYFYBR4A.js +2 -0
- package/dist/bin/chunks/sleep-E3K6M6BN.js +2 -0
- package/dist/bin/chunks/{sort-NZSEYCI6.js → sort-7GENYU2I.js} +1 -1
- package/dist/bin/chunks/sqlite3-SJHZFBT2.js +2 -0
- package/dist/bin/{shell/chunks/tar-VIYVHMER.js → chunks/tar-W5GBTEDZ.js} +1 -1
- package/dist/bin/chunks/time-AWAKKRSE.js +2 -0
- package/dist/bin/chunks/timeout-OLS72AZG.js +2 -0
- package/dist/bin/chunks/tr-LZF57GYP.js +2 -0
- package/dist/bin/chunks/{uniq-FZWFZEN5.js → uniq-TMSAIZM3.js} +1 -1
- package/dist/bin/chunks/worker.js +92 -29
- package/dist/bin/chunks/xan-BJ66NSYT.js +2 -0
- package/dist/bin/chunks/yq-GPYVGU2N.js +2 -0
- package/dist/bin/just-bash.js +294 -294
- package/dist/bin/shell/chunks/awk2-RGDNV4HO.js +2 -0
- package/dist/bin/shell/chunks/{base64-YXBFJFHG.js → base64-43M2R3GA.js} +1 -1
- package/dist/bin/{chunks/cat-3J7U3HHI.js → shell/chunks/cat-XZIJZXKP.js} +1 -1
- package/dist/bin/shell/chunks/chunk-4C4F4EKM.js +2 -0
- package/dist/bin/{chunks/chunk-MZKPWGID.js → shell/chunks/chunk-54G6AE72.js} +23 -23
- package/dist/bin/shell/chunks/chunk-55QIFSKH.js +36 -0
- package/dist/bin/shell/chunks/chunk-6MF2IYQX.js +10 -0
- package/dist/bin/{chunks/chunk-NEQEZ32M.js → shell/chunks/chunk-CGE2EHYP.js} +3 -3
- package/dist/bin/shell/chunks/chunk-DGFDVZ4N.js +21 -0
- package/dist/bin/shell/chunks/chunk-EO5AH4U7.js +5 -0
- package/dist/bin/shell/chunks/{chunk-2SIXTZCJ.js → chunk-EZS766DD.js} +4 -4
- package/dist/bin/{chunks/chunk-THLAHQXV.js → shell/chunks/chunk-FA2CHD73.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-BARKRZDC.js → chunk-GOJZHH3L.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-435ZOZCY.js → chunk-J4WYAO5Q.js} +1 -1
- package/dist/bin/shell/chunks/chunk-LHN3LRVT.js +100 -0
- package/dist/bin/shell/chunks/chunk-MRP4ZCD7.js +6 -0
- package/dist/bin/shell/chunks/{chunk-JNPUO56K.js → chunk-NDP6L74Z.js} +1 -1
- package/dist/bin/shell/chunks/chunk-PWZZGTFL.js +13 -0
- package/dist/bin/shell/chunks/{chunk-3NVWSLHI.js → chunk-Q3FNZYGG.js} +99 -99
- package/dist/bin/{chunks/chunk-7SWOLTCR.js → shell/chunks/chunk-Q4WHWGOT.js} +1 -1
- package/dist/bin/shell/chunks/chunk-SY2WM5RM.js +14 -0
- package/dist/bin/shell/chunks/chunk-SYG3IW7P.js +2 -0
- package/dist/bin/shell/chunks/chunk-SYL34GE7.js +21 -0
- package/dist/bin/shell/chunks/{chunk-DREQRXNN.js → chunk-V5YFCVCZ.js} +1 -1
- package/dist/bin/shell/chunks/chunk-V7VIJQD6.js +6 -0
- package/dist/bin/shell/chunks/chunk-WMYKQURM.js +2 -0
- package/dist/bin/shell/chunks/chunk-WO4B7WUT.js +2 -0
- package/dist/bin/{chunks/chunk-5U7Q4GUC.js → shell/chunks/chunk-WWZVR5NN.js} +4 -4
- package/dist/bin/shell/chunks/{cut-HDHQDWRG.js → cut-5EY2XPXX.js} +1 -1
- package/dist/bin/shell/chunks/expr-VEFRBJT4.js +2 -0
- package/dist/bin/shell/chunks/flag-coverage-K6IBGWAC.js +2 -0
- package/dist/bin/shell/chunks/{gzip-RQ5RIFJV.js → gzip-LHOO65AN.js} +1 -1
- package/dist/bin/shell/chunks/jq-VBB2XIZS.js +2 -0
- package/dist/bin/shell/chunks/ln-BEOFQJNP.js +2 -0
- package/dist/bin/shell/chunks/python3-JX5PXXTX.js +17 -0
- package/dist/bin/shell/chunks/sed-BYFYBR4A.js +2 -0
- package/dist/bin/shell/chunks/sleep-E3K6M6BN.js +2 -0
- package/dist/bin/shell/chunks/{sort-NZSEYCI6.js → sort-7GENYU2I.js} +1 -1
- package/dist/bin/shell/chunks/sqlite3-SJHZFBT2.js +2 -0
- package/dist/bin/{chunks/tar-VIYVHMER.js → shell/chunks/tar-W5GBTEDZ.js} +1 -1
- package/dist/bin/shell/chunks/time-AWAKKRSE.js +2 -0
- package/dist/bin/shell/chunks/timeout-OLS72AZG.js +2 -0
- package/dist/bin/shell/chunks/tr-LZF57GYP.js +2 -0
- package/dist/bin/shell/chunks/{uniq-FZWFZEN5.js → uniq-TMSAIZM3.js} +1 -1
- package/dist/bin/shell/chunks/xan-BJ66NSYT.js +2 -0
- package/dist/bin/shell/chunks/yq-GPYVGU2N.js +2 -0
- package/dist/bin/shell/shell.js +234 -234
- package/dist/bundle/browser.js +671 -671
- package/dist/bundle/chunks/awk2-XLDR2J4Q.js +1 -0
- package/dist/bundle/chunks/{base64-A3SGWC34.js → base64-4YMZCVJ5.js} +1 -1
- package/dist/bundle/chunks/{cat-C2OBLGHA.js → cat-RDUMLXKC.js} +1 -1
- package/dist/bundle/chunks/chunk-2OHMPZNZ.js +20 -0
- package/dist/bundle/chunks/chunk-3RCXHB4E.js +4 -0
- package/dist/bundle/chunks/chunk-CCNMISUL.js +1 -0
- package/dist/bundle/chunks/chunk-DOTBQEPN.js +5 -0
- package/dist/bundle/chunks/chunk-GENDESYN.js +1 -0
- package/dist/bundle/chunks/chunk-H4QOE4W3.js +99 -0
- package/dist/bundle/chunks/{chunk-C6ZZC5FL.js → chunk-K5BTXJQC.js} +99 -99
- package/dist/bundle/chunks/chunk-KAZYKNBG.js +13 -0
- package/dist/bundle/chunks/{chunk-KAEMRWOH.js → chunk-KMEYNNUA.js} +1 -1
- package/dist/bundle/chunks/{chunk-FO655G4V.js → chunk-LTZRCH7N.js} +23 -23
- package/dist/bundle/chunks/{chunk-XULIVM35.js → chunk-N4QLRJ32.js} +1 -1
- package/dist/bundle/chunks/{chunk-5CJQNRNJ.js → chunk-NTP6TTH5.js} +1 -1
- package/dist/bundle/chunks/{chunk-IBFD7QQD.js → chunk-QJ7O6ZN3.js} +1 -1
- package/dist/bundle/chunks/chunk-QUME7R6S.js +9 -0
- package/dist/bundle/chunks/{chunk-U7QI5ZS5.js → chunk-RVT3MU3A.js} +4 -4
- package/dist/bundle/chunks/{chunk-6NY2AP72.js → chunk-SDNKECQQ.js} +4 -4
- package/dist/bundle/chunks/chunk-T2EHE3CV.js +1 -0
- package/dist/bundle/chunks/chunk-TBAWQWQB.js +12 -0
- package/dist/bundle/chunks/chunk-TXBZCHCQ.js +5 -0
- package/dist/bundle/chunks/chunk-VYV3YE2F.js +35 -0
- package/dist/bundle/chunks/{chunk-UJIR5V54.js → chunk-W42IGK5R.js} +1 -1
- package/dist/bundle/chunks/{chunk-7BQDVPII.js → chunk-WAN3B6E3.js} +1 -1
- package/dist/bundle/chunks/{chunk-7C6RBHP3.js → chunk-WKFATFPP.js} +3 -3
- package/dist/bundle/chunks/chunk-XXZ46GOX.js +20 -0
- package/dist/bundle/chunks/chunk-ZK6J6F7O.js +1 -0
- package/dist/bundle/chunks/{cut-LO6YYY5P.js → cut-OPC3VAGB.js} +1 -1
- package/dist/bundle/chunks/expr-74QHYJL5.js +1 -0
- package/dist/bundle/chunks/flag-coverage-VGF5NAZP.js +1 -0
- package/dist/bundle/chunks/{gzip-Y4N2UKE7.js → gzip-AQXSGOVS.js} +1 -1
- package/dist/bundle/chunks/jq-JQXAVWNT.js +1 -0
- package/dist/bundle/chunks/ln-RI2SJGXU.js +1 -0
- package/dist/bundle/chunks/python3-TSPOVUHX.js +16 -0
- package/dist/bundle/chunks/sed-CJFW7UYO.js +1 -0
- package/dist/bundle/chunks/sleep-TFDNFOXK.js +1 -0
- package/dist/bundle/chunks/{sort-T7TNLWXL.js → sort-DCNRDA7U.js} +1 -1
- package/dist/bundle/chunks/sqlite3-CTI4ZW7L.js +1 -0
- package/dist/bundle/chunks/{tar-E2DVQEWO.js → tar-Y6LP5EBC.js} +1 -1
- package/dist/bundle/chunks/time-WBKSMCJ6.js +1 -0
- package/dist/bundle/chunks/timeout-O7WSXY5H.js +1 -0
- package/dist/bundle/chunks/tr-GVTWMRZB.js +1 -0
- package/dist/bundle/chunks/{uniq-ZXE4O5XB.js → uniq-SUNANL47.js} +1 -1
- package/dist/bundle/chunks/worker.js +92 -29
- package/dist/bundle/chunks/xan-VMLUNIDS.js +1 -0
- package/dist/bundle/chunks/yq-QXIYE3MW.js +1 -0
- package/dist/bundle/index.cjs +852 -852
- package/dist/bundle/index.js +242 -242
- package/dist/commands/awk/interpreter/context.d.ts +2 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +2 -0
- package/dist/commands/query-engine/evaluator.d.ts +3 -0
- package/dist/interpreter/defense-aware-command-context.d.ts +6 -0
- package/dist/interpreter/interpreter.d.ts +8 -0
- package/dist/interpreter/types.d.ts +5 -0
- package/dist/timers.d.ts +2 -11
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
- package/dist/bin/chunks/awk2-ZE5HJBNV.js +0 -2
- package/dist/bin/chunks/chunk-2FFXXW3F.js +0 -14
- package/dist/bin/chunks/chunk-4E3LY6YK.js +0 -10
- package/dist/bin/chunks/chunk-4FNW6LFM.js +0 -5
- package/dist/bin/chunks/chunk-4PZYIYYG.js +0 -36
- package/dist/bin/chunks/chunk-6L4K3UGO.js +0 -100
- package/dist/bin/chunks/chunk-EPIOK4SY.js +0 -6
- package/dist/bin/chunks/chunk-IYZRLSTQ.js +0 -2
- package/dist/bin/chunks/chunk-JJHAWOIB.js +0 -2
- package/dist/bin/chunks/chunk-K47SEEPI.js +0 -6
- package/dist/bin/chunks/chunk-KPWFKFSD.js +0 -21
- package/dist/bin/chunks/chunk-RYXW3SZQ.js +0 -13
- package/dist/bin/chunks/chunk-VZKEP45B.js +0 -21
- package/dist/bin/chunks/expr-MLHUWFYI.js +0 -2
- package/dist/bin/chunks/flag-coverage-LQ37DA4R.js +0 -2
- package/dist/bin/chunks/jq-CXSPO2J5.js +0 -2
- package/dist/bin/chunks/ln-5TCJXDGY.js +0 -2
- package/dist/bin/chunks/python3-74B25WCY.js +0 -17
- package/dist/bin/chunks/sed-DNLJZZXZ.js +0 -2
- package/dist/bin/chunks/sleep-GUJH2AMQ.js +0 -2
- package/dist/bin/chunks/sqlite3-57UI7HYL.js +0 -2
- package/dist/bin/chunks/time-FAWHHOMA.js +0 -2
- package/dist/bin/chunks/timeout-4O4YYRTS.js +0 -2
- package/dist/bin/chunks/tr-4V5A3V2C.js +0 -2
- package/dist/bin/chunks/xan-7NIVZ3HP.js +0 -2
- package/dist/bin/chunks/yq-L5ZSGLLO.js +0 -2
- package/dist/bin/shell/chunks/awk2-ZE5HJBNV.js +0 -2
- package/dist/bin/shell/chunks/chunk-2FFXXW3F.js +0 -14
- package/dist/bin/shell/chunks/chunk-4E3LY6YK.js +0 -10
- package/dist/bin/shell/chunks/chunk-4FNW6LFM.js +0 -5
- package/dist/bin/shell/chunks/chunk-4PZYIYYG.js +0 -36
- package/dist/bin/shell/chunks/chunk-6L4K3UGO.js +0 -100
- package/dist/bin/shell/chunks/chunk-EPIOK4SY.js +0 -6
- package/dist/bin/shell/chunks/chunk-IYZRLSTQ.js +0 -2
- package/dist/bin/shell/chunks/chunk-JJHAWOIB.js +0 -2
- package/dist/bin/shell/chunks/chunk-K47SEEPI.js +0 -6
- package/dist/bin/shell/chunks/chunk-KPWFKFSD.js +0 -21
- package/dist/bin/shell/chunks/chunk-RYXW3SZQ.js +0 -13
- package/dist/bin/shell/chunks/chunk-VZKEP45B.js +0 -21
- package/dist/bin/shell/chunks/expr-MLHUWFYI.js +0 -2
- package/dist/bin/shell/chunks/flag-coverage-LQ37DA4R.js +0 -2
- package/dist/bin/shell/chunks/jq-CXSPO2J5.js +0 -2
- package/dist/bin/shell/chunks/ln-5TCJXDGY.js +0 -2
- package/dist/bin/shell/chunks/python3-74B25WCY.js +0 -17
- package/dist/bin/shell/chunks/sed-DNLJZZXZ.js +0 -2
- package/dist/bin/shell/chunks/sleep-GUJH2AMQ.js +0 -2
- package/dist/bin/shell/chunks/sqlite3-57UI7HYL.js +0 -2
- package/dist/bin/shell/chunks/time-FAWHHOMA.js +0 -2
- package/dist/bin/shell/chunks/timeout-4O4YYRTS.js +0 -2
- package/dist/bin/shell/chunks/tr-4V5A3V2C.js +0 -2
- package/dist/bin/shell/chunks/xan-7NIVZ3HP.js +0 -2
- package/dist/bin/shell/chunks/yq-L5ZSGLLO.js +0 -2
- package/dist/bundle/chunks/awk2-T6LHPVZE.js +0 -1
- package/dist/bundle/chunks/chunk-5BFLZVGH.js +0 -20
- package/dist/bundle/chunks/chunk-7DBA735O.js +0 -5
- package/dist/bundle/chunks/chunk-7KHLIOOW.js +0 -4
- package/dist/bundle/chunks/chunk-AOFQVUAD.js +0 -99
- package/dist/bundle/chunks/chunk-BAAVD5NO.js +0 -20
- package/dist/bundle/chunks/chunk-BEFDX7IY.js +0 -1
- package/dist/bundle/chunks/chunk-KPFCTJEX.js +0 -12
- package/dist/bundle/chunks/chunk-LN5KAJOV.js +0 -5
- package/dist/bundle/chunks/chunk-NBAARP4B.js +0 -1
- package/dist/bundle/chunks/chunk-RHOPHAL6.js +0 -35
- package/dist/bundle/chunks/chunk-SL4FN3A5.js +0 -9
- package/dist/bundle/chunks/chunk-YIY2RKBW.js +0 -13
- package/dist/bundle/chunks/expr-3572LAOT.js +0 -1
- package/dist/bundle/chunks/flag-coverage-MPLWXQQK.js +0 -1
- package/dist/bundle/chunks/jq-MYSLFARY.js +0 -1
- package/dist/bundle/chunks/ln-YAIFIHCT.js +0 -1
- package/dist/bundle/chunks/python3-6BKA3FYA.js +0 -16
- package/dist/bundle/chunks/sed-3ZCNFRHI.js +0 -1
- package/dist/bundle/chunks/sleep-LB7FI6AB.js +0 -1
- package/dist/bundle/chunks/sqlite3-FVNA4KNF.js +0 -1
- package/dist/bundle/chunks/time-AGNW2ZY6.js +0 -1
- package/dist/bundle/chunks/timeout-VN35D5O7.js +0 -1
- package/dist/bundle/chunks/tr-2N7Q3KKJ.js +0 -1
- package/dist/bundle/chunks/xan-VTO4FP3H.js +0 -1
- package/dist/bundle/chunks/yq-JRZFRYSK.js +0 -1
|
@@ -55,6 +55,7 @@ export interface AwkRuntimeContext {
|
|
|
55
55
|
exitCode: number;
|
|
56
56
|
}>;
|
|
57
57
|
coverage?: FeatureCoverageWriter;
|
|
58
|
+
requireDefenseContext?: boolean;
|
|
58
59
|
}
|
|
59
60
|
export interface CreateContextOptions {
|
|
60
61
|
fieldSep?: RegexLike;
|
|
@@ -69,5 +70,6 @@ export interface CreateContextOptions {
|
|
|
69
70
|
exitCode: number;
|
|
70
71
|
}>;
|
|
71
72
|
coverage?: FeatureCoverageWriter;
|
|
73
|
+
requireDefenseContext?: boolean;
|
|
72
74
|
}
|
|
73
75
|
export declare function createRuntimeContext(options?: CreateContextOptions): AwkRuntimeContext;
|
|
@@ -10,6 +10,8 @@ export declare class AwkInterpreter {
|
|
|
10
10
|
private program;
|
|
11
11
|
private rangeStates;
|
|
12
12
|
constructor(ctx: AwkRuntimeContext);
|
|
13
|
+
private assertDefenseContext;
|
|
14
|
+
private withDefenseContext;
|
|
13
15
|
/**
|
|
14
16
|
* Initialize the interpreter with a program.
|
|
15
17
|
* Must be called before executeBegin/executeLine/executeEnd.
|
|
@@ -16,6 +16,8 @@ export interface EvalContext {
|
|
|
16
16
|
vars: Map<string, QueryValue>;
|
|
17
17
|
limits: Required<Pick<QueryExecutionLimits, "maxIterations">> & QueryExecutionLimits;
|
|
18
18
|
env?: Map<string, string>;
|
|
19
|
+
requireDefenseContext?: boolean;
|
|
20
|
+
defenseContextChecked?: boolean;
|
|
19
21
|
/** Original document root for parent/root navigation */
|
|
20
22
|
root?: QueryValue;
|
|
21
23
|
/** Current path from root for parent navigation */
|
|
@@ -33,5 +35,6 @@ export interface EvaluateOptions {
|
|
|
33
35
|
limits?: QueryExecutionLimits;
|
|
34
36
|
env?: Map<string, string>;
|
|
35
37
|
coverage?: FeatureCoverageWriter;
|
|
38
|
+
requireDefenseContext?: boolean;
|
|
36
39
|
}
|
|
37
40
|
export declare function evaluate(value: QueryValue, ast: AstNode, ctxOrOptions?: EvalContext | EvaluateOptions): QueryValue[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandContext } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Wrap command context APIs so async boundaries are fail-closed if defense
|
|
4
|
+
* context is expected but missing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createDefenseAwareCommandContext(ctx: CommandContext, commandName: string): CommandContext;
|
|
@@ -34,10 +34,18 @@ export interface InterpreterOptions {
|
|
|
34
34
|
trace?: TraceCallback;
|
|
35
35
|
/** Optional feature coverage writer for fuzzing instrumentation */
|
|
36
36
|
coverage?: FeatureCoverageWriter;
|
|
37
|
+
/**
|
|
38
|
+
* When true, fail closed if execution occurs outside defense async context.
|
|
39
|
+
*/
|
|
40
|
+
requireDefenseContext?: boolean;
|
|
37
41
|
}
|
|
38
42
|
export declare class Interpreter {
|
|
39
43
|
private ctx;
|
|
40
44
|
constructor(options: InterpreterOptions, state: InterpreterState);
|
|
45
|
+
/**
|
|
46
|
+
* Fail closed if defense is expected but async context is missing.
|
|
47
|
+
*/
|
|
48
|
+
private assertDefenseContext;
|
|
41
49
|
/**
|
|
42
50
|
* Build environment record containing only exported variables.
|
|
43
51
|
* In bash, only exported variables are passed to child processes.
|
|
@@ -328,4 +328,9 @@ export interface InterpreterContext {
|
|
|
328
328
|
substitutionDepth?: number;
|
|
329
329
|
/** Optional feature coverage writer for fuzzing instrumentation */
|
|
330
330
|
coverage?: FeatureCoverageWriter;
|
|
331
|
+
/**
|
|
332
|
+
* When true, interpreter execution must run inside DefenseInDepthBox
|
|
333
|
+
* sandbox async context. Used to fail closed on context-loss bugs.
|
|
334
|
+
*/
|
|
335
|
+
requireDefenseContext?: boolean;
|
|
331
336
|
}
|
package/dist/timers.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pre-captured global references.
|
|
3
|
-
*
|
|
4
|
-
* Defense-in-depth replaces dangerous globals with blocking proxies during
|
|
5
|
-
* bash execution. These pre-captured references are taken at module load
|
|
6
|
-
* time (before defense patches are applied) so that just-bash's own
|
|
7
|
-
* infrastructure can use them safely.
|
|
8
|
-
*
|
|
9
|
-
* IMPORTANT: This module must be imported eagerly (at Bash construction time),
|
|
10
|
-
* not lazily during exec(), to ensure the capture happens before patching.
|
|
11
|
-
*/
|
|
12
1
|
export declare const _setTimeout: typeof globalThis.setTimeout;
|
|
13
2
|
export declare const _clearTimeout: typeof globalThis.clearTimeout;
|
|
3
|
+
export declare const _setInterval: typeof globalThis.setInterval;
|
|
4
|
+
export declare const _clearInterval: typeof globalThis.clearInterval;
|
|
14
5
|
export declare const _SharedArrayBuffer: typeof globalThis.SharedArrayBuffer;
|
|
15
6
|
export declare const _Atomics: typeof globalThis.Atomics;
|
|
16
7
|
export declare const _performanceNow: () => number;
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export interface ExecResult {
|
|
|
14
14
|
exitCode: number;
|
|
15
15
|
/** The final environment variables after execution (only set by BashEnv.exec) */
|
|
16
16
|
env?: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Encoding hint for stdout content when writing to files via redirections.
|
|
19
|
+
* Set to "binary" by commands that produce binary output (e.g., cat, gzip)
|
|
20
|
+
* to prevent re-encoding of raw byte data as UTF-8.
|
|
21
|
+
* When not set, the redirect system uses UTF-8 for non-ASCII text.
|
|
22
|
+
*/
|
|
23
|
+
stdoutEncoding?: "binary";
|
|
17
24
|
}
|
|
18
25
|
/** Result from BashEnv.exec() - always includes env */
|
|
19
26
|
export interface BashExecResult extends ExecResult {
|
|
@@ -157,6 +164,12 @@ export interface CommandContext {
|
|
|
157
164
|
* should forward this signal so cooperative cancellation propagates.
|
|
158
165
|
*/
|
|
159
166
|
signal?: AbortSignal;
|
|
167
|
+
/**
|
|
168
|
+
* When true, command execution must remain inside DefenseInDepthBox
|
|
169
|
+
* async context. Commands with async boundaries should assert this
|
|
170
|
+
* before and after awaited operations.
|
|
171
|
+
*/
|
|
172
|
+
requireDefenseContext?: boolean;
|
|
160
173
|
}
|
|
161
174
|
export interface Command {
|
|
162
175
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as p}from"./chunk-4OALHZXB.js";import{e as m}from"./chunk-JJHAWOIB.js";import{a as c}from"./chunk-4PRVMER6.js";var M={name:"time",async execute(r,i){let a="%e %M",o=null,f=!1,u=!1,t=0;for(;t<r.length;){let e=r[t];if(e==="-f"||e==="--format"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-f'
|
|
3
|
-
`,exitCode:1};a=r[t],t++}else if(e==="-o"||e==="--output"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-o'
|
|
4
|
-
`,exitCode:1};o=r[t],t++}else if(e==="-a"||e==="--append")f=!0,t++;else if(e==="-v"||e==="--verbose")a=`Command being timed: %C
|
|
5
|
-
Elapsed (wall clock) time: %e seconds
|
|
6
|
-
Maximum resident set size (kbytes): %M`,t++;else if(e==="-p"||e==="--portability")u=!0,t++;else if(e==="--"){t++;break}else if(e.startsWith("-"))t++;else break}let l=r.slice(t);if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let g=m(),h=p(l),w=l.join(" "),s;try{if(!i.exec)return{stdout:"",stderr:`time: exec not available
|
|
7
|
-
`,exitCode:1};s=await i.exec(h,{env:c(i.env),cwd:i.cwd,stdin:i.stdin,signal:i.signal})}catch(e){s={stdout:"",stderr:`time: ${e.message}
|
|
8
|
-
`,exitCode:127}}let d=(m()-g)/1e3,n;if(u?n=`real ${d.toFixed(2)}
|
|
9
|
-
user 0.00
|
|
10
|
-
sys 0.00
|
|
11
|
-
`:(n=a.replace(/%e/g,d.toFixed(2)).replace(/%E/g,F(d)).replace(/%M/g,"0").replace(/%S/g,"0.00").replace(/%U/g,"0.00").replace(/%P/g,"0%").replace(/%C/g,w),n.endsWith(`
|
|
12
|
-
`)||(n+=`
|
|
13
|
-
`)),o)try{let e=i.fs.resolvePath(i.cwd,o);if(f&&await i.fs.exists(e)){let C=await i.fs.readFile(e);await i.fs.writeFile(e,C+n)}else await i.fs.writeFile(e,n)}catch(e){return{stdout:s.stdout,stderr:s.stderr+`time: cannot write to '${o}': ${e.message}
|
|
14
|
-
`,exitCode:s.exitCode}}else s={...s,stderr:s.stderr+n};return s}};function F(r){let i=Math.floor(r/3600),a=Math.floor(r%3600/60),o=r%60;return i>0?`${i}:${a.toString().padStart(2,"0")}:${o.toFixed(2).padStart(5,"0")}`:`${a}:${o.toFixed(2).padStart(5,"0")}`}var S={name:"time",flags:[{flag:"-p",type:"boolean"}],needsArgs:!0};export{M as a,S as b};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as m,b as h}from"./chunk-GTNBSMZR.js";var g={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},p={name:"ln",async execute(n,s){if(h(n))return m(g);let l=!1,a=!1,f=!1,t=0;for(;t<n.length&&n[t].startsWith("-");){let e=n[t];if(e==="-s"||e==="--symbolic")l=!0,t++;else if(e==="-f"||e==="--force")a=!0,t++;else if(e==="-v"||e==="--verbose")f=!0,t++;else if(e==="-n"||e==="--no-dereference")t++;else if(/^-[sfvn]+$/.test(e))e.includes("s")&&(l=!0),e.includes("f")&&(a=!0),e.includes("v")&&(f=!0),t++;else if(e==="--"){t++;break}else return{stdout:"",stderr:`ln: invalid option -- '${e.slice(1)}'
|
|
3
|
-
`,exitCode:1}}let d=n.slice(t);if(d.length<2)return{stdout:"",stderr:`ln: missing file operand
|
|
4
|
-
`,exitCode:1};let i=d[0],r=d[1],o=s.fs.resolvePath(s.cwd,r);if(await s.fs.exists(o))if(a)try{await s.fs.rm(o,{force:!0})}catch{return{stdout:"",stderr:`ln: cannot remove '${r}': Permission denied
|
|
5
|
-
`,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${l?"symbolic ":""}link '${r}': File exists
|
|
6
|
-
`,exitCode:1};try{if(l)await s.fs.symlink(i,o);else{let e=s.fs.resolvePath(s.cwd,i);if(!await s.fs.exists(e))return{stdout:"",stderr:`ln: failed to access '${i}': No such file or directory
|
|
7
|
-
`,exitCode:1};await s.fs.link(e,o)}}catch(e){let u=e;return u.message.includes("EPERM")?{stdout:"",stderr:`ln: '${i}': hard link not allowed for directory
|
|
8
|
-
`,exitCode:1}:{stdout:"",stderr:`ln: ${u.message}
|
|
9
|
-
`,exitCode:1}}let c="";return f&&(c=`'${r}' -> '${i}'
|
|
10
|
-
`),{stdout:c,stderr:"",exitCode:0}}},b={name:"ln",flags:[{flag:"-s",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2};export{p as a,b};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as g}from"./chunk-KGOUQS5A.js";function m(){let c=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables",allowedKeys:new Set(["NODE_V8_COVERAGE","NODE_DEBUG","NODE_DEBUG_NATIVE","NODE_COMPILE_CACHE","WATCH_REPORT_DEPENDENCIES","FORCE_COLOR","DEBUG","UNDICI_NO_FG","JEST_WORKER_ID","__MINIMATCH_TESTING_PLATFORM__","LOG_TOKENS","LOG_STREAM"])},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"getBuiltinModule",target:process,violationType:"process_get_builtin_module",strategy:"throw",reason:"process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"},{prop:"exit",target:process,violationType:"process_exit",strategy:"throw",reason:"process.exit could terminate the interpreter"},{prop:"abort",target:process,violationType:"process_exit",strategy:"throw",reason:"process.abort could crash the interpreter"},{prop:"kill",target:process,violationType:"process_kill",strategy:"throw",reason:"process.kill could signal other processes"},{prop:"setuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setuid could escalate privileges"},{prop:"setgid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgid could escalate privileges"},{prop:"umask",target:process,violationType:"process_umask",strategy:"throw",reason:"process.umask could modify file creation permissions"},{prop:"argv",target:process,violationType:"process_argv",strategy:"throw",reason:"process.argv may contain secrets in CLI arguments"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"send",target:process,violationType:"process_send",strategy:"throw",reason:"process.send could communicate with parent process in IPC contexts"},{prop:"channel",target:process,violationType:"process_channel",strategy:"throw",reason:"process.channel could access IPC channel to parent process"},{prop:"cpuUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.cpuUsage could enable timing side-channel attacks"},{prop:"memoryUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.memoryUsage could enable timing side-channel attacks"},{prop:"hrtime",target:process,violationType:"process_timing",strategy:"throw",reason:"process.hrtime could enable timing side-channel attacks"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"},{prop:"performance",target:globalThis,violationType:"performance_timing",strategy:"throw",reason:"performance.now() provides sub-millisecond timing for side-channel attacks"},{prop:"stdout",target:process,violationType:"process_stdout",strategy:"throw",reason:"process.stdout could bypass interpreter output to write to host stdout"},{prop:"stderr",target:process,violationType:"process_stderr",strategy:"throw",reason:"process.stderr could bypass interpreter output to write to host stderr"},{prop:"__defineGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineGetter__ allows prototype pollution via getter injection"},{prop:"__defineSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineSetter__ allows prototype pollution via setter injection"},{prop:"__lookupGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupGetter__ enables introspection for prototype pollution attacks"},{prop:"__lookupSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupSetter__ enables introspection for prototype pollution attacks"},{prop:"JSON",target:globalThis,violationType:"json_mutation",strategy:"freeze",reason:"Freeze JSON to prevent mutation of parsing/serialization"},{prop:"Math",target:globalThis,violationType:"math_mutation",strategy:"freeze",reason:"Freeze Math to prevent mutation of math utilities"}];try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let e=Object.getPrototypeOf(async function*(){}).constructor;e&&e!==Function&&e!==Object.getPrototypeOf(async()=>{}).constructor&&c.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return c.filter(e=>{try{return e.target[e.prop]!==void 0}catch{return!1}})}var h=typeof __BROWSER__<"u"&&__BROWSER__;function _(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,c=>{let e=Math.random()*16|0;return(c==="x"?e:e&3|8).toString(16)})}var b=null;if(!h)try{let{AsyncLocalStorage:c}=g("node:async_hooks");b=c}catch{}var w=`
|
|
3
|
-
|
|
4
|
-
This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,p=class extends Error{violation;constructor(e,t){super(e+w),this.violation=t,this.name="SecurityViolationError"}},l=!h&&b?new b:null,T=1e3,y={enabled:!0,auditMode:!1};function k(c){return c===void 0?{...y,enabled:!1}:typeof c=="boolean"?{...y,enabled:c}:{...y,...c}}var x=class c{static instance=null;static importHooksRegistered=!1;config;refCount=0;patchFailures=[];originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(e){this.config=e}static getInstance(e){let t=k(e);if(!c.instance)c.instance=new c(t);else{let r=c.instance.config;if(t.enabled!==r.enabled||t.auditMode!==r.auditMode)throw new Error(`DefenseInDepthBox config conflict: requested {enabled: ${t.enabled}, auditMode: ${t.auditMode}} but singleton already has {enabled: ${r.enabled}, auditMode: ${r.auditMode}}. All Bash instances must use the same defense-in-depth security settings, or call DefenseInDepthBox.resetInstance() between incompatible configurations.`)}return c.instance}static resetInstance(){c.instance&&(c.instance.forceDeactivate(),c.instance=null)}static isInSandboxedContext(){return l?l?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(l)return l?.getStore()?.executionId}isEnabled(){return this.config.enabled===!0&&l!==null&&!h}updateConfig(e){this.config={...this.config,...e}}activate(){if(h||!this.config.enabled||!l){let t=_();return{run:r=>r(),deactivate:()=>{},executionId:t}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let e=_();return{run:t=>l.run({sandboxActive:!0,executionId:e},t),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:e}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}getPatchFailures(){return[...this.patchFailures]}clearViolations(){this.violations=[]}getPathForTarget(e,t){return e===globalThis?`globalThis.${t}`:e===process?`process.${t}`:e===Error?`Error.${t}`:e===Function.prototype?`Function.prototype.${t}`:e===Object.prototype?`Object.prototype.${t}`:`<object>.${t}`}static runTrusted(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}static async runTrustedAsync(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}shouldBlock(){if(h||this.config.auditMode||!l)return!1;let e=l?.getStore();return!(e?.sandboxActive!==!0||e.trusted)}recordViolation(e,t,r){let s={timestamp:Date.now(),type:e,message:r,path:t,stack:new Error().stack,executionId:l?.getStore()?.executionId};if(this.violations.length<T&&this.violations.push(s),this.config.onViolation)try{this.config.onViolation(s)}catch(o){console.debug("[DefenseInDepthBox] onViolation callback threw:",o instanceof Error?o.message:o)}return s}createBlockingProxy(e,t,r){let s=this;return new Proxy(e,{apply(o,n,i){if(s.shouldBlock()){let a=`${t} is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} called (audit mode)`),Reflect.apply(o,n,i)},construct(o,n,i){if(s.shouldBlock()){let a=`${t} constructor is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} constructor called (audit mode)`),Reflect.construct(o,n,i)}})}createBlockingObjectProxy(e,t,r,s){let o=this;return new Proxy(e,{get(n,i,a){if(o.shouldBlock()){if(s&&typeof i=="string"&&s.has(i))return Reflect.get(n,i,a);let u=`${t}.${String(i)}`,d=`${u} is blocked during script execution`,f=o.recordViolation(r,u,d);throw new p(d,f)}if(o.config.auditMode&&l?.getStore()?.sandboxActive===!0){let u=`${t}.${String(i)}`;o.recordViolation(r,u,`${u} accessed (audit mode)`)}return Reflect.get(n,i,a)},set(n,i,a,u){if(o.shouldBlock()){let d=`${t}.${String(i)}`,f=`${d} modification is blocked during script execution`,v=o.recordViolation(r,d,f);throw new p(f,v)}return Reflect.set(n,i,a,u)},ownKeys(n){if(o.shouldBlock()){let i=`${t} enumeration is blocked during script execution`,a=o.recordViolation(r,t,i);throw new p(i,a)}return Reflect.ownKeys(n)},getOwnPropertyDescriptor(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} descriptor access is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.getOwnPropertyDescriptor(n,i)},has(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} existence check is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.has(n,i)}})}applyPatches(){this.patchFailures=[];let e=m(),t=new Set(["process_send","process_channel","process_stdout","process_stderr"]);for(let o of e)t.has(o.violationType)||this.applyPatch(o);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectDynamicImport(),this.protectModuleLoad(),this.protectModuleResolveFilename(),this.protectProcessMainModule(),this.protectProcessExecPath();let r=["Function.prototype.constructor","Module._load"],s=this.patchFailures.filter(o=>r.includes(o));if(s.length>0)throw this.restorePatches(),new Error(`DefenseInDepthBox: critical patches failed: ${s.join(", ")}`)}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(e){this.patchFailures.push("AsyncFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(e){this.patchFailures.push("GeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(async function*(){}).constructor,t=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&e!==t&&this.patchPrototypeConstructor(e.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(e){this.patchFailures.push("AsyncGeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}}protectErrorPrepareStackTrace(){let e=this;try{let t=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:t});let r=t?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return r},set(s){if(e.shouldBlock()){let o="Error.prepareStackTrace modification is blocked during script execution",n=e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",o);throw new p(o,n)}e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),r=s},configurable:!0})}catch(t){this.patchFailures.push("Error.prepareStackTrace"),console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",t instanceof Error?t.message:t)}}patchPrototypeConstructor(e,t,r){let s=this;try{let o=Object.getOwnPropertyDescriptor(e,"constructor");this.originalDescriptors.push({target:e,prop:"constructor",descriptor:o});let n=o?.value;Object.defineProperty(e,"constructor",{get(){if(s.shouldBlock()){let i=`${t} access is blocked during script execution`,a=s.recordViolation(r,t,i);throw new p(i,a)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} accessed (audit mode)`),n},set(i){if(s.shouldBlock()){let a=`${t} modification is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}Object.defineProperty(this,"constructor",{value:i,writable:!0,configurable:!0})},configurable:!0})}catch(o){this.patchFailures.push(t),console.debug(`[DefenseInDepthBox] Could not patch ${t}:`,o instanceof Error?o.message:o)}}protectProcessMainModule(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:t});let r=t?.value;r!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(e.shouldBlock()){let s="process.mainModule access is blocked during script execution",o=e.recordViolation("process_main_module","process.mainModule",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.mainModule modification is blocked during script execution",n=e.recordViolation("process_main_module","process.mainModule",o);throw new p(o,n)}Object.defineProperty(process,"mainModule",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.mainModule"),console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",t instanceof Error?t.message:t)}}protectProcessExecPath(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"execPath");this.originalDescriptors.push({target:process,prop:"execPath",descriptor:t});let r=t?.value??process.execPath;Object.defineProperty(process,"execPath",{get(){if(e.shouldBlock()){let s="process.execPath access is blocked during script execution",o=e.recordViolation("process_exec_path","process.execPath",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_exec_path","process.execPath","process.execPath accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.execPath modification is blocked during script execution",n=e.recordViolation("process_exec_path","process.execPath",o);throw new p(o,n)}Object.defineProperty(process,"execPath",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.execPath"),console.debug("[DefenseInDepthBox] Could not protect process.execPath:",t instanceof Error?t.message:t)}}protectDynamicImport(){if(!(h||c.importHooksRegistered))try{let e=g("node:module");if(typeof e.registerHooks=="function"){e.registerHooks({resolve(t,r,s){if(t.startsWith("data:")||t.startsWith("blob:"))throw new Error(`dynamic import of ${t.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);return s(t,r)}}),c.importHooksRegistered=!0;return}if(typeof e.register=="function"){let t=["export async function resolve(specifier, context, nextResolve) {",' if (specifier.startsWith("data:") || specifier.startsWith("blob:")) {',' throw new Error("dynamic import of " + (specifier.startsWith("data:") ? "data:" : "blob:") + " URLs is blocked by defense-in-depth");'," }"," return nextResolve(specifier, context);","}"].join(`
|
|
5
|
-
`);e.register(`data:text/javascript,${encodeURIComponent(t)}`),c.importHooksRegistered=!0}}catch(e){console.debug("[DefenseInDepthBox] Could not register import() hooks:",e instanceof Error?e.message:e)}}protectModuleLoad(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._load!="function")return;let t=e._load,r=Object.getOwnPropertyDescriptor(e,"_load");this.originalDescriptors.push({target:e,prop:"_load",descriptor:r});let o=this.createBlockingProxy(t,"Module._load","module_load");Object.defineProperty(e,"_load",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._load"),console.debug("[DefenseInDepthBox] Could not protect Module._load:",e instanceof Error?e.message:e)}}protectModuleResolveFilename(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._resolveFilename!="function")return;let t=e._resolveFilename,r=Object.getOwnPropertyDescriptor(e,"_resolveFilename");this.originalDescriptors.push({target:e,prop:"_resolveFilename",descriptor:r});let o=this.createBlockingProxy(t,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(e,"_resolveFilename",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._resolveFilename"),console.debug("[DefenseInDepthBox] Could not protect Module._resolveFilename:",e instanceof Error?e.message:e)}}applyPatch(e){let{target:t,prop:r,violationType:s,strategy:o}=e;try{let n=t[r];if(n===void 0)return;let i=Object.getOwnPropertyDescriptor(t,r);if(this.originalDescriptors.push({target:t,prop:r,descriptor:i}),o==="freeze")typeof n=="object"&&n!==null&&Object.freeze(n);else{let a=this.getPathForTarget(t,r),u=typeof n=="function"?this.createBlockingProxy(n,a,s):this.createBlockingObjectProxy(n,a,s,e.allowedKeys);Object.defineProperty(t,r,{value:u,writable:!0,configurable:!0})}}catch(n){let i=this.getPathForTarget(t,r);this.patchFailures.push(i),console.debug(`[DefenseInDepthBox] Could not patch ${i}:`,n instanceof Error?n.message:n)}}restorePatches(){for(let e=this.originalDescriptors.length-1;e>=0;e--){let{target:t,prop:r,descriptor:s}=this.originalDescriptors[e];try{s?Object.defineProperty(t,r,s):delete t[r]}catch(o){let n=this.getPathForTarget(t,r);console.debug(`[DefenseInDepthBox] Could not restore ${n}:`,o instanceof Error?o.message:o)}}this.originalDescriptors=[]}};export{p as a,x as b};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{b as p}from"./chunk-4FNW6LFM.js";import{a as j,b as h}from"./chunk-JJHAWOIB.js";import{a as S,b as y}from"./chunk-GTNBSMZR.js";import{existsSync as g}from"node:fs";import{dirname as W,join as w}from"node:path";import{fileURLToPath as H}from"node:url";import{Worker as J}from"node:worker_threads";import _ from"sql.js";function E(e,r,n){switch(n.mode){case"list":return M(e,r,n);case"csv":return V(e,r,n);case"json":return B(e,r);case"line":return O(e,r,n);case"column":return I(e,r,n);case"table":return N(e,r,n);case"markdown":return P(e,r,n);case"tabs":return R(e,r,n);case"box":return F(e,r,n);case"quote":return Q(e,r,n);case"html":return D(e,r,n);case"ascii":return U(e,r,n)}}function u(e,r){return e==null?r:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function M(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(n.separator));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(n.separator));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function V(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(x).join(","));for(let a of r)t.push(a.map(i=>x(u(i,n.nullValue))).join(","));return t.length>0?`${t.join(`
|
|
3
|
-
`)}
|
|
4
|
-
`:""}function x(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
5
|
-
`)?`"${e.replace(/"/g,'""')}"`:e}function T(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function A(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):T(e):JSON.stringify(e)}function B(e,r){return r.length===0?"":`[${r.map(t=>`{${e.map((i,s)=>`${JSON.stringify(i)}:${A(t[s])}`).join(",")}}`).join(`,
|
|
6
|
-
`)}]
|
|
7
|
-
`}function O(e,r,n){if(e.length===0||r.length===0)return"";let t=Math.max(5,...e.map(i=>i.length)),a=[];for(let i of r)for(let s=0;s<e.length;s++){let o=e[s].padStart(t);a.push(`${o} = ${u(i[s],n.nullValue)}`)}return`${a.join(`
|
|
8
|
-
`)}
|
|
9
|
-
`}function I(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let a=[];n.header&&(a.push(e.map((i,s)=>i.padEnd(t[s])).join(" ")),a.push(t.map(i=>"-".repeat(i)).join(" ")));for(let i of r)a.push(i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" "));return a.length>0?`${a.join(`
|
|
10
|
-
`)}
|
|
11
|
-
`:""}function N(e,r,n){if(e.length===0)return"";let t=e.map(s=>s.length);for(let s of r)for(let o=0;o<s.length;o++){let f=u(s[o],n.nullValue).length;f>t[o]&&(t[o]=f)}let a=[],i=`+${t.map(s=>"-".repeat(s+2)).join("+")}+`;a.push(i),n.header&&(a.push(`| ${e.map((s,o)=>s.padEnd(t[o])).join(" | ")} |`),a.push(i));for(let s of r)a.push(`| ${s.map((o,f)=>u(o,n.nullValue).padEnd(t[f])).join(" | ")} |`);return a.push(i),`${a.join(`
|
|
12
|
-
`)}
|
|
13
|
-
`}function P(e,r,n){if(e.length===0)return"";let t=[];n.header&&(t.push(`| ${e.join(" | ")} |`),t.push(`|${e.map(()=>"---").join("|")}|`));for(let a of r)t.push(`| ${a.map(i=>u(i,n.nullValue)).join(" | ")} |`);return t.length>0?`${t.join(`
|
|
14
|
-
`)}
|
|
15
|
-
`:""}function R(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(" "));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(" "));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function F(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let a=[];a.push(`\u250C${t.map(i=>"\u2500".repeat(i+2)).join("\u252C")}\u2510`),a.push(`\u2502 ${e.map((i,s)=>i.padEnd(t[s])).join(" \u2502 ")} \u2502`),a.push(`\u251C${t.map(i=>"\u2500".repeat(i+2)).join("\u253C")}\u2524`);for(let i of r)a.push(`\u2502 ${i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" \u2502 ")} \u2502`);return a.push(`\u2514${t.map(i=>"\u2500".repeat(i+2)).join("\u2534")}\u2518`),`${a.join(`
|
|
16
|
-
`)}
|
|
17
|
-
`}function Q(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(a=>`'${a}'`).join(","));for(let a of r)t.push(a.map(i=>i==null?"NULL":typeof i=="number"?Number.isInteger(i)?String(i):T(i):`'${String(i)}'`).join(","));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function D(e,r,n){let t=[];n.header&&e.length>0&&(t.push(`<TR>${e.map(a=>`<TH>${q(a)}</TH>`).join("")}`),t.push("</TR>"));for(let a of r)t.push(`<TR>${a.map(i=>`<TD>${q(u(i,n.nullValue))}</TD>`).join("")}`),t.push("</TR>");return t.length>0?`${t.join(`
|
|
18
|
-
`)}
|
|
19
|
-
`:""}function q(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function U(e,r,n){let i=[];n.header&&e.length>0&&i.push(e.join(""));for(let s of r)i.push(s.map(o=>u(o,n.nullValue)).join(""));return i.length>0?i.join("")+"":""}var z=5e3,X={name:"sqlite3",summary:"SQLite database CLI",usage:"sqlite3 [OPTIONS] DATABASE [SQL]",options:["-list output in list mode (default)","-csv output in CSV mode","-json output in JSON mode","-line output in line mode","-column output in column mode","-table output as ASCII table","-markdown output as markdown table","-tabs output in tab-separated mode","-box output in Unicode box mode","-quote output in SQL quote mode","-html output as HTML table","-ascii output in ASCII mode (control chars)","-header show column headers","-noheader hide column headers","-separator SEP field separator for list mode (default: |)","-newline SEP row separator (default: \\n)","-nullvalue TEXT text for NULL values (default: empty)","-readonly open database read-only (no writeback)","-bail stop on first error","-echo print SQL before execution","-cmd COMMAND run SQL command before main SQL","-version show SQLite version","-- end of options","--help show this help"],examples:['sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"','sqlite3 -json data.db "SELECT * FROM users"','sqlite3 -csv -header data.db "SELECT id, name FROM products"','sqlite3 -box data.db "SELECT * FROM users"']};function Y(e){let r={mode:"list",header:!1,separator:"|",newline:`
|
|
20
|
-
`,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},n=null,t=null,a=!1,i=!1;for(let s=0;s<e.length;s++){let o=e[s];if(i){n===null?n=o:t===null&&(t=o);continue}if(o==="--")i=!0;else if(o==="-version")a=!0;else if(o==="-list")r.mode="list";else if(o==="-csv")r.mode="csv";else if(o==="-json")r.mode="json";else if(o==="-line")r.mode="line";else if(o==="-column")r.mode="column";else if(o==="-table")r.mode="table";else if(o==="-markdown")r.mode="markdown";else if(o==="-tabs")r.mode="tabs";else if(o==="-box")r.mode="box";else if(o==="-quote")r.mode="quote";else if(o==="-html")r.mode="html";else if(o==="-ascii")r.mode="ascii";else if(o==="-header")r.header=!0;else if(o==="-noheader")r.header=!1;else if(o==="-readonly")r.readonly=!0;else if(o==="-bail")r.bail=!0;else if(o==="-echo")r.echo=!0;else if(o==="-separator"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
|
|
21
|
-
`,exitCode:1};r.separator=e[++s]}else if(o==="-newline"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
|
|
22
|
-
`,exitCode:1};r.newline=e[++s]}else if(o==="-nullvalue"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
|
|
23
|
-
`,exitCode:1};r.nullValue=e[++s]}else if(o==="-cmd"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
|
|
24
|
-
`,exitCode:1};r.cmd=e[++s]}else{if(o.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${o.startsWith("--")?o.slice(1):o}
|
|
25
|
-
Use -help for a list of options.
|
|
26
|
-
`,exitCode:1};n===null?n=o:t===null&&(t=o)}}return{options:r,database:n,sql:t,showVersion:a}}async function v(){let e=await p.runTrustedAsync(()=>_()),r=new e.Database;try{let n=r.exec("SELECT sqlite_version()");return n.length>0&&n[0].values.length>0?String(n[0].values[0][0]):"unknown"}finally{r.close()}}function G(){let e=W(H(import.meta.url)),r=w(e,"../../commands/sqlite3/worker.js");if(g(r))return r;let n=w(e,"worker.js");if(g(n))return n;let t=w(e,"../../../dist/commands/sqlite3/worker.js");if(g(t))return t;throw new Error("sqlite3 worker not found. Run 'pnpm build' to compile the worker.")}var K={createWorker(e,r){return new J(e,{workerData:r})}};function Z(e){if(!e||typeof e!="object")return{success:!1,error:"Malformed worker response"};let r=e;return r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?Array.isArray(r.results)?typeof r.hasModifications!="boolean"?{success:!1,error:"Malformed worker response: missing hasModifications flag"}:r.dbBuffer!==null&&r.dbBuffer!==void 0&&!(r.dbBuffer instanceof Uint8Array)?{success:!1,error:"Malformed worker response: invalid dbBuffer"}:{success:!0,results:r.results,hasModifications:r.hasModifications,dbBuffer:r.dbBuffer===void 0?null:r.dbBuffer,defenseStats:r.defenseStats}:{success:!1,error:"Malformed worker response: missing results array"}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}async function ee(e,r){try{let n=G();return await new Promise((t,a)=>{let i=p.runTrusted(()=>K.createWorker(n,e)),s=j(()=>{i.terminate(),t({success:!1,error:`Query timeout: execution exceeded ${r}ms limit`})},r);i.on("message",o=>{h(s),t(Z(o))}),i.on("error",o=>{h(s),a(o)}),i.on("exit",o=>{h(s),o!==0&&t({success:!1,error:`Worker exited with code ${o}`})})})}catch(n){throw new Error(`sqlite3 worker failed to load: ${n.message}`)}}var de={name:"sqlite3",async execute(e,r){if(y(e)||e.includes("-help"))return S(X);let n=Y(e);if("exitCode"in n)return n;let{options:t,database:a,sql:i,showVersion:s}=n;if(s)return{stdout:`${await v()}
|
|
27
|
-
`,stderr:"",exitCode:0};if(!a)return{stdout:"",stderr:`sqlite3: missing database argument
|
|
28
|
-
`,exitCode:1};let o=i||r.stdin.trim();if(t.cmd&&(o=t.cmd+(o?`; ${o}`:"")),!o)return{stdout:"",stderr:`sqlite3: no SQL provided
|
|
29
|
-
`,exitCode:1};let f=a===":memory:",m="",b=null;try{f||(m=r.fs.resolvePath(r.cwd,a),await r.fs.exists(m)&&(b=await r.fs.readFileBuffer(m)))}catch(l){return{stdout:"",stderr:`sqlite3: unable to open database "${a}": ${l.message}
|
|
30
|
-
`,exitCode:1}}let C=r.limits?.maxSqliteTimeoutMs??z,k={dbBuffer:b,sql:o,options:{bail:t.bail,echo:t.echo}},d;try{d=await ee(k,C)}catch(l){return{stdout:"",stderr:`sqlite3: worker error: ${l.message}
|
|
31
|
-
`,exitCode:1}}if(!d.success)return{stdout:"",stderr:`sqlite3: ${d.error}
|
|
32
|
-
`,exitCode:1};let L={mode:t.mode,header:t.header,separator:t.separator,newline:t.newline,nullValue:t.nullValue},c="";t.echo&&(c+=`${o}
|
|
33
|
-
`);let $=!1;for(let l of d.results)if(l.type==="error"){if(t.bail)return{stdout:c,stderr:`Error: ${l.error}
|
|
34
|
-
`,exitCode:1};c+=`Error: ${l.error}
|
|
35
|
-
`,$=!0}else l.columns&&l.rows&&(l.rows.length>0||t.header)&&(c+=E(l.columns,l.rows,L));if(d.hasModifications&&!t.readonly&&!f&&m&&d.dbBuffer)try{await r.fs.writeFile(m,d.dbBuffer)}catch(l){return{stdout:c,stderr:`sqlite3: failed to write database: ${l.message}
|
|
36
|
-
`,exitCode:1}}return{stdout:c,stderr:"",exitCode:$&&t.bail?1:0}}},ce={name:"sqlite3",flags:[],needsArgs:!0};export{K as a,de as b,ce as c};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as N}from"./chunk-SE4C7FJY.js";import{k as C}from"./chunk-6KZRLMG3.js";import{a as G,b as j,c as T}from"./chunk-GTNBSMZR.js";var B=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function P(n){let e="",t=0,i=!1;for(;t<n.length;){if(n[t]==="["&&!i){if(n[t+1]==="["&&n[t+2]===":"){let s=n.indexOf(":]]",t+3);if(s!==-1){let a=n.slice(t+3,s),r=B.get(a);if(r){e+=`[${r}]`,t=s+3;continue}}}if(n[t+1]==="^"&&n[t+2]==="["&&n[t+3]===":"){let s=n.indexOf(":]]",t+4);if(s!==-1){let a=n.slice(t+4,s),r=B.get(a);if(r){e+=`[^${r}]`,t=s+3;continue}}}e+="[",t++,i=!0,t<n.length&&n[t]==="^"&&(e+="^",t++),t<n.length&&n[t]==="]"&&(e+="\\]",t++);continue}if(i){if(n[t]==="]"){e+="]",t++,i=!1;continue}if(n[t]==="["&&n[t+1]===":"){let s=n.indexOf(":]",t+2);if(s!==-1){let a=n.slice(t+2,s),r=B.get(a);if(r){e+=r,t=s+2;continue}}}if(n[t]==="\\"&&t+1<n.length){e+=n[t]+n[t+1],t+=2;continue}e+=n[t],t++;continue}if(n[t]==="\\"&&t+1<n.length){let s=n[t+1];if(s==="+"||s==="?"||s==="|"){e+=s,t+=2;continue}if(s==="("||s===")"){e+=s,t+=2;continue}if(s==="{"||s==="}"){e+=s,t+=2;continue}if(s==="t"){e+=" ",t+=2;continue}if(s==="n"){e+=`
|
|
3
|
-
`,t+=2;continue}if(s==="r"){e+="\r",t+=2;continue}e+=n[t]+s,t+=2;continue}if(n[t]==="+"||n[t]==="?"||n[t]==="|"||n[t]==="("||n[t]===")"){e+=`\\${n[t]}`,t++;continue}if(n[t]==="^"&&!(e===""||e.endsWith("("))){e+="\\^",t++;continue}if(n[t]==="$"){let s=t===n.length-1,a=t+2<n.length&&n[t+1]==="\\"&&n[t+2]===")";if(!s&&!a){e+="\\$",t++;continue}}e+=n[t],t++}return e}function D(n){let e="",t=!1;for(let i=0;i<n.length;i++)n[i]==="["&&!t?(t=!0,e+="[",i++,i<n.length&&n[i]==="^"&&(e+="^",i++),i<n.length&&n[i]==="]"&&(e+="]",i++),i--):n[i]==="]"&&t?(t=!1,e+="]"):!t&&n[i]==="{"&&n[i+1]===","?(e+="{0,",i++):e+=n[i];return e}function Z(n){let e="";for(let t=0;t<n.length;t++){let i=n[t],s=i.charCodeAt(0);i==="\\"?e+="\\\\":i===" "?e+="\\t":i===`
|
|
4
|
-
`?e+=`$
|
|
5
|
-
`:i==="\r"?e+="\\r":i==="\x07"?e+="\\a":i==="\b"?e+="\\b":i==="\f"?e+="\\f":i==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=i}return`${e}$`}var ce=1e4;function Q(n,e,t){return{patternSpace:"",holdSpace:"",lineNumber:0,totalLines:n,deleted:!1,printed:!1,quit:!1,quitSilent:!1,exitCode:void 0,errorMessage:void 0,appendBuffer:[],substitutionMade:!1,lineNumberOutput:[],nCommandOutput:[],restartCycle:!1,inDRestartedCycle:!1,currentFilename:e,pendingFileReads:[],pendingFileWrites:[],pendingExecute:void 0,rangeStates:t||new Map,linesConsumedInCycle:0}}function le(n){return typeof n=="object"&&"first"in n&&"step"in n}function oe(n){return typeof n=="object"&&"offset"in n}function O(n,e,t,i,s){if(n==="$")return e===t;if(typeof n=="number")return e===n;if(le(n)){let{first:a,step:r}=n;return r===0?e===a:(e-a)%r===0&&e>=a}if(typeof n=="object"&&"pattern"in n)try{let a=n.pattern;a===""&&s?.lastPattern?a=s.lastPattern:a!==""&&s&&(s.lastPattern=a);let r=D(P(a));return N(r).test(i)}catch{return!1}return!1}function W(n){let e=t=>t===void 0?"undefined":t==="$"?"$":typeof t=="number"?String(t):"pattern"in t?`/${t.pattern}/`:"first"in t?`${t.first}~${t.step}`:"unknown";return`${e(n.start)},${e(n.end)}`}function ue(n,e,t,i,s,a){if(!n||!n.start&&!n.end)return!0;let r=n.start,l=n.end;if(r!==void 0&&l===void 0)return O(r,e,t,i,a);if(r!==void 0&&l!==void 0){let o=typeof r=="object"&&"pattern"in r,d=typeof l=="object"&&"pattern"in l,f=oe(l);if(f&&s){let m=W(n),p=s.get(m);if(p||(p={active:!1},s.set(m,p)),p.active){let u=p.startLine||e;return e>=u+l.offset&&(p.active=!1,s.set(m,p)),!0}else return O(r,e,t,i,a)?(p.active=!0,p.startLine=e,s.set(m,p),l.offset===0&&(p.active=!1,s.set(m,p)),!0):!1}if(!o&&!d&&!f){let m=typeof r=="number"?r:r==="$"?t:1,p=typeof l=="number"?l:t;if(m<=p)return e>=m&&e<=p;if(s){let u=W(n),h=s.get(u);return h||(h={active:!1},s.set(u,h)),!h.completed&&e>=m?(h.completed=!0,s.set(u,h),!0):!1}return!1}if(s){let m=W(n),p=s.get(m);if(p||(p={active:!1},s.set(m,p)),p.active)return O(l,e,t,i,a)&&(p.active=!1,typeof r=="number"&&(p.completed=!0),s.set(m,p)),!0;{if(p.completed)return!1;let u=!1;return typeof r=="number"?u=e>=r:u=O(r,e,t,i,a),u?(p.active=!0,p.startLine=e,s.set(m,p),O(l,e,t,i,a)&&(p.active=!1,typeof r=="number"&&(p.completed=!0),s.set(m,p)),!0):!1}}return O(r,e,t,i,a)}return!0}function I(n,e,t,i,s,a){let r=ue(n,e,t,i,s,a);return n?.negated?!r:r}function he(n,e,t,i){let s="",a=0,r=!1;for(;a<=n.length;){e.lastIndex=a;let l=e.exec(n);if(!l){s+=n.slice(a);break}if(l.index!==a){s+=n.slice(a,l.index),a=l.index,r=!1;continue}let o=l[0],d=l.slice(1);if(r&&o.length===0){if(a<n.length)s+=n[a],a++;else break;r=!1;continue}if(s+=i(o,d),r=!1,o.length===0)if(a<n.length)s+=n[a],a++;else break;else a+=o.length,r=!0}return s}function q(n,e,t){let i="",s=0;for(;s<n.length;){if(n[s]==="\\"&&s+1<n.length){let a=n[s+1];if(a==="&"){i+="&",s+=2;continue}if(a==="n"){i+=`
|
|
6
|
-
`,s+=2;continue}if(a==="t"){i+=" ",s+=2;continue}if(a==="r"){i+="\r",s+=2;continue}let r=parseInt(a,10);if(r===0){i+=e,s+=2;continue}if(r>=1&&r<=9){i+=t[r-1]||"",s+=2;continue}i+=a,s+=2;continue}if(n[s]==="&"){i+=e,s++;continue}i+=n[s],s++}return i}function K(n,e,t){if(e>0&&n.length>e)throw new C(`sed: ${t} size limit exceeded (${e} bytes)`,"string_length")}function de(n,e,t){let{lineNumber:i,totalLines:s,patternSpace:a}=e;if(n.type==="label"){e.coverage?.hit(`sed:cmd:${n.type}`);return}if(I(n.address,i,s,a,e.rangeStates,e))switch(e.coverage?.hit(`sed:cmd:${n.type}`),n.type){case"substitute":{let r=n,l="";r.global&&(l+="g"),r.ignoreCase&&(l+="i");let o=r.pattern;o===""&&e.lastPattern?o=e.lastPattern:o!==""&&(e.lastPattern=o);let d=D(r.extendedRegex?o:P(o));try{let f=N(d,l),v=f.test(e.patternSpace);if(f.lastIndex=0,v){if(e.substitutionMade=!0,r.nthOccurrence&&r.nthOccurrence>0&&!r.global){let m=0,p=r.nthOccurrence,u=N(d,`g${r.ignoreCase?"i":""}`);e.patternSpace=u.replace(e.patternSpace,(h,...b)=>{if(m++,m===p){let x=b.slice(0,-2);return q(r.replacement,h,x)}return h})}else if(r.global){let m=N(d,`g${r.ignoreCase?"i":""}`);e.patternSpace=he(e.patternSpace,m,r.replacement,(p,u)=>q(r.replacement,p,u))}else e.patternSpace=f.replace(e.patternSpace,(m,...p)=>{let u=p.slice(0,-2);return q(r.replacement,m,u)});r.printOnMatch&&e.lineNumberOutput.push(e.patternSpace)}}catch{}break}case"print":e.lineNumberOutput.push(e.patternSpace);break;case"printFirstLine":{let r=e.patternSpace.indexOf(`
|
|
7
|
-
`);r!==-1?e.lineNumberOutput.push(e.patternSpace.slice(0,r)):e.lineNumberOutput.push(e.patternSpace);break}case"delete":e.deleted=!0;break;case"deleteFirstLine":{let r=e.patternSpace.indexOf(`
|
|
8
|
-
`);r!==-1?(e.patternSpace=e.patternSpace.slice(r+1),e.restartCycle=!0,e.inDRestartedCycle=!0):e.deleted=!0;break}case"zap":e.patternSpace="";break;case"append":e.appendBuffer.push(n.text);break;case"insert":e.appendBuffer.unshift(`__INSERT__${n.text}`);break;case"change":e.deleted=!0,e.changedText=n.text;break;case"hold":e.holdSpace=e.patternSpace;break;case"holdAppend":e.holdSpace?e.holdSpace+=`
|
|
9
|
-
${e.patternSpace}`:e.holdSpace=e.patternSpace,K(e.holdSpace,t?.maxStringLength??0,"hold space");break;case"get":e.patternSpace=e.holdSpace;break;case"getAppend":e.patternSpace+=`
|
|
10
|
-
${e.holdSpace}`,K(e.patternSpace,t?.maxStringLength??0,"pattern space");break;case"exchange":{let r=e.patternSpace;e.patternSpace=e.holdSpace,e.holdSpace=r;break}case"next":e.printed=!0;break;case"quit":e.quit=!0,n.exitCode!==void 0&&(e.exitCode=n.exitCode);break;case"quitSilent":e.quit=!0,e.quitSilent=!0,n.exitCode!==void 0&&(e.exitCode=n.exitCode);break;case"list":{let r=Z(e.patternSpace);e.lineNumberOutput.push(r);break}case"printFilename":e.currentFilename&&e.lineNumberOutput.push(e.currentFilename);break;case"version":{let r=[4,8,0];if(n.minVersion){let l=n.minVersion.split("."),o=[],d=!1;for(let f of l){let v=parseInt(f,10);if(Number.isNaN(v)||v<0){e.quit=!0,e.exitCode=1,e.errorMessage=`sed: invalid version string: ${n.minVersion}`,d=!0;break}o.push(v)}if(!d){for(;o.length<3;)o.push(0);for(let f=0;f<3;f++){if(o[f]>r[f]){e.quit=!0,e.exitCode=1,e.errorMessage=`sed: this is not GNU sed version ${n.minVersion}`;break}if(o[f]<r[f])break}}}break}case"readFile":e.pendingFileReads.push({filename:n.filename,wholeFile:!0});break;case"readFileLine":e.pendingFileReads.push({filename:n.filename,wholeFile:!1});break;case"writeFile":e.pendingFileWrites.push({filename:n.filename,content:`${e.patternSpace}
|
|
11
|
-
`});break;case"writeFirstLine":{let r=e.patternSpace.indexOf(`
|
|
12
|
-
`),l=r!==-1?e.patternSpace.slice(0,r):e.patternSpace;e.pendingFileWrites.push({filename:n.filename,content:`${l}
|
|
13
|
-
`});break}case"execute":n.command?e.pendingExecute={command:n.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=fe(e.patternSpace,n);break;case"lineNumber":e.lineNumberOutput.push(String(e.lineNumber));break;case"branch":break;case"branchOnSubst":break;case"branchOnNoSubst":break;case"group":break}}function fe(n,e){let t="";for(let i of n){let s=e.source.indexOf(i);s!==-1?t+=e.dest[s]:t+=i}return t}function U(n,e,t,i){let s=new Map;for(let o=0;o<n.length;o++){let d=n[o];d.type==="label"&&s.set(d.name,o)}let a=i?.maxIterations??ce,r=0,l=0;for(;l<n.length;){if(r++,r>a)throw new C(`sed: command execution exceeded maximum iterations (${a})`,"iterations");if(e.deleted||e.quit||e.quitSilent||e.restartCycle)break;let o=n[l];if(o.type==="next"){if(I(o.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e))if(e.coverage?.hit("sed:cmd:next"),e.nCommandOutput.push(e.patternSpace),t&&t.currentLineIndex+e.linesConsumedInCycle+1<t.lines.length){e.linesConsumedInCycle++;let d=t.lines[t.currentLineIndex+e.linesConsumedInCycle];e.patternSpace=d,e.lineNumber=t.currentLineIndex+e.linesConsumedInCycle+1,e.substitutionMade=!1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(o.type==="nextAppend"){if(I(o.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e))if(e.coverage?.hit("sed:cmd:nextAppend"),t&&t.currentLineIndex+e.linesConsumedInCycle+1<t.lines.length){e.linesConsumedInCycle++;let d=t.lines[t.currentLineIndex+e.linesConsumedInCycle];e.patternSpace+=`
|
|
14
|
-
${d}`,e.lineNumber=t.currentLineIndex+e.linesConsumedInCycle+1}else{e.quit=!0;break}l++;continue}if(o.type==="branch"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)){if(e.coverage?.hit("sed:cmd:branch"),d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="branchOnSubst"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:branchOnSubst"),e.substitutionMade)){if(e.substitutionMade=!1,d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="branchOnNoSubst"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:branchOnNoSubst"),!e.substitutionMade)){if(d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="group"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:group"),U(d.commands,e,t,i),e.branchRequest)){let f=s.get(e.branchRequest);if(f!==void 0){e.branchRequest=void 0,l=f;continue}break}l++;continue}de(o,e,i),l++}return e.linesConsumedInCycle}var c;(function(n){n.NUMBER="NUMBER",n.DOLLAR="DOLLAR",n.PATTERN="PATTERN",n.STEP="STEP",n.RELATIVE_OFFSET="RELATIVE_OFFSET",n.LBRACE="LBRACE",n.RBRACE="RBRACE",n.SEMICOLON="SEMICOLON",n.NEWLINE="NEWLINE",n.COMMA="COMMA",n.NEGATION="NEGATION",n.COMMAND="COMMAND",n.SUBSTITUTE="SUBSTITUTE",n.TRANSLITERATE="TRANSLITERATE",n.LABEL_DEF="LABEL_DEF",n.BRANCH="BRANCH",n.BRANCH_ON_SUBST="BRANCH_ON_SUBST",n.BRANCH_ON_NO_SUBST="BRANCH_ON_NO_SUBST",n.TEXT_CMD="TEXT_CMD",n.FILE_READ="FILE_READ",n.FILE_READ_LINE="FILE_READ_LINE",n.FILE_WRITE="FILE_WRITE",n.FILE_WRITE_LINE="FILE_WRITE_LINE",n.EXECUTE="EXECUTE",n.VERSION="VERSION",n.EOF="EOF",n.ERROR="ERROR"})(c||(c={}));var A=class{input;pos=0;line=1;column=1;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let t=this.nextToken();t&&e.push(t)}return e.push(this.makeToken(c.EOF,"")),e}makeToken(e,t,i){return{type:e,value:t,line:this.line,column:this.column,...i}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
15
|
-
`?(this.line++,this.column=1):this.column++,e}readEscapedString(e){let t="";for(;this.pos<this.input.length&&this.peek()!==e;)if(this.peek()==="\\"){this.advance();let i=this.advance();i==="n"?t+=`
|
|
16
|
-
`:i==="t"?t+=" ":t+=i}else{if(this.peek()===`
|
|
17
|
-
`)return null;t+=this.advance()}return t}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.peek();if(e===" "||e===" "||e==="\r")this.advance();else if(e==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
18
|
-
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,t=this.column,i=this.peek();return i===`
|
|
19
|
-
`?(this.advance(),{type:c.NEWLINE,value:`
|
|
20
|
-
`,line:e,column:t}):i===";"?(this.advance(),{type:c.SEMICOLON,value:";",line:e,column:t}):i==="{"?(this.advance(),{type:c.LBRACE,value:"{",line:e,column:t}):i==="}"?(this.advance(),{type:c.RBRACE,value:"}",line:e,column:t}):i===","?(this.advance(),{type:c.COMMA,value:",",line:e,column:t}):i==="!"?(this.advance(),{type:c.NEGATION,value:"!",line:e,column:t}):i==="$"?(this.advance(),{type:c.DOLLAR,value:"$",line:e,column:t}):this.isDigit(i)?this.readNumber():i==="+"&&this.isDigit(this.input[this.pos+1]||"")?this.readRelativeOffset():i==="/"?this.readPattern():i===":"?this.readLabelDef():this.readCommand()}readNumber(){let e=this.line,t=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="~"){this.advance();let s="";for(;this.isDigit(this.peek());)s+=this.advance();let a=parseInt(i,10),r=parseInt(s,10)||0;return{type:c.STEP,value:`${a}~${r}`,first:a,step:r,line:e,column:t}}return{type:c.NUMBER,value:parseInt(i,10),line:e,column:t}}readRelativeOffset(){let e=this.line,t=this.column;this.advance();let i="";for(;this.isDigit(this.peek());)i+=this.advance();let s=parseInt(i,10)||0;return{type:c.RELATIVE_OFFSET,value:`+${s}`,offset:s,line:e,column:t}}readPattern(){let e=this.line,t=this.column;this.advance();let i="",s=!1;for(;this.pos<this.input.length;){let a=this.peek();if(a==="/"&&!s)break;if(a==="\\")i+=this.advance(),this.pos<this.input.length&&this.peek()!==`
|
|
21
|
-
`&&(i+=this.advance());else{if(a===`
|
|
22
|
-
`)break;a==="["&&!s?(s=!0,i+=this.advance(),this.peek()==="^"&&(i+=this.advance()),this.peek()==="]"&&(i+=this.advance())):a==="]"&&s?(s=!1,i+=this.advance()):i+=this.advance()}}return this.peek()==="/"&&this.advance(),{type:c.PATTERN,value:i,pattern:i,line:e,column:t}}readLabelDef(){let e=this.line,t=this.column;for(this.advance();this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
|
|
23
|
-
`||s===";"||s==="}"||s==="{")break;i+=this.advance()}return{type:c.LABEL_DEF,value:i,label:i,line:e,column:t}}readCommand(){let e=this.line,t=this.column,i=this.advance();switch(i){case"s":return this.readSubstitute(e,t);case"y":return this.readTransliterate(e,t);case"a":case"i":case"c":return this.readTextCommand(i,e,t);case"b":return this.readBranch(c.BRANCH,"b",e,t);case"t":return this.readBranch(c.BRANCH_ON_SUBST,"t",e,t);case"T":return this.readBranch(c.BRANCH_ON_NO_SUBST,"T",e,t);case"r":return this.readFileCommand(c.FILE_READ,"r",e,t);case"R":return this.readFileCommand(c.FILE_READ_LINE,"R",e,t);case"w":return this.readFileCommand(c.FILE_WRITE,"w",e,t);case"W":return this.readFileCommand(c.FILE_WRITE_LINE,"W",e,t);case"e":return this.readExecute(e,t);case"p":case"P":case"d":case"D":case"h":case"H":case"g":case"G":case"x":case"n":case"N":case"q":case"Q":case"z":case"=":case"l":case"F":return{type:c.COMMAND,value:i,line:e,column:t};case"v":return this.readVersion(e,t);default:return{type:c.ERROR,value:i,line:e,column:t}}}readSubstitute(e,t){let i=this.advance();if(!i||i===`
|
|
24
|
-
`)return{type:c.ERROR,value:"s",line:e,column:t};let s="",a=!1;for(;this.pos<this.input.length;){let o=this.peek();if(o===i&&!a)break;if(o==="\\")this.advance(),this.pos<this.input.length&&this.peek()!==`
|
|
25
|
-
`?this.peek()===i&&!a?s+=this.advance():(s+="\\",s+=this.advance()):s+="\\";else{if(o===`
|
|
26
|
-
`)break;o==="["&&!a?(a=!0,s+=this.advance(),this.peek()==="^"&&(s+=this.advance()),this.peek()==="]"&&(s+=this.advance())):o==="]"&&a?(a=!1,s+=this.advance()):s+=this.advance()}}if(this.peek()!==i)return{type:c.ERROR,value:"unterminated substitution pattern",line:e,column:t};this.advance();let r="";for(;this.pos<this.input.length&&this.peek()!==i;)if(this.peek()==="\\")if(this.advance(),this.pos<this.input.length){let o=this.peek();o==="\\"?(this.advance(),this.pos<this.input.length&&this.peek()===`
|
|
27
|
-
`?(r+=`
|
|
28
|
-
`,this.advance()):r+="\\"):o===`
|
|
29
|
-
`?(r+=`
|
|
30
|
-
`,this.advance()):r+=`\\${this.advance()}`}else r+="\\";else{if(this.peek()===`
|
|
31
|
-
`)break;r+=this.advance()}this.peek()===i&&this.advance();let l="";for(;this.pos<this.input.length;){let o=this.peek();if(o==="g"||o==="i"||o==="p"||o==="I"||this.isDigit(o))l+=this.advance();else break}return{type:c.SUBSTITUTE,value:`s${i}${s}${i}${r}${i}${l}`,pattern:s,replacement:r,flags:l,line:e,column:t}}readTransliterate(e,t){let i=this.advance();if(!i||i===`
|
|
32
|
-
`)return{type:c.ERROR,value:"y",line:e,column:t};let s=this.readEscapedString(i);if(s===null||this.peek()!==i)return{type:c.ERROR,value:"unterminated transliteration source",line:e,column:t};this.advance();let a=this.readEscapedString(i);if(a===null||this.peek()!==i)return{type:c.ERROR,value:"unterminated transliteration dest",line:e,column:t};this.advance();let r=this.peek();for(;r===" "||r===" ";)this.advance(),r=this.peek();return r!==""&&r!==";"&&r!==`
|
|
33
|
-
`&&r!=="}"?{type:c.ERROR,value:"extra text at the end of a transform command",line:e,column:t}:{type:c.TRANSLITERATE,value:`y${i}${s}${i}${a}${i}`,source:s,dest:a,line:e,column:t}}readTextCommand(e,t,i){let s=!1;this.peek()==="\\"&&this.pos+1<this.input.length&&(this.input[this.pos+1]===`
|
|
34
|
-
`||this.input[this.pos+1]===" "||this.input[this.pos+1]===" ")&&(s=!0,this.advance()),(this.peek()===" "||this.peek()===" ")&&this.advance(),this.peek()==="\\"&&this.pos+1<this.input.length&&(this.input[this.pos+1]===" "||this.input[this.pos+1]===" ")&&this.advance(),s&&this.peek()===`
|
|
35
|
-
`&&this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===`
|
|
36
|
-
`){if(a.endsWith("\\")){a=`${a.slice(0,-1)}
|
|
37
|
-
`,this.advance();continue}break}if(r==="\\"&&this.pos+1<this.input.length){let l=this.input[this.pos+1];if(l==="n"){a+=`
|
|
38
|
-
`,this.advance(),this.advance();continue}if(l==="t"){a+=" ",this.advance(),this.advance();continue}if(l==="r"){a+="\r",this.advance(),this.advance();continue}}a+=this.advance()}return{type:c.TEXT_CMD,value:e,text:a,line:t,column:i}}readBranch(e,t,i,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===" "||r===" "||r===`
|
|
39
|
-
`||r===";"||r==="}"||r==="{")break;a+=this.advance()}return{type:e,value:t,label:a||void 0,line:i,column:s}}readVersion(e,t){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
|
|
40
|
-
`||s===";"||s==="}"||s==="{")break;i+=this.advance()}return{type:c.VERSION,value:"v",label:i||void 0,line:e,column:t}}readFileCommand(e,t,i,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===`
|
|
41
|
-
`||r===";")break;a+=this.advance()}return{type:e,value:t,filename:a.trim(),line:i,column:s}}readExecute(e,t){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===`
|
|
42
|
-
`||s===";")break;i+=this.advance()}return{type:c.EXECUTE,value:"e",command:i.trim()||void 0,line:e,column:t}}isDigit(e){return e>="0"&&e<="9"}};var z=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,t=!1){this.scripts=e,this.extendedRegex=t}parse(){let e=[];for(let t of this.scripts){let i=new A(t);for(this.tokens=i.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(c.NEWLINE)||this.check(c.SEMICOLON)){this.advance();continue}let s=this.pos,a=this.parseCommand();if(a.error)return{commands:[],error:a.error};if(a.command&&e.push(a.command),this.pos===s&&!this.isAtEnd())return{commands:[],error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}}return{commands:e}}parseCommand(){let e=this.parseAddressRange();if(e?.error)return{command:null,error:e.error};let t=e?.address;for(this.check(c.NEGATION)&&(this.advance(),t&&(t.negated=!0));this.check(c.NEWLINE)||this.check(c.SEMICOLON);)this.advance();if(this.isAtEnd())return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:"command expected"}:{command:null};let i=this.peek();switch(i.type){case c.COMMAND:return this.parseSimpleCommand(i,t);case c.SUBSTITUTE:return this.parseSubstituteFromToken(i,t);case c.TRANSLITERATE:return this.parseTransliterateFromToken(i,t);case c.LABEL_DEF:return this.advance(),{command:{type:"label",name:i.label||""}};case c.BRANCH:return this.advance(),{command:{type:"branch",address:t,label:i.label}};case c.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:t,label:i.label}};case c.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:t,label:i.label}};case c.TEXT_CMD:return this.advance(),this.parseTextCommand(i,t);case c.FILE_READ:return this.advance(),{command:{type:"readFile",address:t,filename:i.filename||""}};case c.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:t,filename:i.filename||""}};case c.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:t,filename:i.filename||""}};case c.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:t,filename:i.filename||""}};case c.EXECUTE:return this.advance(),{command:{type:"execute",address:t,command:i.command}};case c.VERSION:return this.advance(),{command:{type:"version",address:t,minVersion:i.label}};case c.LBRACE:return this.parseGroup(t);case c.RBRACE:return{command:null};case c.ERROR:return{command:null,error:`invalid command: ${i.value}`};default:return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:"command expected"}:{command:null}}}parseSimpleCommand(e,t){this.advance();let i=e.value;switch(i){case"p":return{command:{type:"print",address:t}};case"P":return{command:{type:"printFirstLine",address:t}};case"d":return{command:{type:"delete",address:t}};case"D":return{command:{type:"deleteFirstLine",address:t}};case"h":return{command:{type:"hold",address:t}};case"H":return{command:{type:"holdAppend",address:t}};case"g":return{command:{type:"get",address:t}};case"G":return{command:{type:"getAppend",address:t}};case"x":return{command:{type:"exchange",address:t}};case"n":return{command:{type:"next",address:t}};case"N":return{command:{type:"nextAppend",address:t}};case"q":return{command:{type:"quit",address:t}};case"Q":return{command:{type:"quitSilent",address:t}};case"z":return{command:{type:"zap",address:t}};case"=":return{command:{type:"lineNumber",address:t}};case"l":return{command:{type:"list",address:t}};case"F":return{command:{type:"printFilename",address:t}};default:return{command:null,error:`unknown command: ${i}`}}}parseSubstituteFromToken(e,t){this.advance();let i=e.flags||"",s,a=i.match(/(\d+)/);return a&&(s=parseInt(a[1],10)),{command:{type:"substitute",address:t,pattern:e.pattern||"",replacement:e.replacement||"",global:i.includes("g"),ignoreCase:i.includes("i")||i.includes("I"),printOnMatch:i.includes("p"),nthOccurrence:s,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,t){this.advance();let i=e.source||"",s=e.dest||"";return i.length!==s.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:t,source:i,dest:s}}}parseTextCommand(e,t){let i=e.value,s=e.text||"";switch(i){case"a":return{command:{type:"append",address:t,text:s}};case"i":return{command:{type:"insert",address:t,text:s}};case"c":return{command:{type:"change",address:t,text:s}};default:return{command:null,error:`unknown text command: ${i}`}}}parseGroup(e){this.advance();let t=[];for(;!this.isAtEnd()&&!this.check(c.RBRACE);){if(this.check(c.NEWLINE)||this.check(c.SEMICOLON)){this.advance();continue}let i=this.pos,s=this.parseCommand();if(s.error)return{command:null,error:s.error};if(s.command&&t.push(s.command),this.pos===i&&!this.isAtEnd())return{command:null,error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}return this.check(c.RBRACE)?(this.advance(),{command:{type:"group",address:e,commands:t}}):{command:null,error:"unmatched brace in grouped commands"}}parseAddressRange(){if(this.check(c.COMMA))return{error:"expected context address"};let e=this.parseAddress();if(e===void 0)return;let t;if(this.check(c.RELATIVE_OFFSET))t={offset:this.advance().offset||0};else if(this.check(c.COMMA)&&(this.advance(),t=this.parseAddress(),t===void 0))return{error:"expected context address"};return{address:{start:e,end:t}}}parseAddress(){let e=this.peek();switch(e.type){case c.NUMBER:return this.advance(),e.value;case c.DOLLAR:return this.advance(),"$";case c.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case c.STEP:return this.advance(),{first:e.first||0,step:e.step||0};case c.RELATIVE_OFFSET:return this.advance(),{offset:e.offset||0};default:return}}peek(){return this.tokens[this.pos]||{type:c.EOF,value:"",line:0,column:0}}advance(){return this.isAtEnd()||this.pos++,this.tokens[this.pos-1]}check(e){return this.peek().type===e}isAtEnd(){return this.peek().type===c.EOF}};function J(n,e=!1){let t=!1,i=!1,s=[];for(let o=0;o<n.length;o++){let d=n[o];if(s.length===0&&o===0){let f=d.match(/^#([nr]+)\s*(?:\n|$)/i);if(f){let v=f[1].toLowerCase();v.includes("n")&&(t=!0),v.includes("r")&&(i=!0),d=d.slice(f[0].length)}}if(s.length>0&&s[s.length-1].endsWith("\\")){let f=s[s.length-1];s[s.length-1]=`${f}
|
|
43
|
-
${d}`}else s.push(d)}let a=s.join(`
|
|
44
|
-
`),l=new z([a],e||i).parse();if(!l.error&&l.commands.length>0){let o=pe(l.commands);if(o)return{commands:[],error:o,silentMode:t,extendedRegexMode:i}}return{...l,silentMode:t,extendedRegexMode:i}}function pe(n){let e=new Set;Y(n,e);let t=ee(n,e);if(t)return`undefined label '${t}'`}function Y(n,e){for(let t of n)t.type==="label"?e.add(t.name):t.type==="group"&&Y(t.commands,e)}function ee(n,e){for(let t of n){if((t.type==="branch"||t.type==="branchOnSubst"||t.type==="branchOnNoSubst")&&t.label&&!e.has(t.label))return t.label;if(t.type==="group"){let i=ee(t.commands,e);if(i)return i}}}var me={name:"sed",summary:"stream editor for filtering and transforming text",usage:"sed [OPTION]... {script} [input-file]...",options:["-n, --quiet, --silent suppress automatic printing of pattern space","-e script add the script to commands to be executed","-f script-file read script from file","-i, --in-place edit files in place","-E, -r, --regexp-extended use extended regular expressions"," --help display this help and exit"],description:`Commands:
|
|
45
|
-
s/regexp/replacement/[flags] substitute
|
|
46
|
-
d delete pattern space
|
|
47
|
-
p print pattern space
|
|
48
|
-
a\\ text append text after line
|
|
49
|
-
i\\ text insert text before line
|
|
50
|
-
c\\ text change (replace) line with text
|
|
51
|
-
h copy pattern space to hold space
|
|
52
|
-
H append pattern space to hold space
|
|
53
|
-
g copy hold space to pattern space
|
|
54
|
-
G append hold space to pattern space
|
|
55
|
-
x exchange pattern and hold spaces
|
|
56
|
-
n read next line into pattern space
|
|
57
|
-
N append next line to pattern space
|
|
58
|
-
y/source/dest/ transliterate characters
|
|
59
|
-
= print line number
|
|
60
|
-
l list pattern space (escape special chars)
|
|
61
|
-
b [label] branch to label
|
|
62
|
-
t [label] branch on substitution
|
|
63
|
-
T [label] branch if no substitution
|
|
64
|
-
:label define label
|
|
65
|
-
q quit
|
|
66
|
-
Q quit without printing
|
|
67
|
-
|
|
68
|
-
Addresses:
|
|
69
|
-
N line number
|
|
70
|
-
$ last line
|
|
71
|
-
/regexp/ lines matching regexp
|
|
72
|
-
N,M range from line N to M
|
|
73
|
-
first~step every step-th line starting at first`};async function H(n,e,t,i={}){let{limits:s,filename:a,fs:r,cwd:l,coverage:o}=i,d=n.endsWith(`
|
|
74
|
-
`),f=n.split(`
|
|
75
|
-
`);f.length>0&&f[f.length-1]===""&&f.pop();let v=f.length,m="",p,u=!1,h=s?.maxStringLength??0,b=R=>{if(m+=R,h>0&&m.length>h)throw new C(`sed: output size limit exceeded (${h} bytes)`,"string_length")},x="",y,te=new Map,F=new Map,$=new Map,_=new Map,ne=s?{maxIterations:s.maxSedIterations,maxStringLength:h}:void 0;for(let R=0;R<f.length;R++){let g={...Q(v,a,te),patternSpace:f[R],holdSpace:x,lastPattern:y,lineNumber:R+1,totalLines:v,substitutionMade:!1,coverage:o},ie={lines:f,currentLineIndex:R},V=0,se=1e4;g.linesConsumedInCycle=0;do{if(V++,V>se)break;if(g.restartCycle=!1,g.pendingFileReads=[],g.pendingFileWrites=[],U(e,g,ie,ne),r&&l){for(let E of g.pendingFileReads){let k=r.resolvePath(l,E.filename);try{if(E.wholeFile){let S=await r.readFile(k);g.appendBuffer.push(S.replace(/\n$/,""))}else{if(!F.has(k)){let ae=await r.readFile(k);F.set(k,ae.split(`
|
|
76
|
-
`)),$.set(k,0)}let S=F.get(k),w=$.get(k);S&&w!==void 0&&w<S.length&&(g.appendBuffer.push(S[w]),$.set(k,w+1))}}catch{}}for(let E of g.pendingFileWrites){let k=r.resolvePath(l,E.filename),S=_.get(k)||"";_.set(k,S+E.content)}}}while(g.restartCycle&&!g.deleted&&!g.quit&&!g.quitSilent);if(R+=g.linesConsumedInCycle,x=g.holdSpace,y=g.lastPattern,!t)for(let E of g.nCommandOutput)b(`${E}
|
|
77
|
-
`);let re=g.lineNumberOutput.length>0;for(let E of g.lineNumberOutput)b(`${E}
|
|
78
|
-
`);let X=[],M=[];for(let E of g.appendBuffer)E.startsWith("__INSERT__")?X.push(E.slice(10)):M.push(E);for(let E of X)b(`${E}
|
|
79
|
-
`);let L=!1;!g.deleted&&!g.quitSilent?t?g.printed&&(b(`${g.patternSpace}
|
|
80
|
-
`),L=!0):(b(`${g.patternSpace}
|
|
81
|
-
`),L=!0):g.changedText!==void 0&&(b(`${g.changedText}
|
|
82
|
-
`),L=!0);for(let E of M)b(`${E}
|
|
83
|
-
`);if(u=(re||L)&&M.length===0,g.quit||g.quitSilent){if(g.exitCode!==void 0&&(p=g.exitCode),g.errorMessage)return{output:"",exitCode:p||1,errorMessage:g.errorMessage};break}}if(r&&l)for(let[R,g]of _)try{await r.writeFile(R,g)}catch{}return!d&&u&&m.endsWith(`
|
|
84
|
-
`)&&(m=m.slice(0,-1)),{output:m,exitCode:p}}var Le={name:"sed",async execute(n,e){if(j(n))return G(me);let t=[],i=[],s=!1,a=!1,r=!1,l=[];for(let u=0;u<n.length;u++){let h=n[u];if(h==="-n"||h==="--quiet"||h==="--silent")s=!0;else if(h==="-i"||h==="--in-place")a=!0;else if(h.startsWith("-i"))a=!0;else if(h==="-E"||h==="-r"||h==="--regexp-extended")r=!0;else if(h==="-e")u+1<n.length&&t.push(n[++u]);else if(h==="-f")u+1<n.length&&i.push(n[++u]);else{if(h.startsWith("--"))return T("sed",h);if(h==="-")l.push(h);else if(h.startsWith("-")&&h.length>1){for(let b of h.slice(1))if(b!=="n"&&b!=="e"&&b!=="f"&&b!=="i"&&b!=="E"&&b!=="r")return T("sed",`-${b}`);h.includes("n")&&(s=!0),h.includes("i")&&(a=!0),(h.includes("E")||h.includes("r"))&&(r=!0),h.includes("e")&&!h.includes("n")&&!h.includes("i")&&u+1<n.length&&t.push(n[++u]),h.includes("f")&&!h.includes("e")&&u+1<n.length&&i.push(n[++u])}else!h.startsWith("-")&&t.length===0&&i.length===0?t.push(h):h.startsWith("-")||l.push(h)}}for(let u of i){let h=e.fs.resolvePath(e.cwd,u);try{let b=await e.fs.readFile(h);for(let x of b.split(`
|
|
85
|
-
`)){let y=x.trim();y&&!y.startsWith("#")&&t.push(y)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${u}: No such file or directory
|
|
86
|
-
`,exitCode:1}}}if(t.length===0)return{stdout:"",stderr:`sed: no script specified
|
|
87
|
-
`,exitCode:1};let{commands:o,error:d,silentMode:f}=J(t,r);if(d)return{stdout:"",stderr:`sed: ${d}
|
|
88
|
-
`,exitCode:1};let v=!!(s||f);if(a){if(l.length===0)return{stdout:"",stderr:`sed: -i requires at least one file argument
|
|
89
|
-
`,exitCode:1};for(let u of l){if(u==="-")continue;let h=e.fs.resolvePath(e.cwd,u);try{let b=await e.fs.readFile(h),x=await H(b,o,v,{limits:e.limits,filename:u,fs:e.fs,cwd:e.cwd,coverage:e.coverage});if(x.errorMessage)return{stdout:"",stderr:`${x.errorMessage}
|
|
90
|
-
`,exitCode:x.exitCode??1};await e.fs.writeFile(h,x.output)}catch(b){return b instanceof C?{stdout:"",stderr:`sed: ${b.message}
|
|
91
|
-
`,exitCode:C.EXIT_CODE}:{stdout:"",stderr:`sed: ${u}: No such file or directory
|
|
92
|
-
`,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}let m="";if(l.length===0){m=e.stdin;try{let u=await H(m,o,v,{limits:e.limits,fs:e.fs,cwd:e.cwd,coverage:e.coverage});return{stdout:u.output,stderr:u.errorMessage?`${u.errorMessage}
|
|
93
|
-
`:"",exitCode:u.exitCode??0}}catch(u){if(u instanceof C)return{stdout:"",stderr:`sed: ${u.message}
|
|
94
|
-
`,exitCode:C.EXIT_CODE};throw u}}let p=!1;for(let u of l){let h;if(u==="-")p?h="":(h=e.stdin,p=!0);else{let b=e.fs.resolvePath(e.cwd,u);try{h=await e.fs.readFile(b)}catch(x){return x instanceof C?{stdout:"",stderr:`sed: ${x.message}
|
|
95
|
-
`,exitCode:C.EXIT_CODE}:{stdout:"",stderr:`sed: ${u}: No such file or directory
|
|
96
|
-
`,exitCode:1}}}m.length>0&&h.length>0&&!m.endsWith(`
|
|
97
|
-
`)&&(m+=`
|
|
98
|
-
`),m+=h}try{let u=await H(m,o,v,{limits:e.limits,filename:l.length===1?l[0]:void 0,fs:e.fs,cwd:e.cwd,coverage:e.coverage});return{stdout:u.output,stderr:u.errorMessage?`${u.errorMessage}
|
|
99
|
-
`:"",exitCode:u.exitCode??0}}catch(u){if(u instanceof C)return{stdout:"",stderr:`sed: ${u.message}
|
|
100
|
-
`,exitCode:C.EXIT_CODE};throw u}}},we={name:"sed",flags:[{flag:"-n",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-E",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-e",type:"value",valueHint:"string"}],stdinType:"text",needsArgs:!0};export{Le as a,we as b};
|