@usine/core 0.2.0 → 0.4.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 +43 -16
- package/dist/agent/agent.d.ts +12 -8
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +14 -10
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/brain.d.ts +2 -6
- package/dist/agent/brain.d.ts.map +1 -1
- package/dist/agent/brain.js +3 -7
- package/dist/agent/brain.js.map +1 -1
- package/dist/agent/capability.d.ts +4 -4
- package/dist/agent/capability.d.ts.map +1 -1
- package/dist/agent/capability.js +4 -4
- package/dist/agent/capability.js.map +1 -1
- package/dist/agent/session.d.ts +95 -21
- package/dist/agent/session.d.ts.map +1 -1
- package/dist/agent/session.js +100 -21
- package/dist/agent/session.js.map +1 -1
- package/dist/attempt/attempt.d.ts +63 -11
- package/dist/attempt/attempt.d.ts.map +1 -1
- package/dist/attempt/attempt.js +81 -11
- package/dist/attempt/attempt.js.map +1 -1
- package/dist/attempt/channel.d.ts +142 -44
- package/dist/attempt/channel.d.ts.map +1 -1
- package/dist/attempt/channel.js +124 -36
- package/dist/attempt/channel.js.map +1 -1
- package/dist/attempt/failure.d.ts +27 -14
- package/dist/attempt/failure.d.ts.map +1 -1
- package/dist/attempt/failure.js +27 -14
- package/dist/attempt/failure.js.map +1 -1
- package/dist/attempt/outcome.d.ts +3 -5
- package/dist/attempt/outcome.d.ts.map +1 -1
- package/dist/attempt/outcome.js +2 -4
- package/dist/attempt/outcome.js.map +1 -1
- package/dist/attempt/salvage.d.ts +50 -0
- package/dist/attempt/salvage.d.ts.map +1 -0
- package/dist/attempt/salvage.js +21 -0
- package/dist/attempt/salvage.js.map +1 -0
- package/dist/attempt/start.d.ts +35 -0
- package/dist/attempt/start.d.ts.map +1 -0
- package/dist/attempt/start.js +30 -0
- package/dist/attempt/start.js.map +1 -0
- package/dist/cycle-budget.d.ts +7 -8
- package/dist/cycle-budget.d.ts.map +1 -1
- package/dist/cycle-budget.js +9 -10
- package/dist/cycle-budget.js.map +1 -1
- package/dist/event.d.ts +4 -8
- package/dist/event.d.ts.map +1 -1
- package/dist/event.js +4 -8
- package/dist/event.js.map +1 -1
- package/dist/instance.d.ts +1 -1
- package/dist/instance.d.ts.map +1 -1
- package/dist/instance.js +1 -1
- package/dist/instance.js.map +1 -1
- package/dist/item.d.ts +1 -2
- package/dist/item.d.ts.map +1 -1
- package/dist/item.js +1 -2
- package/dist/item.js.map +1 -1
- package/dist/loop.d.ts +10 -2
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +9 -2
- package/dist/loop.js.map +1 -1
- package/dist/operator.d.ts +8 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +9 -0
- package/dist/operator.js.map +1 -0
- package/dist/repository.d.ts +6 -8
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +8 -10
- package/dist/repository.js.map +1 -1
- package/dist/run/again.d.ts +13 -0
- package/dist/run/again.d.ts.map +1 -0
- package/dist/run/again.js +13 -0
- package/dist/run/again.js.map +1 -0
- package/dist/run/approval.d.ts +27 -0
- package/dist/run/approval.d.ts.map +1 -0
- package/dist/run/approval.js +26 -0
- package/dist/run/approval.js.map +1 -0
- package/dist/run/run.d.ts +2 -2
- package/dist/run/run.d.ts.map +1 -1
- package/dist/run/run.js +2 -2
- package/dist/run/run.js.map +1 -1
- package/dist/run/state.d.ts +22 -31
- package/dist/run/state.d.ts.map +1 -1
- package/dist/run/state.js +23 -36
- package/dist/run/state.js.map +1 -1
- package/dist/step/harvest.d.ts +44 -0
- package/dist/step/harvest.d.ts.map +1 -0
- package/dist/step/harvest.js +368 -0
- package/dist/step/harvest.js.map +1 -0
- package/dist/step/result.d.ts +15 -4
- package/dist/step/result.d.ts.map +1 -1
- package/dist/step/result.js +14 -4
- package/dist/step/result.js.map +1 -1
- package/dist/step/step.d.ts +2 -8
- package/dist/step/step.d.ts.map +1 -1
- package/dist/step/step.js +2 -8
- package/dist/step/step.js.map +1 -1
- package/dist/worker.d.ts +48 -4
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +47 -4
- package/dist/worker.js.map +1 -1
- package/package.json +27 -2
package/dist/agent/session.js
CHANGED
|
@@ -1,40 +1,58 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Effect, Match, Option, Schema } from "effect";
|
|
2
|
+
import { GatewayCredentialKind } from "../worker.js";
|
|
2
3
|
import { AgentName } from "./agent.js";
|
|
3
4
|
import { BrainSpec } from "./brain.js";
|
|
4
|
-
/**
|
|
5
|
+
/** The usine ID of a parent or child session, distinct from `HarnessSessionId`. */
|
|
5
6
|
export const AgentSessionId = Schema.NonEmptyString.pipe(Schema.brand("AgentSessionId"));
|
|
7
|
+
/** The sum of output tokens and uncached input tokens (new prompt text and cache writes), excluding cache reads. */
|
|
8
|
+
export const TokenCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.brand("TokenCount"));
|
|
6
9
|
const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
|
|
7
|
-
/**
|
|
10
|
+
/** The maximum number of child sessions per Attempt, counting sequential spawns. */
|
|
8
11
|
export const ChildSessionBudget = PositiveInt.pipe(Schema.brand("ChildSessionBudget"));
|
|
9
|
-
/** The 1-based child spawn request
|
|
12
|
+
/** The 1-based number of a child spawn request in an Attempt, counting requests the budget rejected. */
|
|
10
13
|
export const ChildSessionCount = PositiveInt.pipe(Schema.brand("ChildSessionCount"));
|
|
11
|
-
/** The session coordinating an Attempt and delegating work to its coding children. */
|
|
12
14
|
export class ParentSession extends Schema.TaggedClass("Agent/ParentSession")("ParentSession", {
|
|
13
15
|
id: AgentSessionId,
|
|
14
16
|
agent: AgentName,
|
|
15
17
|
brain: BrainSpec,
|
|
16
18
|
}) {
|
|
17
19
|
}
|
|
18
|
-
/** A
|
|
20
|
+
/** A session spawned by the parent session; a child can't spawn children. */
|
|
19
21
|
export class ChildSession extends Schema.TaggedClass("Agent/ChildSession")("ChildSession", {
|
|
20
22
|
id: AgentSessionId,
|
|
21
23
|
parentId: AgentSessionId,
|
|
22
24
|
agent: AgentName,
|
|
23
25
|
brain: BrainSpec,
|
|
26
|
+
/**
|
|
27
|
+
* The credential kind the Gateway used for the child's model requests (ADR 0027), or `None`
|
|
28
|
+
* if the child used its harness's own login or the record is older.
|
|
29
|
+
*/
|
|
30
|
+
gatewayCredential: Schema.OptionFromOptionalKey(GatewayCredentialKind).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
24
31
|
}) {
|
|
25
32
|
}
|
|
26
|
-
/** A participant in an Attempt, with its role, Agent, and effective brain recorded. */
|
|
27
33
|
export const AgentSession = Schema.Union([ParentSession, ChildSession]);
|
|
28
|
-
/**
|
|
29
|
-
export
|
|
34
|
+
/** The harness's ID for its saved conversation, distinct from `AgentSessionId`. */
|
|
35
|
+
export const HarnessSessionId = Schema.NonEmptyString.pipe(Schema.brand("HarnessSessionId"));
|
|
36
|
+
/** A saved harness conversation; `cwd` is the Worker checkout to resume it from. */
|
|
37
|
+
export class HarnessSession extends Schema.Class("Agent/HarnessSession")({
|
|
38
|
+
id: HarnessSessionId,
|
|
39
|
+
cwd: Schema.NonEmptyString,
|
|
40
|
+
}) {
|
|
41
|
+
}
|
|
42
|
+
/** The session identity and the brain selected at launch. */
|
|
43
|
+
export class SessionStarted extends Schema.TaggedClass("Agent/SessionStarted")("SessionStarted", {
|
|
44
|
+
session: AgentSession,
|
|
45
|
+
/** `None` for older transcripts and for harnesses without a saved conversation. */
|
|
46
|
+
harnessSession: Schema.OptionFromOptionalKey(HarnessSession).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
47
|
+
}) {
|
|
30
48
|
}
|
|
31
|
-
/** Completed assistant text
|
|
49
|
+
/** Completed assistant text, which can come before the final result. */
|
|
32
50
|
export class TextOutput extends Schema.TaggedClass("Agent/TextOutput")("TextOutput", {
|
|
33
51
|
session: AgentSession,
|
|
34
52
|
text: Schema.NonEmptyString,
|
|
35
53
|
}) {
|
|
36
54
|
}
|
|
37
|
-
/**
|
|
55
|
+
/** The start of a tool call; `callId` matches the corresponding `ToolFinished`. */
|
|
38
56
|
export class ToolStarted extends Schema.TaggedClass("Agent/ToolStarted")("ToolStarted", {
|
|
39
57
|
session: AgentSession,
|
|
40
58
|
callId: Schema.NonEmptyString,
|
|
@@ -42,7 +60,7 @@ export class ToolStarted extends Schema.TaggedClass("Agent/ToolStarted")("ToolSt
|
|
|
42
60
|
input: Schema.Json,
|
|
43
61
|
}) {
|
|
44
62
|
}
|
|
45
|
-
/**
|
|
63
|
+
/** The result of a tool call; `isError` doesn't end the session. */
|
|
46
64
|
export class ToolFinished extends Schema.TaggedClass("Agent/ToolFinished")("ToolFinished", {
|
|
47
65
|
session: AgentSession,
|
|
48
66
|
callId: Schema.NonEmptyString,
|
|
@@ -51,22 +69,58 @@ export class ToolFinished extends Schema.TaggedClass("Agent/ToolFinished")("Tool
|
|
|
51
69
|
isError: Schema.Boolean,
|
|
52
70
|
}) {
|
|
53
71
|
}
|
|
54
|
-
/**
|
|
72
|
+
/** The end of a session's activity; the Attempt's outcome is recorded separately. */
|
|
55
73
|
export class SessionFinished extends Schema.TaggedClass("Agent/SessionFinished")("SessionFinished", { session: AgentSession }) {
|
|
56
74
|
}
|
|
57
|
-
/**
|
|
75
|
+
/** A supervised session that finished a turn and accepts more operator messages. */
|
|
76
|
+
export class SessionIdle extends Schema.TaggedClass("Agent/SessionIdle")("SessionIdle", { session: AgentSession }) {
|
|
77
|
+
}
|
|
78
|
+
/** A live session that started another user turn in the same conversation. */
|
|
79
|
+
export class SessionResumed extends Schema.TaggedClass("Agent/SessionResumed")("SessionResumed", { session: AgentSession }) {
|
|
80
|
+
}
|
|
81
|
+
/** An estimated amount in US dollars from the harness's own rate table, not a bill (ADR 0013). */
|
|
82
|
+
export const UsdAmount = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.brand("UsdAmount"));
|
|
83
|
+
/**
|
|
84
|
+
* The session's cumulative token count and price, including later operator turns. `costUsd` is
|
|
85
|
+
* `None` for harnesses that don't price usage, such as Codex, and for older transcripts.
|
|
86
|
+
*/
|
|
87
|
+
export class SessionTokensUpdated extends Schema.TaggedClass("Agent/SessionTokensUpdated")("SessionTokensUpdated", {
|
|
88
|
+
session: AgentSession,
|
|
89
|
+
totalTokens: TokenCount,
|
|
90
|
+
costUsd: Schema.OptionFromOptionalKey(UsdAmount).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
91
|
+
}) {
|
|
92
|
+
}
|
|
58
93
|
export const BillingPool = Schema.Literals(["apiKeys", "claudePlan", "chatgptPlan"]);
|
|
59
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Returns the billing pool of a session with `brain` and the Gateway credential kind, if any.
|
|
96
|
+
*
|
|
97
|
+
* - Claude Code: `apiKeys` if the Gateway injects an API key, otherwise `claudePlan` (ADR 0013).
|
|
98
|
+
* - Codex: `chatgptPlan`.
|
|
99
|
+
* - Pi: `chatgptPlan` for `openai-codex/` models, otherwise `apiKeys` (ADR 0021).
|
|
100
|
+
*/
|
|
101
|
+
export const brainPool = (brain, gatewayCredential) => {
|
|
102
|
+
switch (brain.harness) {
|
|
103
|
+
case "claude":
|
|
104
|
+
return Option.contains(gatewayCredential, "api-key") ? "apiKeys" : "claudePlan";
|
|
105
|
+
case "codex":
|
|
106
|
+
return "chatgptPlan";
|
|
107
|
+
case "pi":
|
|
108
|
+
return brain.model.startsWith("openai-codex/") ? "chatgptPlan" : "apiKeys";
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/** Returns the billing pool of a recorded session; the parent never uses a Gateway credential. */
|
|
112
|
+
export const sessionPool = (session) => Match.valueTags(session, {
|
|
113
|
+
ParentSession: ({ brain }) => brainPool(brain, Option.none()),
|
|
114
|
+
ChildSession: ({ brain, gatewayCredential }) => brainPool(brain, gatewayCredential),
|
|
115
|
+
});
|
|
60
116
|
export class RateLimitWindow extends Schema.Class("Agent/RateLimitWindow")({
|
|
61
|
-
/**
|
|
117
|
+
/** The percentage of the allowance used, including usage outside this Attempt. */
|
|
62
118
|
usedPercent: Schema.Number,
|
|
63
|
-
/** Length of the allowance window; absent when the provider omits it. */
|
|
64
119
|
windowDurationMinutes: Schema.OptionFromNullOr(Schema.Number),
|
|
65
|
-
/** When the allowance resets; absent when the provider omits it. */
|
|
66
120
|
resetsAt: Schema.OptionFromNullOr(Schema.DateTimeUtcFromString),
|
|
67
121
|
}) {
|
|
68
122
|
}
|
|
69
|
-
/** The
|
|
123
|
+
/** The rate-limit windows from one provider report; a window is `None` if not reported. */
|
|
70
124
|
export class RateLimitsSnapshot extends Schema.Class("Agent/RateLimitsSnapshot")({
|
|
71
125
|
limitId: Schema.OptionFromNullOr(Schema.String),
|
|
72
126
|
limitName: Schema.OptionFromNullOr(Schema.String),
|
|
@@ -74,14 +128,34 @@ export class RateLimitsSnapshot extends Schema.Class("Agent/RateLimitsSnapshot")
|
|
|
74
128
|
secondary: Schema.OptionFromNullOr(RateLimitWindow),
|
|
75
129
|
}) {
|
|
76
130
|
}
|
|
77
|
-
/** The latest rate windows observed for
|
|
131
|
+
/** The latest rate-limit windows observed for `pool` during the session. */
|
|
78
132
|
export class PoolRateLimitsUpdated extends Schema.TaggedClass("Agent/PoolRateLimitsUpdated")("PoolRateLimitsUpdated", {
|
|
79
133
|
session: AgentSession,
|
|
80
134
|
pool: BillingPool,
|
|
81
135
|
rateLimits: RateLimitsSnapshot,
|
|
82
136
|
}) {
|
|
83
137
|
}
|
|
84
|
-
/**
|
|
138
|
+
/** The number of model provider retries in the current turn, starting at 1. */
|
|
139
|
+
export const ProviderRetries = PositiveInt.pipe(Schema.brand("ProviderRetries"));
|
|
140
|
+
/**
|
|
141
|
+
* A harness report of a failed model provider request that it retries, such as Codex's
|
|
142
|
+
* `Reconnecting...`. The session isn't stopped or failed (ADR 0013).
|
|
143
|
+
*/
|
|
144
|
+
export class ProviderRetrying extends Schema.TaggedClass("Agent/ProviderRetrying")("ProviderRetrying", {
|
|
145
|
+
session: AgentSession,
|
|
146
|
+
/** The harness's failure message, verbatim if it provides one. */
|
|
147
|
+
message: Schema.NonEmptyString,
|
|
148
|
+
/** The retries reported in the current turn, including this one. */
|
|
149
|
+
retries: ProviderRetries,
|
|
150
|
+
}) {
|
|
151
|
+
}
|
|
152
|
+
/** A model provider response after a `ProviderRetrying` in the same turn. */
|
|
153
|
+
export class ProviderRecovered extends Schema.TaggedClass("Agent/ProviderRecovered")("ProviderRecovered", {
|
|
154
|
+
session: AgentSession,
|
|
155
|
+
/** The retries in the turn before the response. */
|
|
156
|
+
retries: ProviderRetries,
|
|
157
|
+
}) {
|
|
158
|
+
}
|
|
85
159
|
export const AgentSessionEvent = Schema.Union([
|
|
86
160
|
SessionStarted,
|
|
87
161
|
TextOutput,
|
|
@@ -89,5 +163,10 @@ export const AgentSessionEvent = Schema.Union([
|
|
|
89
163
|
ToolFinished,
|
|
90
164
|
PoolRateLimitsUpdated,
|
|
91
165
|
SessionFinished,
|
|
166
|
+
SessionIdle,
|
|
167
|
+
SessionResumed,
|
|
168
|
+
SessionTokensUpdated,
|
|
169
|
+
ProviderRetrying,
|
|
170
|
+
ProviderRecovered,
|
|
92
171
|
]);
|
|
93
172
|
//# sourceMappingURL=session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/agent/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/agent/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY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;CACzB,CAAC;CAAG;AAEL,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5C,cAAc;IACd,UAAU;IACV,WAAW;IACX,YAAY;IACZ,qBAAqB;IACrB,eAAe;IACf,WAAW;IACX,cAAc;IACd,oBAAoB;IACpB,gBAAgB;IAChB,iBAAiB;CAClB,CAAC,CAAC"}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { DateTime, Option, Schema } from "effect";
|
|
2
|
+
import { Agent } from "../agent/agent.ts";
|
|
2
3
|
import { BrainSpec } from "../agent/brain.ts";
|
|
4
|
+
import { Comment } from "../step/result.ts";
|
|
3
5
|
import { AttemptFailure } from "./failure.ts";
|
|
4
|
-
/**
|
|
6
|
+
/** The ID of an Attempt; each retry gets a new ID under the same Run and Step. */
|
|
5
7
|
export declare const AttemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
|
|
6
8
|
export type AttemptId = typeof AttemptId.Type;
|
|
7
|
-
/**
|
|
8
|
-
* 1-based position of a try under its step. Retries are attempt N+1 under the
|
|
9
|
-
* same step, and the auto-retry cap counts total attempts.
|
|
10
|
-
*/
|
|
9
|
+
/** The 1-based position of the Attempt in its Step. */
|
|
11
10
|
export declare const AttemptNumber: Schema.brand<Schema.Int, "AttemptNumber">;
|
|
12
11
|
export type AttemptNumber = typeof AttemptNumber.Type;
|
|
13
|
-
/**
|
|
12
|
+
/** The task text for the agent: the interpolated loop prompt or the operator's edit-and-retry text. */
|
|
14
13
|
export declare const AttemptTask: Schema.brand<Schema.String, "AttemptTask">;
|
|
15
14
|
export type AttemptTask = typeof AttemptTask.Type;
|
|
15
|
+
declare const AttemptContext_base: Schema.Class<AttemptContext, Schema.Struct<{
|
|
16
|
+
readonly task: Schema.brand<Schema.String, "AttemptTask">;
|
|
17
|
+
readonly agent: typeof Agent;
|
|
18
|
+
readonly parentModel: Schema.OptionFromNullOr<Schema.brand<Schema.String, "ModelId">>;
|
|
19
|
+
}>, {}>;
|
|
20
|
+
/** The task and Agent that an operator sets for a Run's later Attempts. */
|
|
21
|
+
export declare class AttemptContext extends AttemptContext_base {
|
|
22
|
+
}
|
|
16
23
|
declare const Attempt_base: Schema.Class<Attempt, Schema.Struct<{
|
|
17
24
|
readonly id: Schema.brand<Schema.NonEmptyString, "AttemptId">;
|
|
18
25
|
readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
|
|
@@ -20,17 +27,62 @@ declare const Attempt_base: Schema.Class<Attempt, Schema.Struct<{
|
|
|
20
27
|
readonly worker: Schema.brand<Schema.String, "WorkerName">;
|
|
21
28
|
readonly number: Schema.brand<Schema.Int, "AttemptNumber">;
|
|
22
29
|
readonly brain: typeof BrainSpec;
|
|
30
|
+
readonly task: Schema.brand<Schema.String, "AttemptTask">;
|
|
31
|
+
readonly agent: Schema.brand<Schema.String, "AgentName">;
|
|
32
|
+
readonly operatorIntervened: Schema.Boolean;
|
|
23
33
|
readonly parentModel: Schema.OptionFromNullOr<Schema.brand<Schema.String, "ModelId">>;
|
|
24
34
|
readonly startedAt: Schema.DateTimeUtc;
|
|
25
35
|
readonly outcome: Schema.Option<Schema.Union<readonly [typeof import("./outcome.ts").AttemptSucceeded, typeof import("./outcome.ts").AttemptFailed, typeof import("./outcome.ts").AttemptCanceled]>>;
|
|
36
|
+
readonly endedAt: Schema.Option<Schema.DateTimeUtc>;
|
|
37
|
+
readonly salvage: Schema.Option<Schema.Union<readonly [typeof import("./salvage.ts").SalvagePushed, typeof import("./salvage.ts").SalvageRetained]>>;
|
|
38
|
+
readonly start: Schema.withConstructorDefault<Schema.Option<Schema.Union<readonly [typeof import("./start.ts").StartedByEvent, typeof import("./start.ts").StartedByRetry, typeof import("./start.ts").StartedByEditAndRetry, typeof import("./start.ts").StartedByInfraRetry, typeof import("./start.ts").StartedAfterRestart]>>>;
|
|
39
|
+
readonly reattachedAt: Schema.withConstructorDefault<Schema.Option<Schema.DateTimeUtc>>;
|
|
40
|
+
readonly comments: Schema.withConstructorDefault<Schema.$Array<typeof Comment>>;
|
|
26
41
|
}>, {}>;
|
|
27
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* One try of a Step on a Worker.
|
|
44
|
+
*
|
|
45
|
+
* - `outcome`: `None` while the Attempt runs.
|
|
46
|
+
* - `endedAt`: the time the outcome was recorded; `None` while running and for older records.
|
|
47
|
+
* - `salvage`: what the executor kept of the workspace after an unsuccessful end.
|
|
48
|
+
* - `start`: the reason the Attempt started; `None` for older records.
|
|
49
|
+
* - `reattachedAt`: the last time an orchestrator restart reattached the Attempt.
|
|
50
|
+
* - `comments`: the comments and reviews posted by an unsuccessful Attempt; a successful
|
|
51
|
+
* Attempt's are in the Step result.
|
|
52
|
+
*/
|
|
28
53
|
export declare class Attempt extends Attempt_base {
|
|
29
54
|
}
|
|
55
|
+
declare const AttemptWindow_base: Schema.Class<AttemptWindow, Schema.Struct<{
|
|
56
|
+
readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
|
|
57
|
+
readonly startedAt: Schema.DateTimeUtc;
|
|
58
|
+
readonly endedAt: Schema.Option<Schema.DateTimeUtc>;
|
|
59
|
+
}>, {}>;
|
|
60
|
+
/**
|
|
61
|
+
* The time span of an Attempt, open while `endedAt` is `None`, used to attribute GitHub writes
|
|
62
|
+
* by Attempts that share one App login.
|
|
63
|
+
*/
|
|
64
|
+
export declare class AttemptWindow extends AttemptWindow_base {
|
|
65
|
+
}
|
|
66
|
+
/** Returns the Attempt's window, or `None` if it ended before end times were recorded. */
|
|
67
|
+
export declare const windowOf: (attempt: Attempt) => Option.Option<AttemptWindow>;
|
|
68
|
+
/** Returns whether the GitHub timestamp `at` is inside `window`. */
|
|
69
|
+
export declare const windowHolds: (window: AttemptWindow, at: DateTime.Utc) => boolean;
|
|
70
|
+
/** Returns whether a GitHub timestamp can be inside both windows. */
|
|
71
|
+
export declare const windowsOverlap: (left: AttemptWindow, right: AttemptWindow) => boolean;
|
|
72
|
+
declare const AttemptWindows_base: Schema.Class<AttemptWindows, Schema.Struct<{
|
|
73
|
+
readonly own: Schema.Option<typeof AttemptWindow>;
|
|
74
|
+
readonly overlapping: Schema.$Array<typeof AttemptWindow>;
|
|
75
|
+
}>, {}>;
|
|
76
|
+
/**
|
|
77
|
+
* The windows used to attribute writes on a Run's Item to one Attempt. A write belongs to the
|
|
78
|
+
* Attempt only if its time is inside `own` and outside every `overlapping` window, which are the
|
|
79
|
+
* same Agent's other Attempts on the Item.
|
|
80
|
+
*/
|
|
81
|
+
export declare class AttemptWindows extends AttemptWindows_base {
|
|
82
|
+
}
|
|
30
83
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* `number` is the failed try's position; `maxAutoAttempts` includes the first try.
|
|
84
|
+
* Returns whether `failure` is retryable and the failed Attempt's `number` is below
|
|
85
|
+
* `maxAutoAttempts`, which counts the first try (ADR 0002).
|
|
34
86
|
*/
|
|
35
87
|
export declare const shouldAutoRetry: (options: {
|
|
36
88
|
readonly failure: AttemptFailure;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/attempt/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/attempt/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAW,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAA0B,MAAM,cAAc,CAAC;AAKtE,kFAAkF;AAClF,eAAO,MAAM,SAAS,kDAAwD,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,uDAAuD;AACvD,eAAO,MAAM,aAAa,2CAEzB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;AAEtD,uGAAuG;AACvG,eAAO,MAAM,WAAW,4CAEW,CAAC;AACpC,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;;;;;;AAElD,2EAA2E;AAC3E,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;;;;;;;;;;;;;;;;;;;;AAEL;;;;;;;;;;GAUG;AACH,qBAAa,OAAQ,SAAQ,YAsB3B;CAAG;;;;;;AAEL;;;GAGG;AACH,qBAAa,aAAc,SAAQ,kBAIjC;CAAG;AAEL,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,YAAa,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAShE,CAAC;AAeR,oEAAoE;AACpE,eAAO,MAAM,WAAW,WAAY,aAAa,MAAM,QAAQ,CAAC,GAAG,KAAG,OAGrE,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,cAAc,SAAU,aAAa,SAAS,aAAa,KAAG,OACX,CAAC;;;;;AAEjE;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,mBAGlC;CAAG;AAEL;;;GAGG;AACH,eAAO,MAAM,eAAe,YAAa;IACvC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC;CACzC,KAAG,OAA8F,CAAC"}
|
package/dist/attempt/attempt.js
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { DateTime, Effect, Option, Schema } from "effect";
|
|
2
|
+
import { Agent, AgentName } from "../agent/agent.js";
|
|
2
3
|
import { BrainSpec, ModelId } from "../agent/brain.js";
|
|
3
4
|
import { RunId } from "../run/run.js";
|
|
5
|
+
import { Comment } from "../step/result.js";
|
|
4
6
|
import { StepName } from "../step/step.js";
|
|
5
7
|
import { WorkerName } from "../worker.js";
|
|
6
8
|
import { AttemptFailure, isAutoRetryableFailure } from "./failure.js";
|
|
7
9
|
import { AttemptOutcome } from "./outcome.js";
|
|
8
|
-
|
|
10
|
+
import { AttemptSalvage } from "./salvage.js";
|
|
11
|
+
import { AttemptStart } from "./start.js";
|
|
12
|
+
/** The ID of an Attempt; each retry gets a new ID under the same Run and Step. */
|
|
9
13
|
export const AttemptId = Schema.NonEmptyString.pipe(Schema.brand("AttemptId"));
|
|
10
|
-
/**
|
|
11
|
-
* 1-based position of a try under its step. Retries are attempt N+1 under the
|
|
12
|
-
* same step, and the auto-retry cap counts total attempts.
|
|
13
|
-
*/
|
|
14
|
+
/** The 1-based position of the Attempt in its Step. */
|
|
14
15
|
export const AttemptNumber = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(Schema.brand("AttemptNumber"));
|
|
15
|
-
/**
|
|
16
|
+
/** The task text for the agent: the interpolated loop prompt or the operator's edit-and-retry text. */
|
|
16
17
|
export const AttemptTask = Schema.String.check(Schema.isPattern(/\S/u, { message: "Expected non-blank task text" })).pipe(Schema.brand("AttemptTask"));
|
|
17
|
-
/**
|
|
18
|
+
/** The task and Agent that an operator sets for a Run's later Attempts. */
|
|
19
|
+
export class AttemptContext extends Schema.Class("AttemptContext")({
|
|
20
|
+
task: AttemptTask,
|
|
21
|
+
agent: Agent,
|
|
22
|
+
parentModel: Schema.OptionFromNullOr(ModelId),
|
|
23
|
+
}) {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One try of a Step on a Worker.
|
|
27
|
+
*
|
|
28
|
+
* - `outcome`: `None` while the Attempt runs.
|
|
29
|
+
* - `endedAt`: the time the outcome was recorded; `None` while running and for older records.
|
|
30
|
+
* - `salvage`: what the executor kept of the workspace after an unsuccessful end.
|
|
31
|
+
* - `start`: the reason the Attempt started; `None` for older records.
|
|
32
|
+
* - `reattachedAt`: the last time an orchestrator restart reattached the Attempt.
|
|
33
|
+
* - `comments`: the comments and reviews posted by an unsuccessful Attempt; a successful
|
|
34
|
+
* Attempt's are in the Step result.
|
|
35
|
+
*/
|
|
18
36
|
export class Attempt extends Schema.Class("Attempt")({
|
|
19
37
|
id: AttemptId,
|
|
20
38
|
runId: RunId,
|
|
@@ -22,15 +40,67 @@ export class Attempt extends Schema.Class("Attempt")({
|
|
|
22
40
|
worker: WorkerName,
|
|
23
41
|
number: AttemptNumber,
|
|
24
42
|
brain: BrainSpec,
|
|
43
|
+
task: AttemptTask,
|
|
44
|
+
agent: AgentName,
|
|
45
|
+
operatorIntervened: Schema.Boolean,
|
|
25
46
|
parentModel: Schema.OptionFromNullOr(ModelId),
|
|
26
47
|
startedAt: Schema.DateTimeUtc,
|
|
27
48
|
outcome: Schema.Option(AttemptOutcome),
|
|
49
|
+
endedAt: Schema.Option(Schema.DateTimeUtc),
|
|
50
|
+
salvage: Schema.Option(AttemptSalvage),
|
|
51
|
+
start: Schema.Option(AttemptStart).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
52
|
+
reattachedAt: Schema.Option(Schema.DateTimeUtc).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
53
|
+
comments: Schema.Array(Comment).pipe(Schema.withConstructorDefault(Effect.succeed([]))),
|
|
54
|
+
}) {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The time span of an Attempt, open while `endedAt` is `None`, used to attribute GitHub writes
|
|
58
|
+
* by Attempts that share one App login.
|
|
59
|
+
*/
|
|
60
|
+
export class AttemptWindow extends Schema.Class("AttemptWindow")({
|
|
61
|
+
attemptId: AttemptId,
|
|
62
|
+
startedAt: Schema.DateTimeUtc,
|
|
63
|
+
endedAt: Schema.Option(Schema.DateTimeUtc),
|
|
64
|
+
}) {
|
|
65
|
+
}
|
|
66
|
+
/** Returns the Attempt's window, or `None` if it ended before end times were recorded. */
|
|
67
|
+
export const windowOf = (attempt) => Option.isSome(attempt.outcome) && Option.isNone(attempt.endedAt)
|
|
68
|
+
? Option.none()
|
|
69
|
+
: Option.some(new AttemptWindow({
|
|
70
|
+
attemptId: attempt.id,
|
|
71
|
+
startedAt: attempt.startedAt,
|
|
72
|
+
endedAt: attempt.endedAt,
|
|
73
|
+
}));
|
|
74
|
+
/** Returns the window start truncated to the second, the precision of GitHub timestamps. */
|
|
75
|
+
const opening = (window) => {
|
|
76
|
+
const start = DateTime.toEpochMillis(window.startedAt);
|
|
77
|
+
return start - (start % 1_000);
|
|
78
|
+
};
|
|
79
|
+
/** Returns whether `window` is open or ended at or after `millis`. */
|
|
80
|
+
const reaches = (window, millis) => Option.match(window.endedAt, {
|
|
81
|
+
onNone: () => true,
|
|
82
|
+
onSome: (end) => millis <= DateTime.toEpochMillis(end),
|
|
83
|
+
});
|
|
84
|
+
/** Returns whether the GitHub timestamp `at` is inside `window`. */
|
|
85
|
+
export const windowHolds = (window, at) => {
|
|
86
|
+
const time = DateTime.toEpochMillis(at);
|
|
87
|
+
return opening(window) <= time && reaches(window, time);
|
|
88
|
+
};
|
|
89
|
+
/** Returns whether a GitHub timestamp can be inside both windows. */
|
|
90
|
+
export const windowsOverlap = (left, right) => reaches(left, opening(right)) && reaches(right, opening(left));
|
|
91
|
+
/**
|
|
92
|
+
* The windows used to attribute writes on a Run's Item to one Attempt. A write belongs to the
|
|
93
|
+
* Attempt only if its time is inside `own` and outside every `overlapping` window, which are the
|
|
94
|
+
* same Agent's other Attempts on the Item.
|
|
95
|
+
*/
|
|
96
|
+
export class AttemptWindows extends Schema.Class("AttemptWindows")({
|
|
97
|
+
own: Schema.Option(AttemptWindow),
|
|
98
|
+
overlapping: Schema.Array(AttemptWindow),
|
|
28
99
|
}) {
|
|
29
100
|
}
|
|
30
101
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* `number` is the failed try's position; `maxAutoAttempts` includes the first try.
|
|
102
|
+
* Returns whether `failure` is retryable and the failed Attempt's `number` is below
|
|
103
|
+
* `maxAutoAttempts`, which counts the first try (ADR 0002).
|
|
34
104
|
*/
|
|
35
105
|
export const shouldAutoRetry = (options) => isAutoRetryableFailure(options.failure) && options.number < options.maxAutoAttempts;
|
|
36
106
|
//# sourceMappingURL=attempt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.js","sourceRoot":"","sources":["../../src/attempt/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"attempt.js","sourceRoot":"","sources":["../../src/attempt/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AAI/E,uDAAuD;AACvD,MAAM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