@usine/agents 0.3.0 → 0.5.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 (114) hide show
  1. package/LICENSE +661 -21
  2. package/README.md +100 -30
  3. package/dist/child-host/child-host.d.ts +90 -0
  4. package/dist/child-host/child-host.d.ts.map +1 -0
  5. package/dist/child-host/child-host.js +119 -0
  6. package/dist/child-host/child-host.js.map +1 -0
  7. package/dist/child-host/command.d.ts +22 -0
  8. package/dist/child-host/command.d.ts.map +1 -0
  9. package/dist/child-host/command.js +43 -0
  10. package/dist/child-host/command.js.map +1 -0
  11. package/dist/openai-prices.d.ts +8 -0
  12. package/dist/openai-prices.d.ts.map +1 -0
  13. package/dist/openai-prices.js +28 -0
  14. package/dist/openai-prices.js.map +1 -0
  15. package/dist/pi/authentication.d.ts +11 -2
  16. package/dist/pi/authentication.d.ts.map +1 -1
  17. package/dist/pi/authentication.js +15 -2
  18. package/dist/pi/authentication.js.map +1 -1
  19. package/dist/pi/children.d.ts +1 -4
  20. package/dist/pi/children.d.ts.map +1 -1
  21. package/dist/pi/children.js +1 -4
  22. package/dist/pi/children.js.map +1 -1
  23. package/dist/pi/claude/claude.d.ts +10 -0
  24. package/dist/pi/claude/claude.d.ts.map +1 -0
  25. package/dist/pi/claude/claude.js +610 -0
  26. package/dist/pi/claude/claude.js.map +1 -0
  27. package/dist/pi/claude/codec.d.ts +67 -0
  28. package/dist/pi/claude/codec.d.ts.map +1 -0
  29. package/dist/pi/claude/codec.js +140 -0
  30. package/dist/pi/claude/codec.js.map +1 -0
  31. package/dist/pi/{claude.d.ts → claude/sdk.d.ts} +11 -10
  32. package/dist/pi/claude/sdk.d.ts.map +1 -0
  33. package/dist/pi/claude/sdk.js +63 -0
  34. package/dist/pi/claude/sdk.js.map +1 -0
  35. package/dist/pi/codex/account.d.ts +11 -5
  36. package/dist/pi/codex/account.d.ts.map +1 -1
  37. package/dist/pi/codex/account.js +23 -6
  38. package/dist/pi/codex/account.js.map +1 -1
  39. package/dist/pi/codex/app-server.d.ts +19 -7
  40. package/dist/pi/codex/app-server.d.ts.map +1 -1
  41. package/dist/pi/codex/app-server.js +41 -36
  42. package/dist/pi/codex/app-server.js.map +1 -1
  43. package/dist/pi/codex/codec.d.ts +10 -84
  44. package/dist/pi/codex/codec.d.ts.map +1 -1
  45. package/dist/pi/codex/codec.js +18 -80
  46. package/dist/pi/codex/codec.js.map +1 -1
  47. package/dist/pi/codex/codex.d.ts +0 -1
  48. package/dist/pi/codex/codex.d.ts.map +1 -1
  49. package/dist/pi/codex/codex.js +89 -18
  50. package/dist/pi/codex/codex.js.map +1 -1
  51. package/dist/pi/conversation.d.ts +33 -12
  52. package/dist/pi/conversation.d.ts.map +1 -1
  53. package/dist/pi/conversation.js +58 -18
  54. package/dist/pi/conversation.js.map +1 -1
  55. package/dist/pi/pi.d.ts +1 -4
  56. package/dist/pi/pi.d.ts.map +1 -1
  57. package/dist/pi/pi.js +29 -175
  58. package/dist/pi/pi.js.map +1 -1
  59. package/dist/pi/sdk.d.ts +18 -15
  60. package/dist/pi/sdk.d.ts.map +1 -1
  61. package/dist/pi/sdk.js +45 -55
  62. package/dist/pi/sdk.js.map +1 -1
  63. package/dist/pi/session.d.ts +13 -14
  64. package/dist/pi/session.d.ts.map +1 -1
  65. package/dist/pi/session.js +63 -24
  66. package/dist/pi/session.js.map +1 -1
  67. package/dist/pi/turns.d.ts +7 -7
  68. package/dist/pi/turns.d.ts.map +1 -1
  69. package/dist/pi/turns.js +22 -9
  70. package/dist/pi/turns.js.map +1 -1
  71. package/dist/pi/usage.d.ts +36 -22
  72. package/dist/pi/usage.d.ts.map +1 -1
  73. package/dist/pi/usage.js +79 -33
  74. package/dist/pi/usage.js.map +1 -1
  75. package/dist/preflight/command.d.ts +16 -4
  76. package/dist/preflight/command.d.ts.map +1 -1
  77. package/dist/preflight/command.js +29 -27
  78. package/dist/preflight/command.js.map +1 -1
  79. package/dist/preflight/preflight.d.ts +19 -7
  80. package/dist/preflight/preflight.d.ts.map +1 -1
  81. package/dist/preflight/preflight.js +73 -32
  82. package/dist/preflight/preflight.js.map +1 -1
  83. package/dist/prompt.d.ts +12 -9
  84. package/dist/prompt.d.ts.map +1 -1
  85. package/dist/prompt.js +33 -4
  86. package/dist/prompt.js.map +1 -1
  87. package/dist/protocol/codex.d.ts +122 -7
  88. package/dist/protocol/codex.d.ts.map +1 -1
  89. package/dist/protocol/codex.js +109 -1
  90. package/dist/protocol/codex.js.map +1 -1
  91. package/dist/protocol/count.d.ts +4 -0
  92. package/dist/protocol/count.d.ts.map +1 -0
  93. package/dist/protocol/count.js +4 -0
  94. package/dist/protocol/count.js.map +1 -0
  95. package/dist/runtime.d.ts +110 -55
  96. package/dist/runtime.d.ts.map +1 -1
  97. package/dist/runtime.js +114 -27
  98. package/dist/runtime.js.map +1 -1
  99. package/package.json +35 -19
  100. package/dist/pi/claude.d.ts.map +0 -1
  101. package/dist/pi/claude.js +0 -302
  102. package/dist/pi/claude.js.map +0 -1
  103. package/dist/pi/live.d.ts +0 -4
  104. package/dist/pi/live.d.ts.map +0 -1
  105. package/dist/pi/live.js +0 -11
  106. package/dist/pi/live.js.map +0 -1
  107. package/dist/pi/subagents.d.ts +0 -29
  108. package/dist/pi/subagents.d.ts.map +0 -1
  109. package/dist/pi/subagents.js +0 -120
  110. package/dist/pi/subagents.js.map +0 -1
  111. package/dist/pi/thinking.d.ts +0 -8
  112. package/dist/pi/thinking.d.ts.map +0 -1
  113. package/dist/pi/thinking.js +0 -15
  114. package/dist/pi/thinking.js.map +0 -1
