@usine/core 0.1.0 → 0.3.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.
Files changed (123) hide show
  1. package/README.md +32 -22
  2. package/dist/agent/agent.d.ts +27 -0
  3. package/dist/agent/agent.d.ts.map +1 -0
  4. package/dist/agent/agent.js +26 -0
  5. package/dist/agent/agent.js.map +1 -0
  6. package/dist/agent/brain.d.ts +24 -0
  7. package/dist/agent/brain.d.ts.map +1 -0
  8. package/dist/agent/brain.js +19 -0
  9. package/dist/agent/brain.js.map +1 -0
  10. package/dist/agent/capability.d.ts +23 -0
  11. package/dist/agent/capability.d.ts.map +1 -0
  12. package/dist/agent/capability.js +19 -0
  13. package/dist/agent/capability.js.map +1 -0
  14. package/dist/agent/session.d.ts +139 -0
  15. package/dist/agent/session.d.ts.map +1 -0
  16. package/dist/agent/session.js +119 -0
  17. package/dist/agent/session.js.map +1 -0
  18. package/dist/attempt/attempt.d.ts +53 -0
  19. package/dist/attempt/attempt.d.ts.map +1 -0
  20. package/dist/attempt/attempt.js +47 -0
  21. package/dist/attempt/attempt.js.map +1 -0
  22. package/dist/attempt/channel.d.ts +194 -0
  23. package/dist/attempt/channel.d.ts.map +1 -0
  24. package/dist/attempt/channel.js +196 -0
  25. package/dist/attempt/channel.js.map +1 -0
  26. package/dist/attempt/failure.d.ts +52 -0
  27. package/dist/attempt/failure.d.ts.map +1 -0
  28. package/dist/attempt/failure.js +48 -0
  29. package/dist/attempt/failure.js.map +1 -0
  30. package/dist/attempt/outcome.d.ts +20 -0
  31. package/dist/attempt/outcome.d.ts.map +1 -0
  32. package/dist/attempt/outcome.js +16 -0
  33. package/dist/attempt/outcome.js.map +1 -0
  34. package/dist/cycle-budget.d.ts +38 -0
  35. package/dist/cycle-budget.d.ts.map +1 -0
  36. package/dist/cycle-budget.js +46 -0
  37. package/dist/cycle-budget.js.map +1 -0
  38. package/dist/{lifecycle/event.d.ts → event.d.ts} +6 -11
  39. package/dist/event.d.ts.map +1 -0
  40. package/dist/event.js +21 -0
  41. package/dist/event.js.map +1 -0
  42. package/dist/instance.d.ts +3 -7
  43. package/dist/instance.d.ts.map +1 -1
  44. package/dist/instance.js +2 -6
  45. package/dist/instance.js.map +1 -1
  46. package/dist/item.d.ts +8 -0
  47. package/dist/item.d.ts.map +1 -0
  48. package/dist/item.js +6 -0
  49. package/dist/item.js.map +1 -0
  50. package/dist/loop.d.ts +9 -0
  51. package/dist/loop.d.ts.map +1 -0
  52. package/dist/loop.js +7 -0
  53. package/dist/loop.js.map +1 -0
  54. package/dist/repository.d.ts +12 -17
  55. package/dist/repository.d.ts.map +1 -1
  56. package/dist/repository.js +11 -16
  57. package/dist/repository.js.map +1 -1
  58. package/dist/run/run.d.ts +16 -0
  59. package/dist/run/run.d.ts.map +1 -0
  60. package/dist/run/run.js +16 -0
  61. package/dist/run/run.js.map +1 -0
  62. package/dist/run/state.d.ts +114 -0
  63. package/dist/run/state.d.ts.map +1 -0
  64. package/dist/run/state.js +102 -0
  65. package/dist/run/state.js.map +1 -0
  66. package/dist/{step-result.d.ts → step/result.d.ts} +7 -9
  67. package/dist/step/result.d.ts.map +1 -0
  68. package/dist/{step-result.js → step/result.js} +8 -10
  69. package/dist/step/result.js.map +1 -0
  70. package/dist/step/step.d.ts +21 -0
  71. package/dist/step/step.d.ts.map +1 -0
  72. package/dist/step/step.js +19 -0
  73. package/dist/step/step.js.map +1 -0
  74. package/dist/worker.d.ts +7 -7
  75. package/dist/worker.d.ts.map +1 -1
  76. package/dist/worker.js +5 -5
  77. package/dist/worker.js.map +1 -1
  78. package/package.json +76 -4
  79. package/dist/agent.d.ts +0 -121
  80. package/dist/agent.d.ts.map +0 -1
  81. package/dist/agent.js +0 -105
  82. package/dist/agent.js.map +0 -1
  83. package/dist/attempt-channel.d.ts +0 -134
  84. package/dist/attempt-channel.d.ts.map +0 -1
  85. package/dist/attempt-channel.js +0 -138
  86. package/dist/attempt-channel.js.map +0 -1
  87. package/dist/index.d.ts +0 -24
  88. package/dist/index.d.ts.map +0 -1
  89. package/dist/index.js +0 -24
  90. package/dist/index.js.map +0 -1
  91. package/dist/lifecycle/attempt-failure.d.ts +0 -51
  92. package/dist/lifecycle/attempt-failure.d.ts.map +0 -1
  93. package/dist/lifecycle/attempt-failure.js +0 -45
  94. package/dist/lifecycle/attempt-failure.js.map +0 -1
  95. package/dist/lifecycle/attempt.d.ts +0 -61
  96. package/dist/lifecycle/attempt.d.ts.map +0 -1
  97. package/dist/lifecycle/attempt.js +0 -52
  98. package/dist/lifecycle/attempt.js.map +0 -1
  99. package/dist/lifecycle/event.d.ts.map +0 -1
  100. package/dist/lifecycle/event.js +0 -26
  101. package/dist/lifecycle/event.js.map +0 -1
  102. package/dist/lifecycle/item.d.ts +0 -11
  103. package/dist/lifecycle/item.d.ts.map +0 -1
  104. package/dist/lifecycle/item.js +0 -9
  105. package/dist/lifecycle/item.js.map +0 -1
  106. package/dist/lifecycle/loop.d.ts +0 -17
  107. package/dist/lifecycle/loop.d.ts.map +0 -1
  108. package/dist/lifecycle/loop.js +0 -15
  109. package/dist/lifecycle/loop.js.map +0 -1
  110. package/dist/lifecycle/run-state.d.ts +0 -133
  111. package/dist/lifecycle/run-state.d.ts.map +0 -1
  112. package/dist/lifecycle/run-state.js +0 -126
  113. package/dist/lifecycle/run-state.js.map +0 -1
  114. package/dist/lifecycle/run.d.ts +0 -22
  115. package/dist/lifecycle/run.d.ts.map +0 -1
  116. package/dist/lifecycle/run.js +0 -22
  117. package/dist/lifecycle/run.js.map +0 -1
  118. package/dist/lifecycle/step.d.ts +0 -23
  119. package/dist/lifecycle/step.d.ts.map +0 -1
  120. package/dist/lifecycle/step.js +0 -21
  121. package/dist/lifecycle/step.js.map +0 -1
  122. package/dist/step-result.d.ts.map +0 -1
  123. package/dist/step-result.js.map +0 -1
