@fusebase/harness-lead 0.3.0 → 0.3.3
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 +28 -0
- package/dist/lead.mjs +1490 -1113
- package/package.json +1 -1
- package/skills/lead/SKILL.md +1 -1
- package/skills/lead/delegates/codee/SKILL.md +3 -1
- package/skills/lead/references/qa.md +2 -0
- package/skills/lead/references/status.md +2 -2
- package/skills/lead/references/watch.md +12 -1
package/dist/lead.mjs
CHANGED
|
@@ -1738,7 +1738,7 @@ var require_merge = __commonJS({
|
|
|
1738
1738
|
var require_addPairToJSMap = __commonJS({
|
|
1739
1739
|
"node_modules/.pnpm/yaml@2.7.0/node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports) {
|
|
1740
1740
|
"use strict";
|
|
1741
|
-
var
|
|
1741
|
+
var log2 = require_log();
|
|
1742
1742
|
var merge = require_merge();
|
|
1743
1743
|
var stringify3 = require_stringify();
|
|
1744
1744
|
var identity = require_identity();
|
|
@@ -1787,7 +1787,7 @@ var require_addPairToJSMap = __commonJS({
|
|
|
1787
1787
|
let jsonStr = JSON.stringify(strKey);
|
|
1788
1788
|
if (jsonStr.length > 40)
|
|
1789
1789
|
jsonStr = jsonStr.substring(0, 36) + '..."';
|
|
1790
|
-
|
|
1790
|
+
log2.warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
|
|
1791
1791
|
ctx.mapKeyWarned = true;
|
|
1792
1792
|
}
|
|
1793
1793
|
return strKey;
|
|
@@ -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;
|
|
@@ -7163,7 +7163,7 @@ var require_public_api = __commonJS({
|
|
|
7163
7163
|
var composer = require_composer();
|
|
7164
7164
|
var Document = require_Document();
|
|
7165
7165
|
var errors = require_errors();
|
|
7166
|
-
var
|
|
7166
|
+
var log2 = require_log();
|
|
7167
7167
|
var identity = require_identity();
|
|
7168
7168
|
var lineCounter = require_line_counter();
|
|
7169
7169
|
var parser = require_parser();
|
|
@@ -7215,7 +7215,7 @@ var require_public_api = __commonJS({
|
|
|
7215
7215
|
const doc = parseDocument(src, options);
|
|
7216
7216
|
if (!doc)
|
|
7217
7217
|
return null;
|
|
7218
|
-
doc.warnings.forEach((warning) =>
|
|
7218
|
+
doc.warnings.forEach((warning) => log2.warn(doc.options.logLevel, warning));
|
|
7219
7219
|
if (doc.errors.length > 0) {
|
|
7220
7220
|
if (doc.options.logLevel !== "silent")
|
|
7221
7221
|
throw doc.errors[0];
|
|
@@ -7306,8 +7306,8 @@ var require_dist = __commonJS({
|
|
|
7306
7306
|
});
|
|
7307
7307
|
|
|
7308
7308
|
// src/cli.ts
|
|
7309
|
-
import { mkdirSync as
|
|
7310
|
-
import { dirname as dirname6, join as
|
|
7309
|
+
import { mkdirSync as mkdirSync15, realpathSync as realpathSync6, writeFileSync as writeFileSync16 } from "node:fs";
|
|
7310
|
+
import { dirname as dirname6, join as join33, 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.3'], 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";
|
|
@@ -8232,29 +8241,29 @@ function read(root) {
|
|
|
8232
8241
|
}
|
|
8233
8242
|
function ensureClaudeSettings(root) {
|
|
8234
8243
|
const s = read(root);
|
|
8235
|
-
const
|
|
8244
|
+
const log2 = [];
|
|
8236
8245
|
s.hooks ??= {};
|
|
8237
8246
|
for (const [event, command] of Object.entries(HOOKS)) {
|
|
8238
8247
|
const list = s.hooks[event] ??= [];
|
|
8239
8248
|
if (!list.some((e) => e.hooks?.some((h2) => h2.command === command))) {
|
|
8240
8249
|
list.push({ hooks: [{ type: "command", command }] });
|
|
8241
|
-
|
|
8250
|
+
log2.push(`${CLAUDE_SETTINGS}: added ${event} hook`);
|
|
8242
8251
|
}
|
|
8243
8252
|
}
|
|
8244
8253
|
if (s.permissions?.allow) {
|
|
8245
8254
|
const before = s.permissions.allow.length;
|
|
8246
8255
|
s.permissions.allow = s.permissions.allow.filter((r) => !OLD_ALLOW.includes(r));
|
|
8247
|
-
if (s.permissions.allow.length !== before)
|
|
8256
|
+
if (s.permissions.allow.length !== before) log2.push(`${CLAUDE_SETTINGS}: removed lead's shared allow rules`);
|
|
8248
8257
|
if (!s.permissions.allow.length) delete s.permissions.allow;
|
|
8249
8258
|
if (!Object.keys(s.permissions).length) delete s.permissions;
|
|
8250
8259
|
}
|
|
8251
|
-
if (
|
|
8260
|
+
if (log2.length) {
|
|
8252
8261
|
const p = join10(root, CLAUDE_SETTINGS);
|
|
8253
8262
|
mkdirSync2(dirname(p), { recursive: true });
|
|
8254
8263
|
writeFileSync3(p, `${JSON.stringify(s, null, 2)}
|
|
8255
8264
|
`);
|
|
8256
8265
|
}
|
|
8257
|
-
return
|
|
8266
|
+
return log2;
|
|
8258
8267
|
}
|
|
8259
8268
|
function claudeSettingsOk(root) {
|
|
8260
8269
|
const s = read(root);
|
|
@@ -8270,25 +8279,25 @@ var CODEX = { SessionStart: `${CODEX_CLI} session-start`, Stop: `${CODEX_CLI} st
|
|
|
8270
8279
|
function ensureCodexHooks(root) {
|
|
8271
8280
|
const p = join10(root, CODEX_HOOKS);
|
|
8272
8281
|
const s = existsSync9(p) ? JSON.parse(readFileSync8(p, "utf8")) : {};
|
|
8273
|
-
const
|
|
8282
|
+
const log2 = [];
|
|
8274
8283
|
s.hooks ??= {};
|
|
8275
8284
|
for (const [event, command] of Object.entries(CODEX)) {
|
|
8276
8285
|
const list = s.hooks[event] ??= [];
|
|
8277
8286
|
if (!list.some((e) => e.hooks?.some((h2) => h2.command === command))) {
|
|
8278
8287
|
list.push({ hooks: [{ type: "command", command, ...event === "Stop" ? { timeout: 120 } : {} }] });
|
|
8279
|
-
|
|
8288
|
+
log2.push(`${CODEX_HOOKS}: added ${event} hook`);
|
|
8280
8289
|
}
|
|
8281
8290
|
}
|
|
8282
|
-
if (
|
|
8291
|
+
if (log2.length) {
|
|
8283
8292
|
mkdirSync2(dirname(p), { recursive: true });
|
|
8284
8293
|
writeFileSync3(p, `${JSON.stringify(s, null, 2)}
|
|
8285
8294
|
`);
|
|
8286
8295
|
}
|
|
8287
|
-
return
|
|
8296
|
+
return log2;
|
|
8288
8297
|
}
|
|
8289
8298
|
|
|
8290
8299
|
// src/install.ts
|
|
8291
|
-
var VERSION = true ? "0.3.
|
|
8300
|
+
var VERSION = true ? "0.3.3" : "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"];
|
|
@@ -8333,7 +8342,7 @@ ${block}
|
|
|
8333
8342
|
return "added";
|
|
8334
8343
|
}
|
|
8335
8344
|
function install(kitRoot2, target, cliPath, opts = {}) {
|
|
8336
|
-
const
|
|
8345
|
+
const log2 = [];
|
|
8337
8346
|
const prev = readLock(target);
|
|
8338
8347
|
const files2 = {};
|
|
8339
8348
|
const put = (src, rel) => {
|
|
@@ -8344,10 +8353,10 @@ function install(kitRoot2, target, cliPath, opts = {}) {
|
|
|
8344
8353
|
mkdirSync3(dirname2(side), { recursive: true });
|
|
8345
8354
|
copyFileSync(src, side);
|
|
8346
8355
|
files2[rel] = prev.files[rel];
|
|
8347
|
-
|
|
8356
|
+
log2.push(`kept ${rel}: changed by hand; new kit version is in .lead/update/${rel} \u2014 move the local change to .lead/local/ and run update --force`);
|
|
8348
8357
|
return;
|
|
8349
8358
|
}
|
|
8350
|
-
if (changedByHand)
|
|
8359
|
+
if (changedByHand) log2.push(`overwrote ${rel}: it was changed by hand`);
|
|
8351
8360
|
mkdirSync3(dirname2(dst), { recursive: true });
|
|
8352
8361
|
copyFileSync(src, dst);
|
|
8353
8362
|
files2[rel] = sha256(dst);
|
|
@@ -8360,24 +8369,24 @@ function install(kitRoot2, target, cliPath, opts = {}) {
|
|
|
8360
8369
|
}
|
|
8361
8370
|
put(cliPath, ".lead/lead.mjs");
|
|
8362
8371
|
const block = TEMPLATES["AGENTS.block.md"].trim();
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8372
|
+
log2.push(`AGENTS.md: ${upsertBlock(join11(target, "AGENTS.md"), block, "# Agent instructions\n\n")} lead block`);
|
|
8373
|
+
log2.push(...ensureGitIgnore(target));
|
|
8374
|
+
log2.push(...ensureClaudeSettings(target));
|
|
8375
|
+
log2.push(...ensureCodexHooks(target));
|
|
8367
8376
|
const lock = { version: VERSION, files: files2 };
|
|
8368
8377
|
writeFileSync4(join11(target, LOCK_PATH), `${JSON.stringify(lock, null, 2)}
|
|
8369
8378
|
`);
|
|
8370
|
-
|
|
8371
|
-
return
|
|
8379
|
+
log2.push(prev && prev.version !== VERSION ? `updated lead ${prev.version} \u2192 ${VERSION}: ${Object.keys(files2).length} kit files` : `installed lead ${VERSION}: ${Object.keys(files2).length} kit files`);
|
|
8380
|
+
return log2;
|
|
8372
8381
|
}
|
|
8373
8382
|
function scaffold(root, project) {
|
|
8374
|
-
const
|
|
8383
|
+
const log2 = [];
|
|
8375
8384
|
const make = (rel, template) => {
|
|
8376
8385
|
const abs = join11(root, rel);
|
|
8377
8386
|
if (existsSync10(abs)) return;
|
|
8378
8387
|
mkdirSync3(dirname2(abs), { recursive: true });
|
|
8379
8388
|
writeFileSync4(abs, TEMPLATES[template]);
|
|
8380
|
-
|
|
8389
|
+
log2.push(`created ${rel}`);
|
|
8381
8390
|
};
|
|
8382
8391
|
make(CONFIG_PATH, "config.yml");
|
|
8383
8392
|
make(".lead/local.md", "local.md");
|
|
@@ -8397,11 +8406,11 @@ function scaffold(root, project) {
|
|
|
8397
8406
|
if (!existsSync10(abs)) {
|
|
8398
8407
|
mkdirSync3(abs, { recursive: true });
|
|
8399
8408
|
writeFileSync4(join11(abs, ".gitkeep"), "");
|
|
8400
|
-
|
|
8409
|
+
log2.push(`created ${join11(work, d)}/`);
|
|
8401
8410
|
}
|
|
8402
8411
|
}
|
|
8403
8412
|
}
|
|
8404
|
-
return
|
|
8413
|
+
return log2;
|
|
8405
8414
|
}
|
|
8406
8415
|
function ensureGitIgnore(root) {
|
|
8407
8416
|
const file = join11(root, ".gitignore");
|
|
@@ -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 log2 = [];
|
|
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
|
+
log2.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
8816
8775
|
}
|
|
8817
|
-
return
|
|
8776
|
+
return log2.length ? log2 : ["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
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
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();
|
|
9147
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
9148
|
+
};
|
|
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,55 +9254,55 @@ 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
|
}
|
|
8941
9267
|
}
|
|
8942
9268
|
|
|
8943
9269
|
// src/cli.ts
|
|
8944
|
-
import { execFileSync as execFileSync6, spawnSync as
|
|
8945
|
-
import { existsSync as
|
|
9270
|
+
import { execFileSync as execFileSync6, spawnSync as spawnSync4 } from "node:child_process";
|
|
9271
|
+
import { existsSync as existsSync31, 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,8 +9424,8 @@ 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(
|
|
9102
|
-
let
|
|
9427
|
+
mkdirSync7(join20(ctx.root, ".lead/logs"), { recursive: true });
|
|
9428
|
+
let log2 = "";
|
|
9103
9429
|
const commands = [];
|
|
9104
9430
|
const failures = [];
|
|
9105
9431
|
for (const [name, template] of checks) {
|
|
@@ -9107,14 +9433,14 @@ function recordChecks(ctx, t, opts) {
|
|
|
9107
9433
|
const r = spawnSync2("sh", ["-c", cmd], { cwd: dir, encoding: "utf8", timeout: 15 * 60 * 1e3, maxBuffer: 64 * 1024 * 1024 });
|
|
9108
9434
|
const code = r.status ?? 1;
|
|
9109
9435
|
const output = `${r.stdout ?? ""}${r.stderr ?? ""}`;
|
|
9110
|
-
|
|
9436
|
+
log2 += `$ ${cmd} (${name}, exit ${code})
|
|
9111
9437
|
${output}
|
|
9112
9438
|
`;
|
|
9113
9439
|
commands.push({ cmd, exit_code: code });
|
|
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), log2);
|
|
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];
|
|
@@ -10097,61 +10465,124 @@ function syncRecord(ctx, action, result) {
|
|
|
10097
10465
|
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
|
-
const
|
|
10468
|
+
const log2 = [];
|
|
10101
10469
|
for (const t of ctx.tasks) {
|
|
10102
10470
|
const w = waves.get(t.id);
|
|
10103
10471
|
if (w === void 0 || w === t.wave || t.status === "done") continue;
|
|
10104
|
-
const abs =
|
|
10105
|
-
const text =
|
|
10472
|
+
const abs = join23(ctx.root, t.file);
|
|
10473
|
+
const text = readFileSync18(abs, "utf8");
|
|
10106
10474
|
const { parsed } = parseFrontmatter(text, t.file);
|
|
10107
10475
|
if (!parsed) continue;
|
|
10108
10476
|
parsed.data.wave = w;
|
|
10109
10477
|
writeFileSync10(abs, renderFrontmatter(parsed.data, parsed.body));
|
|
10110
|
-
|
|
10478
|
+
log2.push(`${t.id}: wave ${t.wave ?? "-"} \u2192 ${w}`);
|
|
10111
10479
|
}
|
|
10112
|
-
return
|
|
10480
|
+
return log2;
|
|
10113
10481
|
}
|
|
10114
10482
|
function writeBoard(ctx, isMerged = gitMergedChecker(ctx.root)) {
|
|
10115
10483
|
if (!ctx.project) throw new Error("no project selected");
|
|
10116
|
-
const
|
|
10484
|
+
const log2 = [];
|
|
10117
10485
|
const board = renderBoard({ projectName: ctx.project.name, tasks: ctx.tasks, onePager: ctx.onePager, config: ctx.config });
|
|
10118
|
-
const boardPath =
|
|
10486
|
+
const boardPath = join23(ctx.project.workDir, "board.md");
|
|
10119
10487
|
let old = "";
|
|
10120
10488
|
try {
|
|
10121
|
-
old =
|
|
10489
|
+
old = readFileSync18(boardPath, "utf8");
|
|
10122
10490
|
} catch {
|
|
10123
10491
|
}
|
|
10124
10492
|
if (old !== board) {
|
|
10125
10493
|
writeFileSync10(boardPath, board);
|
|
10126
|
-
|
|
10494
|
+
log2.push("board.md updated");
|
|
10127
10495
|
}
|
|
10128
10496
|
if (ctx.onePager) {
|
|
10129
10497
|
const blocks = renderOnePagerBlocks(ctx.tasks, ctx.onePager.milestones, isMerged, ctx.config.can_show);
|
|
10130
10498
|
const next = replaceBlocks(ctx.onePager.text, (k) => blocks[k]);
|
|
10131
10499
|
if (next !== ctx.onePager.text) {
|
|
10132
|
-
writeFileSync10(
|
|
10133
|
-
|
|
10500
|
+
writeFileSync10(join23(ctx.root, ctx.onePager.file), next);
|
|
10501
|
+
log2.push(`one-pager.md blocks updated: ${blockKinds(next).join(", ")}`);
|
|
10134
10502
|
}
|
|
10135
10503
|
}
|
|
10136
|
-
const backlog =
|
|
10137
|
-
if (
|
|
10138
|
-
const current =
|
|
10504
|
+
const backlog = join23(ctx.project.workDir, "backlog.md");
|
|
10505
|
+
if (existsSync21(backlog)) {
|
|
10506
|
+
const current = readFileSync18(backlog, "utf8");
|
|
10139
10507
|
const next = replaceBlocks(current, (kind) => ["tasks", "proposals"].includes(kind) ? renderBacklogItems(ctx.project.workDir) : void 0);
|
|
10140
10508
|
if (next !== current) {
|
|
10141
10509
|
writeFileSync10(backlog, next);
|
|
10142
|
-
|
|
10510
|
+
log2.push("backlog.md tasks updated");
|
|
10143
10511
|
}
|
|
10144
10512
|
}
|
|
10145
|
-
return
|
|
10513
|
+
return log2;
|
|
10146
10514
|
}
|
|
10147
10515
|
|
|
10148
10516
|
// src/cli.ts
|
|
10149
|
-
import { readFileSync as
|
|
10517
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
10150
10518
|
|
|
10151
|
-
// src/
|
|
10519
|
+
// src/inbox.ts
|
|
10152
10520
|
import { createHash as createHash6 } from "node:crypto";
|
|
10153
|
-
import { existsSync as
|
|
10154
|
-
import {
|
|
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
|
+
});
|
|
10578
|
+
}
|
|
10579
|
+
return items;
|
|
10580
|
+
}
|
|
10581
|
+
|
|
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";
|
|
10155
10586
|
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
10156
10587
|
function packageStores() {
|
|
10157
10588
|
try {
|
|
@@ -10163,9 +10594,9 @@ function packageStores() {
|
|
|
10163
10594
|
}
|
|
10164
10595
|
function gitCommonDir(root) {
|
|
10165
10596
|
try {
|
|
10166
|
-
return
|
|
10597
|
+
return realpathSync5(execFileSync5("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: root, encoding: "utf8" }).trim());
|
|
10167
10598
|
} catch {
|
|
10168
|
-
return
|
|
10599
|
+
return join25(root, ".git");
|
|
10169
10600
|
}
|
|
10170
10601
|
}
|
|
10171
10602
|
var pathRules = (abs) => {
|
|
@@ -10174,12 +10605,12 @@ var pathRules = (abs) => {
|
|
|
10174
10605
|
};
|
|
10175
10606
|
var isUselessRule = (r) => /^(Grep|Glob|Edit)\(\/\//.test(r);
|
|
10176
10607
|
function builderSettings(root, name, source, extra = []) {
|
|
10177
|
-
const abs =
|
|
10608
|
+
const abs = realpathSync5(source);
|
|
10178
10609
|
if (abs === root || abs.startsWith(root + "/")) throw new Error(`the source of ${name} must live outside the repo (found inside ${root})`);
|
|
10179
10610
|
const rel = `.lead/builder-${name.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`;
|
|
10180
|
-
const file =
|
|
10181
|
-
const prev =
|
|
10182
|
-
const paths = [abs,
|
|
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))];
|
|
10183
10614
|
const deny = /* @__PURE__ */ new Set([
|
|
10184
10615
|
...(prev.permissions?.deny ?? []).filter((r) => !isUselessRule(r)),
|
|
10185
10616
|
...paths.flatMap(pathRules),
|
|
@@ -10208,7 +10639,7 @@ function builderSettings(root, name, source, extra = []) {
|
|
|
10208
10639
|
SessionStart: [{ hooks: [{ type: "command", command: `${cli} session-start` }] }]
|
|
10209
10640
|
}
|
|
10210
10641
|
};
|
|
10211
|
-
mkdirSync9(
|
|
10642
|
+
mkdirSync9(join25(root, ".lead"), { recursive: true });
|
|
10212
10643
|
writeFileSync11(file, `${JSON.stringify(settings, null, 2)}
|
|
10213
10644
|
`);
|
|
10214
10645
|
return { path: rel, launch: `claude --settings ${rel}` };
|
|
@@ -10216,16 +10647,16 @@ function builderSettings(root, name, source, extra = []) {
|
|
|
10216
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"]);
|
|
10217
10648
|
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", "coverage", "vendor", ".lead", ".claude"]);
|
|
10218
10649
|
function files(dir, out = []) {
|
|
10219
|
-
if (!
|
|
10220
|
-
const st =
|
|
10650
|
+
if (!existsSync23(dir)) return out;
|
|
10651
|
+
const st = statSync7(dir);
|
|
10221
10652
|
if (st.isFile()) {
|
|
10222
10653
|
out.push(dir);
|
|
10223
10654
|
return out;
|
|
10224
10655
|
}
|
|
10225
|
-
for (const n of
|
|
10656
|
+
for (const n of readdirSync12(dir)) {
|
|
10226
10657
|
if (SKIP.has(n)) continue;
|
|
10227
|
-
const p =
|
|
10228
|
-
const s =
|
|
10658
|
+
const p = join25(dir, n);
|
|
10659
|
+
const s = statSync7(p);
|
|
10229
10660
|
if (s.isDirectory()) files(p, out);
|
|
10230
10661
|
else if (TEXT.has(extname(n)) && s.size < 1e6) out.push(p);
|
|
10231
10662
|
}
|
|
@@ -10234,629 +10665,514 @@ function files(dir, out = []) {
|
|
|
10234
10665
|
function meaningful(text) {
|
|
10235
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));
|
|
10236
10667
|
}
|
|
10237
|
-
var h = (s) =>
|
|
10668
|
+
var h = (s) => createHash7("sha1").update(s).digest("hex");
|
|
10238
10669
|
function similarity(source, targets, root, window = 6, longLine = 200) {
|
|
10239
10670
|
const blocks = /* @__PURE__ */ new Map();
|
|
10240
10671
|
const longs = /* @__PURE__ */ new Map();
|
|
10241
10672
|
for (const f of files(source)) {
|
|
10242
|
-
const m = meaningful(
|
|
10673
|
+
const m = meaningful(readFileSync20(f, "utf8"));
|
|
10243
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 });
|
|
10244
10675
|
for (const x of m) if (x.norm.length >= longLine) longs.set(h(x.norm), { file: f, line: x.line });
|
|
10245
10676
|
}
|
|
10246
10677
|
const matches = [];
|
|
10247
10678
|
for (const t of targets.flatMap((p) => files(p))) {
|
|
10248
|
-
const m = meaningful(
|
|
10679
|
+
const m = meaningful(readFileSync20(t, "utf8"));
|
|
10249
10680
|
let skipUntil = -1;
|
|
10250
10681
|
for (let i = 0; i + window <= m.length; i++) {
|
|
10251
10682
|
if (i < skipUntil) continue;
|
|
10252
10683
|
const hit = blocks.get(h(m.slice(i, i + window).map((x) => x.norm).join("\n")));
|
|
10253
10684
|
if (hit) {
|
|
10254
|
-
matches.push({ file:
|
|
10685
|
+
matches.push({ file: relative12(root, t), line: m[i].line, source: relative12(source, hit.file) || hit.file, sourceLine: hit.line, kind: "block" });
|
|
10255
10686
|
skipUntil = i + window;
|
|
10256
10687
|
}
|
|
10257
10688
|
}
|
|
10258
10689
|
for (const x of m) {
|
|
10259
10690
|
const hit = x.norm.length >= longLine ? longs.get(h(x.norm)) : void 0;
|
|
10260
|
-
if (hit) matches.push({ file:
|
|
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 };
|
|
10332
|
-
}
|
|
10333
|
-
}
|
|
10334
|
-
function writeWatch(root, state) {
|
|
10335
|
-
mkdirSync10(join23(root, ".lead"), { recursive: true });
|
|
10336
|
-
writeFileSync12(join23(root, WATCH_PATH), `${JSON.stringify(state, null, 2)}
|
|
10337
|
-
`);
|
|
10338
|
-
}
|
|
10339
|
-
function alive(pid) {
|
|
10340
|
-
if (!pid || pid <= 1) return false;
|
|
10341
|
-
try {
|
|
10342
|
-
process.kill(pid, 0);
|
|
10343
|
-
return true;
|
|
10344
|
-
} catch {
|
|
10345
|
-
return false;
|
|
10346
|
-
}
|
|
10347
|
-
}
|
|
10348
|
-
function watchStatus(root) {
|
|
10349
|
-
const s = readWatch(root);
|
|
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) };
|
|
10365
|
-
}
|
|
10366
|
-
if (sub === "stop") {
|
|
10367
|
-
if (alive(state.pid)) {
|
|
10368
|
-
try {
|
|
10369
|
-
process.kill(state.pid, "SIGTERM");
|
|
10370
|
-
} catch {
|
|
10371
|
-
}
|
|
10372
|
-
}
|
|
10373
|
-
delete state.pid;
|
|
10374
|
-
delete state.startedAt;
|
|
10375
|
-
delete state.due;
|
|
10376
|
-
writeWatch(root, state);
|
|
10377
|
-
return { ok: true, message: watchStatus(root) };
|
|
10378
|
-
}
|
|
10379
|
-
if (sub === "interval") {
|
|
10380
|
-
const text = args[1];
|
|
10381
|
-
if (!text || parseInterval(text) === void 0) return { ok: false, message: "interval is at least 5m: 15m, 30m, 1h" };
|
|
10382
|
-
state.interval = text.trim();
|
|
10383
|
-
writeWatch(root, state);
|
|
10384
|
-
return { ok: true, message: watchStatus(root) };
|
|
10385
|
-
}
|
|
10386
|
-
if (sub === void 0 || sub === "status") return { ok: true, message: watchStatus(root) };
|
|
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" });
|
|
10396
|
-
}
|
|
10397
|
-
function runWatchLoop(root, sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)) {
|
|
10398
|
-
const state = readWatch(root);
|
|
10399
|
-
if (state.pid !== process.pid) return;
|
|
10400
|
-
for (; ; ) {
|
|
10401
|
-
const cur = readWatch(root);
|
|
10402
|
-
if (cur.pid !== process.pid) return;
|
|
10403
|
-
const ms = parseInterval(cur.interval) ?? parseInterval(DEFAULT_INTERVAL);
|
|
10404
|
-
sleep(ms);
|
|
10405
|
-
const after = readWatch(root);
|
|
10406
|
-
if (after.pid !== process.pid) return;
|
|
10407
|
-
after.due = (/* @__PURE__ */ new Date()).toISOString();
|
|
10408
|
-
writeWatch(root, after);
|
|
10409
|
-
const cmd = process.env.LEAD_WATCH_COMMAND;
|
|
10410
|
-
if (cmd) spawn(cmd, { cwd: root, shell: true, stdio: "ignore", detached: true }).unref();
|
|
10411
|
-
}
|
|
10412
|
-
}
|
|
10413
|
-
|
|
10414
|
-
// src/mergehold.ts
|
|
10415
|
-
import { existsSync as existsSync22, mkdirSync as mkdirSync11, readFileSync as readFileSync20, rmSync as rmSync5, writeFileSync as writeFileSync13 } from "node:fs";
|
|
10416
|
-
import { join as join24 } from "node:path";
|
|
10417
|
-
var MERGE_LOCK = ".lead/merge.json";
|
|
10418
|
-
var HOLD_MS = 15 * 60 * 1e3;
|
|
10419
|
-
function read2(root) {
|
|
10420
|
-
const p = join24(root, MERGE_LOCK);
|
|
10421
|
-
if (!existsSync22(p)) return void 0;
|
|
10422
|
-
try {
|
|
10423
|
-
return JSON.parse(readFileSync20(p, "utf8"));
|
|
10424
|
-
} catch {
|
|
10425
|
-
return void 0;
|
|
10426
|
-
}
|
|
10427
|
-
}
|
|
10428
|
-
function holdMerge(root, opts) {
|
|
10429
|
-
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
10430
|
-
const cur = read2(root);
|
|
10431
|
-
if (cur && cur.session !== opts.session && now.getTime() - Date.parse(cur.at) < HOLD_MS) {
|
|
10432
|
-
return { ok: false, message: `${cur.task} merge is held by session ${cur.session} since ${cur.at}` };
|
|
10433
|
-
}
|
|
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
|
-
}
|
|
10486
|
-
function loadActivity(root, opts = {}) {
|
|
10487
|
-
const days = opts.day ? [opts.day] : listActivityDays(root).filter((d) => !opts.since || d >= opts.since);
|
|
10488
|
-
return days.flatMap((d) => readActivityDay(root, d));
|
|
10489
|
-
}
|
|
10490
|
-
function analyzeActivity(rows) {
|
|
10491
|
-
const byEvent = {};
|
|
10492
|
-
const taskMap = /* @__PURE__ */ new Map();
|
|
10493
|
-
const waits = [];
|
|
10494
|
-
const starts = [];
|
|
10495
|
-
const ends = /* @__PURE__ */ new Set();
|
|
10496
|
-
const days = /* @__PURE__ */ new Set();
|
|
10497
|
-
for (const r of rows) {
|
|
10498
|
-
days.add(r.at.slice(0, 10));
|
|
10499
|
-
byEvent[r.event] = (byEvent[r.event] ?? 0) + 1;
|
|
10500
|
-
if (r.event === "wait") waits.push({ at: r.at, what: r.what, ...r.task ? { task: r.task } : {} });
|
|
10501
|
-
if (r.event === "start") starts.push(r);
|
|
10502
|
-
if (r.event === "end") ends.add(`${r.task ?? ""}|${r.what}`);
|
|
10503
|
-
if (r.task) {
|
|
10504
|
-
const t = taskMap.get(r.task) ?? { events: 0, starts: 0, ends: 0, checks: 0, waits: 0 };
|
|
10505
|
-
t.events++;
|
|
10506
|
-
if (r.event === "start") t.starts++;
|
|
10507
|
-
if (r.event === "end") t.ends++;
|
|
10508
|
-
if (r.event === "check") t.checks++;
|
|
10509
|
-
if (r.event === "wait") t.waits++;
|
|
10510
|
-
taskMap.set(r.task, t);
|
|
10511
|
-
}
|
|
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
|
-
};
|
|
10524
|
-
}
|
|
10525
|
-
function formatActivityReport(r) {
|
|
10526
|
-
if (!r.total) return "no activity events";
|
|
10527
|
-
const lines = [
|
|
10528
|
-
`activity: ${r.total} events across ${r.days.length} day(s) (${r.first} \u2192 ${r.last})`,
|
|
10529
|
-
"",
|
|
10530
|
-
"by event:",
|
|
10531
|
-
...Object.entries(r.byEvent).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([e, n]) => ` ${e} ${n}`)
|
|
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`);
|
|
10543
|
-
}
|
|
10544
|
-
if (r.openStarts.length) {
|
|
10545
|
-
lines.push("", `starts without a matching end (${r.openStarts.length}):`);
|
|
10546
|
-
for (const s of r.openStarts.slice(-10)) lines.push(` ${s.at} ${s.task ?? "-"} ${s.what}`);
|
|
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" });
|
|
10692
|
+
}
|
|
10547
10693
|
}
|
|
10548
|
-
return
|
|
10549
|
-
}
|
|
10550
|
-
function oneLine2(s) {
|
|
10551
|
-
return s.replace(/\s+/g, " ").trim();
|
|
10694
|
+
return matches;
|
|
10552
10695
|
}
|
|
10553
10696
|
|
|
10554
|
-
// src/
|
|
10555
|
-
import {
|
|
10697
|
+
// src/cli.ts
|
|
10698
|
+
import { basename as basename3, relative as relative14, sep as sep5 } from "node:path";
|
|
10699
|
+
|
|
10700
|
+
// src/delegate.ts
|
|
10701
|
+
import { existsSync as existsSync24, readdirSync as readdirSync13, readFileSync as readFileSync21 } from "node:fs";
|
|
10556
10702
|
import { join as join26 } from "node:path";
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
const
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
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
|
-
});
|
|
10584
|
-
}
|
|
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
|
+
};
|
|
10715
|
+
}
|
|
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);
|
|
10585
10722
|
}
|
|
10586
|
-
return
|
|
10723
|
+
return out;
|
|
10724
|
+
}
|
|
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);
|
|
10729
|
+
}
|
|
10730
|
+
if (kit) {
|
|
10731
|
+
for (const d of fromDir(join26(kit, "skills/lead/delegates"), "kit")) byId.set(d.id, d);
|
|
10732
|
+
}
|
|
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));
|
|
10735
|
+
}
|
|
10736
|
+
function delegatedTasks(tasks, id2) {
|
|
10737
|
+
return tasks.filter((t) => t.delegate && (!id2 || t.delegate === id2)).sort((a, b) => a.id.localeCompare(b.id));
|
|
10587
10738
|
}
|
|
10588
10739
|
|
|
10589
|
-
// src/
|
|
10590
|
-
|
|
10591
|
-
import { existsSync as
|
|
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";
|
|
10740
|
+
// src/watch.ts
|
|
10741
|
+
import { spawn } from "node:child_process";
|
|
10742
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync11, readFileSync as readFileSync23, writeFileSync as writeFileSync13 } from "node:fs";
|
|
10596
10743
|
import { join as join28 } from "node:path";
|
|
10597
10744
|
|
|
10598
|
-
// src/
|
|
10599
|
-
import {
|
|
10745
|
+
// src/probe.ts
|
|
10746
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
10747
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
10748
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync25, mkdirSync as mkdirSync10, readFileSync as readFileSync22, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10600
10749
|
import { join as join27 } from "node:path";
|
|
10601
|
-
var
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
if (!
|
|
10750
|
+
var PROBE_LOG = ".lead/logs/watch-probe.jsonl";
|
|
10751
|
+
var PROBE_STATE = ".lead/logs/watch-probe-state.json";
|
|
10752
|
+
var FORCED_AFTER_MS = 24 * 60 * 60 * 1e3;
|
|
10753
|
+
var GATE = { days: 7, ticks: 200, maxUnknownRatio: 0.05 };
|
|
10754
|
+
var shell = (cmd, args) => {
|
|
10755
|
+
const r = spawnSync3(cmd, args, { encoding: "utf8", timeout: 6e4, maxBuffer: 16 * 1024 * 1024 });
|
|
10756
|
+
return { ok: r.status === 0 && !r.error, stdout: r.stdout ?? "", error: r.error?.message ?? (r.status === 0 ? void 0 : (r.stderr ?? "").trim().split("\n")[0]) };
|
|
10757
|
+
};
|
|
10758
|
+
var MR_URL = /https?:\/\/([^\s/)>\]]+)\/([^\s)>\]]+?)\/-\/merge_requests\/(\d+)/g;
|
|
10759
|
+
function mrUrls(text) {
|
|
10760
|
+
return [...new Set([...text.matchAll(MR_URL)].map((m) => m[0]))].sort();
|
|
10761
|
+
}
|
|
10762
|
+
function fetchMr(url, run2) {
|
|
10763
|
+
const m = new RegExp(MR_URL.source).exec(url);
|
|
10764
|
+
if (!m) return { url, unavailable: "not a merge request address" };
|
|
10765
|
+
const r = run2("glab", ["api", "--hostname", m[1], `projects/${encodeURIComponent(m[2])}/merge_requests/${m[3]}`]);
|
|
10766
|
+
if (!r.ok) return { url, unavailable: `glab: ${r.error ?? "failed"}` };
|
|
10616
10767
|
try {
|
|
10617
|
-
const
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10768
|
+
const d = JSON.parse(r.stdout);
|
|
10769
|
+
const pipe = d.head_pipeline ?? d.pipeline;
|
|
10770
|
+
return {
|
|
10771
|
+
url,
|
|
10772
|
+
state: String(d.state ?? ""),
|
|
10773
|
+
sha: String(d.sha ?? ""),
|
|
10774
|
+
pipeline: String(pipe?.status ?? "none"),
|
|
10775
|
+
mergeStatus: String(d.detailed_merge_status ?? d.merge_status ?? ""),
|
|
10776
|
+
conflicts: d.has_conflicts === true,
|
|
10777
|
+
discussionsResolved: d.blocking_discussions_resolved !== false,
|
|
10778
|
+
notes: Number(d.user_notes_count ?? 0)
|
|
10779
|
+
};
|
|
10780
|
+
} catch {
|
|
10781
|
+
return { url, unavailable: "glab: unreadable answer" };
|
|
10624
10782
|
}
|
|
10625
10783
|
}
|
|
10626
|
-
function
|
|
10627
|
-
|
|
10628
|
-
if (
|
|
10629
|
-
|
|
10630
|
-
return {
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
}));
|
|
10784
|
+
function fetchJira(key, run2, command = process.env.LEAD_WATCH_JIRA_COMMAND) {
|
|
10785
|
+
if (!command) return { unavailable: "LEAD_WATCH_JIRA_COMMAND is not set" };
|
|
10786
|
+
if (!/^[A-Z][A-Z0-9]*-\d+$/.test(key)) return { unavailable: `"${key}" is not an issue key` };
|
|
10787
|
+
const r = run2("sh", ["-c", `${command} "$1"`, "sh", key]);
|
|
10788
|
+
if (!r.ok) return { unavailable: `tracker command: ${r.error ?? "failed"}` };
|
|
10789
|
+
try {
|
|
10790
|
+
const d = JSON.parse(r.stdout);
|
|
10791
|
+
if (typeof d.status !== "string" || !d.status) return { unavailable: "tracker command: no status in the answer" };
|
|
10792
|
+
return { status: d.status, ...typeof d.updated === "string" ? { updated: d.updated } : {}, ...typeof d.comments === "number" ? { comments: d.comments } : {} };
|
|
10793
|
+
} catch {
|
|
10794
|
+
return { unavailable: "tracker command: unreadable answer" };
|
|
10795
|
+
}
|
|
10639
10796
|
}
|
|
10640
|
-
function
|
|
10641
|
-
|
|
10797
|
+
function collectFacts(root, run2 = shell, jiraCommand) {
|
|
10798
|
+
const ctx = loadContext(root);
|
|
10799
|
+
return delegatedTasks(ctx.tasks).filter((t) => t.status !== "done").map((t) => {
|
|
10800
|
+
const text = existsSync25(join27(root, t.file)) ? readFileSync22(join27(root, t.file), "utf8") : "";
|
|
10801
|
+
return {
|
|
10802
|
+
task: t.id,
|
|
10803
|
+
...t.delegate_ref ? { ref: t.delegate_ref } : {},
|
|
10804
|
+
...t.delegate_ref ? { jira: fetchJira(t.delegate_ref, run2, jiraCommand ?? process.env.LEAD_WATCH_JIRA_COMMAND) } : {},
|
|
10805
|
+
mrs: mrUrls(text).map((u) => fetchMr(u, run2))
|
|
10806
|
+
};
|
|
10807
|
+
});
|
|
10642
10808
|
}
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
const
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
|
|
10809
|
+
var canon = (v) => Array.isArray(v) ? v.map(canon) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a.localeCompare(b)).map(([k, x]) => [k, canon(x)])) : v;
|
|
10810
|
+
var fingerprint = (f) => createHash8("sha256").update(JSON.stringify(canon(f))).digest("hex").slice(0, 16);
|
|
10811
|
+
var unavailable = (x) => !!x && typeof x === "object" && "unavailable" in x;
|
|
10812
|
+
function classify(f, st, state, now) {
|
|
10813
|
+
const fp = fingerprint(f);
|
|
10814
|
+
const reasons = [];
|
|
10815
|
+
const bad = [f.jira, ...f.mrs].filter(unavailable);
|
|
10816
|
+
const base = { task: f.task, fingerprint: fp };
|
|
10817
|
+
if (bad.length) return { ...base, class: "unknown", needsAi: true, reasons: bad.map((b) => b.unavailable) };
|
|
10818
|
+
if (!st?.handled) return { ...base, class: "new", needsAi: true, reasons: ["no acknowledged check yet"] };
|
|
10819
|
+
const stale = !state.lastAck || now.getTime() - new Date(state.lastAck).getTime() > FORCED_AFTER_MS;
|
|
10820
|
+
if (st.handled === fp) return stale ? { ...base, class: "forced", needsAi: true, reasons: ["full check due: none acknowledged for 24 hours"] } : { ...base, class: "quiet", needsAi: false, reasons: [] };
|
|
10821
|
+
const mrs = f.mrs.filter((m) => !unavailable(m));
|
|
10822
|
+
const status2 = unavailable(f.jira) ? "" : f.jira?.status ?? "";
|
|
10823
|
+
let cls = "changed";
|
|
10824
|
+
if (mrs.some((m) => m.conflicts)) cls = "conflict", reasons.push("a merge request has conflicts");
|
|
10825
|
+
else if (mrs.some((m) => m.pipeline === "failed")) cls = "ci_failed", reasons.push("a pipeline failed");
|
|
10826
|
+
else if (/human review/i.test(status2)) cls = "review", reasons.push(`status ${status2}`);
|
|
10827
|
+
else if (/blocked/i.test(status2)) cls = "blocked", reasons.push(`status ${status2}`);
|
|
10828
|
+
else if (/dev check/i.test(status2)) cls = "dev_check", reasons.push(`status ${status2}`);
|
|
10829
|
+
else if (/clarification/i.test(status2)) cls = "clarification", reasons.push(`status ${status2}`);
|
|
10830
|
+
else if (/ready for qa/i.test(status2)) cls = "qa", reasons.push(`status ${status2}`);
|
|
10831
|
+
else if (/^done$/i.test(status2)) cls = "done", reasons.push(`status ${status2}`);
|
|
10832
|
+
else reasons.push("facts changed since the last acknowledged check");
|
|
10833
|
+
return { ...base, class: cls, needsAi: true, reasons };
|
|
10834
|
+
}
|
|
10835
|
+
function readState(root) {
|
|
10836
|
+
try {
|
|
10837
|
+
const d = JSON.parse(readFileSync22(join27(root, PROBE_STATE), "utf8"));
|
|
10838
|
+
return { tasks: d.tasks ?? {}, ...d.lastAck ? { lastAck: d.lastAck } : {} };
|
|
10839
|
+
} catch {
|
|
10840
|
+
return { tasks: {} };
|
|
10655
10841
|
}
|
|
10656
|
-
return log.length ? log : ["waves are up to date"];
|
|
10657
10842
|
}
|
|
10658
|
-
|
|
10659
|
-
|
|
10660
|
-
|
|
10661
|
-
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
10668
|
-
|
|
10669
|
-
|
|
10670
|
-
|
|
10671
|
-
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
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");
|
|
10843
|
+
var writeState = (root, s) => {
|
|
10844
|
+
mkdirSync10(join27(root, ".lead/logs"), { recursive: true });
|
|
10845
|
+
writeFileSync12(join27(root, PROBE_STATE), `${JSON.stringify(s, null, 2)}
|
|
10846
|
+
`);
|
|
10847
|
+
};
|
|
10848
|
+
var log = (root, record) => {
|
|
10849
|
+
mkdirSync10(join27(root, ".lead/logs"), { recursive: true });
|
|
10850
|
+
appendFileSync2(join27(root, PROBE_LOG), `${JSON.stringify(record)}
|
|
10851
|
+
`);
|
|
10852
|
+
};
|
|
10853
|
+
function runProbe(root, opts = {}) {
|
|
10854
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
10855
|
+
const state = readState(root);
|
|
10856
|
+
const facts = collectFacts(root, opts.run ?? shell, opts.jiraCommand);
|
|
10857
|
+
const verdicts = facts.map((f) => classify(f, state.tasks[f.task], state, now));
|
|
10858
|
+
const result = { at: now.toISOString(), verdicts, wouldWake: verdicts.some((v) => v.needsAi) };
|
|
10859
|
+
if (opts.record !== false) {
|
|
10860
|
+
for (const v of verdicts) state.tasks[v.task] = { ...state.tasks[v.task], seen: v.fingerprint };
|
|
10861
|
+
writeState(root, state);
|
|
10862
|
+
log(root, { event: "probe", at: result.at, wouldWake: result.wouldWake, tasks: verdicts.map((v) => ({ task: v.task, class: v.class, fp: v.fingerprint })) });
|
|
10679
10863
|
}
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
const
|
|
10684
|
-
const
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10864
|
+
return result;
|
|
10865
|
+
}
|
|
10866
|
+
function recordAck(root, acted, now = /* @__PURE__ */ new Date()) {
|
|
10867
|
+
const state = readState(root);
|
|
10868
|
+
for (const t of Object.values(state.tasks)) if (t.seen) t.handled = t.seen;
|
|
10869
|
+
state.lastAck = now.toISOString();
|
|
10870
|
+
writeState(root, state);
|
|
10871
|
+
log(root, { event: "ack", at: now.toISOString(), acted });
|
|
10872
|
+
}
|
|
10873
|
+
function report(root) {
|
|
10874
|
+
const lines = existsSync25(join27(root, PROBE_LOG)) ? readFileSync22(join27(root, PROBE_LOG), "utf8").split("\n").filter(Boolean) : [];
|
|
10875
|
+
const events = lines.flatMap((l) => {
|
|
10876
|
+
try {
|
|
10877
|
+
return [JSON.parse(l)];
|
|
10878
|
+
} catch {
|
|
10879
|
+
return [];
|
|
10693
10880
|
}
|
|
10694
|
-
|
|
10695
|
-
|
|
10881
|
+
});
|
|
10882
|
+
const r = { ticks: 0, acked: 0, quiet: 0, wake: 0, unknown: 0, unreported: 0, misses: 0, falseWakes: 0, spanDays: 0, ready: false, blockers: [] };
|
|
10883
|
+
let last;
|
|
10884
|
+
for (const e of events) {
|
|
10885
|
+
if (e.event === "probe") {
|
|
10886
|
+
r.ticks++;
|
|
10887
|
+
r.firstAt ??= e.at;
|
|
10888
|
+
r.lastAt = e.at;
|
|
10889
|
+
if (e.wouldWake) r.wake++;
|
|
10890
|
+
else r.quiet++;
|
|
10891
|
+
if (e.tasks?.some((t) => t.class === "unknown")) r.unknown++;
|
|
10892
|
+
last = e;
|
|
10893
|
+
} else if (e.event === "ack" && last) {
|
|
10894
|
+
r.acked++;
|
|
10895
|
+
if (e.acted === null || e.acted === void 0) r.unreported++;
|
|
10896
|
+
if (!last.wouldWake && e.acted === true) r.misses++;
|
|
10897
|
+
if (last.wouldWake && e.acted === false) r.falseWakes++;
|
|
10898
|
+
last = void 0;
|
|
10899
|
+
}
|
|
10900
|
+
}
|
|
10901
|
+
r.spanDays = r.firstAt && r.lastAt ? (new Date(r.lastAt).getTime() - new Date(r.firstAt).getTime()) / 864e5 : 0;
|
|
10902
|
+
if (r.spanDays < GATE.days) r.blockers.push(`shadow run is ${r.spanDays.toFixed(1)} days, needs ${GATE.days}`);
|
|
10903
|
+
if (r.ticks < GATE.ticks) r.blockers.push(`${r.ticks} ticks, needs ${GATE.ticks}`);
|
|
10904
|
+
if (r.misses > 0) r.blockers.push(`${r.misses} tick(s) the probe called quiet but an agent acted on`);
|
|
10905
|
+
if (r.acked && r.unreported / r.acked > 0.1) r.blockers.push(`${r.unreported} of ${r.acked} acknowledgements did not say whether the agent acted (use --acted or --idle)`);
|
|
10906
|
+
if (r.ticks && r.unknown / r.ticks > GATE.maxUnknownRatio) r.blockers.push(`${r.unknown} of ${r.ticks} ticks had a source the probe could not read (limit ${GATE.maxUnknownRatio * 100}%)`);
|
|
10907
|
+
r.ready = r.blockers.length === 0;
|
|
10908
|
+
return r;
|
|
10909
|
+
}
|
|
10910
|
+
function renderVerdicts(r) {
|
|
10911
|
+
if (!r.verdicts.length) return ["no delegated tasks to probe"];
|
|
10912
|
+
return [`${r.wouldWake ? "an agent would be woken" : "quiet: no agent needed"} (${r.at})`, ...r.verdicts.map((v) => ` ${v.task} ${v.class}${v.reasons.length ? ` \u2014 ${v.reasons.join("; ")}` : ""}`)];
|
|
10913
|
+
}
|
|
10914
|
+
function renderReport(r) {
|
|
10915
|
+
return [
|
|
10916
|
+
`ticks ${r.ticks} (acknowledged ${r.acked}, without a note ${r.unreported}): quiet ${r.quiet}, would wake ${r.wake}, unreadable source ${r.unknown}`,
|
|
10917
|
+
`misses ${r.misses} (probe quiet, agent acted), unnecessary wakes ${r.falseWakes}`,
|
|
10918
|
+
`span ${r.spanDays.toFixed(1)} days${r.firstAt ? ` (${r.firstAt} \u2026 ${r.lastAt})` : ""}`,
|
|
10919
|
+
r.ready ? "ready: the probe agreed with every acknowledged check" : `not ready: ${r.blockers.join("; ")}`
|
|
10920
|
+
];
|
|
10921
|
+
}
|
|
10922
|
+
|
|
10923
|
+
// src/watch.ts
|
|
10924
|
+
var WATCH_PATH = ".lead/watch.json";
|
|
10925
|
+
var MIN_INTERVAL_MS = 5 * 60 * 1e3;
|
|
10926
|
+
var DEFAULT_INTERVAL = "15m";
|
|
10927
|
+
function parseInterval(text) {
|
|
10928
|
+
const m = /^(\d+)\s*(m|min|h)$/i.exec(text.trim());
|
|
10929
|
+
if (!m) return void 0;
|
|
10930
|
+
const n = Number(m[1]);
|
|
10931
|
+
const ms = m[2].toLowerCase().startsWith("h") ? n * 60 * 60 * 1e3 : n * 60 * 1e3;
|
|
10932
|
+
if (!Number.isFinite(ms) || ms < MIN_INTERVAL_MS) return void 0;
|
|
10933
|
+
return ms;
|
|
10934
|
+
}
|
|
10935
|
+
function readWatch(root) {
|
|
10936
|
+
const p = join28(root, WATCH_PATH);
|
|
10937
|
+
if (!existsSync26(p)) return { interval: DEFAULT_INTERVAL, close: false };
|
|
10938
|
+
try {
|
|
10939
|
+
const d = JSON.parse(readFileSync23(p, "utf8"));
|
|
10940
|
+
return { interval: typeof d.interval === "string" ? d.interval : DEFAULT_INTERVAL, close: d.close === true, pid: d.pid, startedAt: d.startedAt, due: d.due, ...d.probe === "shadow" ? { probe: "shadow" } : {} };
|
|
10941
|
+
} catch {
|
|
10942
|
+
return { interval: DEFAULT_INTERVAL, close: false };
|
|
10696
10943
|
}
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10944
|
+
}
|
|
10945
|
+
function writeWatch(root, state) {
|
|
10946
|
+
mkdirSync11(join28(root, ".lead"), { recursive: true });
|
|
10947
|
+
writeFileSync13(join28(root, WATCH_PATH), `${JSON.stringify(state, null, 2)}
|
|
10948
|
+
`);
|
|
10949
|
+
}
|
|
10950
|
+
function alive(pid) {
|
|
10951
|
+
if (!pid || pid <= 1) return false;
|
|
10952
|
+
try {
|
|
10953
|
+
process.kill(pid, 0);
|
|
10954
|
+
return true;
|
|
10955
|
+
} catch {
|
|
10956
|
+
return false;
|
|
10705
10957
|
}
|
|
10706
|
-
return out;
|
|
10707
10958
|
}
|
|
10708
|
-
function
|
|
10709
|
-
const
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
|
|
10714
|
-
|
|
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
|
-
}));
|
|
10959
|
+
function watchStatus(root) {
|
|
10960
|
+
const s = readWatch(root);
|
|
10961
|
+
const on = alive(s.pid);
|
|
10962
|
+
const bits = [`watch ${on ? "on" : "off"}`, `every ${s.interval}`, s.close ? "may close a finished milestone" : "asks before closing a milestone"];
|
|
10963
|
+
if (s.probe) bits.push(`probe ${s.probe}`);
|
|
10964
|
+
if (s.due) bits.push(`check due since ${s.due}`);
|
|
10965
|
+
return bits.join(", ");
|
|
10719
10966
|
}
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
if (
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
if (!existsSync26(abs)) {
|
|
10738
|
-
issues.push({ level: "warning", file: dir, message: "no initiative.md" });
|
|
10739
|
-
continue;
|
|
10740
|
-
}
|
|
10741
|
-
const { parsed, issues: parseIssues } = parseFrontmatter(readFileSync23(abs, "utf8"), file);
|
|
10742
|
-
issues.push(...parseIssues);
|
|
10743
|
-
if (!parsed) continue;
|
|
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) } : {} });
|
|
10967
|
+
function watchCommand(root, args, opts) {
|
|
10968
|
+
const sub = args[0];
|
|
10969
|
+
const state = readWatch(root);
|
|
10970
|
+
if (sub === "start") {
|
|
10971
|
+
if (alive(state.pid)) return { ok: true, message: watchStatus(root) };
|
|
10972
|
+
state.close = opts.close === true;
|
|
10973
|
+
state.startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10974
|
+
state.pid = opts.spawnLoop?.(root) ?? 0;
|
|
10975
|
+
writeWatch(root, state);
|
|
10976
|
+
return { ok: true, message: watchStatus(root) };
|
|
10977
|
+
}
|
|
10978
|
+
if (sub === "stop") {
|
|
10979
|
+
if (alive(state.pid)) {
|
|
10980
|
+
try {
|
|
10981
|
+
process.kill(state.pid, "SIGTERM");
|
|
10982
|
+
} catch {
|
|
10983
|
+
}
|
|
10757
10984
|
}
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10985
|
+
delete state.pid;
|
|
10986
|
+
delete state.startedAt;
|
|
10987
|
+
delete state.due;
|
|
10988
|
+
writeWatch(root, state);
|
|
10989
|
+
return { ok: true, message: watchStatus(root) };
|
|
10990
|
+
}
|
|
10991
|
+
if (sub === "interval") {
|
|
10992
|
+
const text = args[1];
|
|
10993
|
+
if (!text || parseInterval(text) === void 0) return { ok: false, message: "interval is at least 5m: 15m, 30m, 1h" };
|
|
10994
|
+
state.interval = text.trim();
|
|
10995
|
+
writeWatch(root, state);
|
|
10996
|
+
return { ok: true, message: watchStatus(root) };
|
|
10997
|
+
}
|
|
10998
|
+
if (sub === void 0 || sub === "status") return { ok: true, message: watchStatus(root) };
|
|
10999
|
+
return { ok: false, message: "usage: watch [start|stop|interval 15m|status]" };
|
|
11000
|
+
}
|
|
11001
|
+
function clearDue(root) {
|
|
11002
|
+
const state = readWatch(root);
|
|
11003
|
+
delete state.due;
|
|
11004
|
+
writeWatch(root, state);
|
|
11005
|
+
}
|
|
11006
|
+
function spawnWatchLoop(leadMjs, root) {
|
|
11007
|
+
return spawn(process.execPath, [leadMjs, "watch", "loop", "--cwd", root], { detached: true, stdio: "ignore" });
|
|
11008
|
+
}
|
|
11009
|
+
function runWatchLoop(root, sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)) {
|
|
11010
|
+
const state = readWatch(root);
|
|
11011
|
+
if (state.pid !== process.pid) return;
|
|
11012
|
+
for (; ; ) {
|
|
11013
|
+
const cur = readWatch(root);
|
|
11014
|
+
if (cur.pid !== process.pid) return;
|
|
11015
|
+
const ms = parseInterval(cur.interval) ?? parseInterval(DEFAULT_INTERVAL);
|
|
11016
|
+
sleep(ms);
|
|
11017
|
+
const after = readWatch(root);
|
|
11018
|
+
if (after.pid !== process.pid) return;
|
|
11019
|
+
if (after.probe === "shadow") {
|
|
11020
|
+
try {
|
|
11021
|
+
runProbe(root);
|
|
11022
|
+
} catch {
|
|
11023
|
+
}
|
|
10770
11024
|
}
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
site: str(d.site),
|
|
10776
|
-
flag: str(d.flag),
|
|
10777
|
-
adapter: str(d.adapter),
|
|
10778
|
-
repos,
|
|
10779
|
-
map,
|
|
10780
|
-
dir,
|
|
10781
|
-
file
|
|
10782
|
-
});
|
|
11025
|
+
after.due = (/* @__PURE__ */ new Date()).toISOString();
|
|
11026
|
+
writeWatch(root, after);
|
|
11027
|
+
const cmd = process.env.LEAD_WATCH_COMMAND;
|
|
11028
|
+
if (cmd) spawn(cmd, { cwd: root, shell: true, stdio: "ignore", detached: true }).unref();
|
|
10783
11029
|
}
|
|
10784
|
-
return { initiatives, issues };
|
|
10785
11030
|
}
|
|
10786
|
-
|
|
11031
|
+
|
|
11032
|
+
// src/mergehold.ts
|
|
11033
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync12, readFileSync as readFileSync24, rmSync as rmSync5, writeFileSync as writeFileSync14 } from "node:fs";
|
|
11034
|
+
import { join as join29 } from "node:path";
|
|
11035
|
+
var MERGE_LOCK = ".lead/merge.json";
|
|
11036
|
+
var HOLD_MS = 15 * 60 * 1e3;
|
|
11037
|
+
function read2(root) {
|
|
11038
|
+
const p = join29(root, MERGE_LOCK);
|
|
11039
|
+
if (!existsSync27(p)) return void 0;
|
|
10787
11040
|
try {
|
|
10788
|
-
return
|
|
11041
|
+
return JSON.parse(readFileSync24(p, "utf8"));
|
|
10789
11042
|
} catch {
|
|
10790
11043
|
return void 0;
|
|
10791
11044
|
}
|
|
10792
11045
|
}
|
|
10793
|
-
function
|
|
10794
|
-
const
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
const by = /* @__PURE__ */ new Map();
|
|
10799
|
-
for (const x of Object.values(issues)) {
|
|
10800
|
-
const m = x.milestone ?? "?";
|
|
10801
|
-
const row = by.get(m) ?? { milestone: m, total: 0, states: {} };
|
|
10802
|
-
row.total++;
|
|
10803
|
-
row.states[x.observed ?? "other"] = (row.states[x.observed ?? "other"] ?? 0) + 1;
|
|
10804
|
-
by.set(m, row);
|
|
10805
|
-
}
|
|
10806
|
-
return [...by.values()];
|
|
10807
|
-
} catch {
|
|
10808
|
-
return [];
|
|
11046
|
+
function holdMerge(root, opts) {
|
|
11047
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
11048
|
+
const cur = read2(root);
|
|
11049
|
+
if (cur && cur.session !== opts.session && now.getTime() - Date.parse(cur.at) < HOLD_MS) {
|
|
11050
|
+
return { ok: false, message: `${cur.task} merge is held by session ${cur.session} since ${cur.at}` };
|
|
10809
11051
|
}
|
|
11052
|
+
mkdirSync12(join29(root, ".lead"), { recursive: true });
|
|
11053
|
+
const lock = { task: opts.task, session: opts.session, mr: opts.mr, at: now.toISOString() };
|
|
11054
|
+
writeFileSync14(join29(root, MERGE_LOCK), `${JSON.stringify(lock, null, 2)}
|
|
11055
|
+
`);
|
|
11056
|
+
return { ok: true, message: `merge ${opts.mr} held for ${opts.task}` };
|
|
10810
11057
|
}
|
|
10811
|
-
function
|
|
10812
|
-
const
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
11058
|
+
function releaseMerge(root, opts) {
|
|
11059
|
+
const cur = read2(root);
|
|
11060
|
+
if (!cur) return { ok: true, message: "no merge hold" };
|
|
11061
|
+
if (cur.task !== opts.task) return { ok: false, message: `merge hold is for ${cur.task}, not ${opts.task}` };
|
|
11062
|
+
if (cur.session !== opts.session) return { ok: false, message: `merge hold belongs to session ${cur.session}` };
|
|
11063
|
+
rmSync5(join29(root, MERGE_LOCK), { force: true });
|
|
11064
|
+
return { ok: true, message: `merge hold for ${opts.task} released` };
|
|
11065
|
+
}
|
|
11066
|
+
|
|
11067
|
+
// src/activity.ts
|
|
11068
|
+
import { appendFileSync as appendFileSync3, existsSync as existsSync28, mkdirSync as mkdirSync13, readdirSync as readdirSync14, readFileSync as readFileSync25 } from "node:fs";
|
|
11069
|
+
import { join as join30 } from "node:path";
|
|
11070
|
+
var ACTIVITY_DIR = ".lead/activity";
|
|
11071
|
+
var EVENTS = ["start", "end", "check", "status", "note", "wait", "merge"];
|
|
11072
|
+
function isEvent(v) {
|
|
11073
|
+
return EVENTS.includes(v);
|
|
11074
|
+
}
|
|
11075
|
+
function appendActivity(root, entry) {
|
|
11076
|
+
const at = entry.at ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
11077
|
+
const row = {
|
|
11078
|
+
at,
|
|
11079
|
+
event: entry.event,
|
|
11080
|
+
what: oneLine2(entry.what),
|
|
11081
|
+
...entry.where ? { where: oneLine2(entry.where) } : {},
|
|
11082
|
+
...entry.task ? { task: oneLine2(entry.task) } : {},
|
|
11083
|
+
...entry.project ? { project: oneLine2(entry.project) } : {},
|
|
11084
|
+
...entry.session ? { session: oneLine2(entry.session) } : {},
|
|
11085
|
+
...entry.goal ? { goal: oneLine2(entry.goal) } : {}
|
|
10832
11086
|
};
|
|
11087
|
+
const rel = join30(ACTIVITY_DIR, `${at.slice(0, 10)}.jsonl`);
|
|
11088
|
+
const abs = join30(root, rel);
|
|
11089
|
+
mkdirSync13(join30(root, ACTIVITY_DIR), { recursive: true });
|
|
11090
|
+
appendFileSync3(abs, `${JSON.stringify(row)}
|
|
11091
|
+
`);
|
|
11092
|
+
return rel;
|
|
10833
11093
|
}
|
|
10834
|
-
function
|
|
10835
|
-
const
|
|
10836
|
-
if (!
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
11094
|
+
function readActivityDay(root, day) {
|
|
11095
|
+
const p = join30(root, ACTIVITY_DIR, `${day}.jsonl`);
|
|
11096
|
+
if (!existsSync28(p)) return [];
|
|
11097
|
+
return readFileSync25(p, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
11098
|
+
}
|
|
11099
|
+
function listActivityDays(root) {
|
|
11100
|
+
const dir = join30(root, ACTIVITY_DIR);
|
|
11101
|
+
if (!existsSync28(dir)) return [];
|
|
11102
|
+
return readdirSync14(dir).filter((n) => /^\d{4}-\d{2}-\d{2}\.jsonl$/.test(n)).map((n) => n.replace(/\.jsonl$/, "")).sort();
|
|
11103
|
+
}
|
|
11104
|
+
function loadActivity(root, opts = {}) {
|
|
11105
|
+
const days = opts.day ? [opts.day] : listActivityDays(root).filter((d) => !opts.since || d >= opts.since);
|
|
11106
|
+
return days.flatMap((d) => readActivityDay(root, d));
|
|
11107
|
+
}
|
|
11108
|
+
function analyzeActivity(rows) {
|
|
11109
|
+
const byEvent = {};
|
|
11110
|
+
const taskMap = /* @__PURE__ */ new Map();
|
|
11111
|
+
const waits = [];
|
|
11112
|
+
const starts = [];
|
|
11113
|
+
const ends = /* @__PURE__ */ new Set();
|
|
11114
|
+
const days = /* @__PURE__ */ new Set();
|
|
11115
|
+
for (const r of rows) {
|
|
11116
|
+
days.add(r.at.slice(0, 10));
|
|
11117
|
+
byEvent[r.event] = (byEvent[r.event] ?? 0) + 1;
|
|
11118
|
+
if (r.event === "wait") waits.push({ at: r.at, what: r.what, ...r.task ? { task: r.task } : {} });
|
|
11119
|
+
if (r.event === "start") starts.push(r);
|
|
11120
|
+
if (r.event === "end") ends.add(`${r.task ?? ""}|${r.what}`);
|
|
11121
|
+
if (r.task) {
|
|
11122
|
+
const t = taskMap.get(r.task) ?? { events: 0, starts: 0, ends: 0, checks: 0, waits: 0 };
|
|
11123
|
+
t.events++;
|
|
11124
|
+
if (r.event === "start") t.starts++;
|
|
11125
|
+
if (r.event === "end") t.ends++;
|
|
11126
|
+
if (r.event === "check") t.checks++;
|
|
11127
|
+
if (r.event === "wait") t.waits++;
|
|
11128
|
+
taskMap.set(r.task, t);
|
|
11129
|
+
}
|
|
10842
11130
|
}
|
|
11131
|
+
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 } : {} }));
|
|
11132
|
+
return {
|
|
11133
|
+
days: [...days].sort(),
|
|
11134
|
+
total: rows.length,
|
|
11135
|
+
byEvent,
|
|
11136
|
+
byTask: [...taskMap.entries()].map(([task, v]) => ({ task, ...v })).sort((a, b) => b.events - a.events || a.task.localeCompare(b.task)),
|
|
11137
|
+
waits,
|
|
11138
|
+
openStarts,
|
|
11139
|
+
first: rows[0]?.at,
|
|
11140
|
+
last: rows[rows.length - 1]?.at
|
|
11141
|
+
};
|
|
10843
11142
|
}
|
|
10844
|
-
function
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10854
|
-
|
|
11143
|
+
function formatActivityReport(r) {
|
|
11144
|
+
if (!r.total) return "no activity events";
|
|
11145
|
+
const lines = [
|
|
11146
|
+
`activity: ${r.total} events across ${r.days.length} day(s) (${r.first} \u2192 ${r.last})`,
|
|
11147
|
+
"",
|
|
11148
|
+
"by event:",
|
|
11149
|
+
...Object.entries(r.byEvent).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([e, n]) => ` ${e} ${n}`)
|
|
11150
|
+
];
|
|
11151
|
+
if (r.byTask.length) {
|
|
11152
|
+
lines.push("", "by task:");
|
|
11153
|
+
for (const t of r.byTask) {
|
|
11154
|
+
lines.push(` ${t.task} ${t.events} events (start ${t.starts}, end ${t.ends}, check ${t.checks}, wait ${t.waits})`);
|
|
11155
|
+
}
|
|
10855
11156
|
}
|
|
10856
|
-
|
|
11157
|
+
if (r.waits.length) {
|
|
11158
|
+
lines.push("", `waits (${r.waits.length}):`);
|
|
11159
|
+
for (const w of r.waits.slice(-20)) lines.push(` ${w.at} ${w.task ?? "-"} ${w.what}`);
|
|
11160
|
+
if (r.waits.length > 20) lines.push(` \u2026 ${r.waits.length - 20} earlier`);
|
|
11161
|
+
}
|
|
11162
|
+
if (r.openStarts.length) {
|
|
11163
|
+
lines.push("", `starts without a matching end (${r.openStarts.length}):`);
|
|
11164
|
+
for (const s of r.openStarts.slice(-10)) lines.push(` ${s.at} ${s.task ?? "-"} ${s.what}`);
|
|
11165
|
+
}
|
|
11166
|
+
return lines.join("\n");
|
|
11167
|
+
}
|
|
11168
|
+
function oneLine2(s) {
|
|
11169
|
+
return s.replace(/\s+/g, " ").trim();
|
|
10857
11170
|
}
|
|
10858
11171
|
|
|
10859
11172
|
// src/adopt.ts
|
|
11173
|
+
var import_yaml4 = __toESM(require_dist(), 1);
|
|
11174
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync14, readFileSync as readFileSync26, writeFileSync as writeFileSync15 } from "node:fs";
|
|
11175
|
+
import { dirname as dirname5, join as join31 } from "node:path";
|
|
10860
11176
|
var REPO = /^[a-z][a-z0-9-]*$/;
|
|
10861
11177
|
var keyNum = (key) => Number(/-(\d+)$/.exec(key)?.[1] ?? 0);
|
|
10862
11178
|
function validateInventory(raw) {
|
|
@@ -10942,9 +11258,9 @@ function propose(inv, o) {
|
|
|
10942
11258
|
const lastStage = [...segments].reverse().find((x) => x.qa)?.qa?.n;
|
|
10943
11259
|
let boundary;
|
|
10944
11260
|
for (const sg of segments) {
|
|
10945
|
-
const [
|
|
11261
|
+
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
11262
|
const m = {
|
|
10947
|
-
id: `${prefix}${
|
|
11263
|
+
id: `${prefix}${id2}`,
|
|
10948
11264
|
title: scoped2 ? `${story.key} ${title}` : title,
|
|
10949
11265
|
shows: sg.qa ? subs.find((x) => x.key === sg.qa.key).summary.replace(/^.*?:\s*/, "") : "",
|
|
10950
11266
|
issues: []
|
|
@@ -10972,8 +11288,8 @@ function propose(inv, o) {
|
|
|
10972
11288
|
}
|
|
10973
11289
|
const outside = subs.filter((s) => !planned.includes(s));
|
|
10974
11290
|
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) });
|
|
11291
|
+
const id2 = `${prefix}outside-plan`;
|
|
11292
|
+
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
11293
|
for (const s of outside) {
|
|
10978
11294
|
const t = parseTitle(s.summary);
|
|
10979
11295
|
if (kindOf(s.summary) === "work" && !t.repos.length) unmapped.push({ key: s.key, reason: `repository: ${t.reason}` });
|
|
@@ -10985,7 +11301,7 @@ function propose(inv, o) {
|
|
|
10985
11301
|
kind: kindOf(s.summary),
|
|
10986
11302
|
...t.repos[0] ? { repo: t.repos[0] } : {},
|
|
10987
11303
|
...t.repos.length > 1 ? { also: t.repos.slice(1) } : {},
|
|
10988
|
-
milestone:
|
|
11304
|
+
milestone: id2,
|
|
10989
11305
|
observeOnly: true
|
|
10990
11306
|
};
|
|
10991
11307
|
}
|
|
@@ -11151,54 +11467,54 @@ function syncText(p) {
|
|
|
11151
11467
|
`;
|
|
11152
11468
|
}
|
|
11153
11469
|
function writeProposal(root, p, force = false) {
|
|
11154
|
-
const
|
|
11470
|
+
const log2 = [];
|
|
11155
11471
|
const put = (rel, text, regenerate) => {
|
|
11156
|
-
const abs =
|
|
11157
|
-
if (
|
|
11158
|
-
const prev =
|
|
11159
|
-
if (prev === text) return void
|
|
11160
|
-
if (!regenerate && !force) return void
|
|
11161
|
-
}
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11472
|
+
const abs = join31(root, rel);
|
|
11473
|
+
if (existsSync29(abs)) {
|
|
11474
|
+
const prev = readFileSync26(abs, "utf8");
|
|
11475
|
+
if (prev === text) return void log2.push(`unchanged ${rel}`);
|
|
11476
|
+
if (!regenerate && !force) return void log2.push(`kept ${rel}: it already exists and differs; --force replaces it`);
|
|
11477
|
+
}
|
|
11478
|
+
mkdirSync14(dirname5(abs), { recursive: true });
|
|
11479
|
+
writeFileSync15(abs, text);
|
|
11480
|
+
log2.push(`wrote ${rel}`);
|
|
11165
11481
|
};
|
|
11166
11482
|
const dir = `${INITIATIVES_DIR}/${p.id}`;
|
|
11167
11483
|
put(`${dir}/initiative.md`, initiativeText(p), false);
|
|
11168
11484
|
put(`${dir}/one-pager.md`, onePagerText(p), false);
|
|
11169
11485
|
put(`.lead/adapters/${p.id}/SKILL.md`, adapterText(p), false);
|
|
11170
11486
|
put(`${dir}/sync.json`, syncText(p), true);
|
|
11171
|
-
return
|
|
11487
|
+
return log2;
|
|
11172
11488
|
}
|
|
11173
11489
|
|
|
11174
11490
|
// src/score.ts
|
|
11175
|
-
import { existsSync as
|
|
11176
|
-
import { join as
|
|
11491
|
+
import { existsSync as existsSync30, readdirSync as readdirSync15, readFileSync as readFileSync27 } from "node:fs";
|
|
11492
|
+
import { join as join32, relative as relative13 } from "node:path";
|
|
11177
11493
|
function rubrics(root, kit) {
|
|
11178
11494
|
const dirs = [
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11495
|
+
join32(kit, "skills/lead/scorers"),
|
|
11496
|
+
join32(root, ".claude/skills/lead/scorers"),
|
|
11497
|
+
join32(root, ".agents/skills/lead/scorers"),
|
|
11498
|
+
join32(root, ".lead/local/scorers")
|
|
11183
11499
|
];
|
|
11184
11500
|
const all = /* @__PURE__ */ new Map();
|
|
11185
|
-
for (const dir of dirs.filter(
|
|
11186
|
-
for (const name of
|
|
11187
|
-
const file =
|
|
11188
|
-
if (
|
|
11501
|
+
for (const dir of dirs.filter(existsSync30)) {
|
|
11502
|
+
for (const name of readdirSync15(dir).sort()) {
|
|
11503
|
+
const file = join32(dir, name, "scorer.md");
|
|
11504
|
+
if (existsSync30(file)) all.set(name, file);
|
|
11189
11505
|
}
|
|
11190
11506
|
}
|
|
11191
|
-
return [...all].map(([
|
|
11192
|
-
const text =
|
|
11507
|
+
return [...all].map(([id2, file]) => {
|
|
11508
|
+
const text = readFileSync27(file, "utf8");
|
|
11193
11509
|
const { parsed } = parseFrontmatter(text, file);
|
|
11194
11510
|
const data = parsed?.data;
|
|
11195
|
-
if (!data || !/^[a-z][a-z0-9_-]*$/.test(
|
|
11511
|
+
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
11512
|
throw new Error(`invalid scorer metadata: ${file}`);
|
|
11197
11513
|
}
|
|
11198
11514
|
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
11515
|
if (!Object.keys(classifications).length) throw new Error(`no classifications: ${file}`);
|
|
11200
11516
|
return {
|
|
11201
|
-
id,
|
|
11517
|
+
id: id2,
|
|
11202
11518
|
file,
|
|
11203
11519
|
text,
|
|
11204
11520
|
version: data.version,
|
|
@@ -11223,7 +11539,7 @@ function scorePlan(ctx, kit, scorer, runId, limit = 10) {
|
|
|
11223
11539
|
const previous = readLog(ctx.root, "scores");
|
|
11224
11540
|
const records = runs(ctx.root).filter((run2) => run2.subject.project === ctx.project?.name);
|
|
11225
11541
|
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:
|
|
11542
|
+
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
11543
|
}
|
|
11228
11544
|
function recordScore(ctx, kit, scorer, runId, input) {
|
|
11229
11545
|
const rubric = rubrics(ctx.root, kit).find((r) => r.id === scorer);
|
|
@@ -11308,6 +11624,8 @@ Usage: node .lead/lead.mjs <command> [options]
|
|
|
11308
11624
|
spec [--confirm S | --reopen S] assemble work/spec.md from work/spec/; confirm or reopen a section
|
|
11309
11625
|
builder-settings <x> --source DIR [--deny P,Q] clean room: settings that keep the builder away from X
|
|
11310
11626
|
similarity --source DIR [paths...] fragments shared with the source of X (default: the project folder)
|
|
11627
|
+
inbox [--json] blockers, open questions and approvals waiting for a person
|
|
11628
|
+
docs [--json] [--key KEY] the project's documents, One Pager first, with their FuseBase notes
|
|
11311
11629
|
sync-plan JSON list of FuseBase/Jira writes needed to mirror work/
|
|
11312
11630
|
sync-plan --preview summarize recorded, pending, and uncertain writes
|
|
11313
11631
|
sync-one-pager [--input FILE] render the FuseBase One Pager or verify its read-back Markdown
|
|
@@ -11333,6 +11651,8 @@ Usage: node .lead/lead.mjs <command> [options]
|
|
|
11333
11651
|
initiative waves <id> [--write] compute (and with --write store) waves across the initiative's repositories
|
|
11334
11652
|
adapters [name] [--json] project adapters in .lead/adapters/ (rules for reading this project's existing records)
|
|
11335
11653
|
delegate [id] [check] [--json] services that can take a task, and tasks already handed off
|
|
11654
|
+
watch probe [report|shadow|off] [--dry] token-free pass over delegated tasks; shadow records its decision beside each tick
|
|
11655
|
+
watch ack [--acted|--idle] acknowledge a due check (--acted: an action was taken or required; --idle: nothing to do)
|
|
11336
11656
|
watch [start|stop|interval 15m|ack] local clock for delegated tasks (default 15m; --close on start)
|
|
11337
11657
|
improve print .lead/improve.md (stops, asks, what a kit change would avoid)
|
|
11338
11658
|
improve --kind stop|ask|avoidable --where TEXT --what TEXT [--avoid TEXT]
|
|
@@ -11372,7 +11692,7 @@ function watchLine(root) {
|
|
|
11372
11692
|
function kitRoot() {
|
|
11373
11693
|
return resolve3(dirname6(fileURLToPath(import.meta.url)), "..");
|
|
11374
11694
|
}
|
|
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"]);
|
|
11695
|
+
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", "acted", "idle", "dry"]);
|
|
11376
11696
|
function main(argv, out = (s) => console.log(s)) {
|
|
11377
11697
|
const { cmd, args, flags } = parseArgs(argv);
|
|
11378
11698
|
const unknown = Object.keys(flags).filter((f) => !KNOWN_FLAGS.has(f));
|
|
@@ -11391,13 +11711,13 @@ function main(argv, out = (s) => console.log(s)) {
|
|
|
11391
11711
|
if (cmd && !["help", "--help", "version", "how", "install"].includes(cmd)) {
|
|
11392
11712
|
try {
|
|
11393
11713
|
const runningKit = kitRoot();
|
|
11394
|
-
const deployed =
|
|
11714
|
+
const deployed = basename3(runningKit) === "workspace-kit" && basename3(dirname6(runningKit)) === ".lead";
|
|
11395
11715
|
const ws = deployed ? findWorkspace(dirname6(dirname6(runningKit))) : findWorkspace(origin);
|
|
11396
11716
|
if (deployed && !ws) throw new Error("the shared workspace catalog is missing");
|
|
11397
11717
|
if (ws) {
|
|
11398
|
-
const path =
|
|
11399
|
-
if (path === ".." || path.startsWith(".." +
|
|
11400
|
-
sharedKit =
|
|
11718
|
+
const path = relative14(ws.root, realpathSync6(origin));
|
|
11719
|
+
if (path === ".." || path.startsWith(".." + sep5)) throw new Error("the command directory is outside this workspace");
|
|
11720
|
+
sharedKit = join33(ws.root, RUNTIME);
|
|
11401
11721
|
}
|
|
11402
11722
|
if (flags.repo && (!ws || !str2(flags.repo))) throw new Error("--repo requires a workspace and repository name");
|
|
11403
11723
|
if (cmd === "workspace") {
|
|
@@ -11415,15 +11735,15 @@ function main(argv, out = (s) => console.log(s)) {
|
|
|
11415
11735
|
return 0;
|
|
11416
11736
|
}
|
|
11417
11737
|
if (args[0] === "improve") {
|
|
11418
|
-
const
|
|
11419
|
-
if (flags.json) out(JSON.stringify(
|
|
11738
|
+
const report2 = workspaceImprove(ws);
|
|
11739
|
+
if (flags.json) out(JSON.stringify(report2, null, 2));
|
|
11420
11740
|
else {
|
|
11421
|
-
out(`${
|
|
11422
|
-
for (const repo of
|
|
11741
|
+
out(`${report2.entries.length} improvement entries across ${report2.repositories.length} registered repositories`);
|
|
11742
|
+
for (const repo of report2.repositories) {
|
|
11423
11743
|
const malformed = repo.malformed?.length ? ` \xB7 unparsed headings at lines ${repo.malformed.join(", ")}` : "";
|
|
11424
11744
|
out(`- ${repo.id}: ${repo.count} \xB7 ${repo.state}${malformed}${repo.reason ? ` \xB7 ${repo.reason}` : ""}`);
|
|
11425
11745
|
}
|
|
11426
|
-
for (const entry of
|
|
11746
|
+
for (const entry of report2.entries) {
|
|
11427
11747
|
out(`
|
|
11428
11748
|
## ${entry.at} \u2014 ${entry.kind} \xB7 ${entry.repository}
|
|
11429
11749
|
${entry.source}:${entry.line}
|
|
@@ -11440,7 +11760,7 @@ ${entry.source}:${entry.line}
|
|
|
11440
11760
|
}
|
|
11441
11761
|
if (args[0] === "attach" && args[1]) {
|
|
11442
11762
|
const target = routeScope(ws, ws.root, void 0, args[1]).root;
|
|
11443
|
-
if (
|
|
11763
|
+
if (existsSync31(join33(target, ".lead/lead.mjs")) && !isPortableLauncher(target)) throw new Error("a lead entry point already exists; review and migrate it before attaching");
|
|
11444
11764
|
writeEntrypoints(target);
|
|
11445
11765
|
for (const line of [...ensureGitIgnore(target), ...ensureClaudeSettings(target), ...ensureCodexHooks(target)]) out(line);
|
|
11446
11766
|
out(`attached ${args[1]} to the shared lead workspace`);
|
|
@@ -11467,7 +11787,7 @@ ${entry.source}:${entry.line}
|
|
|
11467
11787
|
if (scope) {
|
|
11468
11788
|
cwd = scope.cwd;
|
|
11469
11789
|
project = scope.project;
|
|
11470
|
-
} else if (repoRoot(origin) === ws.root || !
|
|
11790
|
+
} else if (repoRoot(origin) === ws.root || !existsSync31(join33(repoRoot(origin), ".git"))) {
|
|
11471
11791
|
if (cmd === "session-start" && session) {
|
|
11472
11792
|
out(JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: `lead workspace session: ${session}. Pass --session ${session} to lead commands.` } }));
|
|
11473
11793
|
return 0;
|
|
@@ -11535,19 +11855,19 @@ ${entry.source}:${entry.line}
|
|
|
11535
11855
|
return 1;
|
|
11536
11856
|
}
|
|
11537
11857
|
if (flags.write) {
|
|
11538
|
-
const
|
|
11539
|
-
out(
|
|
11858
|
+
const log2 = writeWaves(ctx);
|
|
11859
|
+
out(log2.length ? log2.join("\n") : "waves already up to date");
|
|
11540
11860
|
} else {
|
|
11541
11861
|
const groups = /* @__PURE__ */ new Map();
|
|
11542
|
-
for (const [
|
|
11862
|
+
for (const [id2, w] of waves) groups.set(w, [...groups.get(w) ?? [], id2]);
|
|
11543
11863
|
for (const w of [...groups.keys()].sort((a, b) => a - b)) out(`wave ${w}: ${groups.get(w).sort().join(" \u2016 ")}`);
|
|
11544
11864
|
}
|
|
11545
11865
|
return 0;
|
|
11546
11866
|
}
|
|
11547
11867
|
case "board": {
|
|
11548
11868
|
const ctx = loadContext(cwd, project);
|
|
11549
|
-
const
|
|
11550
|
-
out(
|
|
11869
|
+
const log2 = writeBoard(ctx);
|
|
11870
|
+
out(log2.length ? log2.join("\n") : "board is up to date");
|
|
11551
11871
|
return 0;
|
|
11552
11872
|
}
|
|
11553
11873
|
case "start":
|
|
@@ -11555,15 +11875,15 @@ ${entry.source}:${entry.line}
|
|
|
11555
11875
|
case "review":
|
|
11556
11876
|
case "finish":
|
|
11557
11877
|
case "block": {
|
|
11558
|
-
const
|
|
11559
|
-
if (!
|
|
11878
|
+
const id2 = args[0];
|
|
11879
|
+
if (!id2 || !session && !(cmd === "finish" && flags.merged)) {
|
|
11560
11880
|
out(`usage: ${cmd} <task> --session ID (or set LEAD_SESSION)`);
|
|
11561
11881
|
return 2;
|
|
11562
11882
|
}
|
|
11563
11883
|
const ctx = loadContext(cwd, project);
|
|
11564
|
-
const task = ctx.tasks.find((t) => t.id ===
|
|
11884
|
+
const task = ctx.tasks.find((t) => t.id === id2);
|
|
11565
11885
|
if (!task) {
|
|
11566
|
-
out(`no task ${
|
|
11886
|
+
out(`no task ${id2}${ctx.project ? "" : " (no project selected: --project NAME)"}`);
|
|
11567
11887
|
return 1;
|
|
11568
11888
|
}
|
|
11569
11889
|
let r;
|
|
@@ -11591,10 +11911,10 @@ ${entry.source}:${entry.line}
|
|
|
11591
11911
|
case "enable":
|
|
11592
11912
|
case "disable": {
|
|
11593
11913
|
const root = repoRoot(cwd);
|
|
11594
|
-
|
|
11595
|
-
if (cmd === "enable")
|
|
11914
|
+
mkdirSync15(join33(root, ".lead"), { recursive: true });
|
|
11915
|
+
if (cmd === "enable") writeFileSync16(join33(root, ENABLED_PATH), `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
11596
11916
|
`);
|
|
11597
|
-
else rmSync6(
|
|
11917
|
+
else rmSync6(join33(root, ENABLED_PATH), { force: true });
|
|
11598
11918
|
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
11919
|
return 0;
|
|
11600
11920
|
}
|
|
@@ -11634,7 +11954,7 @@ ${entry.source}:${entry.line}
|
|
|
11634
11954
|
return 0;
|
|
11635
11955
|
}
|
|
11636
11956
|
case "session-start": {
|
|
11637
|
-
const pointer = sharedKit && scope ? [`lead: this project runs with lead, no /lead needed. Launcher: ${
|
|
11957
|
+
const pointer = sharedKit && scope ? [`lead: this project runs with lead, no /lead needed. Launcher: ${join33(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
11958
|
if (!isEnabled(repoRoot(cwd))) {
|
|
11639
11959
|
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
11960
|
return 0;
|
|
@@ -11663,7 +11983,7 @@ ${entry.source}:${entry.line}
|
|
|
11663
11983
|
out(e.message);
|
|
11664
11984
|
return 1;
|
|
11665
11985
|
}
|
|
11666
|
-
const title = ctx.project.name === "." ?
|
|
11986
|
+
const title = ctx.project.name === "." ? basename3(ctx.root) : ctx.project.name;
|
|
11667
11987
|
const r = assembleSpec(ctx.root, ctx.project.workDir, title);
|
|
11668
11988
|
out(r.changed ? "spec.md updated" : "spec.md is up to date");
|
|
11669
11989
|
return 0;
|
|
@@ -11692,7 +12012,7 @@ start the builder with: ${r.launch}`);
|
|
|
11692
12012
|
return 2;
|
|
11693
12013
|
}
|
|
11694
12014
|
const ctx = loadContext(cwd, project);
|
|
11695
|
-
const targets = args.length ? args.map((a) => resolve3(cwd, a)) : [
|
|
12015
|
+
const targets = args.length ? args.map((a) => resolve3(cwd, a)) : [join33(ctx.root, ctx.project?.path ?? ".")];
|
|
11696
12016
|
const matches = similarity(resolve3(cwd, source), targets, ctx.root);
|
|
11697
12017
|
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
12018
|
out(`${matches.length} shared fragments`);
|
|
@@ -11707,7 +12027,7 @@ start the builder with: ${r.launch}`);
|
|
|
11707
12027
|
}
|
|
11708
12028
|
const file = str2(flags.input);
|
|
11709
12029
|
if (!file) throw new Error("--input FILE must point to the read-back Markdown");
|
|
11710
|
-
const mismatches = verifyOnePager(markdown,
|
|
12030
|
+
const mismatches = verifyOnePager(markdown, readFileSync28(resolve3(cwd, file), "utf8"));
|
|
11711
12031
|
out(mismatches.length ? mismatches.join("\n") : "One Pager read-back matches the roadmap, triage, widgets and links");
|
|
11712
12032
|
return mismatches.length ? 1 : 0;
|
|
11713
12033
|
} catch (e) {
|
|
@@ -11715,6 +12035,39 @@ start the builder with: ${r.launch}`);
|
|
|
11715
12035
|
return 1;
|
|
11716
12036
|
}
|
|
11717
12037
|
}
|
|
12038
|
+
case "inbox": {
|
|
12039
|
+
const ctx = loadContext(cwd, project);
|
|
12040
|
+
if (!ctx.project) {
|
|
12041
|
+
out("no project selected: --project NAME");
|
|
12042
|
+
return 1;
|
|
12043
|
+
}
|
|
12044
|
+
const items = inbox(ctx);
|
|
12045
|
+
if (flags.json) out(JSON.stringify({ project: ctx.project.name, items }, null, 2));
|
|
12046
|
+
else if (!items.length) out("Inbox is empty.");
|
|
12047
|
+
else for (const i of items) out(`${i.kind} \xB7 ${i.title}${i.detail ? ` \u2014 ${i.detail}` : ""} \xB7 ${i.source.path}`);
|
|
12048
|
+
return 0;
|
|
12049
|
+
}
|
|
12050
|
+
case "docs": {
|
|
12051
|
+
const ctx = loadContext(cwd, project);
|
|
12052
|
+
if (!ctx.project) {
|
|
12053
|
+
out("no project selected: --project NAME");
|
|
12054
|
+
return 1;
|
|
12055
|
+
}
|
|
12056
|
+
const key = str2(flags.key);
|
|
12057
|
+
if (key) {
|
|
12058
|
+
const text = docText(ctx, key);
|
|
12059
|
+
if (text === void 0) {
|
|
12060
|
+
out(`no document ${key}`);
|
|
12061
|
+
return 1;
|
|
12062
|
+
}
|
|
12063
|
+
out(text);
|
|
12064
|
+
return 0;
|
|
12065
|
+
}
|
|
12066
|
+
const list = docIndex(ctx);
|
|
12067
|
+
if (flags.json) out(JSON.stringify({ project: ctx.project.name, documents: list }, null, 2));
|
|
12068
|
+
else for (const d of list) out(`${d.group} \xB7 ${d.title} \xB7 ${d.path}${d.url ? ` \xB7 ${d.url}` : ""}`);
|
|
12069
|
+
return 0;
|
|
12070
|
+
}
|
|
11718
12071
|
case "sync-plan": {
|
|
11719
12072
|
const ctx = loadContext(cwd, project);
|
|
11720
12073
|
if (!ctx.project) {
|
|
@@ -11750,8 +12103,8 @@ start the builder with: ${r.launch}`);
|
|
|
11750
12103
|
return 0;
|
|
11751
12104
|
}
|
|
11752
12105
|
const actions = syncPlan(ctx).map((a, i) => ({ id: i + 1, ...a }));
|
|
11753
|
-
|
|
11754
|
-
|
|
12106
|
+
mkdirSync15(join33(ctx.root, ".lead/logs"), { recursive: true });
|
|
12107
|
+
writeFileSync16(syncPlanPath(ctx.root, ctx.project.name), JSON.stringify({ project: ctx.project.name, actions }, null, 2));
|
|
11755
12108
|
out(JSON.stringify(actions, null, 2));
|
|
11756
12109
|
return 0;
|
|
11757
12110
|
}
|
|
@@ -11776,7 +12129,7 @@ start the builder with: ${r.launch}`);
|
|
|
11776
12129
|
if (cmd === "sync-attempt") {
|
|
11777
12130
|
if (!syncPlan(ctx).some((current) => syncActionKey(current) === key)) throw new Error("action is no longer in the current plan");
|
|
11778
12131
|
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(([
|
|
12132
|
+
if (Object.entries(journal).some(([id2, entry]) => id2 !== key && !entry.done && entry.label === syncLabel(action))) {
|
|
11780
12133
|
throw new Error("an earlier action for this item has an uncertain outcome: reconcile it before proceeding");
|
|
11781
12134
|
}
|
|
11782
12135
|
journal[key] = { label: syncLabel(action), done: false, action };
|
|
@@ -11806,7 +12159,7 @@ start the builder with: ${r.launch}`);
|
|
|
11806
12159
|
const input = () => {
|
|
11807
12160
|
const file = str2(flags.input);
|
|
11808
12161
|
if (!file) throw new Error("--input FILE is required");
|
|
11809
|
-
return JSON.parse(
|
|
12162
|
+
return JSON.parse(readFileSync28(resolve3(cwd, file), "utf8"));
|
|
11810
12163
|
};
|
|
11811
12164
|
if (cmd === "qa-record") {
|
|
11812
12165
|
const task = ctx.tasks.find((t) => t.id === args[0]);
|
|
@@ -11822,7 +12175,7 @@ start the builder with: ${r.launch}`);
|
|
|
11822
12175
|
} else if (args[0] === "analyze") {
|
|
11823
12176
|
out(JSON.stringify(analyzeScores(ctx), null, 2));
|
|
11824
12177
|
} 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));
|
|
12178
|
+
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
12179
|
} else {
|
|
11827
12180
|
if (args.length) throw new Error("usage: score [runs|record|analyze]");
|
|
11828
12181
|
const limit = Number(str2(flags.limit) ?? 10);
|
|
@@ -11836,21 +12189,21 @@ start the builder with: ${r.launch}`);
|
|
|
11836
12189
|
}
|
|
11837
12190
|
}
|
|
11838
12191
|
case "settings": {
|
|
11839
|
-
const
|
|
11840
|
-
out(
|
|
12192
|
+
const log2 = ensureClaudeSettings(repoRoot(cwd));
|
|
12193
|
+
out(log2.length ? log2.join("\n") : "settings already up to date");
|
|
11841
12194
|
return 0;
|
|
11842
12195
|
}
|
|
11843
12196
|
case "claim":
|
|
11844
12197
|
case "release": {
|
|
11845
|
-
const
|
|
11846
|
-
if (!
|
|
12198
|
+
const id2 = args[0];
|
|
12199
|
+
if (!id2 || !session) {
|
|
11847
12200
|
out(`usage: ${cmd} <task> --session ID`);
|
|
11848
12201
|
return 2;
|
|
11849
12202
|
}
|
|
11850
12203
|
const ctx = loadContext(cwd, project);
|
|
11851
|
-
const task = ctx.tasks.find((t) => t.id ===
|
|
12204
|
+
const task = ctx.tasks.find((t) => t.id === id2);
|
|
11852
12205
|
if (!task) {
|
|
11853
|
-
out(`no task ${
|
|
12206
|
+
out(`no task ${id2}`);
|
|
11854
12207
|
return 1;
|
|
11855
12208
|
}
|
|
11856
12209
|
let r;
|
|
@@ -11875,8 +12228,8 @@ start the builder with: ${r.launch}`);
|
|
|
11875
12228
|
out(`usage: use <project>; projects: ${projects.map((p) => p.name).join(", ") || "none"}`);
|
|
11876
12229
|
return 2;
|
|
11877
12230
|
}
|
|
11878
|
-
|
|
11879
|
-
|
|
12231
|
+
mkdirSync15(join33(root, ".lead"), { recursive: true });
|
|
12232
|
+
writeFileSync16(join33(root, CURRENT_PATH), `${name}
|
|
11880
12233
|
`);
|
|
11881
12234
|
out(`current project: ${name}`);
|
|
11882
12235
|
return 0;
|
|
@@ -11888,10 +12241,10 @@ start the builder with: ${r.launch}`);
|
|
|
11888
12241
|
}
|
|
11889
12242
|
case "scaffold": {
|
|
11890
12243
|
const ctx = loadContext(cwd, project);
|
|
11891
|
-
const
|
|
11892
|
-
if (!ctx.configExists)
|
|
11893
|
-
else if (!ctx.project)
|
|
11894
|
-
out(
|
|
12244
|
+
const log2 = scaffold(ctx.root, ctx.configExists ? ctx.project : void 0);
|
|
12245
|
+
if (!ctx.configExists) log2.push("fill .lead/config.yml (checks, projects), then run scaffold again to create work/");
|
|
12246
|
+
else if (!ctx.project) log2.push("choose a project (--project NAME or `use NAME`) to create its work/");
|
|
12247
|
+
out(log2.length ? log2.join("\n") : "nothing to create");
|
|
11895
12248
|
return 0;
|
|
11896
12249
|
}
|
|
11897
12250
|
case "doctor": {
|
|
@@ -11906,8 +12259,8 @@ start the builder with: ${r.launch}`);
|
|
|
11906
12259
|
out("usage: install <repo>");
|
|
11907
12260
|
return 2;
|
|
11908
12261
|
}
|
|
11909
|
-
const
|
|
11910
|
-
out(
|
|
12262
|
+
const log2 = install(kitRoot(), realpathSync6(target), fileURLToPath(import.meta.url), { keepModified: !!flags["keep-modified"] });
|
|
12263
|
+
out(log2.join("\n"));
|
|
11911
12264
|
return 0;
|
|
11912
12265
|
}
|
|
11913
12266
|
case "update": {
|
|
@@ -11920,9 +12273,9 @@ start the builder with: ${r.launch}`);
|
|
|
11920
12273
|
const applyKit = (kit) => {
|
|
11921
12274
|
if (!isKitRoot(kit)) throw new Error(`${kit} is not a lead kit release (missing dist/lead.mjs or skills/lead)`);
|
|
11922
12275
|
const before = readLock(root)?.version ?? "none";
|
|
11923
|
-
const r =
|
|
12276
|
+
const r = spawnSync4(
|
|
11924
12277
|
process.execPath,
|
|
11925
|
-
[
|
|
12278
|
+
[join33(kit, "dist/lead.mjs"), "install", root, ...flags.force ? [] : ["--keep-modified"]],
|
|
11926
12279
|
{ cwd: root, encoding: "utf8" }
|
|
11927
12280
|
);
|
|
11928
12281
|
const output = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
@@ -11936,8 +12289,8 @@ start the builder with: ${r.launch}`);
|
|
|
11936
12289
|
try {
|
|
11937
12290
|
if (!from) return withRegistryKit(root, out, applyKit);
|
|
11938
12291
|
const path = resolve3(cwd, from);
|
|
11939
|
-
if (
|
|
11940
|
-
tmp = mkdtempSync3(
|
|
12292
|
+
if (existsSync31(path)) return applyKit(path);
|
|
12293
|
+
tmp = mkdtempSync3(join33(tmpdir3(), "lead-kit-"));
|
|
11941
12294
|
execFileSync6("git", ["clone", "-q", "--depth", "1", "--", from, tmp], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
11942
12295
|
return applyKit(tmp);
|
|
11943
12296
|
} catch (e) {
|
|
@@ -11953,19 +12306,19 @@ start the builder with: ${r.launch}`);
|
|
|
11953
12306
|
case "adopt": {
|
|
11954
12307
|
const root = repoRoot(cwd);
|
|
11955
12308
|
const input = typeof flags.input === "string" ? flags.input : "";
|
|
11956
|
-
const
|
|
12309
|
+
const id2 = typeof flags.id === "string" ? flags.id : "";
|
|
11957
12310
|
const home = typeof flags.home === "string" ? flags.home : "";
|
|
11958
|
-
if (!input || !
|
|
12311
|
+
if (!input || !id2 || !home) {
|
|
11959
12312
|
out("usage: adopt --input FILE --id ID --home REPO [--flag KEY] [--title TEXT] [--write] [--force]");
|
|
11960
12313
|
return 2;
|
|
11961
12314
|
}
|
|
11962
|
-
if (!/^[a-z][a-z0-9-]*$/.test(
|
|
12315
|
+
if (!/^[a-z][a-z0-9-]*$/.test(id2) || id2 === "check" || id2 === "waves" || !/^[a-z][a-z0-9-]*$/.test(home)) {
|
|
11963
12316
|
out('--id and --home must look like "private-space" (id cannot be check or waves)');
|
|
11964
12317
|
return 2;
|
|
11965
12318
|
}
|
|
11966
12319
|
let raw;
|
|
11967
12320
|
try {
|
|
11968
|
-
raw = JSON.parse(
|
|
12321
|
+
raw = JSON.parse(readFileSync28(resolve3(cwd, input), "utf8"));
|
|
11969
12322
|
} catch (error) {
|
|
11970
12323
|
out(`cannot read ${input}: ${error.message}`);
|
|
11971
12324
|
return 2;
|
|
@@ -11975,15 +12328,15 @@ start the builder with: ${r.launch}`);
|
|
|
11975
12328
|
for (const e of errors) out(`error ${e}`);
|
|
11976
12329
|
return 2;
|
|
11977
12330
|
}
|
|
11978
|
-
const syncFile =
|
|
12331
|
+
const syncFile = join33(root, "work/initiatives", id2, "sync.json");
|
|
11979
12332
|
let previous;
|
|
11980
12333
|
try {
|
|
11981
|
-
previous = JSON.parse(
|
|
12334
|
+
previous = JSON.parse(readFileSync28(syncFile, "utf8"));
|
|
11982
12335
|
} catch {
|
|
11983
12336
|
previous = void 0;
|
|
11984
12337
|
}
|
|
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 } : {} });
|
|
12338
|
+
const existing = loadInitiatives(root).initiatives.find((i) => i.id === id2);
|
|
12339
|
+
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
12340
|
const diff = previous ? diffObserved(previous, proposal) : void 0;
|
|
11988
12341
|
if (flags.json) out(JSON.stringify({ ...proposal, ...diff ? { diff } : {} }, null, 2));
|
|
11989
12342
|
else {
|
|
@@ -12002,17 +12355,17 @@ start the builder with: ${r.launch}`);
|
|
|
12002
12355
|
const { initiatives, issues } = loadInitiatives(root);
|
|
12003
12356
|
const errors = issues.filter((i) => i.level === "error");
|
|
12004
12357
|
const sub = args[0] === "check" || args[0] === "waves" ? args[0] : void 0;
|
|
12005
|
-
const
|
|
12358
|
+
const id2 = sub ? args[1] : args[0];
|
|
12006
12359
|
if (sub === "check" || sub === "waves") {
|
|
12007
|
-
if (
|
|
12008
|
-
out(`no initiative "${
|
|
12360
|
+
if (id2 && !initiatives.some((i) => i.id === id2)) {
|
|
12361
|
+
out(`no initiative "${id2}". Known: ${initiatives.map((i) => i.id).join(", ") || "none"}`);
|
|
12009
12362
|
return 1;
|
|
12010
12363
|
}
|
|
12011
|
-
if (sub === "waves" && !
|
|
12364
|
+
if (sub === "waves" && !id2) {
|
|
12012
12365
|
out("usage: initiative waves <id> [--write]");
|
|
12013
12366
|
return 2;
|
|
12014
12367
|
}
|
|
12015
|
-
const chosen = initiatives.filter((i) => !
|
|
12368
|
+
const chosen = initiatives.filter((i) => !id2 || i.id === id2);
|
|
12016
12369
|
if (sub === "waves") {
|
|
12017
12370
|
const target = chosen[0];
|
|
12018
12371
|
if (flags.write) for (const line of writeInitiativeWaves(root, target)) out(line);
|
|
@@ -12028,13 +12381,13 @@ start the builder with: ${r.launch}`);
|
|
|
12028
12381
|
out(all.length ? formatIssues(all) : "initiatives: ok");
|
|
12029
12382
|
return all.some((i) => i.level === "error") ? 1 : 0;
|
|
12030
12383
|
}
|
|
12031
|
-
if (
|
|
12032
|
-
out(`no initiative "${
|
|
12384
|
+
if (id2 && !initiatives.some((i) => i.id === id2)) {
|
|
12385
|
+
out(`no initiative "${id2}". Known: ${initiatives.map((i) => i.id).join(", ") || "none"}`);
|
|
12033
12386
|
return 1;
|
|
12034
12387
|
}
|
|
12035
12388
|
if (typeof flags.in === "string") {
|
|
12036
12389
|
const repo = flags.in;
|
|
12037
|
-
const one = initiatives.filter((i) => !
|
|
12390
|
+
const one = initiatives.filter((i) => !id2 || i.id === id2);
|
|
12038
12391
|
const rows = one.map((i) => {
|
|
12039
12392
|
const o = initiativeOverview(root, i);
|
|
12040
12393
|
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 +12403,7 @@ start the builder with: ${r.launch}`);
|
|
|
12050
12403
|
}
|
|
12051
12404
|
return errors.length ? 1 : 0;
|
|
12052
12405
|
}
|
|
12053
|
-
const overview = initiatives.filter((i) => !
|
|
12406
|
+
const overview = initiatives.filter((i) => !id2 || i.id === id2).map((i) => initiativeOverview(root, i));
|
|
12054
12407
|
if (flags.json) out(JSON.stringify({ initiatives: overview, issues }, null, 2));
|
|
12055
12408
|
else {
|
|
12056
12409
|
for (const o of overview) for (const line of renderInitiative(o)) out(line);
|
|
@@ -12069,7 +12422,7 @@ start the builder with: ${r.launch}`);
|
|
|
12069
12422
|
out(`no adapter "${name}". Known: ${adapters.map((a) => a.id).join(", ") || "none"}`);
|
|
12070
12423
|
return 1;
|
|
12071
12424
|
}
|
|
12072
|
-
out(flags.json ? JSON.stringify({ ...found, text:
|
|
12425
|
+
out(flags.json ? JSON.stringify({ ...found, text: readFileSync28(join33(root, found.file), "utf8") }, null, 2) : readFileSync28(join33(root, found.file), "utf8").trimEnd());
|
|
12073
12426
|
return 0;
|
|
12074
12427
|
}
|
|
12075
12428
|
if (flags.json) out(JSON.stringify({ adapters, issues }, null, 2));
|
|
@@ -12083,14 +12436,14 @@ start the builder with: ${r.launch}`);
|
|
|
12083
12436
|
case "delegate": {
|
|
12084
12437
|
const ctx = loadContext(cwd, project);
|
|
12085
12438
|
const services = listDelegates(ctx.root, kitRoot());
|
|
12086
|
-
const
|
|
12439
|
+
const id2 = args[0] === "check" ? void 0 : args[0];
|
|
12087
12440
|
const checking = args.includes("check");
|
|
12088
|
-
if (
|
|
12089
|
-
out(`no delegate "${
|
|
12441
|
+
if (id2 && !services.some((d) => d.id === id2)) {
|
|
12442
|
+
out(`no delegate "${id2}". Known: ${services.map((d) => d.id).join(", ") || "none"}`);
|
|
12090
12443
|
return 1;
|
|
12091
12444
|
}
|
|
12092
|
-
const tasks = delegatedTasks(ctx.tasks,
|
|
12093
|
-
const payload = { services:
|
|
12445
|
+
const tasks = delegatedTasks(ctx.tasks, id2).map((t) => ({ id: t.id, title: t.title, delegate: t.delegate, ref: t.delegate_ref, status: t.status }));
|
|
12446
|
+
const payload = { services: id2 ? services.filter((d) => d.id === id2) : services, tasks, check: checking };
|
|
12094
12447
|
if (flags.json) out(JSON.stringify(payload, null, 2));
|
|
12095
12448
|
else {
|
|
12096
12449
|
for (const d of payload.services) out(`${d.id} (${d.source}) \u2014 ${d.available || d.title}`);
|
|
@@ -12111,9 +12464,33 @@ start the builder with: ${r.launch}`);
|
|
|
12111
12464
|
}
|
|
12112
12465
|
if (args[0] === "ack") {
|
|
12113
12466
|
clearDue(root);
|
|
12467
|
+
recordAck(root, flags.acted === true ? true : flags.idle === true ? false : null);
|
|
12114
12468
|
out("watch check acknowledged");
|
|
12115
12469
|
return 0;
|
|
12116
12470
|
}
|
|
12471
|
+
if (args[0] === "probe") {
|
|
12472
|
+
const sub = args[1];
|
|
12473
|
+
if (sub === "shadow" || sub === "off") {
|
|
12474
|
+
const st = readWatch(root);
|
|
12475
|
+
if (sub === "shadow") st.probe = "shadow";
|
|
12476
|
+
else delete st.probe;
|
|
12477
|
+
writeWatch(root, st);
|
|
12478
|
+
out(`probe ${sub === "shadow" ? "shadow: each tick also records what the token-free probe would decide; checks are not skipped" : "off"}`);
|
|
12479
|
+
return 0;
|
|
12480
|
+
}
|
|
12481
|
+
if (sub === "report") {
|
|
12482
|
+
const r2 = report(root);
|
|
12483
|
+
for (const line of flags.json ? [JSON.stringify(r2, null, 2)] : renderReport(r2)) out(line);
|
|
12484
|
+
return 0;
|
|
12485
|
+
}
|
|
12486
|
+
if (sub !== void 0) {
|
|
12487
|
+
out("usage: watch probe [report|shadow|off] [--dry] [--json]");
|
|
12488
|
+
return 2;
|
|
12489
|
+
}
|
|
12490
|
+
const res = runProbe(root, { record: flags.dry !== true });
|
|
12491
|
+
for (const line of flags.json ? [JSON.stringify(res, null, 2)] : renderVerdicts(res)) out(line);
|
|
12492
|
+
return 0;
|
|
12493
|
+
}
|
|
12117
12494
|
const r = watchCommand(root, args, {
|
|
12118
12495
|
close: flags.close === true,
|
|
12119
12496
|
spawnLoop: () => {
|
|
@@ -12147,8 +12524,8 @@ start the builder with: ${r.launch}`);
|
|
|
12147
12524
|
const root = repoRoot(cwd);
|
|
12148
12525
|
if (args[0] === "analyze") {
|
|
12149
12526
|
const rows = loadActivity(root, { day: str2(flags.day), since: str2(flags.since) });
|
|
12150
|
-
const
|
|
12151
|
-
out(flags.json ? JSON.stringify(
|
|
12527
|
+
const report2 = analyzeActivity(rows);
|
|
12528
|
+
out(flags.json ? JSON.stringify(report2, null, 2) : formatActivityReport(report2));
|
|
12152
12529
|
return 0;
|
|
12153
12530
|
}
|
|
12154
12531
|
const event = str2(flags.event);
|
|
@@ -12210,12 +12587,12 @@ ${HELP}`);
|
|
|
12210
12587
|
}
|
|
12211
12588
|
}
|
|
12212
12589
|
function syncPlanPath(root, project) {
|
|
12213
|
-
return
|
|
12590
|
+
return join33(root, ".lead/logs", `sync-plan-${project === "." ? "root" : project.replace(/[^a-zA-Z0-9_-]/g, "_")}.json`);
|
|
12214
12591
|
}
|
|
12215
|
-
function savedSyncAction(root, project,
|
|
12216
|
-
const saved = JSON.parse(
|
|
12592
|
+
function savedSyncAction(root, project, id2) {
|
|
12593
|
+
const saved = JSON.parse(readFileSync28(syncPlanPath(root, project), "utf8"));
|
|
12217
12594
|
if (saved.project !== project) throw new Error(`the saved plan is for ${saved.project}, not ${project}`);
|
|
12218
|
-
return saved.actions.find((action) => action.id ===
|
|
12595
|
+
return saved.actions.find((action) => action.id === id2);
|
|
12219
12596
|
}
|
|
12220
12597
|
function syncActionKey(action) {
|
|
12221
12598
|
const { id: _id, ...payload } = action;
|
|
@@ -12227,26 +12604,26 @@ function syncLabel(action) {
|
|
|
12227
12604
|
return `${action.kind}${target ? ` \xB7 ${target}` : ""}${transition}`;
|
|
12228
12605
|
}
|
|
12229
12606
|
function syncJournalPath(root, project) {
|
|
12230
|
-
return
|
|
12607
|
+
return join33(root, ".lead/logs", `sync-journal-${digest(project)}.json`);
|
|
12231
12608
|
}
|
|
12232
12609
|
function readSyncJournal(root, project) {
|
|
12233
12610
|
const file = syncJournalPath(root, project);
|
|
12234
|
-
return
|
|
12611
|
+
return existsSync31(file) ? JSON.parse(readFileSync28(file, "utf8")) : {};
|
|
12235
12612
|
}
|
|
12236
12613
|
function writeSyncJournal(root, project, journal) {
|
|
12237
12614
|
const file = syncJournalPath(root, project);
|
|
12238
|
-
|
|
12239
|
-
|
|
12615
|
+
mkdirSync15(dirname6(file), { recursive: true });
|
|
12616
|
+
writeFileSync16(file, JSON.stringify(journal, null, 2));
|
|
12240
12617
|
}
|
|
12241
12618
|
function readStdinJson() {
|
|
12242
12619
|
try {
|
|
12243
|
-
const text =
|
|
12620
|
+
const text = readFileSync28(0, "utf8");
|
|
12244
12621
|
return text.trim() ? JSON.parse(text) : {};
|
|
12245
12622
|
} catch {
|
|
12246
12623
|
return {};
|
|
12247
12624
|
}
|
|
12248
12625
|
}
|
|
12249
|
-
var isMain = process.argv[1] &&
|
|
12626
|
+
var isMain = process.argv[1] && realpathSync6(process.argv[1]) === realpathSync6(fileURLToPath(import.meta.url));
|
|
12250
12627
|
if (isMain) process.exitCode = main(process.argv.slice(2));
|
|
12251
12628
|
export {
|
|
12252
12629
|
main
|