@usine/agents 0.0.0 → 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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -1
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/pi/authentication.d.ts +13 -0
  8. package/dist/pi/authentication.d.ts.map +1 -0
  9. package/dist/pi/authentication.js +14 -0
  10. package/dist/pi/authentication.js.map +1 -0
  11. package/dist/pi/children.d.ts +5 -0
  12. package/dist/pi/children.d.ts.map +1 -0
  13. package/dist/pi/children.js +26 -0
  14. package/dist/pi/children.js.map +1 -0
  15. package/dist/pi/claude.d.ts +32 -0
  16. package/dist/pi/claude.d.ts.map +1 -0
  17. package/dist/pi/claude.js +237 -0
  18. package/dist/pi/claude.js.map +1 -0
  19. package/dist/pi/codex/app-server.d.ts +24 -0
  20. package/dist/pi/codex/app-server.d.ts.map +1 -0
  21. package/dist/pi/codex/app-server.js +188 -0
  22. package/dist/pi/codex/app-server.js.map +1 -0
  23. package/dist/pi/codex/codex.d.ts +5 -0
  24. package/dist/pi/codex/codex.d.ts.map +1 -0
  25. package/dist/pi/codex/codex.js +342 -0
  26. package/dist/pi/codex/codex.js.map +1 -0
  27. package/dist/pi/index.d.ts +11 -0
  28. package/dist/pi/index.d.ts.map +1 -0
  29. package/dist/pi/index.js +18 -0
  30. package/dist/pi/index.js.map +1 -0
  31. package/dist/pi/pi.d.ts +7 -0
  32. package/dist/pi/pi.d.ts.map +1 -0
  33. package/dist/pi/pi.js +273 -0
  34. package/dist/pi/pi.js.map +1 -0
  35. package/dist/pi/sdk.d.ts +66 -0
  36. package/dist/pi/sdk.d.ts.map +1 -0
  37. package/dist/pi/sdk.js +154 -0
  38. package/dist/pi/sdk.js.map +1 -0
  39. package/dist/pi/session.d.ts +46 -0
  40. package/dist/pi/session.d.ts.map +1 -0
  41. package/dist/pi/session.js +180 -0
  42. package/dist/pi/session.js.map +1 -0
  43. package/dist/pi/subagents.d.ts +23 -0
  44. package/dist/pi/subagents.d.ts.map +1 -0
  45. package/dist/pi/subagents.js +83 -0
  46. package/dist/pi/subagents.js.map +1 -0
  47. package/dist/prompt.d.ts +22 -0
  48. package/dist/prompt.d.ts.map +1 -0
  49. package/dist/prompt.js +42 -0
  50. package/dist/prompt.js.map +1 -0
  51. package/dist/protocol/codex.d.ts +56 -0
  52. package/dist/protocol/codex.d.ts.map +1 -0
  53. package/dist/protocol/codex.js +2 -0
  54. package/dist/protocol/codex.js.map +1 -0
  55. package/dist/runtime.d.ts +114 -0
  56. package/dist/runtime.d.ts.map +1 -0
  57. package/dist/runtime.js +96 -0
  58. package/dist/runtime.js.map +1 -0
  59. package/package.json +54 -4
