@pixelfactoryio/theway 0.11.0 → 0.13.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/dist/theway.js CHANGED
@@ -9430,7 +9430,12 @@ import {
9430
9430
  statSync as statSync2,
9431
9431
  writeFileSync
9432
9432
  } from "node:fs";
9433
- var SHIPPED_DIRS = ["standards", "templates"];
9433
+ var SHIPPED_DIRS = [
9434
+ { dir: "standards", ext: ".md", shared: "standards" },
9435
+ { dir: "templates", ext: ".md" },
9436
+ { dir: "workflows", ext: ".yaml", shared: "workflows" },
9437
+ { dir: "lenses", ext: ".md", shared: "lenses" }
9438
+ ];
9434
9439
  var MANIFEST = ".shipped.json";
9435
9440
  var sha256 = (data) => createHash("sha256").update(data).digest("hex");
9436
9441
  function readManifest(home) {
@@ -9523,16 +9528,18 @@ function migrateDataStandards(src, home) {
9523
9528
  function copyShipped(src, home) {
9524
9529
  const previous = readManifest(home);
9525
9530
  const manifest = {};
9526
- for (const dir of SHIPPED_DIRS) {
9527
- const isStandards = dir === "standards";
9531
+ for (const { dir, ext, shared } of SHIPPED_DIRS) {
9532
+ const isShared = shared !== undefined;
9533
+ const stemOf = (name) => name.slice(0, -ext.length);
9534
+ const defaultExt = `.default${ext}`;
9528
9535
  mkdirSync2(`${home}/${dir}`, { recursive: true });
9529
- const names = readdirSync2(`${src}/${dir}`, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
9536
+ const names = readdirSync2(`${src}/${dir}`, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(ext)).map((e) => e.name).sort();
9530
9537
  for (const name of names) {
9531
9538
  const rel = `${dir}/${name}`;
9532
9539
  const dst = `${home}/${rel}`;
9533
9540
  const shipped = readFileSync5(`${src}/${rel}`);
9534
9541
  const old = previous?.[rel];
9535
- const sibling = `${dir}/${baseOf(name)}.default.md`;
9542
+ const sibling = `${dir}/${stemOf(name)}${defaultExt}`;
9536
9543
  let removeSibling = true;
9537
9544
  let record = true;
9538
9545
  if (!existsSync2(dst)) {
@@ -9542,12 +9549,12 @@ function copyShipped(src, home) {
9542
9549
  if (!current.equals(shipped)) {
9543
9550
  if (typeof old === "string" && sha256(current) === old) {
9544
9551
  writeAtomic(dst, shipped);
9545
- } else if (typeof old === "string" || isStandards && previous === undefined) {
9552
+ } else if (typeof old === "string" || isShared && previous === undefined) {
9546
9553
  removeSibling = false;
9547
9554
  writeAtomic(`${home}/${sibling}`, shipped);
9548
9555
  process.stdout.write(`Kept your edited ${rel} (shipped version: ${sibling})
9549
9556
  `);
9550
- } else if (isStandards) {
9557
+ } else if (isShared) {
9551
9558
  removeSibling = false;
9552
9559
  record = false;
9553
9560
  writeAtomic(`${home}/${sibling}`, shipped);
@@ -9568,9 +9575,9 @@ function copyShipped(src, home) {
9568
9575
  if (record)
9569
9576
  manifest[rel] = sha256(shipped);
9570
9577
  }
9571
- if (isStandards) {
9578
+ if (isShared) {
9572
9579
  for (const [rel, hash] of Object.entries(previous ?? {})) {
9573
- if (!rel.startsWith("standards/") || names.includes(rel.slice("standards/".length)))
9580
+ if (!rel.startsWith(`${dir}/`) || names.includes(rel.slice(dir.length + 1)))
9574
9581
  continue;
9575
9582
  const path2 = `${home}/${rel}`;
9576
9583
  if (!existsSync2(path2))
@@ -9580,15 +9587,15 @@ function copyShipped(src, home) {
9580
9587
  process.stdout.write(`Removed ${rel}: theway no longer ships it
9581
9588
  `);
9582
9589
  } else {
9583
- process.stdout.write(`Kept your edited ${rel}: theway no longer ships it, so it is now one of your standards
9590
+ process.stdout.write(`Kept your edited ${rel}: theway no longer ships it, so it is now one of your ${shared}
9584
9591
  `);
9585
9592
  }
9586
9593
  }
9587
9594
  for (const entry of readdirSync2(`${home}/${dir}`, { withFileTypes: true })) {
9588
9595
  const file = entry.name;
9589
- if (!entry.isFile() || !file.endsWith(".default.md"))
9596
+ if (!entry.isFile() || !file.endsWith(defaultExt))
9590
9597
  continue;
9591
- if (!names.includes(`${file.slice(0, -".default.md".length)}.md`))
9598
+ if (!names.includes(`${file.slice(0, -defaultExt.length)}${ext}`))
9592
9599
  rmSync(`${home}/${dir}/${file}`, { force: true });
9593
9600
  }
9594
9601
  }
@@ -9637,10 +9644,14 @@ var bool = (d) => ({ rule: "boolean", default: d });
9637
9644
  var model = (d) => ({ rule: "model", default: d });
9638
9645
  var OPT_IN = ["core-principles.md", "sre.md", "web-development.md", "quality.md"];
9639
9646
  var CORE = ["interaction.md", "develop.md", "tamm-framework.md", "spec-review.md", "spec-investigation.md"];
9640
- var SHARED = new Set(["data", "templates", "standards"]);
9647
+ var CONVENTIONS = ["commits.md", "git-host.md"];
9648
+ var SHARED = new Set(["data", "templates", "standards", "workflows", "lenses"]);
9649
+ var isShared = (project) => SHARED.has(project);
9650
+ var NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
9651
+ var isLensList = (v) => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === "string" && NAME.test(n)) && new Set(v).size === v.length;
9641
9652
  var keyOf = (name) => name.slice(0, -".md".length).replaceAll("-", "_");
9642
9653
  var OPT_IN_KEYS = OPT_IN.map(keyOf);
9643
- var CORE_KEYS = new Set(CORE.map(keyOf));
9654
+ var FIXED_KEYS = new Set([...CORE, ...CONVENTIONS].map(keyOf));
9644
9655
  function mdFiles(dir) {
9645
9656
  let names;
9646
9657
  try {
@@ -9653,16 +9664,19 @@ function mdFiles(dir) {
9653
9664
  function standardsOf(home, project) {
9654
9665
  const globalDir = join4(home, "standards");
9655
9666
  const projectDir = join4(home, project, "standards");
9656
- const projectNames = SHARED.has(project) ? [] : mdFiles(projectDir);
9667
+ const projectNames = isShared(project) ? [] : mdFiles(projectDir).filter((n) => !CONVENTIONS.includes(n));
9657
9668
  const shipped = readManifest(home) ?? {};
9658
9669
  const out = [];
9659
9670
  for (const name of mdFiles(globalDir)) {
9660
- if (CORE.includes(name) || projectNames.includes(name))
9671
+ if (CORE.includes(name) || CONVENTIONS.includes(name))
9661
9672
  continue;
9662
9673
  const optIn = OPT_IN.includes(name);
9663
9674
  if (!optIn && ((`standards/${name}` in shipped) || name.endsWith(".default.md")))
9664
9675
  continue;
9665
- out.push({ path: join4(globalDir, name), key: keyOf(name), optIn });
9676
+ const global = { path: join4(globalDir, name), key: keyOf(name), optIn };
9677
+ if (projectNames.includes(name))
9678
+ global.shadowedBy = join4(projectDir, name);
9679
+ out.push(global);
9666
9680
  }
9667
9681
  for (const name of projectNames)
9668
9682
  out.push({ path: join4(projectDir, name), key: keyOf(name), optIn: false });
@@ -9680,21 +9694,31 @@ function standardsSchema(standards) {
9680
9694
  var SCHEMA = {
9681
9695
  standards: {},
9682
9696
  engineering: {
9683
- review_rounds: { rule: "non-negative", default: 1 },
9684
- models: { critic: model("opus") }
9697
+ review: {
9698
+ rounds: { rule: "non-negative", default: 1 },
9699
+ model: model("opus")
9700
+ }
9685
9701
  },
9686
9702
  workflow: {
9687
- review_rounds: { rule: "non-negative", default: 1 },
9688
- ci_attempts: { rule: "positive", default: 2 },
9689
- open_pr: bool(true),
9690
- models: { implementer: model("opus"), reviewer: model("opus"), fix: model("opus"), ci: model("sonnet") }
9703
+ defaults: {
9704
+ implement: { model: model("opus") },
9705
+ review: {
9706
+ rounds: { rule: "positive", default: 1 },
9707
+ lenses: { rule: "lenses", default: ["conformance", "correctness"] },
9708
+ model: model("opus"),
9709
+ fix_model: model("opus")
9710
+ },
9711
+ pr: { ci_attempts: { rule: "positive", default: 2 }, model: model("sonnet"), fix_model: model("opus") },
9712
+ agent: { model: model("sonnet") }
9713
+ }
9691
9714
  }
9692
9715
  };
9693
9716
  var RULE_TEXT = {
9694
9717
  boolean: "true or false",
9695
9718
  "non-negative": "a non-negative integer",
9696
9719
  positive: "a positive integer",
9697
- model: "opus or sonnet"
9720
+ model: "opus, sonnet or haiku",
9721
+ lenses: "a non-empty list of names without duplicates"
9698
9722
  };
9699
9723
  var isLeaf = (node) => typeof node.rule === "string";
9700
9724
  function valid(rule, v) {
@@ -9706,13 +9730,16 @@ function valid(rule, v) {
9706
9730
  case "positive":
9707
9731
  return typeof v === "number" && Number.isInteger(v) && v >= 1;
9708
9732
  case "model":
9709
- return v === "opus" || v === "sonnet";
9733
+ return v === "opus" || v === "sonnet" || v === "haiku";
9734
+ case "lenses":
9735
+ return isLensList(v);
9710
9736
  }
9711
9737
  }
9712
9738
  function defaults(schema) {
9713
9739
  const out = dict();
9714
- for (const [key, node] of Object.entries(schema))
9715
- out[key] = isLeaf(node) ? node.default : defaults(node);
9740
+ for (const [key, node] of Object.entries(schema)) {
9741
+ out[key] = isLeaf(node) ? Array.isArray(node.default) ? [...node.default] : node.default : defaults(node);
9742
+ }
9716
9743
  return out;
9717
9744
  }
9718
9745
  var warnLoud = (file, text) => {
@@ -9728,13 +9755,13 @@ function apply(file, schema, layer, into, prefix, warn) {
9728
9755
  if (node === undefined) {
9729
9756
  if (prefix !== "standards")
9730
9757
  warn(file, `unknown key ${dotted}`);
9731
- else if (CORE_KEYS.has(key))
9758
+ else if (FIXED_KEYS.has(key))
9732
9759
  warn(file, `${dotted} cannot be switched`);
9733
9760
  else
9734
9761
  warn(file, `${dotted} has no standard file`);
9735
9762
  } else if (isLeaf(node)) {
9736
9763
  if (valid(node.rule, value))
9737
- into[key] = value;
9764
+ into[key] = Array.isArray(value) ? [...value] : value;
9738
9765
  else
9739
9766
  warn(file, `${dotted} must be ${RULE_TEXT[node.rule]}`);
9740
9767
  } else if (value instanceof Map) {
@@ -9820,10 +9847,7 @@ import { join as join5 } from "node:path";
9820
9847
  // src/core/standards.ts
9821
9848
  import { readFileSync as readFileSync7 } from "node:fs";
9822
9849
  var PHASES = ["engineering", "develop", "document"];
9823
- var USER_PHASES = ["engineering", "develop"];
9824
- var OPT_IN_PHASES = ["engineering", "document"];
9825
9850
  var isPhase = (v) => PHASES.includes(v);
9826
- var isUserPhase = (v) => USER_PHASES.includes(v);
9827
9851
  function parseList(first, rest) {
9828
9852
  let values;
9829
9853
  if (first !== "") {
@@ -9840,7 +9864,7 @@ function parseList(first, rest) {
9840
9864
  values.push((item[1] ?? "").trim());
9841
9865
  }
9842
9866
  }
9843
- if (values.length === 0 || !values.every(isUserPhase))
9867
+ if (values.length === 0 || !values.every(isPhase))
9844
9868
  return null;
9845
9869
  return values;
9846
9870
  }
@@ -9856,19 +9880,19 @@ function phasesOf(path2) {
9856
9880
  const lines = text.split(`
9857
9881
  `).map((l) => l.replace(/\s+$/, ""));
9858
9882
  if (lines[0] !== "---")
9859
- return USER_PHASES;
9883
+ return PHASES;
9860
9884
  const close = lines.indexOf("---", 1);
9861
9885
  if (close === -1)
9862
- return USER_PHASES;
9886
+ return PHASES;
9863
9887
  const front = lines.slice(1, close);
9864
9888
  const at = front.findIndex((l) => /^applies_to:/.test(l));
9865
9889
  if (at === -1)
9866
- return USER_PHASES;
9890
+ return PHASES;
9867
9891
  const phases = parseList((front[at] ?? "").slice("applies_to:".length).trim(), front.slice(at + 1));
9868
9892
  if (phases === null) {
9869
- process.stderr.write(`theway: warning: ${path2}: applies_to must list engineering and/or develop; applied to both
9893
+ process.stderr.write(`theway: warning: ${path2}: applies_to must list engineering, develop and/or document; skipped
9870
9894
  `);
9871
- return USER_PHASES;
9895
+ return [];
9872
9896
  }
9873
9897
  return phases;
9874
9898
  }
@@ -9882,7 +9906,16 @@ function checkPhase(phase) {
9882
9906
  return false;
9883
9907
  }
9884
9908
  function selectStandards(loaded, phase) {
9885
- return loaded.standards.filter((s) => enabled(loaded.config, s.key)).filter((s) => s.optIn ? OPT_IN_PHASES.includes(phase) : phase !== "document" && phasesOf(s.path).includes(phase)).map((s) => s.path);
9909
+ const phases = new Map;
9910
+ const of = (path2) => {
9911
+ let known = phases.get(path2);
9912
+ if (known === undefined) {
9913
+ known = phasesOf(path2);
9914
+ phases.set(path2, known);
9915
+ }
9916
+ return known;
9917
+ };
9918
+ return loaded.standards.filter((s) => enabled(loaded.config, s.key)).filter((s) => of(s.path).includes(phase) && (s.shadowedBy === undefined || !of(s.shadowedBy).includes(phase))).map((s) => s.path);
9886
9919
  }
9887
9920
  function cmdStandards(project, phase) {
9888
9921
  if (invalidSegments([["project", project]]))
@@ -10039,6 +10072,232 @@ function cmdNextId(project, seriesId, count) {
10039
10072
  return 0;
10040
10073
  }
10041
10074
 
10075
+ // src/core/workflow.ts
10076
+ import { readdirSync as readdirSync5 } from "node:fs";
10077
+ import { basename, join as join7, relative } from "node:path";
10078
+ var TYPES = ["implement", "review", "agent", "pr"];
10079
+ var positive = {
10080
+ test: (v) => typeof v === "number" && Number.isInteger(v) && v >= 1,
10081
+ text: "a positive integer"
10082
+ };
10083
+ var model2 = { test: (v) => v === "opus" || v === "sonnet" || v === "haiku", text: "opus, sonnet or haiku" };
10084
+ var lenses = { test: isLensList, text: "a non-empty list of names without duplicates" };
10085
+ var name = {
10086
+ test: (v) => typeof v === "string" && NAME.test(v),
10087
+ text: "a name (lowercase letters, digits and -)"
10088
+ };
10089
+ var nonEmpty = { test: (v) => typeof v === "string" && v.length > 0, text: "a non-empty string" };
10090
+ var bool2 = { test: (v) => typeof v === "boolean", text: "true or false" };
10091
+ var FIELDS = {
10092
+ implement: [["model", model2]],
10093
+ review: [
10094
+ ["rounds", positive],
10095
+ ["lenses", lenses],
10096
+ ["model", model2],
10097
+ ["fix_model", model2]
10098
+ ],
10099
+ agent: [
10100
+ ["name", name],
10101
+ ["prompt", nonEmpty],
10102
+ ["model", model2]
10103
+ ],
10104
+ pr: [
10105
+ ["ci_attempts", positive],
10106
+ ["model", model2],
10107
+ ["fix_model", model2]
10108
+ ]
10109
+ };
10110
+ var REQUIRED = ["name", "prompt"];
10111
+ var MODELS = ["model", "fix_model"];
10112
+ var projectDir = (d, kind) => join7(d.home, d.project, kind);
10113
+ var globalDir = (d, kind) => join7(d.home, kind);
10114
+ var searched = (d, kind) => d.own ? `${projectDir(d, kind)} or ${globalDir(d, kind)}` : globalDir(d, kind);
10115
+ function lensPath(d, lens) {
10116
+ const own = join7(projectDir(d, "lenses"), `${lens}.md`);
10117
+ if (d.own && isFile(own))
10118
+ return own;
10119
+ const global = join7(globalDir(d, "lenses"), `${lens}.md`);
10120
+ return isFile(global) ? global : null;
10121
+ }
10122
+ function validate(d, path2, defaults2) {
10123
+ const rel = relative(d.home, path2);
10124
+ const fail = (reason) => ({ error: `theway: ${rel}: ${reason}` });
10125
+ const loaded = load(d.home, rel);
10126
+ if ("error" in loaded)
10127
+ return loaded;
10128
+ const root = loaded.root;
10129
+ if (!(root instanceof Map))
10130
+ return fail("not a map");
10131
+ for (const key of root.keys()) {
10132
+ if (key !== "default" && key !== "agents" && key !== "steps")
10133
+ return fail(`unknown key ${String(key)}`);
10134
+ }
10135
+ if (root.has("default") && typeof root.get("default") !== "boolean")
10136
+ return fail("default must be true or false");
10137
+ if (root.has("agents") && typeof root.get("agents") !== "boolean")
10138
+ return fail("agents must be true or false");
10139
+ const topAgents = root.has("agents") ? root.get("agents") : true;
10140
+ const entries = root.get("steps");
10141
+ if (!Array.isArray(entries) || entries.length === 0)
10142
+ return fail("steps must be a non-empty list");
10143
+ const steps = [];
10144
+ for (const [i, entry] of entries.entries()) {
10145
+ const at = `steps[${i}]`;
10146
+ const type = entry instanceof Map && entry.size === 1 ? [...entry.keys()][0] : undefined;
10147
+ if (!TYPES.includes(type))
10148
+ return fail(`${at} must be one of ${TYPES.join(", ")}`);
10149
+ const t = type;
10150
+ const value = entry.get(t);
10151
+ if (value !== null && !(value instanceof Map))
10152
+ return fail(`${at}.${t} must be a map`);
10153
+ const given = value ?? new Map;
10154
+ const fields = new Map([["agents", bool2], ...FIELDS[t]]);
10155
+ for (const key of given.keys()) {
10156
+ if (typeof key !== "string" || !fields.has(key))
10157
+ return fail(`${at}.${t}.${String(key)} is not a field of ${t}`);
10158
+ }
10159
+ for (const [key, v] of given) {
10160
+ const rule = fields.get(key);
10161
+ if (!rule.test(v))
10162
+ return fail(`${at}.${t}.${String(key)} must be ${rule.text}`);
10163
+ }
10164
+ const agents = given.has("agents") ? given.get("agents") : topAgents;
10165
+ if (!agents) {
10166
+ for (const key of given.keys()) {
10167
+ if (MODELS.includes(key)) {
10168
+ return fail(`${at}.${t}.${String(key)} has no effect when the step runs inline (agents: false)`);
10169
+ }
10170
+ }
10171
+ }
10172
+ if (t === "agent") {
10173
+ for (const field of REQUIRED)
10174
+ if (!given.has(field))
10175
+ return fail(`${at}.agent.${field} is required`);
10176
+ }
10177
+ if (i === 0 && t !== "implement")
10178
+ return fail("steps[0] must be implement");
10179
+ if (i > 0 && t === "implement")
10180
+ return fail(`${at}: implement may appear only once`);
10181
+ if (t === "pr" && i !== entries.length - 1)
10182
+ return fail(`${at}: pr must be the last step`);
10183
+ const own = defaults2[t] ?? {};
10184
+ const step = { step: t, agents };
10185
+ for (const [field] of FIELDS[t]) {
10186
+ if (!agents && MODELS.includes(field))
10187
+ continue;
10188
+ const v = given.has(field) ? given.get(field) : own[field];
10189
+ step[field] = Array.isArray(v) ? [...v] : v;
10190
+ }
10191
+ if (t === "review") {
10192
+ const found = [];
10193
+ for (const lens of step.lenses) {
10194
+ const p = lensPath(d, lens);
10195
+ if (p === null) {
10196
+ return fail(`${at}.review lens '${lens}' has no file in ${searched(d, "lenses")}`);
10197
+ }
10198
+ found.push({ name: lens, path: p });
10199
+ }
10200
+ step.lenses = found;
10201
+ }
10202
+ steps.push(step);
10203
+ }
10204
+ return { workflow: { name: basename(path2, ".yaml"), file: path2, steps }, isDefault: root.get("default") === true };
10205
+ }
10206
+ function scan(d, dir) {
10207
+ let names;
10208
+ try {
10209
+ names = readdirSync5(dir);
10210
+ } catch {
10211
+ return [];
10212
+ }
10213
+ const out = [];
10214
+ for (const n of names.sort()) {
10215
+ if (!n.endsWith(".yaml") || n.endsWith(".default.yaml") || !isFile(join7(dir, n)))
10216
+ continue;
10217
+ if (!NAME.test(n.slice(0, -".yaml".length))) {
10218
+ process.stderr.write(`theway: warning: ${relative(d.home, join7(dir, n))}: not a valid workflow name; ignored
10219
+ `);
10220
+ continue;
10221
+ }
10222
+ out.push(n);
10223
+ }
10224
+ return out;
10225
+ }
10226
+ var joinAnd = (items) => items.length === 1 ? items[0] : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
10227
+ function defaultOf(d, paths, defaults2) {
10228
+ const marked = [];
10229
+ for (const path2 of paths) {
10230
+ const result = validate(d, path2, defaults2);
10231
+ if ("error" in result)
10232
+ return result;
10233
+ if (result.isDefault)
10234
+ marked.push(result.workflow);
10235
+ }
10236
+ if (marked.length > 1) {
10237
+ return { error: `theway: ${joinAnd(marked.map((w) => relative(d.home, w.file)))} both set default: true` };
10238
+ }
10239
+ return marked.length === 1 ? { workflow: marked[0] } : null;
10240
+ }
10241
+ function byName(d, wanted, defaults2) {
10242
+ const own = join7(projectDir(d, "workflows"), `${wanted}.yaml`);
10243
+ const global = join7(globalDir(d, "workflows"), `${wanted}.yaml`);
10244
+ const path2 = d.own && isFile(own) ? own : isFile(global) ? global : null;
10245
+ if (path2 === null) {
10246
+ return { error: `theway: no workflow '${wanted}' in ${searched(d, "workflows")}` };
10247
+ }
10248
+ return validate(d, path2, defaults2);
10249
+ }
10250
+ function byDefault(d, defaults2) {
10251
+ const ownNames = d.own ? scan(d, projectDir(d, "workflows")) : [];
10252
+ const own = defaultOf(d, ownNames.map((n) => join7(projectDir(d, "workflows"), n)), defaults2);
10253
+ if (own !== null)
10254
+ return own;
10255
+ const globalNames = scan(d, globalDir(d, "workflows")).filter((n) => !ownNames.includes(n));
10256
+ const global = defaultOf(d, globalNames.map((n) => join7(globalDir(d, "workflows"), n)), defaults2);
10257
+ if (global !== null)
10258
+ return global;
10259
+ return byName(d, "develop", defaults2);
10260
+ }
10261
+ function cmdWorkflow(project, wanted) {
10262
+ if (invalidSegments([["project", project]]))
10263
+ return 1;
10264
+ if (wanted !== undefined && !NAME.test(wanted)) {
10265
+ const shown = wanted.replaceAll(`
10266
+ `, "\\n").replaceAll("\r", "\\r");
10267
+ process.stderr.write(`theway: invalid workflow name '${shown}'
10268
+ `);
10269
+ return 1;
10270
+ }
10271
+ const home = thewayHome();
10272
+ const loaded = loadConfig(home, project);
10273
+ if (loaded === null)
10274
+ return 1;
10275
+ const defaults2 = loaded.config.workflow.defaults;
10276
+ const d = { home, project, own: !isShared(project) };
10277
+ const result = wanted === undefined ? byDefault(d, defaults2) : byName(d, wanted, defaults2);
10278
+ if ("error" in result) {
10279
+ process.stderr.write(`${result.error}
10280
+ `);
10281
+ return 1;
10282
+ }
10283
+ const conventions = [];
10284
+ for (const file2 of CONVENTIONS) {
10285
+ const global = join7(home, "standards", file2);
10286
+ if (!isFile(global)) {
10287
+ process.stderr.write(`theway: ${global} not found; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
10288
+ `);
10289
+ return 1;
10290
+ }
10291
+ const own = join7(home, project, "standards", file2);
10292
+ conventions.push(d.own && isFile(own) ? own : global);
10293
+ }
10294
+ const { name: name2, file, steps } = result.workflow;
10295
+ const doc = { name: name2, file, commits: conventions[0], git_host: conventions[1], steps };
10296
+ process.stdout.write(`${JSON.stringify(doc, null, 2)}
10297
+ `);
10298
+ return 0;
10299
+ }
10300
+
10042
10301
  // src/install.ts
10043
10302
  import {
10044
10303
  accessSync,
@@ -10059,7 +10318,7 @@ import {
10059
10318
  writeFileSync as writeFileSync2
10060
10319
  } from "node:fs";
10061
10320
  import { homedir as homedir2 } from "node:os";
10062
- import { delimiter, dirname, isAbsolute, join as join7, resolve as resolve3, sep } from "node:path";
10321
+ import { delimiter, dirname, isAbsolute, join as join8, resolve as resolve3, sep } from "node:path";
10063
10322
  import { fileURLToPath } from "node:url";
10064
10323
 
10065
10324
  // node_modules/@clack/core/dist/index.mjs
@@ -11470,16 +11729,16 @@ ${i2}
11470
11729
  // src/install.ts
11471
11730
  var self = fileURLToPath(import.meta.url);
11472
11731
  var pkgRoot = dirname(dirname(self));
11473
- var plugin = join7(pkgRoot, "plugin");
11474
- var PLUGIN_DIRS = [".claude-plugin", "commands"];
11732
+ var plugin = join8(pkgRoot, "plugin");
11733
+ var PLUGIN_DIRS = [".claude-plugin", "commands", "workflows"];
11475
11734
  var BINARY_MARKER = "theway-cli-binary:pixelfactoryio/theway";
11476
11735
  function claudeHome() {
11477
11736
  const dir = (process.env.CLAUDE_CONFIG_DIR ?? "").trim();
11478
- return dir !== "" ? dir : join7(homedir2(), ".claude");
11737
+ return dir !== "" ? dir : join8(homedir2(), ".claude");
11479
11738
  }
11480
11739
  function installDir() {
11481
11740
  const dir = process.env.THEWAY_INSTALL_DIR ?? "";
11482
- return dir !== "" ? resolve3(dir) : join7(homedir2(), ".local", "bin");
11741
+ return dir !== "" ? resolve3(dir) : join8(homedir2(), ".local", "bin");
11483
11742
  }
11484
11743
  function shownHome(home) {
11485
11744
  return resolve3(home) === resolve3(defaultHome()) ? "~/.theway" : resolve3(home);
@@ -11579,15 +11838,15 @@ function invalidSettings(path2) {
11579
11838
  return fail(`theway: ${path2} is not valid settings JSON; nothing was changed`);
11580
11839
  }
11581
11840
  function copyPlugin(home) {
11582
- const tmp = join7(home, `.theway-install-${process.pid}`);
11583
- const old = join7(home, `.theway-old-${process.pid}`);
11584
- const dest = join7(home, "skills", "theway");
11841
+ const tmp = join8(home, `.theway-install-${process.pid}`);
11842
+ const old = join8(home, `.theway-old-${process.pid}`);
11843
+ const dest = join8(home, "skills", "theway");
11585
11844
  rmSync2(tmp, { recursive: true, force: true });
11586
11845
  try {
11587
11846
  for (const dir of PLUGIN_DIRS) {
11588
- cpSync(join7(plugin, dir), join7(tmp, dir), { recursive: true });
11847
+ cpSync(join8(plugin, dir), join8(tmp, dir), { recursive: true });
11589
11848
  }
11590
- mkdirSync3(join7(home, "skills"), { recursive: true });
11849
+ mkdirSync3(join8(home, "skills"), { recursive: true });
11591
11850
  if (existsSync3(dest))
11592
11851
  renameSync3(dest, old);
11593
11852
  renameSync3(tmp, dest);
@@ -11611,22 +11870,22 @@ function legacyText(path2, match) {
11611
11870
  }
11612
11871
  function removeLegacyBin(home) {
11613
11872
  for (const h2 of new Set([defaultHome(), resolve3(home)])) {
11614
- const bin = join7(h2, "bin");
11615
- if (legacyText(join7(bin, "theway"), (t2) => t2.startsWith(`#!/bin/sh
11873
+ const bin = join8(h2, "bin");
11874
+ if (legacyText(join8(bin, "theway"), (t2) => t2.startsWith(`#!/bin/sh
11616
11875
  exec node `) && t2.endsWith(`theway.js' "$@"
11617
11876
  `))) {
11618
- rmSync2(join7(bin, "theway"), { force: true });
11877
+ rmSync2(join8(bin, "theway"), { force: true });
11619
11878
  }
11620
- if (legacyText(join7(bin, "theway.js"), (t2) => t2.startsWith(`#!/usr/bin/env node
11879
+ if (legacyText(join8(bin, "theway.js"), (t2) => t2.startsWith(`#!/usr/bin/env node
11621
11880
  `))) {
11622
- rmSync2(join7(bin, "theway.js"), { force: true });
11881
+ rmSync2(join8(bin, "theway.js"), { force: true });
11623
11882
  }
11624
11883
  removeIfEmpty2(bin);
11625
11884
  }
11626
11885
  }
11627
11886
  function writeBinary(dir) {
11628
- const dest = join7(dir, "theway");
11629
- const tmp = join7(dir, `.theway-${process.pid}`);
11887
+ const dest = join8(dir, "theway");
11888
+ const tmp = join8(dir, `.theway-${process.pid}`);
11630
11889
  mkdirSync3(dir, { recursive: true });
11631
11890
  try {
11632
11891
  copyFileSync2(self, tmp);
@@ -11690,7 +11949,7 @@ function copiesOnPath() {
11690
11949
  for (const dir of (process.env.PATH ?? "").split(delimiter)) {
11691
11950
  if (dir === "")
11692
11951
  continue;
11693
- const candidate = join7(dir, "theway");
11952
+ const candidate = join8(dir, "theway");
11694
11953
  if (!isFile(candidate))
11695
11954
  continue;
11696
11955
  try {
@@ -11786,7 +12045,7 @@ async function askStandards() {
11786
12045
  return isCancel(answer) ? null : answer;
11787
12046
  }
11788
12047
  async function install(opts) {
11789
- if (!existsSync3(join7(plugin, ".claude-plugin"))) {
12048
+ if (!existsSync3(join8(plugin, ".claude-plugin"))) {
11790
12049
  return fail("theway: run `npx --yes @pixelfactoryio/theway@latest install` to install or update theway");
11791
12050
  }
11792
12051
  let enabled2 = [];
@@ -11809,7 +12068,7 @@ async function install(opts) {
11809
12068
  tHome = home;
11810
12069
  } else {
11811
12070
  const found = resolveHome();
11812
- const neverInstalled = found.source === "default" && !existsSync3(join7(defaultHome(), "config.yaml"));
12071
+ const neverInstalled = found.source === "default" && !existsSync3(join8(defaultHome(), "config.yaml"));
11813
12072
  if (neverInstalled && interactive()) {
11814
12073
  const home = await askHome();
11815
12074
  if (home === null)
@@ -11822,7 +12081,7 @@ async function install(opts) {
11822
12081
  const previous = recordedHome();
11823
12082
  const custom = tHome !== resolve3(defaultHome());
11824
12083
  const dir = installDir();
11825
- const settingsPath = join7(cHome, "settings.json");
12084
+ const settingsPath = join8(cHome, "settings.json");
11826
12085
  const unsafe = unsafeHomeReason(tHome, custom);
11827
12086
  if (unsafe !== "") {
11828
12087
  return fail(`theway: refusing data home ${resolve3(tHome)}: ${unsafe}; set THEWAY_HOME or --home to a dedicated folder`);
@@ -11833,11 +12092,11 @@ async function install(opts) {
11833
12092
  const settings2 = readSettings(resolved.target);
11834
12093
  if (settings2 === null)
11835
12094
  return invalidSettings(settingsPath);
11836
- const target = join7(dir, "theway");
12095
+ const target = join8(dir, "theway");
11837
12096
  if (occupied(target) && !isThewayBinary(target)) {
11838
12097
  return fail(`theway: ${target} exists and is not a theway binary; nothing was changed. Remove it, or set THEWAY_INSTALL_DIR to another folder`);
11839
12098
  }
11840
- const config = join7(resolve3(tHome), "config.yaml");
12099
+ const config = join8(resolve3(tHome), "config.yaml");
11841
12100
  const firstInstall = !existsSync3(config);
11842
12101
  if (opts.standards !== undefined && !firstInstall) {
11843
12102
  return fail(`theway: --standards applies only to a first install; ${config} exists, so set standards.<key>.enabled there instead; nothing was changed`);
@@ -11857,7 +12116,7 @@ async function install(opts) {
11857
12116
  } catch (e) {
11858
12117
  return fail(`theway: ${e.message}`);
11859
12118
  }
11860
- const status = init(join7(plugin, "home"), tHome, enabled2);
12119
+ const status = init(join8(plugin, "home"), tHome, enabled2);
11861
12120
  if (status !== 0)
11862
12121
  return status;
11863
12122
  if (firstInstall && opts.standards === undefined && !asked) {
@@ -11886,7 +12145,7 @@ async function install(opts) {
11886
12145
  writeSettings(resolved.target, settings2);
11887
12146
  }
11888
12147
  checkPath(dir, binary);
11889
- const version = JSON.parse(readFileSync8(join7(pkgRoot, "package.json"), "utf-8")).version;
12148
+ const version = JSON.parse(readFileSync8(join8(pkgRoot, "package.json"), "utf-8")).version;
11890
12149
  process.stdout.write(`Installed theway ${version} to ${dest} (theway@skills-dir), ${binary} and ${tHome}. Start a new Claude Code session or run /reload-plugins.
11891
12150
  `);
11892
12151
  return 0;
@@ -11895,7 +12154,7 @@ function uninstall() {
11895
12154
  const cHome = claudeHome();
11896
12155
  const tHome = resolveHome().home;
11897
12156
  const homes = [...new Set([tHome, recordedHome(), defaultHome()])];
11898
- const settingsPath = join7(cHome, "settings.json");
12157
+ const settingsPath = join8(cHome, "settings.json");
11899
12158
  let settingsFile = settingsPath;
11900
12159
  if (occupied(settingsPath)) {
11901
12160
  const resolved = settingsTarget(settingsPath);
@@ -11903,8 +12162,8 @@ function uninstall() {
11903
12162
  return unwritableSettings(settingsPath, resolved.error);
11904
12163
  settingsFile = resolved.target;
11905
12164
  }
11906
- rmSync2(join7(cHome, "skills", "theway"), { recursive: true, force: true });
11907
- const binary = join7(installDir(), "theway");
12165
+ rmSync2(join8(cHome, "skills", "theway"), { recursive: true, force: true });
12166
+ const binary = join8(installDir(), "theway");
11908
12167
  const removed = isThewayBinary(binary);
11909
12168
  if (removed)
11910
12169
  rmSync2(binary, { force: true });
@@ -11931,12 +12190,12 @@ function uninstall() {
11931
12190
  }
11932
12191
 
11933
12192
  // src/program.ts
11934
- var nonEmpty = (value) => {
12193
+ var nonEmpty2 = (value) => {
11935
12194
  if (value === "")
11936
12195
  throw new InvalidArgumentError("must not be empty");
11937
12196
  return value;
11938
12197
  };
11939
- var positive = (value) => {
12198
+ var positive2 = (value) => {
11940
12199
  if (!/^[1-9][0-9]*$/.test(value))
11941
12200
  throw new InvalidArgumentError("must be a positive integer");
11942
12201
  return Number(value);
@@ -11946,16 +12205,17 @@ var exit = (code) => {
11946
12205
  };
11947
12206
  function buildProgram() {
11948
12207
  const program2 = new Command("theway");
11949
- program2.command("install").option("--home <path>", "", nonEmpty).option("--standards <keys>").action(async (o2) => exit(await install({ home: o2.home, standards: o2.standards })));
12208
+ program2.command("install").option("--home <path>", "", nonEmpty2).option("--standards <keys>").action(async (o2) => exit(await install({ home: o2.home, standards: o2.standards })));
11950
12209
  program2.command("uninstall").action(() => exit(uninstall()));
11951
- program2.command("list").argument("<project>", "", nonEmpty).action((project) => exit(cmdList(project)));
11952
- program2.command("archive").argument("<project>", "", nonEmpty).argument("<change-id>", "", nonEmpty).option("--force").action((project, change, o2) => exit(cmdArchive(project, change, o2.force === true)));
12210
+ program2.command("list").argument("<project>", "", nonEmpty2).action((project) => exit(cmdList(project)));
12211
+ program2.command("archive").argument("<project>", "", nonEmpty2).argument("<change-id>", "", nonEmpty2).option("--force").action((project, change, o2) => exit(cmdArchive(project, change, o2.force === true)));
11953
12212
  program2.command("path").argument("[project]").argument("[change-id]").option("--verbose").action((project, change, o2) => exit(cmdPath(project, change, o2.verbose === true)));
11954
12213
  program2.command("config").argument("<project>").action((project) => exit(cmdConfig(project)));
11955
12214
  program2.command("standards").argument("<project>").argument("<phase>").action((project, phase) => exit(cmdStandards(project, phase)));
11956
12215
  program2.command("context").argument("<project>").argument("<phase>").argument("[change-id]").action((project, phase, change) => exit(cmdContext(project, phase, change)));
12216
+ program2.command("workflow").argument("<project>").argument("[name]").action((project, name2) => exit(cmdWorkflow(project, name2)));
11957
12217
  program2.command("authority").action(() => exit(cmdAuthority()));
11958
- program2.command("next-id").argument("<project>").argument("<series-id>").option("--count <n>", "", positive, 1).action((project, series, o2) => exit(cmdNextId(project, series, o2.count)));
12218
+ program2.command("next-id").argument("<project>").argument("<series-id>").option("--count <n>", "", positive2, 1).action((project, series, o2) => exit(cmdNextId(project, series, o2.count)));
11959
12219
  program2.command("validate-id").argument("<id>").option("--series").action((id, o2) => exit(cmdValidateId(id, o2.series === true)));
11960
12220
  return program2;
11961
12221
  }