@fusebase/harness-lead 0.3.0 → 0.3.2
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/CHANGELOG.md +21 -0
- package/dist/lead.mjs +1322 -1158
- package/package.json +1 -1
- package/skills/lead/SKILL.md +1 -1
- package/skills/lead/delegates/codee/SKILL.md +2 -1
- package/skills/lead/references/status.md +2 -2
package/dist/lead.mjs
CHANGED
|
@@ -3973,10 +3973,10 @@ var require_resolve_block_map = __commonJS({
|
|
|
3973
3973
|
let offset = bm.offset;
|
|
3974
3974
|
let commentEnd = null;
|
|
3975
3975
|
for (const collItem of bm.items) {
|
|
3976
|
-
const { start, key, sep:
|
|
3976
|
+
const { start, key, sep: sep6, value } = collItem;
|
|
3977
3977
|
const keyProps = resolveProps.resolveProps(start, {
|
|
3978
3978
|
indicator: "explicit-key-ind",
|
|
3979
|
-
next: key ??
|
|
3979
|
+
next: key ?? sep6?.[0],
|
|
3980
3980
|
offset,
|
|
3981
3981
|
onError,
|
|
3982
3982
|
parentIndent: bm.indent,
|
|
@@ -3990,7 +3990,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
3990
3990
|
else if ("indent" in key && key.indent !== bm.indent)
|
|
3991
3991
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
3992
3992
|
}
|
|
3993
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
3993
|
+
if (!keyProps.anchor && !keyProps.tag && !sep6) {
|
|
3994
3994
|
commentEnd = keyProps.end;
|
|
3995
3995
|
if (keyProps.comment) {
|
|
3996
3996
|
if (map.comment)
|
|
@@ -4014,7 +4014,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4014
4014
|
ctx.atKey = false;
|
|
4015
4015
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
4016
4016
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
4017
|
-
const valueProps = resolveProps.resolveProps(
|
|
4017
|
+
const valueProps = resolveProps.resolveProps(sep6 ?? [], {
|
|
4018
4018
|
indicator: "map-value-ind",
|
|
4019
4019
|
next: value,
|
|
4020
4020
|
offset: keyNode.range[2],
|
|
@@ -4030,7 +4030,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4030
4030
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
4031
4031
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
4032
4032
|
}
|
|
4033
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
4033
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep6, null, valueProps, onError);
|
|
4034
4034
|
if (ctx.schema.compat)
|
|
4035
4035
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
4036
4036
|
offset = valueNode.range[2];
|
|
@@ -4121,7 +4121,7 @@ var require_resolve_end = __commonJS({
|
|
|
4121
4121
|
let comment = "";
|
|
4122
4122
|
if (end) {
|
|
4123
4123
|
let hasSpace = false;
|
|
4124
|
-
let
|
|
4124
|
+
let sep6 = "";
|
|
4125
4125
|
for (const token of end) {
|
|
4126
4126
|
const { source, type } = token;
|
|
4127
4127
|
switch (type) {
|
|
@@ -4135,13 +4135,13 @@ var require_resolve_end = __commonJS({
|
|
|
4135
4135
|
if (!comment)
|
|
4136
4136
|
comment = cb;
|
|
4137
4137
|
else
|
|
4138
|
-
comment +=
|
|
4139
|
-
|
|
4138
|
+
comment += sep6 + cb;
|
|
4139
|
+
sep6 = "";
|
|
4140
4140
|
break;
|
|
4141
4141
|
}
|
|
4142
4142
|
case "newline":
|
|
4143
4143
|
if (comment)
|
|
4144
|
-
|
|
4144
|
+
sep6 += source;
|
|
4145
4145
|
hasSpace = true;
|
|
4146
4146
|
break;
|
|
4147
4147
|
default:
|
|
@@ -4184,18 +4184,18 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4184
4184
|
let offset = fc.offset + fc.start.source.length;
|
|
4185
4185
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
4186
4186
|
const collItem = fc.items[i];
|
|
4187
|
-
const { start, key, sep:
|
|
4187
|
+
const { start, key, sep: sep6, value } = collItem;
|
|
4188
4188
|
const props = resolveProps.resolveProps(start, {
|
|
4189
4189
|
flow: fcName,
|
|
4190
4190
|
indicator: "explicit-key-ind",
|
|
4191
|
-
next: key ??
|
|
4191
|
+
next: key ?? sep6?.[0],
|
|
4192
4192
|
offset,
|
|
4193
4193
|
onError,
|
|
4194
4194
|
parentIndent: fc.indent,
|
|
4195
4195
|
startOnNewline: false
|
|
4196
4196
|
});
|
|
4197
4197
|
if (!props.found) {
|
|
4198
|
-
if (!props.anchor && !props.tag && !
|
|
4198
|
+
if (!props.anchor && !props.tag && !sep6 && !value) {
|
|
4199
4199
|
if (i === 0 && props.comma)
|
|
4200
4200
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
4201
4201
|
else if (i < fc.items.length - 1)
|
|
@@ -4249,8 +4249,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4249
4249
|
}
|
|
4250
4250
|
}
|
|
4251
4251
|
}
|
|
4252
|
-
if (!isMap && !
|
|
4253
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
4252
|
+
if (!isMap && !sep6 && !props.found) {
|
|
4253
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep6, null, props, onError);
|
|
4254
4254
|
coll.items.push(valueNode);
|
|
4255
4255
|
offset = valueNode.range[2];
|
|
4256
4256
|
if (isBlock(value))
|
|
@@ -4262,7 +4262,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4262
4262
|
if (isBlock(key))
|
|
4263
4263
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
4264
4264
|
ctx.atKey = false;
|
|
4265
|
-
const valueProps = resolveProps.resolveProps(
|
|
4265
|
+
const valueProps = resolveProps.resolveProps(sep6 ?? [], {
|
|
4266
4266
|
flow: fcName,
|
|
4267
4267
|
indicator: "map-value-ind",
|
|
4268
4268
|
next: value,
|
|
@@ -4273,8 +4273,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4273
4273
|
});
|
|
4274
4274
|
if (valueProps.found) {
|
|
4275
4275
|
if (!isMap && !props.found && ctx.options.strict) {
|
|
4276
|
-
if (
|
|
4277
|
-
for (const st of
|
|
4276
|
+
if (sep6)
|
|
4277
|
+
for (const st of sep6) {
|
|
4278
4278
|
if (st === valueProps.found)
|
|
4279
4279
|
break;
|
|
4280
4280
|
if (st.type === "newline") {
|
|
@@ -4291,7 +4291,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4291
4291
|
else
|
|
4292
4292
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
4293
4293
|
}
|
|
4294
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
4294
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep6, null, valueProps, onError) : null;
|
|
4295
4295
|
if (valueNode) {
|
|
4296
4296
|
if (isBlock(value))
|
|
4297
4297
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -4471,7 +4471,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4471
4471
|
chompStart = i + 1;
|
|
4472
4472
|
}
|
|
4473
4473
|
let value = "";
|
|
4474
|
-
let
|
|
4474
|
+
let sep6 = "";
|
|
4475
4475
|
let prevMoreIndented = false;
|
|
4476
4476
|
for (let i = 0; i < contentStart; ++i)
|
|
4477
4477
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
@@ -4488,24 +4488,24 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4488
4488
|
indent = "";
|
|
4489
4489
|
}
|
|
4490
4490
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
4491
|
-
value +=
|
|
4492
|
-
|
|
4491
|
+
value += sep6 + indent.slice(trimIndent) + content;
|
|
4492
|
+
sep6 = "\n";
|
|
4493
4493
|
} else if (indent.length > trimIndent || content[0] === " ") {
|
|
4494
|
-
if (
|
|
4495
|
-
|
|
4496
|
-
else if (!prevMoreIndented &&
|
|
4497
|
-
|
|
4498
|
-
value +=
|
|
4499
|
-
|
|
4494
|
+
if (sep6 === " ")
|
|
4495
|
+
sep6 = "\n";
|
|
4496
|
+
else if (!prevMoreIndented && sep6 === "\n")
|
|
4497
|
+
sep6 = "\n\n";
|
|
4498
|
+
value += sep6 + indent.slice(trimIndent) + content;
|
|
4499
|
+
sep6 = "\n";
|
|
4500
4500
|
prevMoreIndented = true;
|
|
4501
4501
|
} else if (content === "") {
|
|
4502
|
-
if (
|
|
4502
|
+
if (sep6 === "\n")
|
|
4503
4503
|
value += "\n";
|
|
4504
4504
|
else
|
|
4505
|
-
|
|
4505
|
+
sep6 = "\n";
|
|
4506
4506
|
} else {
|
|
4507
|
-
value +=
|
|
4508
|
-
|
|
4507
|
+
value += sep6 + content;
|
|
4508
|
+
sep6 = " ";
|
|
4509
4509
|
prevMoreIndented = false;
|
|
4510
4510
|
}
|
|
4511
4511
|
}
|
|
@@ -4687,25 +4687,25 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
4687
4687
|
if (!match)
|
|
4688
4688
|
return source;
|
|
4689
4689
|
let res = match[1];
|
|
4690
|
-
let
|
|
4690
|
+
let sep6 = " ";
|
|
4691
4691
|
let pos = first.lastIndex;
|
|
4692
4692
|
line.lastIndex = pos;
|
|
4693
4693
|
while (match = line.exec(source)) {
|
|
4694
4694
|
if (match[1] === "") {
|
|
4695
|
-
if (
|
|
4696
|
-
res +=
|
|
4695
|
+
if (sep6 === "\n")
|
|
4696
|
+
res += sep6;
|
|
4697
4697
|
else
|
|
4698
|
-
|
|
4698
|
+
sep6 = "\n";
|
|
4699
4699
|
} else {
|
|
4700
|
-
res +=
|
|
4701
|
-
|
|
4700
|
+
res += sep6 + match[1];
|
|
4701
|
+
sep6 = " ";
|
|
4702
4702
|
}
|
|
4703
4703
|
pos = line.lastIndex;
|
|
4704
4704
|
}
|
|
4705
4705
|
const last = /[ \t]*(.*)/sy;
|
|
4706
4706
|
last.lastIndex = pos;
|
|
4707
4707
|
match = last.exec(source);
|
|
4708
|
-
return res +
|
|
4708
|
+
return res + sep6 + (match?.[1] ?? "");
|
|
4709
4709
|
}
|
|
4710
4710
|
function doubleQuotedValue(source, onError) {
|
|
4711
4711
|
let res = "";
|
|
@@ -5508,14 +5508,14 @@ var require_cst_stringify = __commonJS({
|
|
|
5508
5508
|
}
|
|
5509
5509
|
}
|
|
5510
5510
|
}
|
|
5511
|
-
function stringifyItem({ start, key, sep:
|
|
5511
|
+
function stringifyItem({ start, key, sep: sep6, value }) {
|
|
5512
5512
|
let res = "";
|
|
5513
5513
|
for (const st of start)
|
|
5514
5514
|
res += st.source;
|
|
5515
5515
|
if (key)
|
|
5516
5516
|
res += stringifyToken(key);
|
|
5517
|
-
if (
|
|
5518
|
-
for (const st of
|
|
5517
|
+
if (sep6)
|
|
5518
|
+
for (const st of sep6)
|
|
5519
5519
|
res += st.source;
|
|
5520
5520
|
if (value)
|
|
5521
5521
|
res += stringifyToken(value);
|
|
@@ -6665,18 +6665,18 @@ var require_parser = __commonJS({
|
|
|
6665
6665
|
if (this.type === "map-value-ind") {
|
|
6666
6666
|
const prev = getPrevProps(this.peek(2));
|
|
6667
6667
|
const start = getFirstKeyStartProps(prev);
|
|
6668
|
-
let
|
|
6668
|
+
let sep6;
|
|
6669
6669
|
if (scalar.end) {
|
|
6670
|
-
|
|
6671
|
-
|
|
6670
|
+
sep6 = scalar.end;
|
|
6671
|
+
sep6.push(this.sourceToken);
|
|
6672
6672
|
delete scalar.end;
|
|
6673
6673
|
} else
|
|
6674
|
-
|
|
6674
|
+
sep6 = [this.sourceToken];
|
|
6675
6675
|
const map = {
|
|
6676
6676
|
type: "block-map",
|
|
6677
6677
|
offset: scalar.offset,
|
|
6678
6678
|
indent: scalar.indent,
|
|
6679
|
-
items: [{ start, key: scalar, sep:
|
|
6679
|
+
items: [{ start, key: scalar, sep: sep6 }]
|
|
6680
6680
|
};
|
|
6681
6681
|
this.onKeyLine = true;
|
|
6682
6682
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -6829,15 +6829,15 @@ var require_parser = __commonJS({
|
|
|
6829
6829
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
6830
6830
|
const start2 = getFirstKeyStartProps(it.start);
|
|
6831
6831
|
const key = it.key;
|
|
6832
|
-
const
|
|
6833
|
-
|
|
6832
|
+
const sep6 = it.sep;
|
|
6833
|
+
sep6.push(this.sourceToken);
|
|
6834
6834
|
delete it.key;
|
|
6835
6835
|
delete it.sep;
|
|
6836
6836
|
this.stack.push({
|
|
6837
6837
|
type: "block-map",
|
|
6838
6838
|
offset: this.offset,
|
|
6839
6839
|
indent: this.indent,
|
|
6840
|
-
items: [{ start: start2, key, sep:
|
|
6840
|
+
items: [{ start: start2, key, sep: sep6 }]
|
|
6841
6841
|
});
|
|
6842
6842
|
} else if (start.length > 0) {
|
|
6843
6843
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -7021,13 +7021,13 @@ var require_parser = __commonJS({
|
|
|
7021
7021
|
const prev = getPrevProps(parent);
|
|
7022
7022
|
const start = getFirstKeyStartProps(prev);
|
|
7023
7023
|
fixFlowSeqItems(fc);
|
|
7024
|
-
const
|
|
7025
|
-
|
|
7024
|
+
const sep6 = fc.end.splice(1, fc.end.length);
|
|
7025
|
+
sep6.push(this.sourceToken);
|
|
7026
7026
|
const map = {
|
|
7027
7027
|
type: "block-map",
|
|
7028
7028
|
offset: fc.offset,
|
|
7029
7029
|
indent: fc.indent,
|
|
7030
|
-
items: [{ start, key: fc, sep:
|
|
7030
|
+
items: [{ start, key: fc, sep: sep6 }]
|
|
7031
7031
|
};
|
|
7032
7032
|
this.onKeyLine = true;
|
|
7033
7033
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -7306,8 +7306,8 @@ var require_dist = __commonJS({
|
|
|
7306
7306
|
});
|
|
7307
7307
|
|
|
7308
7308
|
// src/cli.ts
|
|
7309
|
-
import { mkdirSync as mkdirSync14, realpathSync as
|
|
7310
|
-
import { dirname as dirname6, join as
|
|
7309
|
+
import { mkdirSync as mkdirSync14, realpathSync as realpathSync6, writeFileSync as writeFileSync15 } from "node:fs";
|
|
7310
|
+
import { dirname as dirname6, join as join32, resolve as resolve3 } from "node:path";
|
|
7311
7311
|
import { fileURLToPath } from "node:url";
|
|
7312
7312
|
|
|
7313
7313
|
// src/check.ts
|
|
@@ -7335,17 +7335,17 @@ function findCycles(tasks) {
|
|
|
7335
7335
|
const state = /* @__PURE__ */ new Map();
|
|
7336
7336
|
const cycles = [];
|
|
7337
7337
|
const stack = [];
|
|
7338
|
-
const visit = (
|
|
7339
|
-
if (state.get(
|
|
7340
|
-
if (state.get(
|
|
7341
|
-
cycles.push([...stack.slice(stack.indexOf(
|
|
7338
|
+
const visit = (id2) => {
|
|
7339
|
+
if (state.get(id2) === "done") return;
|
|
7340
|
+
if (state.get(id2) === "visiting") {
|
|
7341
|
+
cycles.push([...stack.slice(stack.indexOf(id2)), id2]);
|
|
7342
7342
|
return;
|
|
7343
7343
|
}
|
|
7344
|
-
state.set(
|
|
7345
|
-
stack.push(
|
|
7346
|
-
for (const dep of byId.get(
|
|
7344
|
+
state.set(id2, "visiting");
|
|
7345
|
+
stack.push(id2);
|
|
7346
|
+
for (const dep of byId.get(id2)?.blocked_by ?? []) if (byId.has(dep)) visit(dep);
|
|
7347
7347
|
stack.pop();
|
|
7348
|
-
state.set(
|
|
7348
|
+
state.set(id2, "done");
|
|
7349
7349
|
};
|
|
7350
7350
|
for (const t of [...tasks].sort((a, b) => a.id.localeCompare(b.id))) visit(t.id);
|
|
7351
7351
|
return cycles;
|
|
@@ -7354,12 +7354,12 @@ function computeWaves(tasks, sharedPaths) {
|
|
|
7354
7354
|
if (findCycles(tasks).length) return void 0;
|
|
7355
7355
|
const byId = new Map(tasks.map((t) => [t.id, t]));
|
|
7356
7356
|
const layer = /* @__PURE__ */ new Map();
|
|
7357
|
-
const layerOf = (
|
|
7358
|
-
const known = layer.get(
|
|
7357
|
+
const layerOf = (id2) => {
|
|
7358
|
+
const known = layer.get(id2);
|
|
7359
7359
|
if (known !== void 0) return known;
|
|
7360
|
-
const deps = (byId.get(
|
|
7360
|
+
const deps = (byId.get(id2)?.blocked_by ?? []).filter((d) => byId.has(d));
|
|
7361
7361
|
const l = deps.length ? Math.max(...deps.map(layerOf)) + 1 : 1;
|
|
7362
|
-
layer.set(
|
|
7362
|
+
layer.set(id2, l);
|
|
7363
7363
|
return l;
|
|
7364
7364
|
};
|
|
7365
7365
|
const ordered = [...tasks].sort((a, b) => layerOf(a.id) - layerOf(b.id) || a.id.localeCompare(b.id));
|
|
@@ -7457,10 +7457,10 @@ function runs(root) {
|
|
|
7457
7457
|
return [...new Map(readLog(root, "runs").map((run2) => [run2.id, run2])).values()];
|
|
7458
7458
|
}
|
|
7459
7459
|
function recordRun(root, data) {
|
|
7460
|
-
const
|
|
7461
|
-
const existing = runs(root).find((run3) => run3.id ===
|
|
7460
|
+
const id2 = digest(data);
|
|
7461
|
+
const existing = runs(root).find((run3) => run3.id === id2);
|
|
7462
7462
|
if (existing) return existing;
|
|
7463
|
-
const run2 = { version: 1, id, at: (/* @__PURE__ */ new Date()).toISOString(), ...data };
|
|
7463
|
+
const run2 = { version: 1, id: id2, at: (/* @__PURE__ */ new Date()).toISOString(), ...data };
|
|
7464
7464
|
appendLog(root, "runs", run2);
|
|
7465
7465
|
return run2;
|
|
7466
7466
|
}
|
|
@@ -7534,6 +7534,27 @@ function validateMockupSwarm(root, workDir, input) {
|
|
|
7534
7534
|
return { personas, findings: rows, files: [...files2] };
|
|
7535
7535
|
}
|
|
7536
7536
|
|
|
7537
|
+
// src/templates.gen.ts
|
|
7538
|
+
var TEMPLATES = {
|
|
7539
|
+
"AGENTS.block.md": "<!-- lead:begin -->\n## lead (optional)\n\nThis repo can be worked with lead, a dev-loop kit. It is opt-in: ignore this section unless the person runs `/lead` (Claude Code) or `$lead` (Codex) or asks to use lead.\n\nWhen lead is used:\n- Plans and tasks live in `work/` (or `<project>/work/`); settings in `.lead/config.yml`; repo rules for lead in `.lead/local.md` and `.lead/local/`.\n- A lead task is done only when `node .lead/lead.mjs finish` succeeded.\n- Do not edit lead's own files (`.lead/lead.mjs`, `.agents/skills/lead*`, `.claude/skills/lead*`); an update replaces them.\n- A delegated service lives only in its skill (`\u2026/lead/delegates/<id>/` or `.lead/delegates/<id>/`). How it works, handoff, and check stay there; do not copy them into other lead files.\n- A Cursor `/goal` is not started by lead. When a goal is active here, follow the `lead-goal` skill: a short heartbeat every reply, and append events with `node .lead/lead.mjs activity` into `.lead/activity/` (for later harness analysis).\n<!-- lead:end -->\n",
|
|
7540
|
+
"config.yml": 'version: 1\n# planning: adopted # existing product with an established One Pager and tracker\n# Commands that verify a task. {name} is the project name in a monorepo.\nchecks: {}\nlimits:\n wip: 3 # tasks in progress at once\n rounds: 5 # do-and-check rounds before asking a human\n reviews: 3 # independent reviews before asking a human\n minutes: 60 # wall time on one task before stopping to report\n# projects: # uncomment for a repo with several projects\n# glob: apps/*\n# create: pnpm new {name}\n# work_dir: "{path}/work"\nshared_paths: []\n# worktree_setup: pnpm install --offline --frozen-lockfile # run once in each new task worktree\nreview: task\n# qa: # browser QA in reviews and /lead qa\n# run: pnpm dev {name}\n# url: http://localhost:5173\n# ready: Local:\n# can_show: deployed # one-pager "Can show now" needs `deployed:` on the task, not just a merge\n# sync: # /lead sync to FuseBase and Jira\n# fusebase: {org: <org id>, workspace: <workspace id>, parent_folder: <folder id>}\n# jira: {site: <site>.atlassian.net, project: <KEY>, epic: <KEY-1>}\n# links:\n# repo: https://gitlab.example.com/group/repo # web address; file links and merge requests\n# branch: main\n# app: https://dev.example.com/app # running instance, shown in the one-pager and issues\n',
|
|
7541
|
+
"how.md": 'HOW TO WORK WITH LEAD\n\n /lead say what you want in plain words; lead shows the state and the next step\n /lead how this page /lead help all commands\n /lead enable lead is off by default for each person; this turns on its hooks for you\n\nTHE FLOW YOU (a person)\n 1 plan research or reverse \u2192 flows \u2192 mockups \u25C0\u2500\u2500 confirm the spec (flows, mockups, acceptance)\n \u2192 acceptance \u2192 architecture \u2192 tasks\n 2 build per task: worktree \u2192 code \u2192 checks\n \u2192 independent review with browser QA \u25C0\u2500\u2500 answer questions in "Needs you"\n \u2192 finish (waits for you) \u25C0\u2500\u2500 review and merge the branch\n 3 accept milestone QA in the browser \u25C0\u2500\u2500 decide "good enough": close the milestone,\n move the rest to the next one\n 4 share /lead sync \u2192 FuseBase notes, Jira \u25C0\u2500\u2500 one yes for note updates (if you have access)\n\nSTAGES\n Each bar starts when the previous stage ends. The dates are a reading order, not a plan.\n\n```mermaid\ngantt\n title Project stages\n dateFormat YYYY-MM-DD\n axisFormat %b %d\n\n section Plan\n Research :p1, 2026-01-01, 7d\n Flows :p2, after p1, 7d\n Mockups :p3, after p2, 7d\n Acceptance :p4, after p3, 7d\n Architecture :p5, after p4, 7d\n Tasks :p6, after p5, 7d\n\n section Build\n Build :b1, after p6, 7d\n Review :b2, after b1, 7d\n\n section Accept\n Milestone QA :c1, after b2, 7d\n\n section Share\n Sync :s1, after c1, 7d\n```\n\nWHERE THINGS ARE\n work/one-pager.md for the business: milestones, what can be shown, risks\n work/board.md for the team: ready, in progress, in review, needs you, waves\n work/spec.md the product, assembled from work/spec/ (do not edit spec.md itself)\n work/tasks/ one file per task: criteria, checks, review, questions\n .lead/config.yml checks, projects, sync, QA .lead/local* your rules (kept on update)\n\nRULES THAT MATTER\n \xB7 A task is done only when finish succeeded: checks recorded on the final code, every\n criterion pass, an independent review. "It works" in chat is not done.\n \xB7 A confirmed spec section changes only after you reopen it.\n \xB7 Work stopped midway (limit, computer off)? Run /lead: it offers to continue.\n \xB7 Keep work/ and .lead/config.yml in git: they are the shared state.\n',
|
|
7542
|
+
"local-README.md": "# Project rules for lead skills\n\nFiles here are yours: `lead update` never changes them. Each adds rules on top of one lead skill reference:\n\n- `plan.md` \u2014 planning, spec stages, mockups\n- `task.md` \u2014 doing a task\n- `review.md` / `qa.md` \u2014 review and browser QA\n- `sync.md` \u2014 FuseBase / Jira sync\n- `reverse.md` \u2014 studying a running product\n\nGeneral rules for this repo go to `.lead/local.md`. Do not edit lead's own files (`.lead/lead.mjs`, `.agents/skills/lead*`, `.claude/skills/lead*`): an update replaces them.\n",
|
|
7543
|
+
"local.md": "# Project rules for lead\n\nRules in plain words that lead's skills follow on top of their own. Examples:\n\n- Never edit an existing migration; add the next numbered one.\n- UI tasks are also checked in Safari.\n",
|
|
7544
|
+
"spec-01-research.md": "---\nstage: research\nstatus: draft\n---\n## 1. Research\n\nThe long note before implementation. Product language. No source of another product copied verbatim. Write `unknown` where you did not look. Conclusions are the only part repeated on the one-pager.\n\n### Users and the problem\n\nWho it is for, what they do today, and what is painful.\n\n### What already exists\n\nDocs, a running product, or the code as it is. Name what was read.\n\n### Constraints\n\nLicense, access, data that must not move, and decisions already made.\n\n### Unknown\n\nWhat was not checked, and what would change the plan if it turned out otherwise.\n\n### Conclusions\n\nA few decisions the rest of the spec follows. Not a summary of the sections above.\n\n## Questions to earlier stages\n",
|
|
7545
|
+
"spec-02-flows.md": "---\nstage: flows\nstatus: draft\n---\n## 2. Flows\n\n### 2.1 Roles and what each sees\n\n### 2.2 Journey map\n\n### 2.3 Stages\n\n<!-- For each stage: how a record appears, statuses and their meaning, what is needed to leave, side effects. A state diagram only where transitions are real. -->\n\n### 2.4 Numbers\n\n<!-- For each number or chart: population, time window, aggregation, exceptions. -->\n\n### 2.5 Links between records\n\n## Questions to earlier stages\n",
|
|
7546
|
+
"spec-03-mockups.md": "---\nstage: mockups\nstatus: draft\n---\n## 3. Screens\n\n<!-- One entry per screen: purpose, what is on it, states (empty, loading, error), link to work/mockups/<screen>.html. -->\n\n## Questions to earlier stages\n",
|
|
7547
|
+
"spec-04-acceptance.md": "---\nstage: acceptance\nstatus: draft\n---\n## 4. Acceptance\n\n<!-- Per scenario and screen: steps a browser can follow and what must be seen. Mark places that need a person as `needs human`. -->\n\n## Questions to earlier stages\n",
|
|
7548
|
+
"task.md": '---\nid: T-001\ntitle: ""\nmilestone: mvp\ndemo: ""\nstatus: todo\ntype: feature\nblocked_by: []\ntouches: []\nqa_required: []\n# sync_jira: false # Keep this task outside Jira.\nwave: null\nclaim: null\nbranch: null\nchecks_run: null\nrounds: 0\nowner: ""\n---\n## Goal\n\n<!-- For FuseBase publication, write the full spec in work/task-specs/<task-id>.md using the task note template. -->\n<!-- For a new product feature, record its dedicated flag key, off fallback, dev-on and production-off settings. Add acceptance checks for both flag states. -->\n\n## Acceptance criteria\n\n- [not_tested] \n\n## Verification\n\n## Rounds\n\n## Summary\n',
|
|
7549
|
+
"workspace-crew.md": "---\nname: crew-lead\ndescription: Run the lead workflow. Use only when the user invokes /crew-lead or $crew-lead.\n---\n<!-- evercrew:workspace-entry -->\nFollow the adjacent `../lead/SKILL.md` entry point as if the user invoked lead. Pass through the request and its arguments.\n",
|
|
7550
|
+
"workspace-entry.md": "---\nname: lead\ndescription: Run lead for this project or show the workspace overview. Use when the user types /lead or $lead, asks to use lead, or asks for an overview of all workspace projects.\n---\n<!-- evercrew:workspace-entry -->\nIf the session context already names the lead launcher and kit, use them and skip the next two steps. Otherwise find the nearest `.lead/lead.mjs` from the directory this conversation started in. Preserve that starting directory as `--cwd` on the first call. Run `node <launcher> kit-path`, then read `skills/lead/SKILL.md` from the returned kit directory and follow it. References are relative to that kit directory. Keep the same session ID throughout this conversation. The launcher and kit path are local setup, not product state.\n",
|
|
7551
|
+
"workspace-goal.md": "---\nname: lead-goal\ndescription: Record lead activity and keep the heartbeat for an active Cursor goal.\n---\n<!-- evercrew:workspace-entry -->\nRun `node .lead/lead.mjs kit-path` from the lead workspace or target checkout, then read `skills/lead-goal/SKILL.md` from the returned kit directory. Use the same repository scope and session ID as lead.\n",
|
|
7552
|
+
"workspace-launcher.mjs": "#!/usr/bin/env node\n// evercrew:workspace-entry\n// Portable entry point. The runtime belongs to the workspace or to the user's npm cache.\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdirSync, realpathSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst args = process.argv.slice(2);\nconst here = dirname(dirname(fileURLToPath(import.meta.url)));\nconst hook = args[0] === 'stop-check' || args[0] === 'session-start';\nconst cwdFlag = args.indexOf('--cwd');\nconst cwd = cwdFlag >= 0 && args[cwdFlag + 1] ? resolve(args[cwdFlag + 1]) : process.cwd();\nconst cli = (kit) => join(kit, 'dist/lead.mjs');\n\nfunction workspaceKit(start) {\n let dir = realpathSync(start);\n while (true) {\n if (existsSync(join(dir, '.lead/workspace.yml'))) {\n const kit = join(dir, '.lead/workspace-kit');\n if (existsSync(cli(kit))) return kit;\n if (hook) return;\n throw new Error(`The lead workspace at ${dir} has no runtime. Deploy its kit first.`);\n }\n if (dirname(dir) === dir) return;\n dir = dirname(dir);\n }\n}\n\nfunction run(bin, argv, diagnosticsOnly = false) {\n const result = spawnSync(bin, argv, { stdio: diagnosticsOnly ? ['inherit', 2, 2] : 'inherit', env: bin === 'npm' ? { ...process.env, 'npm_config_@fusebase:registry': 'https://registry.npmjs.org/' } : process.env });\n if (result.error) throw result.error;\n return result.status ?? 1;\n}\n\nfunction main() {\n const shared = workspaceKit(cwd) ?? workspaceKit(here);\n const installed = join(here, 'node_modules/@fusebase/harness-lead');\n const cache = join(process.env.XDG_CACHE_HOME || join(homedir(), '.cache'), 'harness-lead', 'standalone');\n const cached = join(cache, 'node_modules/@fusebase/harness-lead');\n let kit = shared ?? (existsSync(cli(cached)) ? cached : installed);\n if (!shared && (args[0] === 'update' || !existsSync(cli(kit)))) {\n if (hook) return 0;\n if (args[0] === 'update' && args.length > 1) throw new Error('Standalone launcher update refreshes the user cache. Run the chosen kit directly for an explicit source.');\n mkdirSync(cache, { recursive: true });\n const status = run('npm', ['install', '--prefix', cache, '--no-save', '--no-package-lock', '--ignore-scripts', '--no-audit', '--no-fund',\n args[0] === 'update' ? '@fusebase/harness-lead@latest' : '@fusebase/harness-lead@0.3.2'], true);\n if (status || !existsSync(cli(cached))) return status || 1;\n kit = cached;\n if (args[0] === 'update') return run(process.execPath, [cli(kit), 'version']);\n }\n if (args[0] === 'kit-path') {\n console.log(realpathSync(kit));\n return 0;\n }\n return run(process.execPath, [cli(kit), ...args]);\n}\n\ntry { process.exitCode = main(); }\ncatch (error) {\n if (!hook) console.error(`lead: ${error.message}`);\n process.exitCode = hook ? 0 : 1;\n}\n",
|
|
7553
|
+
"backlog-index.md": '# <Project> Backlog\n\n[One Pager](one-pager.md)\n\n## Reviewed backlog\n\n<!-- evercrew:view kind="proposals" -->\n<!-- /evercrew:view -->\n\n## Needs triage\n\n<!-- For each candidate, link the task note and record what needs clarification. -->\n\n## Triage decisions\n\n<!-- Link source evidence and explain why an item was linked, completed, deferred or superseded. -->\n\n## History\n\n<!-- Link the complete source reconciliation, including repeated entries. -->\n',
|
|
7554
|
+
"one-pager.md": '---\nmilestones:\n - id: mvp\n title: MVP\n shows: ""\n status: current\n---\n# <Project> \u2014 One Pager\n\n## Status now\n\n<!-- 3\u20134 sentences, written by a human. -->\n\n**What to show.**\n\n**What landed.**\n\n**Evidence.** <!-- Add the date, source revision, checks and open verification. -->\n\n<!-- evercrew:view kind="stats" -->\n<!-- /evercrew:view -->\n\n## Needs attention\n\n<!-- Decisions and immediate checks. Link the evidence and name the owner when known. -->\n\n## Product bet\n\n<!-- One sentence. -->\n\n## Research\n\nConclusions only. The long note is [the research](spec/01-research.md).\n\n<!-- Paste ### Conclusions from spec/01-research.md. Do not paste the rest. -->\n\n## Readiness\n\n<!-- evercrew:view kind="readiness" -->\n<!-- /evercrew:view -->\n\n## Roadmap\n\n<!-- evercrew:view kind="order" -->\n<!-- /evercrew:view -->\n\n## Next 3 steps\n\n<!-- evercrew:view kind="next-steps" -->\n<!-- /evercrew:view -->\n\n## Inbox triage\n\nTick an item when the team agrees to take it into the plan. Review higher priorities first, then use list order within each priority.\n\n<!-- Example: add real rows and remove this comment.\n:::checklist[Take into the plan]\n::check[:badge[Feature request]{tone="info"} :badge[High]{tone="danger"} Task summary \xB7 [Task note](tasks/T-001-example.md)]{done="false"}\n:::\n-->\n\n## Next versions (do not promise on a demo)\n\n## Reference\n\n- [Execution board](board.md)\n- [Backlog and triage decisions](backlog.md)\n<!-- Link history, architecture and QA evidence once available. -->\n',
|
|
7555
|
+
"task-note.md": "# <Task summary>\n\n## Links\n\n<!-- Fill the links or document permitted exceptions before publishing. -->\n\n- [Epic](https://example.invalid/epic)\n- [Jira Story](https://example.invalid/story)\n- [Proposal](https://example.invalid/proposal)\n- [Mockup](https://example.invalid/mockup)\n- [One Pager](https://example.invalid/one-pager)\n\n## Goal\n\n<!-- Describe the user need and intended outcome. -->\n\n## User flow\n\n<!-- Add a Mermaid diagram covering the requested path. -->\n\n## Technical design\n\n<!-- Describe changes, interfaces, and relevant constraints. -->\n\n## Decisions\n\n<!-- Record agreed decisions and tradeoffs. -->\n\n## Acceptance criteria\n\n<!-- State observable checks and expected results. -->\n\n## Out of scope\n\n<!-- Name exclusions or say whether there are none. -->\n"
|
|
7556
|
+
};
|
|
7557
|
+
|
|
7537
7558
|
// src/spec.ts
|
|
7538
7559
|
var LOCKS = ".confirmed.json";
|
|
7539
7560
|
var hash = (s) => createHash2("sha256").update(s.trim()).digest("hex").slice(0, 16);
|
|
@@ -7613,6 +7634,15 @@ function setSectionStatus(root, workDir, name, status2, project = ".") {
|
|
|
7613
7634
|
writeLocks(workDir, locks);
|
|
7614
7635
|
return `${s.name}: ${status2}`;
|
|
7615
7636
|
}
|
|
7637
|
+
var TEMPLATE_OF = { research: "spec-01-research.md", flows: "spec-02-flows.md", mockups: "spec-03-mockups.md", acceptance: "spec-04-acceptance.md" };
|
|
7638
|
+
var squash = (text) => text.replace(/<!--[\s\S]*?-->/g, "").replace(/\s+/g, " ").trim();
|
|
7639
|
+
function isUntouchedTemplate(name, body) {
|
|
7640
|
+
const key = TEMPLATE_OF[name];
|
|
7641
|
+
const template = key ? TEMPLATES[key] : void 0;
|
|
7642
|
+
if (!template) return false;
|
|
7643
|
+
const { parsed } = parseFrontmatter(template, key);
|
|
7644
|
+
return !!parsed && squash(parsed.body) === squash(body);
|
|
7645
|
+
}
|
|
7616
7646
|
|
|
7617
7647
|
// src/check.ts
|
|
7618
7648
|
var SECRET_PATTERNS = [
|
|
@@ -8195,27 +8225,6 @@ import { createHash as createHash3 } from "node:crypto";
|
|
|
8195
8225
|
import { copyFileSync, existsSync as existsSync10, mkdirSync as mkdirSync3, readdirSync as readdirSync6, readFileSync as readFileSync9, statSync as statSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
8196
8226
|
import { dirname as dirname2, join as join11, relative as relative7 } from "node:path";
|
|
8197
8227
|
|
|
8198
|
-
// src/templates.gen.ts
|
|
8199
|
-
var TEMPLATES = {
|
|
8200
|
-
"AGENTS.block.md": "<!-- lead:begin -->\n## lead (optional)\n\nThis repo can be worked with lead, a dev-loop kit. It is opt-in: ignore this section unless the person runs `/lead` (Claude Code) or `$lead` (Codex) or asks to use lead.\n\nWhen lead is used:\n- Plans and tasks live in `work/` (or `<project>/work/`); settings in `.lead/config.yml`; repo rules for lead in `.lead/local.md` and `.lead/local/`.\n- A lead task is done only when `node .lead/lead.mjs finish` succeeded.\n- Do not edit lead's own files (`.lead/lead.mjs`, `.agents/skills/lead*`, `.claude/skills/lead*`); an update replaces them.\n- A delegated service lives only in its skill (`\u2026/lead/delegates/<id>/` or `.lead/delegates/<id>/`). How it works, handoff, and check stay there; do not copy them into other lead files.\n- A Cursor `/goal` is not started by lead. When a goal is active here, follow the `lead-goal` skill: a short heartbeat every reply, and append events with `node .lead/lead.mjs activity` into `.lead/activity/` (for later harness analysis).\n<!-- lead:end -->\n",
|
|
8201
|
-
"config.yml": 'version: 1\n# planning: adopted # existing product with an established One Pager and tracker\n# Commands that verify a task. {name} is the project name in a monorepo.\nchecks: {}\nlimits:\n wip: 3 # tasks in progress at once\n rounds: 5 # do-and-check rounds before asking a human\n reviews: 3 # independent reviews before asking a human\n minutes: 60 # wall time on one task before stopping to report\n# projects: # uncomment for a repo with several projects\n# glob: apps/*\n# create: pnpm new {name}\n# work_dir: "{path}/work"\nshared_paths: []\n# worktree_setup: pnpm install --offline --frozen-lockfile # run once in each new task worktree\nreview: task\n# qa: # browser QA in reviews and /lead qa\n# run: pnpm dev {name}\n# url: http://localhost:5173\n# ready: Local:\n# can_show: deployed # one-pager "Can show now" needs `deployed:` on the task, not just a merge\n# sync: # /lead sync to FuseBase and Jira\n# fusebase: {org: <org id>, workspace: <workspace id>, parent_folder: <folder id>}\n# jira: {site: <site>.atlassian.net, project: <KEY>, epic: <KEY-1>}\n# links:\n# repo: https://gitlab.example.com/group/repo # web address; file links and merge requests\n# branch: main\n# app: https://dev.example.com/app # running instance, shown in the one-pager and issues\n',
|
|
8202
|
-
"how.md": 'HOW TO WORK WITH LEAD\n\n /lead say what you want in plain words; lead shows the state and the next step\n /lead how this page /lead help all commands\n /lead enable lead is off by default for each person; this turns on its hooks for you\n\nTHE FLOW YOU (a person)\n 1 plan research or reverse \u2192 flows \u2192 mockups \u25C0\u2500\u2500 confirm the spec (flows, mockups, acceptance)\n \u2192 acceptance \u2192 architecture \u2192 tasks\n 2 build per task: worktree \u2192 code \u2192 checks\n \u2192 independent review with browser QA \u25C0\u2500\u2500 answer questions in "Needs you"\n \u2192 finish (waits for you) \u25C0\u2500\u2500 review and merge the branch\n 3 accept milestone QA in the browser \u25C0\u2500\u2500 decide "good enough": close the milestone,\n move the rest to the next one\n 4 share /lead sync \u2192 FuseBase notes, Jira \u25C0\u2500\u2500 one yes for note updates (if you have access)\n\nSTAGES\n Each bar starts when the previous stage ends. The dates are a reading order, not a plan.\n\n```mermaid\ngantt\n title Project stages\n dateFormat YYYY-MM-DD\n axisFormat %b %d\n\n section Plan\n Research :p1, 2026-01-01, 7d\n Flows :p2, after p1, 7d\n Mockups :p3, after p2, 7d\n Acceptance :p4, after p3, 7d\n Architecture :p5, after p4, 7d\n Tasks :p6, after p5, 7d\n\n section Build\n Build :b1, after p6, 7d\n Review :b2, after b1, 7d\n\n section Accept\n Milestone QA :c1, after b2, 7d\n\n section Share\n Sync :s1, after c1, 7d\n```\n\nWHERE THINGS ARE\n work/one-pager.md for the business: milestones, what can be shown, risks\n work/board.md for the team: ready, in progress, in review, needs you, waves\n work/spec.md the product, assembled from work/spec/ (do not edit spec.md itself)\n work/tasks/ one file per task: criteria, checks, review, questions\n .lead/config.yml checks, projects, sync, QA .lead/local* your rules (kept on update)\n\nRULES THAT MATTER\n \xB7 A task is done only when finish succeeded: checks recorded on the final code, every\n criterion pass, an independent review. "It works" in chat is not done.\n \xB7 A confirmed spec section changes only after you reopen it.\n \xB7 Work stopped midway (limit, computer off)? Run /lead: it offers to continue.\n \xB7 Keep work/ and .lead/config.yml in git: they are the shared state.\n',
|
|
8203
|
-
"local-README.md": "# Project rules for lead skills\n\nFiles here are yours: `lead update` never changes them. Each adds rules on top of one lead skill reference:\n\n- `plan.md` \u2014 planning, spec stages, mockups\n- `task.md` \u2014 doing a task\n- `review.md` / `qa.md` \u2014 review and browser QA\n- `sync.md` \u2014 FuseBase / Jira sync\n- `reverse.md` \u2014 studying a running product\n\nGeneral rules for this repo go to `.lead/local.md`. Do not edit lead's own files (`.lead/lead.mjs`, `.agents/skills/lead*`, `.claude/skills/lead*`): an update replaces them.\n",
|
|
8204
|
-
"local.md": "# Project rules for lead\n\nRules in plain words that lead's skills follow on top of their own. Examples:\n\n- Never edit an existing migration; add the next numbered one.\n- UI tasks are also checked in Safari.\n",
|
|
8205
|
-
"spec-01-research.md": "---\nstage: research\nstatus: draft\n---\n## 1. Research\n\nThe long note before implementation. Product language. No source of another product copied verbatim. Write `unknown` where you did not look. Conclusions are the only part repeated on the one-pager.\n\n### Users and the problem\n\nWho it is for, what they do today, and what is painful.\n\n### What already exists\n\nDocs, a running product, or the code as it is. Name what was read.\n\n### Constraints\n\nLicense, access, data that must not move, and decisions already made.\n\n### Unknown\n\nWhat was not checked, and what would change the plan if it turned out otherwise.\n\n### Conclusions\n\nA few decisions the rest of the spec follows. Not a summary of the sections above.\n\n## Questions to earlier stages\n",
|
|
8206
|
-
"spec-02-flows.md": "---\nstage: flows\nstatus: draft\n---\n## 2. Flows\n\n### 2.1 Roles and what each sees\n\n### 2.2 Journey map\n\n### 2.3 Stages\n\n<!-- For each stage: how a record appears, statuses and their meaning, what is needed to leave, side effects. A state diagram only where transitions are real. -->\n\n### 2.4 Numbers\n\n<!-- For each number or chart: population, time window, aggregation, exceptions. -->\n\n### 2.5 Links between records\n\n## Questions to earlier stages\n",
|
|
8207
|
-
"spec-03-mockups.md": "---\nstage: mockups\nstatus: draft\n---\n## 3. Screens\n\n<!-- One entry per screen: purpose, what is on it, states (empty, loading, error), link to work/mockups/<screen>.html. -->\n\n## Questions to earlier stages\n",
|
|
8208
|
-
"spec-04-acceptance.md": "---\nstage: acceptance\nstatus: draft\n---\n## 4. Acceptance\n\n<!-- Per scenario and screen: steps a browser can follow and what must be seen. Mark places that need a person as `needs human`. -->\n\n## Questions to earlier stages\n",
|
|
8209
|
-
"task.md": '---\nid: T-001\ntitle: ""\nmilestone: mvp\ndemo: ""\nstatus: todo\ntype: feature\nblocked_by: []\ntouches: []\nqa_required: []\n# sync_jira: false # Keep this task outside Jira.\nwave: null\nclaim: null\nbranch: null\nchecks_run: null\nrounds: 0\nowner: ""\n---\n## Goal\n\n<!-- For FuseBase publication, write the full spec in work/task-specs/<task-id>.md using the task note template. -->\n<!-- For a new product feature, record its dedicated flag key, off fallback, dev-on and production-off settings. Add acceptance checks for both flag states. -->\n\n## Acceptance criteria\n\n- [not_tested] \n\n## Verification\n\n## Rounds\n\n## Summary\n',
|
|
8210
|
-
"workspace-crew.md": "---\nname: crew-lead\ndescription: Run the lead workflow. Use only when the user invokes /crew-lead or $crew-lead.\n---\n<!-- evercrew:workspace-entry -->\nFollow the adjacent `../lead/SKILL.md` entry point as if the user invoked lead. Pass through the request and its arguments.\n",
|
|
8211
|
-
"workspace-entry.md": "---\nname: lead\ndescription: Run lead for this project or show the workspace overview. Use when the user types /lead or $lead, asks to use lead, or asks for an overview of all workspace projects.\n---\n<!-- evercrew:workspace-entry -->\nIf the session context already names the lead launcher and kit, use them and skip the next two steps. Otherwise find the nearest `.lead/lead.mjs` from the directory this conversation started in. Preserve that starting directory as `--cwd` on the first call. Run `node <launcher> kit-path`, then read `skills/lead/SKILL.md` from the returned kit directory and follow it. References are relative to that kit directory. Keep the same session ID throughout this conversation. The launcher and kit path are local setup, not product state.\n",
|
|
8212
|
-
"workspace-goal.md": "---\nname: lead-goal\ndescription: Record lead activity and keep the heartbeat for an active Cursor goal.\n---\n<!-- evercrew:workspace-entry -->\nRun `node .lead/lead.mjs kit-path` from the lead workspace or target checkout, then read `skills/lead-goal/SKILL.md` from the returned kit directory. Use the same repository scope and session ID as lead.\n",
|
|
8213
|
-
"workspace-launcher.mjs": "#!/usr/bin/env node\n// evercrew:workspace-entry\n// Portable entry point. The runtime belongs to the workspace or to the user's npm cache.\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdirSync, realpathSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst args = process.argv.slice(2);\nconst here = dirname(dirname(fileURLToPath(import.meta.url)));\nconst hook = args[0] === 'stop-check' || args[0] === 'session-start';\nconst cwdFlag = args.indexOf('--cwd');\nconst cwd = cwdFlag >= 0 && args[cwdFlag + 1] ? resolve(args[cwdFlag + 1]) : process.cwd();\nconst cli = (kit) => join(kit, 'dist/lead.mjs');\n\nfunction workspaceKit(start) {\n let dir = realpathSync(start);\n while (true) {\n if (existsSync(join(dir, '.lead/workspace.yml'))) {\n const kit = join(dir, '.lead/workspace-kit');\n if (existsSync(cli(kit))) return kit;\n if (hook) return;\n throw new Error(`The lead workspace at ${dir} has no runtime. Deploy its kit first.`);\n }\n if (dirname(dir) === dir) return;\n dir = dirname(dir);\n }\n}\n\nfunction run(bin, argv, diagnosticsOnly = false) {\n const result = spawnSync(bin, argv, { stdio: diagnosticsOnly ? ['inherit', 2, 2] : 'inherit', env: bin === 'npm' ? { ...process.env, 'npm_config_@fusebase:registry': 'https://registry.npmjs.org/' } : process.env });\n if (result.error) throw result.error;\n return result.status ?? 1;\n}\n\nfunction main() {\n const shared = workspaceKit(cwd) ?? workspaceKit(here);\n const installed = join(here, 'node_modules/@fusebase/harness-lead');\n const cache = join(process.env.XDG_CACHE_HOME || join(homedir(), '.cache'), 'harness-lead', 'standalone');\n const cached = join(cache, 'node_modules/@fusebase/harness-lead');\n let kit = shared ?? (existsSync(cli(cached)) ? cached : installed);\n if (!shared && (args[0] === 'update' || !existsSync(cli(kit)))) {\n if (hook) return 0;\n if (args[0] === 'update' && args.length > 1) throw new Error('Standalone launcher update refreshes the user cache. Run the chosen kit directly for an explicit source.');\n mkdirSync(cache, { recursive: true });\n const status = run('npm', ['install', '--prefix', cache, '--no-save', '--no-package-lock', '--ignore-scripts', '--no-audit', '--no-fund',\n args[0] === 'update' ? '@fusebase/harness-lead@latest' : '@fusebase/harness-lead@0.3.0'], true);\n if (status || !existsSync(cli(cached))) return status || 1;\n kit = cached;\n if (args[0] === 'update') return run(process.execPath, [cli(kit), 'version']);\n }\n if (args[0] === 'kit-path') {\n console.log(realpathSync(kit));\n return 0;\n }\n return run(process.execPath, [cli(kit), ...args]);\n}\n\ntry { process.exitCode = main(); }\ncatch (error) {\n if (!hook) console.error(`lead: ${error.message}`);\n process.exitCode = hook ? 0 : 1;\n}\n",
|
|
8214
|
-
"backlog-index.md": '# <Project> Backlog\n\n[One Pager](one-pager.md)\n\n## Reviewed backlog\n\n<!-- evercrew:view kind="proposals" -->\n<!-- /evercrew:view -->\n\n## Needs triage\n\n<!-- For each candidate, link the task note and record what needs clarification. -->\n\n## Triage decisions\n\n<!-- Link source evidence and explain why an item was linked, completed, deferred or superseded. -->\n\n## History\n\n<!-- Link the complete source reconciliation, including repeated entries. -->\n',
|
|
8215
|
-
"one-pager.md": '---\nmilestones:\n - id: mvp\n title: MVP\n shows: ""\n status: current\n---\n# <Project> \u2014 One Pager\n\n## Status now\n\n<!-- 3\u20134 sentences, written by a human. -->\n\n**What to show.**\n\n**What landed.**\n\n**Evidence.** <!-- Add the date, source revision, checks and open verification. -->\n\n<!-- evercrew:view kind="stats" -->\n<!-- /evercrew:view -->\n\n## Needs attention\n\n<!-- Decisions and immediate checks. Link the evidence and name the owner when known. -->\n\n## Product bet\n\n<!-- One sentence. -->\n\n## Research\n\nConclusions only. The long note is [the research](spec/01-research.md).\n\n<!-- Paste ### Conclusions from spec/01-research.md. Do not paste the rest. -->\n\n## Readiness\n\n<!-- evercrew:view kind="readiness" -->\n<!-- /evercrew:view -->\n\n## Roadmap\n\n<!-- evercrew:view kind="order" -->\n<!-- /evercrew:view -->\n\n## Next 3 steps\n\n<!-- evercrew:view kind="next-steps" -->\n<!-- /evercrew:view -->\n\n## Inbox triage\n\nTick an item when the team agrees to take it into the plan. Review higher priorities first, then use list order within each priority.\n\n<!-- Example: add real rows and remove this comment.\n:::checklist[Take into the plan]\n::check[:badge[Feature request]{tone="info"} :badge[High]{tone="danger"} Task summary \xB7 [Task note](tasks/T-001-example.md)]{done="false"}\n:::\n-->\n\n## Next versions (do not promise on a demo)\n\n## Reference\n\n- [Execution board](board.md)\n- [Backlog and triage decisions](backlog.md)\n<!-- Link history, architecture and QA evidence once available. -->\n',
|
|
8216
|
-
"task-note.md": "# <Task summary>\n\n## Links\n\n<!-- Fill the links or document permitted exceptions before publishing. -->\n\n- [Epic](https://example.invalid/epic)\n- [Jira Story](https://example.invalid/story)\n- [Proposal](https://example.invalid/proposal)\n- [Mockup](https://example.invalid/mockup)\n- [One Pager](https://example.invalid/one-pager)\n\n## Goal\n\n<!-- Describe the user need and intended outcome. -->\n\n## User flow\n\n<!-- Add a Mermaid diagram covering the requested path. -->\n\n## Technical design\n\n<!-- Describe changes, interfaces, and relevant constraints. -->\n\n## Decisions\n\n<!-- Record agreed decisions and tradeoffs. -->\n\n## Acceptance criteria\n\n<!-- State observable checks and expected results. -->\n\n## Out of scope\n\n<!-- Name exclusions or say whether there are none. -->\n"
|
|
8217
|
-
};
|
|
8218
|
-
|
|
8219
8228
|
// src/settings.ts
|
|
8220
8229
|
import { existsSync as existsSync9, mkdirSync as mkdirSync2, readFileSync as readFileSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8221
8230
|
import { dirname, join as join10 } from "node:path";
|
|
@@ -8288,7 +8297,7 @@ function ensureCodexHooks(root) {
|
|
|
8288
8297
|
}
|
|
8289
8298
|
|
|
8290
8299
|
// src/install.ts
|
|
8291
|
-
var VERSION = true ? "0.3.
|
|
8300
|
+
var VERSION = true ? "0.3.2" : "dev";
|
|
8292
8301
|
var LOCK_PATH = ".lead/kit.lock";
|
|
8293
8302
|
var SKILLS = ["lead", "crew-lead", "lead-goal"];
|
|
8294
8303
|
var SKILL_DIRS = [".agents/skills", ".claude/skills"];
|
|
@@ -8527,8 +8536,8 @@ function withRegistryKit(root, out, useKit) {
|
|
|
8527
8536
|
var import_yaml3 = __toESM(require_dist(), 1);
|
|
8528
8537
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
8529
8538
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
8530
|
-
import { copyFileSync as copyFileSync2, cpSync, existsSync as
|
|
8531
|
-
import { dirname as dirname3, isAbsolute as isAbsolute2, join as
|
|
8539
|
+
import { copyFileSync as copyFileSync2, cpSync, existsSync as existsSync16, mkdirSync as mkdirSync5, readFileSync as readFileSync14, readdirSync as readdirSync9, realpathSync as realpathSync3, renameSync, rmSync as rmSync2, writeFileSync as writeFileSync6 } from "node:fs";
|
|
8540
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join17, relative as relative8, resolve as resolve2, sep as sep3 } from "node:path";
|
|
8532
8541
|
|
|
8533
8542
|
// src/board.ts
|
|
8534
8543
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
@@ -8667,184 +8676,484 @@ function renderOnePagerBlocks(tasks, milestones, isMerged, showRule = "merged")
|
|
|
8667
8676
|
};
|
|
8668
8677
|
}
|
|
8669
8678
|
|
|
8670
|
-
// src/
|
|
8671
|
-
import { existsSync as
|
|
8672
|
-
import { join as
|
|
8673
|
-
var IMPROVE_PATH = ".lead/improve.md";
|
|
8674
|
-
var KINDS = ["stop", "ask", "avoidable"];
|
|
8675
|
-
var HEADER = `# Harness improvements
|
|
8676
|
-
|
|
8677
|
-
The project appends a note when lead stops, asks the person, or does something a change to the kit would avoid. Product decisions (what to build, merge, accept) do not belong here.
|
|
8679
|
+
// src/initiative.ts
|
|
8680
|
+
import { existsSync as existsSync14, readdirSync as readdirSync8, readFileSync as readFileSync12 } from "node:fs";
|
|
8681
|
+
import { join as join15 } from "node:path";
|
|
8678
8682
|
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
const
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
if (
|
|
8693
|
-
|
|
8694
|
-
const header = /^##\s+(\S+)\s+—\s+(\w+)\s*$/.exec(lines[i]);
|
|
8695
|
-
const fields = {};
|
|
8696
|
-
let field;
|
|
8697
|
-
while (i + 1 < lines.length && !/^##\s/.test(lines[i + 1])) {
|
|
8698
|
-
const body = lines[++i];
|
|
8699
|
-
const label = /^- (Where|What|Avoid):[ \t]*(.*)$/.exec(body);
|
|
8700
|
-
if (label) {
|
|
8701
|
-
field = label[1].toLowerCase();
|
|
8702
|
-
fields[field] = label[2].trim();
|
|
8703
|
-
} else if (field && /^[ \t]+\S/.test(body)) {
|
|
8704
|
-
fields[field] = `${fields[field]} ${body.trim()}`.trim();
|
|
8705
|
-
}
|
|
8706
|
-
}
|
|
8707
|
-
const at = header?.[1];
|
|
8708
|
-
const kind = header?.[2];
|
|
8709
|
-
if (!at || !Number.isFinite(Date.parse(at)) || !kind || !isKind(kind) || !fields.where || !fields.what) {
|
|
8710
|
-
malformed.push(line);
|
|
8683
|
+
// src/adapter.ts
|
|
8684
|
+
import { existsSync as existsSync12, readdirSync as readdirSync7, readFileSync as readFileSync11 } from "node:fs";
|
|
8685
|
+
import { join as join13 } from "node:path";
|
|
8686
|
+
var ADAPTERS_DIR = ".lead/adapters";
|
|
8687
|
+
var ID2 = /^[a-z][a-z0-9-]*$/;
|
|
8688
|
+
function listAdapters(root) {
|
|
8689
|
+
const dir = join13(root, ADAPTERS_DIR);
|
|
8690
|
+
const adapters = [];
|
|
8691
|
+
const issues = [];
|
|
8692
|
+
if (!existsSync12(dir)) return { adapters, issues };
|
|
8693
|
+
for (const name of readdirSync7(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort()) {
|
|
8694
|
+
const rel = `${ADAPTERS_DIR}/${name}/SKILL.md`;
|
|
8695
|
+
const abs = join13(root, rel);
|
|
8696
|
+
if (!existsSync12(abs)) {
|
|
8697
|
+
issues.push(`${ADAPTERS_DIR}/${name}: no SKILL.md`);
|
|
8711
8698
|
continue;
|
|
8712
8699
|
}
|
|
8713
|
-
|
|
8700
|
+
const { parsed } = parseFrontmatter(readFileSync11(abs, "utf8"), rel);
|
|
8701
|
+
const declared = typeof parsed?.data.name === "string" ? parsed.data.name : name;
|
|
8702
|
+
if (!ID2.test(name)) {
|
|
8703
|
+
issues.push(`${rel}: folder name must look like "private-space"`);
|
|
8704
|
+
} else if (declared !== name) {
|
|
8705
|
+
issues.push(`${rel}: name "${declared}" must match the folder "${name}"`);
|
|
8706
|
+
} else {
|
|
8707
|
+
adapters.push({
|
|
8708
|
+
id: name,
|
|
8709
|
+
title: typeof parsed?.data.title === "string" ? parsed.data.title : name,
|
|
8710
|
+
appliesTo: typeof parsed?.data.applies_to === "string" ? parsed.data.applies_to : "",
|
|
8711
|
+
file: rel
|
|
8712
|
+
});
|
|
8713
|
+
}
|
|
8714
8714
|
}
|
|
8715
|
-
return {
|
|
8716
|
-
}
|
|
8717
|
-
function appendImprove(root, entry) {
|
|
8718
|
-
const at = entry.at ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
8719
|
-
const lines = [`## ${at} \u2014 ${entry.kind}`, "", `- Where: ${oneLine(entry.where)}`, `- What: ${oneLine(entry.what)}`];
|
|
8720
|
-
if (entry.avoid?.trim()) lines.push(`- Avoid: ${oneLine(entry.avoid)}`);
|
|
8721
|
-
lines.push("");
|
|
8722
|
-
const prev = readImprove(root);
|
|
8723
|
-
const body = prev.trim().length ? `${prev.trimEnd()}
|
|
8724
|
-
|
|
8725
|
-
${lines.join("\n")}` : `${HEADER}${lines.join("\n")}`;
|
|
8726
|
-
mkdirSync4(join13(root, ".lead"), { recursive: true });
|
|
8727
|
-
writeFileSync5(join13(root, IMPROVE_PATH), `${body.trimEnd()}
|
|
8728
|
-
`);
|
|
8729
|
-
return `${at} \u2014 ${entry.kind}`;
|
|
8730
|
-
}
|
|
8731
|
-
function oneLine(s) {
|
|
8732
|
-
return s.replace(/\s+/g, " ").trim();
|
|
8715
|
+
return { adapters, issues };
|
|
8733
8716
|
}
|
|
8734
8717
|
|
|
8735
|
-
// src/
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
var
|
|
8739
|
-
function
|
|
8740
|
-
const
|
|
8741
|
-
return
|
|
8718
|
+
// src/initiative-tasks.ts
|
|
8719
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
8720
|
+
import { join as join14 } from "node:path";
|
|
8721
|
+
var REF = /^(?:([a-z][a-z0-9-]*):)?(T-\d{3,})$/;
|
|
8722
|
+
function parseRef(ref) {
|
|
8723
|
+
const m = REF.exec(ref);
|
|
8724
|
+
return m ? { ...m[1] ? { repo: m[1] } : {}, id: m[2] } : void 0;
|
|
8742
8725
|
}
|
|
8743
|
-
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
if (existsSync13(file)) {
|
|
8748
|
-
const { version, repositories } = (0, import_yaml3.parse)(readFileSync12(file, "utf8")) ?? {};
|
|
8749
|
-
if (version !== 1 || !repositories || typeof repositories !== "object" || Array.isArray(repositories)) {
|
|
8750
|
-
throw new Error(`${file}: expected version 1 and a repositories mapping`);
|
|
8751
|
-
}
|
|
8752
|
-
const destinations = /* @__PURE__ */ new Set();
|
|
8753
|
-
const labels = {};
|
|
8754
|
-
const entries = Object.entries(repositories).map(([id, entry]) => {
|
|
8755
|
-
const path = typeof entry === "string" ? entry : entry?.path;
|
|
8756
|
-
if (!ID2.test(id) || typeof path !== "string" || isAbsolute2(path)) throw new Error(`${file}: invalid repository ${id}`);
|
|
8757
|
-
if (typeof entry === "object" && entry) {
|
|
8758
|
-
const { title, apps = {} } = entry;
|
|
8759
|
-
if (title !== void 0 && typeof title !== "string" || typeof apps !== "object" || Array.isArray(apps) || !apps || Object.values(apps).some((t) => typeof t !== "string")) throw new Error(`${file}: invalid titles for ${id}`);
|
|
8760
|
-
labels[id] = { title, apps };
|
|
8761
|
-
}
|
|
8762
|
-
const target = resolve2(root, path);
|
|
8763
|
-
if (target === root || !within(root, target) || destinations.has(target)) throw new Error(`${file}: invalid or repeated checkout for ${id}`);
|
|
8764
|
-
destinations.add(target);
|
|
8765
|
-
return [id, target];
|
|
8766
|
-
});
|
|
8767
|
-
return { root, repositories: Object.fromEntries(entries), labels };
|
|
8768
|
-
}
|
|
8769
|
-
if (dirname3(root) === root) return void 0;
|
|
8770
|
-
root = dirname3(root);
|
|
8771
|
-
}
|
|
8726
|
+
var homeRepo = (i) => i.repos.find((r) => r.role === "home")?.name;
|
|
8727
|
+
var taskRepo = (t, i) => t.repo ?? homeRepo(i) ?? "";
|
|
8728
|
+
function loadInitiativeTasks(root, i) {
|
|
8729
|
+
return loadTasks(root, join14(root, i.dir));
|
|
8772
8730
|
}
|
|
8773
|
-
function
|
|
8774
|
-
|
|
8775
|
-
|
|
8731
|
+
function externalState(ws, repo, id2) {
|
|
8732
|
+
if (!ws) return { state: "unresolved", reason: "no workspace catalog" };
|
|
8733
|
+
const path = ws.repositories[repo];
|
|
8734
|
+
if (!path) return { state: "unresolved", reason: `${repo} is not in the workspace` };
|
|
8735
|
+
if (!existsSync13(path)) return { state: "unresolved", reason: `checkout of ${repo} is missing` };
|
|
8776
8736
|
try {
|
|
8777
|
-
const
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
return
|
|
8781
|
-
|
|
8782
|
-
|
|
8737
|
+
const ctx = loadContext(path);
|
|
8738
|
+
if (!ctx.project) return { state: "unresolved", reason: `${repo} has no single lead project` };
|
|
8739
|
+
const t = ctx.tasks.find((x) => x.id === id2);
|
|
8740
|
+
if (!t) return { state: "unresolved", reason: `${repo} has no task ${id2}` };
|
|
8741
|
+
return { state: t.status === "done" ? "done" : "open" };
|
|
8742
|
+
} catch (error) {
|
|
8743
|
+
return { state: "unresolved", reason: error.message };
|
|
8783
8744
|
}
|
|
8784
8745
|
}
|
|
8785
|
-
function
|
|
8786
|
-
const
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
} catch {
|
|
8791
|
-
return false;
|
|
8792
|
-
}
|
|
8793
|
-
})?.[0];
|
|
8746
|
+
function resolveRef(ref, tasks, ws) {
|
|
8747
|
+
const p = parseRef(ref);
|
|
8748
|
+
if (!p) return { ref, state: "unresolved", reason: "not a task reference" };
|
|
8749
|
+
if (!p.repo) return tasks.some((t) => t.id === p.id) ? { ref, state: "internal" } : { ref, state: "unresolved", reason: "no such task in this initiative" };
|
|
8750
|
+
return { ref, ...externalState(ws, p.repo, p.id) };
|
|
8794
8751
|
}
|
|
8795
|
-
function
|
|
8796
|
-
|
|
8752
|
+
function scoped(tasks, i) {
|
|
8753
|
+
const ids = new Set(tasks.map((t) => t.id));
|
|
8754
|
+
return tasks.map((t) => ({
|
|
8755
|
+
...t,
|
|
8756
|
+
touches: t.touches.map((p) => `${taskRepo(t, i)}/${p.replace(/^\.\//, "")}`),
|
|
8757
|
+
blocked_by: t.blocked_by.filter((b) => ids.has(b))
|
|
8758
|
+
}));
|
|
8797
8759
|
}
|
|
8798
|
-
function
|
|
8799
|
-
|
|
8800
|
-
const file = bindingPath(ws, session);
|
|
8801
|
-
return existsSync13(file) ? JSON.parse(readFileSync12(file, "utf8")) : void 0;
|
|
8760
|
+
function initiativeWaves(tasks, i) {
|
|
8761
|
+
return computeWaves(scoped(tasks, i), []);
|
|
8802
8762
|
}
|
|
8803
|
-
function
|
|
8804
|
-
const
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
const
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
rmSync2(temp, { force: true });
|
|
8763
|
+
function writeInitiativeWaves(root, i) {
|
|
8764
|
+
const { tasks } = loadInitiativeTasks(root, i);
|
|
8765
|
+
const waves = initiativeWaves(tasks, i);
|
|
8766
|
+
if (!waves) throw new Error("dependency cycle: fix blocked_by first (run `lead initiative check`)");
|
|
8767
|
+
const log = [];
|
|
8768
|
+
for (const t of tasks) {
|
|
8769
|
+
const w = waves.get(t.id);
|
|
8770
|
+
if (w === void 0 || w === t.wave || t.status === "done") continue;
|
|
8771
|
+
updateTask(root, t, (d) => {
|
|
8772
|
+
d.wave = w;
|
|
8773
|
+
});
|
|
8774
|
+
log.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
8816
8775
|
}
|
|
8817
|
-
return
|
|
8776
|
+
return log.length ? log : ["waves are up to date"];
|
|
8818
8777
|
}
|
|
8819
|
-
function
|
|
8820
|
-
const
|
|
8821
|
-
const
|
|
8822
|
-
const
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
const
|
|
8827
|
-
if (
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8778
|
+
function checkInitiative(root, i, ws) {
|
|
8779
|
+
const { tasks, issues } = loadInitiativeTasks(root, i);
|
|
8780
|
+
const out = [...issues];
|
|
8781
|
+
const repos = new Set(i.repos.map((r) => r.name));
|
|
8782
|
+
const home = homeRepo(i);
|
|
8783
|
+
const ms = new Set(loadOnePager(root, join14(root, i.dir)).onePager?.milestones.map((m) => m.id) ?? []);
|
|
8784
|
+
for (const t of tasks) {
|
|
8785
|
+
const e = (message, level = "error") => out.push({ level, file: t.file, message });
|
|
8786
|
+
if (t.repo ? !repos.has(t.repo) : !home) e(t.repo ? `repo "${t.repo}" is not listed in ${i.file}` : `no repo: the initiative has no home repository`);
|
|
8787
|
+
if (t.milestone && ms.size && !ms.has(t.milestone)) e(`milestone "${t.milestone}" is not defined in the initiative one-pager`);
|
|
8788
|
+
for (const ref of t.blocked_by) {
|
|
8789
|
+
const p = parseRef(ref);
|
|
8790
|
+
if (!p) e(`blocked_by ${ref}: use T-001 or <repo>:T-001`);
|
|
8791
|
+
else if (!p.repo && p.id === t.id) e(`${t.id} is blocked by itself`);
|
|
8792
|
+
else if (p.repo && !repos.has(p.repo)) e(`blocked_by ${ref}: repository ${p.repo} is not listed in ${i.file}`);
|
|
8793
|
+
else {
|
|
8794
|
+
const r = resolveRef(ref, tasks, ws);
|
|
8795
|
+
if (r.state === "unresolved") e(`blocked_by ${ref}: ${r.reason}`, p.repo ? "warning" : "error");
|
|
8796
|
+
}
|
|
8797
|
+
}
|
|
8798
|
+
if (t.touches.length === 0 && t.status !== "done") e("touches is empty: the task runs alone in its wave until its paths are known", "warning");
|
|
8833
8799
|
}
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
const
|
|
8800
|
+
const sc = scoped(tasks, i);
|
|
8801
|
+
const byId = new Map(tasks.map((t) => [t.id, t]));
|
|
8802
|
+
for (const c of findCycles(sc)) out.push({ level: "error", file: byId.get(c[0]).file, message: `dependency cycle: ${c.join(" \u2192 ")}` });
|
|
8803
|
+
const waves = computeWaves(sc, []);
|
|
8804
|
+
const active = sc.filter((t) => t.status !== "done");
|
|
8805
|
+
for (const t of tasks) {
|
|
8806
|
+
if (t.wave === void 0) {
|
|
8807
|
+
if (t.status !== "done") out.push({ level: "warning", file: t.file, message: "wave not set; run `lead initiative waves <id> --write`" });
|
|
8808
|
+
continue;
|
|
8809
|
+
}
|
|
8810
|
+
for (const dep of t.blocked_by) {
|
|
8811
|
+
const d = byId.get(dep);
|
|
8812
|
+
if (d?.wave !== void 0 && d.wave >= t.wave) out.push({ level: "error", file: t.file, message: `blocked by ${dep} (wave ${d.wave}) but placed in wave ${t.wave}` });
|
|
8813
|
+
}
|
|
8814
|
+
const c = waves?.get(t.id);
|
|
8815
|
+
if (c !== void 0 && c !== t.wave && t.status !== "done") out.push({ level: "warning", file: t.file, message: `wave ${t.wave} differs from computed wave ${c}; run \`lead initiative waves <id> --write\`` });
|
|
8816
|
+
}
|
|
8817
|
+
for (let a = 0; a < active.length; a++) {
|
|
8818
|
+
for (let b = a + 1; b < active.length; b++) {
|
|
8819
|
+
const x = active[a];
|
|
8820
|
+
const y = active[b];
|
|
8821
|
+
if (x.wave === void 0 || x.wave !== y.wave) continue;
|
|
8822
|
+
const hits = touchesOverlap(x.touches, y.touches);
|
|
8823
|
+
if (hits.length) out.push({ level: "error", file: byId.get(y.id).file, message: `wave ${y.wave}: ${y.id} and ${x.id} touch the same paths (${hits.join(", ")})` });
|
|
8824
|
+
}
|
|
8825
|
+
}
|
|
8826
|
+
return out;
|
|
8827
|
+
}
|
|
8828
|
+
function initiativeTaskRows(root, i, ws) {
|
|
8829
|
+
const { tasks } = loadInitiativeTasks(root, i);
|
|
8830
|
+
return tasks.map((t) => ({
|
|
8831
|
+
id: t.id,
|
|
8832
|
+
title: t.title,
|
|
8833
|
+
repo: taskRepo(t, i),
|
|
8834
|
+
status: t.status,
|
|
8835
|
+
...t.wave !== void 0 ? { wave: t.wave } : {},
|
|
8836
|
+
...t.milestone ? { milestone: t.milestone } : {},
|
|
8837
|
+
blocked_by: t.blocked_by.map((b) => resolveRef(b, tasks, ws))
|
|
8838
|
+
}));
|
|
8839
|
+
}
|
|
8840
|
+
|
|
8841
|
+
// src/initiative.ts
|
|
8842
|
+
var INITIATIVES_DIR = "work/initiatives";
|
|
8843
|
+
var ID3 = /^[a-z][a-z0-9-]*$/;
|
|
8844
|
+
var ROLES = ["home", "reference"];
|
|
8845
|
+
var RESERVED = ["check", "waves"];
|
|
8846
|
+
var str = (v) => typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
8847
|
+
function loadInitiatives(root) {
|
|
8848
|
+
const base = join15(root, INITIATIVES_DIR);
|
|
8849
|
+
const initiatives = [];
|
|
8850
|
+
const issues = [];
|
|
8851
|
+
if (!existsSync14(base)) return { initiatives, issues };
|
|
8852
|
+
for (const entry of readdirSync8(base, { withFileTypes: true }).filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
8853
|
+
const dir = `${INITIATIVES_DIR}/${entry.name}`;
|
|
8854
|
+
const file = `${dir}/initiative.md`;
|
|
8855
|
+
const err = (message) => issues.push({ level: "error", file, message });
|
|
8856
|
+
const abs = join15(root, file);
|
|
8857
|
+
if (!existsSync14(abs)) {
|
|
8858
|
+
issues.push({ level: "warning", file: dir, message: "no initiative.md" });
|
|
8859
|
+
continue;
|
|
8860
|
+
}
|
|
8861
|
+
const { parsed, issues: parseIssues } = parseFrontmatter(readFileSync12(abs, "utf8"), file);
|
|
8862
|
+
issues.push(...parseIssues);
|
|
8863
|
+
if (!parsed) continue;
|
|
8864
|
+
const d = parsed.data;
|
|
8865
|
+
if (!ID3.test(entry.name) || RESERVED.includes(entry.name)) err('folder name must look like "private-space" and not be "check" or "waves"');
|
|
8866
|
+
if (str(d.id) !== entry.name) err(`id must equal the folder name "${entry.name}"`);
|
|
8867
|
+
const repos = [];
|
|
8868
|
+
if (d.repos !== void 0 && !Array.isArray(d.repos)) err("repos must be a list");
|
|
8869
|
+
for (const [i, r] of (Array.isArray(d.repos) ? d.repos : []).entries()) {
|
|
8870
|
+
const row = r ?? {};
|
|
8871
|
+
const name = str(row.name);
|
|
8872
|
+
const role = row.role === void 0 ? "reference" : row.role;
|
|
8873
|
+
if (!name || !ID3.test(name)) err(`repos[${i}].name must look like "org-service"`);
|
|
8874
|
+
else if (!ROLES.includes(role)) err(`repos[${i}].role must be one of ${ROLES.join(", ")}`);
|
|
8875
|
+
else if (repos.some((x) => x.name === name)) err(`repos[${i}]: "${name}" is listed twice`);
|
|
8876
|
+
else repos.push({ name, role, ...str(row.url) ? { url: str(row.url) } : {} });
|
|
8877
|
+
}
|
|
8878
|
+
if (repos.filter((r) => r.role === "home").length > 1) err("only one repository can be home");
|
|
8879
|
+
const map = {};
|
|
8880
|
+
if (d.map !== void 0 && (typeof d.map !== "object" || d.map === null || Array.isArray(d.map))) err("map must be a mapping from tracker key to a decision");
|
|
8881
|
+
for (const [key, v] of Object.entries(typeof d.map === "object" && d.map && !Array.isArray(d.map) ? d.map : {})) {
|
|
8882
|
+
const o = v ?? {};
|
|
8883
|
+
const bad = (m) => err(`map.${key}: ${m}`);
|
|
8884
|
+
if (!/^[A-Z][A-Z0-9]*-\d+$/.test(key)) bad("the key must look like KEY-123");
|
|
8885
|
+
else if (o.repo !== void 0 && (typeof o.repo !== "string" || !ID3.test(o.repo))) bad('repo must look like "org-service"');
|
|
8886
|
+
else if (typeof o.repo === "string" && !repos.some((r) => r.name === o.repo)) bad(`repo "${o.repo}" is not listed in repos`);
|
|
8887
|
+
else if (o.milestone !== void 0 && typeof o.milestone !== "string") bad("milestone must be a milestone id");
|
|
8888
|
+
else if (o.kind !== void 0 && !["work", "qa", "manual"].includes(o.kind)) bad("kind must be work, qa or manual");
|
|
8889
|
+
else map[key] = { ...o.repo ? { repo: o.repo } : {}, ...o.milestone ? { milestone: o.milestone } : {}, ...o.kind ? { kind: o.kind } : {} };
|
|
8890
|
+
}
|
|
8891
|
+
initiatives.push({
|
|
8892
|
+
id: entry.name,
|
|
8893
|
+
title: str(d.title) ?? entry.name,
|
|
8894
|
+
epic: str(d.epic),
|
|
8895
|
+
site: str(d.site),
|
|
8896
|
+
flag: str(d.flag),
|
|
8897
|
+
adapter: str(d.adapter),
|
|
8898
|
+
repos,
|
|
8899
|
+
map,
|
|
8900
|
+
dir,
|
|
8901
|
+
file
|
|
8902
|
+
});
|
|
8903
|
+
}
|
|
8904
|
+
return { initiatives, issues };
|
|
8905
|
+
}
|
|
8906
|
+
function optionalWorkspace(root) {
|
|
8907
|
+
try {
|
|
8908
|
+
return findWorkspace(root);
|
|
8909
|
+
} catch {
|
|
8910
|
+
return void 0;
|
|
8911
|
+
}
|
|
8912
|
+
}
|
|
8913
|
+
function observedCounts(root, i) {
|
|
8914
|
+
const file = join15(root, i.dir, "sync.json");
|
|
8915
|
+
if (!existsSync14(file)) return [];
|
|
8916
|
+
try {
|
|
8917
|
+
const issues = JSON.parse(readFileSync12(file, "utf8")).issues ?? {};
|
|
8918
|
+
const by = /* @__PURE__ */ new Map();
|
|
8919
|
+
for (const x of Object.values(issues)) {
|
|
8920
|
+
const m = x.milestone ?? "?";
|
|
8921
|
+
const row = by.get(m) ?? { milestone: m, total: 0, states: {} };
|
|
8922
|
+
row.total++;
|
|
8923
|
+
row.states[x.observed ?? "other"] = (row.states[x.observed ?? "other"] ?? 0) + 1;
|
|
8924
|
+
by.set(m, row);
|
|
8925
|
+
}
|
|
8926
|
+
return [...by.values()];
|
|
8927
|
+
} catch {
|
|
8928
|
+
return [];
|
|
8929
|
+
}
|
|
8930
|
+
}
|
|
8931
|
+
function initiativeOverview(root, i) {
|
|
8932
|
+
const ws = optionalWorkspace(root);
|
|
8933
|
+
const catalog = ws ? Object.entries(ws.repositories) : [];
|
|
8934
|
+
const op = loadOnePager(root, join15(root, i.dir));
|
|
8935
|
+
const adapters = i.adapter ? listAdapters(root).adapters : [];
|
|
8936
|
+
return {
|
|
8937
|
+
id: i.id,
|
|
8938
|
+
title: i.title,
|
|
8939
|
+
...i.epic ? { epic: i.epic } : {},
|
|
8940
|
+
...i.epic && i.site ? { epicUrl: `https://${i.site}/browse/${i.epic}` } : {},
|
|
8941
|
+
...i.flag ? { flag: i.flag } : {},
|
|
8942
|
+
...i.adapter ? { adapter: { name: i.adapter, state: adapters.some((a) => a.id === i.adapter) ? "found" : "missing" } } : {},
|
|
8943
|
+
...op.onePager ? { onePager: op.onePager.file } : {},
|
|
8944
|
+
milestones: op.onePager?.milestones ?? [],
|
|
8945
|
+
repos: i.repos.map((r) => {
|
|
8946
|
+
const path = catalog.find(([name]) => name === r.name)?.[1];
|
|
8947
|
+
const local = r.role === "home" ? "here" : !ws ? "no_workspace" : !path ? "not_in_workspace" : existsSync14(path) ? "available" : "missing";
|
|
8948
|
+
return { ...r, local };
|
|
8949
|
+
}),
|
|
8950
|
+
tasks: initiativeTaskRows(root, i, ws),
|
|
8951
|
+
observed: observedCounts(root, i)
|
|
8952
|
+
};
|
|
8953
|
+
}
|
|
8954
|
+
function observedRecords(root, i, repo) {
|
|
8955
|
+
const file = join15(root, i.dir, "sync.json");
|
|
8956
|
+
if (!existsSync14(file)) return [];
|
|
8957
|
+
try {
|
|
8958
|
+
const issues = JSON.parse(readFileSync12(file, "utf8")).issues ?? {};
|
|
8959
|
+
return Object.entries(issues).filter(([, x]) => !repo || x.repo === repo || (x.also ?? []).includes(repo)).map(([key, x]) => ({ key, ...x })).sort((a, b) => Number(a.key.split("-").pop()) - Number(b.key.split("-").pop()));
|
|
8960
|
+
} catch {
|
|
8961
|
+
return [];
|
|
8962
|
+
}
|
|
8963
|
+
}
|
|
8964
|
+
function renderInitiative(o) {
|
|
8965
|
+
const lines = [`${o.id} \u2014 ${o.title}${o.epic ? ` (${o.epic})` : ""}`];
|
|
8966
|
+
if (o.flag) lines.push(` flag: ${o.flag}`);
|
|
8967
|
+
if (o.adapter) lines.push(` adapter: ${o.adapter.name} (${o.adapter.state})`);
|
|
8968
|
+
lines.push(` one-pager: ${o.onePager ?? "none"}`);
|
|
8969
|
+
for (const m of o.milestones) lines.push(` milestone ${m.id} [${m.status}] ${m.title}${m.shows ? ` \u2014 ${m.shows}` : ""}`);
|
|
8970
|
+
for (const x of o.observed) lines.push(` observed ${x.milestone}: ${x.total} (${Object.entries(x.states).map(([k, v]) => `${k} ${v}`).join(", ")})`);
|
|
8971
|
+
for (const r of o.repos) lines.push(` repo ${r.name} (${r.role}) \u2014 ${r.local}`);
|
|
8972
|
+
for (const t of o.tasks) {
|
|
8973
|
+
const deps = t.blocked_by.map((b) => `${b.ref}${b.state === "internal" ? "" : ` ${b.state}`}`).join(", ");
|
|
8974
|
+
lines.push(` task ${t.id} [${t.status}]${t.wave ? ` w${t.wave}` : ""} ${t.repo} \u2014 ${t.title}${deps ? ` (after ${deps})` : ""}`);
|
|
8975
|
+
}
|
|
8976
|
+
return lines;
|
|
8977
|
+
}
|
|
8978
|
+
|
|
8979
|
+
// src/improve.ts
|
|
8980
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync4, readFileSync as readFileSync13, writeFileSync as writeFileSync5 } from "node:fs";
|
|
8981
|
+
import { join as join16 } from "node:path";
|
|
8982
|
+
var IMPROVE_PATH = ".lead/improve.md";
|
|
8983
|
+
var KINDS = ["stop", "ask", "avoidable"];
|
|
8984
|
+
var HEADER = `# Harness improvements
|
|
8985
|
+
|
|
8986
|
+
The project appends a note when lead stops, asks the person, or does something a change to the kit would avoid. Product decisions (what to build, merge, accept) do not belong here.
|
|
8987
|
+
|
|
8988
|
+
`;
|
|
8989
|
+
function isKind(v) {
|
|
8990
|
+
return KINDS.includes(v);
|
|
8991
|
+
}
|
|
8992
|
+
function readImprove(root) {
|
|
8993
|
+
const p = join16(root, IMPROVE_PATH);
|
|
8994
|
+
return existsSync15(p) ? readFileSync13(p, "utf8") : "";
|
|
8995
|
+
}
|
|
8996
|
+
function parseImprove(text) {
|
|
8997
|
+
const entries = [];
|
|
8998
|
+
const malformed = [];
|
|
8999
|
+
const lines = text.split(/\r?\n/);
|
|
9000
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9001
|
+
if (!/^##\s/.test(lines[i])) continue;
|
|
9002
|
+
const line = i + 1;
|
|
9003
|
+
const header = /^##\s+(\S+)\s+—\s+(\w+)\s*$/.exec(lines[i]);
|
|
9004
|
+
const fields = {};
|
|
9005
|
+
let field;
|
|
9006
|
+
while (i + 1 < lines.length && !/^##\s/.test(lines[i + 1])) {
|
|
9007
|
+
const body = lines[++i];
|
|
9008
|
+
const label = /^- (Where|What|Avoid):[ \t]*(.*)$/.exec(body);
|
|
9009
|
+
if (label) {
|
|
9010
|
+
field = label[1].toLowerCase();
|
|
9011
|
+
fields[field] = label[2].trim();
|
|
9012
|
+
} else if (field && /^[ \t]+\S/.test(body)) {
|
|
9013
|
+
fields[field] = `${fields[field]} ${body.trim()}`.trim();
|
|
9014
|
+
}
|
|
9015
|
+
}
|
|
9016
|
+
const at = header?.[1];
|
|
9017
|
+
const kind = header?.[2];
|
|
9018
|
+
if (!at || !Number.isFinite(Date.parse(at)) || !kind || !isKind(kind) || !fields.where || !fields.what) {
|
|
9019
|
+
malformed.push(line);
|
|
9020
|
+
continue;
|
|
9021
|
+
}
|
|
9022
|
+
entries.push({ at, kind, where: fields.where, what: fields.what, avoid: fields.avoid || void 0, line });
|
|
9023
|
+
}
|
|
9024
|
+
return { entries, malformed };
|
|
9025
|
+
}
|
|
9026
|
+
function appendImprove(root, entry) {
|
|
9027
|
+
const at = entry.at ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
9028
|
+
const lines = [`## ${at} \u2014 ${entry.kind}`, "", `- Where: ${oneLine(entry.where)}`, `- What: ${oneLine(entry.what)}`];
|
|
9029
|
+
if (entry.avoid?.trim()) lines.push(`- Avoid: ${oneLine(entry.avoid)}`);
|
|
9030
|
+
lines.push("");
|
|
9031
|
+
const prev = readImprove(root);
|
|
9032
|
+
const body = prev.trim().length ? `${prev.trimEnd()}
|
|
9033
|
+
|
|
9034
|
+
${lines.join("\n")}` : `${HEADER}${lines.join("\n")}`;
|
|
9035
|
+
mkdirSync4(join16(root, ".lead"), { recursive: true });
|
|
9036
|
+
writeFileSync5(join16(root, IMPROVE_PATH), `${body.trimEnd()}
|
|
9037
|
+
`);
|
|
9038
|
+
return `${at} \u2014 ${entry.kind}`;
|
|
9039
|
+
}
|
|
9040
|
+
function oneLine(s) {
|
|
9041
|
+
return s.replace(/\s+/g, " ").trim();
|
|
9042
|
+
}
|
|
9043
|
+
|
|
9044
|
+
// src/workspace.ts
|
|
9045
|
+
var CATALOG = ".lead/workspace.yml";
|
|
9046
|
+
var RUNTIME = ".lead/workspace-kit";
|
|
9047
|
+
var ID4 = /^[a-z0-9][a-z0-9_-]*$/;
|
|
9048
|
+
function within(parent, child) {
|
|
9049
|
+
const rel = relative8(parent, child);
|
|
9050
|
+
return rel === "" || rel !== ".." && !rel.startsWith(".." + sep3) && !isAbsolute2(rel);
|
|
9051
|
+
}
|
|
9052
|
+
function findWorkspace(cwd) {
|
|
9053
|
+
let root = realpathSync3(cwd);
|
|
9054
|
+
for (; ; ) {
|
|
9055
|
+
const file = join17(root, CATALOG);
|
|
9056
|
+
if (existsSync16(file)) {
|
|
9057
|
+
const { version, repositories } = (0, import_yaml3.parse)(readFileSync14(file, "utf8")) ?? {};
|
|
9058
|
+
if (version !== 1 || !repositories || typeof repositories !== "object" || Array.isArray(repositories)) {
|
|
9059
|
+
throw new Error(`${file}: expected version 1 and a repositories mapping`);
|
|
9060
|
+
}
|
|
9061
|
+
const destinations = /* @__PURE__ */ new Set();
|
|
9062
|
+
const labels = {};
|
|
9063
|
+
const entries = Object.entries(repositories).map(([id2, entry]) => {
|
|
9064
|
+
const path = typeof entry === "string" ? entry : entry?.path;
|
|
9065
|
+
if (!ID4.test(id2) || typeof path !== "string" || isAbsolute2(path)) throw new Error(`${file}: invalid repository ${id2}`);
|
|
9066
|
+
if (typeof entry === "object" && entry) {
|
|
9067
|
+
const { title, apps = {} } = entry;
|
|
9068
|
+
if (title !== void 0 && typeof title !== "string" || typeof apps !== "object" || Array.isArray(apps) || !apps || Object.values(apps).some((t) => typeof t !== "string")) throw new Error(`${file}: invalid titles for ${id2}`);
|
|
9069
|
+
labels[id2] = { title, apps };
|
|
9070
|
+
}
|
|
9071
|
+
const target = resolve2(root, path);
|
|
9072
|
+
if (target === root || !within(root, target) || destinations.has(target)) throw new Error(`${file}: invalid or repeated checkout for ${id2}`);
|
|
9073
|
+
destinations.add(target);
|
|
9074
|
+
return [id2, target];
|
|
9075
|
+
});
|
|
9076
|
+
return { root, repositories: Object.fromEntries(entries), labels };
|
|
9077
|
+
}
|
|
9078
|
+
if (dirname3(root) === root) return void 0;
|
|
9079
|
+
root = dirname3(root);
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
9082
|
+
function repository(ws, id2) {
|
|
9083
|
+
const path = Object.hasOwn(ws.repositories, id2) ? ws.repositories[id2] : void 0;
|
|
9084
|
+
if (!path) throw new Error(`unknown repository "${id2}"; choose ${Object.keys(ws.repositories).join(", ")}`);
|
|
9085
|
+
try {
|
|
9086
|
+
const physical = realpathSync3(path);
|
|
9087
|
+
const top = realpathSync3(execFileSync3("git", ["rev-parse", "--show-toplevel"], { cwd: physical, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim());
|
|
9088
|
+
if (top !== physical || !within(ws.root, physical)) throw new Error("not a checkout inside the workspace");
|
|
9089
|
+
return physical;
|
|
9090
|
+
} catch {
|
|
9091
|
+
throw new Error(`repository "${id2}" is unavailable or not a Git checkout: ${path}`);
|
|
9092
|
+
}
|
|
9093
|
+
}
|
|
9094
|
+
function repoAt(ws, cwd) {
|
|
9095
|
+
const root = repoRoot(cwd);
|
|
9096
|
+
return Object.entries(ws.repositories).find(([, path]) => {
|
|
9097
|
+
try {
|
|
9098
|
+
return realpathSync3(path) === root;
|
|
9099
|
+
} catch {
|
|
9100
|
+
return false;
|
|
9101
|
+
}
|
|
9102
|
+
})?.[0];
|
|
9103
|
+
}
|
|
9104
|
+
function bindingPath(ws, session) {
|
|
9105
|
+
return join17(ws.root, ".lead/sessions", createHash4("sha256").update(session).digest("hex") + ".json");
|
|
9106
|
+
}
|
|
9107
|
+
function readScope(ws, session) {
|
|
9108
|
+
if (!session) return void 0;
|
|
9109
|
+
const file = bindingPath(ws, session);
|
|
9110
|
+
return existsSync16(file) ? JSON.parse(readFileSync14(file, "utf8")) : void 0;
|
|
9111
|
+
}
|
|
9112
|
+
function bindScope(ws, cwd, session, scope) {
|
|
9113
|
+
const local = repoAt(ws, cwd);
|
|
9114
|
+
if (local && local !== scope.repo) throw new Error(`this checkout belongs to ${local}; switch from the workspace root`);
|
|
9115
|
+
const root = repository(ws, scope.repo);
|
|
9116
|
+
if (scope.project && !loadContext(root, scope.project).project) throw new Error(`unknown project ${scope.project} in ${scope.repo}`);
|
|
9117
|
+
const file = bindingPath(ws, session);
|
|
9118
|
+
mkdirSync5(dirname3(file), { recursive: true });
|
|
9119
|
+
const temp = `${file}.${randomUUID()}`;
|
|
9120
|
+
try {
|
|
9121
|
+
writeFileSync6(temp, JSON.stringify(scope) + "\n");
|
|
9122
|
+
renameSync(temp, file);
|
|
9123
|
+
} finally {
|
|
9124
|
+
rmSync2(temp, { force: true });
|
|
9125
|
+
}
|
|
9126
|
+
return { ...scope, root };
|
|
9127
|
+
}
|
|
9128
|
+
function routeScope(ws, cwd, session, repo, project) {
|
|
9129
|
+
const local = repoAt(ws, cwd);
|
|
9130
|
+
const scope = readScope(ws, session);
|
|
9131
|
+
const chosen = scope?.repo ?? local ?? repo;
|
|
9132
|
+
if (local && local !== chosen || repo && repo !== chosen) throw new Error(`this session is scoped to ${chosen}; switch explicitly from the workspace root`);
|
|
9133
|
+
if (scope?.project && project && project !== scope.project) throw new Error(`this session is scoped to project ${scope.project}; switch explicitly`);
|
|
9134
|
+
if (scope?.project && local && !project) {
|
|
9135
|
+
const inferred = loadContext(cwd).project?.name;
|
|
9136
|
+
if (inferred && inferred !== "." && inferred !== scope.project) throw new Error(`this session is scoped to project ${scope.project}, not ${inferred}`);
|
|
9137
|
+
}
|
|
9138
|
+
if (!chosen) return void 0;
|
|
9139
|
+
const root = repository(ws, chosen);
|
|
9140
|
+
if (!local && realpathSync3(cwd) !== ws.root && existsSync16(join17(repoRoot(cwd), ".git"))) {
|
|
9141
|
+
throw new Error("the current checkout is outside the selected scope");
|
|
9142
|
+
}
|
|
9143
|
+
return { repo: chosen, cwd: local ? cwd : root, project: project ?? scope?.project, root };
|
|
9144
|
+
}
|
|
9145
|
+
var readable = (name) => {
|
|
9146
|
+
const words = name.replace(/[-_]+/g, " ").trim();
|
|
8838
9147
|
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
8839
9148
|
};
|
|
8840
9149
|
function workspaceOverview(ws) {
|
|
8841
9150
|
const registered = new Set(Object.values(ws.repositories));
|
|
8842
|
-
const candidates =
|
|
8843
|
-
const repositories = Object.keys(ws.repositories).map((
|
|
8844
|
-
const labels = ws.labels?.[
|
|
8845
|
-
const title = labels.title ?? readable(
|
|
9151
|
+
const candidates = readdirSync9(ws.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !registered.has(join17(ws.root, entry.name)) && existsSync16(join17(ws.root, entry.name, ".git"))).map((entry) => entry.name).sort();
|
|
9152
|
+
const repositories = Object.keys(ws.repositories).map((id2) => {
|
|
9153
|
+
const labels = ws.labels?.[id2] ?? { apps: {} };
|
|
9154
|
+
const title = labels.title ?? readable(id2);
|
|
8846
9155
|
try {
|
|
8847
|
-
const root = repository(ws,
|
|
9156
|
+
const root = repository(ws, id2);
|
|
8848
9157
|
const base = loadContext(root);
|
|
8849
9158
|
const projects = base.projects.map((p) => {
|
|
8850
9159
|
const ctx = loadContext(root, p.name);
|
|
@@ -8854,34 +9163,51 @@ function workspaceOverview(ws) {
|
|
|
8854
9163
|
path: p.path,
|
|
8855
9164
|
title: p.name === "." ? void 0 : labels.apps[p.name] ?? readable(p.name),
|
|
8856
9165
|
milestone: milestone?.title,
|
|
8857
|
-
onePager: ctx.onePager &&
|
|
8858
|
-
active: ctx.tasks.filter((t) => t.status === "in_progress" || t.status === "review").map((t) => ({ title: t.title, file:
|
|
8859
|
-
blocked: ctx.tasks.filter((t) => t.status === "blocked").map((t) => ({ title: t.title, file:
|
|
9166
|
+
onePager: ctx.onePager && join17(root, ctx.onePager.file),
|
|
9167
|
+
active: ctx.tasks.filter((t) => t.status === "in_progress" || t.status === "review").map((t) => ({ title: t.title, file: join17(root, t.file) })),
|
|
9168
|
+
blocked: ctx.tasks.filter((t) => t.status === "blocked").map((t) => ({ title: t.title, file: join17(root, t.file) }))
|
|
9169
|
+
};
|
|
9170
|
+
});
|
|
9171
|
+
const initiatives = loadInitiatives(root).initiatives.map((i) => {
|
|
9172
|
+
const o = initiativeOverview(root, i);
|
|
9173
|
+
const counts = {};
|
|
9174
|
+
for (const t of o.tasks) counts[t.status] = (counts[t.status] ?? 0) + 1;
|
|
9175
|
+
return {
|
|
9176
|
+
id: o.id,
|
|
9177
|
+
title: o.title,
|
|
9178
|
+
epic: o.epic,
|
|
9179
|
+
epicUrl: o.epicUrl,
|
|
9180
|
+
flag: o.flag,
|
|
9181
|
+
onePager: o.onePager && join17(root, o.onePager),
|
|
9182
|
+
milestones: o.milestones,
|
|
9183
|
+
observed: o.observed,
|
|
9184
|
+
tasks: counts,
|
|
9185
|
+
repositories: o.repos.map((r) => ({ name: r.name, role: r.role, url: r.url, local: r.local }))
|
|
8860
9186
|
};
|
|
8861
9187
|
});
|
|
8862
|
-
return { id, title, root, state: base.configExists ? "ready" : "not_configured", projects };
|
|
9188
|
+
return { id: id2, title, root, state: base.configExists ? "ready" : "not_configured", projects, initiatives };
|
|
8863
9189
|
} catch (error) {
|
|
8864
|
-
return { id, title, root: ws.repositories[
|
|
9190
|
+
return { id: id2, title, root: ws.repositories[id2], state: "unavailable", reason: error.message, projects: [] };
|
|
8865
9191
|
}
|
|
8866
9192
|
});
|
|
8867
9193
|
return { root: ws.root, repositories, candidates };
|
|
8868
9194
|
}
|
|
8869
9195
|
function workspaceImprove(ws) {
|
|
8870
9196
|
const entries = [];
|
|
8871
|
-
const repositories = Object.keys(ws.repositories).map((
|
|
9197
|
+
const repositories = Object.keys(ws.repositories).map((id2) => {
|
|
8872
9198
|
let root;
|
|
8873
9199
|
try {
|
|
8874
|
-
root = repository(ws,
|
|
9200
|
+
root = repository(ws, id2);
|
|
8875
9201
|
} catch (error) {
|
|
8876
|
-
return { id, state: "unavailable", count: 0, reason: error.message };
|
|
9202
|
+
return { id: id2, state: "unavailable", count: 0, reason: error.message };
|
|
8877
9203
|
}
|
|
8878
|
-
const source =
|
|
9204
|
+
const source = join17(root, IMPROVE_PATH);
|
|
8879
9205
|
try {
|
|
8880
9206
|
if (!within(root, realpathSync3(source))) throw new Error("improvement log points outside its checkout");
|
|
8881
|
-
const parsed = parseImprove(
|
|
8882
|
-
entries.push(...parsed.entries.map((entry) => ({ ...entry, repository:
|
|
9207
|
+
const parsed = parseImprove(readFileSync14(source, "utf8"));
|
|
9208
|
+
entries.push(...parsed.entries.map((entry) => ({ ...entry, repository: id2, source })));
|
|
8883
9209
|
return {
|
|
8884
|
-
id,
|
|
9210
|
+
id: id2,
|
|
8885
9211
|
source,
|
|
8886
9212
|
state: parsed.entries.length || parsed.malformed.length ? "collected" : "empty",
|
|
8887
9213
|
count: parsed.entries.length,
|
|
@@ -8889,29 +9215,29 @@ function workspaceImprove(ws) {
|
|
|
8889
9215
|
};
|
|
8890
9216
|
} catch (error) {
|
|
8891
9217
|
const missing = error.code === "ENOENT";
|
|
8892
|
-
return { id, source, state: missing ? "missing" : "unreadable", count: 0, reason: missing ? void 0 : error.message };
|
|
9218
|
+
return { id: id2, source, state: missing ? "missing" : "unreadable", count: 0, reason: missing ? void 0 : error.message };
|
|
8893
9219
|
}
|
|
8894
9220
|
});
|
|
8895
9221
|
entries.sort((a, b) => Date.parse(b.at) - Date.parse(a.at) || a.repository.localeCompare(b.repository) || b.line - a.line);
|
|
8896
9222
|
return { root: ws.root, repositories, entries };
|
|
8897
9223
|
}
|
|
8898
9224
|
function deployWorkspace(ws, source) {
|
|
8899
|
-
if (!isKitRoot(source) || !
|
|
9225
|
+
if (!isKitRoot(source) || !existsSync16(join17(source, "skills/lead/references/workspace.md"))) {
|
|
8900
9226
|
throw new Error("this kit release has no workspace support; use --from with a workspace-capable kit");
|
|
8901
9227
|
}
|
|
8902
|
-
const runtime =
|
|
9228
|
+
const runtime = join17(ws.root, RUNTIME);
|
|
8903
9229
|
if (realpathSync3(source) === runtime) throw new Error("already using this workspace kit");
|
|
8904
9230
|
const staging = `${runtime}.${randomUUID()}`;
|
|
8905
9231
|
const previous = `${staging}.previous`;
|
|
8906
9232
|
try {
|
|
8907
|
-
mkdirSync5(
|
|
8908
|
-
copyFileSync2(
|
|
8909
|
-
cpSync(
|
|
8910
|
-
if (
|
|
9233
|
+
mkdirSync5(join17(staging, "dist"), { recursive: true });
|
|
9234
|
+
copyFileSync2(join17(source, "dist/lead.mjs"), join17(staging, "dist/lead.mjs"));
|
|
9235
|
+
cpSync(join17(source, "skills"), join17(staging, "skills"), { recursive: true });
|
|
9236
|
+
if (existsSync16(runtime)) renameSync(runtime, previous);
|
|
8911
9237
|
try {
|
|
8912
9238
|
renameSync(staging, runtime);
|
|
8913
9239
|
} catch (error) {
|
|
8914
|
-
if (
|
|
9240
|
+
if (existsSync16(previous)) renameSync(previous, runtime);
|
|
8915
9241
|
throw error;
|
|
8916
9242
|
}
|
|
8917
9243
|
writeEntrypoints(ws.root);
|
|
@@ -8928,13 +9254,13 @@ function writeEntrypoints(root) {
|
|
|
8928
9254
|
files2[`${host}/skills/lead-goal/SKILL.md`] = "workspace-goal.md";
|
|
8929
9255
|
}
|
|
8930
9256
|
for (const file of Object.keys(files2)) {
|
|
8931
|
-
const target =
|
|
8932
|
-
if (!
|
|
8933
|
-
const managed = file === ".lead/lead.mjs" ? isPortableLauncher(root) : /^<!-- evercrew:workspace-entry -->$/m.test(
|
|
9257
|
+
const target = join17(root, file);
|
|
9258
|
+
if (!existsSync16(target)) continue;
|
|
9259
|
+
const managed = file === ".lead/lead.mjs" ? isPortableLauncher(root) : /^<!-- evercrew:workspace-entry -->$/m.test(readFileSync14(target, "utf8"));
|
|
8934
9260
|
if (!managed) throw new Error(`keep existing ${target}; migrate it before attaching`);
|
|
8935
9261
|
}
|
|
8936
9262
|
for (const [file, template] of Object.entries(files2)) {
|
|
8937
|
-
const target =
|
|
9263
|
+
const target = join17(root, file);
|
|
8938
9264
|
mkdirSync5(dirname3(target), { recursive: true });
|
|
8939
9265
|
writeFileSync6(target, TEMPLATES[template]);
|
|
8940
9266
|
}
|
|
@@ -8942,41 +9268,41 @@ function writeEntrypoints(root) {
|
|
|
8942
9268
|
|
|
8943
9269
|
// src/cli.ts
|
|
8944
9270
|
import { execFileSync as execFileSync6, spawnSync as spawnSync3 } from "node:child_process";
|
|
8945
|
-
import { existsSync as
|
|
9271
|
+
import { existsSync as existsSync30, mkdtempSync as mkdtempSync3, rmSync as rmSync6 } from "node:fs";
|
|
8946
9272
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
8947
9273
|
|
|
8948
9274
|
// src/mode.ts
|
|
8949
|
-
import { existsSync as
|
|
8950
|
-
import { join as
|
|
9275
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync6, readFileSync as readFileSync15, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
9276
|
+
import { join as join18 } from "node:path";
|
|
8951
9277
|
var MODE_PATH = ".lead/mode";
|
|
8952
9278
|
var MODES = ["auto", "approve"];
|
|
8953
9279
|
function isMode(v) {
|
|
8954
9280
|
return MODES.includes(v);
|
|
8955
9281
|
}
|
|
8956
9282
|
function readMode(root) {
|
|
8957
|
-
const p =
|
|
8958
|
-
if (!
|
|
8959
|
-
const v =
|
|
9283
|
+
const p = join18(root, MODE_PATH);
|
|
9284
|
+
if (!existsSync17(p)) return void 0;
|
|
9285
|
+
const v = readFileSync15(p, "utf8").trim().split(/\s+/)[0] ?? "";
|
|
8960
9286
|
return isMode(v) ? v : void 0;
|
|
8961
9287
|
}
|
|
8962
9288
|
function writeMode(root, mode) {
|
|
8963
|
-
mkdirSync6(
|
|
8964
|
-
writeFileSync7(
|
|
9289
|
+
mkdirSync6(join18(root, ".lead"), { recursive: true });
|
|
9290
|
+
writeFileSync7(join18(root, MODE_PATH), `${mode}
|
|
8965
9291
|
`);
|
|
8966
9292
|
}
|
|
8967
9293
|
function clearMode(root) {
|
|
8968
|
-
rmSync3(
|
|
9294
|
+
rmSync3(join18(root, MODE_PATH), { force: true });
|
|
8969
9295
|
}
|
|
8970
9296
|
|
|
8971
9297
|
// src/status.ts
|
|
8972
|
-
import { existsSync as
|
|
8973
|
-
import { join as
|
|
9298
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
9299
|
+
import { join as join21 } from "node:path";
|
|
8974
9300
|
|
|
8975
9301
|
// src/git.ts
|
|
8976
9302
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
8977
9303
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync4 } from "node:fs";
|
|
8978
9304
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8979
|
-
import { join as
|
|
9305
|
+
import { join as join19 } from "node:path";
|
|
8980
9306
|
function git(cwd, args, env = {}) {
|
|
8981
9307
|
return execFileSync4("git", args, {
|
|
8982
9308
|
cwd,
|
|
@@ -8986,8 +9312,8 @@ function git(cwd, args, env = {}) {
|
|
|
8986
9312
|
}).trim();
|
|
8987
9313
|
}
|
|
8988
9314
|
function treeId(cwd) {
|
|
8989
|
-
const dir = mkdtempSync2(
|
|
8990
|
-
const index =
|
|
9315
|
+
const dir = mkdtempSync2(join19(tmpdir2(), "lead-index-"));
|
|
9316
|
+
const index = join19(dir, "index");
|
|
8991
9317
|
try {
|
|
8992
9318
|
const env = { GIT_INDEX_FILE: index };
|
|
8993
9319
|
try {
|
|
@@ -9010,15 +9336,15 @@ function currentBranch(cwd) {
|
|
|
9010
9336
|
|
|
9011
9337
|
// src/lifecycle.ts
|
|
9012
9338
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
9013
|
-
import { cpSync as cpSync2, existsSync as
|
|
9014
|
-
import { dirname as dirname4, join as
|
|
9339
|
+
import { cpSync as cpSync2, existsSync as existsSync18, mkdirSync as mkdirSync7, readFileSync as readFileSync16, realpathSync as realpathSync4, statSync as statSync5, writeFileSync as writeFileSync8 } from "node:fs";
|
|
9340
|
+
import { dirname as dirname4, join as join20, relative as relative9, sep as sep4 } from "node:path";
|
|
9015
9341
|
var slug = (t) => t.title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "task";
|
|
9016
9342
|
var projectPrefix = (ctx) => ctx.project && ctx.project.name !== "." ? `${ctx.project.name}-` : "";
|
|
9017
9343
|
var worktreeRel = (ctx, t) => `.claude/worktrees/${projectPrefix(ctx)}${t.id}`;
|
|
9018
9344
|
var branchName = (ctx, t) => `task/${ctx.project && ctx.project.name !== "." ? `${ctx.project.name}/` : ""}${t.id}-${slug(t)}`;
|
|
9019
9345
|
function taskDir(ctx, t) {
|
|
9020
9346
|
const wt = t.claim?.worktree;
|
|
9021
|
-
return wt &&
|
|
9347
|
+
return wt && existsSync18(join20(ctx.root, wt)) ? join20(ctx.root, wt) : ctx.root;
|
|
9022
9348
|
}
|
|
9023
9349
|
function startTask(ctx, t, opts) {
|
|
9024
9350
|
const byId = new Map(ctx.tasks.map((x) => [x.id, x]));
|
|
@@ -9032,8 +9358,8 @@ function startTask(ctx, t, opts) {
|
|
|
9032
9358
|
const branch = t.branch ?? branchName(ctx, t);
|
|
9033
9359
|
const wtRel = t.claim?.worktree ?? worktreeRel(ctx, t);
|
|
9034
9360
|
let copied = [];
|
|
9035
|
-
const wtAbs =
|
|
9036
|
-
if (!
|
|
9361
|
+
const wtAbs = join20(ctx.root, wtRel);
|
|
9362
|
+
if (!existsSync18(wtAbs)) {
|
|
9037
9363
|
try {
|
|
9038
9364
|
let exists = true;
|
|
9039
9365
|
try {
|
|
@@ -9076,9 +9402,9 @@ function copyUntrackedProject(ctx, wtAbs) {
|
|
|
9076
9402
|
for (const line of porcelain.split("\n")) {
|
|
9077
9403
|
if (!line.startsWith("?? ")) continue;
|
|
9078
9404
|
const file = line.slice(3).replaceAll('"', "");
|
|
9079
|
-
const src =
|
|
9080
|
-
const dst =
|
|
9081
|
-
if (!
|
|
9405
|
+
const src = join20(ctx.root, file);
|
|
9406
|
+
const dst = join20(wtAbs, file);
|
|
9407
|
+
if (!existsSync18(src) || existsSync18(dst)) continue;
|
|
9082
9408
|
mkdirSync7(dirname4(dst), { recursive: true });
|
|
9083
9409
|
cpSync2(src, dst, { recursive: true });
|
|
9084
9410
|
copied.push(file);
|
|
@@ -9098,7 +9424,7 @@ function recordChecks(ctx, t, opts) {
|
|
|
9098
9424
|
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
9099
9425
|
const stamp = now.toISOString().replace(/[:.]/g, "-");
|
|
9100
9426
|
const logRel = `.lead/logs/${t.id}-${stamp}.log`;
|
|
9101
|
-
mkdirSync7(
|
|
9427
|
+
mkdirSync7(join20(ctx.root, ".lead/logs"), { recursive: true });
|
|
9102
9428
|
let log = "";
|
|
9103
9429
|
const commands = [];
|
|
9104
9430
|
const failures = [];
|
|
@@ -9114,7 +9440,7 @@ ${output}
|
|
|
9114
9440
|
if (code !== 0) failures.push(`${name} (exit ${code}):
|
|
9115
9441
|
${tail(output, 40)}`);
|
|
9116
9442
|
}
|
|
9117
|
-
writeFileSync8(
|
|
9443
|
+
writeFileSync8(join20(ctx.root, logRel), log);
|
|
9118
9444
|
const commit = treeId(dir);
|
|
9119
9445
|
const round = t.rounds + 1;
|
|
9120
9446
|
const summary = commands.map((c) => `\`${c.cmd}\` \u2192 ${c.exit_code}`).join(", ");
|
|
@@ -9200,10 +9526,20 @@ function finishTask(ctx, t, opts) {
|
|
|
9200
9526
|
});
|
|
9201
9527
|
let cleanup = "";
|
|
9202
9528
|
const wt = t.claim?.worktree ?? worktreeRel(ctx, t);
|
|
9203
|
-
if (
|
|
9529
|
+
if (existsSync18(join20(ctx.root, wt))) {
|
|
9204
9530
|
try {
|
|
9531
|
+
const abs = join20(ctx.root, wt);
|
|
9532
|
+
const inside = (() => {
|
|
9533
|
+
try {
|
|
9534
|
+
const here = realpathSync4(process.cwd());
|
|
9535
|
+
const target = realpathSync4(abs);
|
|
9536
|
+
return here === target || here.startsWith(target + sep4);
|
|
9537
|
+
} catch {
|
|
9538
|
+
return false;
|
|
9539
|
+
}
|
|
9540
|
+
})();
|
|
9205
9541
|
git(ctx.root, ["worktree", "remove", wt]);
|
|
9206
|
-
cleanup = `; worktree ${wt} removed`;
|
|
9542
|
+
cleanup = `; worktree ${wt} removed${inside ? `; the shell was inside it, so run the next commands from ${ctx.root}` : ""}`;
|
|
9207
9543
|
} catch {
|
|
9208
9544
|
cleanup = `; worktree ${wt} kept (it has local changes)`;
|
|
9209
9545
|
}
|
|
@@ -9215,7 +9551,7 @@ function finishTask(ctx, t, opts) {
|
|
|
9215
9551
|
if (blockers.length) return { ok: false, message: `${t.id} cannot be finished:
|
|
9216
9552
|
- ${blockers.join("\n- ")}` };
|
|
9217
9553
|
const qa = latestQa(ctx, t);
|
|
9218
|
-
const text =
|
|
9554
|
+
const text = readFileSync16(join20(ctx.root, t.file), "utf8");
|
|
9219
9555
|
recordRun(ctx.root, {
|
|
9220
9556
|
kind: "task",
|
|
9221
9557
|
subject: { project: ctx.project.name, task: t.id, tree: t.checks_run.commit },
|
|
@@ -9258,7 +9594,7 @@ function taskActivity(ctx, t) {
|
|
|
9258
9594
|
add(t.claim?.since);
|
|
9259
9595
|
let dirtyFiles = 0;
|
|
9260
9596
|
let commitsAhead = 0;
|
|
9261
|
-
const wt = t.claim?.worktree &&
|
|
9597
|
+
const wt = t.claim?.worktree && existsSync18(join20(ctx.root, t.claim.worktree)) ? join20(ctx.root, t.claim.worktree) : void 0;
|
|
9262
9598
|
if (wt) {
|
|
9263
9599
|
try {
|
|
9264
9600
|
const base = currentBranch(ctx.root);
|
|
@@ -9267,8 +9603,8 @@ function taskActivity(ctx, t) {
|
|
|
9267
9603
|
const lines = git(wt, ["status", "--porcelain", "--untracked-files=all"]).split("\n").filter(Boolean);
|
|
9268
9604
|
dirtyFiles = lines.length;
|
|
9269
9605
|
for (const l of lines.slice(0, 200)) {
|
|
9270
|
-
const f =
|
|
9271
|
-
if (
|
|
9606
|
+
const f = join20(wt, l.slice(3).split(" -> ").pop());
|
|
9607
|
+
if (existsSync18(f)) times.push(statSync5(f).mtimeMs);
|
|
9272
9608
|
}
|
|
9273
9609
|
} catch {
|
|
9274
9610
|
}
|
|
@@ -9280,8 +9616,8 @@ function stopCheck(ctx, input, now = /* @__PURE__ */ new Date()) {
|
|
|
9280
9616
|
const session = input.session_id;
|
|
9281
9617
|
if (!session || !ctx.project) return void 0;
|
|
9282
9618
|
const t = ctx.tasks.find((x) => x.status === "in_progress" && x.claim?.session === session);
|
|
9283
|
-
const counter =
|
|
9284
|
-
const reset = () =>
|
|
9619
|
+
const counter = join20(ctx.root, ".lead/logs", `stop-${session.replace(/[^a-zA-Z0-9-]/g, "")}.json`);
|
|
9620
|
+
const reset = () => existsSync18(counter) && writeFileSync8(counter, '{"count":0}');
|
|
9285
9621
|
if (!t) {
|
|
9286
9622
|
reset();
|
|
9287
9623
|
return void 0;
|
|
@@ -9295,8 +9631,8 @@ function stopCheck(ctx, input, now = /* @__PURE__ */ new Date()) {
|
|
|
9295
9631
|
reset();
|
|
9296
9632
|
return void 0;
|
|
9297
9633
|
}
|
|
9298
|
-
mkdirSync7(
|
|
9299
|
-
const count =
|
|
9634
|
+
mkdirSync7(join20(ctx.root, ".lead/logs"), { recursive: true });
|
|
9635
|
+
const count = existsSync18(counter) ? JSON.parse(readFileSync16(counter, "utf8")).count : 0;
|
|
9300
9636
|
if (count >= MAX_STOP_BLOCKS) {
|
|
9301
9637
|
reset();
|
|
9302
9638
|
updateTask(
|
|
@@ -9422,7 +9758,7 @@ function status(ctx, opts = {}) {
|
|
|
9422
9758
|
const waiting = active.filter((t) => t.status === "blocked" || t.status === "in_progress");
|
|
9423
9759
|
s.independentReady = ready.filter((t) => waiting.every((b) => !touchesOverlap(t.touches, b.touches).length)).map((t) => t.id);
|
|
9424
9760
|
}
|
|
9425
|
-
const hasPlan =
|
|
9761
|
+
const hasPlan = existsSync19(join21(project.workDir, "one-pager.md"));
|
|
9426
9762
|
const merged = tasks.filter((t) => t.status === "review" && t.branch && opts.isMerged?.(t.branch)).map((t) => t.id);
|
|
9427
9763
|
if (s.errors > 0) s.next = { kind: "fix", reason: `${s.errors} errors in work/ or config; run \`lead check\`` };
|
|
9428
9764
|
else if (mine) s.next = { kind: "continue_task", reason: `${mine.id} is in progress in this session`, task: mine.id };
|
|
@@ -9433,7 +9769,7 @@ function status(ctx, opts = {}) {
|
|
|
9433
9769
|
s.next = { kind: "adopted_project", reason: "use the current One Pager and tracker; local lead files do not cover the full roadmap" };
|
|
9434
9770
|
} else if (!hasPlan && tasks.length === 0) s.next = { kind: "plan", reason: "no one-pager and no tasks yet" };
|
|
9435
9771
|
else if (tasks.length === 0) {
|
|
9436
|
-
const drafts = loadSections(ctx.root, project.workDir).sections.filter((x) => x.status === "draft" && x.body.replace(/<!--[\s\S]*?-->/g, "").replace(/^#.*$/gm, "").trim().length > 0);
|
|
9772
|
+
const drafts = loadSections(ctx.root, project.workDir).sections.filter((x) => x.status === "draft" && !isUntouchedTemplate(x.name, x.body) && x.body.replace(/<!--[\s\S]*?-->/g, "").replace(/^#.*$/gm, "").trim().length > 0);
|
|
9437
9773
|
s.next = drafts.length ? { kind: "confirm_spec", reason: "the spec is written and waits for confirmation before tasks", sections: drafts.map((x) => x.name) } : { kind: "plan", reason: "one-pager has no tasks yet" };
|
|
9438
9774
|
} else if (s.blocked.length) s.next = { kind: "answer", reason: "tasks wait for a human decision", tasks: s.blocked };
|
|
9439
9775
|
else if (inWave.length) s.next = { kind: "task", reason: wave === void 0 ? "ready tasks (waves not set)" : `wave ${wave} has ready tasks`, tasks: inWave.map((t) => t.id), wave };
|
|
@@ -9447,23 +9783,23 @@ function status(ctx, opts = {}) {
|
|
|
9447
9783
|
}
|
|
9448
9784
|
|
|
9449
9785
|
// src/write.ts
|
|
9450
|
-
import { readFileSync as
|
|
9451
|
-
import { join as
|
|
9452
|
-
import { existsSync as
|
|
9786
|
+
import { readFileSync as readFileSync18, writeFileSync as writeFileSync10 } from "node:fs";
|
|
9787
|
+
import { join as join23 } from "node:path";
|
|
9788
|
+
import { existsSync as existsSync21 } from "node:fs";
|
|
9453
9789
|
|
|
9454
9790
|
// src/sync.ts
|
|
9455
9791
|
import { createHash as createHash5 } from "node:crypto";
|
|
9456
|
-
import { existsSync as
|
|
9457
|
-
import { basename, join as
|
|
9792
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync8, readdirSync as readdirSync10, readFileSync as readFileSync17, statSync as statSync6, writeFileSync as writeFileSync9 } from "node:fs";
|
|
9793
|
+
import { basename, join as join22, posix, relative as relative10 } from "node:path";
|
|
9458
9794
|
var SYNC_FILE = "sync.json";
|
|
9459
9795
|
var hash2 = (s) => createHash5("sha256").update(s).digest("hex").slice(0, 16);
|
|
9460
9796
|
function readSyncState(workDir) {
|
|
9461
|
-
const p =
|
|
9462
|
-
if (!
|
|
9463
|
-
return JSON.parse(
|
|
9797
|
+
const p = join22(workDir, SYNC_FILE);
|
|
9798
|
+
if (!existsSync20(p)) return { version: 1 };
|
|
9799
|
+
return JSON.parse(readFileSync17(p, "utf8"));
|
|
9464
9800
|
}
|
|
9465
9801
|
function writeSyncState(workDir, s) {
|
|
9466
|
-
writeFileSync9(
|
|
9802
|
+
writeFileSync9(join22(workDir, SYNC_FILE), `${JSON.stringify(s, null, 2)}
|
|
9467
9803
|
`);
|
|
9468
9804
|
}
|
|
9469
9805
|
var projectName = (ctx) => ctx.project.name === "." ? basename(ctx.root) : ctx.project.name;
|
|
@@ -9505,12 +9841,12 @@ function adoptionMapping(ctx) {
|
|
|
9505
9841
|
const story = state.jira?.story;
|
|
9506
9842
|
rows.push(story ? `Jira Story (${story.key}) \u2014 ${story.observeOnly || !story.managed ? "observe-only" : "managed"}` : "Jira Story: unmapped");
|
|
9507
9843
|
const tasks = new Map(ctx.tasks.map((task) => [task.id, task]));
|
|
9508
|
-
for (const [
|
|
9509
|
-
const task = tasks.get(
|
|
9844
|
+
for (const [id2, issue] of Object.entries(state.jira?.tasks ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
|
|
9845
|
+
const task = tasks.get(id2);
|
|
9510
9846
|
const milestone = ctx.onePager?.milestones.find((m) => m.id === task?.milestone);
|
|
9511
9847
|
const access = issue.observeOnly || !issue.managed ? "observe-only" : "managed";
|
|
9512
9848
|
const observed = access === "observe-only" && issue.status ? ` \xB7 source status: ${issue.status}` : "";
|
|
9513
|
-
rows.push(`Jira ${task?.title ??
|
|
9849
|
+
rows.push(`Jira ${task?.title ?? id2} (${issue.key}) \u2014 ${access}${observed} \xB7 ${task ? `milestone: ${milestone?.title ?? task.milestone} \xB7 lead status: ${task.status}` : "no local task"}`);
|
|
9514
9850
|
}
|
|
9515
9851
|
}
|
|
9516
9852
|
return rows;
|
|
@@ -9527,14 +9863,14 @@ function mergeRequestUrl(repo, branch) {
|
|
|
9527
9863
|
}
|
|
9528
9864
|
function remoteMarkdown(text, state, site, notes, links) {
|
|
9529
9865
|
const noteUrl2 = (key) => {
|
|
9530
|
-
const
|
|
9531
|
-
return
|
|
9866
|
+
const id2 = activeNote(state, key)?.id;
|
|
9867
|
+
return id2 && notes ? `https://${notes.host}/space/${notes.workspace}/document/${id2}` : void 0;
|
|
9532
9868
|
};
|
|
9533
|
-
return text.replace(/^---\n[\s\S]*?\n---\n/, "").replace(/<!--[\s\S]*?-->\n?/g, "").replace(/\[(T-\d+)\]\([^)]*\)/g, (_m,
|
|
9534
|
-
const taskNote = noteUrl2(`tasks/${
|
|
9535
|
-
if (taskNote) return `[${
|
|
9536
|
-
const key = state.jira?.tasks[
|
|
9537
|
-
return key && site ? `[${
|
|
9869
|
+
return text.replace(/^---\n[\s\S]*?\n---\n/, "").replace(/<!--[\s\S]*?-->\n?/g, "").replace(/\[(T-\d+)\]\([^)]*\)/g, (_m, id2) => {
|
|
9870
|
+
const taskNote = noteUrl2(`tasks/${id2}`);
|
|
9871
|
+
if (taskNote) return `[${id2}](${taskNote})`;
|
|
9872
|
+
const key = state.jira?.tasks[id2]?.key;
|
|
9873
|
+
return key && site ? `[${id2}](https://${site}/browse/${key})` : id2;
|
|
9538
9874
|
}).replace(/\[([^\]]+)\]\((?!https?:|mailto:|#)([^)\s]+)\)/g, (_m, label, href) => {
|
|
9539
9875
|
const [file, anchor] = href.replace(/^\.\//, "").split("#");
|
|
9540
9876
|
const path = posix.join(links?.dir ?? ".", file);
|
|
@@ -9642,37 +9978,69 @@ function docs(ctx, taskSpecs2 = []) {
|
|
|
9642
9978
|
const w = ctx.project.workDir;
|
|
9643
9979
|
const t = projectTitle(ctx);
|
|
9644
9980
|
const out = [];
|
|
9645
|
-
const add = (key, title, path) =>
|
|
9646
|
-
add("board", `Board (${t})`,
|
|
9647
|
-
add("architecture", `Architecture (${t})`,
|
|
9648
|
-
add("history", `History (${t})`,
|
|
9649
|
-
add("spec-research", `Research (${t})`,
|
|
9650
|
-
const research =
|
|
9651
|
-
if (
|
|
9652
|
-
for (const f of
|
|
9653
|
-
if (f.endsWith(".md")) add(`research/${f}`, `${displayName(f.replace(/\.md$/, ""))} (${t})`,
|
|
9981
|
+
const add = (key, title, path) => existsSync20(path) && out.push({ key, title, text: readFileSync17(path, "utf8"), path: relative10(ctx.root, path) });
|
|
9982
|
+
add("board", `Board (${t})`, join22(w, "board.md"));
|
|
9983
|
+
add("architecture", `Architecture (${t})`, join22(w, "architecture.md"));
|
|
9984
|
+
add("history", `History (${t})`, join22(w, "history.md"));
|
|
9985
|
+
add("spec-research", `Research (${t})`, join22(w, "spec", "01-research.md"));
|
|
9986
|
+
const research = join22(w, "research");
|
|
9987
|
+
if (existsSync20(research)) {
|
|
9988
|
+
for (const f of readdirSync10(research).sort()) {
|
|
9989
|
+
if (f.endsWith(".md")) add(`research/${f}`, `${displayName(f.replace(/\.md$/, ""))} (${t})`, join22(research, f));
|
|
9654
9990
|
}
|
|
9655
9991
|
}
|
|
9656
9992
|
out.push(...taskSpecs2);
|
|
9657
|
-
const candidates =
|
|
9658
|
-
if (
|
|
9659
|
-
for (const file of
|
|
9993
|
+
const candidates = join22(w, "task-notes");
|
|
9994
|
+
if (existsSync20(candidates)) {
|
|
9995
|
+
for (const file of readdirSync10(candidates, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
9660
9996
|
if (!file.isFile() || !file.name.endsWith(".md")) continue;
|
|
9661
|
-
const path =
|
|
9662
|
-
const text =
|
|
9997
|
+
const path = join22(candidates, file.name);
|
|
9998
|
+
const text = readFileSync17(path, "utf8");
|
|
9663
9999
|
const title = /^#\s+([^\n]+)$/m.exec(text)?.[1]?.trim() || displayName(basename(file.name, ".md"));
|
|
9664
10000
|
out.push({ key: `task-notes/${file.name}`, title, text, path: relative10(ctx.root, path) });
|
|
9665
10001
|
}
|
|
9666
10002
|
}
|
|
9667
|
-
const backlog =
|
|
9668
|
-
if (
|
|
9669
|
-
const text = replaceBlocks(
|
|
10003
|
+
const backlog = join22(w, "backlog.md");
|
|
10004
|
+
if (existsSync20(backlog)) {
|
|
10005
|
+
const text = replaceBlocks(readFileSync17(backlog, "utf8"), (kind) => ["tasks", "proposals"].includes(kind) ? renderBacklogItems(w) : void 0);
|
|
9670
10006
|
out.push({ key: "backlog", title: `Backlog (${t})`, text, path: relative10(ctx.root, backlog) });
|
|
9671
10007
|
}
|
|
9672
|
-
add("one-pager", `OnePager (${t})`,
|
|
10008
|
+
add("one-pager", `OnePager (${t})`, join22(w, "one-pager.md"));
|
|
9673
10009
|
return out;
|
|
9674
10010
|
}
|
|
9675
|
-
var noteUrl = (f,
|
|
10011
|
+
var noteUrl = (f, id2) => `https://${f.host}/space/${f.workspace}/document/${id2}`;
|
|
10012
|
+
var DOC_GROUPS = [[/^one-pager$/, "One Pager"], [/^(board|backlog|history|architecture)$/, "Plan"], [/^spec-|^spec\//, "Specification"], [/^research\//, "Research"], [/^tasks\//, "Task specifications"], [/^task-notes\//, "Task notes"]];
|
|
10013
|
+
function docIndex(ctx) {
|
|
10014
|
+
if (!ctx.project) return [];
|
|
10015
|
+
const state = readSyncState(ctx.project.workDir);
|
|
10016
|
+
const f = ctx.config.sync?.fusebase;
|
|
10017
|
+
const listed = docs(ctx, taskSpecs(ctx, state).docs);
|
|
10018
|
+
const specDir2 = join22(ctx.project.workDir, "spec");
|
|
10019
|
+
if (existsSync20(specDir2)) for (const file of readdirSync10(specDir2).sort()) {
|
|
10020
|
+
const path = relative10(ctx.root, join22(specDir2, file));
|
|
10021
|
+
if (file.endsWith(".md") && !listed.some((d) => d.path === path)) listed.push({ key: `spec/${file}`, title: /^#\s+([^\n]+)$/m.exec(readFileSync17(join22(specDir2, file), "utf8"))?.[1]?.trim() || displayName(file.replace(/\.md$/, "")), text: "", path });
|
|
10022
|
+
}
|
|
10023
|
+
const entries = listed.map((d) => {
|
|
10024
|
+
const note = activeNote(state, d.key);
|
|
10025
|
+
return {
|
|
10026
|
+
key: d.key,
|
|
10027
|
+
title: d.title,
|
|
10028
|
+
group: DOC_GROUPS.find(([re]) => re.test(d.key))?.[1] ?? "Other",
|
|
10029
|
+
path: d.path,
|
|
10030
|
+
modified: statSync6(join22(ctx.root, d.path)).mtime.toISOString(),
|
|
10031
|
+
...f && note && { url: noteUrl(f, note.id) }
|
|
10032
|
+
};
|
|
10033
|
+
});
|
|
10034
|
+
const order = DOC_GROUPS.map(([, g]) => g);
|
|
10035
|
+
return entries.sort((a, b) => (order.indexOf(a.group) + 99) % 99 - (order.indexOf(b.group) + 99) % 99 || a.path.localeCompare(b.path));
|
|
10036
|
+
}
|
|
10037
|
+
function docText(ctx, key) {
|
|
10038
|
+
if (!ctx.project) return void 0;
|
|
10039
|
+
const entry = docIndex(ctx).find((d) => d.key === key);
|
|
10040
|
+
if (!entry) return void 0;
|
|
10041
|
+
const rendered = docs(ctx).find((d) => d.key === key)?.text;
|
|
10042
|
+
return rendered || readFileSync17(join22(ctx.root, entry.path), "utf8");
|
|
10043
|
+
}
|
|
9676
10044
|
var SPEC_SECTIONS = ["Goal", "User flow", "Technical design", "Decisions", "Acceptance criteria", "Out of scope"];
|
|
9677
10045
|
var SPEC_LINKS = ["Epic", "Jira Story", "Proposal", "Mockup", "One Pager"];
|
|
9678
10046
|
var EVIDENCE_VIDEO = "Evidence video";
|
|
@@ -9695,9 +10063,9 @@ function taskSpecs(ctx, state) {
|
|
|
9695
10063
|
const key = `tasks/${task.id}`;
|
|
9696
10064
|
const known = state.fusebase?.notes[key];
|
|
9697
10065
|
if (known?.observeOnly || inArchive(known?.path ?? "") || inArchive(task.file)) continue;
|
|
9698
|
-
const spec =
|
|
9699
|
-
const path =
|
|
9700
|
-
const source =
|
|
10066
|
+
const spec = join22(ctx.project.workDir, "task-specs", `${task.id}.md`);
|
|
10067
|
+
const path = existsSync20(spec) ? relative10(ctx.root, spec) : task.file;
|
|
10068
|
+
const source = readFileSync17(join22(ctx.root, path), "utf8");
|
|
9701
10069
|
const missing = [];
|
|
9702
10070
|
const tasksFolder = state.fusebase?.tasksFolder;
|
|
9703
10071
|
if (tasksFolder && inArchive(tasksFolder.path ?? tasksFolder.title)) missing.push("the mapped Tasks folder is archived");
|
|
@@ -9759,10 +10127,10 @@ function taskSyncBlockers(ctx) {
|
|
|
9759
10127
|
return ctx.project ? taskSpecs(ctx, readSyncState(ctx.project.workDir)).blocked : [];
|
|
9760
10128
|
}
|
|
9761
10129
|
function renderBacklogItems(workDir) {
|
|
9762
|
-
const dir =
|
|
9763
|
-
if (!
|
|
9764
|
-
const rows =
|
|
9765
|
-
const title = /^#\s+([^\n]+)$/m.exec(
|
|
10130
|
+
const dir = join22(workDir, "task-notes");
|
|
10131
|
+
if (!existsSync20(dir)) return "No intake proposals recorded.";
|
|
10132
|
+
const rows = readdirSync10(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".md")).sort((a, b) => a.name.localeCompare(b.name)).map(({ name }) => {
|
|
10133
|
+
const title = /^#\s+([^\n]+)$/m.exec(readFileSync17(join22(dir, name), "utf8"))?.[1]?.trim() || basename(name, ".md");
|
|
9766
10134
|
return `- [${esc(title)}](task-notes/${name})`;
|
|
9767
10135
|
});
|
|
9768
10136
|
return rows.join("\n") || "No intake proposals recorded.";
|
|
@@ -9771,7 +10139,7 @@ function remoteOnePager(ctx, d, state, cfg) {
|
|
|
9771
10139
|
if (!ctx.onePager) return d.text;
|
|
9772
10140
|
const blocks = remoteOnePagerBlocks(ctx.tasks, ctx.onePager.milestones, gitMergedChecker(ctx.root), ctx.config.can_show, {
|
|
9773
10141
|
site: cfg.jira?.site,
|
|
9774
|
-
keys: Object.fromEntries(Object.entries(state.jira?.tasks ?? {}).map(([
|
|
10142
|
+
keys: Object.fromEntries(Object.entries(state.jira?.tasks ?? {}).map(([id2, t]) => [id2, t.key]))
|
|
9775
10143
|
}, Object.fromEntries(ctx.tasks.flatMap((task) => {
|
|
9776
10144
|
const note = activeNote(state, `tasks/${task.id}`);
|
|
9777
10145
|
return note && cfg.fusebase ? [[task.id, { url: noteUrl(cfg.fusebase, note.id), evidenceVideo: note.evidenceVideo }]] : [];
|
|
@@ -9905,16 +10273,16 @@ ${open.join("\n")}` : "\u2705 All acceptance criteria pass."
|
|
|
9905
10273
|
return { marker, body };
|
|
9906
10274
|
}
|
|
9907
10275
|
function evidenceFiles(ctx) {
|
|
9908
|
-
const dir =
|
|
9909
|
-
if (!
|
|
10276
|
+
const dir = join22(ctx.root, ".lead/logs/qa");
|
|
10277
|
+
if (!existsSync20(dir)) return [];
|
|
9910
10278
|
const ids = new Set(ctx.tasks.map((t) => t.id));
|
|
9911
10279
|
const out = [];
|
|
9912
|
-
for (const sub of
|
|
9913
|
-
const
|
|
9914
|
-
if (!
|
|
9915
|
-
const p =
|
|
10280
|
+
for (const sub of readdirSync10(dir).sort()) {
|
|
10281
|
+
const id2 = /^(T-\d+)/.exec(sub)?.[1];
|
|
10282
|
+
if (!id2 || !ids.has(id2)) continue;
|
|
10283
|
+
const p = join22(dir, sub);
|
|
9916
10284
|
try {
|
|
9917
|
-
for (const f of
|
|
10285
|
+
for (const f of readdirSync10(p).sort()) if (/\.(png|jpe?g|webp|gif|mp4|webm|mov)$/i.test(f)) out.push(relative10(ctx.root, join22(p, f)));
|
|
9918
10286
|
} catch {
|
|
9919
10287
|
}
|
|
9920
10288
|
}
|
|
@@ -9942,7 +10310,7 @@ function syncPlan(ctx) {
|
|
|
9942
10310
|
for (const t of [...ctx.tasks].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
9943
10311
|
if (t.sync_jira === false) continue;
|
|
9944
10312
|
const tsum = `${t.id} ${t.title}`;
|
|
9945
|
-
const goal = section(
|
|
10313
|
+
const goal = section(readFileSync17(join22(ctx.root, t.file), "utf8"), "Goal");
|
|
9946
10314
|
const tdesc = taskDescription(t, { goal, links: cfg.links, evidence: state.fusebase?.evidence?.files, onePager: onePagerUrl });
|
|
9947
10315
|
const h2 = hash2(tsum + tdesc);
|
|
9948
10316
|
const jiraStatus = j.statuses[t.status] ?? t.status;
|
|
@@ -10008,7 +10376,7 @@ function syncPlan(ctx) {
|
|
|
10008
10376
|
for (const p of files2) {
|
|
10009
10377
|
if (ev.files[p]) continue;
|
|
10010
10378
|
const task = /(T-\d+)/.exec(p)[1];
|
|
10011
|
-
actions.push({ kind: "fusebase.evidence.attach", org: f.org, workspace: f.workspace, noteId: ev.id, task, file:
|
|
10379
|
+
actions.push({ kind: "fusebase.evidence.attach", org: f.org, workspace: f.workspace, noteId: ev.id, task, file: join22(ctx.root, p), path: p });
|
|
10012
10380
|
}
|
|
10013
10381
|
}
|
|
10014
10382
|
}
|
|
@@ -10027,9 +10395,9 @@ function syncRecord(ctx, action, result) {
|
|
|
10027
10395
|
const old = s.fusebase;
|
|
10028
10396
|
if (action.role === "tasks") {
|
|
10029
10397
|
if (!old?.folder || old.folder.id !== action.parentId) throw new Error("the Tasks folder needs a mapped product folder");
|
|
10030
|
-
const
|
|
10031
|
-
if (old.tasksFolder && old.tasksFolder.id !==
|
|
10032
|
-
old.tasksFolder ??= { id, title: action.title };
|
|
10398
|
+
const id2 = need(result.id, "id");
|
|
10399
|
+
if (old.tasksFolder && old.tasksFolder.id !== id2) throw new Error("a different Tasks folder is already mapped");
|
|
10400
|
+
old.tasksFolder ??= { id: id2, title: action.title };
|
|
10033
10401
|
break;
|
|
10034
10402
|
}
|
|
10035
10403
|
s.fusebase = action.replaces ? { notes: {}, folder: { id: need(result.id, "id"), title: action.title }, trash: [...old?.trash ?? [], action.replaces] } : { ...old, notes: old?.notes ?? {}, folder: { id: need(result.id, "id"), title: action.title } };
|
|
@@ -10042,7 +10410,7 @@ function syncRecord(ctx, action, result) {
|
|
|
10042
10410
|
s.fusebase.evidence.files[action.path] = need(result.url, "url");
|
|
10043
10411
|
break;
|
|
10044
10412
|
case "fusebase.trash":
|
|
10045
|
-
s.fusebase.trash = (s.fusebase.trash ?? []).filter((
|
|
10413
|
+
s.fusebase.trash = (s.fusebase.trash ?? []).filter((id2) => !action.itemIds.includes(id2));
|
|
10046
10414
|
break;
|
|
10047
10415
|
case "fusebase.note.create":
|
|
10048
10416
|
case "fusebase.note.update": {
|
|
@@ -10059,8 +10427,8 @@ function syncRecord(ctx, action, result) {
|
|
|
10059
10427
|
...prev?.observeOnly ? { observeOnly: true } : {},
|
|
10060
10428
|
...action.key.startsWith("tasks/") && hasVideoLink(section(action.markdown, EVIDENCE_VIDEO)) ? { evidenceVideo: true } : {}
|
|
10061
10429
|
};
|
|
10062
|
-
mkdirSync8(
|
|
10063
|
-
writeFileSync9(
|
|
10430
|
+
mkdirSync8(join22(ctx.project.workDir, "sync-base"), { recursive: true });
|
|
10431
|
+
writeFileSync9(join22(ctx.project.workDir, "sync-base", `${action.key.replace(/\//g, "__")}.md`), action.markdown);
|
|
10064
10432
|
if (action.kind === "fusebase.note.create") {
|
|
10065
10433
|
if (prev && !action.replaces) throw new Error(`note ${action.key} already recorded`);
|
|
10066
10434
|
if (action.replaces) s.fusebase.trash = [...s.fusebase.trash ?? [], action.replaces];
|
|
@@ -10098,765 +10466,526 @@ function writeWaves(ctx) {
|
|
|
10098
10466
|
const waves = computeWaves(ctx.tasks, ctx.config.shared_paths);
|
|
10099
10467
|
if (!waves) throw new Error("dependency cycle: fix blocked_by first (run `lead check`)");
|
|
10100
10468
|
const log = [];
|
|
10101
|
-
for (const t of ctx.tasks) {
|
|
10102
|
-
const w = waves.get(t.id);
|
|
10103
|
-
if (w === void 0 || w === t.wave || t.status === "done") continue;
|
|
10104
|
-
const abs =
|
|
10105
|
-
const text =
|
|
10106
|
-
const { parsed } = parseFrontmatter(text, t.file);
|
|
10107
|
-
if (!parsed) continue;
|
|
10108
|
-
parsed.data.wave = w;
|
|
10109
|
-
writeFileSync10(abs, renderFrontmatter(parsed.data, parsed.body));
|
|
10110
|
-
log.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
10111
|
-
}
|
|
10112
|
-
return log;
|
|
10113
|
-
}
|
|
10114
|
-
function writeBoard(ctx, isMerged = gitMergedChecker(ctx.root)) {
|
|
10115
|
-
if (!ctx.project) throw new Error("no project selected");
|
|
10116
|
-
const log = [];
|
|
10117
|
-
const board = renderBoard({ projectName: ctx.project.name, tasks: ctx.tasks, onePager: ctx.onePager, config: ctx.config });
|
|
10118
|
-
const boardPath = join20(ctx.project.workDir, "board.md");
|
|
10119
|
-
let old = "";
|
|
10120
|
-
try {
|
|
10121
|
-
old = readFileSync16(boardPath, "utf8");
|
|
10122
|
-
} catch {
|
|
10123
|
-
}
|
|
10124
|
-
if (old !== board) {
|
|
10125
|
-
writeFileSync10(boardPath, board);
|
|
10126
|
-
log.push("board.md updated");
|
|
10127
|
-
}
|
|
10128
|
-
if (ctx.onePager) {
|
|
10129
|
-
const blocks = renderOnePagerBlocks(ctx.tasks, ctx.onePager.milestones, isMerged, ctx.config.can_show);
|
|
10130
|
-
const next = replaceBlocks(ctx.onePager.text, (k) => blocks[k]);
|
|
10131
|
-
if (next !== ctx.onePager.text) {
|
|
10132
|
-
writeFileSync10(join20(ctx.root, ctx.onePager.file), next);
|
|
10133
|
-
log.push(`one-pager.md blocks updated: ${blockKinds(next).join(", ")}`);
|
|
10134
|
-
}
|
|
10135
|
-
}
|
|
10136
|
-
const backlog = join20(ctx.project.workDir, "backlog.md");
|
|
10137
|
-
if (existsSync18(backlog)) {
|
|
10138
|
-
const current = readFileSync16(backlog, "utf8");
|
|
10139
|
-
const next = replaceBlocks(current, (kind) => ["tasks", "proposals"].includes(kind) ? renderBacklogItems(ctx.project.workDir) : void 0);
|
|
10140
|
-
if (next !== current) {
|
|
10141
|
-
writeFileSync10(backlog, next);
|
|
10142
|
-
log.push("backlog.md tasks updated");
|
|
10143
|
-
}
|
|
10144
|
-
}
|
|
10145
|
-
return log;
|
|
10146
|
-
}
|
|
10147
|
-
|
|
10148
|
-
// src/cli.ts
|
|
10149
|
-
import { readFileSync as readFileSync26 } from "node:fs";
|
|
10150
|
-
|
|
10151
|
-
// src/cleanroom.ts
|
|
10152
|
-
import { createHash as createHash6 } from "node:crypto";
|
|
10153
|
-
import { existsSync as existsSync19, mkdirSync as mkdirSync9, readdirSync as readdirSync9, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync6, writeFileSync as writeFileSync11 } from "node:fs";
|
|
10154
|
-
import { extname, join as join21, relative as relative11 } from "node:path";
|
|
10155
|
-
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
10156
|
-
function packageStores() {
|
|
10157
|
-
try {
|
|
10158
|
-
const p = execFileSync5("pnpm", ["store", "path"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
10159
|
-
return p ? [p.replace(/\/v\d+$/, "")] : [];
|
|
10160
|
-
} catch {
|
|
10161
|
-
return [];
|
|
10162
|
-
}
|
|
10163
|
-
}
|
|
10164
|
-
function gitCommonDir(root) {
|
|
10165
|
-
try {
|
|
10166
|
-
return realpathSync4(execFileSync5("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: root, encoding: "utf8" }).trim());
|
|
10167
|
-
} catch {
|
|
10168
|
-
return join21(root, ".git");
|
|
10169
|
-
}
|
|
10170
|
-
}
|
|
10171
|
-
var pathRules = (abs) => {
|
|
10172
|
-
const r = `//${abs.replace(/^\//, "")}`;
|
|
10173
|
-
return [`Read(${r})`, `Read(${r}/**)`];
|
|
10174
|
-
};
|
|
10175
|
-
var isUselessRule = (r) => /^(Grep|Glob|Edit)\(\/\//.test(r);
|
|
10176
|
-
function builderSettings(root, name, source, extra = []) {
|
|
10177
|
-
const abs = realpathSync4(source);
|
|
10178
|
-
if (abs === root || abs.startsWith(root + "/")) throw new Error(`the source of ${name} must live outside the repo (found inside ${root})`);
|
|
10179
|
-
const rel = `.lead/builder-${name.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`;
|
|
10180
|
-
const file = join21(root, rel);
|
|
10181
|
-
const prev = existsSync19(file) ? JSON.parse(readFileSync17(file, "utf8")) : {};
|
|
10182
|
-
const paths = [abs, join21(root, ".lead/logs/reverse"), file, ...extra.map((p) => p.startsWith("/") ? p : join21(root, p))];
|
|
10183
|
-
const deny = /* @__PURE__ */ new Set([
|
|
10184
|
-
...(prev.permissions?.deny ?? []).filter((r) => !isUselessRule(r)),
|
|
10185
|
-
...paths.flatMap(pathRules),
|
|
10186
|
-
"Bash(docker:*)",
|
|
10187
|
-
"Bash(podman:*)",
|
|
10188
|
-
"WebFetch",
|
|
10189
|
-
"WebSearch"
|
|
10190
|
-
]);
|
|
10191
|
-
const denyRead = /* @__PURE__ */ new Set([...prev.sandbox?.filesystem?.denyRead ?? [], ...paths]);
|
|
10192
|
-
const cli = 'node "$CLAUDE_PROJECT_DIR/.lead/lead.mjs"';
|
|
10193
|
-
const stores = packageStores();
|
|
10194
|
-
const settings = {
|
|
10195
|
-
...stores.length ? { env: { npm_config_store_dir: execFileSync5("pnpm", ["store", "path"], { encoding: "utf8" }).trim() } } : {},
|
|
10196
|
-
permissions: { deny: [...deny] },
|
|
10197
|
-
sandbox: {
|
|
10198
|
-
enabled: true,
|
|
10199
|
-
autoAllowBashIfSandboxed: false,
|
|
10200
|
-
allowUnsandboxedCommands: false,
|
|
10201
|
-
// The builder starts in a project folder but must write the repo's work/ and .lead/ state and
|
|
10202
|
-
// the shared .git of task worktrees, and must run the app on a local port for browser QA.
|
|
10203
|
-
filesystem: { denyRead: [...denyRead], allowWrite: [root, gitCommonDir(root), ...stores] },
|
|
10204
|
-
network: { allowLocalBinding: true }
|
|
10205
|
-
},
|
|
10206
|
-
hooks: {
|
|
10207
|
-
Stop: [{ hooks: [{ type: "command", command: `${cli} stop-check` }] }],
|
|
10208
|
-
SessionStart: [{ hooks: [{ type: "command", command: `${cli} session-start` }] }]
|
|
10209
|
-
}
|
|
10210
|
-
};
|
|
10211
|
-
mkdirSync9(join21(root, ".lead"), { recursive: true });
|
|
10212
|
-
writeFileSync11(file, `${JSON.stringify(settings, null, 2)}
|
|
10213
|
-
`);
|
|
10214
|
-
return { path: rel, launch: `claude --settings ${rel}` };
|
|
10215
|
-
}
|
|
10216
|
-
var TEXT = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte", ".css", ".scss", ".html", ".md", ".json", ".py", ".go", ".rb", ".php", ".java", ".kt", ".rs", ".sql", ".yml", ".yaml", ".txt"]);
|
|
10217
|
-
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", "coverage", "vendor", ".lead", ".claude"]);
|
|
10218
|
-
function files(dir, out = []) {
|
|
10219
|
-
if (!existsSync19(dir)) return out;
|
|
10220
|
-
const st = statSync6(dir);
|
|
10221
|
-
if (st.isFile()) {
|
|
10222
|
-
out.push(dir);
|
|
10223
|
-
return out;
|
|
10224
|
-
}
|
|
10225
|
-
for (const n of readdirSync9(dir)) {
|
|
10226
|
-
if (SKIP.has(n)) continue;
|
|
10227
|
-
const p = join21(dir, n);
|
|
10228
|
-
const s = statSync6(p);
|
|
10229
|
-
if (s.isDirectory()) files(p, out);
|
|
10230
|
-
else if (TEXT.has(extname(n)) && s.size < 1e6) out.push(p);
|
|
10231
|
-
}
|
|
10232
|
-
return out;
|
|
10233
|
-
}
|
|
10234
|
-
function meaningful(text) {
|
|
10235
|
-
return text.split("\n").map((l, i) => ({ line: i + 1, norm: l.trim().replace(/\s+/g, " ") })).filter((x) => x.norm.length >= 20 && /[a-zA-Z]{3}/.test(x.norm) && !/^(import|export \{|\/\/|#|\*|<\/?\w+>$)/.test(x.norm));
|
|
10236
|
-
}
|
|
10237
|
-
var h = (s) => createHash6("sha1").update(s).digest("hex");
|
|
10238
|
-
function similarity(source, targets, root, window = 6, longLine = 200) {
|
|
10239
|
-
const blocks = /* @__PURE__ */ new Map();
|
|
10240
|
-
const longs = /* @__PURE__ */ new Map();
|
|
10241
|
-
for (const f of files(source)) {
|
|
10242
|
-
const m = meaningful(readFileSync17(f, "utf8"));
|
|
10243
|
-
for (let i = 0; i + window <= m.length; i++) blocks.set(h(m.slice(i, i + window).map((x) => x.norm).join("\n")), { file: f, line: m[i].line });
|
|
10244
|
-
for (const x of m) if (x.norm.length >= longLine) longs.set(h(x.norm), { file: f, line: x.line });
|
|
10245
|
-
}
|
|
10246
|
-
const matches = [];
|
|
10247
|
-
for (const t of targets.flatMap((p) => files(p))) {
|
|
10248
|
-
const m = meaningful(readFileSync17(t, "utf8"));
|
|
10249
|
-
let skipUntil = -1;
|
|
10250
|
-
for (let i = 0; i + window <= m.length; i++) {
|
|
10251
|
-
if (i < skipUntil) continue;
|
|
10252
|
-
const hit = blocks.get(h(m.slice(i, i + window).map((x) => x.norm).join("\n")));
|
|
10253
|
-
if (hit) {
|
|
10254
|
-
matches.push({ file: relative11(root, t), line: m[i].line, source: relative11(source, hit.file) || hit.file, sourceLine: hit.line, kind: "block" });
|
|
10255
|
-
skipUntil = i + window;
|
|
10256
|
-
}
|
|
10257
|
-
}
|
|
10258
|
-
for (const x of m) {
|
|
10259
|
-
const hit = x.norm.length >= longLine ? longs.get(h(x.norm)) : void 0;
|
|
10260
|
-
if (hit) matches.push({ file: relative11(root, t), line: x.line, source: relative11(source, hit.file) || hit.file, sourceLine: hit.line, kind: "long-line" });
|
|
10261
|
-
}
|
|
10262
|
-
}
|
|
10263
|
-
return matches;
|
|
10264
|
-
}
|
|
10265
|
-
|
|
10266
|
-
// src/cli.ts
|
|
10267
|
-
import { basename as basename2, relative as relative13, sep as sep4 } from "node:path";
|
|
10268
|
-
|
|
10269
|
-
// src/delegate.ts
|
|
10270
|
-
import { existsSync as existsSync20, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
10271
|
-
import { join as join22 } from "node:path";
|
|
10272
|
-
function readDelegate(file, source) {
|
|
10273
|
-
if (!existsSync20(file)) return void 0;
|
|
10274
|
-
const { parsed } = parseFrontmatter(readFileSync18(file, "utf8"), file);
|
|
10275
|
-
const id = typeof parsed?.data.name === "string" ? parsed.data.name : "";
|
|
10276
|
-
if (!/^[a-z][a-z0-9-]*$/.test(id)) return void 0;
|
|
10277
|
-
return {
|
|
10278
|
-
id,
|
|
10279
|
-
title: typeof parsed?.data.title === "string" ? parsed.data.title : id,
|
|
10280
|
-
file,
|
|
10281
|
-
source,
|
|
10282
|
-
available: typeof parsed?.data.available === "string" ? parsed.data.available : ""
|
|
10283
|
-
};
|
|
10284
|
-
}
|
|
10285
|
-
function fromDir(dir, source) {
|
|
10286
|
-
if (!existsSync20(dir)) return [];
|
|
10287
|
-
const out = [];
|
|
10288
|
-
for (const name of readdirSync10(dir).sort()) {
|
|
10289
|
-
const d = readDelegate(join22(dir, name, "SKILL.md"), source);
|
|
10290
|
-
if (d) out.push(d);
|
|
10291
|
-
}
|
|
10292
|
-
return out;
|
|
10293
|
-
}
|
|
10294
|
-
function listDelegates(root, kit) {
|
|
10295
|
-
const byId = /* @__PURE__ */ new Map();
|
|
10296
|
-
for (const d of [...fromDir(join22(root, ".agents/skills/lead/delegates"), "kit"), ...fromDir(join22(root, ".claude/skills/lead/delegates"), "kit")]) {
|
|
10297
|
-
byId.set(d.id, d);
|
|
10298
|
-
}
|
|
10299
|
-
if (kit) {
|
|
10300
|
-
for (const d of fromDir(join22(kit, "skills/lead/delegates"), "kit")) byId.set(d.id, d);
|
|
10301
|
-
}
|
|
10302
|
-
for (const d of fromDir(join22(root, ".lead/delegates"), "project")) byId.set(d.id, d);
|
|
10303
|
-
return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
10304
|
-
}
|
|
10305
|
-
function delegatedTasks(tasks, id) {
|
|
10306
|
-
return tasks.filter((t) => t.delegate && (!id || t.delegate === id)).sort((a, b) => a.id.localeCompare(b.id));
|
|
10307
|
-
}
|
|
10308
|
-
|
|
10309
|
-
// src/watch.ts
|
|
10310
|
-
import { spawn } from "node:child_process";
|
|
10311
|
-
import { existsSync as existsSync21, mkdirSync as mkdirSync10, readFileSync as readFileSync19, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10312
|
-
import { join as join23 } from "node:path";
|
|
10313
|
-
var WATCH_PATH = ".lead/watch.json";
|
|
10314
|
-
var MIN_INTERVAL_MS = 5 * 60 * 1e3;
|
|
10315
|
-
var DEFAULT_INTERVAL = "15m";
|
|
10316
|
-
function parseInterval(text) {
|
|
10317
|
-
const m = /^(\d+)\s*(m|min|h)$/i.exec(text.trim());
|
|
10318
|
-
if (!m) return void 0;
|
|
10319
|
-
const n = Number(m[1]);
|
|
10320
|
-
const ms = m[2].toLowerCase().startsWith("h") ? n * 60 * 60 * 1e3 : n * 60 * 1e3;
|
|
10321
|
-
if (!Number.isFinite(ms) || ms < MIN_INTERVAL_MS) return void 0;
|
|
10322
|
-
return ms;
|
|
10323
|
-
}
|
|
10324
|
-
function readWatch(root) {
|
|
10325
|
-
const p = join23(root, WATCH_PATH);
|
|
10326
|
-
if (!existsSync21(p)) return { interval: DEFAULT_INTERVAL, close: false };
|
|
10327
|
-
try {
|
|
10328
|
-
const d = JSON.parse(readFileSync19(p, "utf8"));
|
|
10329
|
-
return { interval: typeof d.interval === "string" ? d.interval : DEFAULT_INTERVAL, close: d.close === true, pid: d.pid, startedAt: d.startedAt, due: d.due };
|
|
10330
|
-
} catch {
|
|
10331
|
-
return { interval: DEFAULT_INTERVAL, close: false };
|
|
10469
|
+
for (const t of ctx.tasks) {
|
|
10470
|
+
const w = waves.get(t.id);
|
|
10471
|
+
if (w === void 0 || w === t.wave || t.status === "done") continue;
|
|
10472
|
+
const abs = join23(ctx.root, t.file);
|
|
10473
|
+
const text = readFileSync18(abs, "utf8");
|
|
10474
|
+
const { parsed } = parseFrontmatter(text, t.file);
|
|
10475
|
+
if (!parsed) continue;
|
|
10476
|
+
parsed.data.wave = w;
|
|
10477
|
+
writeFileSync10(abs, renderFrontmatter(parsed.data, parsed.body));
|
|
10478
|
+
log.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
10332
10479
|
}
|
|
10480
|
+
return log;
|
|
10333
10481
|
}
|
|
10334
|
-
function
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
if (!pid || pid <= 1) return false;
|
|
10482
|
+
function writeBoard(ctx, isMerged = gitMergedChecker(ctx.root)) {
|
|
10483
|
+
if (!ctx.project) throw new Error("no project selected");
|
|
10484
|
+
const log = [];
|
|
10485
|
+
const board = renderBoard({ projectName: ctx.project.name, tasks: ctx.tasks, onePager: ctx.onePager, config: ctx.config });
|
|
10486
|
+
const boardPath = join23(ctx.project.workDir, "board.md");
|
|
10487
|
+
let old = "";
|
|
10341
10488
|
try {
|
|
10342
|
-
|
|
10343
|
-
return true;
|
|
10489
|
+
old = readFileSync18(boardPath, "utf8");
|
|
10344
10490
|
} catch {
|
|
10345
|
-
return false;
|
|
10346
10491
|
}
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
const on = alive(s.pid);
|
|
10351
|
-
const bits = [`watch ${on ? "on" : "off"}`, `every ${s.interval}`, s.close ? "may close a finished milestone" : "asks before closing a milestone"];
|
|
10352
|
-
if (s.due) bits.push(`check due since ${s.due}`);
|
|
10353
|
-
return bits.join(", ");
|
|
10354
|
-
}
|
|
10355
|
-
function watchCommand(root, args, opts) {
|
|
10356
|
-
const sub = args[0];
|
|
10357
|
-
const state = readWatch(root);
|
|
10358
|
-
if (sub === "start") {
|
|
10359
|
-
if (alive(state.pid)) return { ok: true, message: watchStatus(root) };
|
|
10360
|
-
state.close = opts.close === true;
|
|
10361
|
-
state.startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10362
|
-
state.pid = opts.spawnLoop?.(root) ?? 0;
|
|
10363
|
-
writeWatch(root, state);
|
|
10364
|
-
return { ok: true, message: watchStatus(root) };
|
|
10492
|
+
if (old !== board) {
|
|
10493
|
+
writeFileSync10(boardPath, board);
|
|
10494
|
+
log.push("board.md updated");
|
|
10365
10495
|
}
|
|
10366
|
-
if (
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
}
|
|
10496
|
+
if (ctx.onePager) {
|
|
10497
|
+
const blocks = renderOnePagerBlocks(ctx.tasks, ctx.onePager.milestones, isMerged, ctx.config.can_show);
|
|
10498
|
+
const next = replaceBlocks(ctx.onePager.text, (k) => blocks[k]);
|
|
10499
|
+
if (next !== ctx.onePager.text) {
|
|
10500
|
+
writeFileSync10(join23(ctx.root, ctx.onePager.file), next);
|
|
10501
|
+
log.push(`one-pager.md blocks updated: ${blockKinds(next).join(", ")}`);
|
|
10372
10502
|
}
|
|
10373
|
-
delete state.pid;
|
|
10374
|
-
delete state.startedAt;
|
|
10375
|
-
delete state.due;
|
|
10376
|
-
writeWatch(root, state);
|
|
10377
|
-
return { ok: true, message: watchStatus(root) };
|
|
10378
10503
|
}
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10504
|
+
const backlog = join23(ctx.project.workDir, "backlog.md");
|
|
10505
|
+
if (existsSync21(backlog)) {
|
|
10506
|
+
const current = readFileSync18(backlog, "utf8");
|
|
10507
|
+
const next = replaceBlocks(current, (kind) => ["tasks", "proposals"].includes(kind) ? renderBacklogItems(ctx.project.workDir) : void 0);
|
|
10508
|
+
if (next !== current) {
|
|
10509
|
+
writeFileSync10(backlog, next);
|
|
10510
|
+
log.push("backlog.md tasks updated");
|
|
10511
|
+
}
|
|
10385
10512
|
}
|
|
10386
|
-
|
|
10387
|
-
return { ok: false, message: "usage: watch [start|stop|interval 15m|status]" };
|
|
10388
|
-
}
|
|
10389
|
-
function clearDue(root) {
|
|
10390
|
-
const state = readWatch(root);
|
|
10391
|
-
delete state.due;
|
|
10392
|
-
writeWatch(root, state);
|
|
10393
|
-
}
|
|
10394
|
-
function spawnWatchLoop(leadMjs, root) {
|
|
10395
|
-
return spawn(process.execPath, [leadMjs, "watch", "loop", "--cwd", root], { detached: true, stdio: "ignore" });
|
|
10513
|
+
return log;
|
|
10396
10514
|
}
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10409
|
-
|
|
10410
|
-
|
|
10515
|
+
|
|
10516
|
+
// src/cli.ts
|
|
10517
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
10518
|
+
|
|
10519
|
+
// src/inbox.ts
|
|
10520
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
10521
|
+
import { existsSync as existsSync22, readdirSync as readdirSync11, readFileSync as readFileSync19 } from "node:fs";
|
|
10522
|
+
import { basename as basename2, join as join24, relative as relative11 } from "node:path";
|
|
10523
|
+
var id = (...parts) => createHash6("sha256").update(parts.join("\0")).digest("hex").slice(0, 10);
|
|
10524
|
+
var clean = (text) => text.replace(/<!--[\s\S]*?-->/g, "").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/[*_`]/g, "").trim();
|
|
10525
|
+
function bullets(text, heading) {
|
|
10526
|
+
const part = text.split(/^##\s+/m).slice(1).find((p) => heading.test(p.split("\n")[0].trim()));
|
|
10527
|
+
if (!part) return [];
|
|
10528
|
+
return part.replace(/<!--[\s\S]*?-->/g, "").split("\n").map((l) => /^\s*[-*]\s+(?:\[ \]\s+)?(.+)$/.exec(l)?.[1]).filter((l) => !!l && !/^none\.?$/i.test(l.trim())).map(clean);
|
|
10529
|
+
}
|
|
10530
|
+
function inbox(ctx) {
|
|
10531
|
+
if (!ctx.project) return [];
|
|
10532
|
+
const w = ctx.project.workDir;
|
|
10533
|
+
const rel = (path) => relative11(ctx.root, path);
|
|
10534
|
+
const urls = new Map(docIndex(ctx).filter((d) => d.url).map((d) => [d.path, d.url]));
|
|
10535
|
+
const source = (path) => ({ path: rel(path), ...urls.has(rel(path)) && { url: urls.get(rel(path)) } });
|
|
10536
|
+
const items = [];
|
|
10537
|
+
for (const t of ctx.tasks.filter((x) => x.status === "blocked")) {
|
|
10538
|
+
const waits = t.blocked_by.length ? `waits for ${t.blocked_by.join(", ")}` : "blocked, needs a decision";
|
|
10539
|
+
items.push({ id: id("blocker", t.id), kind: "blocker", title: `${t.id} ${t.title}`, detail: waits, source: source(join24(ctx.root, t.file)) });
|
|
10540
|
+
}
|
|
10541
|
+
const onePager = join24(w, "one-pager.md");
|
|
10542
|
+
if (existsSync22(onePager)) {
|
|
10543
|
+
for (const b of bullets(readFileSync19(onePager, "utf8"), /^needs attention$/i)) {
|
|
10544
|
+
items.push({ id: id("question", "one-pager", b), kind: "question", title: b, source: source(onePager) });
|
|
10545
|
+
}
|
|
10546
|
+
}
|
|
10547
|
+
const backlog = join24(w, "backlog.md");
|
|
10548
|
+
if (existsSync22(backlog)) {
|
|
10549
|
+
for (const b of bullets(readFileSync19(backlog, "utf8"), /^needs triage$/i)) {
|
|
10550
|
+
items.push({ id: id("question", "backlog", b), kind: "question", title: b, detail: "needs triage", source: source(backlog) });
|
|
10551
|
+
}
|
|
10552
|
+
}
|
|
10553
|
+
const notes = join24(w, "task-notes");
|
|
10554
|
+
if (existsSync22(notes)) {
|
|
10555
|
+
for (const name of readdirSync11(notes).filter((n) => n.endsWith(".md")).sort()) {
|
|
10556
|
+
const path = join24(notes, name);
|
|
10557
|
+
const title = /^#\s+([^\n]+)$/m.exec(readFileSync19(path, "utf8"))?.[1]?.trim() || basename2(name, ".md");
|
|
10558
|
+
items.push({
|
|
10559
|
+
id: id("approval", "proposal", name),
|
|
10560
|
+
kind: "approval",
|
|
10561
|
+
title: `Proposal: ${clean(title)}`,
|
|
10562
|
+
detail: "accept into the plan?",
|
|
10563
|
+
source: source(path),
|
|
10564
|
+
approve: `Accept the proposal in ${rel(path)} into the plan as a lead task, following the lead intake rules.`
|
|
10565
|
+
});
|
|
10566
|
+
}
|
|
10567
|
+
}
|
|
10568
|
+
const sections = existsSync22(join24(w, "spec")) ? loadSections(ctx.root, w).sections : [];
|
|
10569
|
+
for (const s of sections.filter((x) => x.status !== "confirmed")) {
|
|
10570
|
+
items.push({
|
|
10571
|
+
id: id("approval", "spec", s.name),
|
|
10572
|
+
kind: "approval",
|
|
10573
|
+
title: `Specification: ${s.name}`,
|
|
10574
|
+
detail: "draft, confirm?",
|
|
10575
|
+
source: source(join24(ctx.root, s.file)),
|
|
10576
|
+
approve: `Confirm the specification section "${s.name}" with lead spec --confirm ${s.name}.`
|
|
10577
|
+
});
|
|
10411
10578
|
}
|
|
10579
|
+
return items;
|
|
10412
10580
|
}
|
|
10413
10581
|
|
|
10414
|
-
// src/
|
|
10415
|
-
import {
|
|
10416
|
-
import {
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
function
|
|
10420
|
-
const p = join24(root, MERGE_LOCK);
|
|
10421
|
-
if (!existsSync22(p)) return void 0;
|
|
10582
|
+
// src/cleanroom.ts
|
|
10583
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
10584
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync9, readdirSync as readdirSync12, readFileSync as readFileSync20, realpathSync as realpathSync5, statSync as statSync7, writeFileSync as writeFileSync11 } from "node:fs";
|
|
10585
|
+
import { extname, join as join25, relative as relative12 } from "node:path";
|
|
10586
|
+
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
10587
|
+
function packageStores() {
|
|
10422
10588
|
try {
|
|
10423
|
-
|
|
10589
|
+
const p = execFileSync5("pnpm", ["store", "path"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
10590
|
+
return p ? [p.replace(/\/v\d+$/, "")] : [];
|
|
10424
10591
|
} catch {
|
|
10425
|
-
return
|
|
10592
|
+
return [];
|
|
10426
10593
|
}
|
|
10427
10594
|
}
|
|
10428
|
-
function
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
return
|
|
10595
|
+
function gitCommonDir(root) {
|
|
10596
|
+
try {
|
|
10597
|
+
return realpathSync5(execFileSync5("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: root, encoding: "utf8" }).trim());
|
|
10598
|
+
} catch {
|
|
10599
|
+
return join25(root, ".git");
|
|
10433
10600
|
}
|
|
10434
|
-
mkdirSync11(join24(root, ".lead"), { recursive: true });
|
|
10435
|
-
const lock = { task: opts.task, session: opts.session, mr: opts.mr, at: now.toISOString() };
|
|
10436
|
-
writeFileSync13(join24(root, MERGE_LOCK), `${JSON.stringify(lock, null, 2)}
|
|
10437
|
-
`);
|
|
10438
|
-
return { ok: true, message: `merge ${opts.mr} held for ${opts.task}` };
|
|
10439
|
-
}
|
|
10440
|
-
function releaseMerge(root, opts) {
|
|
10441
|
-
const cur = read2(root);
|
|
10442
|
-
if (!cur) return { ok: true, message: "no merge hold" };
|
|
10443
|
-
if (cur.task !== opts.task) return { ok: false, message: `merge hold is for ${cur.task}, not ${opts.task}` };
|
|
10444
|
-
if (cur.session !== opts.session) return { ok: false, message: `merge hold belongs to session ${cur.session}` };
|
|
10445
|
-
rmSync5(join24(root, MERGE_LOCK), { force: true });
|
|
10446
|
-
return { ok: true, message: `merge hold for ${opts.task} released` };
|
|
10447
|
-
}
|
|
10448
|
-
|
|
10449
|
-
// src/activity.ts
|
|
10450
|
-
import { appendFileSync as appendFileSync2, existsSync as existsSync23, mkdirSync as mkdirSync12, readdirSync as readdirSync11, readFileSync as readFileSync21 } from "node:fs";
|
|
10451
|
-
import { join as join25 } from "node:path";
|
|
10452
|
-
var ACTIVITY_DIR = ".lead/activity";
|
|
10453
|
-
var EVENTS = ["start", "end", "check", "status", "note", "wait", "merge"];
|
|
10454
|
-
function isEvent(v) {
|
|
10455
|
-
return EVENTS.includes(v);
|
|
10456
|
-
}
|
|
10457
|
-
function appendActivity(root, entry) {
|
|
10458
|
-
const at = entry.at ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
10459
|
-
const row = {
|
|
10460
|
-
at,
|
|
10461
|
-
event: entry.event,
|
|
10462
|
-
what: oneLine2(entry.what),
|
|
10463
|
-
...entry.where ? { where: oneLine2(entry.where) } : {},
|
|
10464
|
-
...entry.task ? { task: oneLine2(entry.task) } : {},
|
|
10465
|
-
...entry.project ? { project: oneLine2(entry.project) } : {},
|
|
10466
|
-
...entry.session ? { session: oneLine2(entry.session) } : {},
|
|
10467
|
-
...entry.goal ? { goal: oneLine2(entry.goal) } : {}
|
|
10468
|
-
};
|
|
10469
|
-
const rel = join25(ACTIVITY_DIR, `${at.slice(0, 10)}.jsonl`);
|
|
10470
|
-
const abs = join25(root, rel);
|
|
10471
|
-
mkdirSync12(join25(root, ACTIVITY_DIR), { recursive: true });
|
|
10472
|
-
appendFileSync2(abs, `${JSON.stringify(row)}
|
|
10473
|
-
`);
|
|
10474
|
-
return rel;
|
|
10475
|
-
}
|
|
10476
|
-
function readActivityDay(root, day) {
|
|
10477
|
-
const p = join25(root, ACTIVITY_DIR, `${day}.jsonl`);
|
|
10478
|
-
if (!existsSync23(p)) return [];
|
|
10479
|
-
return readFileSync21(p, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
10480
|
-
}
|
|
10481
|
-
function listActivityDays(root) {
|
|
10482
|
-
const dir = join25(root, ACTIVITY_DIR);
|
|
10483
|
-
if (!existsSync23(dir)) return [];
|
|
10484
|
-
return readdirSync11(dir).filter((n) => /^\d{4}-\d{2}-\d{2}\.jsonl$/.test(n)).map((n) => n.replace(/\.jsonl$/, "")).sort();
|
|
10485
10601
|
}
|
|
10486
|
-
|
|
10487
|
-
const
|
|
10488
|
-
return
|
|
10489
|
-
}
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
const
|
|
10493
|
-
|
|
10494
|
-
const
|
|
10495
|
-
const
|
|
10496
|
-
const
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10602
|
+
var pathRules = (abs) => {
|
|
10603
|
+
const r = `//${abs.replace(/^\//, "")}`;
|
|
10604
|
+
return [`Read(${r})`, `Read(${r}/**)`];
|
|
10605
|
+
};
|
|
10606
|
+
var isUselessRule = (r) => /^(Grep|Glob|Edit)\(\/\//.test(r);
|
|
10607
|
+
function builderSettings(root, name, source, extra = []) {
|
|
10608
|
+
const abs = realpathSync5(source);
|
|
10609
|
+
if (abs === root || abs.startsWith(root + "/")) throw new Error(`the source of ${name} must live outside the repo (found inside ${root})`);
|
|
10610
|
+
const rel = `.lead/builder-${name.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`;
|
|
10611
|
+
const file = join25(root, rel);
|
|
10612
|
+
const prev = existsSync23(file) ? JSON.parse(readFileSync20(file, "utf8")) : {};
|
|
10613
|
+
const paths = [abs, join25(root, ".lead/logs/reverse"), file, ...extra.map((p) => p.startsWith("/") ? p : join25(root, p))];
|
|
10614
|
+
const deny = /* @__PURE__ */ new Set([
|
|
10615
|
+
...(prev.permissions?.deny ?? []).filter((r) => !isUselessRule(r)),
|
|
10616
|
+
...paths.flatMap(pathRules),
|
|
10617
|
+
"Bash(docker:*)",
|
|
10618
|
+
"Bash(podman:*)",
|
|
10619
|
+
"WebFetch",
|
|
10620
|
+
"WebSearch"
|
|
10621
|
+
]);
|
|
10622
|
+
const denyRead = /* @__PURE__ */ new Set([...prev.sandbox?.filesystem?.denyRead ?? [], ...paths]);
|
|
10623
|
+
const cli = 'node "$CLAUDE_PROJECT_DIR/.lead/lead.mjs"';
|
|
10624
|
+
const stores = packageStores();
|
|
10625
|
+
const settings = {
|
|
10626
|
+
...stores.length ? { env: { npm_config_store_dir: execFileSync5("pnpm", ["store", "path"], { encoding: "utf8" }).trim() } } : {},
|
|
10627
|
+
permissions: { deny: [...deny] },
|
|
10628
|
+
sandbox: {
|
|
10629
|
+
enabled: true,
|
|
10630
|
+
autoAllowBashIfSandboxed: false,
|
|
10631
|
+
allowUnsandboxedCommands: false,
|
|
10632
|
+
// The builder starts in a project folder but must write the repo's work/ and .lead/ state and
|
|
10633
|
+
// the shared .git of task worktrees, and must run the app on a local port for browser QA.
|
|
10634
|
+
filesystem: { denyRead: [...denyRead], allowWrite: [root, gitCommonDir(root), ...stores] },
|
|
10635
|
+
network: { allowLocalBinding: true }
|
|
10636
|
+
},
|
|
10637
|
+
hooks: {
|
|
10638
|
+
Stop: [{ hooks: [{ type: "command", command: `${cli} stop-check` }] }],
|
|
10639
|
+
SessionStart: [{ hooks: [{ type: "command", command: `${cli} session-start` }] }]
|
|
10511
10640
|
}
|
|
10512
|
-
}
|
|
10513
|
-
const openStarts = starts.filter((s) => !ends.has(`${s.task ?? ""}|${s.what}`) && !ends.has(`|${s.what}`)).map((s) => ({ at: s.at, what: s.what, ...s.task ? { task: s.task } : {} }));
|
|
10514
|
-
return {
|
|
10515
|
-
days: [...days].sort(),
|
|
10516
|
-
total: rows.length,
|
|
10517
|
-
byEvent,
|
|
10518
|
-
byTask: [...taskMap.entries()].map(([task, v]) => ({ task, ...v })).sort((a, b) => b.events - a.events || a.task.localeCompare(b.task)),
|
|
10519
|
-
waits,
|
|
10520
|
-
openStarts,
|
|
10521
|
-
first: rows[0]?.at,
|
|
10522
|
-
last: rows[rows.length - 1]?.at
|
|
10523
10641
|
};
|
|
10642
|
+
mkdirSync9(join25(root, ".lead"), { recursive: true });
|
|
10643
|
+
writeFileSync11(file, `${JSON.stringify(settings, null, 2)}
|
|
10644
|
+
`);
|
|
10645
|
+
return { path: rel, launch: `claude --settings ${rel}` };
|
|
10524
10646
|
}
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
if (r.byTask.length) {
|
|
10534
|
-
lines.push("", "by task:");
|
|
10535
|
-
for (const t of r.byTask) {
|
|
10536
|
-
lines.push(` ${t.task} ${t.events} events (start ${t.starts}, end ${t.ends}, check ${t.checks}, wait ${t.waits})`);
|
|
10537
|
-
}
|
|
10538
|
-
}
|
|
10539
|
-
if (r.waits.length) {
|
|
10540
|
-
lines.push("", `waits (${r.waits.length}):`);
|
|
10541
|
-
for (const w of r.waits.slice(-20)) lines.push(` ${w.at} ${w.task ?? "-"} ${w.what}`);
|
|
10542
|
-
if (r.waits.length > 20) lines.push(` \u2026 ${r.waits.length - 20} earlier`);
|
|
10647
|
+
var TEXT = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte", ".css", ".scss", ".html", ".md", ".json", ".py", ".go", ".rb", ".php", ".java", ".kt", ".rs", ".sql", ".yml", ".yaml", ".txt"]);
|
|
10648
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", "coverage", "vendor", ".lead", ".claude"]);
|
|
10649
|
+
function files(dir, out = []) {
|
|
10650
|
+
if (!existsSync23(dir)) return out;
|
|
10651
|
+
const st = statSync7(dir);
|
|
10652
|
+
if (st.isFile()) {
|
|
10653
|
+
out.push(dir);
|
|
10654
|
+
return out;
|
|
10543
10655
|
}
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10656
|
+
for (const n of readdirSync12(dir)) {
|
|
10657
|
+
if (SKIP.has(n)) continue;
|
|
10658
|
+
const p = join25(dir, n);
|
|
10659
|
+
const s = statSync7(p);
|
|
10660
|
+
if (s.isDirectory()) files(p, out);
|
|
10661
|
+
else if (TEXT.has(extname(n)) && s.size < 1e6) out.push(p);
|
|
10547
10662
|
}
|
|
10548
|
-
return
|
|
10663
|
+
return out;
|
|
10549
10664
|
}
|
|
10550
|
-
function
|
|
10551
|
-
return
|
|
10665
|
+
function meaningful(text) {
|
|
10666
|
+
return text.split("\n").map((l, i) => ({ line: i + 1, norm: l.trim().replace(/\s+/g, " ") })).filter((x) => x.norm.length >= 20 && /[a-zA-Z]{3}/.test(x.norm) && !/^(import|export \{|\/\/|#|\*|<\/?\w+>$)/.test(x.norm));
|
|
10552
10667
|
}
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
|
|
10561
|
-
|
|
10562
|
-
const
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10668
|
+
var h = (s) => createHash7("sha1").update(s).digest("hex");
|
|
10669
|
+
function similarity(source, targets, root, window = 6, longLine = 200) {
|
|
10670
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
10671
|
+
const longs = /* @__PURE__ */ new Map();
|
|
10672
|
+
for (const f of files(source)) {
|
|
10673
|
+
const m = meaningful(readFileSync20(f, "utf8"));
|
|
10674
|
+
for (let i = 0; i + window <= m.length; i++) blocks.set(h(m.slice(i, i + window).map((x) => x.norm).join("\n")), { file: f, line: m[i].line });
|
|
10675
|
+
for (const x of m) if (x.norm.length >= longLine) longs.set(h(x.norm), { file: f, line: x.line });
|
|
10676
|
+
}
|
|
10677
|
+
const matches = [];
|
|
10678
|
+
for (const t of targets.flatMap((p) => files(p))) {
|
|
10679
|
+
const m = meaningful(readFileSync20(t, "utf8"));
|
|
10680
|
+
let skipUntil = -1;
|
|
10681
|
+
for (let i = 0; i + window <= m.length; i++) {
|
|
10682
|
+
if (i < skipUntil) continue;
|
|
10683
|
+
const hit = blocks.get(h(m.slice(i, i + window).map((x) => x.norm).join("\n")));
|
|
10684
|
+
if (hit) {
|
|
10685
|
+
matches.push({ file: relative12(root, t), line: m[i].line, source: relative12(source, hit.file) || hit.file, sourceLine: hit.line, kind: "block" });
|
|
10686
|
+
skipUntil = i + window;
|
|
10687
|
+
}
|
|
10570
10688
|
}
|
|
10571
|
-
const
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
issues.push(`${rel}: folder name must look like "private-space"`);
|
|
10575
|
-
} else if (declared !== name) {
|
|
10576
|
-
issues.push(`${rel}: name "${declared}" must match the folder "${name}"`);
|
|
10577
|
-
} else {
|
|
10578
|
-
adapters.push({
|
|
10579
|
-
id: name,
|
|
10580
|
-
title: typeof parsed?.data.title === "string" ? parsed.data.title : name,
|
|
10581
|
-
appliesTo: typeof parsed?.data.applies_to === "string" ? parsed.data.applies_to : "",
|
|
10582
|
-
file: rel
|
|
10583
|
-
});
|
|
10689
|
+
for (const x of m) {
|
|
10690
|
+
const hit = x.norm.length >= longLine ? longs.get(h(x.norm)) : void 0;
|
|
10691
|
+
if (hit) matches.push({ file: relative12(root, t), line: x.line, source: relative12(source, hit.file) || hit.file, sourceLine: hit.line, kind: "long-line" });
|
|
10584
10692
|
}
|
|
10585
10693
|
}
|
|
10586
|
-
return
|
|
10694
|
+
return matches;
|
|
10587
10695
|
}
|
|
10588
10696
|
|
|
10589
|
-
// src/
|
|
10590
|
-
|
|
10591
|
-
import { existsSync as existsSync27, mkdirSync as mkdirSync13, readFileSync as readFileSync24, writeFileSync as writeFileSync14 } from "node:fs";
|
|
10592
|
-
import { dirname as dirname5, join as join29 } from "node:path";
|
|
10593
|
-
|
|
10594
|
-
// src/initiative.ts
|
|
10595
|
-
import { existsSync as existsSync26, readdirSync as readdirSync13, readFileSync as readFileSync23 } from "node:fs";
|
|
10596
|
-
import { join as join28 } from "node:path";
|
|
10697
|
+
// src/cli.ts
|
|
10698
|
+
import { basename as basename3, relative as relative14, sep as sep5 } from "node:path";
|
|
10597
10699
|
|
|
10598
|
-
// src/
|
|
10599
|
-
import { existsSync as
|
|
10600
|
-
import { join as
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
const
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
const path = ws.repositories[repo];
|
|
10614
|
-
if (!path) return { state: "unresolved", reason: `${repo} is not in the workspace` };
|
|
10615
|
-
if (!existsSync25(path)) return { state: "unresolved", reason: `checkout of ${repo} is missing` };
|
|
10616
|
-
try {
|
|
10617
|
-
const ctx = loadContext(path);
|
|
10618
|
-
if (!ctx.project) return { state: "unresolved", reason: `${repo} has no single lead project` };
|
|
10619
|
-
const t = ctx.tasks.find((x) => x.id === id);
|
|
10620
|
-
if (!t) return { state: "unresolved", reason: `${repo} has no task ${id}` };
|
|
10621
|
-
return { state: t.status === "done" ? "done" : "open" };
|
|
10622
|
-
} catch (error) {
|
|
10623
|
-
return { state: "unresolved", reason: error.message };
|
|
10624
|
-
}
|
|
10625
|
-
}
|
|
10626
|
-
function resolveRef(ref, tasks, ws) {
|
|
10627
|
-
const p = parseRef(ref);
|
|
10628
|
-
if (!p) return { ref, state: "unresolved", reason: "not a task reference" };
|
|
10629
|
-
if (!p.repo) return tasks.some((t) => t.id === p.id) ? { ref, state: "internal" } : { ref, state: "unresolved", reason: "no such task in this initiative" };
|
|
10630
|
-
return { ref, ...externalState(ws, p.repo, p.id) };
|
|
10631
|
-
}
|
|
10632
|
-
function scoped(tasks, i) {
|
|
10633
|
-
const ids = new Set(tasks.map((t) => t.id));
|
|
10634
|
-
return tasks.map((t) => ({
|
|
10635
|
-
...t,
|
|
10636
|
-
touches: t.touches.map((p) => `${taskRepo(t, i)}/${p.replace(/^\.\//, "")}`),
|
|
10637
|
-
blocked_by: t.blocked_by.filter((b) => ids.has(b))
|
|
10638
|
-
}));
|
|
10639
|
-
}
|
|
10640
|
-
function initiativeWaves(tasks, i) {
|
|
10641
|
-
return computeWaves(scoped(tasks, i), []);
|
|
10700
|
+
// src/delegate.ts
|
|
10701
|
+
import { existsSync as existsSync24, readdirSync as readdirSync13, readFileSync as readFileSync21 } from "node:fs";
|
|
10702
|
+
import { join as join26 } from "node:path";
|
|
10703
|
+
function readDelegate(file, source) {
|
|
10704
|
+
if (!existsSync24(file)) return void 0;
|
|
10705
|
+
const { parsed } = parseFrontmatter(readFileSync21(file, "utf8"), file);
|
|
10706
|
+
const id2 = typeof parsed?.data.name === "string" ? parsed.data.name : "";
|
|
10707
|
+
if (!/^[a-z][a-z0-9-]*$/.test(id2)) return void 0;
|
|
10708
|
+
return {
|
|
10709
|
+
id: id2,
|
|
10710
|
+
title: typeof parsed?.data.title === "string" ? parsed.data.title : id2,
|
|
10711
|
+
file,
|
|
10712
|
+
source,
|
|
10713
|
+
available: typeof parsed?.data.available === "string" ? parsed.data.available : ""
|
|
10714
|
+
};
|
|
10642
10715
|
}
|
|
10643
|
-
function
|
|
10644
|
-
|
|
10645
|
-
const
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
const w = waves.get(t.id);
|
|
10650
|
-
if (w === void 0 || w === t.wave || t.status === "done") continue;
|
|
10651
|
-
updateTask(root, t, (d) => {
|
|
10652
|
-
d.wave = w;
|
|
10653
|
-
});
|
|
10654
|
-
log.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
10716
|
+
function fromDir(dir, source) {
|
|
10717
|
+
if (!existsSync24(dir)) return [];
|
|
10718
|
+
const out = [];
|
|
10719
|
+
for (const name of readdirSync13(dir).sort()) {
|
|
10720
|
+
const d = readDelegate(join26(dir, name, "SKILL.md"), source);
|
|
10721
|
+
if (d) out.push(d);
|
|
10655
10722
|
}
|
|
10656
|
-
return
|
|
10723
|
+
return out;
|
|
10657
10724
|
}
|
|
10658
|
-
function
|
|
10659
|
-
const
|
|
10660
|
-
const
|
|
10661
|
-
|
|
10662
|
-
const home = homeRepo(i);
|
|
10663
|
-
const ms = new Set(loadOnePager(root, join27(root, i.dir)).onePager?.milestones.map((m) => m.id) ?? []);
|
|
10664
|
-
for (const t of tasks) {
|
|
10665
|
-
const e = (message, level = "error") => out.push({ level, file: t.file, message });
|
|
10666
|
-
if (t.repo ? !repos.has(t.repo) : !home) e(t.repo ? `repo "${t.repo}" is not listed in ${i.file}` : `no repo: the initiative has no home repository`);
|
|
10667
|
-
if (t.milestone && ms.size && !ms.has(t.milestone)) e(`milestone "${t.milestone}" is not defined in the initiative one-pager`);
|
|
10668
|
-
for (const ref of t.blocked_by) {
|
|
10669
|
-
const p = parseRef(ref);
|
|
10670
|
-
if (!p) e(`blocked_by ${ref}: use T-001 or <repo>:T-001`);
|
|
10671
|
-
else if (!p.repo && p.id === t.id) e(`${t.id} is blocked by itself`);
|
|
10672
|
-
else if (p.repo && !repos.has(p.repo)) e(`blocked_by ${ref}: repository ${p.repo} is not listed in ${i.file}`);
|
|
10673
|
-
else {
|
|
10674
|
-
const r = resolveRef(ref, tasks, ws);
|
|
10675
|
-
if (r.state === "unresolved") e(`blocked_by ${ref}: ${r.reason}`, p.repo ? "warning" : "error");
|
|
10676
|
-
}
|
|
10677
|
-
}
|
|
10678
|
-
if (t.touches.length === 0 && t.status !== "done") e("touches is empty: the task runs alone in its wave until its paths are known", "warning");
|
|
10679
|
-
}
|
|
10680
|
-
const sc = scoped(tasks, i);
|
|
10681
|
-
const byId = new Map(tasks.map((t) => [t.id, t]));
|
|
10682
|
-
for (const c of findCycles(sc)) out.push({ level: "error", file: byId.get(c[0]).file, message: `dependency cycle: ${c.join(" \u2192 ")}` });
|
|
10683
|
-
const waves = computeWaves(sc, []);
|
|
10684
|
-
const active = sc.filter((t) => t.status !== "done");
|
|
10685
|
-
for (const t of tasks) {
|
|
10686
|
-
if (t.wave === void 0) {
|
|
10687
|
-
if (t.status !== "done") out.push({ level: "warning", file: t.file, message: "wave not set; run `lead initiative waves <id> --write`" });
|
|
10688
|
-
continue;
|
|
10689
|
-
}
|
|
10690
|
-
for (const dep of t.blocked_by) {
|
|
10691
|
-
const d = byId.get(dep);
|
|
10692
|
-
if (d?.wave !== void 0 && d.wave >= t.wave) out.push({ level: "error", file: t.file, message: `blocked by ${dep} (wave ${d.wave}) but placed in wave ${t.wave}` });
|
|
10693
|
-
}
|
|
10694
|
-
const c = waves?.get(t.id);
|
|
10695
|
-
if (c !== void 0 && c !== t.wave && t.status !== "done") out.push({ level: "warning", file: t.file, message: `wave ${t.wave} differs from computed wave ${c}; run \`lead initiative waves <id> --write\`` });
|
|
10725
|
+
function listDelegates(root, kit) {
|
|
10726
|
+
const byId = /* @__PURE__ */ new Map();
|
|
10727
|
+
for (const d of [...fromDir(join26(root, ".agents/skills/lead/delegates"), "kit"), ...fromDir(join26(root, ".claude/skills/lead/delegates"), "kit")]) {
|
|
10728
|
+
byId.set(d.id, d);
|
|
10696
10729
|
}
|
|
10697
|
-
|
|
10698
|
-
for (
|
|
10699
|
-
const x = active[a];
|
|
10700
|
-
const y = active[b];
|
|
10701
|
-
if (x.wave === void 0 || x.wave !== y.wave) continue;
|
|
10702
|
-
const hits = touchesOverlap(x.touches, y.touches);
|
|
10703
|
-
if (hits.length) out.push({ level: "error", file: byId.get(y.id).file, message: `wave ${y.wave}: ${y.id} and ${x.id} touch the same paths (${hits.join(", ")})` });
|
|
10704
|
-
}
|
|
10730
|
+
if (kit) {
|
|
10731
|
+
for (const d of fromDir(join26(kit, "skills/lead/delegates"), "kit")) byId.set(d.id, d);
|
|
10705
10732
|
}
|
|
10706
|
-
|
|
10733
|
+
for (const d of fromDir(join26(root, ".lead/delegates"), "project")) byId.set(d.id, d);
|
|
10734
|
+
return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
10707
10735
|
}
|
|
10708
|
-
function
|
|
10709
|
-
|
|
10710
|
-
return tasks.map((t) => ({
|
|
10711
|
-
id: t.id,
|
|
10712
|
-
title: t.title,
|
|
10713
|
-
repo: taskRepo(t, i),
|
|
10714
|
-
status: t.status,
|
|
10715
|
-
...t.wave !== void 0 ? { wave: t.wave } : {},
|
|
10716
|
-
...t.milestone ? { milestone: t.milestone } : {},
|
|
10717
|
-
blocked_by: t.blocked_by.map((b) => resolveRef(b, tasks, ws))
|
|
10718
|
-
}));
|
|
10736
|
+
function delegatedTasks(tasks, id2) {
|
|
10737
|
+
return tasks.filter((t) => t.delegate && (!id2 || t.delegate === id2)).sort((a, b) => a.id.localeCompare(b.id));
|
|
10719
10738
|
}
|
|
10720
10739
|
|
|
10721
|
-
// src/
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
var
|
|
10726
|
-
var
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
const
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
const d = parsed.data;
|
|
10745
|
-
if (!ID4.test(entry.name) || RESERVED.includes(entry.name)) err('folder name must look like "private-space" and not be "check" or "waves"');
|
|
10746
|
-
if (str(d.id) !== entry.name) err(`id must equal the folder name "${entry.name}"`);
|
|
10747
|
-
const repos = [];
|
|
10748
|
-
if (d.repos !== void 0 && !Array.isArray(d.repos)) err("repos must be a list");
|
|
10749
|
-
for (const [i, r] of (Array.isArray(d.repos) ? d.repos : []).entries()) {
|
|
10750
|
-
const row = r ?? {};
|
|
10751
|
-
const name = str(row.name);
|
|
10752
|
-
const role = row.role === void 0 ? "reference" : row.role;
|
|
10753
|
-
if (!name || !ID4.test(name)) err(`repos[${i}].name must look like "org-service"`);
|
|
10754
|
-
else if (!ROLES.includes(role)) err(`repos[${i}].role must be one of ${ROLES.join(", ")}`);
|
|
10755
|
-
else if (repos.some((x) => x.name === name)) err(`repos[${i}]: "${name}" is listed twice`);
|
|
10756
|
-
else repos.push({ name, role, ...str(row.url) ? { url: str(row.url) } : {} });
|
|
10757
|
-
}
|
|
10758
|
-
if (repos.filter((r) => r.role === "home").length > 1) err("only one repository can be home");
|
|
10759
|
-
const map = {};
|
|
10760
|
-
if (d.map !== void 0 && (typeof d.map !== "object" || d.map === null || Array.isArray(d.map))) err("map must be a mapping from tracker key to a decision");
|
|
10761
|
-
for (const [key, v] of Object.entries(typeof d.map === "object" && d.map && !Array.isArray(d.map) ? d.map : {})) {
|
|
10762
|
-
const o = v ?? {};
|
|
10763
|
-
const bad = (m) => err(`map.${key}: ${m}`);
|
|
10764
|
-
if (!/^[A-Z][A-Z0-9]*-\d+$/.test(key)) bad("the key must look like KEY-123");
|
|
10765
|
-
else if (o.repo !== void 0 && (typeof o.repo !== "string" || !ID4.test(o.repo))) bad('repo must look like "org-service"');
|
|
10766
|
-
else if (typeof o.repo === "string" && !repos.some((r) => r.name === o.repo)) bad(`repo "${o.repo}" is not listed in repos`);
|
|
10767
|
-
else if (o.milestone !== void 0 && typeof o.milestone !== "string") bad("milestone must be a milestone id");
|
|
10768
|
-
else if (o.kind !== void 0 && !["work", "qa", "manual"].includes(o.kind)) bad("kind must be work, qa or manual");
|
|
10769
|
-
else map[key] = { ...o.repo ? { repo: o.repo } : {}, ...o.milestone ? { milestone: o.milestone } : {}, ...o.kind ? { kind: o.kind } : {} };
|
|
10770
|
-
}
|
|
10771
|
-
initiatives.push({
|
|
10772
|
-
id: entry.name,
|
|
10773
|
-
title: str(d.title) ?? entry.name,
|
|
10774
|
-
epic: str(d.epic),
|
|
10775
|
-
site: str(d.site),
|
|
10776
|
-
flag: str(d.flag),
|
|
10777
|
-
adapter: str(d.adapter),
|
|
10778
|
-
repos,
|
|
10779
|
-
map,
|
|
10780
|
-
dir,
|
|
10781
|
-
file
|
|
10782
|
-
});
|
|
10740
|
+
// src/watch.ts
|
|
10741
|
+
import { spawn } from "node:child_process";
|
|
10742
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync10, readFileSync as readFileSync22, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10743
|
+
import { join as join27 } from "node:path";
|
|
10744
|
+
var WATCH_PATH = ".lead/watch.json";
|
|
10745
|
+
var MIN_INTERVAL_MS = 5 * 60 * 1e3;
|
|
10746
|
+
var DEFAULT_INTERVAL = "15m";
|
|
10747
|
+
function parseInterval(text) {
|
|
10748
|
+
const m = /^(\d+)\s*(m|min|h)$/i.exec(text.trim());
|
|
10749
|
+
if (!m) return void 0;
|
|
10750
|
+
const n = Number(m[1]);
|
|
10751
|
+
const ms = m[2].toLowerCase().startsWith("h") ? n * 60 * 60 * 1e3 : n * 60 * 1e3;
|
|
10752
|
+
if (!Number.isFinite(ms) || ms < MIN_INTERVAL_MS) return void 0;
|
|
10753
|
+
return ms;
|
|
10754
|
+
}
|
|
10755
|
+
function readWatch(root) {
|
|
10756
|
+
const p = join27(root, WATCH_PATH);
|
|
10757
|
+
if (!existsSync25(p)) return { interval: DEFAULT_INTERVAL, close: false };
|
|
10758
|
+
try {
|
|
10759
|
+
const d = JSON.parse(readFileSync22(p, "utf8"));
|
|
10760
|
+
return { interval: typeof d.interval === "string" ? d.interval : DEFAULT_INTERVAL, close: d.close === true, pid: d.pid, startedAt: d.startedAt, due: d.due };
|
|
10761
|
+
} catch {
|
|
10762
|
+
return { interval: DEFAULT_INTERVAL, close: false };
|
|
10783
10763
|
}
|
|
10784
|
-
return { initiatives, issues };
|
|
10785
10764
|
}
|
|
10786
|
-
function
|
|
10765
|
+
function writeWatch(root, state) {
|
|
10766
|
+
mkdirSync10(join27(root, ".lead"), { recursive: true });
|
|
10767
|
+
writeFileSync12(join27(root, WATCH_PATH), `${JSON.stringify(state, null, 2)}
|
|
10768
|
+
`);
|
|
10769
|
+
}
|
|
10770
|
+
function alive(pid) {
|
|
10771
|
+
if (!pid || pid <= 1) return false;
|
|
10787
10772
|
try {
|
|
10788
|
-
|
|
10773
|
+
process.kill(pid, 0);
|
|
10774
|
+
return true;
|
|
10789
10775
|
} catch {
|
|
10790
|
-
return
|
|
10776
|
+
return false;
|
|
10791
10777
|
}
|
|
10792
10778
|
}
|
|
10793
|
-
function
|
|
10794
|
-
const
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10779
|
+
function watchStatus(root) {
|
|
10780
|
+
const s = readWatch(root);
|
|
10781
|
+
const on = alive(s.pid);
|
|
10782
|
+
const bits = [`watch ${on ? "on" : "off"}`, `every ${s.interval}`, s.close ? "may close a finished milestone" : "asks before closing a milestone"];
|
|
10783
|
+
if (s.due) bits.push(`check due since ${s.due}`);
|
|
10784
|
+
return bits.join(", ");
|
|
10785
|
+
}
|
|
10786
|
+
function watchCommand(root, args, opts) {
|
|
10787
|
+
const sub = args[0];
|
|
10788
|
+
const state = readWatch(root);
|
|
10789
|
+
if (sub === "start") {
|
|
10790
|
+
if (alive(state.pid)) return { ok: true, message: watchStatus(root) };
|
|
10791
|
+
state.close = opts.close === true;
|
|
10792
|
+
state.startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10793
|
+
state.pid = opts.spawnLoop?.(root) ?? 0;
|
|
10794
|
+
writeWatch(root, state);
|
|
10795
|
+
return { ok: true, message: watchStatus(root) };
|
|
10796
|
+
}
|
|
10797
|
+
if (sub === "stop") {
|
|
10798
|
+
if (alive(state.pid)) {
|
|
10799
|
+
try {
|
|
10800
|
+
process.kill(state.pid, "SIGTERM");
|
|
10801
|
+
} catch {
|
|
10802
|
+
}
|
|
10805
10803
|
}
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10804
|
+
delete state.pid;
|
|
10805
|
+
delete state.startedAt;
|
|
10806
|
+
delete state.due;
|
|
10807
|
+
writeWatch(root, state);
|
|
10808
|
+
return { ok: true, message: watchStatus(root) };
|
|
10809
|
+
}
|
|
10810
|
+
if (sub === "interval") {
|
|
10811
|
+
const text = args[1];
|
|
10812
|
+
if (!text || parseInterval(text) === void 0) return { ok: false, message: "interval is at least 5m: 15m, 30m, 1h" };
|
|
10813
|
+
state.interval = text.trim();
|
|
10814
|
+
writeWatch(root, state);
|
|
10815
|
+
return { ok: true, message: watchStatus(root) };
|
|
10809
10816
|
}
|
|
10817
|
+
if (sub === void 0 || sub === "status") return { ok: true, message: watchStatus(root) };
|
|
10818
|
+
return { ok: false, message: "usage: watch [start|stop|interval 15m|status]" };
|
|
10810
10819
|
}
|
|
10811
|
-
function
|
|
10812
|
-
const
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
const adapters = i.adapter ? listAdapters(root).adapters : [];
|
|
10816
|
-
return {
|
|
10817
|
-
id: i.id,
|
|
10818
|
-
title: i.title,
|
|
10819
|
-
...i.epic ? { epic: i.epic } : {},
|
|
10820
|
-
...i.epic && i.site ? { epicUrl: `https://${i.site}/browse/${i.epic}` } : {},
|
|
10821
|
-
...i.flag ? { flag: i.flag } : {},
|
|
10822
|
-
...i.adapter ? { adapter: { name: i.adapter, state: adapters.some((a) => a.id === i.adapter) ? "found" : "missing" } } : {},
|
|
10823
|
-
...op.onePager ? { onePager: op.onePager.file } : {},
|
|
10824
|
-
milestones: op.onePager?.milestones ?? [],
|
|
10825
|
-
repos: i.repos.map((r) => {
|
|
10826
|
-
const path = catalog.find(([name]) => name === r.name)?.[1];
|
|
10827
|
-
const local = r.role === "home" ? "here" : !ws ? "no_workspace" : !path ? "not_in_workspace" : existsSync26(path) ? "available" : "missing";
|
|
10828
|
-
return { ...r, local };
|
|
10829
|
-
}),
|
|
10830
|
-
tasks: initiativeTaskRows(root, i, ws),
|
|
10831
|
-
observed: observedCounts(root, i)
|
|
10832
|
-
};
|
|
10820
|
+
function clearDue(root) {
|
|
10821
|
+
const state = readWatch(root);
|
|
10822
|
+
delete state.due;
|
|
10823
|
+
writeWatch(root, state);
|
|
10833
10824
|
}
|
|
10834
|
-
function
|
|
10835
|
-
|
|
10836
|
-
|
|
10825
|
+
function spawnWatchLoop(leadMjs, root) {
|
|
10826
|
+
return spawn(process.execPath, [leadMjs, "watch", "loop", "--cwd", root], { detached: true, stdio: "ignore" });
|
|
10827
|
+
}
|
|
10828
|
+
function runWatchLoop(root, sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)) {
|
|
10829
|
+
const state = readWatch(root);
|
|
10830
|
+
if (state.pid !== process.pid) return;
|
|
10831
|
+
for (; ; ) {
|
|
10832
|
+
const cur = readWatch(root);
|
|
10833
|
+
if (cur.pid !== process.pid) return;
|
|
10834
|
+
const ms = parseInterval(cur.interval) ?? parseInterval(DEFAULT_INTERVAL);
|
|
10835
|
+
sleep(ms);
|
|
10836
|
+
const after = readWatch(root);
|
|
10837
|
+
if (after.pid !== process.pid) return;
|
|
10838
|
+
after.due = (/* @__PURE__ */ new Date()).toISOString();
|
|
10839
|
+
writeWatch(root, after);
|
|
10840
|
+
const cmd = process.env.LEAD_WATCH_COMMAND;
|
|
10841
|
+
if (cmd) spawn(cmd, { cwd: root, shell: true, stdio: "ignore", detached: true }).unref();
|
|
10842
|
+
}
|
|
10843
|
+
}
|
|
10844
|
+
|
|
10845
|
+
// src/mergehold.ts
|
|
10846
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync11, readFileSync as readFileSync23, rmSync as rmSync5, writeFileSync as writeFileSync13 } from "node:fs";
|
|
10847
|
+
import { join as join28 } from "node:path";
|
|
10848
|
+
var MERGE_LOCK = ".lead/merge.json";
|
|
10849
|
+
var HOLD_MS = 15 * 60 * 1e3;
|
|
10850
|
+
function read2(root) {
|
|
10851
|
+
const p = join28(root, MERGE_LOCK);
|
|
10852
|
+
if (!existsSync26(p)) return void 0;
|
|
10837
10853
|
try {
|
|
10838
|
-
|
|
10839
|
-
return Object.entries(issues).filter(([, x]) => !repo || x.repo === repo || (x.also ?? []).includes(repo)).map(([key, x]) => ({ key, ...x })).sort((a, b) => Number(a.key.split("-").pop()) - Number(b.key.split("-").pop()));
|
|
10854
|
+
return JSON.parse(readFileSync23(p, "utf8"));
|
|
10840
10855
|
} catch {
|
|
10841
|
-
return
|
|
10856
|
+
return void 0;
|
|
10842
10857
|
}
|
|
10843
10858
|
}
|
|
10844
|
-
function
|
|
10845
|
-
const
|
|
10846
|
-
|
|
10847
|
-
if (
|
|
10848
|
-
|
|
10849
|
-
for (const m of o.milestones) lines.push(` milestone ${m.id} [${m.status}] ${m.title}${m.shows ? ` \u2014 ${m.shows}` : ""}`);
|
|
10850
|
-
for (const x of o.observed) lines.push(` observed ${x.milestone}: ${x.total} (${Object.entries(x.states).map(([k, v]) => `${k} ${v}`).join(", ")})`);
|
|
10851
|
-
for (const r of o.repos) lines.push(` repo ${r.name} (${r.role}) \u2014 ${r.local}`);
|
|
10852
|
-
for (const t of o.tasks) {
|
|
10853
|
-
const deps = t.blocked_by.map((b) => `${b.ref}${b.state === "internal" ? "" : ` ${b.state}`}`).join(", ");
|
|
10854
|
-
lines.push(` task ${t.id} [${t.status}]${t.wave ? ` w${t.wave}` : ""} ${t.repo} \u2014 ${t.title}${deps ? ` (after ${deps})` : ""}`);
|
|
10859
|
+
function holdMerge(root, opts) {
|
|
10860
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
10861
|
+
const cur = read2(root);
|
|
10862
|
+
if (cur && cur.session !== opts.session && now.getTime() - Date.parse(cur.at) < HOLD_MS) {
|
|
10863
|
+
return { ok: false, message: `${cur.task} merge is held by session ${cur.session} since ${cur.at}` };
|
|
10855
10864
|
}
|
|
10856
|
-
|
|
10865
|
+
mkdirSync11(join28(root, ".lead"), { recursive: true });
|
|
10866
|
+
const lock = { task: opts.task, session: opts.session, mr: opts.mr, at: now.toISOString() };
|
|
10867
|
+
writeFileSync13(join28(root, MERGE_LOCK), `${JSON.stringify(lock, null, 2)}
|
|
10868
|
+
`);
|
|
10869
|
+
return { ok: true, message: `merge ${opts.mr} held for ${opts.task}` };
|
|
10870
|
+
}
|
|
10871
|
+
function releaseMerge(root, opts) {
|
|
10872
|
+
const cur = read2(root);
|
|
10873
|
+
if (!cur) return { ok: true, message: "no merge hold" };
|
|
10874
|
+
if (cur.task !== opts.task) return { ok: false, message: `merge hold is for ${cur.task}, not ${opts.task}` };
|
|
10875
|
+
if (cur.session !== opts.session) return { ok: false, message: `merge hold belongs to session ${cur.session}` };
|
|
10876
|
+
rmSync5(join28(root, MERGE_LOCK), { force: true });
|
|
10877
|
+
return { ok: true, message: `merge hold for ${opts.task} released` };
|
|
10878
|
+
}
|
|
10879
|
+
|
|
10880
|
+
// src/activity.ts
|
|
10881
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync27, mkdirSync as mkdirSync12, readdirSync as readdirSync14, readFileSync as readFileSync24 } from "node:fs";
|
|
10882
|
+
import { join as join29 } from "node:path";
|
|
10883
|
+
var ACTIVITY_DIR = ".lead/activity";
|
|
10884
|
+
var EVENTS = ["start", "end", "check", "status", "note", "wait", "merge"];
|
|
10885
|
+
function isEvent(v) {
|
|
10886
|
+
return EVENTS.includes(v);
|
|
10887
|
+
}
|
|
10888
|
+
function appendActivity(root, entry) {
|
|
10889
|
+
const at = entry.at ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
10890
|
+
const row = {
|
|
10891
|
+
at,
|
|
10892
|
+
event: entry.event,
|
|
10893
|
+
what: oneLine2(entry.what),
|
|
10894
|
+
...entry.where ? { where: oneLine2(entry.where) } : {},
|
|
10895
|
+
...entry.task ? { task: oneLine2(entry.task) } : {},
|
|
10896
|
+
...entry.project ? { project: oneLine2(entry.project) } : {},
|
|
10897
|
+
...entry.session ? { session: oneLine2(entry.session) } : {},
|
|
10898
|
+
...entry.goal ? { goal: oneLine2(entry.goal) } : {}
|
|
10899
|
+
};
|
|
10900
|
+
const rel = join29(ACTIVITY_DIR, `${at.slice(0, 10)}.jsonl`);
|
|
10901
|
+
const abs = join29(root, rel);
|
|
10902
|
+
mkdirSync12(join29(root, ACTIVITY_DIR), { recursive: true });
|
|
10903
|
+
appendFileSync2(abs, `${JSON.stringify(row)}
|
|
10904
|
+
`);
|
|
10905
|
+
return rel;
|
|
10906
|
+
}
|
|
10907
|
+
function readActivityDay(root, day) {
|
|
10908
|
+
const p = join29(root, ACTIVITY_DIR, `${day}.jsonl`);
|
|
10909
|
+
if (!existsSync27(p)) return [];
|
|
10910
|
+
return readFileSync24(p, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
10911
|
+
}
|
|
10912
|
+
function listActivityDays(root) {
|
|
10913
|
+
const dir = join29(root, ACTIVITY_DIR);
|
|
10914
|
+
if (!existsSync27(dir)) return [];
|
|
10915
|
+
return readdirSync14(dir).filter((n) => /^\d{4}-\d{2}-\d{2}\.jsonl$/.test(n)).map((n) => n.replace(/\.jsonl$/, "")).sort();
|
|
10916
|
+
}
|
|
10917
|
+
function loadActivity(root, opts = {}) {
|
|
10918
|
+
const days = opts.day ? [opts.day] : listActivityDays(root).filter((d) => !opts.since || d >= opts.since);
|
|
10919
|
+
return days.flatMap((d) => readActivityDay(root, d));
|
|
10920
|
+
}
|
|
10921
|
+
function analyzeActivity(rows) {
|
|
10922
|
+
const byEvent = {};
|
|
10923
|
+
const taskMap = /* @__PURE__ */ new Map();
|
|
10924
|
+
const waits = [];
|
|
10925
|
+
const starts = [];
|
|
10926
|
+
const ends = /* @__PURE__ */ new Set();
|
|
10927
|
+
const days = /* @__PURE__ */ new Set();
|
|
10928
|
+
for (const r of rows) {
|
|
10929
|
+
days.add(r.at.slice(0, 10));
|
|
10930
|
+
byEvent[r.event] = (byEvent[r.event] ?? 0) + 1;
|
|
10931
|
+
if (r.event === "wait") waits.push({ at: r.at, what: r.what, ...r.task ? { task: r.task } : {} });
|
|
10932
|
+
if (r.event === "start") starts.push(r);
|
|
10933
|
+
if (r.event === "end") ends.add(`${r.task ?? ""}|${r.what}`);
|
|
10934
|
+
if (r.task) {
|
|
10935
|
+
const t = taskMap.get(r.task) ?? { events: 0, starts: 0, ends: 0, checks: 0, waits: 0 };
|
|
10936
|
+
t.events++;
|
|
10937
|
+
if (r.event === "start") t.starts++;
|
|
10938
|
+
if (r.event === "end") t.ends++;
|
|
10939
|
+
if (r.event === "check") t.checks++;
|
|
10940
|
+
if (r.event === "wait") t.waits++;
|
|
10941
|
+
taskMap.set(r.task, t);
|
|
10942
|
+
}
|
|
10943
|
+
}
|
|
10944
|
+
const openStarts = starts.filter((s) => !ends.has(`${s.task ?? ""}|${s.what}`) && !ends.has(`|${s.what}`)).map((s) => ({ at: s.at, what: s.what, ...s.task ? { task: s.task } : {} }));
|
|
10945
|
+
return {
|
|
10946
|
+
days: [...days].sort(),
|
|
10947
|
+
total: rows.length,
|
|
10948
|
+
byEvent,
|
|
10949
|
+
byTask: [...taskMap.entries()].map(([task, v]) => ({ task, ...v })).sort((a, b) => b.events - a.events || a.task.localeCompare(b.task)),
|
|
10950
|
+
waits,
|
|
10951
|
+
openStarts,
|
|
10952
|
+
first: rows[0]?.at,
|
|
10953
|
+
last: rows[rows.length - 1]?.at
|
|
10954
|
+
};
|
|
10955
|
+
}
|
|
10956
|
+
function formatActivityReport(r) {
|
|
10957
|
+
if (!r.total) return "no activity events";
|
|
10958
|
+
const lines = [
|
|
10959
|
+
`activity: ${r.total} events across ${r.days.length} day(s) (${r.first} \u2192 ${r.last})`,
|
|
10960
|
+
"",
|
|
10961
|
+
"by event:",
|
|
10962
|
+
...Object.entries(r.byEvent).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([e, n]) => ` ${e} ${n}`)
|
|
10963
|
+
];
|
|
10964
|
+
if (r.byTask.length) {
|
|
10965
|
+
lines.push("", "by task:");
|
|
10966
|
+
for (const t of r.byTask) {
|
|
10967
|
+
lines.push(` ${t.task} ${t.events} events (start ${t.starts}, end ${t.ends}, check ${t.checks}, wait ${t.waits})`);
|
|
10968
|
+
}
|
|
10969
|
+
}
|
|
10970
|
+
if (r.waits.length) {
|
|
10971
|
+
lines.push("", `waits (${r.waits.length}):`);
|
|
10972
|
+
for (const w of r.waits.slice(-20)) lines.push(` ${w.at} ${w.task ?? "-"} ${w.what}`);
|
|
10973
|
+
if (r.waits.length > 20) lines.push(` \u2026 ${r.waits.length - 20} earlier`);
|
|
10974
|
+
}
|
|
10975
|
+
if (r.openStarts.length) {
|
|
10976
|
+
lines.push("", `starts without a matching end (${r.openStarts.length}):`);
|
|
10977
|
+
for (const s of r.openStarts.slice(-10)) lines.push(` ${s.at} ${s.task ?? "-"} ${s.what}`);
|
|
10978
|
+
}
|
|
10979
|
+
return lines.join("\n");
|
|
10980
|
+
}
|
|
10981
|
+
function oneLine2(s) {
|
|
10982
|
+
return s.replace(/\s+/g, " ").trim();
|
|
10857
10983
|
}
|
|
10858
10984
|
|
|
10859
10985
|
// src/adopt.ts
|
|
10986
|
+
var import_yaml4 = __toESM(require_dist(), 1);
|
|
10987
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync13, readFileSync as readFileSync25, writeFileSync as writeFileSync14 } from "node:fs";
|
|
10988
|
+
import { dirname as dirname5, join as join30 } from "node:path";
|
|
10860
10989
|
var REPO = /^[a-z][a-z0-9-]*$/;
|
|
10861
10990
|
var keyNum = (key) => Number(/-(\d+)$/.exec(key)?.[1] ?? 0);
|
|
10862
10991
|
function validateInventory(raw) {
|
|
@@ -10942,9 +11071,9 @@ function propose(inv, o) {
|
|
|
10942
11071
|
const lastStage = [...segments].reverse().find((x) => x.qa)?.qa?.n;
|
|
10943
11072
|
let boundary;
|
|
10944
11073
|
for (const sg of segments) {
|
|
10945
|
-
const [
|
|
11074
|
+
const [id2, title] = sg.qa ? [`stage-${sg.qa.n}`, `Stage ${sg.qa.n}`] : lastStage !== void 0 ? [`after-stage-${lastStage}`, `After stage ${lastStage}`] : ["stage-1", "Stage 1"];
|
|
10946
11075
|
const m = {
|
|
10947
|
-
id: `${prefix}${
|
|
11076
|
+
id: `${prefix}${id2}`,
|
|
10948
11077
|
title: scoped2 ? `${story.key} ${title}` : title,
|
|
10949
11078
|
shows: sg.qa ? subs.find((x) => x.key === sg.qa.key).summary.replace(/^.*?:\s*/, "") : "",
|
|
10950
11079
|
issues: []
|
|
@@ -10972,8 +11101,8 @@ function propose(inv, o) {
|
|
|
10972
11101
|
}
|
|
10973
11102
|
const outside = subs.filter((s) => !planned.includes(s));
|
|
10974
11103
|
if (outside.length) {
|
|
10975
|
-
const
|
|
10976
|
-
milestones.push({ id, title: scoped2 ? `${story.key} Outside the plan` : "Outside the plan", shows: "Sub-tasks added after the plan was written", issues: outside.map((s) => s.key) });
|
|
11104
|
+
const id2 = `${prefix}outside-plan`;
|
|
11105
|
+
milestones.push({ id: id2, title: scoped2 ? `${story.key} Outside the plan` : "Outside the plan", shows: "Sub-tasks added after the plan was written", issues: outside.map((s) => s.key) });
|
|
10977
11106
|
for (const s of outside) {
|
|
10978
11107
|
const t = parseTitle(s.summary);
|
|
10979
11108
|
if (kindOf(s.summary) === "work" && !t.repos.length) unmapped.push({ key: s.key, reason: `repository: ${t.reason}` });
|
|
@@ -10985,7 +11114,7 @@ function propose(inv, o) {
|
|
|
10985
11114
|
kind: kindOf(s.summary),
|
|
10986
11115
|
...t.repos[0] ? { repo: t.repos[0] } : {},
|
|
10987
11116
|
...t.repos.length > 1 ? { also: t.repos.slice(1) } : {},
|
|
10988
|
-
milestone:
|
|
11117
|
+
milestone: id2,
|
|
10989
11118
|
observeOnly: true
|
|
10990
11119
|
};
|
|
10991
11120
|
}
|
|
@@ -11153,9 +11282,9 @@ function syncText(p) {
|
|
|
11153
11282
|
function writeProposal(root, p, force = false) {
|
|
11154
11283
|
const log = [];
|
|
11155
11284
|
const put = (rel, text, regenerate) => {
|
|
11156
|
-
const abs =
|
|
11157
|
-
if (
|
|
11158
|
-
const prev =
|
|
11285
|
+
const abs = join30(root, rel);
|
|
11286
|
+
if (existsSync28(abs)) {
|
|
11287
|
+
const prev = readFileSync25(abs, "utf8");
|
|
11159
11288
|
if (prev === text) return void log.push(`unchanged ${rel}`);
|
|
11160
11289
|
if (!regenerate && !force) return void log.push(`kept ${rel}: it already exists and differs; --force replaces it`);
|
|
11161
11290
|
}
|
|
@@ -11172,33 +11301,33 @@ function writeProposal(root, p, force = false) {
|
|
|
11172
11301
|
}
|
|
11173
11302
|
|
|
11174
11303
|
// src/score.ts
|
|
11175
|
-
import { existsSync as
|
|
11176
|
-
import { join as
|
|
11304
|
+
import { existsSync as existsSync29, readdirSync as readdirSync15, readFileSync as readFileSync26 } from "node:fs";
|
|
11305
|
+
import { join as join31, relative as relative13 } from "node:path";
|
|
11177
11306
|
function rubrics(root, kit) {
|
|
11178
11307
|
const dirs = [
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11308
|
+
join31(kit, "skills/lead/scorers"),
|
|
11309
|
+
join31(root, ".claude/skills/lead/scorers"),
|
|
11310
|
+
join31(root, ".agents/skills/lead/scorers"),
|
|
11311
|
+
join31(root, ".lead/local/scorers")
|
|
11183
11312
|
];
|
|
11184
11313
|
const all = /* @__PURE__ */ new Map();
|
|
11185
|
-
for (const dir of dirs.filter(
|
|
11186
|
-
for (const name of
|
|
11187
|
-
const file =
|
|
11188
|
-
if (
|
|
11314
|
+
for (const dir of dirs.filter(existsSync29)) {
|
|
11315
|
+
for (const name of readdirSync15(dir).sort()) {
|
|
11316
|
+
const file = join31(dir, name, "scorer.md");
|
|
11317
|
+
if (existsSync29(file)) all.set(name, file);
|
|
11189
11318
|
}
|
|
11190
11319
|
}
|
|
11191
|
-
return [...all].map(([
|
|
11192
|
-
const text =
|
|
11320
|
+
return [...all].map(([id2, file]) => {
|
|
11321
|
+
const text = readFileSync26(file, "utf8");
|
|
11193
11322
|
const { parsed } = parseFrontmatter(text, file);
|
|
11194
11323
|
const data = parsed?.data;
|
|
11195
|
-
if (!data || !/^[a-z][a-z0-9_-]*$/.test(
|
|
11324
|
+
if (!data || !/^[a-z][a-z0-9_-]*$/.test(id2) || data.id !== id2 || typeof data.version !== "number" || !Number.isInteger(data.version) || data.version < 1 || !["task", "mockup", "qa"].includes(String(data.applies_to)) || typeof data.sample_rate !== "number" || !(data.sample_rate >= 0 && data.sample_rate <= 1) || typeof data.pass_threshold !== "number" || !Number.isFinite(data.pass_threshold)) {
|
|
11196
11325
|
throw new Error(`invalid scorer metadata: ${file}`);
|
|
11197
11326
|
}
|
|
11198
11327
|
const classifications = Object.fromEntries([...parsed.body.matchAll(/^\|\s*([a-z][a-z0-9_]*)\s*\|\s*(-?\d+(?:\.\d+)?)\s*\|/gm)].map((m) => [m[1], Number(m[2])]));
|
|
11199
11328
|
if (!Object.keys(classifications).length) throw new Error(`no classifications: ${file}`);
|
|
11200
11329
|
return {
|
|
11201
|
-
id,
|
|
11330
|
+
id: id2,
|
|
11202
11331
|
file,
|
|
11203
11332
|
text,
|
|
11204
11333
|
version: data.version,
|
|
@@ -11223,7 +11352,7 @@ function scorePlan(ctx, kit, scorer, runId, limit = 10) {
|
|
|
11223
11352
|
const previous = readLog(ctx.root, "scores");
|
|
11224
11353
|
const records = runs(ctx.root).filter((run2) => run2.subject.project === ctx.project?.name);
|
|
11225
11354
|
if (runId && !records.some((run2) => run2.id === runId)) throw new Error(`unknown run in this project: ${runId}`);
|
|
11226
|
-
return records.reverse().filter((run2) => !runId || run2.id === runId).flatMap((run2) => candidates.filter((rubric) => applies(rubric, run2) && (runId || parseInt(digest([run2.id, rubric.id]).slice(0, 8), 16) / 2 ** 32 < rubric.rate) && !previous.some((row) => row.subject.run_id === run2.id && row.scorer === rubric.id && row.rubric_hash === rubric.hash)).map(({ id, version, file, text, hash: hash3 }) => ({ scorer:
|
|
11355
|
+
return records.reverse().filter((run2) => !runId || run2.id === runId).flatMap((run2) => candidates.filter((rubric) => applies(rubric, run2) && (runId || parseInt(digest([run2.id, rubric.id]).slice(0, 8), 16) / 2 ** 32 < rubric.rate) && !previous.some((row) => row.subject.run_id === run2.id && row.scorer === rubric.id && row.rubric_hash === rubric.hash)).map(({ id: id2, version, file, text, hash: hash3 }) => ({ scorer: id2, version, hash: hash3, file: relative13(ctx.root, file), rubric: text, run: run2 }))).slice(0, limit);
|
|
11227
11356
|
}
|
|
11228
11357
|
function recordScore(ctx, kit, scorer, runId, input) {
|
|
11229
11358
|
const rubric = rubrics(ctx.root, kit).find((r) => r.id === scorer);
|
|
@@ -11308,6 +11437,8 @@ Usage: node .lead/lead.mjs <command> [options]
|
|
|
11308
11437
|
spec [--confirm S | --reopen S] assemble work/spec.md from work/spec/; confirm or reopen a section
|
|
11309
11438
|
builder-settings <x> --source DIR [--deny P,Q] clean room: settings that keep the builder away from X
|
|
11310
11439
|
similarity --source DIR [paths...] fragments shared with the source of X (default: the project folder)
|
|
11440
|
+
inbox [--json] blockers, open questions and approvals waiting for a person
|
|
11441
|
+
docs [--json] [--key KEY] the project's documents, One Pager first, with their FuseBase notes
|
|
11311
11442
|
sync-plan JSON list of FuseBase/Jira writes needed to mirror work/
|
|
11312
11443
|
sync-plan --preview summarize recorded, pending, and uncertain writes
|
|
11313
11444
|
sync-one-pager [--input FILE] render the FuseBase One Pager or verify its read-back Markdown
|
|
@@ -11372,7 +11503,7 @@ function watchLine(root) {
|
|
|
11372
11503
|
function kitRoot() {
|
|
11373
11504
|
return resolve3(dirname6(fileURLToPath(import.meta.url)), "..");
|
|
11374
11505
|
}
|
|
11375
|
-
var KNOWN_FLAGS = /* @__PURE__ */ new Set(["from", "keep-modified", "deny", "confirm", "reopen", "source", "json", "session", "project", "cwd", "tool", "force", "only", "verdict", "notes", "merged", "question", "write", "id", "result", "status", "worktree", "help", "close", "kind", "where", "what", "avoid", "mr", "event", "day", "goal", "task", "since", "input", "scorer", "run", "limit", "preview", "retry", "action", "discard", "repo", "home", "flag", "title", "in"]);
|
|
11506
|
+
var KNOWN_FLAGS = /* @__PURE__ */ new Set(["from", "keep-modified", "deny", "confirm", "reopen", "source", "json", "session", "project", "cwd", "tool", "force", "only", "verdict", "notes", "merged", "question", "write", "id", "result", "status", "worktree", "help", "close", "kind", "where", "what", "avoid", "mr", "event", "day", "goal", "task", "since", "input", "scorer", "run", "limit", "preview", "retry", "action", "discard", "repo", "home", "flag", "title", "in", "key"]);
|
|
11376
11507
|
function main(argv, out = (s) => console.log(s)) {
|
|
11377
11508
|
const { cmd, args, flags } = parseArgs(argv);
|
|
11378
11509
|
const unknown = Object.keys(flags).filter((f) => !KNOWN_FLAGS.has(f));
|
|
@@ -11391,13 +11522,13 @@ function main(argv, out = (s) => console.log(s)) {
|
|
|
11391
11522
|
if (cmd && !["help", "--help", "version", "how", "install"].includes(cmd)) {
|
|
11392
11523
|
try {
|
|
11393
11524
|
const runningKit = kitRoot();
|
|
11394
|
-
const deployed =
|
|
11525
|
+
const deployed = basename3(runningKit) === "workspace-kit" && basename3(dirname6(runningKit)) === ".lead";
|
|
11395
11526
|
const ws = deployed ? findWorkspace(dirname6(dirname6(runningKit))) : findWorkspace(origin);
|
|
11396
11527
|
if (deployed && !ws) throw new Error("the shared workspace catalog is missing");
|
|
11397
11528
|
if (ws) {
|
|
11398
|
-
const path =
|
|
11399
|
-
if (path === ".." || path.startsWith(".." +
|
|
11400
|
-
sharedKit =
|
|
11529
|
+
const path = relative14(ws.root, realpathSync6(origin));
|
|
11530
|
+
if (path === ".." || path.startsWith(".." + sep5)) throw new Error("the command directory is outside this workspace");
|
|
11531
|
+
sharedKit = join32(ws.root, RUNTIME);
|
|
11401
11532
|
}
|
|
11402
11533
|
if (flags.repo && (!ws || !str2(flags.repo))) throw new Error("--repo requires a workspace and repository name");
|
|
11403
11534
|
if (cmd === "workspace") {
|
|
@@ -11440,7 +11571,7 @@ ${entry.source}:${entry.line}
|
|
|
11440
11571
|
}
|
|
11441
11572
|
if (args[0] === "attach" && args[1]) {
|
|
11442
11573
|
const target = routeScope(ws, ws.root, void 0, args[1]).root;
|
|
11443
|
-
if (
|
|
11574
|
+
if (existsSync30(join32(target, ".lead/lead.mjs")) && !isPortableLauncher(target)) throw new Error("a lead entry point already exists; review and migrate it before attaching");
|
|
11444
11575
|
writeEntrypoints(target);
|
|
11445
11576
|
for (const line of [...ensureGitIgnore(target), ...ensureClaudeSettings(target), ...ensureCodexHooks(target)]) out(line);
|
|
11446
11577
|
out(`attached ${args[1]} to the shared lead workspace`);
|
|
@@ -11467,7 +11598,7 @@ ${entry.source}:${entry.line}
|
|
|
11467
11598
|
if (scope) {
|
|
11468
11599
|
cwd = scope.cwd;
|
|
11469
11600
|
project = scope.project;
|
|
11470
|
-
} else if (repoRoot(origin) === ws.root || !
|
|
11601
|
+
} else if (repoRoot(origin) === ws.root || !existsSync30(join32(repoRoot(origin), ".git"))) {
|
|
11471
11602
|
if (cmd === "session-start" && session) {
|
|
11472
11603
|
out(JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: `lead workspace session: ${session}. Pass --session ${session} to lead commands.` } }));
|
|
11473
11604
|
return 0;
|
|
@@ -11539,7 +11670,7 @@ ${entry.source}:${entry.line}
|
|
|
11539
11670
|
out(log.length ? log.join("\n") : "waves already up to date");
|
|
11540
11671
|
} else {
|
|
11541
11672
|
const groups = /* @__PURE__ */ new Map();
|
|
11542
|
-
for (const [
|
|
11673
|
+
for (const [id2, w] of waves) groups.set(w, [...groups.get(w) ?? [], id2]);
|
|
11543
11674
|
for (const w of [...groups.keys()].sort((a, b) => a - b)) out(`wave ${w}: ${groups.get(w).sort().join(" \u2016 ")}`);
|
|
11544
11675
|
}
|
|
11545
11676
|
return 0;
|
|
@@ -11555,15 +11686,15 @@ ${entry.source}:${entry.line}
|
|
|
11555
11686
|
case "review":
|
|
11556
11687
|
case "finish":
|
|
11557
11688
|
case "block": {
|
|
11558
|
-
const
|
|
11559
|
-
if (!
|
|
11689
|
+
const id2 = args[0];
|
|
11690
|
+
if (!id2 || !session && !(cmd === "finish" && flags.merged)) {
|
|
11560
11691
|
out(`usage: ${cmd} <task> --session ID (or set LEAD_SESSION)`);
|
|
11561
11692
|
return 2;
|
|
11562
11693
|
}
|
|
11563
11694
|
const ctx = loadContext(cwd, project);
|
|
11564
|
-
const task = ctx.tasks.find((t) => t.id ===
|
|
11695
|
+
const task = ctx.tasks.find((t) => t.id === id2);
|
|
11565
11696
|
if (!task) {
|
|
11566
|
-
out(`no task ${
|
|
11697
|
+
out(`no task ${id2}${ctx.project ? "" : " (no project selected: --project NAME)"}`);
|
|
11567
11698
|
return 1;
|
|
11568
11699
|
}
|
|
11569
11700
|
let r;
|
|
@@ -11591,10 +11722,10 @@ ${entry.source}:${entry.line}
|
|
|
11591
11722
|
case "enable":
|
|
11592
11723
|
case "disable": {
|
|
11593
11724
|
const root = repoRoot(cwd);
|
|
11594
|
-
mkdirSync14(
|
|
11595
|
-
if (cmd === "enable") writeFileSync15(
|
|
11725
|
+
mkdirSync14(join32(root, ".lead"), { recursive: true });
|
|
11726
|
+
if (cmd === "enable") writeFileSync15(join32(root, ENABLED_PATH), `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
11596
11727
|
`);
|
|
11597
|
-
else rmSync6(
|
|
11728
|
+
else rmSync6(join32(root, ENABLED_PATH), { force: true });
|
|
11598
11729
|
out(cmd === "enable" ? "lead is on for you in this repo (hooks active; stored in .lead/enabled, not in git)" : "lead is off for you in this repo: hooks are silent");
|
|
11599
11730
|
return 0;
|
|
11600
11731
|
}
|
|
@@ -11634,7 +11765,7 @@ ${entry.source}:${entry.line}
|
|
|
11634
11765
|
return 0;
|
|
11635
11766
|
}
|
|
11636
11767
|
case "session-start": {
|
|
11637
|
-
const pointer = sharedKit && scope ? [`lead: this project runs with lead, no /lead needed. Launcher: ${
|
|
11768
|
+
const pointer = sharedKit && scope ? [`lead: this project runs with lead, no /lead needed. Launcher: ${join32(repoRoot(cwd), ".lead/lead.mjs")}; kit: ${sharedKit} (start from skills/lead/SKILL.md; references are relative to the kit). When the person asks about plans, tasks, status, handoffs or the board, read that SKILL.md and follow it; do not search for the launcher or run kit-path.`] : [];
|
|
11638
11769
|
if (!isEnabled(repoRoot(cwd))) {
|
|
11639
11770
|
if (pointer.length) out(JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: [...pointer, `lead: this session id is ${session ?? "unknown"}; pass --session ${session ?? "<id>"} to lead.mjs commands.`].join("\n") } }));
|
|
11640
11771
|
return 0;
|
|
@@ -11663,7 +11794,7 @@ ${entry.source}:${entry.line}
|
|
|
11663
11794
|
out(e.message);
|
|
11664
11795
|
return 1;
|
|
11665
11796
|
}
|
|
11666
|
-
const title = ctx.project.name === "." ?
|
|
11797
|
+
const title = ctx.project.name === "." ? basename3(ctx.root) : ctx.project.name;
|
|
11667
11798
|
const r = assembleSpec(ctx.root, ctx.project.workDir, title);
|
|
11668
11799
|
out(r.changed ? "spec.md updated" : "spec.md is up to date");
|
|
11669
11800
|
return 0;
|
|
@@ -11692,7 +11823,7 @@ start the builder with: ${r.launch}`);
|
|
|
11692
11823
|
return 2;
|
|
11693
11824
|
}
|
|
11694
11825
|
const ctx = loadContext(cwd, project);
|
|
11695
|
-
const targets = args.length ? args.map((a) => resolve3(cwd, a)) : [
|
|
11826
|
+
const targets = args.length ? args.map((a) => resolve3(cwd, a)) : [join32(ctx.root, ctx.project?.path ?? ".")];
|
|
11696
11827
|
const matches = similarity(resolve3(cwd, source), targets, ctx.root);
|
|
11697
11828
|
for (const m of matches.slice(0, 50)) out(`${m.file}:${m.line} ${m.kind === "block" ? "block of lines" : "long line"} also in ${m.source}:${m.sourceLine}`);
|
|
11698
11829
|
out(`${matches.length} shared fragments`);
|
|
@@ -11707,7 +11838,7 @@ start the builder with: ${r.launch}`);
|
|
|
11707
11838
|
}
|
|
11708
11839
|
const file = str2(flags.input);
|
|
11709
11840
|
if (!file) throw new Error("--input FILE must point to the read-back Markdown");
|
|
11710
|
-
const mismatches = verifyOnePager(markdown,
|
|
11841
|
+
const mismatches = verifyOnePager(markdown, readFileSync27(resolve3(cwd, file), "utf8"));
|
|
11711
11842
|
out(mismatches.length ? mismatches.join("\n") : "One Pager read-back matches the roadmap, triage, widgets and links");
|
|
11712
11843
|
return mismatches.length ? 1 : 0;
|
|
11713
11844
|
} catch (e) {
|
|
@@ -11715,6 +11846,39 @@ start the builder with: ${r.launch}`);
|
|
|
11715
11846
|
return 1;
|
|
11716
11847
|
}
|
|
11717
11848
|
}
|
|
11849
|
+
case "inbox": {
|
|
11850
|
+
const ctx = loadContext(cwd, project);
|
|
11851
|
+
if (!ctx.project) {
|
|
11852
|
+
out("no project selected: --project NAME");
|
|
11853
|
+
return 1;
|
|
11854
|
+
}
|
|
11855
|
+
const items = inbox(ctx);
|
|
11856
|
+
if (flags.json) out(JSON.stringify({ project: ctx.project.name, items }, null, 2));
|
|
11857
|
+
else if (!items.length) out("Inbox is empty.");
|
|
11858
|
+
else for (const i of items) out(`${i.kind} \xB7 ${i.title}${i.detail ? ` \u2014 ${i.detail}` : ""} \xB7 ${i.source.path}`);
|
|
11859
|
+
return 0;
|
|
11860
|
+
}
|
|
11861
|
+
case "docs": {
|
|
11862
|
+
const ctx = loadContext(cwd, project);
|
|
11863
|
+
if (!ctx.project) {
|
|
11864
|
+
out("no project selected: --project NAME");
|
|
11865
|
+
return 1;
|
|
11866
|
+
}
|
|
11867
|
+
const key = str2(flags.key);
|
|
11868
|
+
if (key) {
|
|
11869
|
+
const text = docText(ctx, key);
|
|
11870
|
+
if (text === void 0) {
|
|
11871
|
+
out(`no document ${key}`);
|
|
11872
|
+
return 1;
|
|
11873
|
+
}
|
|
11874
|
+
out(text);
|
|
11875
|
+
return 0;
|
|
11876
|
+
}
|
|
11877
|
+
const list = docIndex(ctx);
|
|
11878
|
+
if (flags.json) out(JSON.stringify({ project: ctx.project.name, documents: list }, null, 2));
|
|
11879
|
+
else for (const d of list) out(`${d.group} \xB7 ${d.title} \xB7 ${d.path}${d.url ? ` \xB7 ${d.url}` : ""}`);
|
|
11880
|
+
return 0;
|
|
11881
|
+
}
|
|
11718
11882
|
case "sync-plan": {
|
|
11719
11883
|
const ctx = loadContext(cwd, project);
|
|
11720
11884
|
if (!ctx.project) {
|
|
@@ -11750,7 +11914,7 @@ start the builder with: ${r.launch}`);
|
|
|
11750
11914
|
return 0;
|
|
11751
11915
|
}
|
|
11752
11916
|
const actions = syncPlan(ctx).map((a, i) => ({ id: i + 1, ...a }));
|
|
11753
|
-
mkdirSync14(
|
|
11917
|
+
mkdirSync14(join32(ctx.root, ".lead/logs"), { recursive: true });
|
|
11754
11918
|
writeFileSync15(syncPlanPath(ctx.root, ctx.project.name), JSON.stringify({ project: ctx.project.name, actions }, null, 2));
|
|
11755
11919
|
out(JSON.stringify(actions, null, 2));
|
|
11756
11920
|
return 0;
|
|
@@ -11776,7 +11940,7 @@ start the builder with: ${r.launch}`);
|
|
|
11776
11940
|
if (cmd === "sync-attempt") {
|
|
11777
11941
|
if (!syncPlan(ctx).some((current) => syncActionKey(current) === key)) throw new Error("action is no longer in the current plan");
|
|
11778
11942
|
if (journal[key]?.done === false && !flags.retry) throw new Error("prior outcome is uncertain: check the remote result before retrying with --retry, or record the existing result");
|
|
11779
|
-
if (Object.entries(journal).some(([
|
|
11943
|
+
if (Object.entries(journal).some(([id2, entry]) => id2 !== key && !entry.done && entry.label === syncLabel(action))) {
|
|
11780
11944
|
throw new Error("an earlier action for this item has an uncertain outcome: reconcile it before proceeding");
|
|
11781
11945
|
}
|
|
11782
11946
|
journal[key] = { label: syncLabel(action), done: false, action };
|
|
@@ -11806,7 +11970,7 @@ start the builder with: ${r.launch}`);
|
|
|
11806
11970
|
const input = () => {
|
|
11807
11971
|
const file = str2(flags.input);
|
|
11808
11972
|
if (!file) throw new Error("--input FILE is required");
|
|
11809
|
-
return JSON.parse(
|
|
11973
|
+
return JSON.parse(readFileSync27(resolve3(cwd, file), "utf8"));
|
|
11810
11974
|
};
|
|
11811
11975
|
if (cmd === "qa-record") {
|
|
11812
11976
|
const task = ctx.tasks.find((t) => t.id === args[0]);
|
|
@@ -11822,7 +11986,7 @@ start the builder with: ${r.launch}`);
|
|
|
11822
11986
|
} else if (args[0] === "analyze") {
|
|
11823
11987
|
out(JSON.stringify(analyzeScores(ctx), null, 2));
|
|
11824
11988
|
} else if (args[0] === "runs") {
|
|
11825
|
-
out(JSON.stringify(runs(ctx.root).filter((row) => row.subject.project === ctx.project?.name).map(({ id, at, kind, subject }) => ({ id, at, kind, subject })), null, 2));
|
|
11989
|
+
out(JSON.stringify(runs(ctx.root).filter((row) => row.subject.project === ctx.project?.name).map(({ id: id2, at, kind, subject }) => ({ id: id2, at, kind, subject })), null, 2));
|
|
11826
11990
|
} else {
|
|
11827
11991
|
if (args.length) throw new Error("usage: score [runs|record|analyze]");
|
|
11828
11992
|
const limit = Number(str2(flags.limit) ?? 10);
|
|
@@ -11842,15 +12006,15 @@ start the builder with: ${r.launch}`);
|
|
|
11842
12006
|
}
|
|
11843
12007
|
case "claim":
|
|
11844
12008
|
case "release": {
|
|
11845
|
-
const
|
|
11846
|
-
if (!
|
|
12009
|
+
const id2 = args[0];
|
|
12010
|
+
if (!id2 || !session) {
|
|
11847
12011
|
out(`usage: ${cmd} <task> --session ID`);
|
|
11848
12012
|
return 2;
|
|
11849
12013
|
}
|
|
11850
12014
|
const ctx = loadContext(cwd, project);
|
|
11851
|
-
const task = ctx.tasks.find((t) => t.id ===
|
|
12015
|
+
const task = ctx.tasks.find((t) => t.id === id2);
|
|
11852
12016
|
if (!task) {
|
|
11853
|
-
out(`no task ${
|
|
12017
|
+
out(`no task ${id2}`);
|
|
11854
12018
|
return 1;
|
|
11855
12019
|
}
|
|
11856
12020
|
let r;
|
|
@@ -11875,8 +12039,8 @@ start the builder with: ${r.launch}`);
|
|
|
11875
12039
|
out(`usage: use <project>; projects: ${projects.map((p) => p.name).join(", ") || "none"}`);
|
|
11876
12040
|
return 2;
|
|
11877
12041
|
}
|
|
11878
|
-
mkdirSync14(
|
|
11879
|
-
writeFileSync15(
|
|
12042
|
+
mkdirSync14(join32(root, ".lead"), { recursive: true });
|
|
12043
|
+
writeFileSync15(join32(root, CURRENT_PATH), `${name}
|
|
11880
12044
|
`);
|
|
11881
12045
|
out(`current project: ${name}`);
|
|
11882
12046
|
return 0;
|
|
@@ -11906,7 +12070,7 @@ start the builder with: ${r.launch}`);
|
|
|
11906
12070
|
out("usage: install <repo>");
|
|
11907
12071
|
return 2;
|
|
11908
12072
|
}
|
|
11909
|
-
const log = install(kitRoot(),
|
|
12073
|
+
const log = install(kitRoot(), realpathSync6(target), fileURLToPath(import.meta.url), { keepModified: !!flags["keep-modified"] });
|
|
11910
12074
|
out(log.join("\n"));
|
|
11911
12075
|
return 0;
|
|
11912
12076
|
}
|
|
@@ -11922,7 +12086,7 @@ start the builder with: ${r.launch}`);
|
|
|
11922
12086
|
const before = readLock(root)?.version ?? "none";
|
|
11923
12087
|
const r = spawnSync3(
|
|
11924
12088
|
process.execPath,
|
|
11925
|
-
[
|
|
12089
|
+
[join32(kit, "dist/lead.mjs"), "install", root, ...flags.force ? [] : ["--keep-modified"]],
|
|
11926
12090
|
{ cwd: root, encoding: "utf8" }
|
|
11927
12091
|
);
|
|
11928
12092
|
const output = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
@@ -11936,8 +12100,8 @@ start the builder with: ${r.launch}`);
|
|
|
11936
12100
|
try {
|
|
11937
12101
|
if (!from) return withRegistryKit(root, out, applyKit);
|
|
11938
12102
|
const path = resolve3(cwd, from);
|
|
11939
|
-
if (
|
|
11940
|
-
tmp = mkdtempSync3(
|
|
12103
|
+
if (existsSync30(path)) return applyKit(path);
|
|
12104
|
+
tmp = mkdtempSync3(join32(tmpdir3(), "lead-kit-"));
|
|
11941
12105
|
execFileSync6("git", ["clone", "-q", "--depth", "1", "--", from, tmp], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
11942
12106
|
return applyKit(tmp);
|
|
11943
12107
|
} catch (e) {
|
|
@@ -11953,19 +12117,19 @@ start the builder with: ${r.launch}`);
|
|
|
11953
12117
|
case "adopt": {
|
|
11954
12118
|
const root = repoRoot(cwd);
|
|
11955
12119
|
const input = typeof flags.input === "string" ? flags.input : "";
|
|
11956
|
-
const
|
|
12120
|
+
const id2 = typeof flags.id === "string" ? flags.id : "";
|
|
11957
12121
|
const home = typeof flags.home === "string" ? flags.home : "";
|
|
11958
|
-
if (!input || !
|
|
12122
|
+
if (!input || !id2 || !home) {
|
|
11959
12123
|
out("usage: adopt --input FILE --id ID --home REPO [--flag KEY] [--title TEXT] [--write] [--force]");
|
|
11960
12124
|
return 2;
|
|
11961
12125
|
}
|
|
11962
|
-
if (!/^[a-z][a-z0-9-]*$/.test(
|
|
12126
|
+
if (!/^[a-z][a-z0-9-]*$/.test(id2) || id2 === "check" || id2 === "waves" || !/^[a-z][a-z0-9-]*$/.test(home)) {
|
|
11963
12127
|
out('--id and --home must look like "private-space" (id cannot be check or waves)');
|
|
11964
12128
|
return 2;
|
|
11965
12129
|
}
|
|
11966
12130
|
let raw;
|
|
11967
12131
|
try {
|
|
11968
|
-
raw = JSON.parse(
|
|
12132
|
+
raw = JSON.parse(readFileSync27(resolve3(cwd, input), "utf8"));
|
|
11969
12133
|
} catch (error) {
|
|
11970
12134
|
out(`cannot read ${input}: ${error.message}`);
|
|
11971
12135
|
return 2;
|
|
@@ -11975,15 +12139,15 @@ start the builder with: ${r.launch}`);
|
|
|
11975
12139
|
for (const e of errors) out(`error ${e}`);
|
|
11976
12140
|
return 2;
|
|
11977
12141
|
}
|
|
11978
|
-
const syncFile =
|
|
12142
|
+
const syncFile = join32(root, "work/initiatives", id2, "sync.json");
|
|
11979
12143
|
let previous;
|
|
11980
12144
|
try {
|
|
11981
|
-
previous = JSON.parse(
|
|
12145
|
+
previous = JSON.parse(readFileSync27(syncFile, "utf8"));
|
|
11982
12146
|
} catch {
|
|
11983
12147
|
previous = void 0;
|
|
11984
12148
|
}
|
|
11985
|
-
const existing = loadInitiatives(root).initiatives.find((i) => i.id ===
|
|
11986
|
-
const proposal = propose(inventory, { id, home, previous, ...existing ? { overrides: existing.map } : {}, ...typeof flags.title === "string" ? { title: flags.title } : {}, ...typeof flags.flag === "string" ? { flag: flags.flag } : {} });
|
|
12149
|
+
const existing = loadInitiatives(root).initiatives.find((i) => i.id === id2);
|
|
12150
|
+
const proposal = propose(inventory, { id: id2, home, previous, ...existing ? { overrides: existing.map } : {}, ...typeof flags.title === "string" ? { title: flags.title } : {}, ...typeof flags.flag === "string" ? { flag: flags.flag } : {} });
|
|
11987
12151
|
const diff = previous ? diffObserved(previous, proposal) : void 0;
|
|
11988
12152
|
if (flags.json) out(JSON.stringify({ ...proposal, ...diff ? { diff } : {} }, null, 2));
|
|
11989
12153
|
else {
|
|
@@ -12002,17 +12166,17 @@ start the builder with: ${r.launch}`);
|
|
|
12002
12166
|
const { initiatives, issues } = loadInitiatives(root);
|
|
12003
12167
|
const errors = issues.filter((i) => i.level === "error");
|
|
12004
12168
|
const sub = args[0] === "check" || args[0] === "waves" ? args[0] : void 0;
|
|
12005
|
-
const
|
|
12169
|
+
const id2 = sub ? args[1] : args[0];
|
|
12006
12170
|
if (sub === "check" || sub === "waves") {
|
|
12007
|
-
if (
|
|
12008
|
-
out(`no initiative "${
|
|
12171
|
+
if (id2 && !initiatives.some((i) => i.id === id2)) {
|
|
12172
|
+
out(`no initiative "${id2}". Known: ${initiatives.map((i) => i.id).join(", ") || "none"}`);
|
|
12009
12173
|
return 1;
|
|
12010
12174
|
}
|
|
12011
|
-
if (sub === "waves" && !
|
|
12175
|
+
if (sub === "waves" && !id2) {
|
|
12012
12176
|
out("usage: initiative waves <id> [--write]");
|
|
12013
12177
|
return 2;
|
|
12014
12178
|
}
|
|
12015
|
-
const chosen = initiatives.filter((i) => !
|
|
12179
|
+
const chosen = initiatives.filter((i) => !id2 || i.id === id2);
|
|
12016
12180
|
if (sub === "waves") {
|
|
12017
12181
|
const target = chosen[0];
|
|
12018
12182
|
if (flags.write) for (const line of writeInitiativeWaves(root, target)) out(line);
|
|
@@ -12028,13 +12192,13 @@ start the builder with: ${r.launch}`);
|
|
|
12028
12192
|
out(all.length ? formatIssues(all) : "initiatives: ok");
|
|
12029
12193
|
return all.some((i) => i.level === "error") ? 1 : 0;
|
|
12030
12194
|
}
|
|
12031
|
-
if (
|
|
12032
|
-
out(`no initiative "${
|
|
12195
|
+
if (id2 && !initiatives.some((i) => i.id === id2)) {
|
|
12196
|
+
out(`no initiative "${id2}". Known: ${initiatives.map((i) => i.id).join(", ") || "none"}`);
|
|
12033
12197
|
return 1;
|
|
12034
12198
|
}
|
|
12035
12199
|
if (typeof flags.in === "string") {
|
|
12036
12200
|
const repo = flags.in;
|
|
12037
|
-
const one = initiatives.filter((i) => !
|
|
12201
|
+
const one = initiatives.filter((i) => !id2 || i.id === id2);
|
|
12038
12202
|
const rows = one.map((i) => {
|
|
12039
12203
|
const o = initiativeOverview(root, i);
|
|
12040
12204
|
return { id: i.id, repo, known: i.repos.some((r) => r.name === repo), tasks: o.tasks.filter((t) => t.repo === repo), observed: observedRecords(root, i, repo) };
|
|
@@ -12050,7 +12214,7 @@ start the builder with: ${r.launch}`);
|
|
|
12050
12214
|
}
|
|
12051
12215
|
return errors.length ? 1 : 0;
|
|
12052
12216
|
}
|
|
12053
|
-
const overview = initiatives.filter((i) => !
|
|
12217
|
+
const overview = initiatives.filter((i) => !id2 || i.id === id2).map((i) => initiativeOverview(root, i));
|
|
12054
12218
|
if (flags.json) out(JSON.stringify({ initiatives: overview, issues }, null, 2));
|
|
12055
12219
|
else {
|
|
12056
12220
|
for (const o of overview) for (const line of renderInitiative(o)) out(line);
|
|
@@ -12069,7 +12233,7 @@ start the builder with: ${r.launch}`);
|
|
|
12069
12233
|
out(`no adapter "${name}". Known: ${adapters.map((a) => a.id).join(", ") || "none"}`);
|
|
12070
12234
|
return 1;
|
|
12071
12235
|
}
|
|
12072
|
-
out(flags.json ? JSON.stringify({ ...found, text:
|
|
12236
|
+
out(flags.json ? JSON.stringify({ ...found, text: readFileSync27(join32(root, found.file), "utf8") }, null, 2) : readFileSync27(join32(root, found.file), "utf8").trimEnd());
|
|
12073
12237
|
return 0;
|
|
12074
12238
|
}
|
|
12075
12239
|
if (flags.json) out(JSON.stringify({ adapters, issues }, null, 2));
|
|
@@ -12083,14 +12247,14 @@ start the builder with: ${r.launch}`);
|
|
|
12083
12247
|
case "delegate": {
|
|
12084
12248
|
const ctx = loadContext(cwd, project);
|
|
12085
12249
|
const services = listDelegates(ctx.root, kitRoot());
|
|
12086
|
-
const
|
|
12250
|
+
const id2 = args[0] === "check" ? void 0 : args[0];
|
|
12087
12251
|
const checking = args.includes("check");
|
|
12088
|
-
if (
|
|
12089
|
-
out(`no delegate "${
|
|
12252
|
+
if (id2 && !services.some((d) => d.id === id2)) {
|
|
12253
|
+
out(`no delegate "${id2}". Known: ${services.map((d) => d.id).join(", ") || "none"}`);
|
|
12090
12254
|
return 1;
|
|
12091
12255
|
}
|
|
12092
|
-
const tasks = delegatedTasks(ctx.tasks,
|
|
12093
|
-
const payload = { services:
|
|
12256
|
+
const tasks = delegatedTasks(ctx.tasks, id2).map((t) => ({ id: t.id, title: t.title, delegate: t.delegate, ref: t.delegate_ref, status: t.status }));
|
|
12257
|
+
const payload = { services: id2 ? services.filter((d) => d.id === id2) : services, tasks, check: checking };
|
|
12094
12258
|
if (flags.json) out(JSON.stringify(payload, null, 2));
|
|
12095
12259
|
else {
|
|
12096
12260
|
for (const d of payload.services) out(`${d.id} (${d.source}) \u2014 ${d.available || d.title}`);
|
|
@@ -12210,12 +12374,12 @@ ${HELP}`);
|
|
|
12210
12374
|
}
|
|
12211
12375
|
}
|
|
12212
12376
|
function syncPlanPath(root, project) {
|
|
12213
|
-
return
|
|
12377
|
+
return join32(root, ".lead/logs", `sync-plan-${project === "." ? "root" : project.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`);
|
|
12214
12378
|
}
|
|
12215
|
-
function savedSyncAction(root, project,
|
|
12216
|
-
const saved = JSON.parse(
|
|
12379
|
+
function savedSyncAction(root, project, id2) {
|
|
12380
|
+
const saved = JSON.parse(readFileSync27(syncPlanPath(root, project), "utf8"));
|
|
12217
12381
|
if (saved.project !== project) throw new Error(`the saved plan is for ${saved.project}, not ${project}`);
|
|
12218
|
-
return saved.actions.find((action) => action.id ===
|
|
12382
|
+
return saved.actions.find((action) => action.id === id2);
|
|
12219
12383
|
}
|
|
12220
12384
|
function syncActionKey(action) {
|
|
12221
12385
|
const { id: _id, ...payload } = action;
|
|
@@ -12227,11 +12391,11 @@ function syncLabel(action) {
|
|
|
12227
12391
|
return `${action.kind}${target ? ` \xB7 ${target}` : ""}${transition}`;
|
|
12228
12392
|
}
|
|
12229
12393
|
function syncJournalPath(root, project) {
|
|
12230
|
-
return
|
|
12394
|
+
return join32(root, ".lead/logs", `sync-journal-${digest(project)}.json`);
|
|
12231
12395
|
}
|
|
12232
12396
|
function readSyncJournal(root, project) {
|
|
12233
12397
|
const file = syncJournalPath(root, project);
|
|
12234
|
-
return
|
|
12398
|
+
return existsSync30(file) ? JSON.parse(readFileSync27(file, "utf8")) : {};
|
|
12235
12399
|
}
|
|
12236
12400
|
function writeSyncJournal(root, project, journal) {
|
|
12237
12401
|
const file = syncJournalPath(root, project);
|
|
@@ -12240,13 +12404,13 @@ function writeSyncJournal(root, project, journal) {
|
|
|
12240
12404
|
}
|
|
12241
12405
|
function readStdinJson() {
|
|
12242
12406
|
try {
|
|
12243
|
-
const text =
|
|
12407
|
+
const text = readFileSync27(0, "utf8");
|
|
12244
12408
|
return text.trim() ? JSON.parse(text) : {};
|
|
12245
12409
|
} catch {
|
|
12246
12410
|
return {};
|
|
12247
12411
|
}
|
|
12248
12412
|
}
|
|
12249
|
-
var isMain = process.argv[1] &&
|
|
12413
|
+
var isMain = process.argv[1] && realpathSync6(process.argv[1]) === realpathSync6(fileURLToPath(import.meta.url));
|
|
12250
12414
|
if (isMain) process.exitCode = main(process.argv.slice(2));
|
|
12251
12415
|
export {
|
|
12252
12416
|
main
|