@usine/agents 0.0.1 → 0.1.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 (58) hide show
  1. package/README.md +25 -2
  2. package/dist/index.d.ts +3 -7
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -7
  5. package/dist/index.js.map +1 -1
  6. package/dist/pi/authentication.d.ts +13 -0
  7. package/dist/pi/authentication.d.ts.map +1 -0
  8. package/dist/pi/authentication.js +14 -0
  9. package/dist/pi/authentication.js.map +1 -0
  10. package/dist/pi/children.d.ts +5 -0
  11. package/dist/pi/children.d.ts.map +1 -0
  12. package/dist/pi/children.js +26 -0
  13. package/dist/pi/children.js.map +1 -0
  14. package/dist/pi/claude.d.ts +32 -0
  15. package/dist/pi/claude.d.ts.map +1 -0
  16. package/dist/pi/claude.js +237 -0
  17. package/dist/pi/claude.js.map +1 -0
  18. package/dist/pi/codex/app-server.d.ts +24 -0
  19. package/dist/pi/codex/app-server.d.ts.map +1 -0
  20. package/dist/pi/codex/app-server.js +188 -0
  21. package/dist/pi/codex/app-server.js.map +1 -0
  22. package/dist/pi/codex/codex.d.ts +5 -0
  23. package/dist/pi/codex/codex.d.ts.map +1 -0
  24. package/dist/pi/codex/codex.js +342 -0
  25. package/dist/pi/codex/codex.js.map +1 -0
  26. package/dist/pi/index.d.ts +11 -0
  27. package/dist/pi/index.d.ts.map +1 -0
  28. package/dist/pi/index.js +18 -0
  29. package/dist/pi/index.js.map +1 -0
  30. package/dist/pi/pi.d.ts +7 -0
  31. package/dist/pi/pi.d.ts.map +1 -0
  32. package/dist/pi/pi.js +273 -0
  33. package/dist/pi/pi.js.map +1 -0
  34. package/dist/pi/sdk.d.ts +66 -0
  35. package/dist/pi/sdk.d.ts.map +1 -0
  36. package/dist/pi/sdk.js +154 -0
  37. package/dist/pi/sdk.js.map +1 -0
  38. package/dist/pi/session.d.ts +46 -0
  39. package/dist/pi/session.d.ts.map +1 -0
  40. package/dist/pi/session.js +180 -0
  41. package/dist/pi/session.js.map +1 -0
  42. package/dist/pi/subagents.d.ts +23 -0
  43. package/dist/pi/subagents.d.ts.map +1 -0
  44. package/dist/pi/subagents.js +83 -0
  45. package/dist/pi/subagents.js.map +1 -0
  46. package/dist/prompt.d.ts +22 -0
  47. package/dist/prompt.d.ts.map +1 -0
  48. package/dist/prompt.js +42 -0
  49. package/dist/prompt.js.map +1 -0
  50. package/dist/protocol/codex.d.ts +56 -0
  51. package/dist/protocol/codex.d.ts.map +1 -0
  52. package/dist/protocol/codex.js +2 -0
  53. package/dist/protocol/codex.js.map +1 -0
  54. package/dist/runtime.d.ts +114 -0
  55. package/dist/runtime.d.ts.map +1 -0
  56. package/dist/runtime.js +96 -0
  57. package/dist/runtime.js.map +1 -0
  58. package/package.json +21 -2
package/README.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @usine/agents
2
2
 
