@garygentry/system1 0.1.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.
- package/LICENSE +21 -0
- package/README.md +14 -0
- package/THIRD-PARTY-NOTICES.md +116 -0
- package/dist/bundle/chunks/bin-IIUCANF7.mjs +141 -0
- package/dist/bundle/chunks/chunk-5LVOFZF3.mjs +130 -0
- package/dist/bundle/chunks/chunk-7LVHD6A5.mjs +165 -0
- package/dist/bundle/chunks/chunk-A7ODZFMY.mjs +197 -0
- package/dist/bundle/chunks/chunk-V7OTO67I.mjs +20583 -0
- package/dist/bundle/chunks/config-QR35VKVT.mjs +116 -0
- package/dist/bundle/chunks/decide-PW7REJ6Y.mjs +77 -0
- package/dist/bundle/chunks/doctor-HAT6XVTW.mjs +61 -0
- package/dist/bundle/chunks/misc-6VZKJEN4.mjs +78 -0
- package/dist/bundle/chunks/spec-Z2LZJ5EZ.mjs +123 -0
- package/dist/bundle/decide.mjs +7 -0
- package/package.json +47 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
parseFileRef,
|
|
4
|
+
parseQuestionSet
|
|
5
|
+
} from "./chunk-V7OTO67I.mjs";
|
|
6
|
+
import {
|
|
7
|
+
DecisionsError
|
|
8
|
+
} from "./chunk-7LVHD6A5.mjs";
|
|
9
|
+
|
|
10
|
+
// src/args.ts
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { resolve } from "node:path";
|
|
13
|
+
import { parseArgs } from "node:util";
|
|
14
|
+
var DECIDE_OPTIONS = {
|
|
15
|
+
spec: { type: "string" },
|
|
16
|
+
question: { type: "string", multiple: true },
|
|
17
|
+
questions: { type: "string" },
|
|
18
|
+
input: { type: "string" },
|
|
19
|
+
glob: { type: "string", multiple: true },
|
|
20
|
+
file: { type: "string", multiple: true },
|
|
21
|
+
jsonl: { type: "string" },
|
|
22
|
+
diff: { type: "string" },
|
|
23
|
+
staged: { type: "boolean" },
|
|
24
|
+
text: { type: "string" },
|
|
25
|
+
stdin: { type: "boolean" },
|
|
26
|
+
"allow-outside": { type: "boolean" },
|
|
27
|
+
split: { type: "string" },
|
|
28
|
+
keep: { type: "string", multiple: true },
|
|
29
|
+
sort: { type: "string" },
|
|
30
|
+
limit: { type: "string" },
|
|
31
|
+
fields: { type: "string" },
|
|
32
|
+
"dry-run": { type: "boolean" },
|
|
33
|
+
confirm: { type: "boolean" },
|
|
34
|
+
record: { type: "boolean" },
|
|
35
|
+
replay: { type: "boolean" },
|
|
36
|
+
live: { type: "boolean" },
|
|
37
|
+
model: { type: "string" },
|
|
38
|
+
concurrency: { type: "string" },
|
|
39
|
+
help: { type: "boolean", short: "h" }
|
|
40
|
+
};
|
|
41
|
+
function parseDecideFlags(argv) {
|
|
42
|
+
try {
|
|
43
|
+
return parseArgs({ args: argv, options: DECIDE_OPTIONS, allowPositionals: true, strict: true });
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new DecisionsError("invalid-request", error.message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function typedParse(config) {
|
|
49
|
+
try {
|
|
50
|
+
return parseArgs(config);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new DecisionsError("invalid-request", error.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function buildInput(values, readStdin, cwd = process.cwd()) {
|
|
56
|
+
if (values.stdin && values.input === "-") {
|
|
57
|
+
throw new DecisionsError("invalid-request", "--stdin and --input - both want stdin; use one");
|
|
58
|
+
}
|
|
59
|
+
if (values.questions !== void 0) {
|
|
60
|
+
const clash = values.spec ? "--spec" : values.question?.length ? "--question" : void 0;
|
|
61
|
+
if (clash) {
|
|
62
|
+
throw new DecisionsError(
|
|
63
|
+
"invalid-request",
|
|
64
|
+
`--questions and ${clash} both give questions; use one`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (values.questions === "-" && (values.stdin || values.input === "-")) {
|
|
68
|
+
throw new DecisionsError(
|
|
69
|
+
"invalid-request",
|
|
70
|
+
`--questions - and ${values.stdin ? "--stdin" : "--input -"} both want stdin; put the questions in a file instead`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const base = values.input ? readJson(resolve(cwd, values.input), values.input, readStdin) : {};
|
|
75
|
+
const sources = [
|
|
76
|
+
...values.glob?.length ? [{ kind: "glob", patterns: values.glob }] : [],
|
|
77
|
+
...(values.file ?? []).map((ref) => ({ kind: "file", ...parseFileRef(ref) })),
|
|
78
|
+
...values.jsonl ? [{ kind: "jsonl", path: values.jsonl }] : [],
|
|
79
|
+
...values.diff !== void 0 || values.staged ? [
|
|
80
|
+
{
|
|
81
|
+
kind: "diff",
|
|
82
|
+
...values.diff ? { range: values.diff } : {},
|
|
83
|
+
...values.staged ? { staged: true } : {}
|
|
84
|
+
}
|
|
85
|
+
] : [],
|
|
86
|
+
...values.text !== void 0 ? [{ kind: "text", text: values.text }] : [],
|
|
87
|
+
...values.stdin ? [{ kind: "stdin", text: readStdin() }] : []
|
|
88
|
+
];
|
|
89
|
+
const modes = ["record", "replay", "live"].filter((m) => values[m]);
|
|
90
|
+
if (modes.length > 1)
|
|
91
|
+
throw new DecisionsError("invalid-request", `Pick one of --${modes.join(", --")}`);
|
|
92
|
+
const input = { ...base };
|
|
93
|
+
const set = (key, value) => {
|
|
94
|
+
if (value !== void 0) input[key] = value;
|
|
95
|
+
};
|
|
96
|
+
set("spec", values.spec);
|
|
97
|
+
if (values.question?.length) input.questions = parseQuestions(values.question);
|
|
98
|
+
if (values.questions !== void 0) {
|
|
99
|
+
const ref = values.questions;
|
|
100
|
+
const inline = ref.includes("\n") || ref.trimStart().startsWith("{");
|
|
101
|
+
input.questions = parseQuestionSet(
|
|
102
|
+
inline ? ref : ref === "-" ? readStdin() : readText(resolve(cwd, ref), ref, "--questions"),
|
|
103
|
+
inline ? "--questions (inline)" : `--questions ${ref}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (sources.length) input.sources = sources;
|
|
107
|
+
set("split", values.split);
|
|
108
|
+
set("keep", values.keep?.length ? values.keep : void 0);
|
|
109
|
+
set("sort", values.sort);
|
|
110
|
+
set("limit", int(values.limit, "--limit"));
|
|
111
|
+
set(
|
|
112
|
+
"fields",
|
|
113
|
+
values.fields ? values.fields.split(",").map((f) => f.trim()).filter(Boolean) : void 0
|
|
114
|
+
);
|
|
115
|
+
set("allowOutside", values["allow-outside"]);
|
|
116
|
+
set("dryRun", values["dry-run"]);
|
|
117
|
+
set("confirm", values.confirm);
|
|
118
|
+
set("mode", modes[0]);
|
|
119
|
+
set("model", values.model);
|
|
120
|
+
set("concurrency", int(values.concurrency, "--concurrency"));
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
function parseQuestions(texts) {
|
|
124
|
+
const questions = {};
|
|
125
|
+
for (const text of texts) {
|
|
126
|
+
const m = /^([A-Za-z_][\w-]*):(noul|choice|score):([^:]+?)(?::(.+))?$/s.exec(text);
|
|
127
|
+
if (!m?.[1] || !m[2] || !m[3]) {
|
|
128
|
+
throw new DecisionsError(
|
|
129
|
+
"invalid-request",
|
|
130
|
+
`Cannot parse --question "${text}". Use name:noul:<text>, name:choice:<text>:a=..|b=.., or name:score:<text>:l0|l1|l2`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const [, name, type, instructions, rest] = m;
|
|
134
|
+
if (name in questions)
|
|
135
|
+
throw new DecisionsError("invalid-request", `Question "${name}" given twice`);
|
|
136
|
+
if (type === "noul") {
|
|
137
|
+
if (rest)
|
|
138
|
+
throw new DecisionsError("invalid-request", `--question "${text}": a noul takes no options`);
|
|
139
|
+
questions[name] = { type, instructions: instructions.trim() };
|
|
140
|
+
} else if (type === "choice") {
|
|
141
|
+
const options = (rest ?? "").split("|").map((o) => o.trim()).filter(Boolean);
|
|
142
|
+
const criteria = Object.fromEntries(
|
|
143
|
+
options.map((o) => {
|
|
144
|
+
const eq = o.indexOf("=");
|
|
145
|
+
if (eq <= 0)
|
|
146
|
+
throw new DecisionsError(
|
|
147
|
+
"invalid-request",
|
|
148
|
+
`--question "${text}": choice options are key=description`
|
|
149
|
+
);
|
|
150
|
+
return [o.slice(0, eq).trim(), o.slice(eq + 1).trim()];
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
questions[name] = { type, instructions: instructions.trim(), criteria };
|
|
154
|
+
} else {
|
|
155
|
+
questions[name] = {
|
|
156
|
+
type,
|
|
157
|
+
instructions: instructions.trim(),
|
|
158
|
+
criteria: (rest ?? "").split("|").map((l) => l.trim()).filter(Boolean)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return questions;
|
|
163
|
+
}
|
|
164
|
+
function readJson(path, ref, readStdin) {
|
|
165
|
+
const text = ref === "-" ? readStdin() : readText(path, ref);
|
|
166
|
+
try {
|
|
167
|
+
const value = JSON.parse(text);
|
|
168
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
169
|
+
throw new Error("not an object");
|
|
170
|
+
return value;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw new DecisionsError(
|
|
173
|
+
"invalid-request",
|
|
174
|
+
`--input ${ref}: not a JSON object (${error.message})`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function readText(path, ref, flag = "--input") {
|
|
179
|
+
try {
|
|
180
|
+
return readFileSync(path, "utf8");
|
|
181
|
+
} catch {
|
|
182
|
+
const hint = flag === "--questions" && /:\s/.test(ref) ? " (inline questions must be JSON, or YAML spanning several lines)" : "";
|
|
183
|
+
throw new DecisionsError("invalid-request", `${flag}: cannot read ${ref}${hint}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function int(value, flag) {
|
|
187
|
+
if (value === void 0) return void 0;
|
|
188
|
+
if (!/^\d+$/.test(value))
|
|
189
|
+
throw new DecisionsError("invalid-request", `${flag} must be a whole number`);
|
|
190
|
+
return Number(value);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
parseDecideFlags,
|
|
195
|
+
typedParse,
|
|
196
|
+
buildInput
|
|
197
|
+
};
|