@@ -0,0 +1,180 @@
1
+ import { Agent } from "@usine/core";
2
+ import { Cause, Deferred, Effect, Queue, Ref, Schema } from "effect";
3
+ import { SessionResult } from "../runtime.js";
4
+ export const sessionChannel = Effect.fn("SessionChannel.make")(function* (options) {
5
+ const events = yield* Queue.make();
6
+ const result = yield* Deferred.make();
7
+ const terminal = yield* Ref.make(false);
8
+ const cleanups = [];
9
+ const runCleanups = Effect.sync(() => {
10
+ for (const cleanup of cleanups.splice(0))
11
+ cleanup();
12
+ });
13
+ const emit = (event) => Queue.offer(events, event).pipe(Effect.flatMap((accepted) => accepted
14
+ ? Effect.void
15
+ : Effect.logWarning(`${options.label} dropped an event after the terminal transition`, {
16
+ event: event._tag,
17
+ sessionId: options.sessionId,
18
+ })));
19
+ const fail = Effect.fn("SessionChannel.fail")(function* (error) {
20
+ if (yield* Ref.getAndSet(terminal, true))
21
+ return;
22
+ yield* Effect.logError(`${options.label} failed`, {
23
+ errorTag: error._tag,
24
+ message: error.message,
25
+ sessionId: options.sessionId,
26
+ });
27
+ yield* Deferred.fail(result, error);
28
+ yield* Queue.fail(events, error);
29
+ yield* runCleanups;
30
+ });
31
+ const finish = Effect.fn("SessionChannel.finish")(function* (session, message) {
32
+ if (yield* Ref.getAndSet(terminal, true))
33
+ return;
34
+ yield* Queue.offer(events, new Agent.SessionFinished({ session }));
35
+ yield* Deferred.succeed(result, new SessionResult({ message }));
36
+ yield* Queue.end(events);
37
+ yield* runCleanups;
38
+ yield* Effect.logInfo(`${options.label} finished`, {
39
+ sessionId: options.sessionId,
40
+ });
41
+ });
42
+ return {
43
+ events,
44
+ result,
45
+ isTerminal: Ref.get(terminal),
46
+ onTerminal: (cleanup) => {
47
+ cleanups.push(cleanup);
48
+ },
49
+ emit,
50
+ fail,
51
+ finish,
52
+ };
53
+ });
54
+ const PiAssistantMessage = Schema.Struct({
55
+ role: Schema.Literal("assistant"),
56
+ content: Schema.Union([Schema.String, Schema.Array(Schema.Json)]),
57
+ });
58
+ const PiTextBlock = Schema.Struct({
59
+ type: Schema.Literal("text"),
60
+ text: Schema.String,
61
+ });
62
+ const decodeSerializedJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Json));
63
+ const toolInputJson = (event) => {
64
+ try {
65
+ return decodeSerializedJson(JSON.stringify(event.args) ?? "null");
66
+ }
67
+ catch {
68
+ return String(event.args);
69
+ }
70
+ };
71
+ const toolOutputJson = (event) => {
72
+ try {
73
+ return decodeSerializedJson(JSON.stringify(event.result) ?? "null");
74
+ }
75
+ catch {
76
+ return String(event.result);
77
+ }
78
+ };
79
+ const messageText = (message) => {
80
+ if (!Schema.is(PiAssistantMessage)(message))
81
+ return undefined;
82
+ if (Schema.is(Schema.String)(message.content))
83
+ return message.content.trim() || undefined;
84
+ const text = message.content
85
+ .filter(Schema.is(PiTextBlock))
86
+ .map(({ text }) => text)
87
+ .join("")
88
+ .trim();
89
+ return text || undefined;
90
+ };
91
+ export const lastPiMessageText = (messages) => {
92
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
93
+ const message = messages[index];
94
+ if (message === undefined)
95
+ continue;
96
+ const text = messageText(message);
97
+ if (text !== undefined)
98
+ return text;
99
+ }
100
+ return undefined;
101
+ };
102
+ const sessionEventFrom = (event, session) => {
103
+ if (event.type === "message_end") {
104
+ const text = messageText(event.message);
105
+ return text === undefined ? undefined : new Agent.TextOutput({ session, text });
106
+ }
107
+ if (event.type === "tool_execution_start") {
108
+ return new Agent.ToolStarted({
109
+ session,
110
+ callId: event.toolCallId,
111
+ tool: event.toolName,
112
+ input: toolInputJson(event),
113
+ });
114
+ }
115
+ if (event.type === "tool_execution_end") {
116
+ return new Agent.ToolFinished({
117
+ session,
118
+ callId: event.toolCallId,
119
+ tool: event.toolName,
120
+ output: toolOutputJson(event),
121
+ isError: event.isError,
122
+ });
123
+ }
124
+ return undefined;
125
+ };
126
+ /**
127
+ * Bridges the Pi SDK's synchronous subscriber onto one session channel.
128
+ * Normalized events reach the queue on the SDK's own tick — no async hop, so
129
+ * nothing can trail the prompt's resolution — while operational events with
130
+ * no normalized shape (retry backoffs, compactions) are logged through the
131
+ * launch fiber's captured services so a silent wait stays explainable.
132
+ */
133
+ export const subscribePiSession = (piSession, session, channel) => Effect.gen(function* () {
134
+ const context = yield* Effect.context();
135
+ const log = Effect.runForkWith(context);
136
+ let lastText;
137
+ const unsubscribe = piSession.subscribe((event) => {
138
+ if (event.type === "auto_retry_start") {
139
+ log(Effect.logWarning("Pi session is backing off before a retry", {
140
+ attempt: event.attempt,
141
+ delayMillis: event.delayMs,
142
+ errorMessage: event.errorMessage,
143
+ maxAttempts: event.maxAttempts,
144
+ sessionId: session.id,
145
+ }));
146
+ return;
147
+ }
148
+ if (event.type === "auto_retry_end") {
149
+ log(Effect.logInfo("Pi session finished retrying", {
150
+ attempt: event.attempt,
151
+ finalError: event.finalError,
152
+ sessionId: session.id,
153
+ success: event.success,
154
+ }));
155
+ return;
156
+ }
157
+ if (event.type === "compaction_start" || event.type === "compaction_end") {
158
+ log(Effect.logInfo("Pi session context compaction", {
159
+ phase: event.type,
160
+ reason: event.reason,
161
+ sessionId: session.id,
162
+ }));
163
+ return;
164
+ }
165
+ const sessionEvent = sessionEventFrom(event, session);
166
+ if (sessionEvent === undefined)
167
+ return;
168
+ if (sessionEvent._tag === "TextOutput")
169
+ lastText = sessionEvent.text;
170
+ if (!Queue.offerUnsafe(channel.events, sessionEvent)) {
171
+ log(Effect.logWarning("Dropped a Pi session event after the terminal transition", {
172
+ event: sessionEvent._tag,
173
+ sessionId: session.id,
174
+ }));
175
+ }
176
+ });
177
+ channel.onTerminal(unsubscribe);
178
+ return { lastText: () => lastText, unsubscribe };
179
+ });
180
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/pi/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAA0B,aAAa,EAAE,MAAM,eAAe,CAAC;AAyBtE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,EACtE,OAA8B;IAE9B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,EAAsD,CAAC;IACvF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAoC,CAAC;IACxE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QACnC,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CAAC,KAAy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AM,CAAC,OAAO,CAAC,+BAA+B,EAAE;gBAC9C,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,OAAO,CAAC,EAAE;aACtB,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QACD,MAAM,YAAY,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS;YAAE,OAAO;QACvC,IAAI,YAAY,CAAC,IAAI,KAAK,YAAY;YAAE,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC;QACrE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC;YACrD,GAAG,CACD,MAAM,CAAC,UAAU,CAAC,0DAA0D,EAAE;gBAC5E,KAAK,EAAE,YAAY,CAAC,IAAI;gBACxB,SAAS,EAAE,OAAO,CAAC,EAAE;aACtB,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type ExtensionFactory, type InlineExtension } from "@earendil-works/pi-coding-agent";
2
+ import { Agent } from "@usine/core";
3
+ import { Effect } from "effect";
4
+ import { type AgentSessionError, type ChildBackend, type WorkingDirectory } from "../runtime.ts";
5
+ export interface SubagentsExtensionOptions {
6
+ readonly agent: Agent.Agent;
7
+ readonly backend: ChildBackend["Service"];
8
+ readonly cwd: WorkingDirectory;
9
+ readonly emit: (event: Agent.SessionEvent) => Effect.Effect<void>;
10
+ readonly parentId: Agent.SessionId;
11
+ /**
12
+ * Executes one child program on the parent launch's own services and scope.
13
+ * Pi invokes the tool outside any usine fiber, so running through the
14
+ * default runtime would lose the stderr log redirect (corrupting the
15
+ * protocol stdout) and detach the child from the Attempt's lifetime.
16
+ */
17
+ readonly run: <A>(program: Effect.Effect<A, AgentSessionError>) => Promise<A>;
18
+ }
19
+ /** Pi-owned extension factory. Its single tool can only create first-level child descriptors. */
20
+ export declare const createSubagentsExtension: (options: SubagentsExtensionOptions) => ExtensionFactory;
21
+ /** Named wrapper keeps the extension identifiable in Pi startup diagnostics. */
22
+ export declare const subagentsExtension: (options: SubagentsExtensionOptions) => InlineExtension;
23
+ //# sourceMappingURL=subagents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagents.d.ts","sourceRoot":"","sources":["../../src/pi/subagents.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAC;AAG/C,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1C,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,iBAAiB,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/E;AAiBD,iGAAiG;AACjG,eAAO,MAAM,wBAAwB,YAAa,yBAAyB,KAAG,gBA0E7E,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,YAAa,yBAAyB,KAAG,eAGtE,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { defineTool, } from "@earendil-works/pi-coding-agent";
2
+ import { Agent } from "@usine/core";
3
+ import { Effect, Fiber, Stream } from "effect";
4
+ import { Type } from "typebox";
5
+ import { assembleChildPrompt } from "../prompt.js";
6
+ import { ChildRequest, } from "../runtime.js";
7
+ const interrupted = (signal, sessionId) => signal === undefined
8
+ ? Effect.logWarning("Pi supplied no abort signal; the child outlives only its scope", {
9
+ sessionId,
10
+ }).pipe(Effect.andThen(Effect.never))
11
+ : Effect.callback((resume) => {
12
+ const onAbort = () => resume(Effect.void);
13
+ if (signal.aborted)
14
+ onAbort();
15
+ else
16
+ signal.addEventListener("abort", onAbort, { once: true });
17
+ return Effect.sync(() => signal.removeEventListener("abort", onAbort));
18
+ });
19
+ /** Pi-owned extension factory. Its single tool can only create first-level child descriptors. */
20
+ export const createSubagentsExtension = (options) => {
21
+ let childNumber = 0;
22
+ return (pi) => {
23
+ pi.registerTool(defineTool({
24
+ name: "subagent",
25
+ label: "Subagent",
26
+ description: "Delegate one focused task to the configured isolated child agent and wait for its report.",
27
+ promptSnippet: "Delegate a focused task to an isolated child agent.",
28
+ promptGuidelines: [
29
+ "Delegate only independent, focused work; the child cannot create more children.",
30
+ ],
31
+ parameters: Type.Object({ task: Type.String({ minLength: 1 }) }, { additionalProperties: false }),
32
+ executionMode: "parallel",
33
+ execute: (_toolCallId, params, signal, onUpdate) => {
34
+ childNumber += 1;
35
+ const session = new Agent.ChildSession({
36
+ id: Agent.SessionId.make(`${options.parentId}:child:${childNumber}`),
37
+ parentId: options.parentId,
38
+ agent: options.agent.name,
39
+ brain: options.agent.brain,
40
+ });
41
+ const request = new ChildRequest({
42
+ session,
43
+ cwd: options.cwd,
44
+ prompt: assembleChildPrompt({
45
+ agent: options.agent.name,
46
+ persona: options.agent.persona,
47
+ task: params.task,
48
+ }),
49
+ });
50
+ const program = Effect.scoped(Effect.gen(function* () {
51
+ yield* Effect.annotateCurrentSpan({
52
+ agent: request.session.agent,
53
+ parentSessionId: request.session.parentId,
54
+ sessionId: request.session.id,
55
+ });
56
+ yield* Effect.logInfo("Delegating task to child session");
57
+ const child = yield* options.backend.launch(request);
58
+ const forward = yield* child.events.pipe(Stream.runForEach(options.emit), Effect.forkScoped);
59
+ const result = yield* Effect.raceFirst(child.result, interrupted(signal, request.session.id).pipe(Effect.andThen(child.interrupt), Effect.andThen(Effect.interrupt)));
60
+ yield* Fiber.join(forward);
61
+ yield* Effect.logInfo("Child session returned to Pi parent", {
62
+ sessionId: request.session.id,
63
+ });
64
+ onUpdate?.({
65
+ content: [{ type: "text", text: result.message }],
66
+ details: { childSessionId: session.id },
67
+ });
68
+ return {
69
+ content: [{ type: "text", text: result.message }],
70
+ details: { childSessionId: session.id },
71
+ };
72
+ }));
73
+ return options.run(program);
74
+ },
75
+ }));
76
+ };
77
+ };
78
+ /** Named wrapper keeps the extension identifiable in Pi startup diagnostics. */
79
+ export const subagentsExtension = (options) => ({
80
+ name: "usine-subagents",
81
+ factory: createSubagentsExtension(options),
82
+ });
83
+ //# sourceMappingURL=subagents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagents.js","sourceRoot":"","sources":["../../src/pi/subagents.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAGL,YAAY,GAE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C,OAAkC,EAAmB,EAAE,CAAC,CAAC;IAC1F,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC;CAC3C,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Agent, AttemptChannel, Repository } from "@usine/core";
2
+ import type { Schema } from "effect";
3
+ export interface PromptParts {
4
+ readonly repository: Repository.Name;
5
+ readonly payload: Schema.Json;
6
+ readonly agent: Agent.Name;
7
+ readonly persona: Agent.Persona;
8
+ readonly task: AttemptChannel.Task;
9
+ }
10
+ export interface ChildPromptParts {
11
+ readonly agent: Agent.Name;
12
+ readonly persona: Agent.Persona;
13
+ /** Free text authored by the parent model, not the rendered loop task. */
14
+ readonly task: string;
15
+ }
16
+ /** Human-visible attribution required on GitHub content authored by an Agent. */
17
+ export declare const githubSignature: (agent: Agent.Name) => string;
18
+ /** Builds the complete parent prompt from immutable run context. */
19
+ export declare const assemblePrompt: (parts: PromptParts) => string;
20
+ /** Builds the isolated prompt given to a first-level child session. */
21
+ export declare const assembleChildPrompt: (parts: ChildPromptParts) => string;
22
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,iFAAiF;AACjF,eAAO,MAAM,eAAe,UAAW,KAAK,CAAC,IAAI,KAAG,MAAmC,CAAC;AAExF,oEAAoE;AACpE,eAAO,MAAM,cAAc,UAAW,WAAW,KAAG,MAuBtC,CAAC;AAEf,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,UAAW,gBAAgB,KAAG,MAchD,CAAC"}
package/dist/prompt.js ADDED
@@ -0,0 +1,42 @@
1
+ /** Human-visible attribution required on GitHub content authored by an Agent. */
2
+ export const githubSignature = (agent) => `— usine agent: ${agent}`;
3
+ /** Builds the complete parent prompt from immutable run context. */
4
+ export const assemblePrompt = (parts) => [
5
+ "# Run context",
6
+ "",
7
+ `Repository: ${parts.repository}`,
8
+ "",
9
+ "Payload snapshot:",
10
+ "```json",
11
+ JSON.stringify(parts.payload, undefined, 2),
12
+ "```",
13
+ "",
14
+ "# Agent persona",
15
+ "",
16
+ parts.persona,
17
+ "",
18
+ "# Task",
19
+ "",
20
+ parts.task,
21
+ "",
22
+ "# GitHub identity",
23
+ "",
24
+ "Append this signature to every GitHub comment, issue, or pull request you publish:",
25
+ githubSignature(parts.agent),
26
+ ].join("\n");
27
+ /** Builds the isolated prompt given to a first-level child session. */
28
+ export const assembleChildPrompt = (parts) => [
29
+ "# Agent persona",
30
+ "",
31
+ parts.persona,
32
+ "",
33
+ "# Delegated task",
34
+ "",
35
+ parts.task,
36
+ "",
37
+ "# GitHub identity",
38
+ "",
39
+ "Append this signature to every GitHub comment, issue, or pull request you publish:",
40
+ githubSignature(parts.agent),
41
+ ].join("\n");
42
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAkBA,iFAAiF;AACjF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAU,EAAE,CAAC,kBAAkB,KAAK,EAAE,CAAC;AAExF,oEAAoE;AACpE,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,EAAE;IACF,KAAK,CAAC,OAAO;IACb,EAAE;IACF,QAAQ;IACR,EAAE;IACF,KAAK,CAAC,IAAI;IACV,EAAE;IACF,mBAAmB;IACnB,EAAE;IACF,oFAAoF;IACpF,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC;CAC7B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEf,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAuB,EAAU,EAAE,CACrE;IACE,iBAAiB;IACjB,EAAE;IACF,KAAK,CAAC,OAAO;IACb,EAAE;IACF,kBAAkB;IAClB,EAAE;IACF,KAAK,CAAC,IAAI;IACV,EAAE;IACF,mBAAmB;IACnB,EAAE;IACF,oFAAoF;IACpF,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC;CAC7B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * NodeNext-compatible view of the exact-pinned generated app-server protocol
3
+ * (`@pwrdrvr/codex-app-server-protocol@0.144.0`, mirroring codex-cli 0.144.0).
4
+ * The upstream package omits extensions in its generated source, so it only
5
+ * resolves under bundler-style resolution; these are the request shapes usine
6
+ * sends on that pinned wire version. `protocol-conformance/check.ts` compiles
7
+ * against the real package and fails `pnpm check` when this view drifts.
8
+ */
9
+ export interface InitializeParams {
10
+ readonly clientInfo: {
11
+ readonly name: string;
12
+ readonly title: string | null;
13
+ readonly version: string;
14
+ };
15
+ readonly capabilities: null;
16
+ }
17
+ export interface ModelListParams {
18
+ readonly cursor?: string | null;
19
+ readonly limit?: number | null;
20
+ readonly includeHidden?: boolean | null;
21
+ }
22
+ export interface ThreadStartParams {
23
+ readonly model?: string | null;
24
+ readonly allowProviderModelFallback?: boolean;
25
+ readonly cwd?: string | null;
26
+ readonly approvalPolicy?: "never" | "on-request" | "untrusted" | null;
27
+ readonly sandbox?: "read-only" | "workspace-write" | "danger-full-access" | null;
28
+ readonly serviceName?: string | null;
29
+ readonly ephemeral?: boolean | null;
30
+ }
31
+ interface TextInput {
32
+ readonly type: "text";
33
+ readonly text: string;
34
+ readonly text_elements: ReadonlyArray<never>;
35
+ }
36
+ export interface TurnStartParams {
37
+ readonly threadId: string;
38
+ readonly input: ReadonlyArray<TextInput>;
39
+ readonly cwd?: string | null;
40
+ readonly approvalPolicy?: "never" | "on-request" | "untrusted" | null;
41
+ readonly sandboxPolicy?: {
42
+ readonly type: "dangerFullAccess";
43
+ } | null;
44
+ readonly effort?: string | null;
45
+ }
46
+ export interface TurnSteerParams {
47
+ readonly threadId: string;
48
+ readonly expectedTurnId: string;
49
+ readonly input: ReadonlyArray<TextInput>;
50
+ }
51
+ export interface TurnInterruptParams {
52
+ readonly threadId: string;
53
+ readonly turnId: string;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=codex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/protocol/codex.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAA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Ac,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,WAAW,GAAG,IAAI,CAAC;IACtE,QAAQ,CAAC,aAAa,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;KAAE,GAAG,IAAI,CAAC;IACtE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=codex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/protocol/codex.ts"],"names":[],"mappings":""}
@@ -0,0 +1,114 @@
1
+ import { Agent, AttemptChannel, AttemptFailure } from "@usine/core";
2
+ import { Context, Effect, Schema, Scope, Stream } from "effect";
3
+ /** Value object: process-local working directory for one isolated Attempt. */
4
+ export declare const WorkingDirectory: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
5
+ export type WorkingDirectory = typeof WorkingDirectory.Type;
6
+ declare const LaunchRequest_base: Schema.Class<LaunchRequest, Schema.Struct<{
7
+ readonly spec: typeof AttemptChannel.RunSpec;
8
+ readonly cwd: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
9
+ }>, {}>;
10
+ /** Complete input required to start the Pi parent inside one Attempt checkout. */
11
+ export declare class LaunchRequest extends LaunchRequest_base {
12
+ }
13
+ declare const ChildRequest_base: Schema.Class<ChildRequest, Schema.Struct<{
14
+ readonly session: typeof Agent.ChildSession;
15
+ readonly cwd: Schema.brand<Schema.NonEmptyString, "AgentWorkingDirectory">;
16
+ readonly prompt: Schema.NonEmptyString;
17
+ }>, {}>;
18
+ /** Complete input for exactly one first-level child session. */
19
+ export declare class ChildRequest extends ChildRequest_base {
20
+ }
21
+ declare const SessionResult_base: Schema.Class<SessionResult, Schema.Struct<{
22
+ readonly message: Schema.NonEmptyString;
23
+ }>, {}>;
24
+ /** Terminal semantic output from a parent or child SDK session. */
25
+ export declare class SessionResult extends SessionResult_base {
26
+ }
27
+ declare const UnknownModelError_base: Schema.Class<UnknownModelError, Schema.TaggedStruct<"UnknownModelError", {
28
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
29
+ readonly model: Schema.brand<Schema.String, "ModelId">;
30
+ readonly message: Schema.NonEmptyString;
31
+ }>, import("effect/Cause").YieldableError>;
32
+ /** The configured vendor model id is well-formed but absent from the selected SDK registry. */
33
+ export declare class UnknownModelError extends UnknownModelError_base {
34
+ }
35
+ declare const PoolUnavailableError_base: Schema.Class<PoolUnavailableError, Schema.TaggedStruct<"PoolUnavailableError", {
36
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
37
+ readonly model: Schema.brand<Schema.String, "ModelId">;
38
+ readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
39
+ readonly message: Schema.NonEmptyString;
40
+ }>, import("effect/Cause").YieldableError>;
41
+ /** The selected credential cannot draw from the billing pool required by this session. */
42
+ export declare class PoolUnavailableError extends PoolUnavailableError_base {
43
+ }
44
+ declare const UnsupportedEffortError_base: Schema.Class<UnsupportedEffortError, Schema.TaggedStruct<"UnsupportedEffortError", {
45
+ readonly harness: Schema.Literals<readonly ["claude", "codex", "pi"]>;
46
+ readonly model: Schema.brand<Schema.String, "ModelId">;
47
+ readonly effort: Schema.Literals<readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"]>;
48
+ readonly message: Schema.NonEmptyString;
49
+ }>, import("effect/Cause").YieldableError>;
50
+ /** The selected model exists but does not support the rostered reasoning effort. */
51
+ export declare class UnsupportedEffortError extends UnsupportedEffortError_base {
52
+ }
53
+ declare const AgentResultError_base: Schema.Class<AgentResultError, Schema.TaggedStruct<"AgentResultError", {
54
+ readonly sessionId: Schema.OptionFromNullOr<Schema.brand<Schema.NonEmptyString, "AgentSessionId">>;
55
+ readonly message: Schema.NonEmptyString;
56
+ }>, import("effect/Cause").YieldableError>;
57
+ /** The session ran to a terminal state and reported that the work itself failed. */
58
+ export declare class AgentResultError extends AgentResultError_base {
59
+ }
60
+ export declare const SESSION_OPERATIONS: readonly ["launch", "stream", "steer", "interrupt"];
61
+ export declare const SessionOperation: Schema.Literals<readonly ["launch", "stream", "steer", "interrupt"]>;
62
+ export type SessionOperation = typeof SessionOperation.Type;
63
+ declare const SessionOperationError_base: Schema.Class<SessionOperationError, Schema.TaggedStruct<"SessionOperationError", {
64
+ readonly operation: Schema.Literals<readonly ["launch", "stream", "steer", "interrupt"]>;
65
+ readonly sessionId: Schema.OptionFromNullOr<Schema.brand<Schema.NonEmptyString, "AgentSessionId">>;
66
+ readonly message: Schema.NonEmptyString;
67
+ readonly cause: Schema.Defect;
68
+ }>, import("effect/Cause").YieldableError>;
69
+ /** SDK/process failure after model and harness validation. */
70
+ export declare class SessionOperationError extends SessionOperationError_base {
71
+ }
72
+ export declare const AgentSessionError: Schema.Union<readonly [typeof UnknownModelError, typeof PoolUnavailableError, typeof UnsupportedEffortError, typeof AgentResultError, typeof SessionOperationError]>;
73
+ export type AgentSessionError = typeof AgentSessionError.Type;
74
+ /**
75
+ * The one place the session error union meets the ADR 0002 retry taxonomy:
76
+ * SDK/process trouble is retryable infrastructure; a bad roster spec or the
77
+ * agent failing its own work always waits for the operator.
78
+ */
79
+ export declare const toAttemptFailure: (error: AgentSessionError) => AttemptFailure.AttemptFailure;
80
+ /** Live SDK session. Its event stream and controls are backend-independent. */
81
+ export interface RunningSession {
82
+ readonly session: Agent.Session;
83
+ readonly events: Stream.Stream<Agent.SessionEvent, AgentSessionError>;
84
+ readonly result: Effect.Effect<SessionResult, AgentSessionError>;
85
+ readonly steer: (message: string) => Effect.Effect<void, AgentSessionError>;
86
+ readonly interrupt: Effect.Effect<void, AgentSessionError>;
87
+ }
88
+ export interface ChildBackendService {
89
+ readonly launch: (request: ChildRequest) => Effect.Effect<RunningSession, AgentSessionError, Scope.Scope>;
90
+ }
91
+ declare const ChildBackend_base: Context.ServiceClass<ChildBackend, "@usine/agents/ChildBackend", ChildBackendService>;
92
+ /** Stable first-level child seam selected by the authored BrainSpec harness. */
93
+ export declare class ChildBackend extends ChildBackend_base {
94
+ }
95
+ declare const ClaudeChildBackend_base: Context.ServiceClass<ClaudeChildBackend, "@usine/agents/ClaudeChildBackend", ChildBackendService>;
96
+ /** Concrete Claude child implementation consumed by the harness dispatcher. */
97
+ export declare class ClaudeChildBackend extends ClaudeChildBackend_base {
98
+ }
99
+ declare const CodexChildBackend_base: Context.ServiceClass<CodexChildBackend, "@usine/agents/CodexChildBackend", ChildBackendService>;
100
+ /** Concrete Codex child implementation consumed by the harness dispatcher. */
101
+ export declare class CodexChildBackend extends CodexChildBackend_base {
102
+ }
103
+ declare const PiChildBackend_base: Context.ServiceClass<PiChildBackend, "@usine/agents/PiChildBackend", ChildBackendService>;
104
+ /** Concrete Pi child implementation consumed by the harness dispatcher. */
105
+ export declare class PiChildBackend extends PiChildBackend_base {
106
+ }
107
+ declare const AgentRuntime_base: Context.ServiceClass<AgentRuntime, "@usine/agents/AgentRuntime", {
108
+ readonly launch: (request: LaunchRequest) => Effect.Effect<RunningSession, AgentSessionError, Scope.Scope>;
109
+ }>;
110
+ /** Stable parent seam consumed by the run host. */
111
+ export declare class AgentRuntime extends AgentRuntime_base {
112
+ }
113
+ export {};
114
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,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