@inhuman.tools/policy 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-with-invariant.js","sourceRoot":"","sources":["../src/error-with-invariant.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,SAAS,CAEd,SAAkB,EAClB,GAAG,IAA8B;QAEjC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -1,43 +0,0 @@
1
- /**
2
- * Pure license decisions. One `LicenseFacts` bag — no jobs.
3
- * Short-circuit order is the law. Do not reorder.
4
- * Job readers stay in harness-model.
5
- */
6
- export type LicenseFacts = {
7
- readonly humanApprove: boolean | null;
8
- readonly completed: boolean;
9
- readonly cancelled: boolean;
10
- readonly commFirst: boolean;
11
- readonly fileReadGrant: boolean;
12
- readonly policy: "manual" | "auto" | "yolo";
13
- readonly policyResult: "policyApprove" | "deny" | "ask" | "block" | null;
14
- readonly classifierResult: "allow" | "deny" | null;
15
- readonly classifierAbstain: string | null;
16
- readonly hatch: boolean;
17
- readonly clusterGranted: boolean;
18
- readonly writeClassifierOff: boolean;
19
- readonly unattended: boolean;
20
- readonly coverDeny: boolean;
21
- };
22
- /** Stored `allow` and `approve` are the previous positive spellings. */
23
- export declare function asPolicyResult(value: unknown): LicenseFacts["policyResult"];
24
- /** Floor `ask` and `deny` share remainder `"ask"`. Ignores hatch. `block` is not remainder. */
25
- export declare function autoRemainderOf(facts: LicenseFacts): "ask" | null;
26
- /** Auto floor `ask` that allow-sides: not hatch, cluster already granted. */
27
- export declare function autoAllowSkip(facts: LicenseFacts): boolean;
28
- /** Floor ask/deny except auto allow-skip. Floor allow is not remainder. */
29
- export declare function autoRemainder(facts: LicenseFacts): "ask" | null;
30
- /**
31
- * Remainder classifier intern. Not the cover. Ungranted write never
32
- * classifies, including after a fail message. Deny classifies when
33
- * unattended, when cover is off, or when the cluster is granted.
34
- */
35
- export declare function autoClassifierPending(facts: LicenseFacts): boolean;
36
- /** Cover predicate. Not a license bit. */
37
- export declare function needsHuman(facts: LicenseFacts): boolean;
38
- /** `true` allow / `false` deny / `null` still waiting. Human first, then the floor. */
39
- export declare function licenseDecision(facts: LicenseFacts): boolean | null;
40
- export declare function licenseAllows(facts: LicenseFacts): boolean;
41
- /** Known-safe leaves. Approved and any judge vote stay visible. */
42
- export declare function tapeFuse(facts: LicenseFacts): boolean;
43
- //# sourceMappingURL=license-law.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"license-law.d.ts","sourceRoot":"","sources":["../src/license-law.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAC5C,QAAQ,CAAC,YAAY,EAAE,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC;IACzE,QAAQ,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;IACnD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAAC,cAAc,CAAC,CAI3E;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,GAAG,IAAI,CAQjE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAS1D;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,GAAG,IAAI,CAO/D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAYlE;AAED,0CAA0C;AAC1C,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAgBvD;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,GAAG,IAAI,CA2BnE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAE1D;AAED,mEAAmE;AACnE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAerD"}
@@ -1,129 +0,0 @@
1
- /**
2
- * Pure license decisions. One `LicenseFacts` bag — no jobs.
3
- * Short-circuit order is the law. Do not reorder.
4
- * Job readers stay in harness-model.
5
- */
6
- /** Stored `allow` and `approve` are the previous positive spellings. */
7
- export function asPolicyResult(value) {
8
- if (value === "policyApprove" || value === "allow" || value === "approve")
9
- return "policyApprove";
10
- if (value === "deny" || value === "ask" || value === "block")
11
- return value;
12
- return null;
13
- }
14
- /** Floor `ask` and `deny` share remainder `"ask"`. Ignores hatch. `block` is not remainder. */
15
- export function autoRemainderOf(facts) {
16
- switch (true) {
17
- case facts.policyResult === "ask":
18
- case facts.policyResult === "deny":
19
- return "ask";
20
- default:
21
- return null;
22
- }
23
- }
24
- /** Auto floor `ask` that allow-sides: not hatch, cluster already granted. */
25
- export function autoAllowSkip(facts) {
26
- switch (true) {
27
- case facts.policy !== "auto":
28
- case facts.policyResult !== "ask":
29
- case facts.hatch:
30
- return false;
31
- default:
32
- return facts.clusterGranted;
33
- }
34
- }
35
- /** Floor ask/deny except auto allow-skip. Floor allow is not remainder. */
36
- export function autoRemainder(facts) {
37
- switch (true) {
38
- case autoAllowSkip(facts):
39
- return null;
40
- default:
41
- return autoRemainderOf(facts);
42
- }
43
- }
44
- /**
45
- * Remainder classifier intern. Not the cover. Ungranted write never
46
- * classifies, including after a fail message. Deny classifies when
47
- * unattended, when cover is off, or when the cluster is granted.
48
- */
49
- export function autoClassifierPending(facts) {
50
- switch (true) {
51
- case facts.policy !== "auto":
52
- case autoRemainder(facts) === null || facts.classifierResult !== null:
53
- case facts.writeClassifierOff:
54
- return false;
55
- case facts.classifierAbstain !== null:
56
- case facts.unattended || facts.policyResult === "ask":
57
- return true;
58
- default:
59
- return facts.policyResult === "deny" && (!facts.coverDeny || facts.clusterGranted);
60
- }
61
- }
62
- /** Cover predicate. Not a license bit. */
63
- export function needsHuman(facts) {
64
- switch (true) {
65
- case facts.completed || facts.cancelled || facts.humanApprove !== null:
66
- case facts.commFirst:
67
- case facts.fileReadGrant:
68
- return false;
69
- case facts.policy === "manual" && (facts.policyResult === "ask" || facts.policyResult === "deny"):
70
- return true;
71
- case facts.policy !== "auto":
72
- case autoRemainder(facts) === null || facts.classifierResult !== null:
73
- return false;
74
- case autoClassifierPending(facts):
75
- return facts.classifierAbstain !== null;
76
- default:
77
- return true;
78
- }
79
- }
80
- /** `true` allow / `false` deny / `null` still waiting. Human first, then the floor. */
81
- export function licenseDecision(facts) {
82
- switch (true) {
83
- case facts.humanApprove === true:
84
- return true;
85
- case facts.humanApprove === false:
86
- return false;
87
- case facts.commFirst:
88
- return true;
89
- case facts.policyResult === "block":
90
- return false;
91
- case facts.fileReadGrant:
92
- case facts.policyResult === "policyApprove":
93
- case facts.policy === "yolo" && (facts.policyResult === "ask" || facts.policyResult === "deny"):
94
- case autoAllowSkip(facts):
95
- return true;
96
- case facts.policy === "auto" && autoRemainderOf(facts) !== null:
97
- switch (facts.classifierResult) {
98
- case "allow":
99
- return true;
100
- case "deny":
101
- return false;
102
- default:
103
- return null;
104
- }
105
- default:
106
- return null;
107
- }
108
- }
109
- export function licenseAllows(facts) {
110
- return licenseDecision(facts) === true;
111
- }
112
- /** Known-safe leaves. Approved and any judge vote stay visible. */
113
- export function tapeFuse(facts) {
114
- switch (true) {
115
- case facts.humanApprove !== null:
116
- case facts.classifierResult !== null:
117
- return false;
118
- case facts.commFirst:
119
- case autoAllowSkip(facts):
120
- return true;
121
- case facts.policyResult === "ask":
122
- case facts.policyResult === "deny":
123
- case facts.policyResult === "block":
124
- return false;
125
- default:
126
- return true;
127
- }
128
- }
129
- //# sourceMappingURL=license-law.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"license-law.js","sourceRoot":"","sources":["../src/license-law.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,KAAK,KAAK,eAAe,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC;IAClG,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAAC,KAAmB;IACjD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC;QAClC,KAAK,KAAK,CAAC,YAAY,KAAK,MAAM;YAChC,OAAO,KAAK,CAAC;QACf;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;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K,CAAC,KAAK,IAAI;YAC7D,QAAQ,KAAK,CAAC,gBAAgB,EAAE,CAAC;gBAC/B,KAAK,OAAO;oBACV,OAAO,IAAI,CAAC;gBACd,KAAK,MAAM;oBACT,OAAO,KAAK,CAAC;gBACf;oBACE,OAAO,IAAI,CAAC;YAChB,CAAC;QACH;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAmB;IAC/C,OAAO,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AACzC,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,QAAQ,CAAC,KAAmB;IAC1C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;QACjC,KAAK,KAAK,CAAC,gBAAgB,KAAK,IAAI;YAClC,OAAO,KAAK,CAAC;QACf,KAAK,KAAK,CAAC,SAAS,CAAC;QACrB,KAAK,aAAa,CAAC,KAAK,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,KAAK,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC;QAClC,KAAK,KAAK,CAAC,YAAY,KAAK,MAAM,CAAC;QACnC,KAAK,KAAK,CAAC,YAAY,KAAK,OAAO;YACjC,OAAO,KAAK,CAAC;QACf;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
package/dist/license.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { asPolicyResult, autoAllowSkip, autoClassifierPending, autoRemainder, autoRemainderOf, licenseAllows, licenseDecision, needsHuman, tapeFuse, } from "./license-law.js";
2
- export type { LicenseFacts } from "./license-law.js";
3
- //# sourceMappingURL=license.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,EACf,UAAU,EACV,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/license.js DELETED
@@ -1,2 +0,0 @@
1
- export { asPolicyResult, autoAllowSkip, autoClassifierPending, autoRemainder, autoRemainderOf, licenseAllows, licenseDecision, needsHuman, tapeFuse, } from "./license-law.js";
2
- //# sourceMappingURL=license.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,EACf,UAAU,EACV,QAAQ,GACT,MAAM,kBAAkB,CAAC"}
@@ -1,8 +0,0 @@
1
- export type PeeledCd = {
2
- readonly cwd: string;
3
- readonly command: string;
4
- };
5
- export declare function peelLeadingCd(source: string): PeeledCd | null;
6
- /** Keep an explicit `cwd` arg when it names the same leaf; never override a disagreement. */
7
- export declare function peelShellCwd(command: string, cwdArg?: string): PeeledCd | null;
8
- //# sourceMappingURL=peel-cwd.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"peel-cwd.d.ts","sourceRoot":"","sources":["../src/peel-cwd.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAyB7D;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAU9E"}
package/dist/peel-cwd.js DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * Peel a leading cwd-only `cd` off a shell command into the `cwd` arg.
3
- * Unbash AST, not regex. Quoted `;` is not a splitter. Remainder stays
4
- * one `/bin/sh -c` — this is not execute-split.
5
- *
6
- * Peel only the first top-level list element (`&&` or `;` / newline).
7
- * `||`, pipes, subshells, brace groups, `cd` that is not first, and
8
- * `cd` with flags/extra operands stay on the command string.
9
- */
10
- import { parse } from "unbash";
11
- const PARTLESS_FORBIDDEN = /[*?[\\$`]/;
12
- export function peelLeadingCd(source) {
13
- const script = parse(source);
14
- if (script.errors !== undefined && script.errors.length > 0)
15
- return null;
16
- const statements = script.commands;
17
- if (statements.length === 0)
18
- return null;
19
- const first = statements[0];
20
- if (first === undefined || first.background === true || first.redirects.length > 0)
21
- return null;
22
- const node = first.command;
23
- const simple = asSimpleCommand(node);
24
- if (simple !== null) {
25
- const cwd = cwdOnlyPath(simple);
26
- if (cwd === null)
27
- return null;
28
- if (statements.length === 1)
29
- return { cwd, command: "" };
30
- return { cwd, command: source.slice(statements[1].pos).trim() };
31
- }
32
- if (node.type !== "AndOr" || node.operators[0] !== "&&")
33
- return null;
34
- const head = asSimpleCommand(node.commands[0]);
35
- if (head === null)
36
- return null;
37
- const cwd = cwdOnlyPath(head);
38
- if (cwd === null)
39
- return null;
40
- const rest = node.commands[1];
41
- if (rest === undefined)
42
- return { cwd, command: "" };
43
- return { cwd, command: source.slice(rest.pos).trim() };
44
- }
45
- /** Keep an explicit `cwd` arg when it names the same leaf; never override a disagreement. */
46
- export function peelShellCwd(command, cwdArg) {
47
- const peeled = peelLeadingCd(command);
48
- if (peeled === null)
49
- return null;
50
- if (cwdArg !== undefined && cwdArg !== "" && normalizeCwdToken(cwdArg) !== normalizeCwdToken(peeled.cwd)) {
51
- return null;
52
- }
53
- return {
54
- cwd: cwdArg !== undefined && cwdArg !== "" ? cwdArg : peeled.cwd,
55
- command: peeled.command,
56
- };
57
- }
58
- function normalizeCwdToken(raw) {
59
- let token = raw.replaceAll("\\", "/").replace(/\/+$/, "");
60
- if (token.startsWith("./"))
61
- token = token.slice(2);
62
- return token === "" ? "." : token;
63
- }
64
- function asSimpleCommand(node) {
65
- if (node === undefined)
66
- return null;
67
- if (node.type === "Command")
68
- return node;
69
- if (node.type !== "Pipeline")
70
- return null;
71
- if (node.commands.length !== 1 || (node.operators?.length ?? 0) > 0)
72
- return null;
73
- if (node.negated === true || node.time === true)
74
- return null;
75
- return asSimpleCommand(node.commands[0]);
76
- }
77
- function cwdOnlyPath(command) {
78
- if (command.prefix.length > 0 || command.redirects.length > 0)
79
- return null;
80
- if (command.name === undefined || !isLiteralWord(command.name))
81
- return null;
82
- let argv0 = command.name.value;
83
- let suffix = command.suffix;
84
- if (argv0 === "builtin" || argv0 === "command") {
85
- const inner = suffix[0];
86
- if (inner === undefined || !isLiteralWord(inner) || inner.value !== "cd")
87
- return null;
88
- argv0 = "cd";
89
- suffix = suffix.slice(1);
90
- }
91
- if (argv0 !== "cd" || suffix.length !== 1)
92
- return null;
93
- const dest = suffix[0];
94
- if (dest === undefined || !isLiteralWord(dest))
95
- return null;
96
- const value = dest.value;
97
- if (value === "" || value === "-" || value === "--" || value.startsWith("-"))
98
- return null;
99
- return value;
100
- }
101
- function isLiteralWord(word) {
102
- if (word.parts === undefined) {
103
- return !PARTLESS_FORBIDDEN.test(word.text) && !word.text.startsWith("~");
104
- }
105
- return word.parts.every(partIsLiteral);
106
- }
107
- function partIsLiteral(part) {
108
- switch (part.type) {
109
- case "Literal":
110
- case "SingleQuoted":
111
- return true;
112
- case "AnsiCQuoted":
113
- return !part.value.includes("\0");
114
- case "DoubleQuoted":
115
- return part.parts.every((child) => child.type === "Literal");
116
- default:
117
- return false;
118
- }
119
- }
120
- //# sourceMappingURL=peel-cwd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"peel-cwd.js","sourceRoot":"","sources":["../src/peel-cwd.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,EAAqD,MAAM,QAAQ,CAAC;AAOlF,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC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C,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC/D;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
package/dist/prep.d.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * Question prep: unbash AST → prepared questions + unparsed acts.
3
- * Hermetic — no PATH, no process.env, no execution. Word.parts is a lazy
4
- * getter; this file always reads it. Nested parse errors live on the nested
5
- * script, not the root.
6
- *
7
- * Partition builds I: a known value-flag attaches; an unknown flag followed
8
- * by a non-dash, non-`--` token forks attached and boolean readings.
9
- * `valueFlagsFor(argv0, suffix)` sees the leading positional spine — not
10
- * every descendant under argv0. `=value` and glued shorts stay one reading.
11
- * `--` never attaches as a value. Cap 16 is open ruling 5; overflow is ⊤I.
12
- * A nameless command still emits its redirects. `xargs -a FILE` is a read
13
- * of FILE as well as the inner command.
14
- */
15
- import { type ParseError } from "unbash";
16
- import { type Which } from "./identity.js";
17
- import type { Question, Reading } from "./types.js";
18
- export type UnparsedVia = "parse-error" | "control-flow" | "function" | "source" | "test" | "arithmetic" | "coproc" | "find-expression" | "non-literal-argv0" | "script-string";
19
- export type UnparsedAct = {
20
- readonly via: UnparsedVia;
21
- readonly source: string;
22
- };
23
- export type RedirectEmit = {
24
- readonly operator: string;
25
- readonly target: string;
26
- };
27
- export type PreparedQuestion = Question & {
28
- readonly wrapChain: readonly string[];
29
- readonly elevated: boolean;
30
- readonly envDelta: Readonly<Record<string, string>>;
31
- readonly redirects: readonly RedirectEmit[];
32
- readonly background: boolean;
33
- readonly stdinIsPipe: boolean;
34
- };
35
- export type PrepResult = {
36
- readonly questions: readonly PreparedQuestion[];
37
- readonly unparsed: readonly UnparsedAct[];
38
- readonly errors: readonly ParseError[];
39
- /** File effects from commands that have no argv0 (`> .env`). */
40
- readonly redirects: readonly RedirectEmit[];
41
- };
42
- export type PrepOpts = {
43
- readonly valueFlags?: ReadonlySet<string>;
44
- readonly valueFlagsFor?: (argv0: string, suffix: readonly string[]) => ReadonlySet<string> | undefined;
45
- /** Path-form peelers are transparent only when this agrees. */
46
- readonly which?: Which;
47
- };
48
- export declare function prep(source: string, opts?: PrepOpts): PrepResult;
49
- /**
50
- * Tokenize argv into positionals + flag bag.
51
- * `closed`: only those names are flags; other dash tokens are positionals.
52
- * Used when a `"--"` field reopens the suffix — undeclared `-file` stays a path.
53
- */
54
- export declare function partition(words: readonly string[], valueFlags: ReadonlySet<string> | undefined, closed?: ReadonlySet<string>): {
55
- readings: Reading[];
56
- overflow: boolean;
57
- };
58
- //# sourceMappingURL=prep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prep.d.ts","sourceRoot":"","sources":["../src/prep.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAML,KAAK,UAAU,EAOhB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,WAAW,GACnB,aAAa,GACb,cAAc,GACd,UAAU,GACV,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,QAAQ,GACR,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,CAAC;AAEpB,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG;IACxC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OA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