package/README.md CHANGED
@@ -1,29 +1,39 @@
1
1
  # @usine/core
2
2
 
3
- Domain model for [usine](https://github.com/basaltbytes/usine), an agent-agnostic software factory: the Event → Run → Step → Attempt vocabulary every other block types against, plus shared instance and repository value objects.
3
+ Domain model for [usine](https://github.com/basaltbytes/usine), an agent-agnostic software factory: the Event → Run → Step → Attempt vocabulary every other block types against, plus the shared instance, repository, worker, and agent values.
4
4
 
5
- Everything lives in the `lifecycle` cluster: a deduplicated Event opens a Run, the Run's named Step is tried as Attempts, and the state machine closes it.
5
+ Import each domain concept from its owning subpath. Identities, records, and operations share that domain module.
6
6
 
7
- ## What each export is
8
-
9
- | Export | Kind |
7
+ | Subpath | Exports |
10
8
  | --- | --- |
11
- | `Event`, `Run`, `Step`, `Attempt` | Entities — the four ledger rows, identity plus validated construction |
12
- | `EventId`, `RunId`, `AttemptId` | Value objects — branded ids; identities that cannot be swapped for each other |
13
- | `DedupKey`, `ItemKey`, `Item.Number`, `LoopName`, `StepName`, `AttemptNumber` | Value objects — branded primitives carrying a domain constraint; Item numbers are positive integers |
14
- | `Instance.Directory`, `Repository.Name`, `Repository.Revision`, `Repository.CommitSha` | Shared value objects — paths and validated Git identities |
15
- | `Worker.Name`, `Worker.Kind` | Value objects — a Worker identity and its local or exe.dev adapter kind |
16
- | `Agent.Agent`, `Agent.BrainSpec` | Agent values — a named persona, its child brain, and optional Pi parent-model override |
17
- | `Agent.SessionEvent` | Session events — typed parent or first-level child lifecycle, text, and tool events |
18
- | `AttemptChannel.*` | Protocol values: the secret-free run spec, framed input, and protocol-v3 Attempt envelopes (`Started` carries the effective parent model) |
19
- | `StepResult.*` | Result values — the final agent message plus commit, pull-request, and comment facts |
20
- | `RunState.*`, `CancelReason`, `Attempt.Outcome` | State value objects — discriminated unions, including a distinct canceled Attempt outcome |
21
- | `RunState.awaitApproval/start/succeed/fail/retry/cancelByOperator/supersede/revoke` | Typestate transitions — each accepts only the states it is legal on, so an illegal transition is a compile error |
22
- | `InfraFailure`, `AgentFailure`, `RunawayFailure` | Typed errors — the attempt-failure taxonomy |
23
- | `AttemptFailure.isAutoRetryable`, `Attempt.shouldAutoRetry` | Derivers — pure decision functions stating the auto-retry law (class rule; class rule capped by attempt count) |
24
-
25
- The run state machine is `pending → waiting → running → succeeded / failed / canceled`, with `failed → running` on operator retry. The failure taxonomy separates infra failures (the only auto-retryable class, capped), agent failures (always wait for the operator), and the runaway guard tripping (never auto-retried).
26
-
27
- Each Attempt records the child `BrainSpec` and effective Pi parent model used for that try. The attempt channel carries immutable repository, payload, task, and agent context in its `Start` frame; outbound `SessionEvent` envelopes retain parent and first-level child session identity.
9
+ | `@usine/core/event` | `Event`, `EventId`, `DedupKey` |
10
+ | `@usine/core/run`, `@usine/core/run/state` | `Run`, `RunId`; the run state machine as a tagged union with typestate transitions (`RunState.start`, `RunState.supersede`, ...) |
11
+ | `@usine/core/step`, `@usine/core/step/result` | `Step`, `StepName`; `StepResult` and its facts (`Commit`, `PullRequest`, `Comment`) |
12
+ | `@usine/core/attempt` | `Attempt`, `AttemptId`, `AttemptNumber`, `AttemptTask`, `shouldAutoRetry` |
13
+ | `@usine/core/attempt/outcome` | `AttemptSucceeded`, `AttemptFailed`, `AttemptCanceled`, `AttemptOutcome` |
14
+ | `@usine/core/attempt/failure` | `InfraFailure`, `DefectFailure`, `AgentFailure`, `RunawayFailure`, `ChildSessionBudgetFailure`, `AttemptFailure`, `isAutoRetryableFailure` |
15
+ | `@usine/core/attempt/channel` | The protocol-v4 attempt channel: `RunSpec`, `Start`, the envelopes, and the `admit` reducer. Import it as a namespace (`AttemptChannel.Started`) |
16
+ | `@usine/core/agent`, `@usine/core/agent/brain`, `@usine/core/agent/session` | `Agent`, `AgentName`, `AgentPersona`, parent-model resolution; `BrainSpec`, `ModelId`, `Harness`, `Effort`; `AgentSessionId`, session descriptors, `AgentSessionEvent`, `ChildSessionBudget`, `ChildSessionCount` |
17
+ | `@usine/core/agent/capability` | `HarnessCapability`, `HarnessReady`, `HarnessUnavailableError`, and the credential-free `HarnessReadiness` preflight response |
18
+ | `@usine/core/repository` | `RepositoryName`, `RepositoryRevision`, `CommitSha`, `splitRepositoryName`, `canonicalRepositoryName` |
19
+ | `@usine/core/worker`, `@usine/core/item`, `@usine/core/loop`, `@usine/core/instance` | `WorkerName`, `WorkerKind`; `ItemKey`, `ItemNumber`; `LoopName`, `ApprovalRequirement`; `InstanceDirectory` |
20
+
21
+ Branded schemas are exported under their brand name, and each has an `export type` twin of the same name so the name works in type positions too.
22
+
23
+ `PullRequest` and `Comment` facts use `URL` values in memory and URL strings in JSON, so Step results round-trip through the Attempt channel and durable storage.
24
+
25
+ The run state machine is `pending → waiting → queued → running → succeeded / failed / canceled`, with `failed → running` on operator retry. The failure taxonomy separates infra failures (the only auto-retryable class, capped), agent failures (always wait for the operator), runaway guard failures, and exhausted child-session budgets. Guard failures never auto-retry.
26
+
27
+ `RunState.operatorActions(state)` returns approval, retry, and cancel availability for operator views. The command handlers enforce the same lifecycle through the typed transitions.
28
+
29
+ Each Attempt records the child `BrainSpec` and effective Pi parent model used for that try. The attempt channel includes immutable repository, payload, task, agent context, and child-session budget in its `Start` frame; outbound `SessionEvent` envelopes retain parent and first-level child session identity.
28
30
 
29
31
  Everything is 0.x: APIs change without notice while the engine grows. `effect` is a peer dependency — supply it yourself at the pinned version.
32
+
33
+ Import `CycleLimit`, `CycleGeneration`, `CycleCount`, `LoopCycleCount`, and `CycleBudgetAsk` from `@usine/core/cycle-budget`. An Item-level Ask records the exhausted Loop, its limit, and participating Loops’ admitted and completed Runs; it can exist before another Run is opened.
34
+
35
+ `DefectFailure` records a programmer defect captured at a boundary that needs a serializable Attempt outcome. It retains the original cause and never qualifies for automatic retry.
36
+
37
+ `SessionStarted.harnessSession` optionally records a `HarnessSession`: the harness-native `HarnessSessionId` and worker working directory (`cwd`). Missing metadata in older transcripts decodes to `Option.none()`; usine's session identity remains separate.
38
+
39
+ Attempt channel protocol v6 adds saved harness session metadata. Upgrade the orchestrator and run host together; worker preflight rejects mismatched protocol versions.
@@ -0,0 +1,27 @@
1
+ import { Schema, Option } from "effect";
2
+ import { BrainSpec, Effort, ModelId } from "./brain.ts";
3
+ /** Kebab-case name of a rostered Agent, taken from its filename. */
4
+ export declare const AgentName: Schema.brand<Schema.String, "AgentName">;
5
+ export type AgentName = typeof AgentName.Type;
6
+ /** Standing Markdown instructions for one Agent. */
7
+ export declare const AgentPersona: Schema.brand<Schema.String, "AgentPersona">;
8
+ export type AgentPersona = typeof AgentPersona.Type;
9
+ declare const Agent_base: Schema.Class<Agent, Schema.Struct<{
10
+ readonly name: Schema.brand<Schema.String, "AgentName">;
11
+ /** Coding harness and settings used for this Agent's delegated child sessions. */
12
+ readonly brain: typeof BrainSpec;
13
+ /** Preferred model for the coordinating Pi parent; an absent override uses the instance default. */
14
+ readonly parentModel: Schema.OptionFromNullOr<Schema.brand<Schema.String, "ModelId">>;
15
+ /** Parent reasoning effort; an absent override uses the instance default, then the child brain's effort. */
16
+ readonly parentEffort: Schema.OptionFromOptionalKey<Schema.Literals<readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"]>>;
17
+ readonly persona: Schema.brand<Schema.String, "AgentPersona">;
18
+ }>, {}>;
19
+ /** One named member of the instance's team roster. */
20
+ export declare class Agent extends Agent_base {
21
+ }
22
+ /** Selects the Agent's parent-model override, then the instance default; `None` leaves selection to Pi. */
23
+ export declare const resolveParentModel: (agent: Agent, instanceDefault: Option.Option<ModelId>) => Option.Option<ModelId>;
24
+ /** The agent's parent-effort override, else the instance default, else the child brain's effort. */
25
+ export declare const resolveParentEffort: (agent: Agent, instanceDefault: Option.Option<Effort>) => Effort;
26
+ export {};
27
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,oEAAoE;AACpE,eAAO,MAAM,SAAS,0CAIW,CAAC;AAElC,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,oDAAoD;AACpD,eAAO,MAAM,YAAY,6CAEW,CAAC;AACrC,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;;;IAKlD,kFAAkF;;IAElF,oGAAoG;;IAGpG,4GAA4G;;;;AAR9G,sDAAsD;AACtD,qBAAa,KAAM,SAAQ,UAUzB;CAAG;AAEL,2GAA2G;AAC3G,eAAO,MAAM,kBAAkB,UACtB,KAAK,mBACK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAA6D,CAAC;AAEtF,oGAAoG;AACpG,eAAO,MAAM,mBAAmB,UAAW,KAAK,mBAAmB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAG,MAIxF,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Schema, Option } from "effect";
2
+ import { BrainSpec, Effort, ModelId } from "./brain.js";
3
+ /** Kebab-case name of a rostered Agent, taken from its filename. */
4
+ export const AgentName = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u, {
5
+ message: "Expected a kebab-case Agent name",
6
+ })).pipe(Schema.brand("AgentName"));
7
+ /** Standing Markdown instructions for one Agent. */
8
+ export const AgentPersona = Schema.String.check(Schema.isPattern(/\S/u, { message: "Expected a non-blank Agent persona" })).pipe(Schema.brand("AgentPersona"));
9
+ /** One named member of the instance's team roster. */
10
+ export class Agent extends Schema.Class("Agent")({
11
+ name: AgentName,
12
+ /** Coding harness and settings used for this Agent's delegated child sessions. */
13
+ brain: BrainSpec,
14
+ /** Preferred model for the coordinating Pi parent; an absent override uses the instance default. */
15
+ parentModel: Schema.OptionFromNullOr(ModelId),
16
+ // Optional key rather than null: older stored agent rows have no such key.
17
+ /** Parent reasoning effort; an absent override uses the instance default, then the child brain's effort. */
18
+ parentEffort: Schema.OptionFromOptionalKey(Effort),
19
+ persona: AgentPersona,
20
+ }) {
21
+ }
22
+ /** Selects the Agent's parent-model override, then the instance default; `None` leaves selection to Pi. */
23
+ export const resolveParentModel = (agent, instanceDefault) => Option.firstSomeOf([agent.parentModel, instanceDefault]);
24
+ /** The agent's parent-effort override, else the instance default, else the child brain's effort. */
25
+ export const resolveParentEffort = (agent, instanceDefault) => Option.getOrElse(Option.firstSomeOf([agent.parentEffort, instanceDefault]), () => agent.brain.effort);
26
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAC1C,MAAM,CAAC,SAAS,CAAC,6BAA6B,EAAE;IAC9C,OAAO,EAAE,kCAAkC;CAC5C,CAAC,CACH,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AAIlC,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAC7C,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,oCAAoC,EAAE,CAAC,CAC3E,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAGrC,sDAAsD;AACtD,MAAM,OAAO,KAAM,SAAQ,MAAM,CAAC,KAAK,CAAQ,OAAO,CAAC,CAAC;IACtD,IAAI,EAAE,SAAS;IACf,kFAAkF;IAClF,KAAK,EAAE,SAAS;IAChB,oGAAoG;IACpG,WAAW,EAAE,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC;IAC7C,2EAA2E;IAC3E,4GAA4G;IAC5G,YAAY,EAAE,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC;IAClD,OAAO,EAAE,YAAY;CACtB,CAAC;CAAG;AAEL,2GAA2G;AAC3G,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAY,EACZ,eAAuC,EACf,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;AAEtF,oGAAoG;AACpG,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAE,eAAsC,EAAU,EAAE,CAClG,MAAM,CAAC,SAAS,CACd,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,EACzD,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CACzB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Schema } from "effect";
2
+ /** A provider's model name; the selected harness checks its availability when the session starts. */
3
+ export declare const ModelId: Schema.brand<Schema.String, "ModelId">;
4
+ export type ModelId = typeof ModelId.Type;
5
+ /** Coding runtimes an Agent can select for delegated work. */
6
+ export declare const HARNESSES: readonly ["claude", "codex", "pi"];
7
+ /** The coding runtime that executes an Agent session. */
8
+ export declare const Harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
9
+ export type Harness = typeof Harness.Type;
10
+ /** Reasoning levels accepted in Agent files; support depends on the chosen harness and model. */
11
+ export declare const EFFORTS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
12
+ /** The requested amount of reasoning for a session; available levels depend on its harness and model. */
13
+ export declare const Effort: Schema.Literals<readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"]>;
14
+ export type Effort = typeof Effort.Type;
15
+ declare const BrainSpec_base: Schema.Class<BrainSpec, Schema.Struct<{
16
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
17
+ readonly model: Schema.brand<Schema.String, "ModelId">;
18
+ readonly effort: Schema.Literals<readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"]>;
19
+ }>, {}>;
20
+ /** How an Agent session runs: its coding harness, model, and reasoning effort. */
21
+ export declare class BrainSpec extends BrainSpec_base {
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=brain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/agent/brain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,qGAAqG;AACrG,eAAO,MAAM,OAAO,wCAEW,CAAC;AAChC,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,8DAA8D;AAC9D,eAAO,MAAM,SAAS,YAAI,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAU,CAAC;AAC5D,yDAAyD;AACzD,eAAO,MAAM,OAAO,qDAA6B,CAAC;AAClD,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAE1C,iGAAiG;AACjG,eAAO,MAAM,OAAO,YAAI,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAC5F,yGAAyG;AACzG,eAAO,MAAM,MAAM,uFAA2B,CAAC;AAC/C,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAC;;;;;;AAExC,kFAAkF;AAClF,qBAAa,SAAU,SAAQ,cAI7B;CAAG"}
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ /** A provider's model name; the selected harness checks its availability when the session starts. */
3
+ export const ModelId = Schema.String.check(Schema.isPattern(/\S/u, { message: "Expected a non-blank model id" })).pipe(Schema.brand("ModelId"));
4
+ /** Coding runtimes an Agent can select for delegated work. */
5
+ export const HARNESSES = ["claude", "codex", "pi"];
6
+ /** The coding runtime that executes an Agent session. */
7
+ export const Harness = Schema.Literals(HARNESSES);
8
+ /** Reasoning levels accepted in Agent files; support depends on the chosen harness and model. */
9
+ export const EFFORTS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
10
+ /** The requested amount of reasoning for a session; available levels depend on its harness and model. */
11
+ export const Effort = Schema.Literals(EFFORTS);
12
+ /** How an Agent session runs: its coding harness, model, and reasoning effort. */
13
+ export class BrainSpec extends Schema.Class("Agent/BrainSpec")({
14
+ harness: Harness,
15
+ model: ModelId,
16
+ effort: Effort,
17
+ }) {
18
+ }
19
+ //# sourceMappingURL=brain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain.js","sourceRoot":"","sources":["../../src/agent/brain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,qGAAqG;AACrG,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CACxC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CACtE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;AAGhC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAU,CAAC;AAC5D,yDAAyD;AACzD,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAGlD,iGAAiG;AACjG,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAC5F,yGAAyG;AACzG,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAG/C,kFAAkF;AAClF,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,KAAK,CAAY,iBAAiB,CAAC,CAAC;IACxE,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,MAAM;CACf,CAAC;CAAG"}
@@ -0,0 +1,23 @@
1
+ import { Schema } from "effect";
2
+ /** A harness prerequisite that requires operator provisioning, never an automatic retry. */
3
+ export declare const HarnessCapability: Schema.Literals<readonly ["binary", "version", "login"]>;
4
+ export type HarnessCapability = typeof HarnessCapability.Type;
5
+ declare const HarnessUnavailableError_base: Schema.Class<HarnessUnavailableError, Schema.TaggedStruct<"HarnessUnavailableError", {
6
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
7
+ readonly capability: Schema.Literals<readonly ["binary", "version", "login"]>;
8
+ readonly message: Schema.NonEmptyString;
9
+ }>, import("effect/Cause").YieldableError>;
10
+ /** The Worker cannot run the requested harness until the operator fixes its provisioning. */
11
+ export declare class HarnessUnavailableError extends HarnessUnavailableError_base {
12
+ }
13
+ declare const HarnessReady_base: Schema.Class<HarnessReady, Schema.TaggedStruct<"HarnessReady", {
14
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
15
+ }>, {}>;
16
+ /** A verify-only probe found the requested harness available in the Worker's environment. */
17
+ export declare class HarnessReady extends HarnessReady_base {
18
+ }
19
+ /** The run host's preflight response; contains no credentials or account identity. */
20
+ export declare const HarnessReadiness: Schema.Union<readonly [typeof HarnessReady, typeof HarnessUnavailableError]>;
21
+ export type HarnessReadiness = typeof HarnessReadiness.Type;
22
+ export {};
23
+ //# sourceMappingURL=capability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/agent/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,4FAA4F;AAC5F,eAAO,MAAM,iBAAiB,0DAAkD,CAAC;AACjF,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;;AAE9D,6FAA6F;AAC7F,qBAAa,uBAAwB,SAAQ,4BAM3C;CAAG;;;;AAEL,6FAA6F;AAC7F,qBAAa,YAAa,SAAQ,iBAEhC;CAAG;AAEL,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,8EAAwD,CAAC;AACtF,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ import { Harness } from "./brain.js";
3
+ /** A harness prerequisite that requires operator provisioning, never an automatic retry. */
4
+ export const HarnessCapability = Schema.Literals(["binary", "version", "login"]);
5
+ /** The Worker cannot run the requested harness until the operator fixes its provisioning. */
6
+ export class HarnessUnavailableError extends Schema.TaggedError("HarnessUnavailableError")("HarnessUnavailableError", {
7
+ harness: Harness,
8
+ capability: HarnessCapability,
9
+ message: Schema.NonEmptyString,
10
+ }) {
11
+ }
12
+ /** A verify-only probe found the requested harness available in the Worker's environment. */
13
+ export class HarnessReady extends Schema.TaggedClass("HarnessReady")("HarnessReady", {
14
+ harness: Harness,
15
+ }) {
16
+ }
17
+ /** The run host's preflight response; contains no credentials or account identity. */
18
+ export const HarnessReadiness = Schema.Union([HarnessReady, HarnessUnavailableError]);
19
+ //# sourceMappingURL=capability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.js","sourceRoot":"","sources":["../../src/agent/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAGjF,6FAA6F;AAC7F,MAAM,OAAO,uBAAwB,SAAQ,MAAM,CAAC,WAAW,CAC7D,yBAAyB,CAC1B,CAAC,yBAAyB,EAAE;IAC3B,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE,iBAAiB;IAC7B,OAAO,EAAE,MAAM,CAAC,cAAc;CAC/B,CAAC;CAAG;AAEL,6FAA6F;AAC7F,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,CAAe,cAAc,CAAC,CAAC,cAAc,EAAE;IACjG,OAAO,EAAE,OAAO;CACjB,CAAC;CAAG;AAEL,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,139 @@
1
+ import { Schema } from "effect";
2
+ import { BrainSpec } from "./brain.ts";
3
+ /** Identity usine assigns to a parent or child session within an Attempt. */
4
+ export declare const AgentSessionId: Schema.brand<Schema.NonEmptyString, "AgentSessionId">;
5
+ export type AgentSessionId = typeof AgentSessionId.Type;
6
+ /** A provider-reported count of input, output, and cached tokens. */
7
+ export declare const TokenCount: Schema.brand<Schema.Int, "TokenCount">;
8
+ export type TokenCount = typeof TokenCount.Type;
9
+ /** Maximum child sessions one Attempt may spawn over its lifetime, including sequential spawns. */
10
+ export declare const ChildSessionBudget: Schema.brand<Schema.Int, "ChildSessionBudget">;
11
+ export type ChildSessionBudget = typeof ChildSessionBudget.Type;
12
+ /** The 1-based child spawn request number within an Attempt, including requests rejected by the budget. */
13
+ export declare const ChildSessionCount: Schema.brand<Schema.Int, "ChildSessionCount">;
14
+ export type ChildSessionCount = typeof ChildSessionCount.Type;
15
+ declare const ParentSession_base: Schema.Class<ParentSession, Schema.TaggedStruct<"ParentSession", {
16
+ readonly id: Schema.brand<Schema.NonEmptyString, "AgentSessionId">;
17
+ readonly agent: Schema.brand<Schema.String, "AgentName">;
18
+ readonly brain: typeof BrainSpec;
19
+ }>, {}>;
20
+ /** The session coordinating an Attempt and delegating work to its coding children. */
21
+ export declare class ParentSession extends ParentSession_base {
22
+ }
23
+ declare const ChildSession_base: Schema.Class<ChildSession, Schema.TaggedStruct<"ChildSession", {
24
+ readonly id: Schema.brand<Schema.NonEmptyString, "AgentSessionId">;
25
+ readonly parentId: Schema.brand<Schema.NonEmptyString, "AgentSessionId">;
26
+ readonly agent: Schema.brand<Schema.String, "AgentName">;
27
+ readonly brain: typeof BrainSpec;
28
+ }>, {}>;
29
+ /** A coding session delegated by the Attempt's parent; children cannot delegate to further children. */
30
+ export declare class ChildSession extends ChildSession_base {
31
+ }
32
+ /** A participant in an Attempt, with its role, Agent, and effective brain recorded. */
33
+ export declare const AgentSession: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
34
+ export type AgentSession = typeof AgentSession.Type;
35
+ /** The identity assigned by a harness to its saved conversation, distinct from usine's session id. */
36
+ export declare const HarnessSessionId: Schema.brand<Schema.NonEmptyString, "HarnessSessionId">;
37
+ export type HarnessSessionId = typeof HarnessSessionId.Type;
38
+ declare const HarnessSession_base: Schema.Class<HarnessSession, Schema.Struct<{
39
+ readonly id: Schema.brand<Schema.NonEmptyString, "HarnessSessionId">;
40
+ readonly cwd: Schema.NonEmptyString;
41
+ }>, {}>;
42
+ /** A saved harness conversation and the worker checkout from which it can be resumed. */
43
+ export declare class HarnessSession extends HarnessSession_base {
44
+ }
45
+ declare const SessionStarted_base: Schema.Class<SessionStarted, Schema.TaggedStruct<"SessionStarted", {
46
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
47
+ /** Absent for older transcripts and harnesses without a saved conversation. */
48
+ readonly harnessSession: Schema.withConstructorDefault<Schema.OptionFromOptionalKey<typeof HarnessSession>>;
49
+ }>, {}>;
50
+ /** Records the session identity and brain actually selected at launch. */
51
+ export declare class SessionStarted extends SessionStarted_base {
52
+ }
53
+ declare const TextOutput_base: Schema.Class<TextOutput, Schema.TaggedStruct<"TextOutput", {
54
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
55
+ readonly text: Schema.NonEmptyString;
56
+ }>, {}>;
57
+ /** Completed assistant text emitted during the session, which may precede its final result. */
58
+ export declare class TextOutput extends TextOutput_base {
59
+ }
60
+ declare const ToolStarted_base: Schema.Class<ToolStarted, Schema.TaggedStruct<"ToolStarted", {
61
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
62
+ readonly callId: Schema.NonEmptyString;
63
+ readonly tool: Schema.NonEmptyString;
64
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
65
+ }>, {}>;
66
+ /** A session began a tool call; `callId` pairs it with the corresponding result. */
67
+ export declare class ToolStarted extends ToolStarted_base {
68
+ }
69
+ declare const ToolFinished_base: Schema.Class<ToolFinished, Schema.TaggedStruct<"ToolFinished", {
70
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
71
+ readonly callId: Schema.NonEmptyString;
72
+ readonly tool: Schema.NonEmptyString;
73
+ readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
74
+ readonly isError: Schema.Boolean;
75
+ }>, {}>;
76
+ /** A tool call returned its output; a tool error does not by itself close the session. */
77
+ export declare class ToolFinished extends ToolFinished_base {
78
+ }
79
+ declare const SessionFinished_base: Schema.Class<SessionFinished, Schema.TaggedStruct<"SessionFinished", {
80
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
81
+ }>, {}>;
82
+ /** Marks the end of a session's activity in the transcript; the Attempt's outcome is recorded separately. */
83
+ export declare class SessionFinished extends SessionFinished_base {
84
+ }
85
+ declare const SessionIdle_base: Schema.Class<SessionIdle, Schema.TaggedStruct<"SessionIdle", {
86
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
87
+ }>, {}>;
88
+ /** A supervised session finished a turn and remains available for further operator messages. */
89
+ export declare class SessionIdle extends SessionIdle_base {
90
+ }
91
+ declare const SessionResumed_base: Schema.Class<SessionResumed, Schema.TaggedStruct<"SessionResumed", {
92
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
93
+ }>, {}>;
94
+ /** A live session is processing another user turn in the same conversation. */
95
+ export declare class SessionResumed extends SessionResumed_base {
96
+ }
97
+ declare const SessionTokensUpdated_base: Schema.Class<SessionTokensUpdated, Schema.TaggedStruct<"SessionTokensUpdated", {
98
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
99
+ readonly totalTokens: Schema.brand<Schema.Int, "TokenCount">;
100
+ }>, {}>;
101
+ /** Cumulative tokens consumed by this session, including its later operator turns. */
102
+ export declare class SessionTokensUpdated extends SessionTokensUpdated_base {
103
+ }
104
+ /** The billing source whose meter produced a usage or rate-limit observation. */
105
+ export declare const BillingPool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
106
+ export type BillingPool = typeof BillingPool.Type;
107
+ declare const RateLimitWindow_base: Schema.Class<RateLimitWindow, Schema.Struct<{
108
+ /** Percentage of the allowance already consumed, including usage outside this Attempt. */
109
+ readonly usedPercent: Schema.Number;
110
+ /** Length of the allowance window; absent when the provider omits it. */
111
+ readonly windowDurationMinutes: Schema.OptionFromNullOr<Schema.Number>;
112
+ /** When the allowance resets; absent when the provider omits it. */
113
+ readonly resetsAt: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
114
+ }>, {}>;
115
+ /** A billing pool's observed usage for one allowance window. */
116
+ export declare class RateLimitWindow extends RateLimitWindow_base {
117
+ }
118
+ declare const RateLimitsSnapshot_base: Schema.Class<RateLimitsSnapshot, Schema.Struct<{
119
+ readonly limitId: Schema.OptionFromNullOr<Schema.String>;
120
+ readonly limitName: Schema.OptionFromNullOr<Schema.String>;
121
+ readonly primary: Schema.OptionFromNullOr<typeof RateLimitWindow>;
122
+ readonly secondary: Schema.OptionFromNullOr<typeof RateLimitWindow>;
123
+ }>, {}>;
124
+ /** The allowance windows reported together by a provider; omitted windows remain unknown. */
125
+ export declare class RateLimitsSnapshot extends RateLimitsSnapshot_base {
126
+ }
127
+ declare const PoolRateLimitsUpdated_base: Schema.Class<PoolRateLimitsUpdated, Schema.TaggedStruct<"PoolRateLimitsUpdated", {
128
+ readonly session: Schema.Union<readonly [typeof ParentSession, typeof ChildSession]>;
129
+ readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
130
+ readonly rateLimits: typeof RateLimitsSnapshot;
131
+ }>, {}>;
132
+ /** The latest rate windows observed for a billing pool during one session. */
133
+ export declare class PoolRateLimitsUpdated extends PoolRateLimitsUpdated_base {
134
+ }
135
+ /** Session activity and billing observations recorded in an Attempt's transcript. */
136
+ export declare const AgentSessionEvent: Schema.Union<readonly [typeof SessionStarted, typeof TextOutput, typeof ToolStarted, typeof ToolFinished, typeof PoolRateLimitsUpdated, typeof SessionFinished, typeof SessionIdle, typeof SessionResumed, typeof SessionTokensUpdated]>;
137
+ export type AgentSessionEvent = typeof AgentSessionEvent.Type;
138
+ export {};
139
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/agent/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,6EAA6E;AAC7E,eAAO,MAAM,cAAc,uDAA6D,CAAC;AACzF,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAExD,qEAAqE;AACrE,eAAO,MAAM,UAAU,wCAEtB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAC;AAIhD,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,gDAAuD,CAAC;AACvF,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAC;AAEhE,2GAA2G;AAC3G,eAAO,MAAM,iBAAiB,+CAAsD,CAAC;AACrF,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;;AAE9D,sFAAsF;AACt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AAa,qBAAsB,SAAQ,0BAMzC;CAAG;AAEL,qFAAqF;AACrF,eAAO,MAAM,iBAAiB,0OAU5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { Effect, Option, Schema } from "effect";
2
+ import { AgentName } from "./agent.js";
3
+ import { BrainSpec } from "./brain.js";
4
+ /** Identity usine assigns to a parent or child session within an Attempt. */
5
+ export const AgentSessionId = Schema.NonEmptyString.pipe(Schema.brand("AgentSessionId"));
6
+ /** A provider-reported count of input, output, and cached tokens. */
7
+ export const TokenCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.brand("TokenCount"));
8
+ const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
9
+ /** Maximum child sessions one Attempt may spawn over its lifetime, including sequential spawns. */
10
+ export const ChildSessionBudget = PositiveInt.pipe(Schema.brand("ChildSessionBudget"));
11
+ /** The 1-based child spawn request number within an Attempt, including requests rejected by the budget. */
12
+ export const ChildSessionCount = PositiveInt.pipe(Schema.brand("ChildSessionCount"));
13
+ /** The session coordinating an Attempt and delegating work to its coding children. */
14
+ export class ParentSession extends Schema.TaggedClass("Agent/ParentSession")("ParentSession", {
15
+ id: AgentSessionId,
16
+ agent: AgentName,
17
+ brain: BrainSpec,
18
+ }) {
19
+ }
20
+ /** A coding session delegated by the Attempt's parent; children cannot delegate to further children. */
21
+ export class ChildSession extends Schema.TaggedClass("Agent/ChildSession")("ChildSession", {
22
+ id: AgentSessionId,
23
+ parentId: AgentSessionId,
24
+ agent: AgentName,
25
+ brain: BrainSpec,
26
+ }) {
27
+ }
28
+ /** A participant in an Attempt, with its role, Agent, and effective brain recorded. */
29
+ export const AgentSession = Schema.Union([ParentSession, ChildSession]);
30
+ /** The identity assigned by a harness to its saved conversation, distinct from usine's session id. */
31
+ export const HarnessSessionId = Schema.NonEmptyString.pipe(Schema.brand("HarnessSessionId"));
32
+ /** A saved harness conversation and the worker checkout from which it can be resumed. */
33
+ export class HarnessSession extends Schema.Class("Agent/HarnessSession")({
34
+ id: HarnessSessionId,
35
+ cwd: Schema.NonEmptyString,
36
+ }) {
37
+ }
38
+ /** Records the session identity and brain actually selected at launch. */
39
+ export class SessionStarted extends Schema.TaggedClass("Agent/SessionStarted")("SessionStarted", {
40
+ session: AgentSession,
41
+ /** Absent for older transcripts and harnesses without a saved conversation. */
42
+ harnessSession: Schema.OptionFromOptionalKey(HarnessSession).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
43
+ }) {
44
+ }
45
+ /** Completed assistant text emitted during the session, which may precede its final result. */
46
+ export class TextOutput extends Schema.TaggedClass("Agent/TextOutput")("TextOutput", {
47
+ session: AgentSession,
48
+ text: Schema.NonEmptyString,
49
+ }) {
50
+ }
51
+ /** A session began a tool call; `callId` pairs it with the corresponding result. */
52
+ export class ToolStarted extends Schema.TaggedClass("Agent/ToolStarted")("ToolStarted", {
53
+ session: AgentSession,
54
+ callId: Schema.NonEmptyString,
55
+ tool: Schema.NonEmptyString,
56
+ input: Schema.Json,
57
+ }) {
58
+ }
59
+ /** A tool call returned its output; a tool error does not by itself close the session. */
60
+ export class ToolFinished extends Schema.TaggedClass("Agent/ToolFinished")("ToolFinished", {
61
+ session: AgentSession,
62
+ callId: Schema.NonEmptyString,
63
+ tool: Schema.NonEmptyString,
64
+ output: Schema.Json,
65
+ isError: Schema.Boolean,
66
+ }) {
67
+ }
68
+ /** Marks the end of a session's activity in the transcript; the Attempt's outcome is recorded separately. */
69
+ export class SessionFinished extends Schema.TaggedClass("Agent/SessionFinished")("SessionFinished", { session: AgentSession }) {
70
+ }
71
+ /** A supervised session finished a turn and remains available for further operator messages. */
72
+ export class SessionIdle extends Schema.TaggedClass("Agent/SessionIdle")("SessionIdle", { session: AgentSession }) {
73
+ }
74
+ /** A live session is processing another user turn in the same conversation. */
75
+ export class SessionResumed extends Schema.TaggedClass("Agent/SessionResumed")("SessionResumed", { session: AgentSession }) {
76
+ }
77
+ /** Cumulative tokens consumed by this session, including its later operator turns. */
78
+ export class SessionTokensUpdated extends Schema.TaggedClass("Agent/SessionTokensUpdated")("SessionTokensUpdated", { session: AgentSession, totalTokens: TokenCount }) {
79
+ }
80
+ /** The billing source whose meter produced a usage or rate-limit observation. */
81
+ export const BillingPool = Schema.Literals(["apiKeys", "claudePlan", "chatgptPlan"]);
82
+ /** A billing pool's observed usage for one allowance window. */
83
+ export class RateLimitWindow extends Schema.Class("Agent/RateLimitWindow")({
84
+ /** Percentage of the allowance already consumed, including usage outside this Attempt. */
85
+ usedPercent: Schema.Number,
86
+ /** Length of the allowance window; absent when the provider omits it. */
87
+ windowDurationMinutes: Schema.OptionFromNullOr(Schema.Number),
88
+ /** When the allowance resets; absent when the provider omits it. */
89
+ resetsAt: Schema.OptionFromNullOr(Schema.DateTimeUtcFromString),
90
+ }) {
91
+ }
92
+ /** The allowance windows reported together by a provider; omitted windows remain unknown. */
93
+ export class RateLimitsSnapshot extends Schema.Class("Agent/RateLimitsSnapshot")({
94
+ limitId: Schema.OptionFromNullOr(Schema.String),
95
+ limitName: Schema.OptionFromNullOr(Schema.String),
96
+ primary: Schema.OptionFromNullOr(RateLimitWindow),
97
+ secondary: Schema.OptionFromNullOr(RateLimitWindow),
98
+ }) {
99
+ }
100
+ /** The latest rate windows observed for a billing pool during one session. */
101
+ export class PoolRateLimitsUpdated extends Schema.TaggedClass("Agent/PoolRateLimitsUpdated")("PoolRateLimitsUpdated", {
102
+ session: AgentSession,
103
+ pool: BillingPool,
104
+ rateLimits: RateLimitsSnapshot,
105
+ }) {
106
+ }
107
+ /** Session activity and billing observations recorded in an Attempt's transcript. */
108
+ export const AgentSessionEvent = Schema.Union([
109
+ SessionStarted,
110
+ TextOutput,
111
+ ToolStarted,
112
+ ToolFinished,
113
+ PoolRateLimitsUpdated,
114
+ SessionFinished,
115
+ SessionIdle,
116
+ SessionResumed,
117
+ SessionTokensUpdated,
118
+ ]);
119
+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,CAAC,KAAK,CAAkB,uBAAuB,CAAC,CAAC;IAC1F,0FAA0F;IAC1F,WAAW,EAAE,MAAM,CAAC,MAAM;IAC1B,yEAAyE;IACzE,qBAAqB,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC;IAC7D,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,qBAAqB,CAAC;CAChE,CAAC;CAAG;AAEL,6FAA6F;AAC7F,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,KAAK,CAClD,0BAA0B,CAC3B,CAAC;IACA,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC;CACpD,CAAC;CAAG;AAEL,8EAA8E;AAC9E,MAAM,OAAO,qBAAsB,SAAQ,MAAM,CAAC,WAAW,CAC3D,6BAA6B,CAC9B,CAAC,uBAAuB,EAAE;IACzB,OAAO,EAAE,YAAY;IACrB,IAAI,EAAE,WAAW;IACjB,UAAU,EAAE,kBAAkB;CAC/B,CAAC;CAAG;AAEL,qFAAqF;AACrF,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;CACrB,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { Schema } from "effect";
2
+ import { Agent } from "../agent/agent.ts";
3
+ import { BrainSpec } from "../agent/brain.ts";
4
+ import { AttemptFailure } from "./failure.ts";
5
+ /** Identity of one execution try; each retry receives a new identity under the same Run and Step. */
6
+ export declare const AttemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
7
+ export type AttemptId = typeof AttemptId.Type;
8
+ /**
9
+ * 1-based position of a try under its step. Retries are attempt N+1 under the
10
+ * same step, and the auto-retry cap counts total attempts.
11
+ */
12
+ export declare const AttemptNumber: Schema.brand<Schema.Int, "AttemptNumber">;
13
+ export type AttemptNumber = typeof AttemptNumber.Type;
14
+ /** Task text given to the agent after loop interpolation or an operator's edit-and-retry amendment. */
15
+ export declare const AttemptTask: Schema.brand<Schema.String, "AttemptTask">;
16
+ export type AttemptTask = typeof AttemptTask.Type;
17
+ declare const AttemptContext_base: Schema.Class<AttemptContext, Schema.Struct<{
18
+ readonly task: Schema.brand<Schema.String, "AttemptTask">;
19
+ readonly agent: typeof Agent;
20
+ readonly parentModel: Schema.OptionFromNullOr<Schema.brand<Schema.String, "ModelId">>;
21
+ }>, {}>;
22
+ /** The effective task and roster Agent an operator assigns to a Run's later Attempts. */
23
+ export declare class AttemptContext extends AttemptContext_base {
24
+ }
25
+ declare const Attempt_base: Schema.Class<Attempt, Schema.Struct<{
26
+ readonly id: Schema.brand<Schema.NonEmptyString, "AttemptId">;
27
+ readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
28
+ readonly stepName: Schema.brand<Schema.NonEmptyString, "StepName">;
29
+ readonly worker: Schema.brand<Schema.String, "WorkerName">;
30
+ readonly number: Schema.brand<Schema.Int, "AttemptNumber">;
31
+ readonly brain: typeof BrainSpec;
32
+ readonly task: Schema.brand<Schema.String, "AttemptTask">;
33
+ readonly agent: Schema.brand<Schema.String, "AgentName">;
34
+ readonly operatorIntervened: Schema.Boolean;
35
+ readonly parentModel: Schema.OptionFromNullOr<Schema.brand<Schema.String, "ModelId">>;
36
+ readonly startedAt: Schema.DateTimeUtc;
37
+ readonly outcome: Schema.Option<Schema.Union<readonly [typeof import("./outcome.ts").AttemptSucceeded, typeof import("./outcome.ts").AttemptFailed, typeof import("./outcome.ts").AttemptCanceled]>>;
38
+ }>, {}>;
39
+ /** One try of a step on a worker. `outcome` is none while the attempt is in flight. */
40
+ export declare class Attempt extends Attempt_base {
41
+ }
42
+ /**
43
+ * The auto-retry law: only an infra failure retries, and only while the attempt
44
+ * number is below `maxAutoAttempts` (ADR 0002).
45
+ * `number` is the failed try's position; `maxAutoAttempts` includes the first try.
46
+ */
47
+ export declare const shouldAutoRetry: (options: {
48
+ readonly failure: AttemptFailure;
49
+ readonly number: AttemptNumber;
50
+ readonly maxAutoAttempts: AttemptNumber;
51
+ }) => boolean;
52
+ export {};
53
+ //# sourceMappingURL=attempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/attempt/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAW,MAAM,mBAAmB,CAAC;AAIvD,OAAO,EAAE,cAAc,EAA0B,MAAM,cAAc,CAAC;AAGtE,qGAAqG;AACrG,eAAO,MAAM,SAAS,kDAAwD,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C;;;GAGG;AACH,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,yFAAyF;AACzF,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;;;;;;;;;;;;;;;AAEL,uFAAuF;AACvF,qBAAa,OAAQ,SAAQ,YAa3B;CAAG;AAEL;;;;GAIG;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"}