@kitman-sh/software-engineering 0.10.89 → 0.10.91

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 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 }
@@ -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 });
@@ -23960,22 +23973,50 @@ var Proposal2 = Struct({
23960
23973
  kind: Literals(["memory", "task"]),
23961
23974
  id: String5,
23962
23975
  matched: Boolean3,
23963
- runIds: ArraySchema(String5)
23976
+ runIds: ArraySchema(String5),
23977
+ recurrence: Int
23964
23978
  });
23965
23979
  var Output11 = Struct({
23966
23980
  summary: OneSentence,
23967
23981
  proposals: ArraySchema(Proposal2),
23968
23982
  leftOut: ArraySchema(Struct({ key: String5, reason: Reason })),
23969
- improvements: ArraySchema(Struct({ key: String5, loop: Literals(["errand", "build"]), outcome: String5 }))
23970
- });
23971
- var prompt4 = (runs, days) => [
23972
- `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 Run: 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.`,
23973
- "```json",
23974
- JSON.stringify(runs, null, 2),
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),
23975
24015
  "```",
24016
+ earlier(read.findings ?? []),
23976
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.`,
23977
24018
  "Give each a stable kebab-case key naming the problem, not the week: the same problem must get the same key next time.",
23978
- "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 Run only.",
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.",
23979
24020
  "Never quote a person's words into a lesson."
23980
24021
  ].join(`
23981
24022
 
@@ -23986,34 +24027,42 @@ var shared = (cited, field) => {
23986
24027
  const [only] = values;
23987
24028
  return values.size === 1 ? only : undefined;
23988
24029
  };
23989
- var proposal = (finding, runs) => {
24030
+ var proposal = (finding, runs, teamId) => {
23990
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)]));
23991
24033
  const citations = [
23992
24034
  ...new Map(finding.citations.filter((cited) => evidence.has(point(cited))).map((cited) => [point(cited), cited])).values()
23993
24035
  ];
23994
24036
  const runIds = new Set(citations.map((cited) => cited.runId));
24037
+ const pieces = new Set(citations.map((cited) => roots.get(cited.runId)));
23995
24038
  const [first, ...rest] = citations;
23996
24039
  if (first === undefined)
23997
24040
  return { reason: "It cites no evidence that was read: an agent\u2019s own words or a summary are not evidence" };
23998
- if (runIds.size < 2)
23999
- return { reason: "It was seen in one Run only" };
24000
- const teamId = shared(runs.filter((run) => runIds.has(run.runId)), "teamId");
24001
- if (finding.kind === "memory" && teamId !== undefined)
24002
- return { request: { kind: "memory", teamId, content: finding.lesson, citations: [first, ...rest] } };
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;
24003
24050
  return {
24004
24051
  request: {
24005
24052
  kind: "task",
24006
24053
  title: finding.lesson,
24007
24054
  description: finding.detail ?? finding.lesson,
24008
- ...teamId === undefined ? undefined : { teamId },
24055
+ ...team === undefined ? undefined : { teamId: team },
24009
24056
  key: finding.key,
24010
24057
  citations: [first, ...rest]
24011
- }
24058
+ },
24059
+ recurrence: pieces.size
24012
24060
  };
24013
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`;
24014
24063
  var hindsight_default = defineLoop({
24015
24064
  id: "hindsight",
24016
- version: "1.0.0",
24065
+ version: "1.1.0",
24017
24066
  title: "Hindsight",
24018
24067
  input: Input10,
24019
24068
  output: Output11,
@@ -24025,34 +24074,47 @@ var hindsight_default = defineLoop({
24025
24074
  calls: () => [errand_default, build_default],
24026
24075
  run: (input) => gen2(function* () {
24027
24076
  const days = input.days ?? 7;
24028
- const read = yield* transcripts("read", { days });
24029
- const runs = read.runs.filter((run) => input.teamId === undefined || run.teamId === input.teamId);
24030
- if (runs.length < 2)
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)
24031
24084
  return {
24032
- summary: `Nothing recurred: ${runs.length === 0 ? "no Run" : "one Run"} settled in the last ${days} days.`,
24085
+ summary: `Nothing recurred: ${pieces === 0 ? "no Run" : "one Run"} settled in the last ${days} days.`,
24033
24086
  proposals: [],
24034
24087
  leftOut: [],
24035
- improvements: []
24088
+ improvements: [],
24089
+ notStarted: []
24036
24090
  };
24037
24091
  const { findings } = yield* agentWork("find", {
24038
24092
  agent: "investigator",
24039
- prompt: prompt4(runs, days),
24093
+ prompt: prompt4(read, days),
24040
24094
  output: Findings
24041
24095
  });
24042
- const judged = findings.map((finding) => ({ finding, judged: proposal(finding, runs) }));
24096
+ const judged = findings.map((finding) => ({ finding, judged: proposal(finding, runs, input.teamId) }));
24043
24097
  const leftOut = judged.flatMap(({ finding, judged }) => judged.request === undefined ? [{ key: finding.key, reason: judged.reason }] : []);
24044
- const kept = judged.flatMap(({ finding, judged }) => judged.request === undefined ? [] : [{ finding, request: judged.request }]);
24045
- const proposals = yield* forEach2(kept, ({ finding, request }) => map8(propose(`propose:${finding.key}`, request), (made) => ({
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 }) => ({
24046
24101
  key: finding.key,
24047
24102
  category: finding.category,
24048
24103
  kind: made.kind,
24049
24104
  id: made.id,
24050
24105
  matched: made.matched === true,
24051
- runIds: [...new Set(request.citations.map((cited) => cited.runId))]
24052
- })));
24053
- const fixable = kept.flatMap(({ finding }) => finding.fix === undefined ? [] : [{ ...finding, fix: finding.fix }]);
24054
- const improvements = yield* forEach2(fixable.slice(0, input.improvements ?? 0), (finding) => {
24055
- const started = finding.fix.size === "errand" ? map8(call(`improve:${finding.key}`, errand_default, { words: finding.fix.words }), (done) => done.status) : map8(call(`improve:${finding.key}`, build_default, { words: finding.fix.words }), (built) => built.stopped);
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);
24056
24118
  return started.pipe(catchTag2("ChildFailed", (failed) => succeed7(`failed: ${failed.reason}`)), map8((outcome) => ({ key: finding.key, loop: finding.fix.size, outcome })));
24057
24119
  });
24058
24120
  const fresh = proposals.filter((made) => !made.matched).length;
@@ -24060,7 +24122,8 @@ var hindsight_default = defineLoop({
24060
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.`,
24061
24123
  proposals,
