@pixelfactoryio/theway 0.14.1 → 0.15.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/README.md +2 -0
- package/dist/theway.js +1156 -291
- package/package.json +5 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/archive.md +1 -0
- package/plugin/commands/document.md +2 -0
- package/plugin/commands/engineering.md +1 -129
- package/plugin/commands/list.md +1 -0
- package/plugin/commands/workflow.md +85 -35
- package/plugin/home/config.yaml +7 -36
- package/plugin/home/prompts/ci-diagnose.md +15 -0
- package/plugin/home/prompts/ci-fix.md +7 -0
- package/plugin/home/prompts/ci-wait.md +5 -0
- package/plugin/home/prompts/fix-check.md +7 -0
- package/plugin/home/{templates → prompts}/fix-spec-template.md +7 -1
- package/plugin/home/prompts/fix.md +9 -0
- package/plugin/home/prompts/grounding.md +7 -0
- package/plugin/home/prompts/implement.md +9 -0
- package/plugin/home/prompts/implementability.md +12 -0
- package/plugin/home/{templates → prompts}/light-spec-template.md +3 -1
- package/plugin/home/prompts/open-pr.md +5 -0
- package/plugin/home/prompts/reviewer.md +7 -0
- package/plugin/home/prompts/scaffold-light.md +38 -0
- package/plugin/home/prompts/scaffold-rules.md +22 -0
- package/plugin/home/prompts/scaffold.md +55 -0
- package/plugin/home/prompts/spec-fix.md +5 -0
- package/plugin/home/{standards → prompts}/spec-investigation.md +5 -4
- package/plugin/home/prompts/spec-reviewer.md +16 -0
- package/plugin/home/{templates → prompts}/spec-template.md +10 -1
- package/plugin/home/prompts/spec-triage.md +5 -0
- package/plugin/home/{standards → prompts}/tamm-framework.md +8 -0
- package/plugin/home/{templates → prompts}/tasks-template.md +3 -0
- package/plugin/home/prompts/triage.md +3 -0
- package/plugin/home/prompts/verdicts.md +11 -0
- package/plugin/home/schemas/step.v1.json +449 -0
- package/plugin/home/schemas/workflow.v1.json +110 -0
- package/plugin/home/standards/commits.md +1 -1
- package/plugin/home/standards/develop.md +2 -2
- package/plugin/home/standards/interaction.md +1 -1
- package/plugin/home/standards/sre.md +2 -2
- package/plugin/home/standards/web-development.md +3 -0
- package/plugin/home/steps/implement.yaml +7 -0
- package/plugin/home/steps/pr.yaml +21 -0
- package/plugin/home/steps/review.yaml +25 -0
- package/plugin/home/steps/scaffold-light.yaml +7 -0
- package/plugin/home/steps/scaffold.yaml +7 -0
- package/plugin/home/steps/spec-review.yaml +26 -0
- package/plugin/home/templates/source-tree-template.md +5 -0
- package/plugin/home/templates/tech-stack-template.md +7 -0
- package/plugin/home/workflows/agents.yaml +4 -1
- package/plugin/home/workflows/develop.yaml +4 -1
- package/plugin/home/workflows/engineering-light.yaml +7 -0
- package/plugin/home/workflows/engineering.yaml +7 -0
- package/plugin/workflows/run-pipeline.js +466 -464
- package/plugin/home/standards/spec-review.md +0 -61
- /package/plugin/home/{lenses → prompts}/conformance.md +0 -0
- /package/plugin/home/{lenses → prompts}/correctness.md +0 -0
package/dist/theway.js
CHANGED
|
@@ -9124,6 +9124,18 @@ function isFile(path2) {
|
|
|
9124
9124
|
return false;
|
|
9125
9125
|
}
|
|
9126
9126
|
}
|
|
9127
|
+
var NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
9128
|
+
var isNameList = (v) => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === "string" && NAME.test(n)) && new Set(v).size === v.length;
|
|
9129
|
+
var MODELS = ["opus", "sonnet", "haiku"];
|
|
9130
|
+
var escaped = (s) => s.replaceAll(`
|
|
9131
|
+
`, "\\n").replaceAll("\r", "\\r");
|
|
9132
|
+
function invalidName(kind, wanted) {
|
|
9133
|
+
if (wanted === undefined || NAME.test(wanted))
|
|
9134
|
+
return false;
|
|
9135
|
+
process.stderr.write(`theway: invalid ${kind} name '${escaped(wanted)}'
|
|
9136
|
+
`);
|
|
9137
|
+
return true;
|
|
9138
|
+
}
|
|
9127
9139
|
|
|
9128
9140
|
// src/core/list.ts
|
|
9129
9141
|
import { readdirSync, readFileSync as readFileSync2 } from "node:fs";
|
|
@@ -9172,8 +9184,7 @@ function resolveKey(override) {
|
|
|
9172
9184
|
const reason = projectReason(override);
|
|
9173
9185
|
if (reason === "")
|
|
9174
9186
|
return override;
|
|
9175
|
-
const shown = override
|
|
9176
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
9187
|
+
const shown = escaped(override);
|
|
9177
9188
|
process.stderr.write(`theway: invalid project '${shown}': ${reason}
|
|
9178
9189
|
`);
|
|
9179
9190
|
return null;
|
|
@@ -9296,8 +9307,7 @@ function invalidChangeId(changeId) {
|
|
|
9296
9307
|
const reason = changeIdReason(changeId);
|
|
9297
9308
|
if (reason === "")
|
|
9298
9309
|
return false;
|
|
9299
|
-
const shown = changeId
|
|
9300
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
9310
|
+
const shown = escaped(changeId);
|
|
9301
9311
|
process.stderr.write(`theway: invalid change id '${shown}': ${reason}
|
|
9302
9312
|
`);
|
|
9303
9313
|
return true;
|
|
@@ -9423,8 +9433,8 @@ function cmdAuthority() {
|
|
|
9423
9433
|
}
|
|
9424
9434
|
|
|
9425
9435
|
// src/core/config.ts
|
|
9426
|
-
import { readdirSync as
|
|
9427
|
-
import { join as
|
|
9436
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
9437
|
+
import { join as join6 } from "node:path";
|
|
9428
9438
|
|
|
9429
9439
|
// node_modules/yaml/dist/index.js
|
|
9430
9440
|
var composer = require_composer();
|
|
@@ -9489,8 +9499,20 @@ var SHIPPED_DIRS = [
|
|
|
9489
9499
|
{ dir: "standards", ext: ".md", shared: "standards" },
|
|
9490
9500
|
{ dir: "templates", ext: ".md" },
|
|
9491
9501
|
{ dir: "workflows", ext: ".yaml", shared: "workflows" },
|
|
9492
|
-
{ dir: "
|
|
9502
|
+
{ dir: "steps", ext: ".yaml", shared: "steps" },
|
|
9503
|
+
{ dir: "prompts", ext: ".md", shared: "prompts" },
|
|
9504
|
+
{ dir: "schemas", ext: ".json" }
|
|
9493
9505
|
];
|
|
9506
|
+
var MOVED = {
|
|
9507
|
+
"standards/tamm-framework.md": "prompts/tamm-framework.md",
|
|
9508
|
+
"standards/spec-investigation.md": "prompts/spec-investigation.md",
|
|
9509
|
+
"standards/spec-review.md": "prompts/spec-reviewer.md, grounding.md, implementability.md, verdicts.md, spec-triage.md and spec-fix.md",
|
|
9510
|
+
"templates/spec-template.md": "prompts/spec-template.md",
|
|
9511
|
+
"templates/fix-spec-template.md": "prompts/fix-spec-template.md",
|
|
9512
|
+
"templates/light-spec-template.md": "prompts/light-spec-template.md",
|
|
9513
|
+
"templates/tasks-template.md": "prompts/tasks-template.md"
|
|
9514
|
+
};
|
|
9515
|
+
var LENSES = "lenses";
|
|
9494
9516
|
var MANIFEST = ".shipped.json";
|
|
9495
9517
|
var sha256 = (data) => createHash("sha256").update(data).digest("hex");
|
|
9496
9518
|
function readManifest(home) {
|
|
@@ -9580,8 +9602,72 @@ function migrateDataStandards(src, home) {
|
|
|
9580
9602
|
process.stdout.write(`Left data/: it still holds files theway does not ship
|
|
9581
9603
|
`);
|
|
9582
9604
|
}
|
|
9605
|
+
function retireLenses(home, previous) {
|
|
9606
|
+
const dir = `${home}/${LENSES}`;
|
|
9607
|
+
if (!existsSync2(dir) || !statSync2(dir).isDirectory())
|
|
9608
|
+
return;
|
|
9609
|
+
const move = (name) => `theway no longer reads ${LENSES}/; move it to prompts/${name}`;
|
|
9610
|
+
const listed = new Set;
|
|
9611
|
+
for (const [rel, hash] of Object.entries(previous ?? {})) {
|
|
9612
|
+
if (!rel.startsWith(`${LENSES}/`))
|
|
9613
|
+
continue;
|
|
9614
|
+
const name = rel.slice(LENSES.length + 1);
|
|
9615
|
+
listed.add(name);
|
|
9616
|
+
const path2 = `${home}/${rel}`;
|
|
9617
|
+
if (!existsSync2(path2))
|
|
9618
|
+
continue;
|
|
9619
|
+
if (sha256(readFileSync5(path2)) === hash) {
|
|
9620
|
+
rmSync(path2);
|
|
9621
|
+
process.stdout.write(`Removed ${rel}: theway no longer ships it
|
|
9622
|
+
`);
|
|
9623
|
+
} else {
|
|
9624
|
+
process.stdout.write(`Kept your edited ${rel}: ${move(name)}
|
|
9625
|
+
`);
|
|
9626
|
+
}
|
|
9627
|
+
}
|
|
9628
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : 1)) {
|
|
9629
|
+
const name = entry.name;
|
|
9630
|
+
if (!entry.isFile() || !name.endsWith(".md") || listed.has(name))
|
|
9631
|
+
continue;
|
|
9632
|
+
if (name.endsWith(".default.md")) {
|
|
9633
|
+
rmSync(`${dir}/${name}`, { force: true });
|
|
9634
|
+
continue;
|
|
9635
|
+
}
|
|
9636
|
+
process.stdout.write(`Kept ${LENSES}/${name}: ${move(name)}
|
|
9637
|
+
`);
|
|
9638
|
+
}
|
|
9639
|
+
removeIfEmpty(dir);
|
|
9640
|
+
}
|
|
9641
|
+
function retireMoved(home) {
|
|
9642
|
+
const previous = readManifest(home);
|
|
9643
|
+
let changed = false;
|
|
9644
|
+
for (const [rel, now] of Object.entries(MOVED)) {
|
|
9645
|
+
const path2 = `${home}/${rel}`;
|
|
9646
|
+
if (existsSync2(path2) && statSync2(path2).isFile()) {
|
|
9647
|
+
const current = readFileSync5(path2);
|
|
9648
|
+
if (previous?.[rel] === sha256(current)) {
|
|
9649
|
+
rmSync(path2);
|
|
9650
|
+
process.stdout.write(`Removed ${rel}: theway no longer ships it
|
|
9651
|
+
`);
|
|
9652
|
+
} else {
|
|
9653
|
+
const bak = backupPath(home, rel, current);
|
|
9654
|
+
renameSync2(path2, `${home}/${bak}`);
|
|
9655
|
+
process.stdout.write(`Moved your edited ${rel} to ${bak}: theway now reads ${now}
|
|
9656
|
+
`);
|
|
9657
|
+
}
|
|
9658
|
+
}
|
|
9659
|
+
rmSync(`${home}/${rel.slice(0, -".md".length)}.default.md`, { force: true });
|
|
9660
|
+
if (previous !== undefined && rel in previous) {
|
|
9661
|
+
delete previous[rel];
|
|
9662
|
+
changed = true;
|
|
9663
|
+
}
|
|
9664
|
+
}
|
|
9665
|
+
if (changed && previous !== undefined)
|
|
9666
|
+
writeManifest(home, previous);
|
|
9667
|
+
}
|
|
9583
9668
|
function copyShipped(src, home) {
|
|
9584
9669
|
const previous = readManifest(home);
|
|
9670
|
+
retireLenses(home, previous);
|
|
9585
9671
|
const manifest = {};
|
|
9586
9672
|
for (const { dir, ext, shared } of SHIPPED_DIRS) {
|
|
9587
9673
|
const isShared = shared !== undefined;
|
|
@@ -9669,6 +9755,26 @@ function enableStandards(text, enabled) {
|
|
|
9669
9755
|
return lines.join(`
|
|
9670
9756
|
`);
|
|
9671
9757
|
}
|
|
9758
|
+
function reportRetiredKeys(file) {
|
|
9759
|
+
let doc;
|
|
9760
|
+
try {
|
|
9761
|
+
doc = $parse(readFileSync5(file, "utf-8"));
|
|
9762
|
+
} catch {
|
|
9763
|
+
return;
|
|
9764
|
+
}
|
|
9765
|
+
const isMap = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
9766
|
+
if (!isMap(doc))
|
|
9767
|
+
return;
|
|
9768
|
+
if (Object.hasOwn(doc, "engineering")) {
|
|
9769
|
+
process.stdout.write(`Your config.yaml still has engineering: theway ignores it and reads workflow.defaults.spec-review; remove it
|
|
9770
|
+
`);
|
|
9771
|
+
}
|
|
9772
|
+
const workflow = doc.workflow;
|
|
9773
|
+
if (isMap(workflow) && isMap(workflow.defaults) && Object.hasOwn(workflow.defaults, "agent")) {
|
|
9774
|
+
process.stdout.write(`Your config.yaml still has workflow.defaults.agent: the agent step is gone and theway ignores it; remove it
|
|
9775
|
+
`);
|
|
9776
|
+
}
|
|
9777
|
+
}
|
|
9672
9778
|
function init(src, home, enabled = []) {
|
|
9673
9779
|
try {
|
|
9674
9780
|
mkdirSync2(home, { recursive: true });
|
|
@@ -9676,12 +9782,14 @@ function init(src, home, enabled = []) {
|
|
|
9676
9782
|
if (existsSync2(`${home}/config.yaml`)) {
|
|
9677
9783
|
process.stdout.write(`Kept existing config.yaml (shipped defaults: config.default.yaml)
|
|
9678
9784
|
`);
|
|
9785
|
+
reportRetiredKeys(`${home}/config.yaml`);
|
|
9679
9786
|
} else if (enabled.length === 0) {
|
|
9680
9787
|
copyFileSync(`${src}/config.yaml`, `${home}/config.yaml`);
|
|
9681
9788
|
} else {
|
|
9682
9789
|
writeFileSync(`${home}/config.yaml`, enableStandards(readFileSync5(`${src}/config.yaml`, "utf-8"), enabled));
|
|
9683
9790
|
}
|
|
9684
9791
|
migrateDataStandards(src, home);
|
|
9792
|
+
retireMoved(home);
|
|
9685
9793
|
copyShipped(src, home);
|
|
9686
9794
|
} catch (e) {
|
|
9687
9795
|
process.stderr.write(`theway: ${e.message}
|
|
@@ -9693,30 +9801,116 @@ function init(src, home, enabled = []) {
|
|
|
9693
9801
|
return 0;
|
|
9694
9802
|
}
|
|
9695
9803
|
|
|
9804
|
+
// src/core/step-files.ts
|
|
9805
|
+
import { readdirSync as readdirSync3 } from "node:fs";
|
|
9806
|
+
import { join as join5 } from "node:path";
|
|
9807
|
+
var EXT = { workflows: ".yaml", steps: ".yaml", prompts: ".md" };
|
|
9808
|
+
var dirsOf = (home, key, kind) => [join5(projectDir(home, key), kind), join5(home, kind)];
|
|
9809
|
+
var searched = (home, key, kind) => dirsOf(home, key, kind).join(" or ");
|
|
9810
|
+
function fileOf(home, key, kind, name) {
|
|
9811
|
+
for (const dir of dirsOf(home, key, kind)) {
|
|
9812
|
+
const path2 = join5(dir, `${name}${EXT[kind]}`);
|
|
9813
|
+
if (isFile(path2))
|
|
9814
|
+
return path2;
|
|
9815
|
+
}
|
|
9816
|
+
return null;
|
|
9817
|
+
}
|
|
9818
|
+
function namesIn(dir, kind, rejected) {
|
|
9819
|
+
let entries;
|
|
9820
|
+
try {
|
|
9821
|
+
entries = readdirSync3(dir);
|
|
9822
|
+
} catch {
|
|
9823
|
+
return [];
|
|
9824
|
+
}
|
|
9825
|
+
const ext = EXT[kind];
|
|
9826
|
+
const out = [];
|
|
9827
|
+
for (const n of entries.sort()) {
|
|
9828
|
+
if (!n.endsWith(ext) || n.endsWith(`.default${ext}`) || !isFile(join5(dir, n)))
|
|
9829
|
+
continue;
|
|
9830
|
+
const stem = n.slice(0, -ext.length);
|
|
9831
|
+
if (NAME.test(stem))
|
|
9832
|
+
out.push(stem);
|
|
9833
|
+
else
|
|
9834
|
+
rejected?.(join5(dir, n));
|
|
9835
|
+
}
|
|
9836
|
+
return out.sort();
|
|
9837
|
+
}
|
|
9838
|
+
function knownSteps(home, key) {
|
|
9839
|
+
const [own, global] = dirsOf(home, key, "steps");
|
|
9840
|
+
return [...new Set([...namesIn(own, "steps"), ...namesIn(global, "steps")])].filter((n) => n !== "gate").sort();
|
|
9841
|
+
}
|
|
9842
|
+
function distance(a, b) {
|
|
9843
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
9844
|
+
for (let i = 1;i <= a.length; i++) {
|
|
9845
|
+
const cur = [i];
|
|
9846
|
+
for (let j = 1;j <= b.length; j++) {
|
|
9847
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
9848
|
+
}
|
|
9849
|
+
prev = cur;
|
|
9850
|
+
}
|
|
9851
|
+
return prev[b.length];
|
|
9852
|
+
}
|
|
9853
|
+
function suggest(wanted, known, noun) {
|
|
9854
|
+
let best = null;
|
|
9855
|
+
let bestDistance = 3;
|
|
9856
|
+
for (const k of known) {
|
|
9857
|
+
const d = distance(wanted, k);
|
|
9858
|
+
if (d < bestDistance) {
|
|
9859
|
+
best = k;
|
|
9860
|
+
bestDistance = d;
|
|
9861
|
+
}
|
|
9862
|
+
}
|
|
9863
|
+
if (best !== null)
|
|
9864
|
+
return `; did you mean '${best}'?`;
|
|
9865
|
+
return ` (${noun}: ${known.join(", ")})`;
|
|
9866
|
+
}
|
|
9867
|
+
function warnUnknownDefaults(home, key, loaded, warn) {
|
|
9868
|
+
const known = knownSteps(home, key);
|
|
9869
|
+
const unknown = new Set;
|
|
9870
|
+
for (const layer of loaded.defaults) {
|
|
9871
|
+
for (const step of layer.steps.keys()) {
|
|
9872
|
+
if (known.includes(step))
|
|
9873
|
+
continue;
|
|
9874
|
+
unknown.add(step);
|
|
9875
|
+
warn(layer.file, `workflow.defaults.${step}: no step '${step}' in ${searched(home, key, "steps")}${suggest(step, known, "steps")}`);
|
|
9876
|
+
}
|
|
9877
|
+
}
|
|
9878
|
+
return unknown;
|
|
9879
|
+
}
|
|
9880
|
+
|
|
9696
9881
|
// src/core/config.ts
|
|
9697
9882
|
var dict = () => Object.create(null);
|
|
9698
9883
|
var bool = (d) => ({ rule: "boolean", default: d });
|
|
9699
|
-
var model = (d) => ({ rule: "model", default: d });
|
|
9700
9884
|
var OPT_IN = ["core-principles.md", "sre.md", "web-development.md", "quality.md"];
|
|
9701
|
-
var CORE = ["interaction.md", "develop.md"
|
|
9885
|
+
var CORE = ["interaction.md", "develop.md"];
|
|
9702
9886
|
var CONVENTIONS = ["commits.md", "git-host.md"];
|
|
9703
|
-
|
|
9704
|
-
|
|
9887
|
+
function kindOf(v) {
|
|
9888
|
+
if (typeof v === "string")
|
|
9889
|
+
return "string";
|
|
9890
|
+
if (typeof v === "boolean")
|
|
9891
|
+
return "boolean";
|
|
9892
|
+
if (typeof v === "number" && Number.isInteger(v))
|
|
9893
|
+
return "integer";
|
|
9894
|
+
if (isNameList(v))
|
|
9895
|
+
return "list";
|
|
9896
|
+
return null;
|
|
9897
|
+
}
|
|
9898
|
+
var PARAM_VALUE_TEXT = "a string, an integer, a boolean or a non-empty list of names without duplicates";
|
|
9705
9899
|
var keyOf2 = (name) => name.slice(0, -".md".length).replaceAll("-", "_");
|
|
9706
9900
|
var OPT_IN_KEYS = OPT_IN.map(keyOf2);
|
|
9707
9901
|
var FIXED_KEYS = new Set([...CORE, ...CONVENTIONS].map(keyOf2));
|
|
9708
9902
|
function mdFiles(dir) {
|
|
9709
9903
|
let names;
|
|
9710
9904
|
try {
|
|
9711
|
-
names =
|
|
9905
|
+
names = readdirSync4(dir);
|
|
9712
9906
|
} catch {
|
|
9713
9907
|
return [];
|
|
9714
9908
|
}
|
|
9715
|
-
return names.filter((n) => n.endsWith(".md") && isFile(
|
|
9909
|
+
return names.filter((n) => n.endsWith(".md") && isFile(join6(dir, n))).sort();
|
|
9716
9910
|
}
|
|
9717
9911
|
function standardsOf(home, key) {
|
|
9718
|
-
const globalDir =
|
|
9719
|
-
const ownDir =
|
|
9912
|
+
const globalDir = join6(home, "standards");
|
|
9913
|
+
const ownDir = join6(projectDir(home, key), "standards");
|
|
9720
9914
|
const projectNames = mdFiles(ownDir).filter((n) => !CONVENTIONS.includes(n));
|
|
9721
9915
|
const shipped = readManifest(home) ?? {};
|
|
9722
9916
|
const out = [];
|
|
@@ -9726,13 +9920,13 @@ function standardsOf(home, key) {
|
|
|
9726
9920
|
const optIn = OPT_IN.includes(name);
|
|
9727
9921
|
if (!optIn && ((`standards/${name}` in shipped) || name.endsWith(".default.md")))
|
|
9728
9922
|
continue;
|
|
9729
|
-
const global = { path:
|
|
9923
|
+
const global = { path: join6(globalDir, name), key: keyOf2(name), optIn };
|
|
9730
9924
|
if (projectNames.includes(name))
|
|
9731
|
-
global.shadowedBy =
|
|
9925
|
+
global.shadowedBy = join6(ownDir, name);
|
|
9732
9926
|
out.push(global);
|
|
9733
9927
|
}
|
|
9734
9928
|
for (const name of projectNames)
|
|
9735
|
-
out.push({ path:
|
|
9929
|
+
out.push({ path: join6(ownDir, name), key: keyOf2(name), optIn: false });
|
|
9736
9930
|
return out;
|
|
9737
9931
|
}
|
|
9738
9932
|
function standardsSchema(standards) {
|
|
@@ -9746,46 +9940,17 @@ function standardsSchema(standards) {
|
|
|
9746
9940
|
}
|
|
9747
9941
|
var SCHEMA = {
|
|
9748
9942
|
standards: {},
|
|
9749
|
-
|
|
9750
|
-
review: {
|
|
9751
|
-
rounds: { rule: "non-negative", default: 1 },
|
|
9752
|
-
model: model("opus")
|
|
9753
|
-
}
|
|
9754
|
-
},
|
|
9755
|
-
workflow: {
|
|
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
|
-
}
|
|
9767
|
-
}
|
|
9943
|
+
workflow: { defaults: {} }
|
|
9768
9944
|
};
|
|
9945
|
+
var DEFAULTS_KEY = "workflow.defaults";
|
|
9769
9946
|
var RULE_TEXT = {
|
|
9770
|
-
boolean: "true or false"
|
|
9771
|
-
"non-negative": "a non-negative integer",
|
|
9772
|
-
positive: "a positive integer",
|
|
9773
|
-
model: "opus, sonnet or haiku",
|
|
9774
|
-
lenses: "a non-empty list of names without duplicates"
|
|
9947
|
+
boolean: "true or false"
|
|
9775
9948
|
};
|
|
9776
9949
|
var isLeaf = (node) => typeof node.rule === "string";
|
|
9777
9950
|
function valid(rule, v) {
|
|
9778
9951
|
switch (rule) {
|
|
9779
9952
|
case "boolean":
|
|
9780
9953
|
return typeof v === "boolean";
|
|
9781
|
-
case "non-negative":
|
|
9782
|
-
return typeof v === "number" && Number.isInteger(v) && v >= 0;
|
|
9783
|
-
case "positive":
|
|
9784
|
-
return typeof v === "number" && Number.isInteger(v) && v >= 1;
|
|
9785
|
-
case "model":
|
|
9786
|
-
return v === "opus" || v === "sonnet" || v === "haiku";
|
|
9787
|
-
case "lenses":
|
|
9788
|
-
return isLensList(v);
|
|
9789
9954
|
}
|
|
9790
9955
|
}
|
|
9791
9956
|
function defaults(schema) {
|
|
@@ -9800,7 +9965,30 @@ var warnLoud = (file, text) => {
|
|
|
9800
9965
|
`);
|
|
9801
9966
|
};
|
|
9802
9967
|
var warnQuiet = () => {};
|
|
9803
|
-
function
|
|
9968
|
+
function applyDefaults(file, value, into, layer, warn) {
|
|
9969
|
+
for (const [rawStep, params] of value) {
|
|
9970
|
+
const step = String(rawStep);
|
|
9971
|
+
if (!(params instanceof Map)) {
|
|
9972
|
+
warn(file, `${DEFAULTS_KEY}.${step} must be a map`);
|
|
9973
|
+
continue;
|
|
9974
|
+
}
|
|
9975
|
+
const kept = layer.steps.get(step) ?? new Map;
|
|
9976
|
+
layer.steps.set(step, kept);
|
|
9977
|
+
if (!Object.hasOwn(into, step))
|
|
9978
|
+
into[step] = dict();
|
|
9979
|
+
for (const [rawParam, v] of params) {
|
|
9980
|
+
const param = String(rawParam);
|
|
9981
|
+
if (kindOf(v) === null) {
|
|
9982
|
+
warn(file, `${DEFAULTS_KEY}.${step}.${param} must be ${PARAM_VALUE_TEXT}`);
|
|
9983
|
+
continue;
|
|
9984
|
+
}
|
|
9985
|
+
const copy = Array.isArray(v) ? [...v] : v;
|
|
9986
|
+
kept.set(param, copy);
|
|
9987
|
+
into[step][param] = Array.isArray(copy) ? [...copy] : copy;
|
|
9988
|
+
}
|
|
9989
|
+
}
|
|
9990
|
+
}
|
|
9991
|
+
function apply(file, schema, layer, into, prefix, warn, defaults2) {
|
|
9804
9992
|
for (const [rawKey, value] of layer) {
|
|
9805
9993
|
const key = String(rawKey);
|
|
9806
9994
|
const dotted = prefix === "" ? key : `${prefix}.${key}`;
|
|
@@ -9818,33 +10006,45 @@ function apply(file, schema, layer, into, prefix, warn) {
|
|
|
9818
10006
|
else
|
|
9819
10007
|
warn(file, `${dotted} must be ${RULE_TEXT[node.rule]}`);
|
|
9820
10008
|
} else if (value instanceof Map) {
|
|
9821
|
-
|
|
10009
|
+
if (dotted === DEFAULTS_KEY)
|
|
10010
|
+
applyDefaults(file, value, into[key], defaults2, warn);
|
|
10011
|
+
else
|
|
10012
|
+
apply(file, node, value, into[key], dotted, warn, defaults2);
|
|
9822
10013
|
} else {
|
|
9823
10014
|
warn(file, `${dotted} must be a map`);
|
|
9824
10015
|
}
|
|
9825
10016
|
}
|
|
9826
10017
|
}
|
|
10018
|
+
var QUOTE_HINT = '; quote ${…} references, for example model: "${model}"';
|
|
9827
10019
|
function load(home, file) {
|
|
10020
|
+
const parsed = parseFile(home, file);
|
|
10021
|
+
return "reason" in parsed ? { error: `theway: ${file}: ${parsed.reason}` } : parsed;
|
|
10022
|
+
}
|
|
10023
|
+
function parseFile(home, file, refs = false) {
|
|
9828
10024
|
let text;
|
|
9829
10025
|
try {
|
|
9830
|
-
text = readFileSync6(
|
|
10026
|
+
text = readFileSync6(join6(home, file), "utf-8");
|
|
9831
10027
|
} catch {
|
|
9832
|
-
return {
|
|
10028
|
+
return { reason: "cannot be read" };
|
|
9833
10029
|
}
|
|
9834
10030
|
try {
|
|
9835
10031
|
return { root: $parse(text, { mapAsMap: true, logLevel: "error" }) };
|
|
9836
10032
|
} catch (e) {
|
|
9837
10033
|
const first = (e instanceof Error ? e.message : String(e)).split(`
|
|
9838
10034
|
`)[0] ?? "";
|
|
9839
|
-
|
|
10035
|
+
const line = e.linePos?.[0]?.line;
|
|
10036
|
+
const failing = line === undefined ? "" : text.split(`
|
|
10037
|
+
`)[line - 1] ?? "";
|
|
10038
|
+
const hint = refs && failing.includes("${") ? QUOTE_HINT : "";
|
|
10039
|
+
return { reason: `invalid YAML: ${first.replace(/:$/, "")}${hint}` };
|
|
9840
10040
|
}
|
|
9841
10041
|
}
|
|
9842
10042
|
function effectiveConfig(home, key, loud) {
|
|
9843
10043
|
const files = [];
|
|
9844
|
-
const own =
|
|
9845
|
-
if (isFile(
|
|
10044
|
+
const own = join6("projects", key, "config.yaml");
|
|
10045
|
+
if (isFile(join6(home, "config.yaml")))
|
|
9846
10046
|
files.push("config.yaml");
|
|
9847
|
-
if (isFile(
|
|
10047
|
+
if (isFile(join6(home, own)))
|
|
9848
10048
|
files.push(own);
|
|
9849
10049
|
const roots = [];
|
|
9850
10050
|
for (const file of files) {
|
|
@@ -9857,22 +10057,25 @@ function effectiveConfig(home, key, loud) {
|
|
|
9857
10057
|
const schema = Object.assign(dict(), SCHEMA, { standards: standardsSchema(standards) });
|
|
9858
10058
|
const warn = loud ? warnLoud : warnQuiet;
|
|
9859
10059
|
const config = defaults(schema);
|
|
10060
|
+
const layers = [];
|
|
9860
10061
|
for (const [file, root] of roots) {
|
|
10062
|
+
const layer = { file, steps: new Map };
|
|
10063
|
+
layers.push(layer);
|
|
9861
10064
|
if (root === null)
|
|
9862
10065
|
continue;
|
|
9863
10066
|
if (root instanceof Map)
|
|
9864
|
-
apply(file, schema, root, config, "", warn);
|
|
10067
|
+
apply(file, schema, root, config, "", warn, layer);
|
|
9865
10068
|
else
|
|
9866
10069
|
warn(file, "not a map");
|
|
9867
10070
|
}
|
|
9868
|
-
return { config, standards };
|
|
10071
|
+
return { config, standards, defaults: layers };
|
|
9869
10072
|
}
|
|
9870
10073
|
function enabled(config, key) {
|
|
9871
10074
|
const all = config.standards;
|
|
9872
10075
|
return !Object.hasOwn(all, key) || all[key].enabled === true;
|
|
9873
10076
|
}
|
|
9874
10077
|
function loadConfig(home, key) {
|
|
9875
|
-
if (!isFile(
|
|
10078
|
+
if (!isFile(join6(home, "config.yaml"))) {
|
|
9876
10079
|
process.stderr.write(`theway: config.yaml not found in ${home}; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
|
|
9877
10080
|
`);
|
|
9878
10081
|
return null;
|
|
@@ -9889,15 +10092,19 @@ function cmdConfig(override) {
|
|
|
9889
10092
|
const key = resolveKey(override);
|
|
9890
10093
|
if (key === null)
|
|
9891
10094
|
return 1;
|
|
9892
|
-
const
|
|
10095
|
+
const home = thewayHome();
|
|
10096
|
+
const loaded = loadConfig(home, key);
|
|
9893
10097
|
if (loaded === null)
|
|
9894
10098
|
return 1;
|
|
10099
|
+
const defaults2 = loaded.config.workflow.defaults;
|
|
10100
|
+
for (const step of warnUnknownDefaults(home, key, loaded, warnLoud))
|
|
10101
|
+
delete defaults2[step];
|
|
9895
10102
|
process.stdout.write($stringify(loaded.config));
|
|
9896
10103
|
return 0;
|
|
9897
10104
|
}
|
|
9898
10105
|
|
|
9899
10106
|
// src/core/context.ts
|
|
9900
|
-
import { join as
|
|
10107
|
+
import { join as join7 } from "node:path";
|
|
9901
10108
|
|
|
9902
10109
|
// src/core/standards.ts
|
|
9903
10110
|
import { readFileSync as readFileSync7 } from "node:fs";
|
|
@@ -9954,8 +10161,7 @@ function phasesOf(path2) {
|
|
|
9954
10161
|
function checkPhase(phase) {
|
|
9955
10162
|
if (isPhase(phase))
|
|
9956
10163
|
return true;
|
|
9957
|
-
const shown = phase
|
|
9958
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
10164
|
+
const shown = escaped(phase);
|
|
9959
10165
|
process.stderr.write(`theway: invalid phase '${shown}': must be engineering, develop or document
|
|
9960
10166
|
`);
|
|
9961
10167
|
return false;
|
|
@@ -10005,7 +10211,7 @@ function cmdContext(phase, changeId, override) {
|
|
|
10005
10211
|
const dir = projectDir(home, key);
|
|
10006
10212
|
const doc = { home, project: key, project_dir: dir };
|
|
10007
10213
|
if (changeId !== undefined)
|
|
10008
|
-
doc.change_dir =
|
|
10214
|
+
doc.change_dir = join7(dir, "changes", changeId);
|
|
10009
10215
|
doc.standards = selectStandards(loaded, phase);
|
|
10010
10216
|
doc.config = loaded.config;
|
|
10011
10217
|
process.stdout.write($stringify(doc));
|
|
@@ -10013,8 +10219,8 @@ function cmdContext(phase, changeId, override) {
|
|
|
10013
10219
|
}
|
|
10014
10220
|
|
|
10015
10221
|
// src/core/next-id.ts
|
|
10016
|
-
import { readdirSync as
|
|
10017
|
-
import { join as
|
|
10222
|
+
import { readdirSync as readdirSync5 } from "node:fs";
|
|
10223
|
+
import { join as join8 } from "node:path";
|
|
10018
10224
|
|
|
10019
10225
|
// src/core/validate-id.ts
|
|
10020
10226
|
var VERB = /^(add|update|refactor|remove|fix)-/;
|
|
@@ -10065,8 +10271,7 @@ function seriesReason(id) {
|
|
|
10065
10271
|
function cmdValidateId(id, series) {
|
|
10066
10272
|
const reason = series ? seriesReason(id) : standaloneReason(id);
|
|
10067
10273
|
if (reason !== "") {
|
|
10068
|
-
const shown = id
|
|
10069
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
10274
|
+
const shown = escaped(id);
|
|
10070
10275
|
process.stderr.write(`invalid change id '${shown}': ${reason}
|
|
10071
10276
|
`);
|
|
10072
10277
|
return 1;
|
|
@@ -10077,7 +10282,7 @@ function cmdValidateId(id, series) {
|
|
|
10077
10282
|
// src/core/next-id.ts
|
|
10078
10283
|
function dirs(dir) {
|
|
10079
10284
|
try {
|
|
10080
|
-
return
|
|
10285
|
+
return readdirSync5(dir).filter((n) => isDir(join8(dir, n)));
|
|
10081
10286
|
} catch {
|
|
10082
10287
|
return [];
|
|
10083
10288
|
}
|
|
@@ -10098,19 +10303,18 @@ function cmdNextId(seriesId, count, override) {
|
|
|
10098
10303
|
const rest = seriesId.replace(/-[0-9]{2}$/, "");
|
|
10099
10304
|
const reason = seriesIdReason(rest);
|
|
10100
10305
|
if (reason !== "") {
|
|
10101
|
-
const shown = rest
|
|
10102
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
10306
|
+
const shown = escaped(rest);
|
|
10103
10307
|
process.stderr.write(`invalid change id '${shown}': ${reason}
|
|
10104
10308
|
`);
|
|
10105
10309
|
return 1;
|
|
10106
10310
|
}
|
|
10107
|
-
const changes =
|
|
10311
|
+
const changes = join8(projectDir(thewayHome(), key), "changes");
|
|
10108
10312
|
const active = new RegExp(`^${rest}-([0-9]{2})$`);
|
|
10109
10313
|
const archived = new RegExp(`^[0-9]{4}-[0-9]{2}-[0-9]{2}-${rest}-([0-9]{2})$`);
|
|
10110
10314
|
let max = 0;
|
|
10111
10315
|
for (const [dir, pattern] of [
|
|
10112
10316
|
[changes, active],
|
|
10113
|
-
[
|
|
10317
|
+
[join8(changes, "archive"), archived]
|
|
10114
10318
|
]) {
|
|
10115
10319
|
for (const name of dirs(dir)) {
|
|
10116
10320
|
const m = pattern.exec(name);
|
|
@@ -10132,161 +10336,741 @@ function cmdNextId(seriesId, count, override) {
|
|
|
10132
10336
|
}
|
|
10133
10337
|
|
|
10134
10338
|
// src/core/workflow.ts
|
|
10135
|
-
import {
|
|
10136
|
-
|
|
10137
|
-
var
|
|
10138
|
-
var
|
|
10139
|
-
|
|
10140
|
-
|
|
10339
|
+
import { basename as basename2, join as join9, relative } from "node:path";
|
|
10340
|
+
var WORKFLOW_VERSION = "theway.workflow/v1";
|
|
10341
|
+
var STEP_VERSION = "theway.step/v1";
|
|
10342
|
+
var WORKFLOW_KEYS = ["version", "input", "default", "agents", "steps"];
|
|
10343
|
+
var STEP_KEYS = ["version", "description", "params", "do"];
|
|
10344
|
+
var TYPES = ["work", "findings", "verdicts", "resolutions", "pr", "ci", "diagnosis", "scaffold", "edits"];
|
|
10345
|
+
var CONDITIONS = [
|
|
10346
|
+
"findings",
|
|
10347
|
+
"no-findings",
|
|
10348
|
+
"confirmed",
|
|
10349
|
+
"no-confirmed",
|
|
10350
|
+
"green",
|
|
10351
|
+
"red",
|
|
10352
|
+
"fixable",
|
|
10353
|
+
"more",
|
|
10354
|
+
"decision",
|
|
10355
|
+
"no-decision"
|
|
10356
|
+
];
|
|
10357
|
+
var ACCESS = ["read", "commit", "push", "spec"];
|
|
10358
|
+
var INPUTS = ["changes", "request"];
|
|
10359
|
+
var EXHAUSTED = ["continue", "fail"];
|
|
10360
|
+
var CONSTRUCTS = ["agent", "foreach", "loop", "when"];
|
|
10361
|
+
var PRODUCER = {
|
|
10362
|
+
findings: "findings",
|
|
10363
|
+
"no-findings": "findings",
|
|
10364
|
+
confirmed: "verdicts",
|
|
10365
|
+
"no-confirmed": "verdicts",
|
|
10366
|
+
green: "ci",
|
|
10367
|
+
red: "ci",
|
|
10368
|
+
fixable: "diagnosis",
|
|
10369
|
+
decision: "verdicts",
|
|
10370
|
+
"no-decision": "verdicts"
|
|
10141
10371
|
};
|
|
10142
|
-
var
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10372
|
+
var READS = {
|
|
10373
|
+
verdicts: ["findings"],
|
|
10374
|
+
resolutions: ["verdicts", "work"],
|
|
10375
|
+
diagnosis: ["ci"],
|
|
10376
|
+
edits: ["verdicts"]
|
|
10147
10377
|
};
|
|
10148
|
-
var
|
|
10149
|
-
var bool2 = { test: (v) => typeof v === "boolean", text: "true or false" };
|
|
10378
|
+
var SPEC_TYPES = ["scaffold", "edits"];
|
|
10150
10379
|
var FIELDS = {
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
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
|
-
]
|
|
10380
|
+
agent: ["prompt", "returns", "model", "access"],
|
|
10381
|
+
foreach: ["parallel", "do"],
|
|
10382
|
+
loop: ["max", "until", "exhausted", "do"],
|
|
10383
|
+
when: ["do", "fail", "block"]
|
|
10168
10384
|
};
|
|
10169
|
-
var
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10385
|
+
var RULE = {
|
|
10386
|
+
returns: `one of ${TYPES.join(", ")}`,
|
|
10387
|
+
condition: `one of ${CONDITIONS.join(", ")}`,
|
|
10388
|
+
access: "read, commit, push or spec",
|
|
10389
|
+
exhausted: "continue or fail",
|
|
10390
|
+
model: `one of ${MODELS.join(", ")}`,
|
|
10391
|
+
positive: "a positive integer",
|
|
10392
|
+
bool: "true or false",
|
|
10393
|
+
fail: "true",
|
|
10394
|
+
block: "true or a non-empty string",
|
|
10395
|
+
names: "a non-empty list of names",
|
|
10396
|
+
prompt: "a name or a non-empty list of names",
|
|
10397
|
+
nonEmpty: "a non-empty string",
|
|
10398
|
+
nodes: "a non-empty list"
|
|
10399
|
+
};
|
|
10400
|
+
var PARAM = /^[a-z][a-z0-9_]*$/;
|
|
10401
|
+
var RESERVED = ["agents", "item"];
|
|
10402
|
+
var REF = /^\$\{([^}]*)\}$/;
|
|
10403
|
+
|
|
10404
|
+
class Fail {
|
|
10405
|
+
file;
|
|
10406
|
+
reason;
|
|
10407
|
+
constructor(file, reason) {
|
|
10408
|
+
this.file = file;
|
|
10409
|
+
this.reason = reason;
|
|
10410
|
+
}
|
|
10411
|
+
get line() {
|
|
10412
|
+
return `theway: ${this.file}: ${this.reason}`;
|
|
10413
|
+
}
|
|
10414
|
+
}
|
|
10415
|
+
var failIn = (file) => (reason) => {
|
|
10416
|
+
throw new Fail(file, reason);
|
|
10417
|
+
};
|
|
10418
|
+
function rootOf(home, file, refs = false) {
|
|
10419
|
+
const parsed = parseFile(home, file, refs);
|
|
10420
|
+
if ("reason" in parsed)
|
|
10421
|
+
throw new Fail(file, parsed.reason);
|
|
10422
|
+
return parsed.root;
|
|
10423
|
+
}
|
|
10424
|
+
var KIND_TEXT = {
|
|
10425
|
+
string: "a string",
|
|
10426
|
+
integer: "an integer",
|
|
10427
|
+
boolean: "true or false",
|
|
10428
|
+
list: "a non-empty list of names without duplicates"
|
|
10429
|
+
};
|
|
10430
|
+
var rel = (d, path2) => relative(d.home, path2);
|
|
10431
|
+
var isMap = (v) => v instanceof Map;
|
|
10432
|
+
function readStep(d, name, path2, full) {
|
|
10433
|
+
const file = rel(d, path2);
|
|
10434
|
+
const fail = failIn(file);
|
|
10435
|
+
const root = rootOf(d.home, file, true);
|
|
10436
|
+
if (!isMap(root))
|
|
10189
10437
|
return fail("not a map");
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
if (
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10222
|
-
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
if (
|
|
10227
|
-
|
|
10228
|
-
}
|
|
10229
|
-
}
|
|
10230
|
-
}
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10438
|
+
if (!root.has("version"))
|
|
10439
|
+
fail(`version is required (${STEP_VERSION})`);
|
|
10440
|
+
if (root.get("version") !== STEP_VERSION)
|
|
10441
|
+
fail(`version must be ${STEP_VERSION}`);
|
|
10442
|
+
if (full) {
|
|
10443
|
+
for (const k of root.keys()) {
|
|
10444
|
+
if (!STEP_KEYS.includes(k))
|
|
10445
|
+
fail(`unknown key ${String(k)}`);
|
|
10446
|
+
}
|
|
10447
|
+
}
|
|
10448
|
+
const params = new Map;
|
|
10449
|
+
for (const k of root.keys()) {
|
|
10450
|
+
if (k === "description") {
|
|
10451
|
+
const v = root.get(k);
|
|
10452
|
+
if (typeof v !== "string" || v.trim() === "")
|
|
10453
|
+
fail("description must be a non-empty string");
|
|
10454
|
+
if (v.includes("${"))
|
|
10455
|
+
fail("description does not take a reference");
|
|
10456
|
+
} else if (k === "params") {
|
|
10457
|
+
const v = root.get(k);
|
|
10458
|
+
if (!isMap(v))
|
|
10459
|
+
return fail("params must be a map");
|
|
10460
|
+
for (const [rawP, def] of v) {
|
|
10461
|
+
const p = String(rawP);
|
|
10462
|
+
if (RESERVED.includes(p))
|
|
10463
|
+
fail(`params.${p}: agents and item are reserved`);
|
|
10464
|
+
if (!PARAM.test(p))
|
|
10465
|
+
fail(`params.${p} must be a param name (lowercase letters, digits and _, starting with a letter)`);
|
|
10466
|
+
if (!isMap(def) || def.size !== 2 || !def.has("default") || !def.has("description"))
|
|
10467
|
+
fail(`params.${p} must be {default, description}`);
|
|
10468
|
+
const dv = def.get("default");
|
|
10469
|
+
const desc = def.get("description");
|
|
10470
|
+
if (kindOf(dv) === null)
|
|
10471
|
+
fail(`params.${p}.default must be ${PARAM_VALUE_TEXT}`);
|
|
10472
|
+
if (typeof dv === "string" && dv.includes("${"))
|
|
10473
|
+
fail(`params.${p}.default does not take a reference`);
|
|
10474
|
+
if (typeof desc !== "string" || desc.trim() === "")
|
|
10475
|
+
fail(`params.${p}.description must be a non-empty string`);
|
|
10476
|
+
params.set(p, { default: dv, description: desc });
|
|
10477
|
+
}
|
|
10478
|
+
} else if (k === "do" && full) {
|
|
10479
|
+
const v = root.get(k);
|
|
10480
|
+
if (!Array.isArray(v) || v.length === 0)
|
|
10481
|
+
fail("do must be a non-empty list");
|
|
10482
|
+
}
|
|
10483
|
+
}
|
|
10484
|
+
if (!root.has("description"))
|
|
10485
|
+
fail("description must be a non-empty string");
|
|
10486
|
+
if (full && !root.has("do"))
|
|
10487
|
+
fail("do must be a non-empty list");
|
|
10488
|
+
return { name, path: path2, rel: file, description: root.get("description"), params, root };
|
|
10489
|
+
}
|
|
10490
|
+
function modelParams(step) {
|
|
10491
|
+
const out = new Set;
|
|
10492
|
+
if (step.params.has("model"))
|
|
10493
|
+
out.add("model");
|
|
10494
|
+
const walk = (v) => {
|
|
10495
|
+
if (Array.isArray(v))
|
|
10496
|
+
v.forEach(walk);
|
|
10497
|
+
else if (isMap(v)) {
|
|
10498
|
+
const agent = v.get("agent");
|
|
10499
|
+
if (isMap(agent)) {
|
|
10500
|
+
const m = REF.exec(String(agent.get("model") ?? ""));
|
|
10501
|
+
if (m !== null && step.params.has(m[1]))
|
|
10502
|
+
out.add(m[1]);
|
|
10503
|
+
}
|
|
10504
|
+
for (const child of v.values())
|
|
10505
|
+
walk(child);
|
|
10249
10506
|
}
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10507
|
+
};
|
|
10508
|
+
walk(step.root.get("do"));
|
|
10509
|
+
return out;
|
|
10510
|
+
}
|
|
10511
|
+
function paramSuffix(step, wanted) {
|
|
10512
|
+
const known = [...step.params.keys()];
|
|
10513
|
+
if (known.length === 0)
|
|
10514
|
+
return `; ${step.name} declares no params`;
|
|
10515
|
+
return suggest(wanted, known, "params");
|
|
10516
|
+
}
|
|
10517
|
+
function effectiveParams(d, step, given, entryOrigin, inline) {
|
|
10518
|
+
const models = inline ? modelParams(step) : new Set;
|
|
10519
|
+
const valid2 = [];
|
|
10520
|
+
for (const layer of d.loaded.defaults) {
|
|
10521
|
+
const values = new Map;
|
|
10522
|
+
valid2.push(values);
|
|
10523
|
+
for (const [p, v] of layer.steps.get(step.name) ?? []) {
|
|
10524
|
+
const def = step.params.get(p);
|
|
10525
|
+
if (def === undefined) {
|
|
10526
|
+
d.warn(layer.file, `workflow.defaults.${step.name}.${p} is not a param of ${step.name}${paramSuffix(step, p)}`);
|
|
10527
|
+
} else if (!models.has(p)) {
|
|
10528
|
+
const kind = kindOf(def.default);
|
|
10529
|
+
if (kindOf(v) !== kind)
|
|
10530
|
+
d.warn(layer.file, `workflow.defaults.${step.name}.${p} must be ${KIND_TEXT[kind]}`);
|
|
10531
|
+
else
|
|
10532
|
+
values.set(p, { value: v, file: layer.file });
|
|
10258
10533
|
}
|
|
10259
|
-
step.lenses = found;
|
|
10260
10534
|
}
|
|
10261
|
-
steps.push(step);
|
|
10262
10535
|
}
|
|
10263
|
-
|
|
10536
|
+
const out = new Map;
|
|
10537
|
+
for (const [p, def] of step.params) {
|
|
10538
|
+
if (given.has(p)) {
|
|
10539
|
+
out.set(p, { value: given.get(p), from: entryOrigin, origin: entryOrigin });
|
|
10540
|
+
continue;
|
|
10541
|
+
}
|
|
10542
|
+
const layer = valid2.findLast((l) => l.has(p));
|
|
10543
|
+
if (layer !== undefined) {
|
|
10544
|
+
const { value, file } = layer.get(p);
|
|
10545
|
+
out.set(p, { value, from: file, origin: file });
|
|
10546
|
+
} else {
|
|
10547
|
+
out.set(p, { value: def.default, from: step.rel, origin: `params.${p}` });
|
|
10548
|
+
}
|
|
10549
|
+
}
|
|
10550
|
+
return out;
|
|
10264
10551
|
}
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10552
|
+
var agentPaths = new WeakMap;
|
|
10553
|
+
function fail(ctx, reason, origin) {
|
|
10554
|
+
return failIn(ctx.step.rel)(`${reason}${origin === undefined ? "" : ` (value from ${origin})`}`);
|
|
10555
|
+
}
|
|
10556
|
+
var visible = (ctx) => ctx.loop === undefined ? ctx.producers.outer : ctx.loop.types;
|
|
10557
|
+
function produced(ctx, type) {
|
|
10558
|
+
visible(ctx).add(type);
|
|
10559
|
+
}
|
|
10560
|
+
function needs(ctx, path2, what, type, loopMessage) {
|
|
10561
|
+
if (visible(ctx).has(type))
|
|
10562
|
+
return;
|
|
10563
|
+
if (loopMessage && ctx.loop === undefined) {
|
|
10564
|
+
const loop = ctx.producers.ended.find((l) => l.types.has(type));
|
|
10565
|
+
if (loop !== undefined)
|
|
10566
|
+
fail(ctx, `${path2}: ${what} is set only inside the loop at ${loop.path}; use exhausted: fail`);
|
|
10567
|
+
}
|
|
10568
|
+
fail(ctx, `${path2}: ${what} needs an earlier ${type} agent in this step`);
|
|
10569
|
+
}
|
|
10570
|
+
function noRef(ctx, path2, v) {
|
|
10571
|
+
const has = (x) => typeof x === "string" && x.includes("${");
|
|
10572
|
+
if (has(v) || Array.isArray(v) && v.some(has))
|
|
10573
|
+
fail(ctx, `${path2} does not take a reference`);
|
|
10574
|
+
}
|
|
10575
|
+
function subst(ctx, path2, v) {
|
|
10576
|
+
if (typeof v !== "string" || !v.includes("${"))
|
|
10577
|
+
return { value: v };
|
|
10578
|
+
const m = REF.exec(v);
|
|
10579
|
+
if (m === null)
|
|
10580
|
+
fail(ctx, `${path2}: \${…} must be the whole value; there is no string templating`);
|
|
10581
|
+
const name = m[1];
|
|
10582
|
+
if (name === "item") {
|
|
10583
|
+
if (ctx.item === undefined)
|
|
10584
|
+
fail(ctx, `${path2}: \${item} outside foreach`);
|
|
10585
|
+
return { value: ctx.item?.value, origin: ctx.item?.origin };
|
|
10586
|
+
}
|
|
10587
|
+
const p = ctx.params.get(name);
|
|
10588
|
+
if (p === undefined)
|
|
10589
|
+
fail(ctx, `${path2}: \${${name}} is not a param of ${ctx.step.name}${paramSuffix(ctx.step, name)}`);
|
|
10590
|
+
return { value: Array.isArray(p?.value) ? [...p?.value] : p?.value, origin: p?.origin };
|
|
10591
|
+
}
|
|
10592
|
+
function conditions(ctx, path2, v) {
|
|
10593
|
+
noRef(ctx, path2, v);
|
|
10594
|
+
const list = Array.isArray(v) ? v : [v];
|
|
10595
|
+
if (list.length === 0 || !list.every((c) => CONDITIONS.includes(c)))
|
|
10596
|
+
fail(ctx, `${path2} must be ${RULE.condition}`);
|
|
10597
|
+
return list;
|
|
10598
|
+
}
|
|
10599
|
+
function nodes(ctx, path2, v) {
|
|
10600
|
+
if (!Array.isArray(v) || v.length === 0)
|
|
10601
|
+
fail(ctx, `${path2} must be ${RULE.nodes}`);
|
|
10602
|
+
return v.flatMap((n, i) => node(ctx, `${path2}[${i}]`, n));
|
|
10603
|
+
}
|
|
10604
|
+
function siblings(ctx, path2, raw, construct) {
|
|
10605
|
+
for (const k of raw.keys()) {
|
|
10606
|
+
if (k !== construct && !FIELDS[construct].includes(k)) {
|
|
10607
|
+
fail(ctx, `${path2}.${construct}.${String(k)} is not a field of ${construct} (fields: ${FIELDS[construct].join(", ")})`);
|
|
10608
|
+
}
|
|
10609
|
+
}
|
|
10610
|
+
}
|
|
10611
|
+
function fieldMap(ctx, path2, raw, construct) {
|
|
10612
|
+
for (const k of raw.keys()) {
|
|
10613
|
+
if (k !== construct)
|
|
10614
|
+
fail(ctx, `${path2}.${String(k)} is not a field of ${construct} (fields: ${FIELDS[construct].join(", ")})`);
|
|
10615
|
+
}
|
|
10616
|
+
const v = raw.get(construct);
|
|
10617
|
+
if (v === null)
|
|
10618
|
+
return new Map;
|
|
10619
|
+
if (!isMap(v))
|
|
10620
|
+
fail(ctx, `${path2}.${construct} must be a map`);
|
|
10621
|
+
const map = v;
|
|
10622
|
+
for (const k of map.keys()) {
|
|
10623
|
+
if (!FIELDS[construct].includes(k)) {
|
|
10624
|
+
fail(ctx, `${path2}.${construct}.${String(k)} is not a field of ${construct} (fields: ${FIELDS[construct].join(", ")})`);
|
|
10625
|
+
}
|
|
10626
|
+
}
|
|
10627
|
+
return map;
|
|
10628
|
+
}
|
|
10629
|
+
function node(ctx, path2, raw) {
|
|
10630
|
+
const exactly = `${path2} must have exactly one of ${CONSTRUCTS.join(", ")}`;
|
|
10631
|
+
if (!isMap(raw))
|
|
10632
|
+
fail(ctx, exactly);
|
|
10633
|
+
const map = raw;
|
|
10634
|
+
if (map.has("gate"))
|
|
10635
|
+
fail(ctx, `${path2}: gate is a workflow entry; a step cannot ask the user`);
|
|
10636
|
+
if (map.has("parallel") && !map.has("foreach"))
|
|
10637
|
+
fail(ctx, `${path2}: parallel is output only; write foreach: … with parallel: true`);
|
|
10638
|
+
const found = CONSTRUCTS.filter((c) => map.has(c));
|
|
10639
|
+
if (found.length !== 1)
|
|
10640
|
+
fail(ctx, exactly);
|
|
10641
|
+
switch (found[0]) {
|
|
10642
|
+
case "agent":
|
|
10643
|
+
return [{ agent: agent(ctx, `${path2}.agent`, fieldMap(ctx, path2, map, "agent")) }];
|
|
10644
|
+
case "foreach":
|
|
10645
|
+
return foreach(ctx, `${path2}.foreach`, map);
|
|
10646
|
+
case "loop":
|
|
10647
|
+
return [loop(ctx, `${path2}.loop`, fieldMap(ctx, path2, map, "loop"))];
|
|
10648
|
+
default:
|
|
10649
|
+
return [when(ctx, `${path2}.when`, map)];
|
|
10650
|
+
}
|
|
10651
|
+
}
|
|
10652
|
+
function agent(ctx, path2, map) {
|
|
10653
|
+
let prompt = { names: [ctx.step.name] };
|
|
10654
|
+
let returns;
|
|
10655
|
+
let model;
|
|
10656
|
+
let access;
|
|
10657
|
+
for (const [k, v] of map) {
|
|
10658
|
+
const at = `${path2}.${String(k)}`;
|
|
10659
|
+
if (k === "prompt") {
|
|
10660
|
+
let origin;
|
|
10661
|
+
let value;
|
|
10662
|
+
if (Array.isArray(v)) {
|
|
10663
|
+
value = v.map((x, i) => {
|
|
10664
|
+
const s = subst(ctx, `${at}[${i}]`, x);
|
|
10665
|
+
origin ??= s.origin;
|
|
10666
|
+
return s.value;
|
|
10667
|
+
});
|
|
10668
|
+
} else {
|
|
10669
|
+
const s = subst(ctx, at, v);
|
|
10670
|
+
value = s.value;
|
|
10671
|
+
origin = s.origin;
|
|
10672
|
+
}
|
|
10673
|
+
const list = Array.isArray(value) ? value : [value];
|
|
10674
|
+
if (list.length === 0 || !list.every((n) => typeof n === "string" && NAME.test(n)))
|
|
10675
|
+
fail(ctx, `${at} must be ${RULE.prompt}`, origin);
|
|
10676
|
+
prompt = { names: list, origin };
|
|
10677
|
+
} else if (k === "returns") {
|
|
10678
|
+
noRef(ctx, at, v);
|
|
10679
|
+
if (!TYPES.includes(v))
|
|
10680
|
+
fail(ctx, `${at} must be ${RULE.returns}`);
|
|
10681
|
+
returns = v;
|
|
10682
|
+
} else if (k === "model") {
|
|
10683
|
+
const s = subst(ctx, at, v);
|
|
10684
|
+
if (!MODELS.includes(s.value))
|
|
10685
|
+
fail(ctx, `${at} must be ${RULE.model}`, s.origin);
|
|
10686
|
+
model = { value: s.value, origin: s.origin };
|
|
10687
|
+
} else {
|
|
10688
|
+
noRef(ctx, at, v);
|
|
10689
|
+
if (!ACCESS.includes(v))
|
|
10690
|
+
fail(ctx, `${at} must be ${RULE.access}`);
|
|
10691
|
+
access = v;
|
|
10692
|
+
}
|
|
10693
|
+
}
|
|
10694
|
+
if (returns === undefined)
|
|
10695
|
+
return fail(ctx, `${path2}.returns is required (${RULE.returns})`);
|
|
10696
|
+
const own = ctx.item?.origin;
|
|
10697
|
+
access ??= returns === "work" ? "commit" : returns === "pr" ? "push" : SPEC_TYPES.includes(returns) ? "spec" : "read";
|
|
10698
|
+
if (returns === "work" && access !== "commit" && access !== "push")
|
|
10699
|
+
fail(ctx, `${path2}.access must be commit or push for returns: work`, own);
|
|
10700
|
+
if (returns === "pr" && access !== "push")
|
|
10701
|
+
fail(ctx, `${path2}.access must be push for returns: pr`, own);
|
|
10702
|
+
if (SPEC_TYPES.includes(returns) && access !== "spec")
|
|
10703
|
+
fail(ctx, `${path2}.access must be spec for returns: ${returns}`, own);
|
|
10704
|
+
const paths = [];
|
|
10705
|
+
for (const n of prompt.names) {
|
|
10706
|
+
const p = fileOf(ctx.d.home, ctx.d.key, "prompts", n);
|
|
10707
|
+
if (p === null)
|
|
10708
|
+
fail(ctx, `${path2}.prompt: prompt '${n}' has no file in ${searched(ctx.d.home, ctx.d.key, "prompts")}`, prompt.origin ?? own);
|
|
10709
|
+
paths.push(p);
|
|
10710
|
+
}
|
|
10711
|
+
for (const type of READS[returns] ?? [])
|
|
10712
|
+
needs(ctx, path2, `returns ${returns}`, type, false);
|
|
10713
|
+
if (returns === "work" && ctx.loop !== undefined && !ctx.conds.includes("more")) {
|
|
10714
|
+
ctx.loop.unguarded.push({ path: path2, conds: ctx.conds });
|
|
10715
|
+
}
|
|
10716
|
+
produced(ctx, returns);
|
|
10717
|
+
const out = { name: prompt.names[prompt.names.length - 1], label: "", prompt: paths, returns, access };
|
|
10718
|
+
agentPaths.set(out, path2);
|
|
10719
|
+
if (!ctx.inline) {
|
|
10720
|
+
const fallback = ctx.params.get("model");
|
|
10721
|
+
if (model === undefined && fallback !== undefined && !MODELS.includes(fallback.value)) {
|
|
10722
|
+
fail(ctx, `${path2}.model must be ${RULE.model}`, fallback.origin);
|
|
10723
|
+
}
|
|
10724
|
+
out.model = model?.value ?? (fallback === undefined ? "sonnet" : fallback.value);
|
|
10271
10725
|
}
|
|
10726
|
+
return out;
|
|
10727
|
+
}
|
|
10728
|
+
function foreach(ctx, path2, map) {
|
|
10729
|
+
siblings(ctx, path2.slice(0, -".foreach".length), map, "foreach");
|
|
10730
|
+
if (ctx.inForeach)
|
|
10731
|
+
fail(ctx, `${path2}: no foreach inside a foreach`);
|
|
10732
|
+
const s = subst(ctx, path2, map.get("foreach"));
|
|
10733
|
+
if (!Array.isArray(s.value) || s.value.length === 0 || !s.value.every((n) => typeof n === "string" && NAME.test(n))) {
|
|
10734
|
+
fail(ctx, `${path2} must be ${RULE.names}`, s.origin);
|
|
10735
|
+
}
|
|
10736
|
+
const items = s.value;
|
|
10737
|
+
let parallel = false;
|
|
10738
|
+
if (map.has("parallel")) {
|
|
10739
|
+
const v = map.get("parallel");
|
|
10740
|
+
noRef(ctx, `${path2}.parallel`, v);
|
|
10741
|
+
if (typeof v !== "boolean")
|
|
10742
|
+
fail(ctx, `${path2}.parallel must be ${RULE.bool}`);
|
|
10743
|
+
parallel = v;
|
|
10744
|
+
}
|
|
10745
|
+
if (!map.has("do"))
|
|
10746
|
+
fail(ctx, `${path2}.do is required (${RULE.nodes})`);
|
|
10747
|
+
const group = new Set;
|
|
10748
|
+
const copies = [];
|
|
10749
|
+
for (const item of items) {
|
|
10750
|
+
const before = new Set(visible(ctx));
|
|
10751
|
+
const inner = { ...ctx, item: { value: item, origin: s.origin }, inForeach: true };
|
|
10752
|
+
const out = nodes(inner, `${path2}[item=${item}].do`, map.get("do"));
|
|
10753
|
+
if (parallel) {
|
|
10754
|
+
if (!out.every((n) => ("agent" in n) && n.agent.access === "read"))
|
|
10755
|
+
fail(ctx, `${path2}: a parallel foreach may hold only agents with access: read`, s.origin);
|
|
10756
|
+
for (const t of visible(ctx))
|
|
10757
|
+
if (!before.has(t))
|
|
10758
|
+
group.add(t);
|
|
10759
|
+
visible(ctx).clear();
|
|
10760
|
+
for (const t of before)
|
|
10761
|
+
visible(ctx).add(t);
|
|
10762
|
+
}
|
|
10763
|
+
copies.push(...out);
|
|
10764
|
+
}
|
|
10765
|
+
if (!parallel)
|
|
10766
|
+
return copies;
|
|
10767
|
+
for (const t of group)
|
|
10768
|
+
produced(ctx, t);
|
|
10769
|
+
return copies.length === 0 ? [] : [{ parallel: copies }];
|
|
10770
|
+
}
|
|
10771
|
+
function loop(ctx, path2, map) {
|
|
10772
|
+
if (ctx.loop !== undefined)
|
|
10773
|
+
fail(ctx, `${path2}: no loop inside a loop`);
|
|
10774
|
+
let max;
|
|
10775
|
+
let until;
|
|
10776
|
+
let exhausted;
|
|
10777
|
+
for (const [k, v] of map) {
|
|
10778
|
+
const at = `${path2}.${String(k)}`;
|
|
10779
|
+
if (k === "max") {
|
|
10780
|
+
const s = subst(ctx, at, v);
|
|
10781
|
+
if (typeof s.value !== "number" || !Number.isInteger(s.value) || s.value < 1)
|
|
10782
|
+
fail(ctx, `${at} must be ${RULE.positive}`, s.origin);
|
|
10783
|
+
max = s.value;
|
|
10784
|
+
} else if (k === "until") {
|
|
10785
|
+
until = conditions(ctx, at, v);
|
|
10786
|
+
} else if (k === "exhausted") {
|
|
10787
|
+
noRef(ctx, at, v);
|
|
10788
|
+
if (!EXHAUSTED.includes(v))
|
|
10789
|
+
fail(ctx, `${at} must be ${RULE.exhausted}`);
|
|
10790
|
+
exhausted = v;
|
|
10791
|
+
}
|
|
10792
|
+
}
|
|
10793
|
+
if (max === undefined)
|
|
10794
|
+
fail(ctx, `${path2}.max is required (${RULE.positive})`);
|
|
10795
|
+
if (until === undefined)
|
|
10796
|
+
fail(ctx, `${path2}.until is required (${RULE.condition})`);
|
|
10797
|
+
if (exhausted === undefined)
|
|
10798
|
+
fail(ctx, `${path2}.exhausted is required (${RULE.exhausted}); say what happens when the loop ends without until`);
|
|
10799
|
+
if (!map.has("do"))
|
|
10800
|
+
fail(ctx, `${path2}.do is required (${RULE.nodes})`);
|
|
10801
|
+
const inner = { ...ctx, loop: { path: path2, types: new Set, unguarded: [] }, conds: [] };
|
|
10802
|
+
const body = nodes(inner, `${path2}.do`, map.get("do"));
|
|
10803
|
+
const types = inner.loop?.types;
|
|
10804
|
+
for (const c of until) {
|
|
10805
|
+
if (c !== "more" && !types.has(PRODUCER[c]))
|
|
10806
|
+
fail(ctx, `${path2}.until: ${c} needs an earlier ${PRODUCER[c]} agent in this step`);
|
|
10807
|
+
}
|
|
10808
|
+
if (exhausted === "fail") {
|
|
10809
|
+
for (const u of inner.loop?.unguarded ?? []) {
|
|
10810
|
+
const conds = u.conds.length > 0 ? u.conds.join(", ") : "<condition>";
|
|
10811
|
+
ctx.d.warn(ctx.step.rel, `${path2}: exhausted: fail with a work agent not guarded by more; its last fix is never checked (guard it with when: [${conds}, more])`);
|
|
10812
|
+
}
|
|
10813
|
+
}
|
|
10814
|
+
ctx.producers.ended.push({ path: path2, types });
|
|
10815
|
+
return { loop: { max, until, exhausted, do: body } };
|
|
10816
|
+
}
|
|
10817
|
+
function when(ctx, path2, map) {
|
|
10818
|
+
siblings(ctx, path2.slice(0, -".when".length), map, "when");
|
|
10819
|
+
const conds = conditions(ctx, path2, map.get("when"));
|
|
10820
|
+
for (const c of conds) {
|
|
10821
|
+
if (c === "more") {
|
|
10822
|
+
if (ctx.loop === undefined)
|
|
10823
|
+
fail(ctx, `${path2}: more outside a loop`);
|
|
10824
|
+
} else {
|
|
10825
|
+
needs(ctx, path2, c, PRODUCER[c], true);
|
|
10826
|
+
}
|
|
10827
|
+
}
|
|
10828
|
+
if (map.has("fail")) {
|
|
10829
|
+
noRef(ctx, `${path2}.fail`, map.get("fail"));
|
|
10830
|
+
if (map.get("fail") !== true)
|
|
10831
|
+
fail(ctx, `${path2}.fail must be ${RULE.fail}`);
|
|
10832
|
+
}
|
|
10833
|
+
let block;
|
|
10834
|
+
if (map.has("block")) {
|
|
10835
|
+
block = subst(ctx, `${path2}.block`, map.get("block"));
|
|
10836
|
+
const v = block.value;
|
|
10837
|
+
if (v !== true && (typeof v !== "string" || v.trim() === ""))
|
|
10838
|
+
fail(ctx, `${path2}.block must be ${RULE.block}`, block.origin);
|
|
10839
|
+
}
|
|
10840
|
+
if (["do", "fail", "block"].filter((k) => map.has(k)).length !== 1)
|
|
10841
|
+
fail(ctx, `${path2}: when needs exactly one of do, fail or block`);
|
|
10842
|
+
if (map.has("fail"))
|
|
10843
|
+
return { when: conds, fail: true };
|
|
10844
|
+
if (block !== undefined)
|
|
10845
|
+
return { when: conds, block: block.value };
|
|
10846
|
+
const inner = { ...ctx, conds: ctx.loop === undefined ? [] : [...ctx.conds, ...conds] };
|
|
10847
|
+
return { when: conds, do: nodes(inner, `${path2}.do`, map.get("do")) };
|
|
10848
|
+
}
|
|
10849
|
+
function uniqueNames(literal) {
|
|
10850
|
+
const counts = new Map;
|
|
10851
|
+
const used = new Set;
|
|
10852
|
+
return (base) => {
|
|
10853
|
+
let n = counts.get(base) ?? 0;
|
|
10854
|
+
let out;
|
|
10855
|
+
do {
|
|
10856
|
+
n += 1;
|
|
10857
|
+
out = n === 1 ? base : `${base}-${n}`;
|
|
10858
|
+
} while (used.has(out) || n > 1 && literal.has(out));
|
|
10859
|
+
counts.set(base, n);
|
|
10860
|
+
used.add(out);
|
|
10861
|
+
return out;
|
|
10862
|
+
};
|
|
10863
|
+
}
|
|
10864
|
+
function walk(tree, f) {
|
|
10865
|
+
for (const n of tree) {
|
|
10866
|
+
f(n);
|
|
10867
|
+
if ("parallel" in n)
|
|
10868
|
+
walk(n.parallel, f);
|
|
10869
|
+
else if ("loop" in n)
|
|
10870
|
+
walk(n.loop.do, f);
|
|
10871
|
+
else if ("do" in n)
|
|
10872
|
+
walk(n.do, f);
|
|
10873
|
+
}
|
|
10874
|
+
}
|
|
10875
|
+
function name(tree, id) {
|
|
10876
|
+
const literal = new Set;
|
|
10877
|
+
walk(tree, (n) => {
|
|
10878
|
+
if ("agent" in n)
|
|
10879
|
+
literal.add(n.agent.name);
|
|
10880
|
+
});
|
|
10881
|
+
const unique = uniqueNames(literal);
|
|
10882
|
+
walk(tree, (n) => {
|
|
10883
|
+
if (!("agent" in n))
|
|
10884
|
+
return;
|
|
10885
|
+
n.agent.name = unique(n.agent.name);
|
|
10886
|
+
n.agent.label = `${id}:${n.agent.name}`;
|
|
10887
|
+
});
|
|
10888
|
+
}
|
|
10889
|
+
function resolveStep(d, step, id, agents, given, entryOrigin) {
|
|
10890
|
+
const params = effectiveParams(d, step, given, entryOrigin, !agents);
|
|
10891
|
+
const ctx = { d, step, params, inline: !agents, inForeach: false, conds: [], producers: { outer: new Set, ended: [] } };
|
|
10892
|
+
const tree = nodes(ctx, "do", step.root.get("do"));
|
|
10893
|
+
name(tree, id);
|
|
10894
|
+
const models = agents ? new Set : modelParams(step);
|
|
10895
|
+
const printed = {};
|
|
10896
|
+
for (const [p, e] of params)
|
|
10897
|
+
if (!models.has(p))
|
|
10898
|
+
printed[p] = { value: e.value, from: e.from };
|
|
10899
|
+
return { id, step: step.name, agents, file: step.path, description: step.description, params: printed, do: tree };
|
|
10900
|
+
}
|
|
10901
|
+
function pushes(entry) {
|
|
10902
|
+
if (!("do" in entry))
|
|
10903
|
+
return false;
|
|
10904
|
+
let push = false;
|
|
10905
|
+
walk(entry.do, (n) => {
|
|
10906
|
+
if ("agent" in n && n.agent.access === "push")
|
|
10907
|
+
push = true;
|
|
10908
|
+
});
|
|
10909
|
+
return push;
|
|
10910
|
+
}
|
|
10911
|
+
function agentsOf(entry) {
|
|
10272
10912
|
const out = [];
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10913
|
+
if ("do" in entry) {
|
|
10914
|
+
walk(entry.do, (n) => {
|
|
10915
|
+
if ("agent" in n)
|
|
10916
|
+
out.push(n.agent);
|
|
10917
|
+
});
|
|
10918
|
+
}
|
|
10919
|
+
return out;
|
|
10920
|
+
}
|
|
10921
|
+
function inputRules(fail2, input, entry, i, scaffolds) {
|
|
10922
|
+
const agents = agentsOf(entry);
|
|
10923
|
+
const at = `steps[${i}]`;
|
|
10924
|
+
if (input === "request" && i === 0 && agents[0]?.returns !== "scaffold") {
|
|
10925
|
+
fail2(`${at}: an input: request workflow starts with a step whose first agent returns scaffold`);
|
|
10926
|
+
}
|
|
10927
|
+
for (const a of agents) {
|
|
10928
|
+
const path2 = agentPaths.get(a);
|
|
10929
|
+
if (input === "request") {
|
|
10930
|
+
if (a.access === "commit" || a.access === "push")
|
|
10931
|
+
fail2(`${at}: ${path2}: access ${a.access} is not allowed in an input: request workflow`);
|
|
10932
|
+
if (a.returns === "scaffold" && ++scaffolds.count > 1)
|
|
10933
|
+
fail2(`${at}: only one agent may return scaffold`);
|
|
10934
|
+
} else if (SPEC_TYPES.includes(a.returns) || a.access === "spec") {
|
|
10935
|
+
const what = SPEC_TYPES.includes(a.returns) ? `returns ${a.returns} and access spec are` : "access spec is";
|
|
10936
|
+
fail2(`${at}: ${path2}: ${what} only for an input: request workflow`);
|
|
10937
|
+
}
|
|
10938
|
+
}
|
|
10939
|
+
}
|
|
10940
|
+
function workingTree(steps) {
|
|
10941
|
+
if (steps.length !== 1)
|
|
10942
|
+
return false;
|
|
10943
|
+
const only = steps[0];
|
|
10944
|
+
if (!("do" in only) || only.agents || only.do.length !== 1)
|
|
10945
|
+
return false;
|
|
10946
|
+
const first = only.do[0];
|
|
10947
|
+
return "agent" in first && first.agent.returns === "work" && first.agent.access === "commit";
|
|
10948
|
+
}
|
|
10949
|
+
function validate(d, path2) {
|
|
10950
|
+
try {
|
|
10951
|
+
return validateOrThrow(d, path2);
|
|
10952
|
+
} catch (e) {
|
|
10953
|
+
if (e instanceof Fail)
|
|
10954
|
+
return { error: e.line };
|
|
10955
|
+
throw e;
|
|
10956
|
+
}
|
|
10957
|
+
}
|
|
10958
|
+
function validateOrThrow(d, path2) {
|
|
10959
|
+
const file = rel(d, path2);
|
|
10960
|
+
const fail2 = failIn(file);
|
|
10961
|
+
const root = rootOf(d.home, file);
|
|
10962
|
+
if (!isMap(root))
|
|
10963
|
+
return fail2("not a map");
|
|
10964
|
+
if (!root.has("version"))
|
|
10965
|
+
fail2(`version is required (${WORKFLOW_VERSION})`);
|
|
10966
|
+
if (root.get("version") !== WORKFLOW_VERSION)
|
|
10967
|
+
fail2(`version must be ${WORKFLOW_VERSION}`);
|
|
10968
|
+
for (const key of root.keys()) {
|
|
10969
|
+
if (!WORKFLOW_KEYS.includes(key))
|
|
10970
|
+
fail2(`unknown key ${String(key)}`);
|
|
10971
|
+
}
|
|
10972
|
+
const input = root.has("input") ? root.get("input") : "changes";
|
|
10973
|
+
if (!INPUTS.includes(input))
|
|
10974
|
+
fail2("input must be changes or request");
|
|
10975
|
+
const scaffolds = { count: 0 };
|
|
10976
|
+
const topAgents = typeof root.get("agents") === "boolean" ? root.get("agents") : true;
|
|
10977
|
+
const steps = [];
|
|
10978
|
+
const pushing = [];
|
|
10979
|
+
const listed = root.get("steps");
|
|
10980
|
+
const literalIds = new Set;
|
|
10981
|
+
if (Array.isArray(listed)) {
|
|
10982
|
+
for (const entry of listed)
|
|
10983
|
+
if (isMap(entry) && entry.size === 1)
|
|
10984
|
+
literalIds.add(String([...entry.keys()][0]));
|
|
10985
|
+
}
|
|
10986
|
+
const idOf = uniqueNames(literalIds);
|
|
10987
|
+
const cache = new Map;
|
|
10988
|
+
for (const key of root.keys()) {
|
|
10989
|
+
if (key === "default" && typeof root.get(key) !== "boolean")
|
|
10990
|
+
fail2("default must be true or false");
|
|
10991
|
+
if (key === "default" && root.get(key) === true && input === "request")
|
|
10992
|
+
fail2("default: true is only for an input: changes workflow");
|
|
10993
|
+
if (key === "agents" && typeof root.get(key) !== "boolean")
|
|
10994
|
+
fail2("agents must be true or false");
|
|
10995
|
+
if (key !== "steps")
|
|
10279
10996
|
continue;
|
|
10997
|
+
const entries = root.get("steps");
|
|
10998
|
+
if (!Array.isArray(entries) || entries.length === 0)
|
|
10999
|
+
fail2("steps must be a non-empty list");
|
|
11000
|
+
for (const [i, entry] of entries.entries()) {
|
|
11001
|
+
const at = `steps[${i}]`;
|
|
11002
|
+
if (!isMap(entry) || entry.size !== 1)
|
|
11003
|
+
fail2(`${at} must be a map with one key: a step name or gate`);
|
|
11004
|
+
const [k, value] = [...entry][0];
|
|
11005
|
+
if (k === "gate") {
|
|
11006
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
11007
|
+
fail2(`${at}.gate must be a non-empty question`);
|
|
11008
|
+
const gate = { id: idOf("gate"), gate: value, agents: false };
|
|
11009
|
+
inputRules(fail2, input, gate, i, scaffolds);
|
|
11010
|
+
steps.push(gate);
|
|
11011
|
+
continue;
|
|
11012
|
+
}
|
|
11013
|
+
const stepName = String(k);
|
|
11014
|
+
const stepPath = NAME.test(stepName) ? fileOf(d.home, d.key, "steps", stepName) : null;
|
|
11015
|
+
if (stepPath === null) {
|
|
11016
|
+
fail2(`${at}: no step '${stepName}' in ${searched(d.home, d.key, "steps")}${suggest(stepName, knownSteps(d.home, d.key), "steps")}`);
|
|
11017
|
+
}
|
|
11018
|
+
if (value !== null && !isMap(value))
|
|
11019
|
+
fail2(`${at}.${stepName} must be a map`);
|
|
11020
|
+
const given = value ?? new Map;
|
|
11021
|
+
const step = cache.get(stepPath) ?? readStep(d, stepName, stepPath, true);
|
|
11022
|
+
cache.set(stepPath, step);
|
|
11023
|
+
for (const p of given.keys()) {
|
|
11024
|
+
if (p !== "agents" && !step.params.has(p)) {
|
|
11025
|
+
fail2(`${at}.${stepName}.${String(p)} is not a param of ${stepName}${paramSuffix(step, String(p))}`);
|
|
11026
|
+
}
|
|
11027
|
+
}
|
|
11028
|
+
const values = new Map;
|
|
11029
|
+
for (const [p, v] of given) {
|
|
11030
|
+
if (p === "agents") {
|
|
11031
|
+
if (typeof v !== "boolean")
|
|
11032
|
+
fail2(`${at}.${stepName}.agents must be true or false`);
|
|
11033
|
+
continue;
|
|
11034
|
+
}
|
|
11035
|
+
const kind = kindOf(step.params.get(p)?.default);
|
|
11036
|
+
if (kindOf(v) !== kind)
|
|
11037
|
+
fail2(`${at}.${stepName}.${String(p)} must be ${KIND_TEXT[kind]}`);
|
|
11038
|
+
values.set(p, v);
|
|
11039
|
+
}
|
|
11040
|
+
const agents = given.has("agents") ? given.get("agents") : topAgents;
|
|
11041
|
+
if (!agents) {
|
|
11042
|
+
const models = modelParams(step);
|
|
11043
|
+
for (const p of values.keys()) {
|
|
11044
|
+
if (models.has(p))
|
|
11045
|
+
fail2(`${at}.${stepName}.${p} has no effect when the step runs inline (agents: false)`);
|
|
11046
|
+
}
|
|
11047
|
+
}
|
|
11048
|
+
const resolved = resolveStep(d, step, idOf(stepName), agents, values, `${file} ${at}`);
|
|
11049
|
+
inputRules(fail2, input, resolved, i, scaffolds);
|
|
11050
|
+
if (pushes(resolved))
|
|
11051
|
+
pushing.push(i);
|
|
11052
|
+
steps.push(resolved);
|
|
10280
11053
|
}
|
|
10281
|
-
out.push(n);
|
|
10282
11054
|
}
|
|
10283
|
-
|
|
11055
|
+
if (!root.has("steps"))
|
|
11056
|
+
fail2("steps must be a non-empty list");
|
|
11057
|
+
if (pushing.length > 1)
|
|
11058
|
+
fail2(`steps[${pushing[1]}]: only one step may push`);
|
|
11059
|
+
if (pushing.length === 1 && pushing[0] !== steps.length - 1)
|
|
11060
|
+
fail2(`steps[${pushing[0]}]: a pushing step must be the last step`);
|
|
11061
|
+
if ("gate" in steps[steps.length - 1])
|
|
11062
|
+
fail2(`steps[${steps.length - 1}]: a gate cannot be the last step`);
|
|
11063
|
+
return { workflow: { name: basename2(path2, ".yaml"), file: path2, input, steps }, isDefault: root.get("default") === true };
|
|
11064
|
+
}
|
|
11065
|
+
function scan(d, dir) {
|
|
11066
|
+
const names = namesIn(dir, "workflows", (path2) => warnLoud(rel(d, path2), "not a valid workflow name"));
|
|
11067
|
+
return names.map((n) => `${n}.yaml`).sort();
|
|
10284
11068
|
}
|
|
10285
11069
|
var joinAnd = (items) => items.length === 1 ? items[0] : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
10286
|
-
function defaultOf(d, paths
|
|
11070
|
+
function defaultOf(d, paths) {
|
|
10287
11071
|
const marked = [];
|
|
10288
11072
|
for (const path2 of paths) {
|
|
10289
|
-
const result = validate(d, path2
|
|
11073
|
+
const result = validate(d, path2);
|
|
10290
11074
|
if ("error" in result)
|
|
10291
11075
|
return result;
|
|
10292
11076
|
if (result.isDefault)
|
|
@@ -10297,44 +11081,56 @@ function defaultOf(d, paths, defaults2) {
|
|
|
10297
11081
|
}
|
|
10298
11082
|
return marked.length === 1 ? { workflow: marked[0] } : null;
|
|
10299
11083
|
}
|
|
10300
|
-
function byName(d, wanted
|
|
10301
|
-
const
|
|
10302
|
-
const global = join8(globalDir(d, "workflows"), `${wanted}.yaml`);
|
|
10303
|
-
const path2 = isFile(own) ? own : isFile(global) ? global : null;
|
|
11084
|
+
function byName(d, wanted) {
|
|
11085
|
+
const path2 = fileOf(d.home, d.key, "workflows", wanted);
|
|
10304
11086
|
if (path2 === null) {
|
|
10305
|
-
return { error: `theway: no workflow '${wanted}' in ${searched(d, "workflows")}` };
|
|
11087
|
+
return { error: `theway: no workflow '${wanted}' in ${searched(d.home, d.key, "workflows")}` };
|
|
10306
11088
|
}
|
|
10307
|
-
return validate(d, path2
|
|
11089
|
+
return validate(d, path2);
|
|
10308
11090
|
}
|
|
10309
|
-
function byDefault(d
|
|
10310
|
-
const
|
|
10311
|
-
const
|
|
11091
|
+
function byDefault(d) {
|
|
11092
|
+
const [ownDir, globalDir] = dirsOf(d.home, d.key, "workflows");
|
|
11093
|
+
const ownNames = scan(d, ownDir);
|
|
11094
|
+
const own = defaultOf(d, ownNames.map((n) => join9(ownDir, n)));
|
|
10312
11095
|
if (own !== null)
|
|
10313
11096
|
return own;
|
|
10314
|
-
const globalNames = scan(d, globalDir
|
|
10315
|
-
const global = defaultOf(d, globalNames.map((n) =>
|
|
11097
|
+
const globalNames = scan(d, globalDir).filter((n) => !ownNames.includes(n));
|
|
11098
|
+
const global = defaultOf(d, globalNames.map((n) => join9(globalDir, n)));
|
|
10316
11099
|
if (global !== null)
|
|
10317
11100
|
return global;
|
|
10318
|
-
return byName(d, "develop"
|
|
11101
|
+
return byName(d, "develop");
|
|
11102
|
+
}
|
|
11103
|
+
function dirsFor(home, key) {
|
|
11104
|
+
const loaded = loadConfig(home, key);
|
|
11105
|
+
if (loaded === null)
|
|
11106
|
+
return null;
|
|
11107
|
+
const printed = new Set;
|
|
11108
|
+
const warn = (file, text) => {
|
|
11109
|
+
const line = `${file}\x00${text}`;
|
|
11110
|
+
if (printed.has(line))
|
|
11111
|
+
return;
|
|
11112
|
+
printed.add(line);
|
|
11113
|
+
warnLoud(file, text);
|
|
11114
|
+
};
|
|
11115
|
+
const d = { home, key, loaded, warn };
|
|
11116
|
+
for (const dir of dirsOf(home, key, "steps")) {
|
|
11117
|
+
if (isFile(join9(dir, "gate.yaml")))
|
|
11118
|
+
warn(rel(d, join9(dir, "gate.yaml")), "gate is reserved for the gate entry");
|
|
11119
|
+
}
|
|
11120
|
+
warnUnknownDefaults(home, key, loaded, warn);
|
|
11121
|
+
return d;
|
|
10319
11122
|
}
|
|
10320
11123
|
function cmdWorkflow(wanted, override) {
|
|
10321
11124
|
const key = resolveKey(override);
|
|
10322
11125
|
if (key === null)
|
|
10323
11126
|
return 1;
|
|
10324
|
-
if (
|
|
10325
|
-
const shown = wanted.replaceAll(`
|
|
10326
|
-
`, "\\n").replaceAll("\r", "\\r");
|
|
10327
|
-
process.stderr.write(`theway: invalid workflow name '${shown}'
|
|
10328
|
-
`);
|
|
11127
|
+
if (invalidName("workflow", wanted))
|
|
10329
11128
|
return 1;
|
|
10330
|
-
}
|
|
10331
11129
|
const home = thewayHome();
|
|
10332
|
-
const
|
|
10333
|
-
if (
|
|
11130
|
+
const d = dirsFor(home, key);
|
|
11131
|
+
if (d === null)
|
|
10334
11132
|
return 1;
|
|
10335
|
-
const
|
|
10336
|
-
const d = { home, key };
|
|
10337
|
-
const result = wanted === undefined ? byDefault(d, defaults2) : byName(d, wanted, defaults2);
|
|
11133
|
+
const result = wanted === undefined ? byDefault(d) : byName(d, wanted);
|
|
10338
11134
|
if ("error" in result) {
|
|
10339
11135
|
process.stderr.write(`${result.error}
|
|
10340
11136
|
`);
|
|
@@ -10342,21 +11138,89 @@ function cmdWorkflow(wanted, override) {
|
|
|
10342
11138
|
}
|
|
10343
11139
|
const conventions = [];
|
|
10344
11140
|
for (const file2 of CONVENTIONS) {
|
|
10345
|
-
const global =
|
|
11141
|
+
const global = join9(home, "standards", file2);
|
|
10346
11142
|
if (!isFile(global)) {
|
|
10347
11143
|
process.stderr.write(`theway: ${global} not found; run npx --yes @pixelfactoryio/theway@latest install, then /reload-plugins
|
|
10348
11144
|
`);
|
|
10349
11145
|
return 1;
|
|
10350
11146
|
}
|
|
10351
|
-
const own =
|
|
11147
|
+
const own = join9(projectDir(home, key), "standards", file2);
|
|
10352
11148
|
conventions.push(isFile(own) ? own : global);
|
|
10353
11149
|
}
|
|
10354
|
-
const { name:
|
|
10355
|
-
const
|
|
11150
|
+
const { name: workflowName, file, input, steps } = result.workflow;
|
|
11151
|
+
const changes = input === "changes";
|
|
11152
|
+
const doc = {
|
|
11153
|
+
name: workflowName,
|
|
11154
|
+
file,
|
|
11155
|
+
input,
|
|
11156
|
+
commits: conventions[0],
|
|
11157
|
+
git_host: conventions[1],
|
|
11158
|
+
pushes: changes && steps.some(pushes),
|
|
11159
|
+
working_tree: changes && workingTree(steps),
|
|
11160
|
+
steps
|
|
11161
|
+
};
|
|
10356
11162
|
process.stdout.write(`${JSON.stringify(doc, null, 2)}
|
|
10357
11163
|
`);
|
|
10358
11164
|
return 0;
|
|
10359
11165
|
}
|
|
11166
|
+
var shown = (v) => Array.isArray(v) ? v.join(",") : String(v);
|
|
11167
|
+
function cmdSteps(wanted, override) {
|
|
11168
|
+
const key = resolveKey(override);
|
|
11169
|
+
if (key === null)
|
|
11170
|
+
return 1;
|
|
11171
|
+
if (invalidName("step", wanted))
|
|
11172
|
+
return 1;
|
|
11173
|
+
const home = thewayHome();
|
|
11174
|
+
const d = dirsFor(home, key);
|
|
11175
|
+
if (d === null)
|
|
11176
|
+
return 1;
|
|
11177
|
+
if (wanted !== undefined) {
|
|
11178
|
+
const path2 = wanted === "gate" ? null : fileOf(home, key, "steps", wanted);
|
|
11179
|
+
if (path2 === null) {
|
|
11180
|
+
process.stderr.write(`theway: no step '${wanted}' in ${searched(home, key, "steps")}${suggest(wanted, knownSteps(home, key), "steps")}
|
|
11181
|
+
`);
|
|
11182
|
+
return 1;
|
|
11183
|
+
}
|
|
11184
|
+
try {
|
|
11185
|
+
const step = readStep(d, wanted, path2, true);
|
|
11186
|
+
const resolved = resolveStep(d, step, wanted, true, new Map, "");
|
|
11187
|
+
process.stdout.write(`${JSON.stringify(resolved, null, 2)}
|
|
11188
|
+
`);
|
|
11189
|
+
return 0;
|
|
11190
|
+
} catch (e) {
|
|
11191
|
+
if (!(e instanceof Fail))
|
|
11192
|
+
throw e;
|
|
11193
|
+
process.stderr.write(`${e.line}
|
|
11194
|
+
`);
|
|
11195
|
+
return 1;
|
|
11196
|
+
}
|
|
11197
|
+
}
|
|
11198
|
+
const [ownDir, globalDir] = dirsOf(home, key, "steps");
|
|
11199
|
+
const own = namesIn(ownDir, "steps").filter((n) => n !== "gate");
|
|
11200
|
+
const found = [
|
|
11201
|
+
...own.map((n) => ({ n, origin: "project", path: join9(ownDir, `${n}.yaml`) })),
|
|
11202
|
+
...namesIn(globalDir, "steps").filter((n) => n !== "gate" && !own.includes(n)).map((n) => ({ n, origin: "global", path: join9(globalDir, `${n}.yaml`) }))
|
|
11203
|
+
].sort((a, b) => a.n < b.n ? -1 : a.n > b.n ? 1 : 0);
|
|
11204
|
+
const lines = [];
|
|
11205
|
+
for (const { n, origin, path: path2 } of found) {
|
|
11206
|
+
let step;
|
|
11207
|
+
try {
|
|
11208
|
+
step = readStep(d, n, path2, false);
|
|
11209
|
+
} catch (e) {
|
|
11210
|
+
if (!(e instanceof Fail))
|
|
11211
|
+
throw e;
|
|
11212
|
+
d.warn(e.file, e.reason);
|
|
11213
|
+
continue;
|
|
11214
|
+
}
|
|
11215
|
+
lines.push(`${n} ${origin} ${step.description}`);
|
|
11216
|
+
for (const [p, e] of effectiveParams(d, step, new Map, "", false)) {
|
|
11217
|
+
lines.push(` ${p}=${shown(e.value)} ${step.params.get(p).description}`);
|
|
11218
|
+
}
|
|
11219
|
+
}
|
|
11220
|
+
process.stdout.write(lines.map((l) => `${l}
|
|
11221
|
+
`).join(""));
|
|
11222
|
+
return 0;
|
|
11223
|
+
}
|
|
10360
11224
|
|
|
10361
11225
|
// src/install.ts
|
|
10362
11226
|
import {
|
|
@@ -10378,7 +11242,7 @@ import {
|
|
|
10378
11242
|
writeFileSync as writeFileSync2
|
|
10379
11243
|
} from "node:fs";
|
|
10380
11244
|
import { homedir as homedir2 } from "node:os";
|
|
10381
|
-
import { delimiter, dirname as dirname2, isAbsolute, join as
|
|
11245
|
+
import { delimiter, dirname as dirname2, isAbsolute, join as join10, resolve as resolve4, sep } from "node:path";
|
|
10382
11246
|
import { fileURLToPath } from "node:url";
|
|
10383
11247
|
|
|
10384
11248
|
// node_modules/@clack/core/dist/index.mjs
|
|
@@ -10557,18 +11421,18 @@ var wrapWord = (rows, word, columns) => {
|
|
|
10557
11421
|
let isInsideEscape = false;
|
|
10558
11422
|
let isInsideLinkEscape = false;
|
|
10559
11423
|
let lastRow = rows.at(-1);
|
|
10560
|
-
let
|
|
11424
|
+
let visible2 = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
10561
11425
|
let currentCharacter = characters.next();
|
|
10562
11426
|
let nextCharacter = characters.next();
|
|
10563
11427
|
let rawCharacterIndex = 0;
|
|
10564
11428
|
while (!currentCharacter.done) {
|
|
10565
11429
|
const character = currentCharacter.value;
|
|
10566
11430
|
const characterLength = dist_default2(character);
|
|
10567
|
-
if (
|
|
11431
|
+
if (visible2 + characterLength <= columns) {
|
|
10568
11432
|
rows[rows.length - 1] += character;
|
|
10569
11433
|
} else {
|
|
10570
11434
|
rows.push(character);
|
|
10571
|
-
|
|
11435
|
+
visible2 = 0;
|
|
10572
11436
|
}
|
|
10573
11437
|
if (character === ESC || character === CSI) {
|
|
10574
11438
|
isInsideEscape = true;
|
|
@@ -10584,10 +11448,10 @@ var wrapWord = (rows, word, columns) => {
|
|
|
10584
11448
|
isInsideEscape = false;
|
|
10585
11449
|
}
|
|
10586
11450
|
} else {
|
|
10587
|
-
|
|
10588
|
-
if (
|
|
11451
|
+
visible2 += characterLength;
|
|
11452
|
+
if (visible2 === columns && !nextCharacter.done) {
|
|
10589
11453
|
rows.push("");
|
|
10590
|
-
|
|
11454
|
+
visible2 = 0;
|
|
10591
11455
|
}
|
|
10592
11456
|
}
|
|
10593
11457
|
currentCharacter = nextCharacter;
|
|
@@ -10595,7 +11459,7 @@ var wrapWord = (rows, word, columns) => {
|
|
|
10595
11459
|
rawCharacterIndex += character.length;
|
|
10596
11460
|
}
|
|
10597
11461
|
lastRow = rows.at(-1);
|
|
10598
|
-
if (!
|
|
11462
|
+
if (!visible2 && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
10599
11463
|
rows[rows.length - 2] += rows.pop();
|
|
10600
11464
|
}
|
|
10601
11465
|
};
|
|
@@ -11789,16 +12653,16 @@ ${i2}
|
|
|
11789
12653
|
// src/install.ts
|
|
11790
12654
|
var self = fileURLToPath(import.meta.url);
|
|
11791
12655
|
var pkgRoot = dirname2(dirname2(self));
|
|
11792
|
-
var plugin =
|
|
12656
|
+
var plugin = join10(pkgRoot, "plugin");
|
|
11793
12657
|
var PLUGIN_DIRS = [".claude-plugin", "commands", "workflows"];
|
|
11794
12658
|
var BINARY_MARKER = "theway-cli-binary:pixelfactoryio/theway";
|
|
11795
12659
|
function claudeHome() {
|
|
11796
12660
|
const dir = (process.env.CLAUDE_CONFIG_DIR ?? "").trim();
|
|
11797
|
-
return dir !== "" ? dir :
|
|
12661
|
+
return dir !== "" ? dir : join10(homedir2(), ".claude");
|
|
11798
12662
|
}
|
|
11799
12663
|
function installDir() {
|
|
11800
12664
|
const dir = process.env.THEWAY_INSTALL_DIR ?? "";
|
|
11801
|
-
return dir !== "" ? resolve4(dir) :
|
|
12665
|
+
return dir !== "" ? resolve4(dir) : join10(homedir2(), ".local", "bin");
|
|
11802
12666
|
}
|
|
11803
12667
|
function shownHome(home) {
|
|
11804
12668
|
return resolve4(home) === resolve4(defaultHome()) ? "~/.theway" : resolve4(home);
|
|
@@ -11823,7 +12687,7 @@ function recordedHome() {
|
|
|
11823
12687
|
function legacyRules(home) {
|
|
11824
12688
|
return [...new Set(["Bash(~/.theway/bin/theway:*)", `Bash(${shownHome(home)}/bin/theway:*)`])];
|
|
11825
12689
|
}
|
|
11826
|
-
function
|
|
12690
|
+
function fail2(line) {
|
|
11827
12691
|
process.stderr.write(`${line}
|
|
11828
12692
|
`);
|
|
11829
12693
|
return 1;
|
|
@@ -11879,7 +12743,7 @@ function settingsTarget(path2) {
|
|
|
11879
12743
|
return { target };
|
|
11880
12744
|
}
|
|
11881
12745
|
function unwritableSettings(path2, reason) {
|
|
11882
|
-
return
|
|
12746
|
+
return fail2(`theway: cannot write ${path2}: ${reason}; nothing was changed`);
|
|
11883
12747
|
}
|
|
11884
12748
|
function writeSettings(target, settings2) {
|
|
11885
12749
|
mkdirSync3(dirname2(target), { recursive: true });
|
|
@@ -11895,18 +12759,18 @@ function writeSettings(target, settings2) {
|
|
|
11895
12759
|
}
|
|
11896
12760
|
}
|
|
11897
12761
|
function invalidSettings(path2) {
|
|
11898
|
-
return
|
|
12762
|
+
return fail2(`theway: ${path2} is not valid settings JSON; nothing was changed`);
|
|
11899
12763
|
}
|
|
11900
12764
|
function copyPlugin(home) {
|
|
11901
|
-
const tmp =
|
|
11902
|
-
const old =
|
|
11903
|
-
const dest =
|
|
12765
|
+
const tmp = join10(home, `.theway-install-${process.pid}`);
|
|
12766
|
+
const old = join10(home, `.theway-old-${process.pid}`);
|
|
12767
|
+
const dest = join10(home, "skills", "theway");
|
|
11904
12768
|
rmSync2(tmp, { recursive: true, force: true });
|
|
11905
12769
|
try {
|
|
11906
12770
|
for (const dir of PLUGIN_DIRS) {
|
|
11907
|
-
cpSync(
|
|
12771
|
+
cpSync(join10(plugin, dir), join10(tmp, dir), { recursive: true });
|
|
11908
12772
|
}
|
|
11909
|
-
mkdirSync3(
|
|
12773
|
+
mkdirSync3(join10(home, "skills"), { recursive: true });
|
|
11910
12774
|
if (existsSync3(dest))
|
|
11911
12775
|
renameSync3(dest, old);
|
|
11912
12776
|
renameSync3(tmp, dest);
|
|
@@ -11930,22 +12794,22 @@ function legacyText(path2, match) {
|
|
|
11930
12794
|
}
|
|
11931
12795
|
function removeLegacyBin(home) {
|
|
11932
12796
|
for (const h2 of new Set([defaultHome(), resolve4(home)])) {
|
|
11933
|
-
const bin =
|
|
11934
|
-
if (legacyText(
|
|
12797
|
+
const bin = join10(h2, "bin");
|
|
12798
|
+
if (legacyText(join10(bin, "theway"), (t2) => t2.startsWith(`#!/bin/sh
|
|
11935
12799
|
exec node `) && t2.endsWith(`theway.js' "$@"
|
|
11936
12800
|
`))) {
|
|
11937
|
-
rmSync2(
|
|
12801
|
+
rmSync2(join10(bin, "theway"), { force: true });
|
|
11938
12802
|
}
|
|
11939
|
-
if (legacyText(
|
|
12803
|
+
if (legacyText(join10(bin, "theway.js"), (t2) => t2.startsWith(`#!/usr/bin/env node
|
|
11940
12804
|
`))) {
|
|
11941
|
-
rmSync2(
|
|
12805
|
+
rmSync2(join10(bin, "theway.js"), { force: true });
|
|
11942
12806
|
}
|
|
11943
12807
|
removeIfEmpty2(bin);
|
|
11944
12808
|
}
|
|
11945
12809
|
}
|
|
11946
12810
|
function writeBinary(dir) {
|
|
11947
|
-
const dest =
|
|
11948
|
-
const tmp =
|
|
12811
|
+
const dest = join10(dir, "theway");
|
|
12812
|
+
const tmp = join10(dir, `.theway-${process.pid}`);
|
|
11949
12813
|
mkdirSync3(dir, { recursive: true });
|
|
11950
12814
|
try {
|
|
11951
12815
|
copyFileSync2(self, tmp);
|
|
@@ -12009,7 +12873,7 @@ function copiesOnPath() {
|
|
|
12009
12873
|
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
12010
12874
|
if (dir === "")
|
|
12011
12875
|
continue;
|
|
12012
|
-
const candidate =
|
|
12876
|
+
const candidate = join10(dir, "theway");
|
|
12013
12877
|
if (!isFile(candidate))
|
|
12014
12878
|
continue;
|
|
12015
12879
|
try {
|
|
@@ -12105,14 +12969,14 @@ async function askStandards() {
|
|
|
12105
12969
|
return isCancel(answer) ? null : answer;
|
|
12106
12970
|
}
|
|
12107
12971
|
async function install(opts) {
|
|
12108
|
-
if (!existsSync3(
|
|
12109
|
-
return
|
|
12972
|
+
if (!existsSync3(join10(plugin, ".claude-plugin"))) {
|
|
12973
|
+
return fail2("theway: run `npx --yes @pixelfactoryio/theway@latest install` to install or update theway");
|
|
12110
12974
|
}
|
|
12111
12975
|
let enabled2 = [];
|
|
12112
12976
|
if (opts.standards !== undefined) {
|
|
12113
12977
|
const parsed = parseStandards(opts.standards);
|
|
12114
12978
|
if (!Array.isArray(parsed))
|
|
12115
|
-
return
|
|
12979
|
+
return fail2(parsed.error);
|
|
12116
12980
|
enabled2 = parsed;
|
|
12117
12981
|
}
|
|
12118
12982
|
const cHome = claudeHome();
|
|
@@ -12120,19 +12984,19 @@ async function install(opts) {
|
|
|
12120
12984
|
if (opts.home !== undefined) {
|
|
12121
12985
|
const home = expandHome(opts.home);
|
|
12122
12986
|
if (typeof home !== "string")
|
|
12123
|
-
return
|
|
12987
|
+
return fail2(`theway: invalid --home '${opts.home}': ${home.error}; nothing was changed`);
|
|
12124
12988
|
const env = process.env.THEWAY_HOME ?? "";
|
|
12125
12989
|
if (env !== "" && resolve4(env) !== home) {
|
|
12126
|
-
return
|
|
12990
|
+
return fail2(`theway: --home ${home} and THEWAY_HOME ${resolve4(env)} differ; unset THEWAY_HOME or drop --home; nothing was changed`);
|
|
12127
12991
|
}
|
|
12128
12992
|
tHome = home;
|
|
12129
12993
|
} else {
|
|
12130
12994
|
const found = resolveHome();
|
|
12131
|
-
const neverInstalled = found.source === "default" && !existsSync3(
|
|
12995
|
+
const neverInstalled = found.source === "default" && !existsSync3(join10(defaultHome(), "config.yaml"));
|
|
12132
12996
|
if (neverInstalled && interactive()) {
|
|
12133
12997
|
const home = await askHome();
|
|
12134
12998
|
if (home === null)
|
|
12135
|
-
return
|
|
12999
|
+
return fail2(CANCELLED);
|
|
12136
13000
|
tHome = home;
|
|
12137
13001
|
} else {
|
|
12138
13002
|
tHome = found.home;
|
|
@@ -12141,10 +13005,10 @@ async function install(opts) {
|
|
|
12141
13005
|
const previous = recordedHome();
|
|
12142
13006
|
const custom = tHome !== resolve4(defaultHome());
|
|
12143
13007
|
const dir = installDir();
|
|
12144
|
-
const settingsPath =
|
|
13008
|
+
const settingsPath = join10(cHome, "settings.json");
|
|
12145
13009
|
const unsafe = unsafeHomeReason(tHome, custom);
|
|
12146
13010
|
if (unsafe !== "") {
|
|
12147
|
-
return
|
|
13011
|
+
return fail2(`theway: refusing data home ${resolve4(tHome)}: ${unsafe}; set THEWAY_HOME or --home to a dedicated folder`);
|
|
12148
13012
|
}
|
|
12149
13013
|
const resolved = settingsTarget(settingsPath);
|
|
12150
13014
|
if ("error" in resolved)
|
|
@@ -12152,20 +13016,20 @@ async function install(opts) {
|
|
|
12152
13016
|
const settings2 = readSettings(resolved.target);
|
|
12153
13017
|
if (settings2 === null)
|
|
12154
13018
|
return invalidSettings(settingsPath);
|
|
12155
|
-
const target =
|
|
13019
|
+
const target = join10(dir, "theway");
|
|
12156
13020
|
if (occupied(target) && !isThewayBinary(target)) {
|
|
12157
|
-
return
|
|
13021
|
+
return fail2(`theway: ${target} exists and is not a theway binary; nothing was changed. Remove it, or set THEWAY_INSTALL_DIR to another folder`);
|
|
12158
13022
|
}
|
|
12159
|
-
const config =
|
|
13023
|
+
const config = join10(resolve4(tHome), "config.yaml");
|
|
12160
13024
|
const firstInstall = !existsSync3(config);
|
|
12161
13025
|
if (opts.standards !== undefined && !firstInstall) {
|
|
12162
|
-
return
|
|
13026
|
+
return fail2(`theway: --standards applies only to a first install; ${config} exists, so set standards.<key>.enabled there instead; nothing was changed`);
|
|
12163
13027
|
}
|
|
12164
13028
|
const asked = firstInstall && opts.standards === undefined && interactive();
|
|
12165
13029
|
if (asked) {
|
|
12166
13030
|
const chosen = await askStandards();
|
|
12167
13031
|
if (chosen === null)
|
|
12168
|
-
return
|
|
13032
|
+
return fail2(CANCELLED);
|
|
12169
13033
|
enabled2 = chosen;
|
|
12170
13034
|
}
|
|
12171
13035
|
const dest = copyPlugin(cHome);
|
|
@@ -12174,9 +13038,9 @@ async function install(opts) {
|
|
|
12174
13038
|
removeLegacyBin(tHome);
|
|
12175
13039
|
binary = writeBinary(dir);
|
|
12176
13040
|
} catch (e) {
|
|
12177
|
-
return
|
|
13041
|
+
return fail2(`theway: ${e.message}`);
|
|
12178
13042
|
}
|
|
12179
|
-
const status = init(
|
|
13043
|
+
const status = init(join10(plugin, "home"), tHome, enabled2);
|
|
12180
13044
|
if (status !== 0)
|
|
12181
13045
|
return status;
|
|
12182
13046
|
if (firstInstall && opts.standards === undefined && !asked) {
|
|
@@ -12186,7 +13050,7 @@ async function install(opts) {
|
|
|
12186
13050
|
try {
|
|
12187
13051
|
writePointer(tHome, custom);
|
|
12188
13052
|
} catch (e) {
|
|
12189
|
-
return
|
|
13053
|
+
return fail2(`theway: ${e.message}`);
|
|
12190
13054
|
}
|
|
12191
13055
|
const perms = settings2.permissions ?? {};
|
|
12192
13056
|
const allow = perms.allow ?? [];
|
|
@@ -12205,7 +13069,7 @@ async function install(opts) {
|
|
|
12205
13069
|
writeSettings(resolved.target, settings2);
|
|
12206
13070
|
}
|
|
12207
13071
|
checkPath(dir, binary);
|
|
12208
|
-
const version = JSON.parse(readFileSync8(
|
|
13072
|
+
const version = JSON.parse(readFileSync8(join10(pkgRoot, "package.json"), "utf-8")).version;
|
|
12209
13073
|
process.stdout.write(`Installed theway ${version} to ${dest} (theway@skills-dir), ${binary} and ${tHome}. Start a new Claude Code session or run /reload-plugins.
|
|
12210
13074
|
`);
|
|
12211
13075
|
return 0;
|
|
@@ -12214,7 +13078,7 @@ function uninstall() {
|
|
|
12214
13078
|
const cHome = claudeHome();
|
|
12215
13079
|
const tHome = resolveHome().home;
|
|
12216
13080
|
const homes = [...new Set([tHome, recordedHome(), defaultHome()])];
|
|
12217
|
-
const settingsPath =
|
|
13081
|
+
const settingsPath = join10(cHome, "settings.json");
|
|
12218
13082
|
let settingsFile = settingsPath;
|
|
12219
13083
|
if (occupied(settingsPath)) {
|
|
12220
13084
|
const resolved = settingsTarget(settingsPath);
|
|
@@ -12222,8 +13086,8 @@ function uninstall() {
|
|
|
12222
13086
|
return unwritableSettings(settingsPath, resolved.error);
|
|
12223
13087
|
settingsFile = resolved.target;
|
|
12224
13088
|
}
|
|
12225
|
-
rmSync2(
|
|
12226
|
-
const binary =
|
|
13089
|
+
rmSync2(join10(cHome, "skills", "theway"), { recursive: true, force: true });
|
|
13090
|
+
const binary = join10(installDir(), "theway");
|
|
12227
13091
|
const removed = isThewayBinary(binary);
|
|
12228
13092
|
if (removed)
|
|
12229
13093
|
rmSync2(binary, { force: true });
|
|
@@ -12250,12 +13114,12 @@ function uninstall() {
|
|
|
12250
13114
|
}
|
|
12251
13115
|
|
|
12252
13116
|
// src/program.ts
|
|
12253
|
-
var
|
|
13117
|
+
var nonEmpty = (value) => {
|
|
12254
13118
|
if (value === "")
|
|
12255
13119
|
throw new InvalidArgumentError("must not be empty");
|
|
12256
13120
|
return value;
|
|
12257
13121
|
};
|
|
12258
|
-
var
|
|
13122
|
+
var positive = (value) => {
|
|
12259
13123
|
if (!/^[1-9][0-9]*$/.test(value))
|
|
12260
13124
|
throw new InvalidArgumentError("must be a positive integer");
|
|
12261
13125
|
return Number(value);
|
|
@@ -12265,18 +13129,19 @@ var exit = (code) => {
|
|
|
12265
13129
|
};
|
|
12266
13130
|
function buildProgram() {
|
|
12267
13131
|
const program2 = new Command("theway");
|
|
12268
|
-
program2.command("install").option("--home <path>", "",
|
|
13132
|
+
program2.command("install").option("--home <path>", "", nonEmpty).option("--standards <keys>").action(async (o2) => exit(await install({ home: o2.home, standards: o2.standards })));
|
|
12269
13133
|
program2.command("uninstall").action(() => exit(uninstall()));
|
|
12270
13134
|
program2.command("list").option("--project <key>").action((o2) => exit(cmdList(o2.project)));
|
|
12271
|
-
program2.command("archive").argument("<change-id>", "",
|
|
13135
|
+
program2.command("archive").argument("<change-id>", "", nonEmpty).option("--project <key>").option("--force").action((change, o2) => exit(cmdArchive(change, o2.project, o2.force === true)));
|
|
12272
13136
|
program2.command("path").argument("[change-id]").option("--project <key>").option("--verbose").action((change, o2) => exit(cmdPath(change, o2.project, o2.verbose === true)));
|
|
12273
13137
|
program2.command("project").option("--project <key>").action((o2) => exit(cmdProject(o2.project)));
|
|
12274
13138
|
program2.command("config").option("--project <key>").action((o2) => exit(cmdConfig(o2.project)));
|
|
12275
13139
|
program2.command("standards").argument("<phase>").option("--project <key>").action((phase, o2) => exit(cmdStandards(phase, o2.project)));
|
|
12276
13140
|
program2.command("context").argument("<phase>").argument("[change-id]").option("--project <key>").action((phase, change, o2) => exit(cmdContext(phase, change, o2.project)));
|
|
12277
13141
|
program2.command("workflow").argument("[name]").option("--project <key>").action((name2, o2) => exit(cmdWorkflow(name2, o2.project)));
|
|
13142
|
+
program2.command("steps").argument("[name]").option("--project <key>").action((name2, o2) => exit(cmdSteps(name2, o2.project)));
|
|
12278
13143
|
program2.command("authority").action(() => exit(cmdAuthority()));
|
|
12279
|
-
program2.command("next-id").argument("<series-id>").option("--project <key>").option("--count <n>", "",
|
|
13144
|
+
program2.command("next-id").argument("<series-id>").option("--project <key>").option("--count <n>", "", positive, 1).action((series, o2) => exit(cmdNextId(series, o2.count, o2.project)));
|
|
12280
13145
|
program2.command("validate-id").argument("<id>").option("--series").action((id, o2) => exit(cmdValidateId(id, o2.series === true)));
|
|
12281
13146
|
return program2;
|
|
12282
13147
|
}
|