@pixelfactoryio/theway 0.12.0 → 0.14.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
@@ -9128,66 +9128,71 @@ function isFile(path2) {
9128
9128
  // src/core/list.ts
9129
9129
  import { readdirSync, readFileSync as readFileSync2 } from "node:fs";
9130
9130
 
9131
- // src/core/path.ts
9132
- import { join as join2, resolve as resolve2 } from "node:path";
9133
- var CHANGE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
9134
- var PROJECT = /^[A-Za-z0-9_][A-Za-z0-9._-]*$/;
9135
- function changeIdReason(v) {
9136
- if (v === "")
9137
- return "must not be empty";
9138
- if (v.length > 200)
9139
- return "must be at most 200 characters";
9140
- if (!CHANGE_ID.test(v))
9141
- return "must be lowercase letters and digits in words separated by single hyphens";
9142
- return "";
9143
- }
9131
+ // src/core/project.ts
9132
+ import { spawnSync } from "node:child_process";
9133
+ import { realpathSync } from "node:fs";
9134
+ import { basename, dirname, join as join2, resolve as resolve2 } from "node:path";
9135
+ var KEY = /^[A-Za-z0-9-]{1,200}$/;
9144
9136
  function projectReason(v) {
9145
- if (v === "")
9146
- return "must not be empty";
9147
- if (v.length > 200)
9148
- return "must be at most 200 characters";
9149
- if (!PROJECT.test(v))
9150
- return 'must be letters, digits, ".", "_" or "-", not starting with "." or "-"';
9151
- return "";
9137
+ return KEY.test(v) ? "" : 'must be letters, digits and "-", at most 200 characters';
9152
9138
  }
9153
- function invalidSegments(segments) {
9154
- for (const [label, value] of segments) {
9155
- if (value === undefined)
9156
- continue;
9157
- const reason = label === "project" ? projectReason(value) : changeIdReason(value);
9158
- if (reason !== "") {
9159
- const shown = value.replaceAll(`
9160
- `, "\\n").replaceAll("\r", "\\r");
9161
- process.stderr.write(`theway: invalid ${label} '${shown}': ${reason}
9162
- `);
9163
- return true;
9139
+ function revParse(flag) {
9140
+ const res = spawnSync("git", ["rev-parse", flag], {
9141
+ cwd: process.cwd(),
9142
+ encoding: "utf-8",
9143
+ stdio: ["ignore", "pipe", "pipe"]
9144
+ });
9145
+ if (res.error !== undefined || res.status !== 0)
9146
+ return null;
9147
+ return res.stdout.trim();
9148
+ }
9149
+ function projectRoot() {
9150
+ const cwd = process.cwd();
9151
+ let root = cwd;
9152
+ const common = revParse("--git-common-dir");
9153
+ if (common !== null) {
9154
+ const dir = resolve2(cwd, common);
9155
+ if (basename(dir) === ".git")
9156
+ root = dirname(dir);
9157
+ else {
9158
+ const top = revParse("--show-toplevel");
9159
+ root = top !== null && top !== "" ? resolve2(cwd, top) : cwd;
9164
9160
  }
9165
9161
  }
9166
- return false;
9162
+ try {
9163
+ return realpathSync(root);
9164
+ } catch {
9165
+ return root;
9166
+ }
9167
9167
  }
9168
- function cmdPath(project, changeId, verbose) {
9169
- if (invalidSegments([
9170
- ["project", project],
9171
- ["change id", changeId]
9172
- ]))
9173
- return 1;
9174
- const { home, source } = resolveHome();
9175
- if (verbose)
9176
- process.stderr.write(`theway: home ${home} (from ${source})
9168
+ var keyOf = (root) => root.replace(/[^A-Za-z0-9]/g, "-");
9169
+ var projectDir = (home, key) => join2(home, "projects", key);
9170
+ function resolveKey(override) {
9171
+ if (override !== undefined) {
9172
+ const reason = projectReason(override);
9173
+ if (reason === "")
9174
+ return override;
9175
+ const shown = override.replaceAll(`
9176
+ `, "\\n").replaceAll("\r", "\\r");
9177
+ process.stderr.write(`theway: invalid project '${shown}': ${reason}
9177
9178
  `);
9178
- if (source === "env") {
9179
- const pointer = readPointer();
9180
- if (pointer !== "" && resolve2(pointer) !== home) {
9181
- process.stderr.write(`theway: warning: THEWAY_HOME is ${home} (from env) but ${pointerPath()} holds ${resolve2(pointer)} (from pointer); using ${home}
9179
+ return null;
9180
+ }
9181
+ const root = projectRoot();
9182
+ const key = keyOf(root);
9183
+ if (key.length > 200) {
9184
+ process.stderr.write(`theway: project key for ${root} is longer than 200 characters; pass --project <key>
9182
9185
  `);
9183
- }
9186
+ return null;
9184
9187
  }
9185
- let out = home;
9186
- if (project !== undefined)
9187
- out = join2(home, project);
9188
- if (project !== undefined && changeId !== undefined)
9189
- out = join2(home, project, "changes", changeId);
9190
- process.stdout.write(`${out}
9188
+ return key;
9189
+ }
9190
+ function cmdProject(override) {
9191
+ const key = resolveKey(override);
9192
+ if (key === null)
9193
+ return 1;
9194
+ process.stdout.write(`key: ${key}
9195
+ dir: ${projectDir(thewayHome(), key)}
9191
9196
  `);
9192
9197
  return 0;
9193
9198
  }
@@ -9208,11 +9213,11 @@ function subdirs(dir) {
9208
9213
  function filesEndingWith(dir, suffix) {
9209
9214
  return visibleNames(dir).filter((n) => n.endsWith(suffix) && isFile(`${dir}/${n}`));
9210
9215
  }
9211
- function activeIds(home, project) {
9212
- return subdirs(`${home}/${project}/changes`).filter((n) => n !== "archive");
9216
+ function activeIds(dir) {
9217
+ return subdirs(`${dir}/changes`).filter((n) => n !== "archive");
9213
9218
  }
9214
- function archiveDirs(home, project) {
9215
- return subdirs(`${home}/${project}/changes/archive`);
9219
+ function archiveDirs(dir) {
9220
+ return subdirs(`${dir}/changes/archive`);
9216
9221
  }
9217
9222
  function taskCounts(dir) {
9218
9223
  let checked = 0;
@@ -9230,21 +9235,22 @@ function taskCounts(dir) {
9230
9235
  }
9231
9236
  return [checked, total];
9232
9237
  }
9233
- function cmdList(project) {
9234
- if (invalidSegments([["project", project]]))
9238
+ function cmdList(override) {
9239
+ const key = resolveKey(override);
9240
+ if (key === null)
9235
9241
  return 1;
9236
- const home = thewayHome();
9237
- const base = `${home}/${project}/changes`;
9238
- let text = `theway changes — ${project}
9242
+ const dir = projectDir(thewayHome(), key);
9243
+ const base = `${dir}/changes`;
9244
+ let text = `theway changes — ${key}
9239
9245
 
9240
9246
  Active changes
9241
9247
 
9242
9248
  `;
9243
- const active = activeIds(home, project);
9249
+ const active = activeIds(dir);
9244
9250
  for (const name of active) {
9245
- const dir = `${base}/${name}`;
9246
- const files = filesEndingWith(dir, ".md").length;
9247
- const [checked, total] = taskCounts(dir);
9251
+ const change = `${base}/${name}`;
9252
+ const files = filesEndingWith(change, ".md").length;
9253
+ const [checked, total] = taskCounts(change);
9248
9254
  text += ` ${name.padEnd(20)} ${files} files ${checked}/${total} tasks done
9249
9255
  `;
9250
9256
  }
@@ -9253,7 +9259,7 @@ Active changes
9253
9259
  `;
9254
9260
  text += `
9255
9261
  `;
9256
- const archived = archiveDirs(home, project);
9262
+ const archived = archiveDirs(dir);
9257
9263
  text += `Archived changes (${archived.length})
9258
9264
 
9259
9265
  `;
@@ -9272,6 +9278,55 @@ Summary: ${active.length} active change(s), ${archived.length} archived.
9272
9278
  return 0;
9273
9279
  }
9274
9280
 
9281
+ // src/core/path.ts
9282
+ import { join as join3, resolve as resolve3 } from "node:path";
9283
+ var CHANGE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
9284
+ function changeIdReason(v) {
9285
+ if (v === "")
9286
+ return "must not be empty";
9287
+ if (v.length > 200)
9288
+ return "must be at most 200 characters";
9289
+ if (!CHANGE_ID.test(v))
9290
+ return "must be lowercase letters and digits in words separated by single hyphens";
9291
+ return "";
9292
+ }
9293
+ function invalidChangeId(changeId) {
9294
+ if (changeId === undefined)
9295
+ return false;
9296
+ const reason = changeIdReason(changeId);
9297
+ if (reason === "")
9298
+ return false;
9299
+ const shown = changeId.replaceAll(`
9300
+ `, "\\n").replaceAll("\r", "\\r");
9301
+ process.stderr.write(`theway: invalid change id '${shown}': ${reason}
9302
+ `);
9303
+ return true;
9304
+ }
9305
+ function cmdPath(changeId, override, verbose) {
9306
+ if (changeId === undefined && override !== undefined && resolveKey(override) === null)
9307
+ return 1;
9308
+ const key = changeId === undefined ? null : resolveKey(override);
9309
+ if (changeId !== undefined && key === null)
9310
+ return 1;
9311
+ if (invalidChangeId(changeId))
9312
+ return 1;
9313
+ const { home, source } = resolveHome();
9314
+ if (verbose)
9315
+ process.stderr.write(`theway: home ${home} (from ${source})
9316
+ `);
9317
+ if (source === "env") {
9318
+ const pointer = readPointer();
9319
+ if (pointer !== "" && resolve3(pointer) !== home) {
9320
+ process.stderr.write(`theway: warning: THEWAY_HOME is ${home} (from env) but ${pointerPath()} holds ${resolve3(pointer)} (from pointer); using ${home}
9321
+ `);
9322
+ }
9323
+ }
9324
+ const out = changeId !== undefined && key !== null ? join3(projectDir(home, key), "changes", changeId) : home;
9325
+ process.stdout.write(`${out}
9326
+ `);
9327
+ return 0;
9328
+ }
9329
+
9275
9330
  // src/core/archive.ts
9276
9331
  function localDate() {
9277
9332
  const d = new Date;
@@ -9282,15 +9337,15 @@ function uncheckedLines(path2) {
9282
9337
  return readFileSync3(path2, "utf-8").split(`
9283
9338
  `).flatMap((line, i) => UNCHECKED.test(line) ? [`${i + 1}:${line}`] : []);
9284
9339
  }
9285
- function cmdArchive(project, changeId, force) {
9286
- if (invalidSegments([
9287
- ["project", project],
9288
- ["change id", changeId]
9289
- ]))
9340
+ function cmdArchive(changeId, override, force) {
9341
+ const key = resolveKey(override);
9342
+ if (key === null)
9290
9343
  return 1;
9291
- const home = thewayHome();
9292
- const src = `${home}/${project}/changes/${changeId}`;
9293
- const dst = `${home}/${project}/changes/archive/${localDate()}-${changeId}`;
9344
+ if (invalidChangeId(changeId))
9345
+ return 1;
9346
+ const dir = projectDir(thewayHome(), key);
9347
+ const src = `${dir}/changes/${changeId}`;
9348
+ const dst = `${dir}/changes/archive/${localDate()}-${changeId}`;
9294
9349
  if (!isDir(src)) {
9295
9350
  process.stderr.write(`Error: ${src} not found
9296
9351
  `);
@@ -9320,7 +9375,7 @@ ${list}`);
9320
9375
  }
9321
9376
  }
9322
9377
  try {
9323
- mkdirSync(`${home}/${project}/changes/archive`, { recursive: true });
9378
+ mkdirSync(`${dir}/changes/archive`, { recursive: true });
9324
9379
  renameSync(src, dst);
9325
9380
  } catch (e) {
9326
9381
  process.stderr.write(`mv: ${e.message}
@@ -9334,7 +9389,7 @@ ${list}`);
9334
9389
 
9335
9390
  // src/core/authority.ts
9336
9391
  import { readFileSync as readFileSync4 } from "node:fs";
9337
- import { join as join3 } from "node:path";
9392
+ import { join as join4 } from "node:path";
9338
9393
  function authoritySection(path2) {
9339
9394
  let text;
9340
9395
  try {
@@ -9356,10 +9411,10 @@ function authoritySection(path2) {
9356
9411
  `;
9357
9412
  }
9358
9413
  function cmdAuthority() {
9359
- const dir = join3(thewayHome(), "standards");
9360
- const section = authoritySection(join3(dir, "interaction.md")) ?? authoritySection(join3(dir, "interaction.default.md"));
9414
+ const dir = join4(thewayHome(), "standards");
9415
+ const section = authoritySection(join4(dir, "interaction.md")) ?? authoritySection(join4(dir, "interaction.default.md"));
9361
9416
  if (section === null) {
9362
- process.stderr.write(`theway: no ## Authority section in ${join3(dir, "interaction.md")} or interaction.default.md; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
9417
+ process.stderr.write(`theway: no ## Authority section in ${join4(dir, "interaction.md")} or interaction.default.md; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
9363
9418
  `);
9364
9419
  return 1;
9365
9420
  }
@@ -9369,7 +9424,7 @@ function cmdAuthority() {
9369
9424
 
9370
9425
  // src/core/config.ts
9371
9426
  import { readdirSync as readdirSync3, readFileSync as readFileSync6 } from "node:fs";
9372
- import { join as join4 } from "node:path";
9427
+ import { join as join5 } from "node:path";
9373
9428
 
9374
9429
  // node_modules/yaml/dist/index.js
9375
9430
  var composer = require_composer();
@@ -9430,7 +9485,12 @@ import {
9430
9485
  statSync as statSync2,
9431
9486
  writeFileSync
9432
9487
  } from "node:fs";
9433
- var SHIPPED_DIRS = ["standards", "templates"];
9488
+ var SHIPPED_DIRS = [
9489
+ { dir: "standards", ext: ".md", shared: "standards" },
9490
+ { dir: "templates", ext: ".md" },
9491
+ { dir: "workflows", ext: ".yaml", shared: "workflows" },
9492
+ { dir: "lenses", ext: ".md", shared: "lenses" }
9493
+ ];
9434
9494
  var MANIFEST = ".shipped.json";
9435
9495
  var sha256 = (data) => createHash("sha256").update(data).digest("hex");
9436
9496
  function readManifest(home) {
@@ -9523,16 +9583,18 @@ function migrateDataStandards(src, home) {
9523
9583
  function copyShipped(src, home) {
9524
9584
  const previous = readManifest(home);
9525
9585
  const manifest = {};
9526
- for (const dir of SHIPPED_DIRS) {
9527
- const isStandards = dir === "standards";
9586
+ for (const { dir, ext, shared } of SHIPPED_DIRS) {
9587
+ const isShared = shared !== undefined;
9588
+ const stemOf = (name) => name.slice(0, -ext.length);
9589
+ const defaultExt = `.default${ext}`;
9528
9590
  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();
9591
+ const names = readdirSync2(`${src}/${dir}`, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(ext)).map((e) => e.name).sort();
9530
9592
  for (const name of names) {
9531
9593
  const rel = `${dir}/${name}`;
9532
9594
  const dst = `${home}/${rel}`;
9533
9595
  const shipped = readFileSync5(`${src}/${rel}`);
9534
9596
  const old = previous?.[rel];
9535
- const sibling = `${dir}/${baseOf(name)}.default.md`;
9597
+ const sibling = `${dir}/${stemOf(name)}${defaultExt}`;
9536
9598
  let removeSibling = true;
9537
9599
  let record = true;
9538
9600
  if (!existsSync2(dst)) {
@@ -9542,12 +9604,12 @@ function copyShipped(src, home) {
9542
9604
  if (!current.equals(shipped)) {
9543
9605
  if (typeof old === "string" && sha256(current) === old) {
9544
9606
  writeAtomic(dst, shipped);
9545
- } else if (typeof old === "string" || isStandards && previous === undefined) {
9607
+ } else if (typeof old === "string" || isShared && previous === undefined) {
9546
9608
  removeSibling = false;
9547
9609
  writeAtomic(`${home}/${sibling}`, shipped);
9548
9610
  process.stdout.write(`Kept your edited ${rel} (shipped version: ${sibling})
9549
9611
  `);
9550
- } else if (isStandards) {
9612
+ } else if (isShared) {
9551
9613
  removeSibling = false;
9552
9614
  record = false;
9553
9615
  writeAtomic(`${home}/${sibling}`, shipped);
@@ -9568,9 +9630,9 @@ function copyShipped(src, home) {
9568
9630
  if (record)
9569
9631
  manifest[rel] = sha256(shipped);
9570
9632
  }
9571
- if (isStandards) {
9633
+ if (isShared) {
9572
9634
  for (const [rel, hash] of Object.entries(previous ?? {})) {
9573
- if (!rel.startsWith("standards/") || names.includes(rel.slice("standards/".length)))
9635
+ if (!rel.startsWith(`${dir}/`) || names.includes(rel.slice(dir.length + 1)))
9574
9636
  continue;
9575
9637
  const path2 = `${home}/${rel}`;
9576
9638
  if (!existsSync2(path2))
@@ -9580,15 +9642,15 @@ function copyShipped(src, home) {
9580
9642
  process.stdout.write(`Removed ${rel}: theway no longer ships it
9581
9643
  `);
9582
9644
  } else {
9583
- process.stdout.write(`Kept your edited ${rel}: theway no longer ships it, so it is now one of your standards
9645
+ process.stdout.write(`Kept your edited ${rel}: theway no longer ships it, so it is now one of your ${shared}
9584
9646
  `);
9585
9647
  }
9586
9648
  }
9587
9649
  for (const entry of readdirSync2(`${home}/${dir}`, { withFileTypes: true })) {
9588
9650
  const file = entry.name;
9589
- if (!entry.isFile() || !file.endsWith(".default.md"))
9651
+ if (!entry.isFile() || !file.endsWith(defaultExt))
9590
9652
  continue;
9591
- if (!names.includes(`${file.slice(0, -".default.md".length)}.md`))
9653
+ if (!names.includes(`${file.slice(0, -defaultExt.length)}${ext}`))
9592
9654
  rmSync(`${home}/${dir}/${file}`, { force: true });
9593
9655
  }
9594
9656
  }
@@ -9637,10 +9699,12 @@ var bool = (d) => ({ rule: "boolean", default: d });
9637
9699
  var model = (d) => ({ rule: "model", default: d });
9638
9700
  var OPT_IN = ["core-principles.md", "sre.md", "web-development.md", "quality.md"];
9639
9701
  var CORE = ["interaction.md", "develop.md", "tamm-framework.md", "spec-review.md", "spec-investigation.md"];
9640
- var SHARED = new Set(["data", "templates", "standards"]);
9641
- var keyOf = (name) => name.slice(0, -".md".length).replaceAll("-", "_");
9642
- var OPT_IN_KEYS = OPT_IN.map(keyOf);
9643
- var CORE_KEYS = new Set(CORE.map(keyOf));
9702
+ var CONVENTIONS = ["commits.md", "git-host.md"];
9703
+ var NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
9704
+ var isLensList = (v) => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === "string" && NAME.test(n)) && new Set(v).size === v.length;
9705
+ var keyOf2 = (name) => name.slice(0, -".md".length).replaceAll("-", "_");
9706
+ var OPT_IN_KEYS = OPT_IN.map(keyOf2);
9707
+ var FIXED_KEYS = new Set([...CORE, ...CONVENTIONS].map(keyOf2));
9644
9708
  function mdFiles(dir) {
9645
9709
  let names;
9646
9710
  try {
@@ -9648,27 +9712,27 @@ function mdFiles(dir) {
9648
9712
  } catch {
9649
9713
  return [];
9650
9714
  }
9651
- return names.filter((n) => n.endsWith(".md") && isFile(join4(dir, n))).sort();
9715
+ return names.filter((n) => n.endsWith(".md") && isFile(join5(dir, n))).sort();
9652
9716
  }
9653
- function standardsOf(home, project) {
9654
- const globalDir = join4(home, "standards");
9655
- const projectDir = join4(home, project, "standards");
9656
- const projectNames = SHARED.has(project) ? [] : mdFiles(projectDir);
9717
+ function standardsOf(home, key) {
9718
+ const globalDir = join5(home, "standards");
9719
+ const ownDir = join5(projectDir(home, key), "standards");
9720
+ const projectNames = mdFiles(ownDir).filter((n) => !CONVENTIONS.includes(n));
9657
9721
  const shipped = readManifest(home) ?? {};
9658
9722
  const out = [];
9659
9723
  for (const name of mdFiles(globalDir)) {
9660
- if (CORE.includes(name))
9724
+ if (CORE.includes(name) || CONVENTIONS.includes(name))
9661
9725
  continue;
9662
9726
  const optIn = OPT_IN.includes(name);
9663
9727
  if (!optIn && ((`standards/${name}` in shipped) || name.endsWith(".default.md")))
9664
9728
  continue;
9665
- const global = { path: join4(globalDir, name), key: keyOf(name), optIn };
9729
+ const global = { path: join5(globalDir, name), key: keyOf2(name), optIn };
9666
9730
  if (projectNames.includes(name))
9667
- global.shadowedBy = join4(projectDir, name);
9731
+ global.shadowedBy = join5(ownDir, name);
9668
9732
  out.push(global);
9669
9733
  }
9670
9734
  for (const name of projectNames)
9671
- out.push({ path: join4(projectDir, name), key: keyOf(name), optIn: false });
9735
+ out.push({ path: join5(ownDir, name), key: keyOf2(name), optIn: false });
9672
9736
  return out;
9673
9737
  }
9674
9738
  function standardsSchema(standards) {
@@ -9683,21 +9747,31 @@ function standardsSchema(standards) {
9683
9747
  var SCHEMA = {
9684
9748
  standards: {},
9685
9749
  engineering: {
9686
- review_rounds: { rule: "non-negative", default: 1 },
9687
- models: { critic: model("opus") }
9750
+ review: {
9751
+ rounds: { rule: "non-negative", default: 1 },
9752
+ model: model("opus")
9753
+ }
9688
9754
  },
9689
9755
  workflow: {
9690
- review_rounds: { rule: "non-negative", default: 1 },
9691
- ci_attempts: { rule: "positive", default: 2 },
9692
- open_pr: bool(true),
9693
- models: { implementer: model("opus"), reviewer: model("opus"), fix: model("opus"), ci: model("sonnet") }
9756
+ defaults: {
9757
+ implement: { model: model("opus") },
9758
+ review: {
9759
+ rounds: { rule: "positive", default: 1 },
9760
+ lenses: { rule: "lenses", default: ["conformance", "correctness"] },
9761
+ model: model("opus"),
9762
+ fix_model: model("opus")
9763
+ },
9764
+ pr: { ci_attempts: { rule: "positive", default: 2 }, model: model("sonnet"), fix_model: model("opus") },
9765
+ agent: { model: model("sonnet") }
9766
+ }
9694
9767
  }
9695
9768
  };
9696
9769
  var RULE_TEXT = {
9697
9770
  boolean: "true or false",
9698
9771
  "non-negative": "a non-negative integer",
9699
9772
  positive: "a positive integer",
9700
- model: "opus, sonnet or haiku"
9773
+ model: "opus, sonnet or haiku",
9774
+ lenses: "a non-empty list of names without duplicates"
9701
9775
  };
9702
9776
  var isLeaf = (node) => typeof node.rule === "string";
9703
9777
  function valid(rule, v) {
@@ -9710,12 +9784,15 @@ function valid(rule, v) {
9710
9784
  return typeof v === "number" && Number.isInteger(v) && v >= 1;
9711
9785
  case "model":
9712
9786
  return v === "opus" || v === "sonnet" || v === "haiku";
9787
+ case "lenses":
9788
+ return isLensList(v);
9713
9789
  }
9714
9790
  }
9715
9791
  function defaults(schema) {
9716
9792
  const out = dict();
9717
- for (const [key, node] of Object.entries(schema))
9718
- out[key] = isLeaf(node) ? node.default : defaults(node);
9793
+ for (const [key, node] of Object.entries(schema)) {
9794
+ out[key] = isLeaf(node) ? Array.isArray(node.default) ? [...node.default] : node.default : defaults(node);
9795
+ }
9719
9796
  return out;
9720
9797
  }
9721
9798
  var warnLoud = (file, text) => {
@@ -9731,13 +9808,13 @@ function apply(file, schema, layer, into, prefix, warn) {
9731
9808
  if (node === undefined) {
9732
9809
  if (prefix !== "standards")
9733
9810
  warn(file, `unknown key ${dotted}`);
9734
- else if (CORE_KEYS.has(key))
9811
+ else if (FIXED_KEYS.has(key))
9735
9812
  warn(file, `${dotted} cannot be switched`);
9736
9813
  else
9737
9814
  warn(file, `${dotted} has no standard file`);
9738
9815
  } else if (isLeaf(node)) {
9739
9816
  if (valid(node.rule, value))
9740
- into[key] = value;
9817
+ into[key] = Array.isArray(value) ? [...value] : value;
9741
9818
  else
9742
9819
  warn(file, `${dotted} must be ${RULE_TEXT[node.rule]}`);
9743
9820
  } else if (value instanceof Map) {
@@ -9750,7 +9827,7 @@ function apply(file, schema, layer, into, prefix, warn) {
9750
9827
  function load(home, file) {
9751
9828
  let text;
9752
9829
  try {
9753
- text = readFileSync6(join4(home, file), "utf-8");
9830
+ text = readFileSync6(join5(home, file), "utf-8");
9754
9831
  } catch {
9755
9832
  return { error: `theway: ${file}: cannot be read` };
9756
9833
  }
@@ -9762,12 +9839,13 @@ function load(home, file) {
9762
9839
  return { error: `theway: ${file}: invalid YAML: ${first.replace(/:$/, "")}` };
9763
9840
  }
9764
9841
  }
9765
- function effectiveConfig(home, project, loud) {
9842
+ function effectiveConfig(home, key, loud) {
9766
9843
  const files = [];
9767
- if (isFile(join4(home, "config.yaml")))
9844
+ const own = join5("projects", key, "config.yaml");
9845
+ if (isFile(join5(home, "config.yaml")))
9768
9846
  files.push("config.yaml");
9769
- if (isFile(join4(home, project, "config.yaml")))
9770
- files.push(join4(project, "config.yaml"));
9847
+ if (isFile(join5(home, own)))
9848
+ files.push(own);
9771
9849
  const roots = [];
9772
9850
  for (const file of files) {
9773
9851
  const loaded = load(home, file);
@@ -9775,7 +9853,7 @@ function effectiveConfig(home, project, loud) {
9775
9853
  return { error: loaded.error };
9776
9854
  roots.push([file, loaded.root]);
9777
9855
  }
9778
- const standards = standardsOf(home, project);
9856
+ const standards = standardsOf(home, key);
9779
9857
  const schema = Object.assign(dict(), SCHEMA, { standards: standardsSchema(standards) });
9780
9858
  const warn = loud ? warnLoud : warnQuiet;
9781
9859
  const config = defaults(schema);
@@ -9793,13 +9871,13 @@ function enabled(config, key) {
9793
9871
  const all = config.standards;
9794
9872
  return !Object.hasOwn(all, key) || all[key].enabled === true;
9795
9873
  }
9796
- function loadConfig(home, project) {
9797
- if (!isFile(join4(home, "config.yaml"))) {
9874
+ function loadConfig(home, key) {
9875
+ if (!isFile(join5(home, "config.yaml"))) {
9798
9876
  process.stderr.write(`theway: config.yaml not found in ${home}; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
9799
9877
  `);
9800
9878
  return null;
9801
9879
  }
9802
- const result = effectiveConfig(home, project, true);
9880
+ const result = effectiveConfig(home, key, true);
9803
9881
  if ("error" in result) {
9804
9882
  process.stderr.write(`${result.error}
9805
9883
  `);
@@ -9807,10 +9885,11 @@ function loadConfig(home, project) {
9807
9885
  }
9808
9886
  return result;
9809
9887
  }
9810
- function cmdConfig(project) {
9811
- if (invalidSegments([["project", project]]))
9888
+ function cmdConfig(override) {
9889
+ const key = resolveKey(override);
9890
+ if (key === null)
9812
9891
  return 1;
9813
- const loaded = loadConfig(thewayHome(), project);
9892
+ const loaded = loadConfig(thewayHome(), key);
9814
9893
  if (loaded === null)
9815
9894
  return 1;
9816
9895
  process.stdout.write($stringify(loaded.config));
@@ -9818,7 +9897,7 @@ function cmdConfig(project) {
9818
9897
  }
9819
9898
 
9820
9899
  // src/core/context.ts
9821
- import { join as join5 } from "node:path";
9900
+ import { join as join6 } from "node:path";
9822
9901
 
9823
9902
  // src/core/standards.ts
9824
9903
  import { readFileSync as readFileSync7 } from "node:fs";
@@ -9893,12 +9972,13 @@ function selectStandards(loaded, phase) {
9893
9972
  };
9894
9973
  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);
9895
9974
  }
9896
- function cmdStandards(project, phase) {
9897
- if (invalidSegments([["project", project]]))
9975
+ function cmdStandards(phase, override) {
9976
+ const key = resolveKey(override);
9977
+ if (key === null)
9898
9978
  return 1;
9899
9979
  if (!checkPhase(phase))
9900
9980
  return 1;
9901
- const result = effectiveConfig(thewayHome(), project, false);
9981
+ const result = effectiveConfig(thewayHome(), key, false);
9902
9982
  if ("error" in result) {
9903
9983
  process.stderr.write(`${result.error}
9904
9984
  `);
@@ -9910,20 +9990,22 @@ function cmdStandards(project, phase) {
9910
9990
  }
9911
9991
 
9912
9992
  // src/core/context.ts
9913
- function cmdContext(project, phase, changeId) {
9914
- if (invalidSegments([["project", project]]))
9993
+ function cmdContext(phase, changeId, override) {
9994
+ const key = resolveKey(override);
9995
+ if (key === null)
9915
9996
  return 1;
9916
9997
  if (!checkPhase(phase))
9917
9998
  return 1;
9918
- if (invalidSegments([["change id", changeId]]))
9999
+ if (invalidChangeId(changeId))
9919
10000
  return 1;
9920
10001
  const home = thewayHome();
9921
- const loaded = loadConfig(home, project);
10002
+ const loaded = loadConfig(home, key);
9922
10003
  if (loaded === null)
9923
10004
  return 1;
9924
- const doc = { home };
10005
+ const dir = projectDir(home, key);
10006
+ const doc = { home, project: key, project_dir: dir };
9925
10007
  if (changeId !== undefined)
9926
- doc.change_dir = join5(home, project, "changes", changeId);
10008
+ doc.change_dir = join6(dir, "changes", changeId);
9927
10009
  doc.standards = selectStandards(loaded, phase);
9928
10010
  doc.config = loaded.config;
9929
10011
  process.stdout.write($stringify(doc));
@@ -9932,7 +10014,7 @@ function cmdContext(project, phase, changeId) {
9932
10014
 
9933
10015
  // src/core/next-id.ts
9934
10016
  import { readdirSync as readdirSync4 } from "node:fs";
9935
- import { join as join6 } from "node:path";
10017
+ import { join as join7 } from "node:path";
9936
10018
 
9937
10019
  // src/core/validate-id.ts
9938
10020
  var VERB = /^(add|update|refactor|remove|fix)-/;
@@ -9995,7 +10077,7 @@ function cmdValidateId(id, series) {
9995
10077
  // src/core/next-id.ts
9996
10078
  function dirs(dir) {
9997
10079
  try {
9998
- return readdirSync4(dir).filter((n) => isDir(join6(dir, n)));
10080
+ return readdirSync4(dir).filter((n) => isDir(join7(dir, n)));
9999
10081
  } catch {
10000
10082
  return [];
10001
10083
  }
@@ -10009,8 +10091,9 @@ function seriesIdReason(id) {
10009
10091
  return `ends in a number (-${tail}); a series id cannot end in a number`;
10010
10092
  return "";
10011
10093
  }
10012
- function cmdNextId(project, seriesId, count) {
10013
- if (invalidSegments([["project", project]]))
10094
+ function cmdNextId(seriesId, count, override) {
10095
+ const key = resolveKey(override);
10096
+ if (key === null)
10014
10097
  return 1;
10015
10098
  const rest = seriesId.replace(/-[0-9]{2}$/, "");
10016
10099
  const reason = seriesIdReason(rest);
@@ -10021,13 +10104,13 @@ function cmdNextId(project, seriesId, count) {
10021
10104
  `);
10022
10105
  return 1;
10023
10106
  }
10024
- const changes = join6(thewayHome(), project, "changes");
10107
+ const changes = join7(projectDir(thewayHome(), key), "changes");
10025
10108
  const active = new RegExp(`^${rest}-([0-9]{2})$`);
10026
10109
  const archived = new RegExp(`^[0-9]{4}-[0-9]{2}-[0-9]{2}-${rest}-([0-9]{2})$`);
10027
10110
  let max = 0;
10028
10111
  for (const [dir, pattern] of [
10029
10112
  [changes, active],
10030
- [join6(changes, "archive"), archived]
10113
+ [join7(changes, "archive"), archived]
10031
10114
  ]) {
10032
10115
  for (const name of dirs(dir)) {
10033
10116
  const m = pattern.exec(name);
@@ -10048,6 +10131,233 @@ function cmdNextId(project, seriesId, count) {
10048
10131
  return 0;
10049
10132
  }
10050
10133
 
10134
+ // src/core/workflow.ts
10135
+ import { readdirSync as readdirSync5 } from "node:fs";
10136
+ import { basename as basename2, join as join8, relative } from "node:path";
10137
+ var TYPES = ["implement", "review", "agent", "pr"];
10138
+ var positive = {
10139
+ test: (v) => typeof v === "number" && Number.isInteger(v) && v >= 1,
10140
+ text: "a positive integer"
10141
+ };
10142
+ var model2 = { test: (v) => v === "opus" || v === "sonnet" || v === "haiku", text: "opus, sonnet or haiku" };
10143
+ var lenses = { test: isLensList, text: "a non-empty list of names without duplicates" };
10144
+ var name = {
10145
+ test: (v) => typeof v === "string" && NAME.test(v),
10146
+ text: "a name (lowercase letters, digits and -)"
10147
+ };
10148
+ var nonEmpty = { test: (v) => typeof v === "string" && v.length > 0, text: "a non-empty string" };
10149
+ var bool2 = { test: (v) => typeof v === "boolean", text: "true or false" };
10150
+ var FIELDS = {
10151
+ implement: [["model", model2]],
10152
+ review: [
10153
+ ["rounds", positive],
10154
+ ["lenses", lenses],
10155
+ ["model", model2],
10156
+ ["fix_model", model2]
10157
+ ],
10158
+ agent: [
10159
+ ["name", name],
10160
+ ["prompt", nonEmpty],
10161
+ ["model", model2]
10162
+ ],
10163
+ pr: [
10164
+ ["ci_attempts", positive],
10165
+ ["model", model2],
10166
+ ["fix_model", model2]
10167
+ ]
10168
+ };
10169
+ var REQUIRED = ["name", "prompt"];
10170
+ var MODELS = ["model", "fix_model"];
10171
+ var projectDir2 = (d, kind) => join8(projectDir(d.home, d.key), kind);
10172
+ var globalDir = (d, kind) => join8(d.home, kind);
10173
+ var searched = (d, kind) => `${projectDir2(d, kind)} or ${globalDir(d, kind)}`;
10174
+ function lensPath(d, lens) {
10175
+ const own = join8(projectDir2(d, "lenses"), `${lens}.md`);
10176
+ if (isFile(own))
10177
+ return own;
10178
+ const global = join8(globalDir(d, "lenses"), `${lens}.md`);
10179
+ return isFile(global) ? global : null;
10180
+ }
10181
+ function validate(d, path2, defaults2) {
10182
+ const rel = relative(d.home, path2);
10183
+ const fail = (reason) => ({ error: `theway: ${rel}: ${reason}` });
10184
+ const loaded = load(d.home, rel);
10185
+ if ("error" in loaded)
10186
+ return loaded;
10187
+ const root = loaded.root;
10188
+ if (!(root instanceof Map))
10189
+ return fail("not a map");
10190
+ for (const key of root.keys()) {
10191
+ if (key !== "default" && key !== "agents" && key !== "steps")
10192
+ return fail(`unknown key ${String(key)}`);
10193
+ }
10194
+ if (root.has("default") && typeof root.get("default") !== "boolean")
10195
+ return fail("default must be true or false");
10196
+ if (root.has("agents") && typeof root.get("agents") !== "boolean")
10197
+ return fail("agents must be true or false");
10198
+ const topAgents = root.has("agents") ? root.get("agents") : true;
10199
+ const entries = root.get("steps");
10200
+ if (!Array.isArray(entries) || entries.length === 0)
10201
+ return fail("steps must be a non-empty list");
10202
+ const steps = [];
10203
+ for (const [i, entry] of entries.entries()) {
10204
+ const at = `steps[${i}]`;
10205
+ const type = entry instanceof Map && entry.size === 1 ? [...entry.keys()][0] : undefined;
10206
+ if (!TYPES.includes(type))
10207
+ return fail(`${at} must be one of ${TYPES.join(", ")}`);
10208
+ const t = type;
10209
+ const value = entry.get(t);
10210
+ if (value !== null && !(value instanceof Map))
10211
+ return fail(`${at}.${t} must be a map`);
10212
+ const given = value ?? new Map;
10213
+ const fields = new Map([["agents", bool2], ...FIELDS[t]]);
10214
+ for (const key of given.keys()) {
10215
+ if (typeof key !== "string" || !fields.has(key))
10216
+ return fail(`${at}.${t}.${String(key)} is not a field of ${t}`);
10217
+ }
10218
+ for (const [key, v] of given) {
10219
+ const rule = fields.get(key);
10220
+ if (!rule.test(v))
10221
+ return fail(`${at}.${t}.${String(key)} must be ${rule.text}`);
10222
+ }
10223
+ const agents = given.has("agents") ? given.get("agents") : topAgents;
10224
+ if (!agents) {
10225
+ for (const key of given.keys()) {
10226
+ if (MODELS.includes(key)) {
10227
+ return fail(`${at}.${t}.${String(key)} has no effect when the step runs inline (agents: false)`);
10228
+ }
10229
+ }
10230
+ }
10231
+ if (t === "agent") {
10232
+ for (const field of REQUIRED)
10233
+ if (!given.has(field))
10234
+ return fail(`${at}.agent.${field} is required`);
10235
+ }
10236
+ if (i === 0 && t !== "implement")
10237
+ return fail("steps[0] must be implement");
10238
+ if (i > 0 && t === "implement")
10239
+ return fail(`${at}: implement may appear only once`);
10240
+ if (t === "pr" && i !== entries.length - 1)
10241
+ return fail(`${at}: pr must be the last step`);
10242
+ const own = defaults2[t] ?? {};
10243
+ const step = { step: t, agents };
10244
+ for (const [field] of FIELDS[t]) {
10245
+ if (!agents && MODELS.includes(field))
10246
+ continue;
10247
+ const v = given.has(field) ? given.get(field) : own[field];
10248
+ step[field] = Array.isArray(v) ? [...v] : v;
10249
+ }
10250
+ if (t === "review") {
10251
+ const found = [];
10252
+ for (const lens of step.lenses) {
10253
+ const p = lensPath(d, lens);
10254
+ if (p === null) {
10255
+ return fail(`${at}.review lens '${lens}' has no file in ${searched(d, "lenses")}`);
10256
+ }
10257
+ found.push({ name: lens, path: p });
10258
+ }
10259
+ step.lenses = found;
10260
+ }
10261
+ steps.push(step);
10262
+ }
10263
+ return { workflow: { name: basename2(path2, ".yaml"), file: path2, steps }, isDefault: root.get("default") === true };
10264
+ }
10265
+ function scan(d, dir) {
10266
+ let names;
10267
+ try {
10268
+ names = readdirSync5(dir);
10269
+ } catch {
10270
+ return [];
10271
+ }
10272
+ const out = [];
10273
+ for (const n of names.sort()) {
10274
+ if (!n.endsWith(".yaml") || n.endsWith(".default.yaml") || !isFile(join8(dir, n)))
10275
+ continue;
10276
+ if (!NAME.test(n.slice(0, -".yaml".length))) {
10277
+ process.stderr.write(`theway: warning: ${relative(d.home, join8(dir, n))}: not a valid workflow name; ignored
10278
+ `);
10279
+ continue;
10280
+ }
10281
+ out.push(n);
10282
+ }
10283
+ return out;
10284
+ }
10285
+ var joinAnd = (items) => items.length === 1 ? items[0] : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
10286
+ function defaultOf(d, paths, defaults2) {
10287
+ const marked = [];
10288
+ for (const path2 of paths) {
10289
+ const result = validate(d, path2, defaults2);
10290
+ if ("error" in result)
10291
+ return result;
10292
+ if (result.isDefault)
10293
+ marked.push(result.workflow);
10294
+ }
10295
+ if (marked.length > 1) {
10296
+ return { error: `theway: ${joinAnd(marked.map((w) => relative(d.home, w.file)))} both set default: true` };
10297
+ }
10298
+ return marked.length === 1 ? { workflow: marked[0] } : null;
10299
+ }
10300
+ function byName(d, wanted, defaults2) {
10301
+ const own = join8(projectDir2(d, "workflows"), `${wanted}.yaml`);
10302
+ const global = join8(globalDir(d, "workflows"), `${wanted}.yaml`);
10303
+ const path2 = isFile(own) ? own : isFile(global) ? global : null;
10304
+ if (path2 === null) {
10305
+ return { error: `theway: no workflow '${wanted}' in ${searched(d, "workflows")}` };
10306
+ }
10307
+ return validate(d, path2, defaults2);
10308
+ }
10309
+ function byDefault(d, defaults2) {
10310
+ const ownNames = scan(d, projectDir2(d, "workflows"));
10311
+ const own = defaultOf(d, ownNames.map((n) => join8(projectDir2(d, "workflows"), n)), defaults2);
10312
+ if (own !== null)
10313
+ return own;
10314
+ const globalNames = scan(d, globalDir(d, "workflows")).filter((n) => !ownNames.includes(n));
10315
+ const global = defaultOf(d, globalNames.map((n) => join8(globalDir(d, "workflows"), n)), defaults2);
10316
+ if (global !== null)
10317
+ return global;
10318
+ return byName(d, "develop", defaults2);
10319
+ }
10320
+ function cmdWorkflow(wanted, override) {
10321
+ const key = resolveKey(override);
10322
+ if (key === null)
10323
+ return 1;
10324
+ if (wanted !== undefined && !NAME.test(wanted)) {
10325
+ const shown = wanted.replaceAll(`
10326
+ `, "\\n").replaceAll("\r", "\\r");
10327
+ process.stderr.write(`theway: invalid workflow name '${shown}'
10328
+ `);
10329
+ return 1;
10330
+ }
10331
+ const home = thewayHome();
10332
+ const loaded = loadConfig(home, key);
10333
+ if (loaded === null)
10334
+ return 1;
10335
+ const defaults2 = loaded.config.workflow.defaults;
10336
+ const d = { home, key };
10337
+ const result = wanted === undefined ? byDefault(d, defaults2) : byName(d, wanted, defaults2);
10338
+ if ("error" in result) {
10339
+ process.stderr.write(`${result.error}
10340
+ `);
10341
+ return 1;
10342
+ }
10343
+ const conventions = [];
10344
+ for (const file2 of CONVENTIONS) {
10345
+ const global = join8(home, "standards", file2);
10346
+ if (!isFile(global)) {
10347
+ process.stderr.write(`theway: ${global} not found; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
10348
+ `);
10349
+ return 1;
10350
+ }
10351
+ const own = join8(projectDir(home, key), "standards", file2);
10352
+ conventions.push(isFile(own) ? own : global);
10353
+ }
10354
+ const { name: name2, file, steps } = result.workflow;
10355
+ const doc = { name: name2, file, commits: conventions[0], git_host: conventions[1], steps };
10356
+ process.stdout.write(`${JSON.stringify(doc, null, 2)}
10357
+ `);
10358
+ return 0;
10359
+ }
10360
+
10051
10361
  // src/install.ts
10052
10362
  import {
10053
10363
  accessSync,
@@ -10060,7 +10370,7 @@ import {
10060
10370
  mkdirSync as mkdirSync3,
10061
10371
  readFileSync as readFileSync8,
10062
10372
  readlinkSync,
10063
- realpathSync,
10373
+ realpathSync as realpathSync2,
10064
10374
  renameSync as renameSync3,
10065
10375
  rmdirSync,
10066
10376
  rmSync as rmSync2,
@@ -10068,7 +10378,7 @@ import {
10068
10378
  writeFileSync as writeFileSync2
10069
10379
  } from "node:fs";
10070
10380
  import { homedir as homedir2 } from "node:os";
10071
- import { delimiter, dirname, isAbsolute, join as join7, resolve as resolve3, sep } from "node:path";
10381
+ import { delimiter, dirname as dirname2, isAbsolute, join as join9, resolve as resolve4, sep } from "node:path";
10072
10382
  import { fileURLToPath } from "node:url";
10073
10383
 
10074
10384
  // node_modules/@clack/core/dist/index.mjs
@@ -11478,20 +11788,20 @@ ${i2}
11478
11788
 
11479
11789
  // src/install.ts
11480
11790
  var self = fileURLToPath(import.meta.url);
11481
- var pkgRoot = dirname(dirname(self));
11482
- var plugin = join7(pkgRoot, "plugin");
11483
- var PLUGIN_DIRS = [".claude-plugin", "commands"];
11791
+ var pkgRoot = dirname2(dirname2(self));
11792
+ var plugin = join9(pkgRoot, "plugin");
11793
+ var PLUGIN_DIRS = [".claude-plugin", "commands", "workflows"];
11484
11794
  var BINARY_MARKER = "theway-cli-binary:pixelfactoryio/theway";
11485
11795
  function claudeHome() {
11486
11796
  const dir = (process.env.CLAUDE_CONFIG_DIR ?? "").trim();
11487
- return dir !== "" ? dir : join7(homedir2(), ".claude");
11797
+ return dir !== "" ? dir : join9(homedir2(), ".claude");
11488
11798
  }
11489
11799
  function installDir() {
11490
11800
  const dir = process.env.THEWAY_INSTALL_DIR ?? "";
11491
- return dir !== "" ? resolve3(dir) : join7(homedir2(), ".local", "bin");
11801
+ return dir !== "" ? resolve4(dir) : join9(homedir2(), ".local", "bin");
11492
11802
  }
11493
11803
  function shownHome(home) {
11494
- return resolve3(home) === resolve3(defaultHome()) ? "~/.theway" : resolve3(home);
11804
+ return resolve4(home) === resolve4(defaultHome()) ? "~/.theway" : resolve4(home);
11495
11805
  }
11496
11806
  function ruleRoot(home) {
11497
11807
  const at = shownHome(home);
@@ -11508,7 +11818,7 @@ function rules(home) {
11508
11818
  }
11509
11819
  function recordedHome() {
11510
11820
  const pointer = readPointer();
11511
- return pointer !== "" ? resolve3(pointer) : defaultHome();
11821
+ return pointer !== "" ? resolve4(pointer) : defaultHome();
11512
11822
  }
11513
11823
  function legacyRules(home) {
11514
11824
  return [...new Set(["Bash(~/.theway/bin/theway:*)", `Bash(${shownHome(home)}/bin/theway:*)`])];
@@ -11556,11 +11866,11 @@ function settingsTarget(path2) {
11556
11866
  if (seen.has(target) || seen.size >= 40)
11557
11867
  return { error: "it is a symlink loop" };
11558
11868
  seen.add(target);
11559
- target = resolve3(dirname(target), readlinkSync(target));
11869
+ target = resolve4(dirname2(target), readlinkSync(target));
11560
11870
  }
11561
- let dir = dirname(target);
11562
- while (!existsSync3(dir) && dirname(dir) !== dir)
11563
- dir = dirname(dir);
11871
+ let dir = dirname2(target);
11872
+ while (!existsSync3(dir) && dirname2(dir) !== dir)
11873
+ dir = dirname2(dir);
11564
11874
  try {
11565
11875
  accessSync(dir, constants.W_OK);
11566
11876
  } catch {
@@ -11572,7 +11882,7 @@ function unwritableSettings(path2, reason) {
11572
11882
  return fail(`theway: cannot write ${path2}: ${reason}; nothing was changed`);
11573
11883
  }
11574
11884
  function writeSettings(target, settings2) {
11575
- mkdirSync3(dirname(target), { recursive: true });
11885
+ mkdirSync3(dirname2(target), { recursive: true });
11576
11886
  const mode = existsSync3(target) ? statSync3(target).mode & 511 : 384;
11577
11887
  const tmp = `${target}.tmp-${process.pid}`;
11578
11888
  try {
@@ -11588,15 +11898,15 @@ function invalidSettings(path2) {
11588
11898
  return fail(`theway: ${path2} is not valid settings JSON; nothing was changed`);
11589
11899
  }
11590
11900
  function copyPlugin(home) {
11591
- const tmp = join7(home, `.theway-install-${process.pid}`);
11592
- const old = join7(home, `.theway-old-${process.pid}`);
11593
- const dest = join7(home, "skills", "theway");
11901
+ const tmp = join9(home, `.theway-install-${process.pid}`);
11902
+ const old = join9(home, `.theway-old-${process.pid}`);
11903
+ const dest = join9(home, "skills", "theway");
11594
11904
  rmSync2(tmp, { recursive: true, force: true });
11595
11905
  try {
11596
11906
  for (const dir of PLUGIN_DIRS) {
11597
- cpSync(join7(plugin, dir), join7(tmp, dir), { recursive: true });
11907
+ cpSync(join9(plugin, dir), join9(tmp, dir), { recursive: true });
11598
11908
  }
11599
- mkdirSync3(join7(home, "skills"), { recursive: true });
11909
+ mkdirSync3(join9(home, "skills"), { recursive: true });
11600
11910
  if (existsSync3(dest))
11601
11911
  renameSync3(dest, old);
11602
11912
  renameSync3(tmp, dest);
@@ -11619,23 +11929,23 @@ function legacyText(path2, match) {
11619
11929
  }
11620
11930
  }
11621
11931
  function removeLegacyBin(home) {
11622
- for (const h2 of new Set([defaultHome(), resolve3(home)])) {
11623
- const bin = join7(h2, "bin");
11624
- if (legacyText(join7(bin, "theway"), (t2) => t2.startsWith(`#!/bin/sh
11932
+ for (const h2 of new Set([defaultHome(), resolve4(home)])) {
11933
+ const bin = join9(h2, "bin");
11934
+ if (legacyText(join9(bin, "theway"), (t2) => t2.startsWith(`#!/bin/sh
11625
11935
  exec node `) && t2.endsWith(`theway.js' "$@"
11626
11936
  `))) {
11627
- rmSync2(join7(bin, "theway"), { force: true });
11937
+ rmSync2(join9(bin, "theway"), { force: true });
11628
11938
  }
11629
- if (legacyText(join7(bin, "theway.js"), (t2) => t2.startsWith(`#!/usr/bin/env node
11939
+ if (legacyText(join9(bin, "theway.js"), (t2) => t2.startsWith(`#!/usr/bin/env node
11630
11940
  `))) {
11631
- rmSync2(join7(bin, "theway.js"), { force: true });
11941
+ rmSync2(join9(bin, "theway.js"), { force: true });
11632
11942
  }
11633
11943
  removeIfEmpty2(bin);
11634
11944
  }
11635
11945
  }
11636
11946
  function writeBinary(dir) {
11637
- const dest = join7(dir, "theway");
11638
- const tmp = join7(dir, `.theway-${process.pid}`);
11947
+ const dest = join9(dir, "theway");
11948
+ const tmp = join9(dir, `.theway-${process.pid}`);
11639
11949
  mkdirSync3(dir, { recursive: true });
11640
11950
  try {
11641
11951
  copyFileSync2(self, tmp);
@@ -11667,7 +11977,7 @@ function isThewayBinary(path2) {
11667
11977
  function writePointer(home, custom) {
11668
11978
  const path2 = pointerPath();
11669
11979
  if (custom) {
11670
- mkdirSync3(dirname(path2), { recursive: true });
11980
+ mkdirSync3(dirname2(path2), { recursive: true });
11671
11981
  writeFileSync2(path2, `${home}
11672
11982
  `);
11673
11983
  } else {
@@ -11676,13 +11986,13 @@ function writePointer(home, custom) {
11676
11986
  }
11677
11987
  function realpathOr(path2) {
11678
11988
  try {
11679
- return realpathSync(path2);
11989
+ return realpathSync2(path2);
11680
11990
  } catch {
11681
- return resolve3(path2);
11991
+ return resolve4(path2);
11682
11992
  }
11683
11993
  }
11684
11994
  function unsafeHomeReason(tHome, custom) {
11685
- const home = resolve3(tHome);
11995
+ const home = resolve4(tHome);
11686
11996
  const real = realpathOr(home);
11687
11997
  const user = realpathOr(homedir2());
11688
11998
  if (real === user || user.startsWith(real + sep) || real === "/") {
@@ -11699,7 +12009,7 @@ function copiesOnPath() {
11699
12009
  for (const dir of (process.env.PATH ?? "").split(delimiter)) {
11700
12010
  if (dir === "")
11701
12011
  continue;
11702
- const candidate = join7(dir, "theway");
12012
+ const candidate = join9(dir, "theway");
11703
12013
  if (!isFile(candidate))
11704
12014
  continue;
11705
12015
  try {
@@ -11717,7 +12027,7 @@ function copiesOnPath() {
11717
12027
  }
11718
12028
  function checkPath(dir, binary) {
11719
12029
  const dirs2 = (process.env.PATH ?? "").split(delimiter).filter((d) => d !== "");
11720
- if (!dirs2.some((d) => resolve3(d) === dir)) {
12030
+ if (!dirs2.some((d) => resolve4(d) === dir)) {
11721
12031
  process.stdout.write(`Add ${dir} to your PATH, e.g.: export PATH="${dir}:$PATH"
11722
12032
  `);
11723
12033
  }
@@ -11741,9 +12051,9 @@ function expandHome(value) {
11741
12051
  if (v === "~")
11742
12052
  return homedir2();
11743
12053
  if (v.startsWith("~/"))
11744
- return resolve3(homedir2(), v.slice(2));
12054
+ return resolve4(homedir2(), v.slice(2));
11745
12055
  if (isAbsolute(v))
11746
- return resolve3(v);
12056
+ return resolve4(v);
11747
12057
  return { error: "must be an absolute path or start with ~/" };
11748
12058
  }
11749
12059
  function parseStandards(value) {
@@ -11777,7 +12087,7 @@ async function askHome() {
11777
12087
  const home2 = expandHome(value);
11778
12088
  if (typeof home2 !== "string")
11779
12089
  return home2.error;
11780
- const reason = unsafeHomeReason(home2, home2 !== resolve3(defaultHome()));
12090
+ const reason = unsafeHomeReason(home2, home2 !== resolve4(defaultHome()));
11781
12091
  return reason !== "" ? `refusing ${home2}: ${reason}` : undefined;
11782
12092
  }
11783
12093
  });
@@ -11795,7 +12105,7 @@ async function askStandards() {
11795
12105
  return isCancel(answer) ? null : answer;
11796
12106
  }
11797
12107
  async function install(opts) {
11798
- if (!existsSync3(join7(plugin, ".claude-plugin"))) {
12108
+ if (!existsSync3(join9(plugin, ".claude-plugin"))) {
11799
12109
  return fail("theway: run `npx --yes @pixelfactoryio/theway@latest install` to install or update theway");
11800
12110
  }
11801
12111
  let enabled2 = [];
@@ -11812,13 +12122,13 @@ async function install(opts) {
11812
12122
  if (typeof home !== "string")
11813
12123
  return fail(`theway: invalid --home '${opts.home}': ${home.error}; nothing was changed`);
11814
12124
  const env = process.env.THEWAY_HOME ?? "";
11815
- if (env !== "" && resolve3(env) !== home) {
11816
- return fail(`theway: --home ${home} and THEWAY_HOME ${resolve3(env)} differ; unset THEWAY_HOME or drop --home; nothing was changed`);
12125
+ if (env !== "" && resolve4(env) !== home) {
12126
+ return fail(`theway: --home ${home} and THEWAY_HOME ${resolve4(env)} differ; unset THEWAY_HOME or drop --home; nothing was changed`);
11817
12127
  }
11818
12128
  tHome = home;
11819
12129
  } else {
11820
12130
  const found = resolveHome();
11821
- const neverInstalled = found.source === "default" && !existsSync3(join7(defaultHome(), "config.yaml"));
12131
+ const neverInstalled = found.source === "default" && !existsSync3(join9(defaultHome(), "config.yaml"));
11822
12132
  if (neverInstalled && interactive()) {
11823
12133
  const home = await askHome();
11824
12134
  if (home === null)
@@ -11829,12 +12139,12 @@ async function install(opts) {
11829
12139
  }
11830
12140
  }
11831
12141
  const previous = recordedHome();
11832
- const custom = tHome !== resolve3(defaultHome());
12142
+ const custom = tHome !== resolve4(defaultHome());
11833
12143
  const dir = installDir();
11834
- const settingsPath = join7(cHome, "settings.json");
12144
+ const settingsPath = join9(cHome, "settings.json");
11835
12145
  const unsafe = unsafeHomeReason(tHome, custom);
11836
12146
  if (unsafe !== "") {
11837
- return fail(`theway: refusing data home ${resolve3(tHome)}: ${unsafe}; set THEWAY_HOME or --home to a dedicated folder`);
12147
+ return fail(`theway: refusing data home ${resolve4(tHome)}: ${unsafe}; set THEWAY_HOME or --home to a dedicated folder`);
11838
12148
  }
11839
12149
  const resolved = settingsTarget(settingsPath);
11840
12150
  if ("error" in resolved)
@@ -11842,11 +12152,11 @@ async function install(opts) {
11842
12152
  const settings2 = readSettings(resolved.target);
11843
12153
  if (settings2 === null)
11844
12154
  return invalidSettings(settingsPath);
11845
- const target = join7(dir, "theway");
12155
+ const target = join9(dir, "theway");
11846
12156
  if (occupied(target) && !isThewayBinary(target)) {
11847
12157
  return fail(`theway: ${target} exists and is not a theway binary; nothing was changed. Remove it, or set THEWAY_INSTALL_DIR to another folder`);
11848
12158
  }
11849
- const config = join7(resolve3(tHome), "config.yaml");
12159
+ const config = join9(resolve4(tHome), "config.yaml");
11850
12160
  const firstInstall = !existsSync3(config);
11851
12161
  if (opts.standards !== undefined && !firstInstall) {
11852
12162
  return fail(`theway: --standards applies only to a first install; ${config} exists, so set standards.<key>.enabled there instead; nothing was changed`);
@@ -11866,7 +12176,7 @@ async function install(opts) {
11866
12176
  } catch (e) {
11867
12177
  return fail(`theway: ${e.message}`);
11868
12178
  }
11869
- const status = init(join7(plugin, "home"), tHome, enabled2);
12179
+ const status = init(join9(plugin, "home"), tHome, enabled2);
11870
12180
  if (status !== 0)
11871
12181
  return status;
11872
12182
  if (firstInstall && opts.standards === undefined && !asked) {
@@ -11895,7 +12205,7 @@ async function install(opts) {
11895
12205
  writeSettings(resolved.target, settings2);
11896
12206
  }
11897
12207
  checkPath(dir, binary);
11898
- const version = JSON.parse(readFileSync8(join7(pkgRoot, "package.json"), "utf-8")).version;
12208
+ const version = JSON.parse(readFileSync8(join9(pkgRoot, "package.json"), "utf-8")).version;
11899
12209
  process.stdout.write(`Installed theway ${version} to ${dest} (theway@skills-dir), ${binary} and ${tHome}. Start a new Claude Code session or run /reload-plugins.
11900
12210
  `);
11901
12211
  return 0;
@@ -11904,7 +12214,7 @@ function uninstall() {
11904
12214
  const cHome = claudeHome();
11905
12215
  const tHome = resolveHome().home;
11906
12216
  const homes = [...new Set([tHome, recordedHome(), defaultHome()])];
11907
- const settingsPath = join7(cHome, "settings.json");
12217
+ const settingsPath = join9(cHome, "settings.json");
11908
12218
  let settingsFile = settingsPath;
11909
12219
  if (occupied(settingsPath)) {
11910
12220
  const resolved = settingsTarget(settingsPath);
@@ -11912,13 +12222,13 @@ function uninstall() {
11912
12222
  return unwritableSettings(settingsPath, resolved.error);
11913
12223
  settingsFile = resolved.target;
11914
12224
  }
11915
- rmSync2(join7(cHome, "skills", "theway"), { recursive: true, force: true });
11916
- const binary = join7(installDir(), "theway");
12225
+ rmSync2(join9(cHome, "skills", "theway"), { recursive: true, force: true });
12226
+ const binary = join9(installDir(), "theway");
11917
12227
  const removed = isThewayBinary(binary);
11918
12228
  if (removed)
11919
12229
  rmSync2(binary, { force: true });
11920
12230
  rmSync2(pointerPath(), { force: true });
11921
- removeIfEmpty2(dirname(pointerPath()));
12231
+ removeIfEmpty2(dirname2(pointerPath()));
11922
12232
  if (existsSync3(settingsPath)) {
11923
12233
  const settings2 = readSettings(settingsFile);
11924
12234
  if (settings2 === null)
@@ -11940,12 +12250,12 @@ function uninstall() {
11940
12250
  }
11941
12251
 
11942
12252
  // src/program.ts
11943
- var nonEmpty = (value) => {
12253
+ var nonEmpty2 = (value) => {
11944
12254
  if (value === "")
11945
12255
  throw new InvalidArgumentError("must not be empty");
11946
12256
  return value;
11947
12257
  };
11948
- var positive = (value) => {
12258
+ var positive2 = (value) => {
11949
12259
  if (!/^[1-9][0-9]*$/.test(value))
11950
12260
  throw new InvalidArgumentError("must be a positive integer");
11951
12261
  return Number(value);
@@ -11955,16 +12265,18 @@ var exit = (code) => {
11955
12265
  };
11956
12266
  function buildProgram() {
11957
12267
  const program2 = new Command("theway");
11958
- program2.command("install").option("--home <path>", "", nonEmpty).option("--standards <keys>").action(async (o2) => exit(await install({ home: o2.home, standards: o2.standards })));
12268
+ program2.command("install").option("--home <path>", "", nonEmpty2).option("--standards <keys>").action(async (o2) => exit(await install({ home: o2.home, standards: o2.standards })));
11959
12269
  program2.command("uninstall").action(() => exit(uninstall()));
11960
- program2.command("list").argument("<project>", "", nonEmpty).action((project) => exit(cmdList(project)));
11961
- program2.command("archive").argument("<project>", "", nonEmpty).argument("<change-id>", "", nonEmpty).option("--force").action((project, change, o2) => exit(cmdArchive(project, change, o2.force === true)));
11962
- program2.command("path").argument("[project]").argument("[change-id]").option("--verbose").action((project, change, o2) => exit(cmdPath(project, change, o2.verbose === true)));
11963
- program2.command("config").argument("<project>").action((project) => exit(cmdConfig(project)));
11964
- program2.command("standards").argument("<project>").argument("<phase>").action((project, phase) => exit(cmdStandards(project, phase)));
11965
- program2.command("context").argument("<project>").argument("<phase>").argument("[change-id]").action((project, phase, change) => exit(cmdContext(project, phase, change)));
12270
+ program2.command("list").option("--project <key>").action((o2) => exit(cmdList(o2.project)));
12271
+ program2.command("archive").argument("<change-id>", "", nonEmpty2).option("--project <key>").option("--force").action((change, o2) => exit(cmdArchive(change, o2.project, o2.force === true)));
12272
+ program2.command("path").argument("[change-id]").option("--project <key>").option("--verbose").action((change, o2) => exit(cmdPath(change, o2.project, o2.verbose === true)));
12273
+ program2.command("project").option("--project <key>").action((o2) => exit(cmdProject(o2.project)));
12274
+ program2.command("config").option("--project <key>").action((o2) => exit(cmdConfig(o2.project)));
12275
+ program2.command("standards").argument("<phase>").option("--project <key>").action((phase, o2) => exit(cmdStandards(phase, o2.project)));
12276
+ program2.command("context").argument("<phase>").argument("[change-id]").option("--project <key>").action((phase, change, o2) => exit(cmdContext(phase, change, o2.project)));
12277
+ program2.command("workflow").argument("[name]").option("--project <key>").action((name2, o2) => exit(cmdWorkflow(name2, o2.project)));
11966
12278
  program2.command("authority").action(() => exit(cmdAuthority()));
11967
- program2.command("next-id").argument("<project>").argument("<series-id>").option("--count <n>", "", positive, 1).action((project, series, o2) => exit(cmdNextId(project, series, o2.count)));
12279
+ program2.command("next-id").argument("<series-id>").option("--project <key>").option("--count <n>", "", positive2, 1).action((series, o2) => exit(cmdNextId(series, o2.count, o2.project)));
11968
12280
  program2.command("validate-id").argument("<id>").option("--series").action((id, o2) => exit(cmdValidateId(id, o2.series === true)));
11969
12281
  return program2;
11970
12282
  }