@amykit/agent-kit 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @amykit/agent-kit
2
+
3
+ The part of "being an agent" that is the same whichever harness answers.
4
+
5
+ Not a plugin. A library the harness plugins share, so that adding a harness
6
+ means teaching amy a **command line**, not re-teaching it the job.
7
+
8
+ ## What is here
9
+
10
+ **`Harness`** is the whole surface a harness has to implement:
11
+
12
+ ```ts
13
+ interface Harness {
14
+ readonly name: string;
15
+ ask(prompt: string, cwd: string): Promise<HarnessReply>;
16
+ }
17
+ ```
18
+
19
+ One method. Everything else about being useful to a ticket lives in
20
+ `HarnessAgent`, which turns that one method into the `agent` port: the triage,
21
+ implement and review-answering prompts, the JSON the replies are read out of,
22
+ and the git dance around each call.
23
+
24
+ **`contributeTiers`** adds one agent per model tier to the collection the
25
+ relay reads. The naming lives here rather than in each plugin because it is a
26
+ contract: `claude:opus` is what an operator writes in a ladder, so three
27
+ plugins inventing three conventions would make the config unlearnable.
28
+
29
+ ## Why a harness contributes instead of mounting
30
+
31
+ A port has exactly one owner. Three harnesses that each mounted `agent` would
32
+ refuse to mount together, which is the correct behaviour for a port and the
33
+ wrong outcome here.
34
+
35
+ So a harness contributes a `NamedAgent` and `@amykit/plugin-agent-relay` is the
36
+ only thing that mounts the port. A single-harness install goes through the
37
+ relay too, with a ladder one rung long and nothing special about that case.
38
+
39
+ `harness` and `model` are declared on each `NamedAgent` rather than discovered
40
+ from a result, because the relay has to decide **where to go next** before it
41
+ runs anything.
42
+
43
+ ## Two decisions inherited by every harness
44
+
45
+ **A clean exit that changed nothing is a failure.** The ticket asked for work.
46
+ Reporting success would send an empty pull request to a reviewer.
47
+
48
+ **An unanswered review comment becomes a disagreement, not a silence.** A
49
+ comment the agent did not answer is pushed to the owner rather than dropped.
@@ -0,0 +1,39 @@
1
+ import { AgentResult, Git, Harness, ReviewThread } from "@amykit/core";
2
+ import { Agent, AttemptOutcome, ThreadVerdict, Ticket, TriageOutcome } from "@amykit/workflow-ticket-to-qa";
3
+ export interface HarnessAgentConfig {
4
+ /**
5
+ * Extra guidance to append when answering a particular reviewer, keyed by
6
+ * their host login. A reviewer with known habits is cheaper to satisfy on
7
+ * the first pass than on the third.
8
+ */
9
+ reviewerHints?: Readonly<Record<string, string>>;
10
+ /**
11
+ * A skill to hand the step to, instead of amy asking in its own words.
12
+ *
13
+ * The step's own instructions still follow the invocation, because the
14
+ * answer has to arrive in the same shape whoever does the work.
15
+ */
16
+ skill?: string;
17
+ }
18
+ /**
19
+ * An agent for a ticket, over any harness.
20
+ *
21
+ * Every call runs in the ticket's own checkout, on the branch the tracker
22
+ * named, and anything the harness leaves behind is committed and pushed. The
23
+ * machine's notion of "implemented" means the work is on the remote, because
24
+ * that is what a pull request can be opened against.
25
+ */
26
+ export declare class HarnessAgent implements Agent {
27
+ private readonly harness;
28
+ private readonly git;
29
+ private readonly config;
30
+ constructor(harness: Harness, git: Git, config?: HarnessAgentConfig);
31
+ triage(ticket: Ticket): Promise<AgentResult<TriageOutcome>>;
32
+ implement(ticket: Ticket, retryContext?: string): Promise<AgentResult<AttemptOutcome>>;
33
+ addressThreads(ticket: Ticket, threads: readonly ReviewThread[], from: "automated" | "human"): Promise<AgentResult<ThreadVerdict[]>>;
34
+ private threadPrompt;
35
+ private ask;
36
+ /** The prompt, addressed to a skill when one was named. */
37
+ private invoke;
38
+ }
39
+ //# sourceMappingURL=HarnessAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HarnessAgent.d.ts","sourceRoot":"","sources":["../src/HarnessAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAgB,YAAY,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EACL,KAAK,EACL,cAAc,EACd,aAAa,EACb,MAAM,EACN,aAAa,EACd,MAAM,+BAA+B,CAAC;AAGvC,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAWD;;;;;;;GAOG;AACH,qBAAa,YAAa,YAAW,KAAK;IAEtC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,EACR,MAAM,GAAE,kBAAuB;IAG5C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IA4C3D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAuDtF,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,IAAI,EAAE,WAAW,GAAG,OAAO,GAC1B,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC;IAoCxC,OAAO,CAAC,YAAY;IAoCpB,OAAO,CAAC,GAAG;IAMX,2DAA2D;IAC3D,OAAO,CAAC,MAAM;CAGf"}
@@ -0,0 +1,161 @@
1
+ import { extractJson } from "./json.js";
2
+ /**
3
+ * An agent for a ticket, over any harness.
4
+ *
5
+ * Every call runs in the ticket's own checkout, on the branch the tracker
6
+ * named, and anything the harness leaves behind is committed and pushed. The
7
+ * machine's notion of "implemented" means the work is on the remote, because
8
+ * that is what a pull request can be opened against.
9
+ */
10
+ export class HarnessAgent {
11
+ harness;
12
+ git;
13
+ config;
14
+ constructor(harness, git, config = {}) {
15
+ this.harness = harness;
16
+ this.git = git;
17
+ this.config = config;
18
+ }
19
+ async triage(ticket) {
20
+ const reply = await this.ask(ticket, [
21
+ `You are deciding whether a ticket can be implemented as written.`,
22
+ ``,
23
+ `Ticket ${ticket.id}: ${ticket.title}`,
24
+ `Tracker: ${ticket.url}`,
25
+ ``,
26
+ `Read the ticket and enough of this repository to judge it. Answer with a`,
27
+ `single JSON object and nothing else:`,
28
+ ``,
29
+ `{"clear": true}`,
30
+ ``,
31
+ `if you could start implementing right now, or:`,
32
+ ``,
33
+ `{"clear": false, "questions": ["...", "..."]}`,
34
+ ``,
35
+ `listing only questions that genuinely block the work. A question you`,
36
+ `could answer yourself by reading the code is not a blocking question.`,
37
+ ].join("\n"));
38
+ // A run that did not complete has no answer to parse, and this returns
39
+ // rather than throwing so that a relay above can read the cause and try
40
+ // another harness. Throwing here would skip the whole escalation exactly
41
+ // when it is needed. Nothing consumes this value: an agent action whose
42
+ // run did not complete is failed by the engine.
43
+ if (reply.run.outcome !== "completed") {
44
+ return { value: { clear: false, questions: [], at: new Date().toISOString() }, run: reply.run };
45
+ }
46
+ const answer = extractJson(reply.text);
47
+ return {
48
+ value: {
49
+ clear: answer.clear,
50
+ questions: answer.clear ? [] : (answer.questions ?? []),
51
+ at: new Date().toISOString(),
52
+ },
53
+ run: reply.run,
54
+ };
55
+ }
56
+ async implement(ticket, retryContext) {
57
+ await this.git.prepareBranch(ticket.repo, ticket.branchName);
58
+ const reply = await this.ask(ticket, [
59
+ `Implement this ticket in the current repository.`,
60
+ ``,
61
+ `Ticket ${ticket.id}: ${ticket.title}`,
62
+ `Tracker: ${ticket.url}`,
63
+ ...(retryContext
64
+ ? [
65
+ ``,
66
+ `A previous attempt did not hold. This is what went wrong, verbatim:`,
67
+ ``,
68
+ retryContext,
69
+ ``,
70
+ `Fix the underlying cause. Do not discard work that was already correct.`,
71
+ ]
72
+ : []),
73
+ ``,
74
+ `Follow the conventions already in this repository. Do not commit: that is`,
75
+ `handled for you.`,
76
+ ].join("\n"));
77
+ const at = new Date().toISOString();
78
+ if (reply.run.outcome !== "completed") {
79
+ return { value: { ok: false, output: reply.run.output, at }, run: reply.run };
80
+ }
81
+ const pushed = await this.git.commitAndPush(ticket.repo, ticket.branchName, `${ticket.id}: ${ticket.title}`);
82
+ if (!pushed) {
83
+ // The harness exited cleanly and changed nothing. For a ticket that
84
+ // asked for work, that is a failure worth reporting rather than a
85
+ // success, and the account has to agree so a relay can act on it.
86
+ return {
87
+ value: {
88
+ ok: false,
89
+ output: `the agent finished without changing any file\n\n${reply.run.output}`,
90
+ at,
91
+ },
92
+ run: { ...reply.run, outcome: "failed" },
93
+ };
94
+ }
95
+ return { value: { ok: true, output: reply.run.output, at }, run: reply.run };
96
+ }
97
+ async addressThreads(ticket, threads, from) {
98
+ await this.git.prepareBranch(ticket.repo, ticket.branchName);
99
+ const reply = await this.ask(ticket, this.threadPrompt(ticket, threads, from));
100
+ // Returned rather than thrown, for the same reason as in `triage`: the
101
+ // relay above decides whether another harness gets a turn, and it needs
102
+ // the run to decide. The engine is what fails the action once every
103
+ // harness has been tried, so an empty list is never mistaken for "no
104
+ // comment needed answering".
105
+ if (reply.run.outcome !== "completed") {
106
+ return { value: [], run: reply.run };
107
+ }
108
+ const answer = extractJson(reply.text);
109
+ const verdicts = threads.map((thread) => {
110
+ const given = answer.verdicts?.find((v) => v.threadId === thread.id);
111
+ return {
112
+ threadId: thread.id,
113
+ // A comment the agent did not answer is not silently dropped. It is
114
+ // pushed to the owner, because an unanswered review comment is the
115
+ // one thing that must never disappear.
116
+ verdict: given?.verdict ?? "disagreed",
117
+ note: given?.note ?? "the agent did not answer this comment",
118
+ };
119
+ });
120
+ await this.git.commitAndPush(ticket.repo, ticket.branchName, `${ticket.id}: address review comments`);
121
+ return { value: verdicts, run: reply.run };
122
+ }
123
+ threadPrompt(ticket, threads, from) {
124
+ const hints = [
125
+ ...new Set(threads
126
+ .map((thread) => this.config.reviewerHints?.[thread.author.toLowerCase()])
127
+ .filter((hint) => Boolean(hint))),
128
+ ];
129
+ return [
130
+ from === "automated"
131
+ ? `An automated reviewer left comments on the pull request for this ticket.`
132
+ : `A human reviewer left comments on the pull request for this ticket.`,
133
+ ``,
134
+ `Ticket ${ticket.id}: ${ticket.title}`,
135
+ ``,
136
+ `Comments:`,
137
+ ...threads.map((thread) => `\n[${thread.id}] ${thread.author} said:\n${thread.body}`),
138
+ ...(hints.length ? [``, `Reviewer notes:`, ...hints.map((hint) => `- ${hint}`)] : []),
139
+ ``,
140
+ `For each comment, either change the code or say why you disagree. Do not`,
141
+ `argue on the pull request. Do not commit: that is handled for you.`,
142
+ ``,
143
+ `Then answer with a single JSON object and nothing else:`,
144
+ ``,
145
+ `{"verdicts": [{"threadId": "...", "verdict": "fixed", "note": "what you changed"}]}`,
146
+ ``,
147
+ `Use "disagreed" only when you did not change the code, and say why in the`,
148
+ `note. A disagreement goes to the ticket owner to settle, so be specific.`,
149
+ ].join("\n");
150
+ }
151
+ ask(ticket, prompt) {
152
+ return this.harness.ask(this.invoke(prompt), this.git.pathFor(ticket.repo), {
153
+ workId: ticket.id,
154
+ });
155
+ }
156
+ /** The prompt, addressed to a skill when one was named. */
157
+ invoke(prompt) {
158
+ return this.config.skill ? `/${this.config.skill}\n\n${prompt}` : prompt;
159
+ }
160
+ }
161
+ //# sourceMappingURL=HarnessAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HarnessAgent.js","sourceRoot":"","sources":["../src/HarnessAgent.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AA2BxC;;;;;;;GAOG;AACH,MAAM,OAAO,YAAY;IAEJ;IACA;IACA;IAHnB,YACmB,OAAgB,EAChB,GAAQ,EACR,SAA6B,EAAE;QAF/B,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAK;QACR,WAAM,GAAN,MAAM,CAAyB;IAC/C,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAC1B,MAAM,E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0EAA0E;SAC3E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IAEO,GAAG,CAAC,MAAc,EAAE,MAAc;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YAC1E,MAAM,EAAE,MAAM,CAAC,EAAE;SAClB,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IACnD,MAAM,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3E,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ import { AskContext, Harness, HarnessReply } from "@amykit/core";
2
+ import { NamedHarness } from "./collection.js";
3
+ import { HandoffLog } from "./handoff.js";
4
+ import { Ladders } from "./ladders.js";
5
+ /** Which skills answer for a step, in the order they are tried. */
6
+ export type SkillLadders = Readonly<Record<string, readonly string[]>>;
7
+ export interface HarnessRelayDeps extends HandoffLog {
8
+ skills?: SkillLadders;
9
+ }
10
+ /**
11
+ * One harness made of several, with nobody's prompts in it.
12
+ *
13
+ * The same two ladders the ticket-shaped relay climbs, over the same rungs,
14
+ * for the same reasons: the skill ladder is who should do the step, the
15
+ * harness ladder is what to do when the one asked ran out of quota or was not
16
+ * up to it. What is missing here is any notion of what the step *is* — a
17
+ * caller hands over a prompt and a directory, and gets back an answer and an
18
+ * account of what it cost.
19
+ *
20
+ * That is the whole difference between a harness plugin one workflow can use
21
+ * and a harness plugin any workflow can.
22
+ */
23
+ export declare class HarnessRelay implements Harness {
24
+ private readonly ladders;
25
+ private readonly deps;
26
+ readonly name = "relay";
27
+ constructor(ladders: Ladders<NamedHarness>, deps?: HarnessRelayDeps);
28
+ /**
29
+ * Hands the question to each skill named for the step, until one answers.
30
+ *
31
+ * With no skill configured this is one turn on the caller's own prompt,
32
+ * which is every install that has not asked for anything else.
33
+ */
34
+ ask(prompt: string, cwd: string, context?: AskContext): Promise<HarnessReply>;
35
+ /**
36
+ * Walks the harness ladder until something answers, or until the policy
37
+ * says there is nowhere left to go.
38
+ *
39
+ * The reply that comes back is the last one attempted, so a caller sees a
40
+ * real outcome rather than a summary of several.
41
+ */
42
+ private climb;
43
+ }
44
+ //# sourceMappingURL=HarnessRelay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HarnessRelay.d.ts","sourceRoot":"","sources":["../src/HarnessRelay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAkD,MAAM,cAAc,CAAC;AAE1F,OAAO,EAAE,OAAO,EAAuB,MAAM,cAAc,CAAC;AAE5D,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAEvE,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,YAAW,OAAO;IAIxC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJvB,QAAQ,CAAC,IAAI,WAAW;gBAGL,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,IAAI,GAAE,gBAAqB;IAO9C;;;;;OAKG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,YAAY,CAAC;IAwBvF;;;;;;OAMG;YACW,KAAK;CA+BpB"}
@@ -0,0 +1,96 @@
1
+ import { handoffNote, recordHandoff, recordSkillHandoff } from "./handoff.js";
2
+ import { nextRung } from "./ladder.js";
3
+ import { everyRung, rungsFor } from "./ladders.js";
4
+ /**
5
+ * One harness made of several, with nobody's prompts in it.
6
+ *
7
+ * The same two ladders the ticket-shaped relay climbs, over the same rungs,
8
+ * for the same reasons: the skill ladder is who should do the step, the
9
+ * harness ladder is what to do when the one asked ran out of quota or was not
10
+ * up to it. What is missing here is any notion of what the step *is* — a
11
+ * caller hands over a prompt and a directory, and gets back an answer and an
12
+ * account of what it cost.
13
+ *
14
+ * That is the whole difference between a harness plugin one workflow can use
15
+ * and a harness plugin any workflow can.
16
+ */
17
+ export class HarnessRelay {
18
+ ladders;
19
+ deps;
20
+ name = "relay";
21
+ constructor(ladders, deps = {}) {
22
+ this.ladders = ladders;
23
+ this.deps = deps;
24
+ if (everyRung(ladders).length === 0) {
25
+ throw new Error("the relay has no harness to relay to: no harness plugin contributed one");
26
+ }
27
+ }
28
+ /**
29
+ * Hands the question to each skill named for the step, until one answers.
30
+ *
31
+ * With no skill configured this is one turn on the caller's own prompt,
32
+ * which is every install that has not asked for anything else.
33
+ */
34
+ async ask(prompt, cwd, context = {}) {
35
+ const skills = (context.step && this.deps.skills?.[context.step]) || [];
36
+ if (skills.length === 0)
37
+ return this.climb(prompt, cwd, context, undefined);
38
+ let last = null;
39
+ for (let index = 0; index < skills.length; index += 1) {
40
+ const skill = skills[index];
41
+ last = await this.climb(prompt, cwd, context, skill);
42
+ if (last.run.outcome === "completed")
43
+ return last;
44
+ // `abandoned` stops here for the same reason it stops the harness
45
+ // ladder: it is what a killed child looks like, and the handbrake has
46
+ // to mean the next thing does not start.
47
+ const next = skills[index + 1];
48
+ if (!next || last.run.outcome === "abandoned")
49
+ break;
50
+ recordSkillHandoff(this.deps, context.workId, step(context), skill, next, last.run);
51
+ }
52
+ return last;
53
+ }
54
+ /**
55
+ * Walks the harness ladder until something answers, or until the policy
56
+ * says there is nowhere left to go.
57
+ *
58
+ * The reply that comes back is the last one attempted, so a caller sees a
59
+ * real outcome rather than a summary of several.
60
+ */
61
+ async climb(prompt, cwd, context, skill) {
62
+ // Chosen once per climb rather than per rung: a step that swapped ladders
63
+ // half way up would make "the next rung" mean nothing.
64
+ const ladder = rungsFor(this.ladders, context.step);
65
+ let index = 0;
66
+ let handoff;
67
+ let last = null;
68
+ while (index < ladder.length) {
69
+ const rung = ladder[index];
70
+ last = await rung.cli.ask(asked(prompt, skill, handoff), cwd, context);
71
+ const next = nextRung(ladder, index, last.run.outcome);
72
+ if (next === null)
73
+ return last;
74
+ const to = ladder[next];
75
+ recordHandoff(this.deps, context.workId, step(context), rung, to, last.run);
76
+ handoff = handoffNote(rung, last.run);
77
+ index = next;
78
+ }
79
+ // Unreachable while the ladder is non-empty, and the constructor refuses
80
+ // an empty one.
81
+ return last;
82
+ }
83
+ }
84
+ /**
85
+ * The prompt as it is actually sent: addressed to a skill when one was named,
86
+ * and carrying what the previous rung left behind.
87
+ */
88
+ function asked(prompt, skill, handoff) {
89
+ const body = handoff ? `${prompt}\n\n${handoff}` : prompt;
90
+ return skill ? `/${skill}\n\n${body}` : body;
91
+ }
92
+ /** What the log calls the step, for a caller that did not say. */
93
+ function step(context) {
94
+ return context.step ?? "ask";
95
+ }
96
+ //# sourceMappingURL=HarnessRelay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HarnessRelay.js","sourceRoot":"","sources":["../src/HarnessRelay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAW,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAS5D;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;IAIJ;IACA;IAJV,IAAI,GAAG,OAAO,CAAC;I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AChB,OAAO,IAAK,CAAC;IACf,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,KAAK,CAAC,MAAc,EAAE,KAAyB,EAAE,OAA2B;IACnF,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC1D,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,kEAAkE;AAClE,SAAS,IAAI,CAAC,OAAmB;IAC/B,OAAO,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { Harness } from "@amykit/core";
2
+ import { Agent } from "@amykit/workflow-ticket-to-qa";
3
+ import { Rung } from "./ladder.js";
4
+ /** The collection every harness plugin adds its ticket-shaped agents to. */
5
+ export declare const AGENT_COLLECTION = "agent";
6
+ /**
7
+ * The collection every harness plugin adds the bare CLI to.
8
+ *
9
+ * Two collections rather than one, because they are two different things at
10
+ * two different levels. A `NamedAgent` already knows what a ticket is, which
11
+ * prompt to send and when to commit; a `NamedHarness` knows none of that and
12
+ * is what a second workflow wants, so that its own prompts go up the same
13
+ * ladder as the first workflow's do.
14
+ */
15
+ export declare const HARNESS_COLLECTION = "harness";
16
+ /**
17
+ * One harness at one model tier, ready to be asked.
18
+ *
19
+ * A harness plugin contributes one of these per model it was configured with,
20
+ * rather than mounting the `agent` port. Only one plugin can own a port, and
21
+ * three harnesses that each want to be *the* agent would simply refuse to
22
+ * mount together. Contributing instead lets a relay compose them, and lets a
23
+ * single-harness install work through the same relay with nothing special
24
+ * about it.
25
+ *
26
+ * `harness` and `model` are declared rather than discovered, because the
27
+ * relay has to decide **where to go next** before running anything: a quota
28
+ * problem wants a different harness and a failure wants a stronger model, and
29
+ * both are choices made in advance.
30
+ */
31
+ export interface NamedAgent extends Rung {
32
+ readonly agent: Agent;
33
+ /**
34
+ * The same harness and model, with a named skill doing the step.
35
+ *
36
+ * A second agent rather than an argument on the port, because which skill
37
+ * answers is decided before the call, exactly like which harness does.
38
+ */
39
+ readonly using: (skill: string) => Agent;
40
+ }
41
+ /** The same rung of the same ladder, with no workflow's prompts on it. */
42
+ export interface NamedHarness extends Rung {
43
+ readonly cli: Harness;
44
+ }
45
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,UAAW,SAAQ,IAAI;IACtC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC;CAC1C;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAa,SAAQ,IAAI;IACxC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB"}
@@ -0,0 +1,13 @@
1
+ /** The collection every harness plugin adds its ticket-shaped agents to. */
2
+ export const AGENT_COLLECTION = "agent";
3
+ /**
4
+ * The collection every harness plugin adds the bare CLI to.
5
+ *
6
+ * Two collections rather than one, because they are two different things at
7
+ * two different levels. A `NamedAgent` already knows what a ticket is, which
8
+ * prompt to send and when to commit; a `NamedHarness` knows none of that and
9
+ * is what a second workflow wants, so that its own prompts go up the same
10
+ * ladder as the first workflow's do.
11
+ */
12
+ export const HARNESS_COLLECTION = "harness";
13
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAIA,4EAA4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { AgentRun, EventLog } from "@amykit/core";
2
+ import { Rung } from "./ladder.js";
3
+ export interface HandoffLog {
4
+ log?: EventLog;
5
+ now?: () => Date;
6
+ }
7
+ /**
8
+ * What the next harness is told about the one before it.
9
+ *
10
+ * The working tree is left exactly as the harness that gave up left it, so
11
+ * the next one is told it is picking up half-done work. Resetting would throw
12
+ * away whatever was already right, and on a long piece of work that is
13
+ * expensive enough to risk hitting the same quota again.
14
+ */
15
+ export declare function handoffNote(from: Rung, run: AgentRun): string;
16
+ /** Says which rung gave up and which one is being asked next. */
17
+ export declare function recordHandoff(deps: HandoffLog, workId: string | undefined, action: string, from: Rung, to: Rung, run: AgentRun): void;
18
+ /**
19
+ * The same event as a harness handoff, because it is the same question with a
20
+ * third axis: `moved` already answers "what changed".
21
+ */
22
+ export declare function recordSkillHandoff(deps: HandoffLog, workId: string | undefined, action: string, from: string, to: string, run: AgentRun): void;
23
+ //# sourceMappingURL=handoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAY7D;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,IAAI,EACR,GAAG,EAAE,QAAQ,GACZ,IAAI,CASN;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,QAAQ,GACZ,IAAI,CAQN"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * What the next harness is told about the one before it.
3
+ *
4
+ * The working tree is left exactly as the harness that gave up left it, so
5
+ * the next one is told it is picking up half-done work. Resetting would throw
6
+ * away whatever was already right, and on a long piece of work that is
7
+ * expensive enough to risk hitting the same quota again.
8
+ */
9
+ export function handoffNote(from, run) {
10
+ const because = run.outcome === "rate-limited"
11
+ ? `ran out of quota partway through`
12
+ : `did not succeed`;
13
+ return [
14
+ `A previous attempt by ${from.harness} (${from.model}) ${because}.`,
15
+ `The working tree is exactly as it left it, so this may be half-done work`,
16
+ `rather than a clean start. Continue it; do not begin again.`,
17
+ ...(run.output ? [``, `What it said:`, ``, run.output] : []),
18
+ ].join("\n");
19
+ }
20
+ /** Says which rung gave up and which one is being asked next. */
21
+ export function recordHandoff(deps, workId, action, from, to, run) {
22
+ append(deps, workId, {
23
+ action,
24
+ cause: run.outcome,
25
+ from: { harness: from.harness, model: from.model },
26
+ to: { harness: to.harness, model: to.model },
27
+ // Which axis moved, which is what a report about reliability wants.
28
+ moved: from.harness === to.harness ? "model" : "harness",
29
+ });
30
+ }
31
+ /**
32
+ * The same event as a harness handoff, because it is the same question with a
33
+ * third axis: `moved` already answers "what changed".
34
+ */
35
+ export function recordSkillHandoff(deps, workId, action, from, to, run) {
36
+ append(deps, workId, {
37
+ action,
38
+ cause: run.outcome,
39
+ from: { skill: from },
40
+ to: { skill: to },
41
+ moved: "skill",
42
+ });
43
+ }
44
+ function append(deps, workId, detail) {
45
+ deps.log?.append({
46
+ at: (deps.now ?? (() => new Date()))().toISOString(),
47
+ kind: "agent.handoff",
48
+ ...(workId === undefined ? {} : { workId }),
49
+ detail,
50
+ });
51
+ }
52
+ //# sourceMappingURL=handoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,GAAa;IACnD,MAAM,OAAO,GACX,GAAG,CAAC,OAAO,KAAK,cAAc;QAC5B,CAAC,CAAC,kCAAkC;QACpC,CAAC,CAAC,iBAAiB,CAAC;IAExB,OAAO;QACL,yBAAyB,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK,KAAK,OAAO,GAAG;QACnE,0EAA0E;QAC1E,6DAA6D;QAC7D,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,aAAa,CAC3B,IAAgB,EAChB,MAA0B,EAC1B,MAAc,EACd,IAAU,EACV,EAAQ,EACR,GAAa;IAEb,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;QACnB,MAAM;QACN,KAAK,EAAE,GAAG,CAAC,OAAO;QAClB,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;QAClD,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE;QAC5C,oEAAoE;QACpE,KAAK,EAAE,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;KACzD,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAgB,EAChB,MAA0B,EAC1B,MAAc,EACd,IAAY,EACZ,EAAU,EACV,GAAa;IAEb,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;QACnB,MAAM;QACN,KAAK,EAAE,GAAG,CAAC,OAAO;QAClB,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;QACrB,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QACjB,KAAK,EAAE,OAAO;KACf,CAAC,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,IAAgB,EAAE,MAA0B,EAAE,MAA+B;IAC3F,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC;QACf,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE;QACpD,IAAI,EAAE,eAAe;QACrB,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3C,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,16 @@
1
+ export { HarnessAgent } from "./HarnessAgent.js";
2
+ export type { HarnessAgentConfig } from "./HarnessAgent.js";
3
+ export { HarnessRelay } from "./HarnessRelay.js";
4
+ export type { HarnessRelayDeps, SkillLadders } from "./HarnessRelay.js";
5
+ export { extractJson } from "./json.js";
6
+ export { AGENT_COLLECTION, HARNESS_COLLECTION } from "./collection.js";
7
+ export type { NamedAgent, NamedHarness } from "./collection.js";
8
+ export { handoffNote, recordHandoff, recordSkillHandoff } from "./handoff.js";
9
+ export type { HandoffLog } from "./handoff.js";
10
+ export { nextRung } from "./ladder.js";
11
+ export type { Rung } from "./ladder.js";
12
+ export { everyRung, oneLadder, rungsFor } from "./ladders.js";
13
+ export type { Ladders } from "./ladders.js";
14
+ export { contributeTiers, tierName } from "./tiers.js";
15
+ export type { TierOptions } from "./tiers.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC9E,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC9D,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { HarnessAgent } from "./HarnessAgent.js";
2
+ export { HarnessRelay } from "./HarnessRelay.js";
3
+ export { extractJson } from "./json.js";
4
+ export { AGENT_COLLECTION, HARNESS_COLLECTION } from "./collection.js";
5
+ export { handoffNote, recordHandoff, recordSkillHandoff } from "./handoff.js";
6
+ export { nextRung } from "./ladder.js";
7
+ export { everyRung, oneLadder, rungsFor } from "./ladders.js";
8
+ export { contributeTiers, tierName } from "./tiers.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
package/dist/json.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Pulls the first JSON object out of a model's answer.
3
+ *
4
+ * An agent asked for JSON will usually oblige, and will sometimes wrap it in
5
+ * a fenced block or a sentence. Scanning for the first balanced object is
6
+ * more forgiving than trusting the whole reply to parse, and still fails
7
+ * loudly when there is no object at all.
8
+ */
9
+ export declare function extractJson<T>(text: string): T;
10
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAqC9C"}
package/dist/json.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Pulls the first JSON object out of a model's answer.
3
+ *
4
+ * An agent asked for JSON will usually oblige, and will sometimes wrap it in
5
+ * a fenced block or a sentence. Scanning for the first balanced object is
6
+ * more forgiving than trusting the whole reply to parse, and still fails
7
+ * loudly when there is no object at all.
8
+ */
9
+ export function extractJson(text) {
10
+ const start = text.indexOf("{");
11
+ if (start === -1) {
12
+ throw new Error(`no JSON object in the reply: ${preview(text)}`);
13
+ }
14
+ let depth = 0;
15
+ let inString = false;
16
+ let escaped = false;
17
+ for (let index = start; index < text.length; index += 1) {
18
+ const character = text[index];
19
+ if (escaped) {
20
+ escaped = false;
21
+ continue;
22
+ }
23
+ if (character === "\\") {
24
+ escaped = true;
25
+ continue;
26
+ }
27
+ if (character === '"') {
28
+ inString = !inString;
29
+ continue;
30
+ }
31
+ if (inString)
32
+ continue;
33
+ if (character === "{")
34
+ depth += 1;
35
+ if (character === "}") {
36
+ depth -= 1;
37
+ if (depth === 0) {
38
+ return JSON.parse(text.slice(start, index + 1));
39
+ }
40
+ }
41
+ }
42
+ throw new Error(`the JSON object in the reply is not closed: ${preview(text)}`);
43
+ }
44
+ function preview(text) {
45
+ const trimmed = text.trim();
46
+ return trimmed.length > 200 ? `${trimmed.slice(0, 200)}...` : trimmed;
47
+ }
48
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAI,IAAY;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,K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CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { AgentOutcome } from "@amykit/core";
2
+ export interface Rung {
3
+ readonly name: string;
4
+ readonly harness: string;
5
+ readonly model: string;
6
+ }
7
+ /**
8
+ * Where to go after a rung did not work out, or nowhere.
9
+ *
10
+ * The two causes want opposite moves, which is the whole reason this is not a
11
+ * plain retry loop:
12
+ *
13
+ * - **rate-limited** is not a capability problem. A stronger model on the
14
+ * same harness is still behind the same quota, so every remaining rung of
15
+ * that harness is skipped and the next harness gets it.
16
+ * - **failed** might be a capability problem, so the next rung is tried in
17
+ * order: the next model of the same harness first, and only once those run
18
+ * out, the next harness. That is how both axes get exhausted rather than
19
+ * one.
20
+ * - **abandoned** stops the ladder. A missing binary is one cause and
21
+ * `amy stop` killing the child is another, and retrying the second would
22
+ * start a fresh child the moment the handbrake came down. `amy doctor`
23
+ * is what catches the missing binary, before a ticket is touched.
24
+ * - **completed** never asks.
25
+ */
26
+ export declare function nextRung(ladder: readonly Rung[], current: number, outcome: AgentOutcome): number | null;
27
+ //# sourceMappingURL=ladder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ladder.d.ts","sourceRoot":"","sources":["../src/ladder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,SAAS,IAAI,EAAE,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,GACpB,MAAM,GAAG,IAAI,CAaf"}
package/dist/ladder.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Where to go after a rung did not work out, or nowhere.
3
+ *
4
+ * The two causes want opposite moves, which is the whole reason this is not a
5
+ * plain retry loop:
6
+ *
7
+ * - **rate-limited** is not a capability problem. A stronger model on the
8
+ * same harness is still behind the same quota, so every remaining rung of
9
+ * that harness is skipped and the next harness gets it.
10
+ * - **failed** might be a capability problem, so the next rung is tried in
11
+ * order: the next model of the same harness first, and only once those run
12
+ * out, the next harness. That is how both axes get exhausted rather than
13
+ * one.
14
+ * - **abandoned** stops the ladder. A missing binary is one cause and
15
+ * `amy stop` killing the child is another, and retrying the second would
16
+ * start a fresh child the moment the handbrake came down. `amy doctor`
17
+ * is what catches the missing binary, before a ticket is touched.
18
+ * - **completed** never asks.
19
+ */
20
+ export function nextRung(ladder, current, outcome) {
21
+ if (outcome === "completed" || outcome === "abandoned")
22
+ return null;
23
+ const here = ladder[current];
24
+ if (!here)
25
+ return null;
26
+ for (let index = current + 1; index < ladder.length; index += 1) {
27
+ const rung = ladder[index];
28
+ if (outcome === "rate-limited" && rung.harness === here.harness)
29
+ continue;
30
+ return index;
31
+ }
32
+ return null;
33
+ }
34
+ //# sourceMappingURL=ladder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ladder.js","sourceRoot":"","sources":["../src/ladder.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAuB,EACvB,OAAe,EACf,OAAqB;IAErB,IAAI,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAEpE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,KAAK,IAAI,KAAK,GAAG,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAE,CAAC;QAC5B,IAAI,OAAO,KAAK,cAAc,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;YAAE,SAAS;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Rung } from "./ladder.js";
2
+ /**
3
+ * Which rungs answer for a step, and which answer for everything else.
4
+ *
5
+ * One ladder for the whole install is the right default and the wrong ceiling.
6
+ * Reading a ticket to decide whether it is clear enough to start is not the
7
+ * same job as writing the change, and putting both behind one list means
8
+ * paying the expensive model to do the cheap step, or asking the cheap one to
9
+ * do the work.
10
+ *
11
+ * So the ladder is per step, with a default, and the step is the action's own
12
+ * name — which the relay already had in hand for choosing a skill. That is
13
+ * also what makes routing by difficulty possible without anything here
14
+ * learning the word: a workflow that triages into easy and hard emits
15
+ * different actions for each, and the config points them at different rungs.
16
+ */
17
+ export interface Ladders<T extends Rung> {
18
+ /** Used by any step that names no ladder of its own. */
19
+ readonly fallback: readonly T[];
20
+ readonly byStep: Readonly<Record<string, readonly T[]>>;
21
+ }
22
+ /** One ladder for everything, which is what an install starts with. */
23
+ export declare function oneLadder<T extends Rung>(rungs: readonly T[]): Ladders<T>;
24
+ /**
25
+ * The rungs for a step, or the fallback.
26
+ *
27
+ * A step with an empty ladder falls back rather than failing: an operator who
28
+ * writes `triage: []` has said nothing about triage, and the alternative is a
29
+ * relay with nowhere to go, which the constructor already refuses to be.
30
+ */
31
+ export declare function rungsFor<T extends Rung>(ladders: Ladders<T>, step?: string): readonly T[];
32
+ /** Every rung any step could reach, for a caller that has to check them all. */
33
+ export declare function everyRung<T extends Rung>(ladders: Ladders<T>): readonly T[];
34
+ //# sourceMappingURL=ladders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ladders.d.ts","sourceRoot":"","sources":["../src/ladders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,IAAI;IACrC,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;CACzD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,CAGzF;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAE3E"}
@@ -0,0 +1,20 @@
1
+ /** One ladder for everything, which is what an install starts with. */
2
+ export function oneLadder(rungs) {
3
+ return { fallback: rungs, byStep: {} };
4
+ }
5
+ /**
6
+ * The rungs for a step, or the fallback.
7
+ *
8
+ * A step with an empty ladder falls back rather than failing: an operator who
9
+ * writes `triage: []` has said nothing about triage, and the alternative is a
10
+ * relay with nowhere to go, which the constructor already refuses to be.
11
+ */
12
+ export function rungsFor(ladders, step) {
13
+ const named = step ? ladders.byStep[step] : undefined;
14
+ return named && named.length > 0 ? named : ladders.fallback;
15
+ }
16
+ /** Every rung any step could reach, for a caller that has to check them all. */
17
+ export function everyRung(ladders) {
18
+ return [...ladders.fallback, ...Object.values(ladders.byStep).flat()];
19
+ }
20
+ //# sourceMappingURL=ladders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ladders.js","sourceRoot":"","sources":["../src/ladders.ts"],"names":[],"mappings":"AAuBA,uEAAuE;AACvE,MAAM,UAAU,SAAS,CAAiB,KAAmB;IAC3D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAiB,OAAmB,EAAE,IAAa;IACzE,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;AAC9D,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,SAAS,CAAiB,OAAmB;IAC3D,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Git, Harness, Registry } from "@amykit/core";
2
+ import { NamedAgent } from "./collection.js";
3
+ import { HarnessAgentConfig } from "./HarnessAgent.js";
4
+ export interface TierOptions {
5
+ /** The harness name, which is also the axis the relay swaps along. */
6
+ harness: string;
7
+ /**
8
+ * The model tiers, cheapest first. Empty means one agent on whatever model
9
+ * the harness defaults to, which is the single-model install.
10
+ */
11
+ models: readonly string[];
12
+ make: (model: string) => Harness;
13
+ git: Git;
14
+ agent?: HarnessAgentConfig;
15
+ }
16
+ /**
17
+ * Adds one agent **and one bare harness** per model tier to the collections
18
+ * the relay reads.
19
+ *
20
+ * Both, because they are used at different levels. The agent already knows
21
+ * what a ticket is; the harness knows nothing, and is what a second workflow
22
+ * asks its own questions through. Contributing only the first is what made
23
+ * `@amykit/plugin-claude` a plugin exactly one workflow could use.
24
+ *
25
+ * The naming lives here rather than in each harness plugin because it is a
26
+ * contract: the ladder in a config file refers to these names, so three
27
+ * plugins inventing three conventions would make the config unlearnable. One
28
+ * name covers both collections, so a ladder means the same thing whichever
29
+ * level reads it.
30
+ */
31
+ export declare function contributeTiers(registry: Registry, opts: TierOptions): NamedAgent[];
32
+ /** `claude:opus`, or plain `claude` when no model was named. */
33
+ export declare function tierName(harness: string, model: string): string;
34
+ //# sourceMappingURL=tiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAwC,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAgB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACjC,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,CAiBnF;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D"}
package/dist/tiers.js ADDED
@@ -0,0 +1,35 @@
1
+ import { AGENT_COLLECTION, HARNESS_COLLECTION } from "./collection.js";
2
+ import { HarnessAgent } from "./HarnessAgent.js";
3
+ /**
4
+ * Adds one agent **and one bare harness** per model tier to the collections
5
+ * the relay reads.
6
+ *
7
+ * Both, because they are used at different levels. The agent already knows
8
+ * what a ticket is; the harness knows nothing, and is what a second workflow
9
+ * asks its own questions through. Contributing only the first is what made
10
+ * `@amykit/plugin-claude` a plugin exactly one workflow could use.
11
+ *
12
+ * The naming lives here rather than in each harness plugin because it is a
13
+ * contract: the ladder in a config file refers to these names, so three
14
+ * plugins inventing three conventions would make the config unlearnable. One
15
+ * name covers both collections, so a ladder means the same thing whichever
16
+ * level reads it.
17
+ */
18
+ export function contributeTiers(registry, opts) {
19
+ const models = opts.models.length > 0 ? opts.models : [""];
20
+ return models.map((model) => {
21
+ const cli = opts.make(model);
22
+ const agent = (skill) => new HarnessAgent(cli, opts.git, { ...(opts.agent ?? {}), skill });
23
+ const rung = { name: tierName(opts.harness, model), harness: opts.harness, model };
24
+ const named = { ...rung, agent: agent(), using: (skill) => agent(skill) };
25
+ const bare = { ...rung, cli };
26
+ registry.contribute(AGENT_COLLECTION, named.name, named);
27
+ registry.contribute(HARNESS_COLLECTION, bare.name, bare);
28
+ return named;
29
+ });
30
+ }
31
+ /** `claude:opus`, or plain `claude` when no model was named. */
32
+ export function tierName(harness, model) {
33
+ return model ? `${harness}:${model}` : harness;
34
+ }
35
+ //# sourceMappingURL=tiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.js","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAA4B,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AAerE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,QAAkB,EAAE,IAAiB;IACnE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE3D,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,CAAC,KAAc,EAAgB,EAAE,CAC7C,IAAI,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAEpE,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACnF,MAAM,KAAK,GAAe,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACtF,MAAM,IAAI,GAAiB,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC;QAE5C,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzD,QAAQ,CAAC,UAAU,CAAC,kBAAkB,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAEzD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,KAAa;IACrD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACjD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@amykit/agent-kit",
3
+ "version": "0.2.0",
4
+ "description": "What every agent does the same way: the prompts, the git dance, and the JSON.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Nicolas Melo",
8
+ "homepage": "https://github.com/nicolasmelo1/amy#readme",
9
+ "bugs": "https://github.com/nicolasmelo1/amy/issues",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/nicolasmelo1/amy.git",
13
+ "directory": "packages/agent-kit"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org"
18
+ },
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@amykit/core": "^0.2.0",
32
+ "@amykit/workflow-ticket-to-qa": "^0.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "@amykit/test-fixtures": "^0.1.0"
36
+ }
37
+ }