@inixiative/agent-session 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.
- package/README.md +73 -0
- package/package.json +24 -0
- package/src/claude-code-session.ts +779 -0
- package/src/codex-session.ts +947 -0
- package/src/harness-session.ts +155 -0
- package/src/index.ts +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @inixiative/agent-session
|
|
2
|
+
|
|
3
|
+
Drive coding-agent CLIs as **persistent, streaming, event-captured sessions** —
|
|
4
|
+
one interface, any agent. Claude Code and Codex today; Gemini and Grok planned.
|
|
5
|
+
|
|
6
|
+
Most ways to script a coding agent are one-shot (`claude -p "…"`) and lose the
|
|
7
|
+
process. `agent-session` keeps a single long-lived agent process, streams turns
|
|
8
|
+
in over stdin, and classifies **every** event coming back — text, thinking,
|
|
9
|
+
tool calls, tool results, usage — so you can drive multi-turn work and capture
|
|
10
|
+
exactly what the agent did. Built for eval harnesses, agent comparisons, and
|
|
11
|
+
multi-agent orchestration.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { ClaudeCodeSession } from "@inixiative/agent-session";
|
|
15
|
+
|
|
16
|
+
const session = new ClaudeCodeSession({
|
|
17
|
+
cwd: "/path/to/workdir",
|
|
18
|
+
model: "sonnet",
|
|
19
|
+
permissionMode: "bypassPermissions",
|
|
20
|
+
});
|
|
21
|
+
await session.start();
|
|
22
|
+
|
|
23
|
+
const result = await session.send("Build a CLI that …");
|
|
24
|
+
console.log(result.content); // final text
|
|
25
|
+
console.log(result.tokens); // { input, output }
|
|
26
|
+
for (const e of result.events) { // full classified event stream
|
|
27
|
+
if (e.kind === "tool_use") console.log("tool:", e.toolName);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
session.kill();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Why it's different
|
|
34
|
+
|
|
35
|
+
- **Persistent, multi-turn.** One process per session; `send()` per turn,
|
|
36
|
+
resolves on the runtime's `result` event. Not one-shot `-p`.
|
|
37
|
+
- **Full event capture.** A normalized `SessionEvent` taxonomy
|
|
38
|
+
(`text` / `thinking` / `tool_use` / `tool_result` / `result` / `error` /
|
|
39
|
+
`session_compact`) — the same shape regardless of runtime.
|
|
40
|
+
- **Subscription auth, no API billing.** The Claude Code adapter strips
|
|
41
|
+
`ANTHROPIC_API_KEY` and authenticates via the CLI's subscription / an
|
|
42
|
+
`CLAUDE_CODE_OAUTH_TOKEN` from `claude setup-token` — works headless and in
|
|
43
|
+
containers.
|
|
44
|
+
- **fork / resume / interrupt** and pre-send hooks (rewrite the outgoing
|
|
45
|
+
message — e.g. inject just-in-time context per turn).
|
|
46
|
+
- **Zero dependencies.** Just Bun + the agent CLI you're driving.
|
|
47
|
+
|
|
48
|
+
## Interface
|
|
49
|
+
|
|
50
|
+
`HarnessSession` is the provider-agnostic contract (`start` / `send` / `kill` /
|
|
51
|
+
`fork` / `interrupt` + an event handler). `ClaudeCodeSession` implements it over
|
|
52
|
+
`claude --print --input-format stream-json --output-format stream-json`.
|
|
53
|
+
|
|
54
|
+
## Roadmap
|
|
55
|
+
|
|
56
|
+
| Runtime | Status |
|
|
57
|
+
|---|---|
|
|
58
|
+
| Claude Code | ✅ shipped |
|
|
59
|
+
| Codex CLI (`codex mcp-server`, JSON-RPC) | ✅ shipped (`CodexSession`; `CodexAppServerSession` experimental) |
|
|
60
|
+
| Gemini CLI | planned |
|
|
61
|
+
| Grok CLI | planned (when its headless/stream mode matures) |
|
|
62
|
+
|
|
63
|
+
Opaque runtimes degrade gracefully — fewer event types, never a hard failure.
|
|
64
|
+
|
|
65
|
+
## Provenance
|
|
66
|
+
|
|
67
|
+
Extracted from [`inixiative/foundry`](https://github.com/inixiative/foundry),
|
|
68
|
+
where this drives the Artificer session. Consumed by foundry, foundry-oracle,
|
|
69
|
+
and the inixiative bench.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inixiative/agent-session",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drive coding-agent CLIs as persistent, streaming, event-captured sessions. Claude Code and Codex today; Gemini, Grok planned.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"files": ["src"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"typecheck": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"claude-code", "codex", "agent", "session", "stream", "stream-json",
|
|
17
|
+
"ai", "cli", "sandbox", "harness", "eval"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/bun": "latest",
|
|
22
|
+
"typescript": "^5.7.0"
|
|
23
|
+
}
|
|
24
|
+
}
|