24062
24124
  leftOut,
24063
- improvements
24125
+ improvements,
24126
+ notStarted
24064
24127
  };
24065
24128
  })
24066
24129
  });
@@ -27342,7 +27405,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27342
27405
  }),
27343
27406
  error: RunnerRpcError
27344
27407
  }), make29("ReadTranscripts", {
27345
- payload: { lease: ProgramLease, step: String5, days: Int },
27408
+ payload: { lease: ProgramLease, step: String5, days: Int, teamId: optionalKey2(String5) },
27346
27409
  success: Struct({
27347
27410
  runs: ArraySchema(Struct({
27348
27411
  runId: String5,
@@ -27356,8 +27419,17 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27356
27419
  sequence: Int,
27357
27420
  kind: String5,
27358
27421
  text: String5
27359
- }))
27360
- }))
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
+ })))
27361
27433
  }),
27362
27434
  error: RunnerRpcError
27363
27435
  }), make29("PipelineStatus", {
@@ -27458,7 +27530,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27458
27530
  success: Struct({
27459
27531
  kind: Literals(["memory", "task"]),
27460
27532
  id: String5,
27461
- matched: optionalKey2(Boolean3)
27533
+ matched: optionalKey2(Boolean3),
27534
+ task: optionalKey2(Struct({ id: String5, active: Boolean3 }))
27462
27535
  }),
27463
27536
  error: RunnerRpcError
27464
27537
  }), make29("ReadProject", {
@@ -30264,4 +30337,4 @@ var runKit = (config, identity, packages) => {
30264
30337
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30265
30338
  };
30266
30339
  // .kitman-build-entry.ts
30267
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.89" }, []);
30340
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.91" }, []);
@@ -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.0.0",
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.89",
3531
+ "version": "0.10.91",
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.89",
3
+ "version": "0.10.91",
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.89",
20
+ "@kitman-sh/sdk": "0.10.91",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "758a06a41fdf6cd627ab650fe1292143b0b33b32d3b5a8f2d1035399ae67bc65",
25
+ "digest": "59d1513c526ad394e8733d33c5b2e2137e5eb33ad65c020ffe5f23692697254c",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
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 ReadRun = TranscriptsResult['runs'][number]
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 = (runs: readonly ReadRun[], days: number) =>
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 Run: 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.`,
84
- '```json',
85
- JSON.stringify(runs, null, 2),
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 Run only.",
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 (runIds.size < 2) return { reason: 'It was seen in one Run only' }
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 teamId = shared(
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' && teamId !== undefined)
141
- return { request: { kind: 'memory', teamId, content: finding.lesson, citations: [first, ...rest] } }
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
- ...(teamId === undefined ? undefined : { teamId }),
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, each with a category and a stable key. A key that
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 are started as Errands or Builds. Memory belongs to one Team, so a lesson from Runs in several
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.0.0',
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
- if (runs.length < 2)
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: ${runs.length === 0 ? 'no Run' : 'one Run'} settled in the last ${days} days.`,
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(runs, days),
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 proposals = yield* Effect.forEach(kept, ({ finding, request }) =>
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 fixable = kept.flatMap(({ finding }) =>
216
- finding.fix === undefined ? [] : [{ ...finding, fix: finding.fix }]
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 improvements = yield* Effect.forEach(fixable.slice(0, input.improvements ?? 0), finding => {
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, { words: finding.fix.words }), done => done.status)
223
- : Effect.map(call(`improve:${finding.key}`, build, { words: finding.fix.words }), built => built.stopped)
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
  })