package/dist/prompt.js CHANGED
@@ -1,5 +1,15 @@
1
- /** The attribution line every GitHub comment or review written by an Agent ends with. */
2
- export const githubSignature = (agent) => `— usine agent: ${agent}`;
1
+ import { githubSignature } from "@usine/core/agent";
2
+ import { Option } from "effect";
3
+ import { BLOCKED_MARKER, QUESTION_MARKER } from "./runtime.js";
4
+ const completionInstructions = [
5
+ "# Task completion",
6
+ "",
7
+ "Run gates, tests, and CI watches in the foreground. If a tool starts background work, wait for its result and finish every dependent step before returning your final answer.",
8
+ "Do not end a turn promising to resume after a background notification. Your final answer returns control to the caller and may end the Attempt and remove its worktree. Push all commits that must survive before returning.",
9
+ "A running command or pending CI check is unfinished work, not a blocker. Keep waiting and complete the task. For a genuine blocker, record the exact blocker on the issue or pull request and report which work remains incomplete.",
10
+ `For an unresolved blocker, start your final answer with exactly ${BLOCKED_MARKER} on its own line, followed by the exact blocker and incomplete work. This reserved marker reports a failed Attempt. A child's report that starts with the marker fails the Attempt: return it verbatim as your own final answer. Use an ordinary final answer only after completing the task.`,
11
+ `When the work needs a decision that only the operator can make, post the question on the task's issue or pull request when it has one, then start your final answer with exactly ${QUESTION_MARKER} on its own line, followed by the question and the options you see. This reserved marker ends the Attempt and asks the operator; usine does not run this task again on the same Item until the operator answers or the Item changes. Return a child's report that starts with this marker verbatim as your own final answer.`,
12
+ ];
3
13
  const githubInstructions = (agent) => [
4
14
  "# GitHub identity",
5
15
  "",
@@ -9,11 +19,26 @@ const githubInstructions = (agent) => [
9
19
  "Append this signature to every GitHub comment, issue, pull request, or review you publish:",
10
20
  githubSignature(agent),
11
21
  ];
12
- /** Builds the parent's instructions from the saved payload, effective task, and Agent persona, including GitHub attribution. */
22
+ const resumeLines = (parts) => [
23
+ ...Option.match(parts.resume, {
24
+ onNone: () => [],
25
+ onSome: ({ ref, commit }) => [
26
+ `Resumes from: ${ref} at ${commit}, the previous Attempt's unfinished work, checked out at HEAD. Its last commit is an automatic work-in-progress snapshot. Continue from this state instead of starting over.`,
27
+ ],
28
+ }),
29
+ ...Option.match(parts.conflictingSalvage, {
30
+ onNone: () => [],
31
+ onSome: ({ ref, commit }) => [
32
+ `Previous work: ${ref} at ${commit}, the previous Attempt's unfinished work, conflicts with the current revision, so the checkout starts without it. Fetch that branch to reuse parts of it.`,
33
+ ],
34
+ }),
35
+ ];
36
+ /** Returns the parent's instructions, including GitHub attribution. */
13
37
  export const assemblePrompt = (parts) => [
14
38
  "# Run context",
15
39
  "",
16
40
  `Repository: ${parts.repository}`,
41
+ ...resumeLines(parts),
17
42
  "",
18
43
  "Payload snapshot:",
19
44
  "```json",
@@ -28,9 +53,11 @@ export const assemblePrompt = (parts) => [
28
53
  "",
29
54
  parts.task,
30
55
  "",
56
+ ...completionInstructions,
57
+ "",
31
58
  ...githubInstructions(parts.agent),
32
59
  ].join("\n");
33
- /** Builds a child's instructions from the delegated task and Agent persona, including GitHub attribution. */
60
+ /** Returns a child's instructions, including GitHub attribution. */
34
61
  export const assembleChildPrompt = (parts) => [
35
62
  "# Agent persona",
36
63
  "",
@@ -40,6 +67,8 @@ export const assembleChildPrompt = (parts) => [
40
67
  "",
41
68
  parts.task,
42
69
  "",
70
+ ...completionInstructions,
71
+ "",
43
72
  ...githubInstructions(parts.agent),
44
73
  ].join("\n");
45
74
  //# sourceMappingURL=prompt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAsBA,yFAAyF;AACzF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAgB,EAAU,EAAE,CAAC,kBAAkB,KAAK,EAAE,CAAC;AAEvF,MAAM,kBAAkB,GAAG,CAAC,KAAgB,EAAyB,EAAE,CAAC;IACtE,mBAAmB;IACnB,EAAE;IACF,sGAAsG;IACtG,iKAAiK;IACjK,mOAAmO;IACnO,4FAA4F;IAC5F,eAAe,CAAC,KAAK,CAAC;CACvB,CAAC;AAEF,gIAAgI;AAChI,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAkB,EAAU,EAAE,CAC3D;IACE,eAAe;IACf,EAAE;IACF,eAAe,KAAK,CAAC,UAAU,EAAE;IACjC,EAAE;IACF,mBAAmB;IACnB,SAAS;IACT,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC3C,KAAK;IACL,EAAE;IACF,iBAAiB;IACjB,EAA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,IAAI,CAAC,CAAC"}
@@ -1,12 +1,10 @@
1
1
  import { Schema } from "effect";
2
2
  /**
3
- * The request shapes usine sends to the Codex app server, restated from
4
- * `@pwrdrvr/codex-app-server-protocol@0.144.0` (codex-cli 0.144.0) because
5
- * that package resolves only under bundler-style resolution.
6
- * This is the baseline protocol. Additional supported CLI builds are verified
7
- * against their generated types and the live steering/interruption contracts.
8
- * `protocol-conformance/check.ts` compiles against the baseline package and fails
9
- * `pnpm check` when these shapes drift.
3
+ * The Codex app-server wire types: the request types that usine sends, copied from
4
+ * `@pwrdrvr/codex-app-server-protocol@0.159.2` (codex-cli 0.159.2) because that package resolves
5
+ * only under bundler module resolution, and the decoders for the responses and notifications that
6
+ * usine reads. `protocol-conformance/check.ts` fails `pnpm check` if either drifts from the
7
+ * package; it compiles this module without Node types, so nothing here imports a Node module.
10
8
  */
11
9
  export interface InitializeParams {
12
10
  readonly clientInfo: {
@@ -66,5 +64,122 @@ export declare const AccountResponse: Schema.Struct<{
66
64
  export declare const AccountUpdated: Schema.Struct<{
67
65
  readonly authMode: Schema.NullOr<Schema.String>;
68
66
  }>;
67
+ /** The model catalog page, used to validate the requested model and reasoning effort. */
68
+ export declare const ModelListResponse: Schema.Struct<{
69
+ readonly data: Schema.$Array<Schema.Struct<{
70
+ readonly id: Schema.String;
71
+ readonly model: Schema.String;
72
+ readonly supportedReasoningEfforts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
73
+ readonly reasoningEffort: Schema.String;
74
+ }>>>;
75
+ }>>;
76
+ readonly nextCursor: Schema.NullOr<Schema.String>;
77
+ }>;
78
+ /** The thread ID and effective model returned when a child thread starts. */
79
+ export declare const ThreadStartResponse: Schema.Struct<{
80
+ readonly thread: Schema.Struct<{
81
+ readonly id: Schema.brand<Schema.NonEmptyString, "HarnessSessionId">;
82
+ }>;
83
+ readonly model: Schema.NonEmptyString;
84
+ readonly instructionSources: Schema.$Array<Schema.String>;
85
+ }>;
86
+ /** The turn ID, needed to steer or interrupt the turn. */
87
+ export declare const TurnStartResponse: Schema.Struct<{
88
+ readonly turn: Schema.Struct<{
89
+ readonly id: Schema.NonEmptyString;
90
+ }>;
91
+ }>;
92
+ /** An item notification with its thread and turn IDs; `item` is kept as JSON. */
93
+ export declare const ItemNotification: Schema.Struct<{
94
+ readonly item: Schema.Codec<Schema.Json, Schema.Json, never, never>;
95
+ readonly threadId: Schema.String;
96
+ readonly turnId: Schema.String;
97
+ }>;
98
+ /** A user message recorded in the thread: a turn's input, or steered input once the running turn reads it. */
99
+ export declare const UserMessageItem: Schema.Struct<{
100
+ readonly type: Schema.Literal<"userMessage">;
101
+ readonly content: Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
102
+ }>;
103
+ /** The text part of a user message. */
104
+ export declare const UserTextInput: Schema.Struct<{
105
+ readonly type: Schema.Literal<"text">;
106
+ readonly text: Schema.String;
107
+ }>;
108
+ /** A completed assistant message; `phase` distinguishes a final answer from commentary. */
109
+ export declare const AgentMessageItem: Schema.Struct<{
110
+ readonly type: Schema.Literal<"agentMessage">;
111
+ readonly id: Schema.NonEmptyString;
112
+ readonly text: Schema.String;
113
+ readonly phase: Schema.optionalKey<Schema.NullOr<Schema.String>>;
114
+ }>;
115
+ /** A recognized tool item, with the fields needed to match starts and results. */
116
+ export declare const ToolItem: Schema.Struct<{
117
+ readonly type: Schema.Literals<readonly ["commandExecution", "fileChange", "mcpToolCall", "dynamicToolCall", "webSearch", "imageView", "imageGeneration"]>;
118
+ readonly id: Schema.NonEmptyString;
119
+ readonly status: Schema.optionalKey<Schema.String>;
120
+ readonly success: Schema.optionalKey<Schema.NullOr<Schema.Boolean>>;
121
+ }>;
122
+ /** The outcome of a turn, used to resume a conversation on Hold or report a session failure. */
123
+ export declare const TurnCompleted: Schema.Struct<{
124
+ readonly turn: Schema.Struct<{
125
+ readonly id: Schema.String;
126
+ readonly status: Schema.Literals<readonly ["completed", "interrupted", "failed", "inProgress"]>;
127
+ readonly error: Schema.NullOr<Schema.Struct<{
128
+ readonly message: Schema.String;
129
+ readonly additionalDetails: Schema.NullOr<Schema.String>;
130
+ }>>;
131
+ }>;
132
+ }>;
133
+ /** A turn error from the app server; if `willRetry` is set, the model provider request is retried, for example `Reconnecting... 2/5`. */
134
+ export declare const ErrorNotification: Schema.Struct<{
135
+ readonly error: Schema.Struct<{
136
+ readonly message: Schema.String;
137
+ readonly additionalDetails: Schema.optionalKey<Schema.NullOr<Schema.String>>;
138
+ }>;
139
+ readonly willRetry: Schema.Boolean;
140
+ readonly turnId: Schema.String;
141
+ }>;
142
+ /** Any notification for one turn, for example an item or a streaming delta. */
143
+ export declare const TurnActivity: Schema.Struct<{
144
+ readonly turnId: Schema.String;
145
+ }>;
146
+ export declare const RateLimitWindow: Schema.Struct<{
147
+ readonly usedPercent: Schema.Number;
148
+ readonly windowDurationMins: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
149
+ readonly resetsAt: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
150
+ }>;
151
+ /** A partial account usage update; omitted windows are also absent in the normalized snapshot. */
152
+ export declare const RateLimitsUpdated: Schema.Struct<{
153
+ readonly rateLimits: Schema.Struct<{
154
+ readonly limitId: Schema.optionalKey<Schema.NullOr<Schema.String>>;
155
+ readonly limitName: Schema.optionalKey<Schema.NullOr<Schema.String>>;
156
+ readonly primary: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
157
+ readonly usedPercent: Schema.Number;
158
+ readonly windowDurationMins: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
159
+ readonly resetsAt: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
160
+ }>>>;
161
+ readonly secondary: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
162
+ readonly usedPercent: Schema.Number;
163
+ readonly windowDurationMins: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
164
+ readonly resetsAt: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
165
+ }>>>;
166
+ }>;
167
+ }>;
168
+ /**
169
+ * The Codex thread token usage, cumulative across turns; `inputTokens` includes cache reads and
170
+ * cache writes.
171
+ */
172
+ export declare const CodexTokenUsage: Schema.Struct<{
173
+ readonly threadId: Schema.NonEmptyString;
174
+ readonly tokenUsage: Schema.Struct<{
175
+ readonly total: Schema.Struct<{
176
+ readonly inputTokens: Schema.Int;
177
+ readonly cachedInputTokens: Schema.Int;
178
+ readonly cacheWriteInputTokens: Schema.Int;
179
+ readonly outputTokens: Schema.Int;
180
+ }>;
181
+ }>;
182
+ }>;
183
+ export type CodexTokenUsage = typeof CodexTokenUsage.Type;
69
184
  export {};
70
185
  //# sourceMappingURL=codex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/protocol/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,0BAA0B,CAAC,EAAE,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MAAM,mBAAmB;;;;;;EAI9B,CAAC;AACH,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB;;;;EAE5B,CAAC;AACH,iFAAiF;AACjF,eAAO,MAAM,gBAAgB;;;;EAI3B,CAAC;AACH,8GAA8G;AAC9G,eAAO,MAAM,eAAe;;;EAG1B,CAAC;AACH,uCAAuC;AACvC,eAAO,MAAM,aAAa;;;EAAuE,CAAC;AAClG,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;;;;EAK3B,CAAC;AACH,kFAAkF;AAClF,eAAO,MAAM,QAAQ;;;;;EAanB,CAAC;AACH,gGAAgG;AAChG,eAAO,MAAM,aAAa;;;;;;;;;EAWxB,CAAC;AACH,yIAAyI;AACzI,eAAO,MAAM,iBAAiB;;;;;;;EAO5B,CAAC;AACH,+EAA+E;AAC/E,eAAO,MAAM,YAAY;;EAA2C,CAAC;AAGrE,eAAO,MAAM,eAAe;;;;EAI1B,CAAC;AACH,kGAAkG;AAClG,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;EAO5B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;EAU1B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAC"}
@@ -1,8 +1,116 @@
1
+ import { HarnessSessionId } from "@usine/core/agent/session";
1
2
  import { Schema } from "effect";
2
- // Only authentication mode crosses this boundary; account identity is never logged.
3
+ import { UsageCount } from "./count.js";
4
+ // Decodes only the authentication type, so account identity is never logged.
3
5
  export const AccountResponse = Schema.Struct({
4
6
  account: Schema.NullOr(Schema.Struct({ type: Schema.String })),
5
7
  requiresOpenaiAuth: Schema.Boolean,
6
8
  });
7
9
  export const AccountUpdated = Schema.Struct({ authMode: Schema.NullOr(Schema.String) });
10
+ /** The model catalog page, used to validate the requested model and reasoning effort. */
11
+ export const ModelListResponse = Schema.Struct({
12
+ data: Schema.Array(Schema.Struct({
13
+ id: Schema.String,
14
+ model: Schema.String,
15
+ supportedReasoningEfforts: Schema.optionalKey(Schema.Array(Schema.Struct({ reasoningEffort: Schema.String }))),
16
+ })),
17
+ nextCursor: Schema.NullOr(Schema.String),
18
+ });
19
+ /** The thread ID and effective model returned when a child thread starts. */
20
+ export const ThreadStartResponse = Schema.Struct({
21
+ thread: Schema.Struct({ id: HarnessSessionId }),
22
+ model: Schema.NonEmptyString,
23
+ instructionSources: Schema.Array(Schema.String),
24
+ });
25
+ /** The turn ID, needed to steer or interrupt the turn. */
26
+ export const TurnStartResponse = Schema.Struct({
27
+ turn: Schema.Struct({ id: Schema.NonEmptyString }),
28
+ });
29
+ /** An item notification with its thread and turn IDs; `item` is kept as JSON. */
30
+ export const ItemNotification = Schema.Struct({
31
+ item: Schema.Json,
32
+ threadId: Schema.String,
33
+ turnId: Schema.String,
34
+ });
35
+ /** A user message recorded in the thread: a turn's input, or steered input once the running turn reads it. */
36
+ export const UserMessageItem = Schema.Struct({
37
+ type: Schema.Literal("userMessage"),
38
+ content: Schema.Array(Schema.Json),
39
+ });
40
+ /** The text part of a user message. */
41
+ export const UserTextInput = Schema.Struct({ type: Schema.Literal("text"), text: Schema.String });
42
+ /** A completed assistant message; `phase` distinguishes a final answer from commentary. */
43
+ export const AgentMessageItem = Schema.Struct({
44
+ type: Schema.Literal("agentMessage"),
45
+ id: Schema.NonEmptyString,
46
+ text: Schema.String,
47
+ phase: Schema.optionalKey(Schema.NullOr(Schema.String)),
48
+ });
49
+ /** A recognized tool item, with the fields needed to match starts and results. */
50
+ export const ToolItem = Schema.Struct({
51
+ type: Schema.Literals([
52
+ "commandExecution",
53
+ "fileChange",
54
+ "mcpToolCall",
55
+ "dynamicToolCall",
56
+ "webSearch",
57
+ "imageView",
58
+ "imageGeneration",
59
+ ]),
60
+ id: Schema.NonEmptyString,
61
+ status: Schema.optionalKey(Schema.String),
62
+ success: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
63
+ });
64
+ /** The outcome of a turn, used to resume a conversation on Hold or report a session failure. */
65
+ export const TurnCompleted = Schema.Struct({
66
+ turn: Schema.Struct({
67
+ id: Schema.String,
68
+ status: Schema.Literals(["completed", "interrupted", "failed", "inProgress"]),
69
+ error: Schema.NullOr(Schema.Struct({
70
+ message: Schema.String,
71
+ additionalDetails: Schema.NullOr(Schema.String),
72
+ })),
73
+ }),
74
+ });
75
+ /** A turn error from the app server; if `willRetry` is set, the model provider request is retried, for example `Reconnecting... 2/5`. */
76
+ export const ErrorNotification = Schema.Struct({
77
+ error: Schema.Struct({
78
+ message: Schema.String,
79
+ additionalDetails: Schema.optionalKey(Schema.NullOr(Schema.String)),
80
+ }),
81
+ willRetry: Schema.Boolean,
82
+ turnId: Schema.String,
83
+ });
84
+ /** Any notification for one turn, for example an item or a streaming delta. */
85
+ export const TurnActivity = Schema.Struct({ turnId: Schema.String });
86
+ // Upstream sends partial updates where any field can be absent, so only `usedPercent` is required.
87
+ export const RateLimitWindow = Schema.Struct({
88
+ usedPercent: Schema.Number,
89
+ windowDurationMins: Schema.optionalKey(Schema.NullOr(Schema.Number)),
90
+ resetsAt: Schema.optionalKey(Schema.NullOr(Schema.Number)),
91
+ });
92
+ /** A partial account usage update; omitted windows are also absent in the normalized snapshot. */
93
+ export const RateLimitsUpdated = Schema.Struct({
94
+ rateLimits: Schema.Struct({
95
+ limitId: Schema.optionalKey(Schema.NullOr(Schema.String)),
96
+ limitName: Schema.optionalKey(Schema.NullOr(Schema.String)),
97
+ primary: Schema.optionalKey(Schema.NullOr(RateLimitWindow)),
98
+ secondary: Schema.optionalKey(Schema.NullOr(RateLimitWindow)),
99
+ }),
100
+ });
101
+ /**
102
+ * The Codex thread token usage, cumulative across turns; `inputTokens` includes cache reads and
103
+ * cache writes.
104
+ */
105
+ export const CodexTokenUsage = Schema.Struct({
106
+ threadId: Schema.NonEmptyString,
107
+ tokenUsage: Schema.Struct({
108
+ total: Schema.Struct({
109
+ inputTokens: UsageCount,
110
+ cachedInputTokens: UsageCount,
111
+ cacheWriteInputTokens: UsageCount,
112
+ outputTokens: UsageCount,
113
+ }),
114
+ }),
115
+ });
8
116
  //# sourceMappingURL=codex.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/protocol/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkEhC,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,kBAAkB,EAAE,MAAM,CAAC,OAAO;CACnC,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/protocol/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAgExC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,kBAAkB,EAAE,MAAM,CAAC,OAAO;CACnC,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AA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xB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzD,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC3D,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;KAC9D,CAAC;CACH,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC,cAAc;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;YACnB,WAAW,EAAE,UAAU;YACvB,iBAAiB,EAAE,UAAU;YAC7B,qBAAqB,EAAE,UAAU;YACjC,YAAY,EAAE,UAAU;SACzB,CAAC;KACH,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Schema } from "effect";
2
+ /** A non-negative integer in a harness's usage report, such as an input or cached token count. */
3
+ export declare const UsageCount: Schema.Int;
4
+ //# sourceMappingURL=count.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../src/protocol/count.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,kGAAkG;AAClG,eAAO,MAAM,UAAU,YAAqD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Schema } from "effect";
2
+ /** A non-negative integer in a harness's usage report, such as an input or cached token count. */
3
+ export const UsageCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
4
+ //# sourceMappingURL=count.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count.js","sourceRoot":"","sources":["../../src/protocol/count.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC"}
package/dist/runtime.d.ts CHANGED
@@ -1,23 +1,33 @@
1
- import { AgentSession, AgentSessionEvent, ChildSession } from "@usine/core/agent/session";
1
+ import { AgentSession, AgentSessionEvent, AgentSessionId, ChildSession } from "@usine/core/agent/session";
2
2
  import * as AttemptChannel from "@usine/core/attempt/channel";
3
+ import { MachineId, WorkerName } from "@usine/core/worker";
3
4
  import { AttemptFailure } from "@usine/core/attempt/failure";
4
- import { Context, Effect, Schema, Scope, Stream } from "effect";
5
- /** The checkout directory one Attempt runs in. */
5
+ import { Context, Effect, Option, Schema, Scope, Stream } from "effect";
6
+ /** The checkout directory of an Attempt. */
6
7
  export declare const WorkingDirectory: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
7
8
  export type WorkingDirectory = typeof WorkingDirectory.Type;
8
- declare const LaunchRequest_base: Schema.Class<LaunchRequest, Schema.Struct<{
9
- readonly spec: typeof AttemptChannel.RunSpec;
10
- readonly cwd: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
11
- }>, {}>;
12
- /** The Attempt's task and Agent choices, together with the prepared checkout where its parent starts. */
13
- export declare class LaunchRequest extends LaunchRequest_base {
14
- }
15
9
  declare const ChildRequest_base: Schema.Class<ChildRequest, Schema.Struct<{
16
10
  readonly session: typeof ChildSession;
11
+ /** The checkout directory on `host`. */
17
12
  readonly cwd: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
18
13
  readonly prompt: Schema.NonEmptyString;
14
+ /**
15
+ * The complete environment of the child process and its commands: the Worker's allowlisted
16
+ * variables plus the Attempt's credential configuration, with nothing inherited from the launching
17
+ * process (ADR 0011). On a `RemoteShell` host, the variables are exported on top of the remote
18
+ * environment, which contains no orchestrator secret.
19
+ */
20
+ readonly environment: Schema.$Record<Schema.String, Schema.String>;
21
+ readonly host: Schema.Union<readonly [typeof import("./child-host/child-host.ts").LocalProcess, typeof import("./child-host/child-host.ts").RemoteShell]>;
22
+ /** The Worker that `host` runs on. */
23
+ readonly worker: Schema.brand<Schema.String, "WorkerName">;
24
+ /**
25
+ * The provider's ID of the machine that a provisioned Worker created for the Attempt, or `None`
26
+ * on other Workers, whose Attempts share one Claude login.
27
+ */
28
+ readonly machine: Schema.Option<Schema.brand<Schema.String, "MachineId">>;
19
29
  }>, {}>;
20
- /** Work delegated to one child, with its assigned identity and the checkout it shares with the parent. */
30
+ /** A task delegated to one child, with its session and the checkout it shares with the parent. */
21
31
  export declare class ChildRequest extends ChildRequest_base {
22
32
  }
23
33
  declare const SessionResult_base: Schema.Class<SessionResult, Schema.Struct<{
@@ -31,7 +41,7 @@ declare const UnknownModelError_base: Schema.Class<UnknownModelError, Schema.Tag
31
41
  readonly model: Schema.brand<Schema.String, "ModelId">;
32
42
  readonly message: Schema.NonEmptyString;
33
43
  }>, import("effect/Cause").YieldableError>;
34
- /** The rostered model id is well-formed but the SDK's registry does not list it. */
44
+ /** An error for a well-formed rostered model ID that the SDK's registry does not list. */
35
45
  export declare class UnknownModelError extends UnknownModelError_base {
36
46
  }
37
47
  declare const PoolUnavailableError_base: Schema.Class<PoolUnavailableError, Schema.TaggedStruct<"PoolUnavailableError", {
@@ -40,7 +50,7 @@ declare const PoolUnavailableError_base: Schema.Class<PoolUnavailableError, Sche
40
50
  readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
41
51
  readonly message: Schema.NonEmptyString;
42
52
  }>, import("effect/Cause").YieldableError>;
43
- /** The credential cannot spend from the billing pool this session needs. */
53
+ /** An error for a credential that cannot use the billing pool the session needs. */
44
54
  export declare class PoolUnavailableError extends PoolUnavailableError_base {
45
55
  }
46
56
  declare const UnsupportedEffortError_base: Schema.Class<UnsupportedEffortError, Schema.TaggedStruct<"UnsupportedEffortError", {
@@ -49,22 +59,52 @@ declare const UnsupportedEffortError_base: Schema.Class<UnsupportedEffortError,
49
59
  readonly effort: Schema.Literals<readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"]>;
50
60
  readonly message: Schema.NonEmptyString;
51
61
  }>, import("effect/Cause").YieldableError>;
52
- /** The model exists but does not support the rostered reasoning effort. */
62
+ /** An error for a model that does not support the rostered reasoning effort. */
53
63
  export declare class UnsupportedEffortError extends UnsupportedEffortError_base {
54
64
  }
65
+ /**
66
+ * The reserved prefix of a final answer that reports an unresolved blocker. The session fails with
67
+ * `AgentBlockedError`, whose message is the text after the marker.
68
+ */
69
+ export declare const BLOCKED_MARKER = "[usine:blocked]";
70
+ /**
71
+ * The reserved prefix of a final answer that asks the operator for a decision. The session fails
72
+ * with `AgentQuestionError`, whose message is the text after the marker.
73
+ */
74
+ export declare const QUESTION_MARKER = "[usine:question]";
75
+ /**
76
+ * The reserved prefix of a report that relays a harness failure, such as a child's failed Codex
77
+ * turn, to the parent. The session fails with `AgentResultError`, which ends the Attempt with
78
+ * `AgentFailure`.
79
+ */
80
+ export declare const FAILED_MARKER = "[usine:failed]";
55
81
  declare const AgentResultError_base: Schema.Class<AgentResultError, Schema.TaggedStruct<"AgentResultError", {
56
82
  readonly sessionId: Schema.OptionFromNullOr<Schema.brand<Schema.NonEmptyString, "AgentSessionId">>;
57
83
  readonly message: Schema.NonEmptyString;
58
84
  }>, import("effect/Cause").YieldableError>;
59
- /** The session finished and reported that the work itself failed. */
85
+ /** An error for a session that finished and reported that the work failed. */
60
86
  export declare class AgentResultError extends AgentResultError_base {
61
87
  }
88
+ declare const AgentBlockedError_base: Schema.Class<AgentBlockedError, Schema.TaggedStruct<"AgentBlockedError", {
89
+ readonly sessionId: Schema.OptionFromNullOr<Schema.brand<Schema.NonEmptyString, "AgentSessionId">>;
90
+ readonly message: Schema.NonEmptyString;
91
+ }>, import("effect/Cause").YieldableError>;
92
+ /** An error for a session that finished with the blocker marker; `message` is the blocker text. */
93
+ export declare class AgentBlockedError extends AgentBlockedError_base {
94
+ }
95
+ declare const AgentQuestionError_base: Schema.Class<AgentQuestionError, Schema.TaggedStruct<"AgentQuestionError", {
96
+ readonly sessionId: Schema.OptionFromNullOr<Schema.brand<Schema.NonEmptyString, "AgentSessionId">>;
97
+ readonly message: Schema.NonEmptyString;
98
+ }>, import("effect/Cause").YieldableError>;
99
+ /** An error for a session that finished with a question for the operator; `message` is the question. */
100
+ export declare class AgentQuestionError extends AgentQuestionError_base {
101
+ }
62
102
  declare const ChildSessionBudgetExceededError_base: Schema.Class<ChildSessionBudgetExceededError, Schema.TaggedStruct<"ChildSessionBudgetExceededError", {
63
103
  readonly maxChildren: Schema.brand<Schema.Int, "ChildSessionBudget">;
64
104
  readonly attemptedChildren: Schema.brand<Schema.Int, "ChildSessionCount">;
65
105
  readonly message: Schema.NonEmptyString;
66
106
  }>, import("effect/Cause").YieldableError>;
67
- /** The Pi parent asked for one more child than this Attempt's budget allows. */
107
+ /** An error for a Pi parent that requested more children than the Attempt's budget allows. */
68
108
  export declare class ChildSessionBudgetExceededError extends ChildSessionBudgetExceededError_base {
69
109
  }
70
110
  export declare const SESSION_OPERATIONS: readonly ["launch", "stream", "steer", "interrupt"];
@@ -76,73 +116,88 @@ declare const SessionOperationError_base: Schema.Class<SessionOperationError, Sc
76
116
  readonly message: Schema.NonEmptyString;
77
117
  readonly cause: Schema.Defect;
78
118
  }>, import("effect/Cause").YieldableError>;
79
- /** The SDK or its process failed after the model and harness were validated. */
119
+ /** An error for an SDK or process failure after the model and harness were validated. */
80
120
  export declare class SessionOperationError extends SessionOperationError_base {
81
121
  }
82
- /** A session could not start, continue, or finish its work; the failure determines whether retry needs an operator. */
83
- export declare const AgentSessionError: Schema.Union<readonly [typeof UnknownModelError, typeof PoolUnavailableError, typeof UnsupportedEffortError, typeof AgentResultError, typeof ChildSessionBudgetExceededError, typeof SessionOperationError]>;
122
+ /** Any error that stops a session from starting, continuing, or finishing; the error type determines whether a retry needs the operator. */
123
+ export declare const AgentSessionError: Schema.Union<readonly [typeof UnknownModelError, typeof PoolUnavailableError, typeof UnsupportedEffortError, typeof AgentResultError, typeof AgentBlockedError, typeof AgentQuestionError, typeof ChildSessionBudgetExceededError, typeof SessionOperationError]>;
84
124
  export type AgentSessionError = typeof AgentSessionError.Type;
85
125
  /**
86
- * Maps session errors onto the retry taxonomy: an SDK or process failure is
87
- * retryable infrastructure, while a bad roster spec or the agent failing its
88
- * own work waits for the operator (ADR 0002).
126
+ * A report that a session ends with: a blocker or question marked in its final answer, or a failure
127
+ * reported by its harness. A child relays each report to the parent with the same marker.
128
+ */
129
+ export type AgentReport = AgentResultError | AgentBlockedError | AgentQuestionError;
130
+ /**
131
+ * Returns the report of a final answer that starts with `[usine:blocked]`, `[usine:question]`, or
132
+ * `[usine:failed]`; the details can follow on the same line or the next. Returns `None` if the answer
133
+ * does not start with a marker.
134
+ */
135
+ export declare const reportedOutcome: (sessionId: Option.Option<AgentSessionId>, answer: string) => Option.Option<AgentReport>;
136
+ /** Returns the final answer that relays `report`, starting with its marker. */
137
+ export declare const reportText: (report: AgentReport) => string;
138
+ /**
139
+ * Maps a session error to an Attempt failure: SDK and process failures are retryable infrastructure
140
+ * failures; roster errors and Agent-reported failures wait for the operator (ADR 0002).
89
141
  */
90
142
  export declare const toAttemptFailure: (error: AgentSessionError) => AttemptFailure;
91
- /** A live parent or child session whose activity can be observed while its work continues. */
143
+ /** A running parent or child session. */
92
144
  export interface RunningSession {
93
145
  readonly session: AgentSession;
94
- /** Activity to record in the Attempt transcript while waiting for the result. */
146
+ /** The session activity to record in the Attempt transcript. */
95
147
  readonly events: Stream.Stream<AgentSessionEvent, AgentSessionError>;
96
- /** Waits for the final message or the failure that ends this session's work. */
148
+ /** Waits for the session's final message, or fails with the error that ended it. */
97
149
  readonly result: Effect.Effect<SessionResult, AgentSessionError>;
98
150
  /** Adds operator guidance to the running session without creating a new Attempt. */
99
151
  readonly steer: (message: string) => Effect.Effect<void, AgentSessionError>;
100
- /** Requests that this session stop its current work. */
152
+ /** Requests that the session stop its current work. */
101
153
  readonly interrupt: Effect.Effect<void, AgentSessionError>;
102
- /** Applies a nonterminal operator action; child messages hold completion until release. */
103
- readonly intervene: (action: AttemptChannel.OperatorAction) => Effect.Effect<AttemptChannel.InterventionState, AgentSessionError>;
104
- }
105
- /**
106
- * Records each live child session so the run host can route operator input
107
- * (steer, interrupt, or a takeover message) to one by the id it reports in the
108
- * normalized event stream. The parent registers no child; it is addressed
109
- * directly. Registration is scoped: the entry is removed when the child's scope
110
- * closes, so a returned child is no longer addressable (ADR 0018).
111
- */
112
- export interface ChildSessions {
113
- readonly register: (session: RunningSession) => Effect.Effect<void, never, Scope.Scope>;
154
+ /**
155
+ * Applies a nonterminal operator action; after a child message, the session does not complete
156
+ * until release. If the harness reads the message only at its next boundary, returns `queued` and
157
+ * calls `onDelivery` once: with the session state when it is read, or `None` if the session stops
158
+ * first.
159
+ */
160
+ readonly intervene: (action: AttemptChannel.OperatorAction, onDelivery: OnDelivery) => Effect.Effect<AttemptChannel.InterventionState, AgentSessionError>;
114
161
  }
115
- /** Launches coding sessions for tasks delegated by an Attempt's parent. */
162
+ /** A callback, called once for a queued operator message with the session state when it was read, or `None` if the session stopped first. */
163
+ export type OnDelivery = (delivered: Option.Option<AttemptChannel.InterventionState>) => Effect.Effect<void>;
164
+ /** A backend that launches child sessions for tasks delegated by an Attempt's parent. */
116
165
  export interface ChildBackendService {
117
- /** Starts the assigned child and returns its controls; its result is awaited separately. */
166
+ /** Starts the child and returns its controls; `result` is awaited separately. */
118
167
  readonly launch: (request: ChildRequest) => Effect.Effect<RunningSession, AgentSessionError, Scope.Scope>;
119
168
  }
120
169
  declare const ChildBackend_base: Context.ServiceClass<ChildBackend, "@usine/agents/ChildBackend", ChildBackendService>;
121
- /** Runs the coding work delegated by an Attempt's parent. */
170
+ /** The service that runs tasks delegated by an Attempt's parent. */
122
171
  export declare class ChildBackend extends ChildBackend_base {
123
172
  }
173
+ declare const ClaudeLoginLock_base: Context.ServiceClass<ClaudeLoginLock, "@usine/agents/ClaudeLoginLock", {
174
+ /**
175
+ * Runs `effect` with the lock of the login on `worker`'s provisioned `machine`, or of the
176
+ * Worker's shared login if `machine` is `None`, after waiting for any other effect that has
177
+ * the lock.
178
+ */
179
+ readonly withLock: (worker: WorkerName, machine: Option.Option<MachineId>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
180
+ }>;
181
+ /**
182
+ * A lock per Claude login for the Claude commands that can refresh it: the preflight login check
183
+ * and the start of a Claude child. Claude Code ends a process that finds another process
184
+ * refreshing the login (#453). Each machine of a provisioned Worker has its own login; on other
185
+ * Workers, all Attempts share one. Provide one instance to both the executor and the Attempt
186
+ * runtime.
187
+ */
188
+ export declare class ClaudeLoginLock extends ClaudeLoginLock_base {
189
+ }
124
190
  declare const ClaudeChildBackend_base: Context.ServiceClass<ClaudeChildBackend, "@usine/agents/ClaudeChildBackend", ChildBackendService>;
125
- /** Runs delegated coding work with Claude Code. */
191
+ /** The child backend for Claude Code. */
126
192
  export declare class ClaudeChildBackend extends ClaudeChildBackend_base {
127
193
  }
128
194
  declare const CodexChildBackend_base: Context.ServiceClass<CodexChildBackend, "@usine/agents/CodexChildBackend", ChildBackendService>;
129
- /** Runs delegated coding work with Codex. */
195
+ /** The child backend for Codex. */
130
196
  export declare class CodexChildBackend extends CodexChildBackend_base {
131
197
  }
132
198
  declare const PiChildBackend_base: Context.ServiceClass<PiChildBackend, "@usine/agents/PiChildBackend", ChildBackendService>;
133
- /** Runs delegated coding work with Pi. */
199
+ /** The child backend for Pi. */
134
200
  export declare class PiChildBackend extends PiChildBackend_base {
135
201
  }
136
- declare const AgentRuntime_base: Context.ServiceClass<AgentRuntime, "@usine/agents/AgentRuntime", {
137
- /**
138
- * Starts work in the prepared checkout and returns controls for observing and
139
- * guiding the parent. Each child it spawns registers with `children` so the
140
- * run host can address a takeover to it by id.
141
- */
142
- readonly launch: (request: LaunchRequest, children: ChildSessions) => Effect.Effect<RunningSession, AgentSessionError, Scope.Scope>;
143
- }>;
144
- /** Starts the parent that coordinates one Attempt's task and delegates coding work to children. */
145
- export declare class AgentRuntime extends AgentRuntime_base {
146
- }
147
202
  export {};
148
203
  //# sourceMappingURL=runtime.d.ts.map