@brainervirus/workit-codex 8.17.1 → 8.19.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.
@@ -10,8 +10,13 @@ import { spawnSync } from "node:child_process";
10
10
  import fs from "node:fs";
11
11
  import path from "node:path";
12
12
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
13
- var CHECKS_FILE = "workit.checks.json";
14
- var checksConfigFile = (root) => path.join(root, CHECKS_FILE);
13
+ var CHECKS_FILE = ".workit/checks.json";
14
+ var LEGACY_CHECKS_FILE = "workit.checks.json";
15
+ function checksConfigFile(root) {
16
+ const current = path.join(root, CHECKS_FILE);
17
+ const legacy = path.join(root, LEGACY_CHECKS_FILE);
18
+ return !fs.existsSync(current) && fs.existsSync(legacy) ? legacy : current;
19
+ }
15
20
  function repoHeavyCommands(root) {
16
21
  try {
17
22
  const value = JSON.parse(fs.readFileSync(checksConfigFile(root), "utf8"));
@@ -135,19 +140,25 @@ var GATES = ["testing", "verification"];
135
140
  function loadCheckConfig(cwd) {
136
141
  const root = checkRoot(cwd);
137
142
  const file = checksConfigFile(root);
143
+ const legacy = path.basename(file) === LEGACY_CHECKS_FILE;
144
+ const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
145
+ const note = legacy ? {
146
+ note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
147
+ } : {};
138
148
  const none = (error = null) => ({
139
- source: error ? CHECKS_FILE : "none",
149
+ source: error ? label : "none",
140
150
  root,
141
151
  checks: [],
142
152
  gates: {},
143
- error
153
+ error,
154
+ ...note
144
155
  });
145
156
  let text = null;
146
157
  try {
147
158
  text = fs.readFileSync(file, "utf8");
148
159
  } catch (error) {
149
160
  if (error.code !== "ENOENT")
150
- return none(`cannot read ${CHECKS_FILE}: ${error.message}`);
161
+ return none(`cannot read ${label}: ${error.message}`);
151
162
  }
152
163
  if (text === null) {
153
164
  const checks = detectedChecks(root);
@@ -157,33 +168,33 @@ function loadCheckConfig(cwd) {
157
168
  try {
158
169
  parsed = JSON.parse(text);
159
170
  } catch {
160
- return none(`${CHECKS_FILE} is not valid JSON`);
171
+ return none(`${label} is not valid JSON`);
161
172
  }
162
173
  if (!isRecord(parsed) || !isRecord(parsed.checks))
163
- return none(`${CHECKS_FILE} must be {"checks":{"<name>":"<command>"|["argv",…]}}`);
174
+ return none(`${label} must be {"checks":{"<name>":"<command>"|["argv",…]}}`);
164
175
  const checks = [];
165
176
  for (const [name, value] of Object.entries(parsed.checks)) {
166
177
  if (!CHECK_NAME.test(name))
167
- return none(`${CHECKS_FILE}: check name "${name}" must match ${CHECK_NAME.source}`);
178
+ return none(`${label}: check name "${name}" must match ${CHECK_NAME.source}`);
168
179
  const argv = typeof value === "string" ? splitCommand(value) : Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string" && item.length > 0) ? value : new Error("expected a command string or a non-empty argv array");
169
180
  if (argv instanceof Error)
170
- return none(`${CHECKS_FILE}: check "${name}": ${argv.message}`);
181
+ return none(`${label}: check "${name}": ${argv.message}`);
171
182
  checks.push({ name, argv, accepts: [argv] });
172
183
  }
173
184
  const gates = {};
174
185
  if (parsed.gates !== undefined) {
175
186
  if (!isRecord(parsed.gates))
176
- return none(`${CHECKS_FILE}: gates must be {"testing":"<name>"|["<name>",…]}`);
187
+ return none(`${label}: gates must be {"testing":"<name>"|["<name>",…]}`);
177
188
  for (const [gate, value] of Object.entries(parsed.gates)) {
178
189
  if (!GATES.includes(gate))
179
- return none(`${CHECKS_FILE}: unknown gate "${gate}" (use ${GATES.join(" or ")})`);
190
+ return none(`${label}: unknown gate "${gate}" (use ${GATES.join(" or ")})`);
180
191
  const names = typeof value === "string" ? [value] : value;
181
192
  if (!Array.isArray(names) || names.length === 0 || !names.every((name) => typeof name === "string" && checks.some((c) => c.name === name)))
182
- return none(`${CHECKS_FILE}: gates.${gate} must name configured checks`);
193
+ return none(`${label}: gates.${gate} must name configured checks`);
183
194
  gates[gate] = names;
184
195
  }
185
196
  }
186
- return { source: CHECKS_FILE, root, checks, gates, error: null, resources: parsed.resources };
197
+ return { source: label, root, checks, gates, error: null, ...note, resources: parsed.resources };
187
198
  }
188
199
  var sameArgv = (left, right) => left.length === right.length && left.every((item, index) => item === right[index]);
189
200
  function matchesNamedCheck(config, name, argv, cwd) {