@shivaedev/agent-codex 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/adapters/backend.d.ts +5 -0
- package/dist/adapters/backend.d.ts.map +1 -0
- package/dist/adapters/backend.js +23 -0
- package/dist/adapters/backend.js.map +1 -0
- package/dist/adapters/census.d.ts +4 -0
- package/dist/adapters/census.d.ts.map +1 -0
- package/dist/adapters/census.js +10 -0
- package/dist/adapters/census.js.map +1 -0
- package/dist/adapters/configuredBackend.d.ts +6 -0
- package/dist/adapters/configuredBackend.d.ts.map +1 -0
- package/dist/adapters/configuredBackend.js +3 -0
- package/dist/adapters/configuredBackend.js.map +1 -0
- package/dist/adapters/engine.d.ts +3 -5
- package/dist/adapters/engine.d.ts.map +1 -1
- package/dist/adapters/engine.js +6 -77
- package/dist/adapters/engine.js.map +1 -1
- package/dist/adapters/initializeCodex.d.ts +770 -0
- package/dist/adapters/initializeCodex.d.ts.map +1 -0
- package/dist/adapters/initializeCodex.js +8 -0
- package/dist/adapters/initializeCodex.js.map +1 -0
- package/dist/adapters/initializeEngine.d.ts +774 -0
- package/dist/adapters/initializeEngine.d.ts.map +1 -0
- package/dist/adapters/initializeEngine.js +63 -0
- package/dist/adapters/initializeEngine.js.map +1 -0
- package/dist/codex.d.ts +2 -2
- package/dist/codex.d.ts.map +1 -1
- package/dist/codex.js +7 -7
- package/dist/codex.js.map +1 -1
- package/package.json +7 -7
- package/src/adapters/backend.ts +29 -0
- package/src/adapters/census.ts +17 -0
- package/src/adapters/configuredBackend.ts +6 -0
- package/src/adapters/engine.ts +7 -97
- package/src/adapters/initializeCodex.ts +8 -0
- package/src/adapters/initializeEngine.ts +75 -0
- package/src/codex.ts +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 - 2026-11-04
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
|
|
8
|
+
|
|
3
9
|
## 0.2.0 - 2026-11-04
|
|
4
10
|
|
|
5
11
|
### Added
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ConfiguredBackend } from "@shivaedev/agent/backend.ts";
|
|
3
|
+
import type { EngineState } from "#adapters/initializeEngine.ts";
|
|
4
|
+
export declare function backend(state: EngineState): () => Effect.Effect<ConfiguredBackend, never, never>;
|
|
5
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/adapters/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,wDAuBzC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Effect, PubSub, Stream } from "effect";
|
|
2
|
+
export function backend(state) {
|
|
3
|
+
const configured = {
|
|
4
|
+
backend: "codex",
|
|
5
|
+
events: (receipt) => Stream.unwrap(Effect.gen(function* () {
|
|
6
|
+
const session = state.sessions.get(receipt.session?.value ?? "");
|
|
7
|
+
if (session === undefined) {
|
|
8
|
+
return Stream.empty;
|
|
9
|
+
}
|
|
10
|
+
const subscription = yield* PubSub.subscribe(session.events);
|
|
11
|
+
return Stream.fromIterable([
|
|
12
|
+
{ receipt, type: "acknowledged" },
|
|
13
|
+
{ reference: session.threadId, type: "session.opened" },
|
|
14
|
+
]).pipe(Stream.concat(Stream.fromSubscription(subscription)), Stream.interruptWhen(state.exited));
|
|
15
|
+
})),
|
|
16
|
+
features: state.features,
|
|
17
|
+
inspect: state.inspect,
|
|
18
|
+
reconcile: state.reconcile,
|
|
19
|
+
start: state.start,
|
|
20
|
+
};
|
|
21
|
+
return Effect.fn("Codex.backend")(() => Effect.succeed(configured));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/adapters/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhD,MAAM,UAAU,OAAO,CAAC,KAAkB;IACzC,MAAM,UAAU,GAAsB;QACrC,OAAO,EAAE,OAAO;QAChB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CACnB,MAAM,CAAC,MAAM,CACZ,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACjE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,MAAM,CAAC,KAAK,CAAC;YACrB,CAAC;YACD,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7D,OAAO,MAAM,CAAC,YAAY,CAAW;gBACpC,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE;gBACjC,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE;aACvD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACnG,CAAC,CAAC,CACF;QACF,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;KAClB,CAAC;IACF,OAAO,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { EngineState } from "#adapters/initializeEngine.ts";
|
|
3
|
+
export declare function census(state: Pick<EngineState, "claims" | "read">): (rootThreadId: string) => Effect.Effect<import("#adapters/threadSweep.ts").CensusSweep, import("@shivaedev/agent/failures.ts").ReadFailure, never>;
|
|
4
|
+
//# sourceMappingURL=census.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"census.d.ts","sourceRoot":"","sources":["../../src/adapters/census.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,wBAAgB,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,MAAM,CAAC,sJAYjE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { sweepSpawnedDescendants } from "#adapters/threadSweep.ts";
|
|
3
|
+
export function census(state) {
|
|
4
|
+
return Effect.fn("Codex.census")((rootThreadId) => sweepSpawnedDescendants(state.read, rootThreadId).pipe(Effect.tap((children) => Effect.sync(() => {
|
|
5
|
+
for (const child of children) {
|
|
6
|
+
state.claims.claim(rootThreadId, child.threadId);
|
|
7
|
+
}
|
|
8
|
+
}))));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=census.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"census.js","sourceRoot":"","sources":["../../src/adapters/census.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,UAAU,MAAM,CAAC,KAA2C;IACjE,OAAO,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,YAAoB,EAAE,EAAE,CACzD,uBAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,IAAI,CACrD,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACvB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QAChB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC9B,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAClD,CAAC;IACF,CAAC,CAAC,CACF,CACD,CACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { ConfiguredBackend } from "@shivaedev/agent/backend.ts";
|
|
3
|
+
export declare const configuredBackend: (codex: {
|
|
4
|
+
readonly backend: () => Effect.Effect<ConfiguredBackend>;
|
|
5
|
+
}) => Effect.Effect<ConfiguredBackend, never, never>;
|
|
6
|
+
//# sourceMappingURL=configuredBackend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuredBackend.d.ts","sourceRoot":"","sources":["../../src/adapters/configuredBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,eAAO,MAAM,iBAAiB;sBAAoE,MAAM,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;oDAEvI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuredBackend.js","sourceRoot":"","sources":["../../src/adapters/configuredBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,CAAC,KAAmE,EAAE,EAAE,CAC7I,KAAK,CAAC,OAAO,EAAE,CACf,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type { ConfiguredBackend } from "@shivaedev/agent/backend.ts";
|
|
3
|
-
import { Rejected, UnknownAcceptance } from "@shivaedev/agent/failures.ts";
|
|
4
2
|
import type { LineProcess } from "#adapters/process.ts";
|
|
5
3
|
import type { CodexConfiguration } from "#config.ts";
|
|
6
4
|
export declare const engine: (config: CodexConfiguration, spawn?: (() => LineProcess) | undefined) => Effect.Effect<{
|
|
7
|
-
backend: () => Effect.Effect<ConfiguredBackend, never, never>;
|
|
8
|
-
census: (rootThreadId: string) => Effect.Effect<import("
|
|
9
|
-
}, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | Rejected | UnknownAcceptance, import("effect/Scope").Scope>;
|
|
5
|
+
backend: () => Effect.Effect<import("@shivaedev/agent/backend.ts").ConfiguredBackend, never, never>;
|
|
6
|
+
census: (rootThreadId: string) => Effect.Effect<import("./threadSweep.ts").CensusSweep, import("@shivaedev/agent/failures.ts").ReadFailure, never>;
|
|
7
|
+
}, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, import("effect/Scope").Scope>;
|
|
10
8
|
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/adapters/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/adapters/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,MAAM,8CAAkF,WAAW;;;iQAG9G,CAAC"}
|
package/dist/adapters/engine.js
CHANGED
|
@@ -1,80 +1,9 @@
|
|
|
1
|
-
import { Effect
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { receiptOf, recovery } from "#adapters/recovery.ts";
|
|
6
|
-
import { AppServer, openServer } from "#adapters/server.ts";
|
|
7
|
-
import { openSession } from "#adapters/session.ts";
|
|
8
|
-
import { sweepSpawnedDescendants } from "#adapters/threadSweep.ts";
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { backend } from "#adapters/backend.ts";
|
|
3
|
+
import { census } from "#adapters/census.ts";
|
|
4
|
+
import { initializeEngine } from "#adapters/initializeEngine.ts";
|
|
9
5
|
export const engine = Effect.fn("Codex.engine")(function* (config, spawn) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const { operations, refusals, reconcile } = yield* recovery(sessions).pipe(Effect.provideService(AppServer, server));
|
|
13
|
-
const submissionGate = yield* Semaphore.make(1);
|
|
14
|
-
const submit = Effect.fn("Codex.submit")(function* (request, reference) {
|
|
15
|
-
if (operations.has(request.operationId)) {
|
|
16
|
-
const result = yield* reconcile(request.operationId);
|
|
17
|
-
if (result.type === "accepted") {
|
|
18
|
-
return result.receipt;
|
|
19
|
-
}
|
|
20
|
-
if (result.type === "not-accepted") {
|
|
21
|
-
return yield* new Rejected({ backend: "codex", message: result.evidence });
|
|
22
|
-
}
|
|
23
|
-
return yield* new UnknownAcceptance({
|
|
24
|
-
backend: "codex",
|
|
25
|
-
message: result.reason,
|
|
26
|
-
operationId: request.operationId,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (reference !== undefined && (reference.version !== 1 || server.claims.isNode(reference.value))) {
|
|
30
|
-
return yield* new Rejected({ backend: "codex", message: "Child threads are observed passively and cannot be resumed" });
|
|
31
|
-
}
|
|
32
|
-
operations.set(request.operationId, reference?.value);
|
|
33
|
-
const session = yield* openSession(config, request, reference?.value, (operationId, threadId) => {
|
|
34
|
-
operations.set(operationId, threadId);
|
|
35
|
-
}).pipe(Effect.provideService(AppServer, server));
|
|
36
|
-
operations.set(request.operationId, session.threadId);
|
|
37
|
-
sessions.set(session.threadId, session);
|
|
38
|
-
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
39
|
-
if (sessions.get(session.threadId) === session) {
|
|
40
|
-
sessions.delete(session.threadId);
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
const turnId = yield* session.driver.start(request.input, request.operationId);
|
|
44
|
-
return receiptOf(request.operationId, session.threadId, turnId);
|
|
45
|
-
});
|
|
46
|
-
function start(request, session) {
|
|
47
|
-
return Semaphore.withPermit(submissionGate)(submit(request, session)).pipe(Effect.tapError((error) => Effect.sync(() => {
|
|
48
|
-
if (error._tag === "Rejected") {
|
|
49
|
-
refusals.set(request.operationId, error.message);
|
|
50
|
-
}
|
|
51
|
-
})));
|
|
52
|
-
}
|
|
53
|
-
const backend = {
|
|
54
|
-
backend: "codex",
|
|
55
|
-
events: (receipt) => Stream.unwrap(Effect.gen(function* () {
|
|
56
|
-
const session = sessions.get(receipt.session?.value ?? "");
|
|
57
|
-
if (session === undefined) {
|
|
58
|
-
return Stream.empty;
|
|
59
|
-
}
|
|
60
|
-
const subscription = yield* PubSub.subscribe(session.events);
|
|
61
|
-
return Stream.fromIterable([
|
|
62
|
-
{ receipt, type: "acknowledged" },
|
|
63
|
-
{ reference: session.threadId, type: "session.opened" },
|
|
64
|
-
]).pipe(Stream.concat(Stream.fromSubscription(subscription)), Stream.interruptWhen(server.exited));
|
|
65
|
-
})),
|
|
66
|
-
features: yield* features(sessions, start).pipe(Effect.provideService(AppServer, server)),
|
|
67
|
-
inspect: (receipt) => observe(receipt).pipe(Effect.provideService(AppServer, server)),
|
|
68
|
-
reconcile,
|
|
69
|
-
start,
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
backend: () => Effect.succeed(backend),
|
|
73
|
-
census: (rootThreadId) => sweepSpawnedDescendants((method, params) => readRequest(method, params).pipe(Effect.provideService(AppServer, server)), rootThreadId).pipe(Effect.tap((children) => Effect.sync(() => {
|
|
74
|
-
for (const child of children) {
|
|
75
|
-
server.claims.claim(rootThreadId, child.threadId);
|
|
76
|
-
}
|
|
77
|
-
}))),
|
|
78
|
-
};
|
|
6
|
+
const state = yield* initializeEngine(config, spawn);
|
|
7
|
+
return { backend: backend(state), census: census(state) };
|
|
79
8
|
});
|
|
80
9
|
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/adapters/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/adapters/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAIjE,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,EAAE,MAA0B,EAAE,KAAyB;IAC/G,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3D,CAAC,CAAC,CAAC"}
|