3
- The usine agent layer: Pi parent adapter, subagents extension, team roster and brain specs.
3
+ The agent runtime for [usine](https://github.com/basaltbytes/usine). Each Attempt starts an in-process Pi parent, which can delegate focused work through the usine-owned `subagent` tool. An agent's brain spec selects Claude Code, Codex, or Pi for the child.
4
4
 
5
- Part of [usine](https://github.com/basaltbytes/usine), an agent-agnostic software factory. This block is not implemented yet — its 0.0.x releases reserve the seam while the engine grows. Everything here is 0.x: APIs change without notice.
5
+ The package root is platform-free. It exports prompt assembly, normalized session events, typed runtime errors, and the `AgentRuntime` and `ChildBackend` service contracts. The Node implementation lives at `@usine/agents/pi`:
6
+
7
+ ```ts
8
+ import { layer as agentLayer } from "@usine/agents/pi";
9
+ ```
10
+
11
+ The production layer resolves the Pi parent model from the Run spec, installs the subagents extension, and dispatches each child from the rostered `harness` field. The parent accepts API-key-backed Pi models and ChatGPT subscription models from the `openai-codex` provider. Claude Code runs with `bypassPermissions` and reads only worker-user settings. Codex uses app-server JSON-RPC over standard input and output with `approvalPolicy: never`; its thread stays ephemeral and records ChatGPT plan rate-window updates as `PoolRateLimitsUpdated` session events. Pi children remain API-key-only.
12
+
13
+ The Attempt worktree counts as repository-controlled input. Pi ignores project `.pi/` settings, extensions, prompt templates, skills, and themes. Claude omits project setting sources, while Codex marks the worktree untrusted before starting its thread. AGENTS instructions remain available to the coding harnesses. Worker isolation remains the executor's responsibility.
14
+
15
+ Parent and child output becomes typed session events: `SessionStarted`, `TextOutput`, tool calls, pool observations, and `SessionFinished`. Each completed assistant message produces one `TextOutput`; streaming deltas don't enter the Attempt transcript. Parent and child controls support steer and interrupt. A child session always names one parent session, so recursive child events cannot enter the public model.
16
+
17
+ Model identifiers stay opaque until the selected harness checks its registry. Agent-reported failures use `AgentResultError`; SDK, process, and protocol failures use `SessionOperationError`. `toAttemptFailure` maps only `SessionOperationError` to retryable infrastructure failure.
18
+
19
+ Configure Pi with either a provider API key or ChatGPT Plus/Pro OAuth for the parent. Pi children require API keys; Claude and Codex children use their CLI login state. The parent-start log records `apiKeys` or `chatgptPlan` according to the resolved credential. The harness SDK and protocol dependencies use exact versions.
20
+
21
+ Run the opt-in live contracts with explicit models:
22
+
23
+ ```sh
24
+ USINE_CODEX_INTEGRATION_MODEL=gpt-5.6-terra pnpm --filter @usine/agents test:integration:codex
25
+ USINE_PI_INTEGRATION_MODEL=anthropic/claude-sonnet-4-6 pnpm --filter @usine/agents test:integration:pi
26
+ ```
27
+
28
+ Everything here is 0.x, so APIs can change between minor releases. Supply `effect` at the version pinned by the usine workspace.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- /**
2
- * @usine/agents — The usine agent layer: Pi parent adapter, subagents extension, team roster and brain specs.
3
- *
4
- * Not implemented yet: this 0.0.x release reserves the block's seam while the
5
- * engine grows.
6
- */
7
- export {};
1
+ /** @usine/agents — parent-agent and harness-child contracts for usine. */
2
+ export * from "./prompt.ts";
3
+ export * from "./runtime.ts";
8
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,4 @@
1
- /**
2
- * @usine/agents — The usine agent layer: Pi parent adapter, subagents extension, team roster and brain specs.
3
- *
4
- * Not implemented yet: this 0.0.x release reserves the block's seam while the
5
- * engine grows.
6
- */
7
- export {};
1
+ /** @usine/agents — parent-agent and harness-child contracts for usine. */
2
+ export * from "./prompt.js";
3
+ export * from "./runtime.js";
8
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Agent } from "@usine/core";
2
+ export type PiAuthentication = {
3
+ readonly _tag: "ApiKey";
4
+ } | {
5
+ readonly _tag: "OAuth";
6
+ readonly subscription: boolean;
7
+ };
8
+ export type PiPool = Extract<Agent.Pool, "apiKeys" | "chatgptPlan">;
9
+ /** Billing pool the selected Pi provider must have available before launch. */
10
+ export declare const requiredPiPool: (provider: string) => PiPool;
11
+ /** Resolve Pi's billing source from the credential that will spend the model request. */
12
+ export declare const resolvePiPool: (provider: string, authentication: PiAuthentication | undefined) => PiPool | undefined;
13
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/pi/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC;AAC/D,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC;AAEpE,+EAA+E;AAC/E,eAAO,MAAM,cAAc,aAAc,MAAM,KAAG,MACO,CAAC;AAE1D,yFAAyF;AACzF,eAAO,MAAM,aAAa,aACd,MAAM,kBACA,gBAAgB,GAAG,SAAS,KAC3C,MAAM,GAAG,SAUX,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** Billing pool the selected Pi provider must have available before launch. */
2
+ export const requiredPiPool = (provider) => provider === "openai-codex" ? "chatgptPlan" : "apiKeys";
3
+ /** Resolve Pi's billing source from the credential that will spend the model request. */
4
+ export const resolvePiPool = (provider, authentication) => {
5
+ if (authentication?._tag === "ApiKey")
6
+ return "apiKeys";
7
+ if (authentication?._tag === "OAuth" &&
8
+ authentication.subscription &&
9
+ provider === "openai-codex") {
10
+ return "chatgptPlan";
11
+ }
12
+ return undefined;
13
+ };
14
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/pi/authentication.ts"],"names":[],"mappings":"AAOA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAU,EAAE,CACzD,QAAQ,KAAK,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;AAE1D,yFAAyF;AACzF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,QAAgB,EAChB,cAA4C,EACxB,EAAE;IACtB,IAAI,cAAc,EAAE,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACxD,IACE,cAAc,EAAE,IAAI,KAAK,OAAO;QAChC,cAAc,CAAC,YAAY;QAC3B,QAAQ,KAAK,cAAc,EAC3B,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { ChildBackend, ClaudeChildBackend, CodexChildBackend, PiChildBackend } from "../runtime.ts";
3
+ /** Selects one concrete child backend from the authored BrainSpec harness. */
4
+ export declare const childDispatcherLayer: Layer.Layer<ChildBackend, never, ClaudeChildBackend | CodexChildBackend | PiChildBackend>;
5
+ //# sourceMappingURL=children.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../../src/pi/children.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAyBpG,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,2FAAkD,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Effect, Layer } from "effect";
2
+ import { ChildBackend, ClaudeChildBackend, CodexChildBackend, PiChildBackend } from "../runtime.js";
3
+ const makeChildDispatcher = Effect.gen(function* () {
4
+ const claude = yield* ClaudeChildBackend;
5
+ const codex = yield* CodexChildBackend;
6
+ const pi = yield* PiChildBackend;
7
+ return ChildBackend.of({
8
+ launch: Effect.fn("ChildBackend.launch")(function* (request) {
9
+ yield* Effect.logDebug("Dispatching child session", {
10
+ harness: request.session.brain.harness,
11
+ sessionId: request.session.id,
12
+ });
13
+ switch (request.session.brain.harness) {
14
+ case "claude":
15
+ return yield* claude.launch(request);
16
+ case "codex":
17
+ return yield* codex.launch(request);
18
+ case "pi":
19
+ return yield* pi.launch(request);
20
+ }
21
+ }),
22
+ });
23
+ });
24
+ /** Selects one concrete child backend from the authored BrainSpec harness. */
25
+ export const childDispatcherLayer = Layer.effect(ChildBackend, makeChildDispatcher);
26
+ //# sourceMappingURL=children.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"children.js","sourceRoot":"","sources":["../../src/pi/children.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpG,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,kBAAkB,CAAC;IACzC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC;IACvC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;IAEjC,OAAO,YAAY,CAAC,EAAE,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO;YACzD,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,2BAA2B,EAAE;gBAClD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;gBACtC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;aAC9B,CAAC,CAAC;YACH,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACtC,KAAK,QAAQ;oBACX,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACvC,KAAK,OAAO;oBACV,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACtC,KAAK,IAAI;oBACP,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;QACH,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type Options } from "@anthropic-ai/claude-agent-sdk";
2
+ import { Context, Layer, Schema } from "effect";
3
+ import { ClaudeChildBackend, ChildBackend } from "../runtime.ts";
4
+ export interface ClaudeUserMessage {
5
+ readonly type: "user";
6
+ readonly message: {
7
+ readonly role: "user";
8
+ readonly content: string;
9
+ };
10
+ readonly parent_tool_use_id: null;
11
+ }
12
+ export type ClaudeQueryOptions = Pick<Options, "allowDangerouslySkipPermissions" | "cwd" | "effort" | "model" | "permissionMode" | "persistSession" | "settingSources" | "thinking">;
13
+ export interface ClaudeModelInfo {
14
+ readonly value: string;
15
+ readonly resolvedModel?: string;
16
+ }
17
+ /** Narrow vendor seam: tests never need to imitate the SDK's large Query surface. */
18
+ export interface ClaudeQuery extends AsyncIterable<Schema.Json> {
19
+ readonly close: () => void;
20
+ readonly interrupt: () => Promise<void>;
21
+ readonly supportedModels: () => Promise<ReadonlyArray<ClaudeModelInfo>>;
22
+ }
23
+ declare const ClaudeSdk_base: Context.ServiceClass<ClaudeSdk, "@usine/agents/pi/ClaudeSdk", {
24
+ readonly open: (input: AsyncIterable<ClaudeUserMessage>, options: ClaudeQueryOptions) => ClaudeQuery;
25
+ }>;
26
+ export declare class ClaudeSdk extends ClaudeSdk_base {
27
+ }
28
+ export declare const claudeSdkLive: Layer.Layer<ClaudeSdk, never, never>;
29
+ export declare const claudeChildLayer: Layer.Layer<ChildBackend, never, ClaudeSdk>;
30
+ export declare const claudeChildBackendLayer: Layer.Layer<ClaudeChildBackend, never, ClaudeSdk>;
31
+ export {};
32
+ //# sourceMappingURL=claude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cla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a,sCAexB,CAAC;AAgRH,eAAO,MAAM,gBAAgB,6CAA8C,CAAC;AAC5E,eAAO,MAAM,uBAAuB,mDAAoD,CAAC"}
@@ -0,0 +1,237 @@
1
+ import { query as openClaudeQuery, } from "@anthropic-ai/claude-agent-sdk";
2
+ import { Agent } from "@usine/core";
3
+ import { Context, Deferred, Effect, Layer, Option, Schema, Stream } from "effect";
4
+ import { AgentResultError, ClaudeChildBackend, ChildBackend, SessionOperationError, UnknownModelError, } from "../runtime.js";
5
+ import { sessionChannel } from "./session.js";
6
+ export class ClaudeSdk extends Context.Service()("@usine/agents/pi/ClaudeSdk") {
7
+ }
8
+ const decodeVendorMessage = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Json));
9
+ const vendorMessageJson = (message) => decodeVendorMessage(JSON.stringify(message));
10
+ export const claudeSdkLive = Layer.succeed(ClaudeSdk)({
11
+ open: (input, options) => {
12
+ // SAFETY: ClaudeUserMessage is the exact streaming-input subset of SDKUserMessage.
13
+ const query = openClaudeQuery({ prompt: input, options });
14
+ return {
15
+ close: () => query.close(),
16
+ interrupt: async () => {
17
+ await query.interrupt();
18
+ },
19
+ supportedModels: () => query.supportedModels(),
20
+ async *[Symbol.asyncIterator]() {
21
+ for await (const message of query)
22
+ yield vendorMessageJson(message);
23
+ },
24
+ };
25
+ },
26
+ });
27
+ class AsyncInput {
28
+ #buffer = [];
29
+ #waiters = [];
30
+ #ended = false;
31
+ offer(message) {
32
+ if (this.#ended)
33
+ throw new Error("Claude input is closed");
34
+ const waiter = this.#waiters.shift();
35
+ if (waiter === undefined)
36
+ this.#buffer.push(message);
37
+ else
38
+ waiter({ done: false, value: message });
39
+ }
40
+ end() {
41
+ if (this.#ended)
42
+ return;
43
+ this.#ended = true;
44
+ for (const waiter of this.#waiters.splice(0))
45
+ waiter({ done: true, value: undefined });
46
+ }
47
+ [Symbol.asyncIterator]() {
48
+ return {
49
+ next: () => {
50
+ const value = this.#buffer.shift();
51
+ if (value !== undefined)
52
+ return Promise.resolve({ done: false, value });
53
+ if (this.#ended)
54
+ return Promise.resolve({ done: true, value: undefined });
55
+ return new Promise((resolve) => this.#waiters.push(resolve));
56
+ },
57
+ };
58
+ }
59
+ }
60
+ const userMessage = (content) => ({
61
+ type: "user",
62
+ message: { role: "user", content },
63
+ parent_tool_use_id: null,
64
+ });
65
+ const operationError = (operation, request, message, cause) => new SessionOperationError({
66
+ operation,
67
+ sessionId: Option.some(request.session.id),
68
+ message,
69
+ cause,
70
+ });
71
+ const optionsFor = (request) => {
72
+ const effort = request.session.brain.effort;
73
+ const shared = {
74
+ allowDangerouslySkipPermissions: true,
75
+ cwd: request.cwd,
76
+ model: request.session.brain.model,
77
+ permissionMode: "bypassPermissions",
78
+ persistSession: false,
79
+ // The Attempt worktree is repository-controlled input: its project and
80
+ // local settings (hooks, env) must never load into a child that carries
81
+ // the App credential. Only the worker user's own settings apply.
82
+ settingSources: ["user"],
83
+ };
84
+ return effort === "off"
85
+ ? { ...shared, thinking: { type: "disabled" } }
86
+ : {
87
+ ...shared,
88
+ effort: effort === "minimal" ? "low" : effort,
89
+ thinking: { type: "adaptive" },
90
+ };
91
+ };
92
+ const modelExists = (models, model) => models.some((candidate) => candidate.value === model || candidate.resolvedModel === model);
93
+ const ClaudeTextBlock = Schema.Struct({
94
+ type: Schema.Literal("text"),
95
+ text: Schema.NonEmptyString,
96
+ });
97
+ const ClaudeContentMessage = Schema.Struct({
98
+ type: Schema.Literals(["assistant", "user"]),
99
+ message: Schema.Struct({ content: Schema.Array(Schema.Json) }),
100
+ });
101
+ const ClaudeToolUseBlock = Schema.Struct({
102
+ type: Schema.Literal("tool_use"),
103
+ id: Schema.NonEmptyString,
104
+ name: Schema.NonEmptyString,
105
+ input: Schema.Json,
106
+ });
107
+ const ClaudeToolResultBlock = Schema.Struct({
108
+ type: Schema.Literal("tool_result"),
109
+ tool_use_id: Schema.NonEmptyString,
110
+ content: Schema.Json,
111
+ is_error: Schema.optionalKey(Schema.Boolean),
112
+ });
113
+ const ClaudeResultMessage = Schema.Struct({
114
+ type: Schema.Literal("result"),
115
+ subtype: Schema.String,
116
+ result: Schema.optionalKey(Schema.String),
117
+ errors: Schema.optionalKey(Schema.Array(Schema.String)),
118
+ queued_turn_count: Schema.optionalKey(Schema.Number),
119
+ });
120
+ const sessionEventsFrom = (message, session, tools) => {
121
+ if (!Schema.is(ClaudeContentMessage)(message))
122
+ return [];
123
+ const events = [];
124
+ for (const block of message.message.content) {
125
+ // Complete messages only: one TextOutput per finished assistant message
126
+ // keeps transcript volume at message granularity, matching the parent.
127
+ if (message.type === "assistant" && Schema.is(ClaudeTextBlock)(block)) {
128
+ events.push(new Agent.TextOutput({ session, text: block.text }));
129
+ }
130
+ else if (Schema.is(ClaudeToolUseBlock)(block)) {
131
+ tools.set(block.id, block.name);
132
+ events.push(new Agent.ToolStarted({
133
+ session,
134
+ callId: block.id,
135
+ tool: block.name,
136
+ input: block.input,
137
+ }));
138
+ }
139
+ else if (Schema.is(ClaudeToolResultBlock)(block)) {
140
+ events.push(new Agent.ToolFinished({
141
+ session,
142
+ callId: block.tool_use_id,
143
+ tool: tools.get(block.tool_use_id) ?? "unknown",
144
+ output: block.content,
145
+ isError: block.is_error === true,
146
+ }));
147
+ }
148
+ }
149
+ return events;
150
+ };
151
+ const makeClaudeChild = Effect.gen(function* () {
152
+ const sdk = yield* ClaudeSdk;
153
+ const launch = Effect.fn("ClaudeChildBackend.launch")(function* (request) {
154
+ yield* Effect.annotateCurrentSpan({
155
+ agent: request.session.agent,
156
+ effort: request.session.brain.effort,
157
+ harness: request.session.brain.harness,
158
+ model: request.session.brain.model,
159
+ parentSessionId: request.session.parentId,
160
+ sessionId: request.session.id,
161
+ });
162
+ yield* Effect.logInfo("Launching Claude child session");
163
+ const input = new AsyncInput();
164
+ const query = sdk.open(input, optionsFor(request));
165
+ yield* Effect.addFinalizer(() => Effect.sync(() => {
166
+ input.end();
167
+ query.close();
168
+ }));
169
+ const models = yield* Effect.tryPromise({
170
+ try: () => query.supportedModels(),
171
+ catch: (cause) => operationError("launch", request, "Claude model discovery failed", cause),
172
+ });
173
+ if (!modelExists(models, request.session.brain.model)) {
174
+ yield* Effect.logError("Claude child rejected an unknown model");
175
+ return yield* new UnknownModelError({
176
+ harness: "claude",
177
+ model: request.session.brain.model,
178
+ message: `Claude does not expose model ${request.session.brain.model}`,
179
+ });
180
+ }
181
+ const channel = yield* sessionChannel({
182
+ label: "Claude child session",
183
+ sessionId: request.session.id,
184
+ });
185
+ channel.onTerminal(() => {
186
+ input.end();
187
+ });
188
+ const tools = new Map();
189
+ yield* channel.emit(new Agent.SessionStarted({ session: request.session }));
190
+ input.offer(userMessage(request.prompt));
191
+ const consume = Stream.fromAsyncIterable(query, (cause) => operationError("stream", request, "Claude output stream failed", cause)).pipe(Stream.runForEach((message) => Effect.gen(function* () {
192
+ for (const event of sessionEventsFrom(message, request.session, tools)) {
193
+ yield* channel.emit(event);
194
+ }
195
+ if (!Schema.is(ClaudeResultMessage)(message))
196
+ return;
197
+ if (message.subtype !== "success" || message.result === undefined) {
198
+ const detail = message.errors?.join("; ") ?? "Claude returned an unsuccessful result";
199
+ yield* channel.fail(new AgentResultError({
200
+ sessionId: Option.some(request.session.id),
201
+ message: detail,
202
+ }));
203
+ return;
204
+ }
205
+ if (message.queued_turn_count !== undefined && message.queued_turn_count > 0) {
206
+ return;
207
+ }
208
+ yield* channel.finish(request.session, message.result.trim() || "Claude child session completed");
209
+ })), Effect.flatMap(() => channel.isTerminal.pipe(Effect.flatMap((done) => done
210
+ ? Effect.void
211
+ : channel.fail(operationError("stream", request, "Claude output closed without a result", new Error("unexpected end of output")))))), Effect.catch((error) => channel.fail(error)));
212
+ yield* Effect.forkScoped(consume);
213
+ const steer = Effect.fn("ClaudeChildBackend.steer")((message) => Effect.logDebug("Steering Claude child session", {
214
+ sessionId: request.session.id,
215
+ }).pipe(Effect.andThen(Effect.try({
216
+ try: () => input.offer(userMessage(message)),
217
+ catch: (cause) => operationError("steer", request, "Could not steer Claude", cause),
218
+ }))));
219
+ const interrupt = Effect.logInfo("Interrupting Claude child session", {
220
+ sessionId: request.session.id,
221
+ }).pipe(Effect.andThen(Effect.tryPromise({
222
+ try: () => query.interrupt(),
223
+ catch: (cause) => operationError("interrupt", request, "Could not interrupt Claude", cause),
224
+ })), Effect.tap(() => Effect.sync(() => input.end())), Effect.asVoid);
225
+ return {
226
+ session: request.session,
227
+ events: Stream.fromQueue(channel.events),
228
+ interrupt,
229
+ result: Deferred.await(channel.result),
230
+ steer,
231
+ };
232
+ });
233
+ return ChildBackend.of({ launch });
234
+ });
235
+ export const claudeChildLayer = Layer.effect(ChildBackend, makeClaudeChild);
236
+ export const claudeChildBackendLayer = Layer.effect(ClaudeChildBackend, makeClaudeChild);
237
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/pi/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,eAAe,GAIzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClF,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EAGZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAgC9C,MAAM,OAAO,SAAU,SAAQ,OAAO,CAAC,OAAO,EAQ3C,CAAC,4BAA4B,CAAC;CAAG;AAEpC,MAAM,mBAAmB,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAEzF,MAAM,iBAAiB,GAAG,CAAC,OAAmB,EAAe,EAAE,CAC7D,mBAAmB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CACd,CAAC;QACF,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC;YACxC,SAAS;YACT,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YACtC,KAAK;SACmB,CAAC;IAC7B,CAAC,CACF,CAAC;IACF,OAAO,YAAY,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Context, Effect, Layer, Schema, Scope, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
3
+ import { type ChildRequest, SessionOperationError } from "../../runtime.ts";
4
+ export interface CodexNotification {
5
+ readonly method: string;
6
+ readonly params: Schema.Json;
7
+ }
8
+ /** One scoped JSON-RPC app-server connection, narrow enough to script in tests. */
9
+ export interface CodexConnection {
10
+ readonly notifications: Stream.Stream<CodexNotification, SessionOperationError>;
11
+ readonly request: (operation: SessionOperationError["operation"], method: string, params: Schema.Json) => Effect.Effect<Schema.Json, SessionOperationError>;
12
+ readonly notify: (operation: SessionOperationError["operation"], method: string, params: Schema.Json) => Effect.Effect<void, SessionOperationError>;
13
+ }
14
+ declare const CodexAppServer_base: Context.ServiceClass<CodexAppServer, "@usine/agents/pi/CodexAppServer", {
15
+ readonly open: (request: ChildRequest) => Effect.Effect<CodexConnection, SessionOperationError, Scope.Scope>;
16
+ }>;
17
+ /** Process seam for the Codex app-server transport. */
18
+ export declare class CodexAppServer extends CodexAppServer_base {
19
+ }
20
+ export declare const operationError: (operation: SessionOperationError["operation"], request: ChildRequest, message: string, cause: unknown) => SessionOperationError;
21
+ export declare const codexAppServerCommand: (cwd: string, stdin?: ChildProcess.CommandOptions["stdin"]) => ChildProcess.Command;
22
+ export declare const codexAppServerLive: Layer.Layer<CodexAppServer, never, ChildProcessSpawner.ChildProcessSpawner>;
23
+ export {};
24
+ //# sourceMappingURL=app-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-server.d.ts","sourceRoot":"","sources":["../../../src/pi/codex/app-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAEP,MAAM,EACN,KAAK,EAIL,MAAM,EACN,KAAK,EACL,MAAM,EACP,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EAAE,KAAK,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;CAC9B;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;IAChF,QAAQ,CAAC,OAAO,EAAE,CAChB,SAAS,EAAE,qBAAqB,CAAC,WAAW,CAAC,EAC7C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,KAChB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IACvD,QAAQ,CAAC,MAAM,EAAE,CACf,SAAS,EAAE,qBAAqB,CAAC,WAAW,CAAC,EAC7C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,KAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAAC,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