@kitman-sh/software-engineering 0.10.88 → 0.10.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +119 -45
- package/dist/declarations.json +116 -5
- package/package.json +3 -3
- package/src/build.ts +12 -4
- package/src/hindsight.ts +148 -46
package/dist/bundle.js
CHANGED
|
@@ -14562,6 +14562,7 @@ var LoopManifest = Struct({
|
|
|
14562
14562
|
from: optionalKey2(String5)
|
|
14563
14563
|
})),
|
|
14564
14564
|
capabilities: ArraySchema(Literals(LoopCapabilities)),
|
|
14565
|
+
ownCapabilities: optionalKey2(ArraySchema(Literals(LoopCapabilities))),
|
|
14565
14566
|
secrets: optionalKey2(ArraySchema(SecretName2)),
|
|
14566
14567
|
network: optionalKey2(AgentSandboxNetwork),
|
|
14567
14568
|
schedule: optionalKey2(Struct({ rule: ScheduleRule, timezone: String5 }))
|
|
@@ -14694,6 +14695,7 @@ var loopManifest = (definition) => gen2(function* () {
|
|
|
14694
14695
|
when: definition.when ?? [],
|
|
14695
14696
|
offers: definition.offers ?? [],
|
|
14696
14697
|
capabilities: capabilitiesOf(definition),
|
|
14698
|
+
...(definition.calls?.() ?? []).length === 0 ? undefined : { ownCapabilities: definition.capabilities },
|
|
14697
14699
|
...definition.secrets === undefined ? undefined : { secrets: definition.secrets },
|
|
14698
14700
|
...definition.network === undefined ? undefined : { network: definition.network },
|
|
14699
14701
|
...definition.schedule === undefined ? undefined : { schedule: definition.schedule }
|
|
@@ -19257,7 +19259,7 @@ var ChangeRequestRequest = Struct({
|
|
|
19257
19259
|
integration: optional2(String5)
|
|
19258
19260
|
});
|
|
19259
19261
|
var ChangeRequestResult = Struct({ id: String5, number: String5, url: String5 });
|
|
19260
|
-
var WriteBackMilestones = ["started", "change_request_opened", "merged", "failed"];
|
|
19262
|
+
var WriteBackMilestones = ["started", "change_request_opened", "merged", "failed", "blocked"];
|
|
19261
19263
|
var WriteBackRequest = Struct({
|
|
19262
19264
|
milestone: optional2(Literals(WriteBackMilestones)),
|
|
19263
19265
|
changeRequestUrl: optional2(String5)
|
|
@@ -19418,18 +19420,28 @@ var TranscriptPoint = Struct({
|
|
|
19418
19420
|
sequence: Int
|
|
19419
19421
|
});
|
|
19420
19422
|
var TranscriptsRequest = Struct({
|
|
19421
|
-
days: Int.check(isGreaterThanOrEqualTo2(1), isLessThanOrEqualTo3(31))
|
|
19423
|
+
days: Int.check(isGreaterThanOrEqualTo2(1), isLessThanOrEqualTo3(31)),
|
|
19424
|
+
teamId: optionalKey2(String5)
|
|
19422
19425
|
});
|
|
19423
19426
|
var TranscriptsResult = Struct({
|
|
19424
19427
|
runs: ArraySchema(Struct({
|
|
19425
19428
|
runId: String5,
|
|
19426
19429
|
loopId: String5,
|
|
19430
|
+
rootRunId: optional2(String5),
|
|
19427
19431
|
status: optional2(Literals(["completed", "failed", "canceled", "expired"])),
|
|
19428
19432
|
teamId: optional2(String5),
|
|
19429
19433
|
failure: optional2(String5),
|
|
19430
19434
|
retried: optional2(Boolean3),
|
|
19431
|
-
entries: ArraySchema(Struct({ stepAttemptId: String5, sequence: Int, kind: String5, text: String5 }))
|
|
19432
|
-
|
|
19435
|
+
entries: ArraySchema(Struct({ stepAttemptId: String5, sequence: Int, kind: String5, text: String5 })),
|
|
19436
|
+
omitted: optional2(Int)
|
|
19437
|
+
})),
|
|
19438
|
+
artifactId: optional2(String5),
|
|
19439
|
+
findings: optional2(ArraySchema(Struct({
|
|
19440
|
+
key: String5,
|
|
19441
|
+
title: String5,
|
|
19442
|
+
taskId: optional2(String5),
|
|
19443
|
+
taskKey: optional2(String5)
|
|
19444
|
+
})))
|
|
19433
19445
|
});
|
|
19434
19446
|
var Citations = NonEmptyArray(TranscriptPoint);
|
|
19435
19447
|
var ProposeRequest = Union2([
|
|
@@ -19451,7 +19463,8 @@ var ProposeRequest = Union2([
|
|
|
19451
19463
|
var ProposeResult = Struct({
|
|
19452
19464
|
kind: Literals(["memory", "task"]),
|
|
19453
19465
|
id: String5,
|
|
19454
|
-
matched: optionalKey2(Boolean3)
|
|
19466
|
+
matched: optionalKey2(Boolean3),
|
|
19467
|
+
task: optionalKey2(Struct({ id: String5, active: Boolean3 }))
|
|
19455
19468
|
});
|
|
19456
19469
|
var Health = Literals(["on_track", "at_risk", "off_track"]);
|
|
19457
19470
|
var ProjectActivityRequest = Struct({ projectId: String5 });
|
|
@@ -22472,7 +22485,7 @@ var rally = (input) => gen2(function* () {
|
|
|
22472
22485
|
});
|
|
22473
22486
|
var build2 = defineLoop({
|
|
22474
22487
|
id: "build",
|
|
22475
|
-
version: "2.
|
|
22488
|
+
version: "2.6.0",
|
|
22476
22489
|
title: "Build",
|
|
22477
22490
|
input: BuildInput,
|
|
22478
22491
|
output: BuildOutput,
|
|
@@ -22611,6 +22624,7 @@ var build2 = defineLoop({
|
|
|
22611
22624
|
].join(`
|
|
22612
22625
|
`)
|
|
22613
22626
|
});
|
|
22627
|
+
yield* ignore2(writeBack("write-back:blocked", { milestone: "blocked" }));
|
|
22614
22628
|
return yield* new BuildBlocked({
|
|
22615
22629
|
message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join("; ")}`
|
|
22616
22630
|
});
|
|
@@ -22644,7 +22658,7 @@ var build2 = defineLoop({
|
|
|
22644
22658
|
...landed === undefined ? undefined : { landed },
|
|
22645
22659
|
next: { changeRequestId: opened.id }
|
|
22646
22660
|
};
|
|
22647
|
-
}).pipe(tapError2(() => ignore2(writeBack("write-back:failed", { milestone: "failed" }))))
|
|
22661
|
+
}).pipe(tapError2((error) => error instanceof BuildBlocked ? void_3 : ignore2(writeBack("write-back:failed", { milestone: "failed" }))))
|
|
22648
22662
|
});
|
|
22649
22663
|
var build_default = build2;
|
|
22650
22664
|
|
|
@@ -23959,22 +23973,50 @@ var Proposal2 = Struct({
|
|
|
23959
23973
|
kind: Literals(["memory", "task"]),
|
|
23960
23974
|
id: String5,
|
|
23961
23975
|
matched: Boolean3,
|
|
23962
|
-
runIds: ArraySchema(String5)
|
|
23976
|
+
runIds: ArraySchema(String5),
|
|
23977
|
+
recurrence: Int
|
|
23963
23978
|
});
|
|
23964
23979
|
var Output11 = Struct({
|
|
23965
23980
|
summary: OneSentence,
|
|
23966
23981
|
proposals: ArraySchema(Proposal2),
|
|
23967
23982
|
leftOut: ArraySchema(Struct({ key: String5, reason: Reason })),
|
|
23968
|
-
improvements: ArraySchema(Struct({ key: String5, loop: Literals(["errand", "build"]), outcome: String5 }))
|
|
23969
|
-
})
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
23973
|
-
|
|
23983
|
+
improvements: ArraySchema(Struct({ key: String5, loop: Literals(["errand", "build"]), outcome: String5 })),
|
|
23984
|
+
notStarted: ArraySchema(Struct({ key: String5, reason: Reason }))
|
|
23985
|
+
});
|
|
23986
|
+
var oneLine = (text) => text.replace(/\s*\n\s*/g, " \u23CE ");
|
|
23987
|
+
var rootOf = (run) => run.rootRunId ?? run.runId;
|
|
23988
|
+
var digest = (runs) => runs.flatMap((run) => [
|
|
23989
|
+
[
|
|
23990
|
+
`Run ${run.runId}`,
|
|
23991
|
+
run.loopId,
|
|
23992
|
+
run.status ?? "settled",
|
|
23993
|
+
...rootOf(run) === run.runId ? [] : [`part of ${rootOf(run)}`],
|
|
23994
|
+
...run.teamId === undefined ? [] : [`team ${run.teamId}`],
|
|
23995
|
+
...run.retried === true ? ["retried"] : [],
|
|
23996
|
+
...run.failure === undefined ? [] : [`failure: ${oneLine(run.failure)}`],
|
|
23997
|
+
...run.omitted === undefined ? [] : [`${run.omitted} entries left out`]
|
|
23998
|
+
].join(" \xB7 "),
|
|
23999
|
+
...run.entries.flatMap((entry, index) => [
|
|
24000
|
+
...run.entries[index - 1]?.stepAttemptId === entry.stepAttemptId ? [] : [` attempt ${entry.stepAttemptId}`],
|
|
24001
|
+
` ${entry.sequence} ${entry.kind}: ${oneLine(entry.text)}`
|
|
24002
|
+
])
|
|
24003
|
+
]).join(`
|
|
24004
|
+
`);
|
|
24005
|
+
var earlier = (findings) => findings.length === 0 ? "No earlier finding is open." : [
|
|
24006
|
+
"Earlier findings still open, by key. When a problem is one of these, give it that key exactly; a new key only for a new problem:",
|
|
24007
|
+
...findings.map((found) => `- ${found.key}: ${oneLine(found.title)} (${found.taskKey === undefined ? "proposal waiting for a decision" : `open Task ${found.taskKey}`})`)
|
|
24008
|
+
].join(`
|
|
24009
|
+
`);
|
|
24010
|
+
var prompt4 = (read, days) => [
|
|
24011
|
+
`These Runs settled in the last ${days} days, each with its status: a failed one with its failure, one with a retried Step marked retried. Find what keeps going wrong in more than one piece of work: a failure, or in Runs that completed, a wasted step, a wrong turn, a check run again and again, or work redone. Fix the cause, not the symptom.`,
|
|
24012
|
+
`A Run "part of" another is one of its Child Runs, such as a Build's review, land or fix: a Run and its Child Runs are one piece of work, and count once. Each step attempt is a digest from start to end, its tool output cut short; each entry is "sequence kind: text".`,
|
|
24013
|
+
"```text",
|
|
24014
|
+
digest(read.runs),
|
|
23974
24015
|
"```",
|
|
24016
|
+
earlier(read.findings ?? []),
|
|
23975
24017
|
`Give each finding a category: ${categories.join(", ")}. Use kitman when Kitman itself misbehaved: a Run that stalled, parked or needed rescue for a reason in Kitman, not in the work.`,
|
|
23976
24018
|
"Give each a stable kebab-case key naming the problem, not the week: the same problem must get the same key next time.",
|
|
23977
|
-
"Propose Memory when agents can avoid it by knowing something, or a Task when something has to change; when the change is clear, say how to fix it as an errand (small) or a build (a feature). Cite every Transcript point (runId, stepAttemptId, sequence) it shows in. Cite what happened: tool calls and results, files and answers. An agent's own messages are not evidence. Leave out anything seen in one
|
|
24019
|
+
"Propose Memory when agents can avoid it by knowing something, or a Task when something has to change; when the change is clear, say how to fix it as an errand (small) or a build (a feature). Cite every Transcript point (runId, stepAttemptId, sequence) it shows in. Cite what happened: tool calls and results, files and answers. An agent's own messages are not evidence. Leave out anything seen in one piece of work only.",
|
|
23978
24020
|
"Never quote a person's words into a lesson."
|
|
23979
24021
|
].join(`
|
|
23980
24022
|
|
|
@@ -23985,34 +24027,42 @@ var shared = (cited, field) => {
|
|
|
23985
24027
|
const [only] = values;
|
|
23986
24028
|
return values.size === 1 ? only : undefined;
|
|
23987
24029
|
};
|
|
23988
|
-
var proposal = (finding, runs) => {
|
|
24030
|
+
var proposal = (finding, runs, teamId) => {
|
|
23989
24031
|
const evidence = new Set(runs.flatMap((run) => run.entries.flatMap((entry) => entry.kind === "message" ? [] : [point({ runId: run.runId, stepAttemptId: entry.stepAttemptId, sequence: entry.sequence })])));
|
|
24032
|
+
const roots = new Map(runs.map((run) => [run.runId, rootOf(run)]));
|
|
23990
24033
|
const citations = [
|
|
23991
24034
|
...new Map(finding.citations.filter((cited) => evidence.has(point(cited))).map((cited) => [point(cited), cited])).values()
|
|
23992
24035
|
];
|
|
23993
24036
|
const runIds = new Set(citations.map((cited) => cited.runId));
|
|
24037
|
+
const pieces = new Set(citations.map((cited) => roots.get(cited.runId)));
|
|
23994
24038
|
const [first, ...rest] = citations;
|
|
23995
24039
|
if (first === undefined)
|
|
23996
24040
|
return { reason: "It cites no evidence that was read: an agent\u2019s own words or a summary are not evidence" };
|
|
23997
|
-
if (
|
|
23998
|
-
return { reason: "It was seen in one Run only" };
|
|
23999
|
-
const
|
|
24000
|
-
if (finding.kind === "memory" &&
|
|
24001
|
-
return {
|
|
24041
|
+
if (pieces.size < 2)
|
|
24042
|
+
return { reason: "It was seen in one Run only, counting a Run with its Child Runs once" };
|
|
24043
|
+
const citedTeam = shared(runs.filter((run) => runIds.has(run.runId)), "teamId");
|
|
24044
|
+
if (finding.kind === "memory" && citedTeam !== undefined)
|
|
24045
|
+
return {
|
|
24046
|
+
request: { kind: "memory", teamId: citedTeam, content: finding.lesson, citations: [first, ...rest] },
|
|
24047
|
+
recurrence: pieces.size
|
|
24048
|
+
};
|
|
24049
|
+
const team = citedTeam ?? teamId;
|
|
24002
24050
|
return {
|
|
24003
24051
|
request: {
|
|
24004
24052
|
kind: "task",
|
|
24005
24053
|
title: finding.lesson,
|
|
24006
24054
|
description: finding.detail ?? finding.lesson,
|
|
24007
|
-
...
|
|
24055
|
+
...team === undefined ? undefined : { teamId: team },
|
|
24008
24056
|
key: finding.key,
|
|
24009
24057
|
citations: [first, ...rest]
|
|
24010
|
-
}
|
|
24058
|
+
},
|
|
24059
|
+
recurrence: pieces.size
|
|
24011
24060
|
};
|
|
24012
24061
|
};
|
|
24062
|
+
var notStartedReason = (finding, wanted) => finding.kind === "memory" ? "It became Memory, which has no Task to start on" : finding.task === undefined ? "Its Task waits for a person to accept the proposal" : finding.task.active ? "A Run is already working on its Task" : `Only ${wanted} ${wanted === 1 ? "improvement was" : "improvements were"} asked for, and findings that recurred in more top-level Runs went first`;
|
|
24013
24063
|
var hindsight_default = defineLoop({
|
|
24014
24064
|
id: "hindsight",
|
|
24015
|
-
version: "1.
|
|
24065
|
+
version: "1.1.0",
|
|
24016
24066
|
title: "Hindsight",
|
|
24017
24067
|
input: Input10,
|
|
24018
24068
|
output: Output11,
|
|
@@ -24024,34 +24074,47 @@ var hindsight_default = defineLoop({
|
|
|
24024
24074
|
calls: () => [errand_default, build_default],
|
|
24025
24075
|
run: (input) => gen2(function* () {
|
|
24026
24076
|
const days = input.days ?? 7;
|
|
24027
|
-
const read = yield* transcripts("read", {
|
|
24028
|
-
|
|
24029
|
-
|
|
24077
|
+
const read = yield* transcripts("read", {
|
|
24078
|
+
days,
|
|
24079
|
+
...input.teamId === undefined ? undefined : { teamId: input.teamId }
|
|
24080
|
+
});
|
|
24081
|
+
const runs = read.runs;
|
|
24082
|
+
const pieces = new Set(runs.map(rootOf)).size;
|
|
24083
|
+
if (pieces < 2)
|
|
24030
24084
|
return {
|
|
24031
|
-
summary: `Nothing recurred: ${
|
|
24085
|
+
summary: `Nothing recurred: ${pieces === 0 ? "no Run" : "one Run"} settled in the last ${days} days.`,
|
|
24032
24086
|
proposals: [],
|
|
24033
24087
|
leftOut: [],
|
|
24034
|
-
improvements: []
|
|
24088
|
+
improvements: [],
|
|
24089
|
+
notStarted: []
|
|
24035
24090
|
};
|
|
24036
24091
|
const { findings } = yield* agentWork("find", {
|
|
24037
24092
|
agent: "investigator",
|
|
24038
|
-
prompt: prompt4(
|
|
24093
|
+
prompt: prompt4(read, days),
|
|
24039
24094
|
output: Findings
|
|
24040
24095
|
});
|
|
24041
|
-
const judged = findings.map((finding) => ({ finding, judged: proposal(finding, runs) }));
|
|
24096
|
+
const judged = findings.map((finding) => ({ finding, judged: proposal(finding, runs, input.teamId) }));
|
|
24042
24097
|
const leftOut = judged.flatMap(({ finding, judged }) => judged.request === undefined ? [{ key: finding.key, reason: judged.reason }] : []);
|
|
24043
|
-
const kept = judged.flatMap(({ finding, judged }) => judged.request === undefined ? [] : [{ finding, request: judged.request }]);
|
|
24044
|
-
const
|
|
24098
|
+
const kept = judged.flatMap(({ finding, judged }) => judged.request === undefined ? [] : [{ finding, request: judged.request, recurrence: judged.recurrence }]);
|
|
24099
|
+
const made = yield* forEach2(kept, (kept) => map8(propose(`propose:${kept.finding.key}`, kept.request), (made) => ({ ...kept, made })));
|
|
24100
|
+
const proposals = made.map(({ finding, request, recurrence, made }) => ({
|
|
24045
24101
|
key: finding.key,
|
|
24046
24102
|
category: finding.category,
|
|
24047
24103
|
kind: made.kind,
|
|
24048
24104
|
id: made.id,
|
|
24049
24105
|
matched: made.matched === true,
|
|
24050
|
-
runIds: [...new Set(request.citations.map((cited) => cited.runId))]
|
|
24051
|
-
|
|
24052
|
-
|
|
24053
|
-
const
|
|
24054
|
-
|
|
24106
|
+
runIds: [...new Set(request.citations.map((cited) => cited.runId))],
|
|
24107
|
+
recurrence
|
|
24108
|
+
}));
|
|
24109
|
+
const wanted = input.improvements ?? 0;
|
|
24110
|
+
const fixable = made.flatMap(({ finding, recurrence, made }) => finding.fix === undefined ? [] : [{ key: finding.key, kind: made.kind, fix: finding.fix, recurrence, task: made.task }]);
|
|
24111
|
+
const startable = fixable.flatMap((finding) => finding.task === undefined || finding.task.active ? [] : [{ ...finding, taskId: finding.task.id }]).toSorted((a, b) => b.recurrence - a.recurrence);
|
|
24112
|
+
const chosen = startable.slice(0, wanted);
|
|
24113
|
+
const chosenKeys = new Set(chosen.map((finding) => finding.key));
|
|
24114
|
+
const notStarted = wanted === 0 ? [] : fixable.flatMap((finding) => chosenKeys.has(finding.key) ? [] : [{ key: finding.key, reason: notStartedReason(finding, wanted) }]);
|
|
24115
|
+
const improvements = yield* forEach2(chosen, (finding) => {
|
|
24116
|
+
const on = { words: finding.fix.words, taskId: finding.taskId };
|
|
24117
|
+
const started = finding.fix.size === "errand" ? map8(call(`improve:${finding.key}`, errand_default, on), (done) => done.status) : map8(call(`improve:${finding.key}`, build_default, on), (built) => built.stopped);
|
|
24055
24118
|
return started.pipe(catchTag2("ChildFailed", (failed) => succeed7(`failed: ${failed.reason}`)), map8((outcome) => ({ key: finding.key, loop: finding.fix.size, outcome })));
|
|
24056
24119
|
});
|
|
24057
24120
|
const fresh = proposals.filter((made) => !made.matched).length;
|
|
@@ -24059,7 +24122,8 @@ var hindsight_default = defineLoop({
|
|
|
24059
24122
|
summary: proposals.length === 0 ? `Nothing recurred with evidence in ${runs.length} Runs.` : `${proposals.length} recurring ${proposals.length === 1 ? "problem" : "problems"}: ${fresh} proposed, ${proposals.length - fresh} added to earlier work.`,
|
|
24060
24123
|
proposals,
|
|
24061
24124
|
leftOut,
|
|
24062
|
-
improvements
|
|
24125
|
+
improvements,
|
|
24126
|
+
notStarted
|
|
24063
24127
|
};
|
|
24064
24128
|
})
|
|
24065
24129
|
});
|
|
@@ -27316,7 +27380,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
|
|
|
27316
27380
|
}),
|
|
27317
27381
|
Struct({
|
|
27318
27382
|
kind: Literal2("write_back"),
|
|
27319
|
-
milestone: optionalKey2(Literals(["started", "change_request_opened", "merged", "failed"])),
|
|
27383
|
+
milestone: optionalKey2(Literals(["started", "change_request_opened", "merged", "failed", "blocked"])),
|
|
27320
27384
|
changeRequestUrl: optionalKey2(String5)
|
|
27321
27385
|
})
|
|
27322
27386
|
])
|
|
@@ -27341,7 +27405,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
|
|
|
27341
27405
|
}),
|
|
27342
27406
|
error: RunnerRpcError
|
|
27343
27407
|
}), make29("ReadTranscripts", {
|
|
27344
|
-
payload: { lease: ProgramLease, step: String5, days: Int },
|
|
27408
|
+
payload: { lease: ProgramLease, step: String5, days: Int, teamId: optionalKey2(String5) },
|
|
27345
27409
|
success: Struct({
|
|
27346
27410
|
runs: ArraySchema(Struct({
|
|
27347
27411
|
runId: String5,
|
|
@@ -27355,8 +27419,17 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
|
|
|
27355
27419
|
sequence: Int,
|
|
27356
27420
|
kind: String5,
|
|
27357
27421
|
text: String5
|
|
27358
|
-
}))
|
|
27359
|
-
|
|
27422
|
+
})),
|
|
27423
|
+
rootRunId: optionalKey2(String5),
|
|
27424
|
+
omitted: optionalKey2(Int)
|
|
27425
|
+
})),
|
|
27426
|
+
artifactId: optionalKey2(String5),
|
|
27427
|
+
findings: optionalKey2(ArraySchema(Struct({
|
|
27428
|
+
key: String5,
|
|
27429
|
+
title: String5,
|
|
27430
|
+
taskId: optionalKey2(String5),
|
|
27431
|
+
taskKey: optionalKey2(String5)
|
|
27432
|
+
})))
|
|
27360
27433
|
}),
|
|
27361
27434
|
error: RunnerRpcError
|
|
27362
27435
|
}), make29("PipelineStatus", {
|
|
@@ -27457,7 +27530,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
|
|
|
27457
27530
|
success: Struct({
|
|
27458
27531
|
kind: Literals(["memory", "task"]),
|
|
27459
27532
|
id: String5,
|
|
27460
|
-
matched: optionalKey2(Boolean3)
|
|
27533
|
+
matched: optionalKey2(Boolean3),
|
|
27534
|
+
task: optionalKey2(Struct({ id: String5, active: Boolean3 }))
|
|
27461
27535
|
}),
|
|
27462
27536
|
error: RunnerRpcError
|
|
27463
27537
|
}), make29("ReadProject", {
|
|
@@ -30263,4 +30337,4 @@ var runKit = (config, identity, packages) => {
|
|
|
30263
30337
|
runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
|
|
30264
30338
|
};
|
|
30265
30339
|
// .kitman-build-entry.ts
|
|
30266
|
-
runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.
|
|
30340
|
+
runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.90" }, []);
|
package/dist/declarations.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
{
|
|
4
4
|
"id": "build",
|
|
5
5
|
"title": "Build",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.6.0",
|
|
7
7
|
"input": {
|
|
8
8
|
"type": "object",
|
|
9
9
|
"properties": {
|
|
@@ -538,6 +538,14 @@
|
|
|
538
538
|
"merge_change_request",
|
|
539
539
|
"claim",
|
|
540
540
|
"publish_release"
|
|
541
|
+
],
|
|
542
|
+
"ownCapabilities": [
|
|
543
|
+
"agent_work",
|
|
544
|
+
"verify",
|
|
545
|
+
"change_request",
|
|
546
|
+
"write_back",
|
|
547
|
+
"post_comment",
|
|
548
|
+
"approve_change_request"
|
|
541
549
|
]
|
|
542
550
|
},
|
|
543
551
|
{
|
|
@@ -664,6 +672,13 @@
|
|
|
664
672
|
"merge_change_request",
|
|
665
673
|
"claim",
|
|
666
674
|
"publish_release"
|
|
675
|
+
],
|
|
676
|
+
"ownCapabilities": [
|
|
677
|
+
"agent_work",
|
|
678
|
+
"verify",
|
|
679
|
+
"change_request",
|
|
680
|
+
"write_back",
|
|
681
|
+
"ask"
|
|
667
682
|
]
|
|
668
683
|
},
|
|
669
684
|
{
|
|
@@ -1010,6 +1025,15 @@
|
|
|
1010
1025
|
"approve_change_request",
|
|
1011
1026
|
"claim",
|
|
1012
1027
|
"publish_release"
|
|
1028
|
+
],
|
|
1029
|
+
"ownCapabilities": [
|
|
1030
|
+
"agent_work",
|
|
1031
|
+
"verify",
|
|
1032
|
+
"measure",
|
|
1033
|
+
"change_request",
|
|
1034
|
+
"write_back",
|
|
1035
|
+
"ask",
|
|
1036
|
+
"create_tasks"
|
|
1013
1037
|
]
|
|
1014
1038
|
},
|
|
1015
1039
|
{
|
|
@@ -1194,6 +1218,11 @@
|
|
|
1194
1218
|
"merge_change_request",
|
|
1195
1219
|
"claim",
|
|
1196
1220
|
"publish_release"
|
|
1221
|
+
],
|
|
1222
|
+
"ownCapabilities": [
|
|
1223
|
+
"agent_work",
|
|
1224
|
+
"ask",
|
|
1225
|
+
"create_tasks"
|
|
1197
1226
|
]
|
|
1198
1227
|
},
|
|
1199
1228
|
{
|
|
@@ -1488,6 +1517,18 @@
|
|
|
1488
1517
|
"approve_change_request",
|
|
1489
1518
|
"claim",
|
|
1490
1519
|
"publish_release"
|
|
1520
|
+
],
|
|
1521
|
+
"ownCapabilities": [
|
|
1522
|
+
"agent_work",
|
|
1523
|
+
"ask",
|
|
1524
|
+
"call",
|
|
1525
|
+
"verify",
|
|
1526
|
+
"change_request",
|
|
1527
|
+
"write_back",
|
|
1528
|
+
"create_tasks",
|
|
1529
|
+
"merge_change_request",
|
|
1530
|
+
"read_change_request",
|
|
1531
|
+
"post_comment"
|
|
1491
1532
|
]
|
|
1492
1533
|
},
|
|
1493
1534
|
{
|
|
@@ -1904,7 +1945,7 @@
|
|
|
1904
1945
|
{
|
|
1905
1946
|
"id": "hindsight",
|
|
1906
1947
|
"title": "Hindsight",
|
|
1907
|
-
"version": "1.
|
|
1948
|
+
"version": "1.1.0",
|
|
1908
1949
|
"input": {
|
|
1909
1950
|
"type": "object",
|
|
1910
1951
|
"properties": {
|
|
@@ -1993,6 +2034,11 @@
|
|
|
1993
2034
|
"items": {
|
|
1994
2035
|
"type": "string"
|
|
1995
2036
|
}
|
|
2037
|
+
},
|
|
2038
|
+
"recurrence": {
|
|
2039
|
+
"type": "integer",
|
|
2040
|
+
"minimum": -9007199254740991,
|
|
2041
|
+
"maximum": 9007199254740991
|
|
1996
2042
|
}
|
|
1997
2043
|
},
|
|
1998
2044
|
"required": [
|
|
@@ -2001,7 +2047,8 @@
|
|
|
2001
2047
|
"kind",
|
|
2002
2048
|
"id",
|
|
2003
2049
|
"matched",
|
|
2004
|
-
"runIds"
|
|
2050
|
+
"runIds",
|
|
2051
|
+
"recurrence"
|
|
2005
2052
|
],
|
|
2006
2053
|
"additionalProperties": true
|
|
2007
2054
|
}
|
|
@@ -2053,13 +2100,35 @@
|
|
|
2053
2100
|
],
|
|
2054
2101
|
"additionalProperties": true
|
|
2055
2102
|
}
|
|
2103
|
+
},
|
|
2104
|
+
"notStarted": {
|
|
2105
|
+
"type": "array",
|
|
2106
|
+
"items": {
|
|
2107
|
+
"type": "object",
|
|
2108
|
+
"properties": {
|
|
2109
|
+
"key": {
|
|
2110
|
+
"type": "string"
|
|
2111
|
+
},
|
|
2112
|
+
"reason": {
|
|
2113
|
+
"type": "string",
|
|
2114
|
+
"maxLength": 600,
|
|
2115
|
+
"description": "At most 600 characters."
|
|
2116
|
+
}
|
|
2117
|
+
},
|
|
2118
|
+
"required": [
|
|
2119
|
+
"key",
|
|
2120
|
+
"reason"
|
|
2121
|
+
],
|
|
2122
|
+
"additionalProperties": true
|
|
2123
|
+
}
|
|
2056
2124
|
}
|
|
2057
2125
|
},
|
|
2058
2126
|
"required": [
|
|
2059
2127
|
"summary",
|
|
2060
2128
|
"proposals",
|
|
2061
2129
|
"leftOut",
|
|
2062
|
-
"improvements"
|
|
2130
|
+
"improvements",
|
|
2131
|
+
"notStarted"
|
|
2063
2132
|
],
|
|
2064
2133
|
"additionalProperties": true,
|
|
2065
2134
|
"$defs": {}
|
|
@@ -2087,6 +2156,11 @@
|
|
|
2087
2156
|
"claim",
|
|
2088
2157
|
"publish_release"
|
|
2089
2158
|
],
|
|
2159
|
+
"ownCapabilities": [
|
|
2160
|
+
"read_transcripts",
|
|
2161
|
+
"agent_work",
|
|
2162
|
+
"propose"
|
|
2163
|
+
],
|
|
2090
2164
|
"schedule": {
|
|
2091
2165
|
"rule": {
|
|
2092
2166
|
"frequency": "weekly",
|
|
@@ -2614,6 +2688,18 @@
|
|
|
2614
2688
|
"approve_change_request",
|
|
2615
2689
|
"claim",
|
|
2616
2690
|
"publish_release"
|
|
2691
|
+
],
|
|
2692
|
+
"ownCapabilities": [
|
|
2693
|
+
"agent_work",
|
|
2694
|
+
"post_comment",
|
|
2695
|
+
"ask",
|
|
2696
|
+
"call",
|
|
2697
|
+
"verify",
|
|
2698
|
+
"change_request",
|
|
2699
|
+
"write_back",
|
|
2700
|
+
"read_change_request",
|
|
2701
|
+
"merge_change_request",
|
|
2702
|
+
"approve_change_request"
|
|
2617
2703
|
]
|
|
2618
2704
|
},
|
|
2619
2705
|
{
|
|
@@ -2913,6 +2999,18 @@
|
|
|
2913
2999
|
"claim",
|
|
2914
3000
|
"change_request",
|
|
2915
3001
|
"publish_release"
|
|
3002
|
+
],
|
|
3003
|
+
"ownCapabilities": [
|
|
3004
|
+
"agent_work",
|
|
3005
|
+
"read_change_request",
|
|
3006
|
+
"post_comment",
|
|
3007
|
+
"merge_change_request",
|
|
3008
|
+
"approve_change_request",
|
|
3009
|
+
"call",
|
|
3010
|
+
"write_back",
|
|
3011
|
+
"ask",
|
|
3012
|
+
"verify",
|
|
3013
|
+
"claim"
|
|
2916
3014
|
]
|
|
2917
3015
|
},
|
|
2918
3016
|
{
|
|
@@ -3114,6 +3212,13 @@
|
|
|
3114
3212
|
"claim",
|
|
3115
3213
|
"publish_release"
|
|
3116
3214
|
],
|
|
3215
|
+
"ownCapabilities": [
|
|
3216
|
+
"agent_work",
|
|
3217
|
+
"verify",
|
|
3218
|
+
"change_request",
|
|
3219
|
+
"read_change_request",
|
|
3220
|
+
"merge_change_request"
|
|
3221
|
+
],
|
|
3117
3222
|
"schedule": {
|
|
3118
3223
|
"rule": {
|
|
3119
3224
|
"frequency": "weekly",
|
|
@@ -3281,6 +3386,12 @@
|
|
|
3281
3386
|
"claim",
|
|
3282
3387
|
"publish_release",
|
|
3283
3388
|
"create_tasks"
|
|
3389
|
+
],
|
|
3390
|
+
"ownCapabilities": [
|
|
3391
|
+
"agent_work",
|
|
3392
|
+
"ask",
|
|
3393
|
+
"verify",
|
|
3394
|
+
"change_request"
|
|
3284
3395
|
]
|
|
3285
3396
|
}
|
|
3286
3397
|
],
|
|
@@ -3417,7 +3528,7 @@
|
|
|
3417
3528
|
"carried": [
|
|
3418
3529
|
{
|
|
3419
3530
|
"name": "@kitman-sh/software-engineering",
|
|
3420
|
-
"version": "0.10.
|
|
3531
|
+
"version": "0.10.90",
|
|
3421
3532
|
"setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
|
|
3422
3533
|
"loops": [
|
|
3423
3534
|
"build",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitman-sh/software-engineering",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.90",
|
|
4
4
|
"description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"tsconfig.json"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@kitman-sh/sdk": "0.10.
|
|
20
|
+
"@kitman-sh/sdk": "0.10.90",
|
|
21
21
|
"effect": "^4.1.2"
|
|
22
22
|
},
|
|
23
23
|
"kitman": {
|
|
24
24
|
"bundle": "dist/bundle.js",
|
|
25
|
-
"digest": "
|
|
25
|
+
"digest": "3ed2c0f768eacc6ba00523150124c71975f002972fa42839d40820d020bc4c59",
|
|
26
26
|
"protocolVersion": 5,
|
|
27
27
|
"declarations": "dist/declarations.json",
|
|
28
28
|
"setup": {
|
package/src/build.ts
CHANGED
|
@@ -403,12 +403,12 @@ const rally = (input: {
|
|
|
403
403
|
/**
|
|
404
404
|
* Implements a Task or words, reviews and fixes until the rally stops, gates on the evidence for the head, and opens
|
|
405
405
|
* the Run's ChangeRequest with the evidence, the claims and whatever it could not settle (ADR-0051). It writes the
|
|
406
|
-
* Run's milestones to its Task: started, ChangeRequest opened, and failed
|
|
407
|
-
* rebuilds run out go on the Task as a blocker before the Run fails.
|
|
406
|
+
* Run's milestones to its Task: started, ChangeRequest opened, and failed, or blocked instead of failed when findings
|
|
407
|
+
* still stand once full auto's rebuilds run out; those findings go on the Task as a blocker before the Run fails.
|
|
408
408
|
*/
|
|
409
409
|
const build = defineLoop({
|
|
410
410
|
id: 'build',
|
|
411
|
-
version: '2.
|
|
411
|
+
version: '2.6.0',
|
|
412
412
|
title: 'Build',
|
|
413
413
|
input: BuildInput,
|
|
414
414
|
output: BuildOutput,
|
|
@@ -612,6 +612,8 @@ const build = defineLoop({
|
|
|
612
612
|
].join('\n')
|
|
613
613
|
})
|
|
614
614
|
|
|
615
|
+
yield* Effect.ignore(writeBack('write-back:blocked', { milestone: 'blocked' }))
|
|
616
|
+
|
|
615
617
|
return yield* new BuildBlocked({
|
|
616
618
|
message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join('; ')}`
|
|
617
619
|
})
|
|
@@ -658,7 +660,13 @@ const build = defineLoop({
|
|
|
658
660
|
...(landed === undefined ? undefined : { landed }),
|
|
659
661
|
next: { changeRequestId: opened.id }
|
|
660
662
|
}
|
|
661
|
-
}).pipe(
|
|
663
|
+
}).pipe(
|
|
664
|
+
Effect.tapError(error =>
|
|
665
|
+
error instanceof BuildBlocked
|
|
666
|
+
? Effect.void
|
|
667
|
+
: Effect.ignore(writeBack('write-back:failed', { milestone: 'failed' }))
|
|
668
|
+
)
|
|
669
|
+
)
|
|
662
670
|
})
|
|
663
671
|
|
|
664
672
|
export default build
|
package/src/hindsight.ts
CHANGED
|
@@ -62,7 +62,9 @@ const Proposal = Schema.Struct({
|
|
|
62
62
|
id: Schema.String,
|
|
63
63
|
/** It matched an earlier proposal or open Task, which it added to instead. */
|
|
64
64
|
matched: Schema.Boolean,
|
|
65
|
-
runIds: Schema.Array(Schema.String)
|
|
65
|
+
runIds: Schema.Array(Schema.String),
|
|
66
|
+
/** How many top-level Runs it recurred in: a Run and its Child Runs count once. */
|
|
67
|
+
recurrence: Schema.Int
|
|
66
68
|
})
|
|
67
69
|
|
|
68
70
|
const Output = Schema.Struct({
|
|
@@ -73,20 +75,62 @@ const Output = Schema.Struct({
|
|
|
73
75
|
leftOut: Schema.Array(Schema.Struct({ key: Schema.String, reason: Reason })),
|
|
74
76
|
improvements: Schema.Array(
|
|
75
77
|
Schema.Struct({ key: Schema.String, loop: Schema.Literals(['errand', 'build']), outcome: Schema.String })
|
|
76
|
-
)
|
|
78
|
+
),
|
|
79
|
+
/** Findings with a fix that no Run started on, and why. */
|
|
80
|
+
notStarted: Schema.Array(Schema.Struct({ key: Schema.String, reason: Reason }))
|
|
77
81
|
})
|
|
78
82
|
|
|
79
|
-
type
|
|
83
|
+
type Read = TranscriptsResult
|
|
84
|
+
|
|
85
|
+
type ReadRun = Read['runs'][number]
|
|
86
|
+
|
|
87
|
+
const oneLine = (text: string) => text.replace(/\s*\n\s*/g, ' ⏎ ')
|
|
88
|
+
|
|
89
|
+
const rootOf = (run: ReadRun) => run.rootRunId ?? run.runId
|
|
90
|
+
|
|
91
|
+
/** The read as a compact digest: one line per Run, per step attempt and per entry. */
|
|
92
|
+
const digest = (runs: readonly ReadRun[]) =>
|
|
93
|
+
runs
|
|
94
|
+
.flatMap(run => [
|
|
95
|
+
[
|
|
96
|
+
`Run ${run.runId}`,
|
|
97
|
+
run.loopId,
|
|
98
|
+
run.status ?? 'settled',
|
|
99
|
+
...(rootOf(run) === run.runId ? [] : [`part of ${rootOf(run)}`]),
|
|
100
|
+
...(run.teamId === undefined ? [] : [`team ${run.teamId}`]),
|
|
101
|
+
...(run.retried === true ? ['retried'] : []),
|
|
102
|
+
...(run.failure === undefined ? [] : [`failure: ${oneLine(run.failure)}`]),
|
|
103
|
+
...(run.omitted === undefined ? [] : [`${run.omitted} entries left out`])
|
|
104
|
+
].join(' · '),
|
|
105
|
+
...run.entries.flatMap((entry, index) => [
|
|
106
|
+
...(run.entries[index - 1]?.stepAttemptId === entry.stepAttemptId ? [] : [` attempt ${entry.stepAttemptId}`]),
|
|
107
|
+
` ${entry.sequence} ${entry.kind}: ${oneLine(entry.text)}`
|
|
108
|
+
])
|
|
109
|
+
])
|
|
110
|
+
.join('\n')
|
|
111
|
+
|
|
112
|
+
const earlier = (findings: NonNullable<Read['findings']>) =>
|
|
113
|
+
findings.length === 0
|
|
114
|
+
? 'No earlier finding is open.'
|
|
115
|
+
: [
|
|
116
|
+
'Earlier findings still open, by key. When a problem is one of these, give it that key exactly; a new key only for a new problem:',
|
|
117
|
+
...findings.map(
|
|
118
|
+
found =>
|
|
119
|
+
`- ${found.key}: ${oneLine(found.title)} (${found.taskKey === undefined ? 'proposal waiting for a decision' : `open Task ${found.taskKey}`})`
|
|
120
|
+
)
|
|
121
|
+
].join('\n')
|
|
80
122
|
|
|
81
|
-
const prompt = (
|
|
123
|
+
const prompt = (read: Read, days: number) =>
|
|
82
124
|
[
|
|
83
|
-
`These Runs settled in the last ${days} days, each with its status: a failed one with its failure, one with a retried Step marked retried. Find what keeps going wrong in more than one
|
|
84
|
-
'
|
|
85
|
-
|
|
125
|
+
`These Runs settled in the last ${days} days, each with its status: a failed one with its failure, one with a retried Step marked retried. Find what keeps going wrong in more than one piece of work: a failure, or in Runs that completed, a wasted step, a wrong turn, a check run again and again, or work redone. Fix the cause, not the symptom.`,
|
|
126
|
+
'A Run "part of" another is one of its Child Runs, such as a Build\'s review, land or fix: a Run and its Child Runs are one piece of work, and count once. Each step attempt is a digest from start to end, its tool output cut short; each entry is "sequence kind: text".',
|
|
127
|
+
'```text',
|
|
128
|
+
digest(read.runs),
|
|
86
129
|
'```',
|
|
130
|
+
earlier(read.findings ?? []),
|
|
87
131
|
`Give each finding a category: ${categories.join(', ')}. Use kitman when Kitman itself misbehaved: a Run that stalled, parked or needed rescue for a reason in Kitman, not in the work.`,
|
|
88
132
|
'Give each a stable kebab-case key naming the problem, not the week: the same problem must get the same key next time.',
|
|
89
|
-
"Propose Memory when agents can avoid it by knowing something, or a Task when something has to change; when the change is clear, say how to fix it as an errand (small) or a build (a feature). Cite every Transcript point (runId, stepAttemptId, sequence) it shows in. Cite what happened: tool calls and results, files and answers. An agent's own messages are not evidence. Leave out anything seen in one
|
|
133
|
+
"Propose Memory when agents can avoid it by knowing something, or a Task when something has to change; when the change is clear, say how to fix it as an errand (small) or a build (a feature). Cite every Transcript point (runId, stepAttemptId, sequence) it shows in. Cite what happened: tool calls and results, files and answers. An agent's own messages are not evidence. Leave out anything seen in one piece of work only.",
|
|
90
134
|
"Never quote a person's words into a lesson."
|
|
91
135
|
].join('\n\n')
|
|
92
136
|
|
|
@@ -100,14 +144,16 @@ const shared = (cited: readonly ReadRun[], field: 'teamId') => {
|
|
|
100
144
|
return values.size === 1 ? only : undefined
|
|
101
145
|
}
|
|
102
146
|
|
|
147
|
+
type Judged =
|
|
148
|
+
| { readonly request: ProposeRequest; readonly recurrence: number }
|
|
149
|
+
| { readonly request?: undefined; readonly reason: string }
|
|
150
|
+
|
|
103
151
|
/**
|
|
104
152
|
* What a finding proposes, citing only evidence that was read (not an agent's own messages), or why it is left out
|
|
105
|
-
* when that evidence falls in fewer than two Runs.
|
|
153
|
+
* when that evidence falls in fewer than two top-level Runs. A Task goes to the cited Runs' shared Team, else the Team
|
|
154
|
+
* read; Kitman gives one with neither the Run's own.
|
|
106
155
|
*/
|
|
107
|
-
const proposal = (
|
|
108
|
-
finding: Finding,
|
|
109
|
-
runs: readonly ReadRun[]
|
|
110
|
-
): { readonly request: ProposeRequest } | { readonly request?: undefined; readonly reason: string } => {
|
|
156
|
+
const proposal = (finding: Finding, runs: readonly ReadRun[], teamId: string | undefined): Judged => {
|
|
111
157
|
const evidence = new Set(
|
|
112
158
|
runs.flatMap(run =>
|
|
113
159
|
run.entries.flatMap(entry =>
|
|
@@ -118,6 +164,8 @@ const proposal = (
|
|
|
118
164
|
)
|
|
119
165
|
)
|
|
120
166
|
|
|
167
|
+
const roots = new Map(runs.map(run => [run.runId, rootOf(run)]))
|
|
168
|
+
|
|
121
169
|
const citations = [
|
|
122
170
|
...new Map(
|
|
123
171
|
finding.citations.filter(cited => evidence.has(point(cited))).map(cited => [point(cited), cited])
|
|
@@ -125,43 +173,64 @@ const proposal = (
|
|
|
125
173
|
]
|
|
126
174
|
|
|
127
175
|
const runIds = new Set(citations.map(cited => cited.runId))
|
|
176
|
+
const pieces = new Set(citations.map(cited => roots.get(cited.runId)))
|
|
128
177
|
const [first, ...rest] = citations
|
|
129
178
|
|
|
130
179
|
if (first === undefined)
|
|
131
180
|
return { reason: 'It cites no evidence that was read: an agent’s own words or a summary are not evidence' }
|
|
132
181
|
|
|
133
|
-
if (
|
|
182
|
+
if (pieces.size < 2) return { reason: 'It was seen in one Run only, counting a Run with its Child Runs once' }
|
|
134
183
|
|
|
135
|
-
const
|
|
184
|
+
const citedTeam = shared(
|
|
136
185
|
runs.filter(run => runIds.has(run.runId)),
|
|
137
186
|
'teamId'
|
|
138
187
|
)
|
|
139
188
|
|
|
140
|
-
if (finding.kind === 'memory' &&
|
|
141
|
-
return {
|
|
189
|
+
if (finding.kind === 'memory' && citedTeam !== undefined)
|
|
190
|
+
return {
|
|
191
|
+
request: { kind: 'memory', teamId: citedTeam, content: finding.lesson, citations: [first, ...rest] },
|
|
192
|
+
recurrence: pieces.size
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const team = citedTeam ?? teamId
|
|
142
196
|
|
|
143
197
|
return {
|
|
144
198
|
request: {
|
|
145
199
|
kind: 'task',
|
|
146
200
|
title: finding.lesson,
|
|
147
201
|
description: finding.detail ?? finding.lesson,
|
|
148
|
-
...(
|
|
202
|
+
...(team === undefined ? undefined : { teamId: team }),
|
|
149
203
|
key: finding.key,
|
|
150
204
|
citations: [first, ...rest]
|
|
151
|
-
}
|
|
205
|
+
},
|
|
206
|
+
recurrence: pieces.size
|
|
152
207
|
}
|
|
153
208
|
}
|
|
154
209
|
|
|
210
|
+
/** Why a finding with a fix had no Run started on it. */
|
|
211
|
+
const notStartedReason = (
|
|
212
|
+
finding: { readonly kind: 'memory' | 'task'; readonly task?: { readonly active: boolean } | undefined },
|
|
213
|
+
wanted: number
|
|
214
|
+
) =>
|
|
215
|
+
finding.kind === 'memory'
|
|
216
|
+
? 'It became Memory, which has no Task to start on'
|
|
217
|
+
: finding.task === undefined
|
|
218
|
+
? 'Its Task waits for a person to accept the proposal'
|
|
219
|
+
: finding.task.active
|
|
220
|
+
? 'A Run is already working on its Task'
|
|
221
|
+
: `Only ${wanted} ${wanted === 1 ? 'improvement was' : 'improvements were'} asked for, and findings that recurred in more top-level Runs went first`
|
|
222
|
+
|
|
155
223
|
/**
|
|
156
224
|
* Reads every Run that settled in the last week (or `days`), of one Team or every Team the person it acts for may read,
|
|
157
|
-
* completed ones too, and proposes Memory and Tasks for what went wrong in at least two
|
|
225
|
+
* completed ones too, as a bounded digest, and proposes Memory and Tasks for what went wrong in at least two top-level
|
|
226
|
+
* Runs, each with a category and a stable key; the investigator sees earlier open findings' keys to reuse. A key that
|
|
158
227
|
* matches an open Task or a waiting proposal adds the new Runs there instead of a duplicate. With `improvements`, that
|
|
159
|
-
* many findings
|
|
160
|
-
* becomes a Task.
|
|
228
|
+
* many findings that matched an open Task no Run works on are started on it as Errands or Builds, those that recurred
|
|
229
|
+
* in the most top-level Runs first. Memory belongs to one Team, so a lesson from Runs in several becomes a Task.
|
|
161
230
|
*/
|
|
162
231
|
export default defineLoop({
|
|
163
232
|
id: 'hindsight',
|
|
164
|
-
version: '1.
|
|
233
|
+
version: '1.1.0',
|
|
165
234
|
title: 'Hindsight',
|
|
166
235
|
input: Input,
|
|
167
236
|
output: Output,
|
|
@@ -174,53 +243,85 @@ export default defineLoop({
|
|
|
174
243
|
run: input =>
|
|
175
244
|
Effect.gen(function* () {
|
|
176
245
|
const days = input.days ?? 7
|
|
177
|
-
const read = yield* transcripts('read', { days })
|
|
178
|
-
const runs = read.runs.filter(run => input.teamId === undefined || run.teamId === input.teamId)
|
|
179
246
|
|
|
180
|
-
|
|
247
|
+
const read = yield* transcripts('read', {
|
|
248
|
+
days,
|
|
249
|
+
...(input.teamId === undefined ? undefined : { teamId: input.teamId })
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
const runs = read.runs
|
|
253
|
+
const pieces = new Set(runs.map(rootOf)).size
|
|
254
|
+
|
|
255
|
+
if (pieces < 2)
|
|
181
256
|
return {
|
|
182
|
-
summary: `Nothing recurred: ${
|
|
257
|
+
summary: `Nothing recurred: ${pieces === 0 ? 'no Run' : 'one Run'} settled in the last ${days} days.`,
|
|
183
258
|
proposals: [],
|
|
184
259
|
leftOut: [],
|
|
185
|
-
improvements: []
|
|
260
|
+
improvements: [],
|
|
261
|
+
notStarted: []
|
|
186
262
|
}
|
|
187
263
|
|
|
188
264
|
const { findings } = yield* agentWork('find', {
|
|
189
265
|
agent: 'investigator',
|
|
190
|
-
prompt: prompt(
|
|
266
|
+
prompt: prompt(read, days),
|
|
191
267
|
output: Findings
|
|
192
268
|
})
|
|
193
269
|
|
|
194
|
-
const judged = findings.map(finding => ({ finding, judged: proposal(finding, runs) }))
|
|
270
|
+
const judged = findings.map(finding => ({ finding, judged: proposal(finding, runs, input.teamId) }))
|
|
195
271
|
|
|
196
272
|
const leftOut = judged.flatMap(({ finding, judged }) =>
|
|
197
273
|
judged.request === undefined ? [{ key: finding.key, reason: judged.reason }] : []
|
|
198
274
|
)
|
|
199
275
|
|
|
200
276
|
const kept = judged.flatMap(({ finding, judged }) =>
|
|
201
|
-
judged.request === undefined ? [] : [{ finding, request: judged.request }]
|
|
277
|
+
judged.request === undefined ? [] : [{ finding, request: judged.request, recurrence: judged.recurrence }]
|
|
202
278
|
)
|
|
203
279
|
|
|
204
|
-
const
|
|
205
|
-
Effect.map(propose(`propose:${finding.key}`, request), made => ({
|
|
206
|
-
key: finding.key,
|
|
207
|
-
category: finding.category,
|
|
208
|
-
kind: made.kind,
|
|
209
|
-
id: made.id,
|
|
210
|
-
matched: made.matched === true,
|
|
211
|
-
runIds: [...new Set(request.citations.map(cited => cited.runId))]
|
|
212
|
-
}))
|
|
280
|
+
const made = yield* Effect.forEach(kept, kept =>
|
|
281
|
+
Effect.map(propose(`propose:${kept.finding.key}`, kept.request), made => ({ ...kept, made }))
|
|
213
282
|
)
|
|
214
283
|
|
|
215
|
-
const
|
|
216
|
-
|
|
284
|
+
const proposals = made.map(({ finding, request, recurrence, made }) => ({
|
|
285
|
+
key: finding.key,
|
|
286
|
+
category: finding.category,
|
|
287
|
+
kind: made.kind,
|
|
288
|
+
id: made.id,
|
|
289
|
+
matched: made.matched === true,
|
|
290
|
+
runIds: [...new Set(request.citations.map(cited => cited.runId))],
|
|
291
|
+
recurrence
|
|
292
|
+
}))
|
|
293
|
+
|
|
294
|
+
const wanted = input.improvements ?? 0
|
|
295
|
+
|
|
296
|
+
const fixable = made.flatMap(({ finding, recurrence, made }) =>
|
|
297
|
+
finding.fix === undefined
|
|
298
|
+
? []
|
|
299
|
+
: [{ key: finding.key, kind: made.kind, fix: finding.fix, recurrence, task: made.task }]
|
|
217
300
|
)
|
|
218
301
|
|
|
219
|
-
const
|
|
302
|
+
const startable = fixable
|
|
303
|
+
.flatMap(finding =>
|
|
304
|
+
finding.task === undefined || finding.task.active ? [] : [{ ...finding, taskId: finding.task.id }]
|
|
305
|
+
)
|
|
306
|
+
.toSorted((a, b) => b.recurrence - a.recurrence)
|
|
307
|
+
|
|
308
|
+
const chosen = startable.slice(0, wanted)
|
|
309
|
+
const chosenKeys = new Set(chosen.map(finding => finding.key))
|
|
310
|
+
|
|
311
|
+
const notStarted =
|
|
312
|
+
wanted === 0
|
|
313
|
+
? []
|
|
314
|
+
: fixable.flatMap(finding =>
|
|
315
|
+
chosenKeys.has(finding.key) ? [] : [{ key: finding.key, reason: notStartedReason(finding, wanted) }]
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
const improvements = yield* Effect.forEach(chosen, finding => {
|
|
319
|
+
const on = { words: finding.fix.words, taskId: finding.taskId }
|
|
320
|
+
|
|
220
321
|
const started =
|
|
221
322
|
finding.fix.size === 'errand'
|
|
222
|
-
? Effect.map(call(`improve:${finding.key}`, errand,
|
|
223
|
-
: Effect.map(call(`improve:${finding.key}`, build,
|
|
323
|
+
? Effect.map(call(`improve:${finding.key}`, errand, on), done => done.status)
|
|
324
|
+
: Effect.map(call(`improve:${finding.key}`, build, on), built => built.stopped)
|
|
224
325
|
|
|
225
326
|
return started.pipe(
|
|
226
327
|
Effect.catchTag('ChildFailed', failed => Effect.succeed(`failed: ${failed.reason}`)),
|
|
@@ -237,7 +338,8 @@ export default defineLoop({
|
|
|
237
338
|
: `${proposals.length} recurring ${proposals.length === 1 ? 'problem' : 'problems'}: ${fresh} proposed, ${proposals.length - fresh} added to earlier work.`,
|
|
238
339
|
proposals,
|
|
239
340
|
leftOut,
|
|
240
|
-
improvements
|
|
341
|
+
improvements,
|
|
342
|
+
notStarted
|
|
241
343
|
}
|
|
242
344
|
})
|
|
243
345
|
})
|