@alpacakit/agents 0.1.0-beta.19
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/LICENSE +21 -0
- package/README.md +224 -0
- package/dist/agents/builtin.d.ts +19 -0
- package/dist/agents/builtin.d.ts.map +1 -0
- package/dist/agents/builtin.js +14 -0
- package/dist/agents/claude.d.ts +20 -0
- package/dist/agents/claude.d.ts.map +1 -0
- package/dist/agents/claude.js +480 -0
- package/dist/agents/codex.d.ts +19 -0
- package/dist/agents/codex.d.ts.map +1 -0
- package/dist/agents/codex.js +355 -0
- package/dist/agents/openai-compatible/config.d.ts +16 -0
- package/dist/agents/openai-compatible/config.d.ts.map +1 -0
- package/dist/agents/openai-compatible/config.js +160 -0
- package/dist/agents/openai-compatible/engine.d.ts +18 -0
- package/dist/agents/openai-compatible/engine.d.ts.map +1 -0
- package/dist/agents/openai-compatible/engine.js +10 -0
- package/dist/agents/openai-compatible/fetch-engine.d.ts +38 -0
- package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -0
- package/dist/agents/openai-compatible/fetch-engine.js +216 -0
- package/dist/agents/openai-compatible/pi/engine.d.ts +32 -0
- package/dist/agents/openai-compatible/pi/engine.d.ts.map +1 -0
- package/dist/agents/openai-compatible/pi/engine.js +98 -0
- package/dist/agents/openai-compatible/pi/module.d.ts +87 -0
- package/dist/agents/openai-compatible/pi/module.d.ts.map +1 -0
- package/dist/agents/openai-compatible/pi/module.js +43 -0
- package/dist/agents/openai-compatible/pi/sandbox.d.ts +25 -0
- package/dist/agents/openai-compatible/pi/sandbox.d.ts.map +1 -0
- package/dist/agents/openai-compatible/pi/sandbox.js +69 -0
- package/dist/agents/openai-compatible/pi/session.d.ts +17 -0
- package/dist/agents/openai-compatible/pi/session.d.ts.map +1 -0
- package/dist/agents/openai-compatible/pi/session.js +354 -0
- package/dist/agents/openai-compatible/response.d.ts +19 -0
- package/dist/agents/openai-compatible/response.d.ts.map +1 -0
- package/dist/agents/openai-compatible/response.js +203 -0
- package/dist/agents/openai-compatible/types.d.ts +34 -0
- package/dist/agents/openai-compatible/types.d.ts.map +1 -0
- package/dist/agents/openai-compatible/types.js +1 -0
- package/dist/agents/openai-compatible.d.ts +12 -0
- package/dist/agents/openai-compatible.d.ts.map +1 -0
- package/dist/agents/openai-compatible.js +45 -0
- package/dist/auth/login-probe.d.ts +21 -0
- package/dist/auth/login-probe.d.ts.map +1 -0
- package/dist/auth/login-probe.js +47 -0
- package/dist/auth/login.d.ts +79 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +9 -0
- package/dist/auth/material.d.ts +87 -0
- package/dist/auth/material.d.ts.map +1 -0
- package/dist/auth/material.js +59 -0
- package/dist/auth/profile-store.d.ts +14 -0
- package/dist/auth/profile-store.d.ts.map +1 -0
- package/dist/auth/profile-store.js +101 -0
- package/dist/auth/secrets.d.ts +14 -0
- package/dist/auth/secrets.d.ts.map +1 -0
- package/dist/auth/secrets.js +40 -0
- package/dist/codex/app-server.d.ts +30 -0
- package/dist/codex/app-server.d.ts.map +1 -0
- package/dist/codex/app-server.js +322 -0
- package/dist/codex/index.d.ts +3 -0
- package/dist/codex/index.d.ts.map +1 -0
- package/dist/codex/index.js +1 -0
- package/dist/codex/protocol.d.ts +124 -0
- package/dist/codex/protocol.d.ts.map +1 -0
- package/dist/codex/protocol.js +283 -0
- package/dist/config/agent-config-validation.d.ts +22 -0
- package/dist/config/agent-config-validation.d.ts.map +1 -0
- package/dist/config/agent-config-validation.js +31 -0
- package/dist/config/agent-configs.d.ts +37 -0
- package/dist/config/agent-configs.d.ts.map +1 -0
- package/dist/config/agent-configs.js +214 -0
- package/dist/config/compose.d.ts +10 -0
- package/dist/config/compose.d.ts.map +1 -0
- package/dist/config/compose.js +89 -0
- package/dist/config/config.d.ts +21 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +33 -0
- package/dist/config/errors.d.ts +45 -0
- package/dist/config/errors.d.ts.map +1 -0
- package/dist/config/errors.js +37 -0
- package/dist/config/extension.d.ts +3 -0
- package/dist/config/extension.d.ts.map +1 -0
- package/dist/config/extension.js +1 -0
- package/dist/config/ids.d.ts +8 -0
- package/dist/config/ids.d.ts.map +1 -0
- package/dist/config/ids.js +4 -0
- package/dist/config/index.d.ts +12 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/model.d.ts +105 -0
- package/dist/config/model.d.ts.map +1 -0
- package/dist/config/model.js +1 -0
- package/dist/config/paths.d.ts +7 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +10 -0
- package/dist/config/schema.d.ts +59 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +83 -0
- package/dist/config/store.d.ts +34 -0
- package/dist/config/store.d.ts.map +1 -0
- package/dist/config/store.js +420 -0
- package/dist/config/support.d.ts +14 -0
- package/dist/config/support.d.ts.map +1 -0
- package/dist/config/support.js +32 -0
- package/dist/config/values.d.ts +21 -0
- package/dist/config/values.d.ts.map +1 -0
- package/dist/config/values.js +22 -0
- package/dist/config/xdg.d.ts +20 -0
- package/dist/config/xdg.d.ts.map +1 -0
- package/dist/config/xdg.js +23 -0
- package/dist/core/async-queue.d.ts +14 -0
- package/dist/core/async-queue.d.ts.map +1 -0
- package/dist/core/async-queue.js +46 -0
- package/dist/core/env.d.ts +19 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/env.js +39 -0
- package/dist/core/error.d.ts +121 -0
- package/dist/core/error.d.ts.map +1 -0
- package/dist/core/error.js +88 -0
- package/dist/core/fs.d.ts +16 -0
- package/dist/core/fs.d.ts.map +1 -0
- package/dist/core/fs.js +30 -0
- package/dist/core/json.d.ts +20 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +42 -0
- package/dist/core/node-ports.d.ts +9 -0
- package/dist/core/node-ports.d.ts.map +1 -0
- package/dist/core/node-ports.js +135 -0
- package/dist/core/ports.d.ts +71 -0
- package/dist/core/ports.d.ts.map +1 -0
- package/dist/core/ports.js +19 -0
- package/dist/core/redact.d.ts +8 -0
- package/dist/core/redact.d.ts.map +1 -0
- package/dist/core/redact.js +66 -0
- package/dist/core/run.d.ts +125 -0
- package/dist/core/run.d.ts.map +1 -0
- package/dist/core/run.js +27 -0
- package/dist/core/values.d.ts +12 -0
- package/dist/core/values.d.ts.map +1 -0
- package/dist/core/values.js +9 -0
- package/dist/corpus/failure-corpus.d.ts +21 -0
- package/dist/corpus/failure-corpus.d.ts.map +1 -0
- package/dist/corpus/failure-corpus.js +89 -0
- package/dist/fleet/fleet.d.ts +120 -0
- package/dist/fleet/fleet.d.ts.map +1 -0
- package/dist/fleet/fleet.js +409 -0
- package/dist/fleet/policy.d.ts +45 -0
- package/dist/fleet/policy.d.ts.map +1 -0
- package/dist/fleet/policy.js +50 -0
- package/dist/fleet/store.d.ts +28 -0
- package/dist/fleet/store.d.ts.map +1 -0
- package/dist/fleet/store.js +225 -0
- package/dist/host/capabilities.d.ts +146 -0
- package/dist/host/capabilities.d.ts.map +1 -0
- package/dist/host/capabilities.js +59 -0
- package/dist/host/context.d.ts +29 -0
- package/dist/host/context.d.ts.map +1 -0
- package/dist/host/context.js +11 -0
- package/dist/host/github-dir.d.ts +16 -0
- package/dist/host/github-dir.d.ts.map +1 -0
- package/dist/host/github-dir.js +164 -0
- package/dist/host/mcp-list.d.ts +12 -0
- package/dist/host/mcp-list.d.ts.map +1 -0
- package/dist/host/mcp-list.js +122 -0
- package/dist/host/requirement-ref.d.ts +12 -0
- package/dist/host/requirement-ref.d.ts.map +1 -0
- package/dist/host/requirement-ref.js +40 -0
- package/dist/host/run-command.d.ts +27 -0
- package/dist/host/run-command.d.ts.map +1 -0
- package/dist/host/run-command.js +66 -0
- package/dist/host/validate-spec.d.ts +10 -0
- package/dist/host/validate-spec.d.ts.map +1 -0
- package/dist/host/validate-spec.js +69 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/kernel/classify.d.ts +44 -0
- package/dist/kernel/classify.d.ts.map +1 -0
- package/dist/kernel/classify.js +136 -0
- package/dist/kernel/cli-agent.d.ts +62 -0
- package/dist/kernel/cli-agent.d.ts.map +1 -0
- package/dist/kernel/cli-agent.js +281 -0
- package/dist/kernel/cli-login.d.ts +13 -0
- package/dist/kernel/cli-login.d.ts.map +1 -0
- package/dist/kernel/cli-login.js +199 -0
- package/dist/kernel/definition.d.ts +41 -0
- package/dist/kernel/definition.d.ts.map +1 -0
- package/dist/kernel/definition.js +13 -0
- package/dist/kernel/env-template.d.ts +17 -0
- package/dist/kernel/env-template.d.ts.map +1 -0
- package/dist/kernel/env-template.js +78 -0
- package/dist/kernel/facets.d.ts +58 -0
- package/dist/kernel/facets.d.ts.map +1 -0
- package/dist/kernel/facets.js +102 -0
- package/dist/kernel/guard.d.ts +24 -0
- package/dist/kernel/guard.d.ts.map +1 -0
- package/dist/kernel/guard.js +69 -0
- package/dist/kernel/handle.d.ts +29 -0
- package/dist/kernel/handle.d.ts.map +1 -0
- package/dist/kernel/handle.js +97 -0
- package/dist/kernel/keyed.d.ts +19 -0
- package/dist/kernel/keyed.d.ts.map +1 -0
- package/dist/kernel/keyed.js +35 -0
- package/dist/kernel/login.d.ts +20 -0
- package/dist/kernel/login.d.ts.map +1 -0
- package/dist/kernel/login.js +74 -0
- package/dist/kernel/options.d.ts +73 -0
- package/dist/kernel/options.d.ts.map +1 -0
- package/dist/kernel/options.js +41 -0
- package/dist/kernel/run.d.ts +20 -0
- package/dist/kernel/run.d.ts.map +1 -0
- package/dist/kernel/run.js +245 -0
- package/dist/kernel/runtime.d.ts +48 -0
- package/dist/kernel/runtime.d.ts.map +1 -0
- package/dist/kernel/runtime.js +108 -0
- package/dist/keyring/index.d.ts +2 -0
- package/dist/keyring/index.d.ts.map +1 -0
- package/dist/keyring/index.js +1 -0
- package/dist/keyring/resolver.d.ts +9 -0
- package/dist/keyring/resolver.d.ts.map +1 -0
- package/dist/keyring/resolver.js +62 -0
- package/dist/run-agent.d.ts +19 -0
- package/dist/run-agent.d.ts.map +1 -0
- package/dist/run-agent.js +25 -0
- package/dist/structured/extract.d.ts +27 -0
- package/dist/structured/extract.d.ts.map +1 -0
- package/dist/structured/extract.js +188 -0
- package/dist/structured/run-structured.d.ts +83 -0
- package/dist/structured/run-structured.d.ts.map +1 -0
- package/dist/structured/run-structured.js +202 -0
- package/dist/structured/standard-schema.d.ts +34 -0
- package/dist/structured/standard-schema.d.ts.map +1 -0
- package/dist/structured/standard-schema.js +6 -0
- package/dist/testing/fake-agent.d.ts +32 -0
- package/dist/testing/fake-agent.d.ts.map +1 -0
- package/dist/testing/fake-agent.js +43 -0
- package/dist/testing/fake-clock.d.ts +8 -0
- package/dist/testing/fake-clock.d.ts.map +1 -0
- package/dist/testing/fake-clock.js +44 -0
- package/dist/testing/fake-exec.d.ts +26 -0
- package/dist/testing/fake-exec.d.ts.map +1 -0
- package/dist/testing/fake-exec.js +69 -0
- package/dist/testing/fake-secrets.d.ts +3 -0
- package/dist/testing/fake-secrets.d.ts.map +1 -0
- package/dist/testing/fake-secrets.js +5 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +9 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Masahiro Tonomura (codemafia0000)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# @alpacakit/agents
|
|
2
|
+
|
|
3
|
+
Run AI coding agents programmatically: execute claude / codex / custom
|
|
4
|
+
agents against a working directory, stream their output, classify
|
|
5
|
+
failures, fail over across credentials and agents.
|
|
6
|
+
|
|
7
|
+
Design: [`src/v2/design/l_agents_library.md`](https://github.com/alpacakit/alpacaloop/blob/main/src/v2/design/l_agents_library.md).
|
|
8
|
+
|
|
9
|
+
The whole runtime surface — including extension points — ships from one
|
|
10
|
+
root entry. Only genuine isolation lives on a subpath: dev fakes
|
|
11
|
+
(`/testing`), the codex app-server client (`/codex`), the native keyring
|
|
12
|
+
(`/keyring`), and machine-local config storage (`/config`).
|
|
13
|
+
|
|
14
|
+
Most apps need only a handful of root exports: `runAgent`,
|
|
15
|
+
`createAgentRuntime`, `processEnv`, the built-in `claude` / `codex`
|
|
16
|
+
factories, `openaiCompatible`, `createFleet`, `candidateFromProfile` /
|
|
17
|
+
`candidateForAgent`, `createHomeDirProfile` / `createApiKeyProfile`, and
|
|
18
|
+
`AgentError` / `isAgentError`. Everything else on the root entry is an
|
|
19
|
+
extension point (custom agents, guards, auth materials, host facets) you
|
|
20
|
+
reach for only when extending the runtime.
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { runAgent } from "@alpacakit/agents";
|
|
26
|
+
|
|
27
|
+
const { text } = await runAgent({
|
|
28
|
+
agent: "claude", // or "codex"
|
|
29
|
+
workspace: "/work/repo",
|
|
30
|
+
prompt: "Summarize the failing tests.",
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`runAgent` is the minimal-persona sugar: it reads `process.env` by
|
|
35
|
+
default and applies a documented 1-hour total timeout.
|
|
36
|
+
|
|
37
|
+
## Runtime, streaming, and limits
|
|
38
|
+
|
|
39
|
+
`createAgentRuntime` never reads `process.env` implicitly, so `baseEnv`
|
|
40
|
+
is a **required** argument — omitting it can no longer silently produce an
|
|
41
|
+
empty env that fails auth at run time. Pass the exported `processEnv()`
|
|
42
|
+
snapshot for the ambient environment, or `{}` for a hermetic run.
|
|
43
|
+
(`runAgent` above is the only entry that defaults `baseEnv` to
|
|
44
|
+
`processEnv()`.)
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import {
|
|
48
|
+
createAgentRuntime,
|
|
49
|
+
claude,
|
|
50
|
+
maxToolCalls,
|
|
51
|
+
processEnv,
|
|
52
|
+
} from "@alpacakit/agents";
|
|
53
|
+
|
|
54
|
+
const runtime = createAgentRuntime({ agents: [claude()], baseEnv: processEnv() });
|
|
55
|
+
const handle = runtime.agent("claude").run({
|
|
56
|
+
prompt,
|
|
57
|
+
workspace,
|
|
58
|
+
sandbox: { mode: "read-only", grants: [{ kind: "shell", command: "git status" }] },
|
|
59
|
+
limits: { totalMs: 600_000, idleMs: 120_000, guards: [maxToolCalls(120)] },
|
|
60
|
+
signal: controller.signal,
|
|
61
|
+
});
|
|
62
|
+
for await (const event of handle.events) {
|
|
63
|
+
// started / output / message / turn / tool / trace / ended
|
|
64
|
+
}
|
|
65
|
+
const result = await handle; // await handle === await handle.result
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Structured output
|
|
69
|
+
|
|
70
|
+
Any Standard Schema validator (zod v4 etc.) works. Repair happens within
|
|
71
|
+
one structured run handle; an exhausted budget throws `AgentError` with
|
|
72
|
+
`output_rejected`.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const { output } = await runtime.agent("claude").run({
|
|
76
|
+
prompt,
|
|
77
|
+
workspace,
|
|
78
|
+
contract: { schema: hintListSchema },
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`agent.run({ ..., contract })` returns an awaitable handle: `await` it
|
|
83
|
+
for the result, or iterate `.events` to stream every repair attempt's run
|
|
84
|
+
events as they happen (`for await (const event of handle.events) …`).
|
|
85
|
+
|
|
86
|
+
## Failover across credentials and agents
|
|
87
|
+
|
|
88
|
+
`fleet.run` runs the same raw or structured run options across ordered
|
|
89
|
+
candidates. Each attempt is candidate-bound: auth env, model / effort
|
|
90
|
+
defaults, and the linked abort signal are already folded in.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import {
|
|
94
|
+
candidateFromProfile,
|
|
95
|
+
createFleet,
|
|
96
|
+
createHomeDirProfile,
|
|
97
|
+
fileFleetStore,
|
|
98
|
+
} from "@alpacakit/agents";
|
|
99
|
+
|
|
100
|
+
const codexProfile = createHomeDirProfile({
|
|
101
|
+
id: "codex-work",
|
|
102
|
+
agentId: "codex",
|
|
103
|
+
path: "/home/me/.codex",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const fleet = createFleet({ runtime, store: fileFleetStore(statePath) });
|
|
107
|
+
const outcome = await fleet.run({
|
|
108
|
+
candidates: [candidateFromProfile(codexProfile, { model: "gpt-5" })],
|
|
109
|
+
runOptions: { ...options, contract },
|
|
110
|
+
});
|
|
111
|
+
if (outcome.status === "deferred") schedule(outcome.earliestRetryAt);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## OpenAI-compatible and custom agents
|
|
115
|
+
|
|
116
|
+
`openaiCompatible` needs only `id` / `baseUrl` / `model`; `apiKey`,
|
|
117
|
+
`headers`, and `requestParams` default to absent. Any field may be an
|
|
118
|
+
`${ENV_VAR}` template resolved against `baseEnv`.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { createAgentRuntime, openaiCompatible } from "@alpacakit/agents";
|
|
122
|
+
|
|
123
|
+
const runtime = createAgentRuntime({
|
|
124
|
+
agents: [openaiCompatible({ id: "ollama", baseUrl: "http://localhost:11434/v1", model: "llama3.1" })],
|
|
125
|
+
baseEnv: processEnv(),
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Add a whole new CLI agent with `defineCliAgent` (sandbox argv, line
|
|
130
|
+
parsing, auth materials, and failure matchers are all keyed records — no
|
|
131
|
+
`if`), or wrap any executor with `defineAgent`.
|
|
132
|
+
|
|
133
|
+
## Machine-local config (`@alpacakit/agents/config`)
|
|
134
|
+
|
|
135
|
+
`@alpacakit/agents/config` persists auth profiles, agent settings, and
|
|
136
|
+
fleet state, then projects them into runtime primitives. It is
|
|
137
|
+
convention-neutral: it never reads env or picks a home directory — the app
|
|
138
|
+
supplies `rootDir` (and any secret resolvers) and wires the runtime.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { createAgentRuntime, createFleet, processEnv } from "@alpacakit/agents";
|
|
142
|
+
import {
|
|
143
|
+
candidatesForFleet,
|
|
144
|
+
loadAgentsRuntimeConfig,
|
|
145
|
+
secretsForRuntime,
|
|
146
|
+
} from "@alpacakit/agents/config";
|
|
147
|
+
|
|
148
|
+
const config = await loadAgentsRuntimeConfig({ rootDir });
|
|
149
|
+
const runtime = createAgentRuntime({
|
|
150
|
+
agents: config.agents,
|
|
151
|
+
ports: { secrets: secretsForRuntime(config) },
|
|
152
|
+
baseEnv: processEnv(),
|
|
153
|
+
});
|
|
154
|
+
const fleet = createFleet({ runtime, store: config.fleetStateStore });
|
|
155
|
+
const outcome = await fleet.run({
|
|
156
|
+
candidates: candidatesForFleet(config),
|
|
157
|
+
attempt: (agent) => agent.run({ prompt, workspace }),
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Register profiles and agent configs with plain string ids — no id
|
|
162
|
+
factory to call:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { openAgentsConfig, openAiCompatibleAgentConfig } from "@alpacakit/agents/config";
|
|
166
|
+
|
|
167
|
+
const home = openAgentsConfig({ rootDir });
|
|
168
|
+
await home.profiles.addHomeDir({ id: "codex-main", agentId: "codex", path: "/home/me/.codex" });
|
|
169
|
+
await home.agentConfigs.add(
|
|
170
|
+
openAiCompatibleAgentConfig({ id: "ollama", baseUrl: "http://localhost:11434/v1", model: "llama3.1" }),
|
|
171
|
+
);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Operator note: `config.candidates` also carries `source` provenance
|
|
175
|
+
(which agent-config / profile produced each candidate) for control-plane
|
|
176
|
+
bookkeeping; `candidatesForFleet` drops it for the common fleet path.
|
|
177
|
+
|
|
178
|
+
The root config API is convention-neutral — the app supplies `rootDir`.
|
|
179
|
+
For the common case, `@alpacakit/agents/config/xdg` resolves it from the
|
|
180
|
+
XDG spec (`$XDG_CONFIG_HOME/<appName>/agents`):
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { resolveXdgAgentsConfigOptions } from "@alpacakit/agents/config/xdg";
|
|
184
|
+
|
|
185
|
+
const config = await loadAgentsRuntimeConfig(
|
|
186
|
+
resolveXdgAgentsConfigOptions({ appName: "acme", homeDir: os.homedir(), env: process.env }),
|
|
187
|
+
);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Family-specific conventions (a fixed path env var + a keyring service)
|
|
191
|
+
belong in the consumer's own convention module, not in this package — they
|
|
192
|
+
are a plain instance of the same preset shape.
|
|
193
|
+
|
|
194
|
+
## Host plane: skills & MCP (operator)
|
|
195
|
+
|
|
196
|
+
Agents expose optional `agent.skills` / `agent.mcp` / `agent.doctor`
|
|
197
|
+
facets for provisioning and health checks. This surface is still
|
|
198
|
+
aspirational: the first slice covers Claude local-dir skills and
|
|
199
|
+
Claude / Codex stdio MCP registration; broad inventory and availability
|
|
200
|
+
listing are in progress.
|
|
201
|
+
|
|
202
|
+
## Package entries
|
|
203
|
+
|
|
204
|
+
| Entry | Contents |
|
|
205
|
+
|---|---|
|
|
206
|
+
| `.` | runtime, fleet, structured output, auth materials, guards, errors, and every extension point |
|
|
207
|
+
| `/config` | machine-local profile / agent-settings / fleet-state storage |
|
|
208
|
+
| `/config/xdg` | XDG Base Directory config-root preset (general apps) |
|
|
209
|
+
| `/config/extension` | custom agent-config kinds (`defineAgentConfigType`) |
|
|
210
|
+
| `/testing` | `fakeExec`, `fakeClock`, `fakeAgent`, `fakeSecretResolver` — no subprocess ever spawns |
|
|
211
|
+
| `/codex` | codex app-server JSON-RPC client (advanced) |
|
|
212
|
+
| `/keyring` | `keyringResolver` (loads the optional `@napi-rs/keyring` peer) |
|
|
213
|
+
|
|
214
|
+
## Status
|
|
215
|
+
|
|
216
|
+
Implemented: kernel (runtime, run handle, guards, classification), CLI
|
|
217
|
+
blueprint with built-in `claude()` / `codex()`, structured output with
|
|
218
|
+
repair, fleet with cooldown / auth-mark stores, auth materials and secret
|
|
219
|
+
resolvers, `openaiCompatible` (engine port; the built-in HTTP
|
|
220
|
+
chat-completions engine is the dependency-free default), and the first
|
|
221
|
+
host-plane skill / MCP implementations (Claude local-dir skills plus
|
|
222
|
+
Claude / Codex stdio MCP registration). Not yet implemented: the
|
|
223
|
+
in-process pi-session engine for `openaiCompatible`, GitHub / plugin skill
|
|
224
|
+
installers, and availability listing for installed skills / MCP servers.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in agent registry: a single source of truth for the two
|
|
3
|
+
* bundled agent ids and their factories. `runAgent` binds them by id, and
|
|
4
|
+
* the config layer reuses `BUILTIN_AGENT_ID` for its agent-config kinds —
|
|
5
|
+
* so "codex"/"claude" is spelled once, not once per layer.
|
|
6
|
+
*/
|
|
7
|
+
import { claude } from "./claude.js";
|
|
8
|
+
import { codex } from "./codex.js";
|
|
9
|
+
export declare const BUILTIN_AGENT_ID: {
|
|
10
|
+
readonly codex: "codex";
|
|
11
|
+
readonly claude: "claude";
|
|
12
|
+
};
|
|
13
|
+
export type BuiltinAgentId = (typeof BUILTIN_AGENT_ID)[keyof typeof BUILTIN_AGENT_ID];
|
|
14
|
+
/** Keyed record, not a branch: adding a built-in is adding an entry. */
|
|
15
|
+
export declare const builtinAgentFactories: {
|
|
16
|
+
readonly claude: typeof claude;
|
|
17
|
+
readonly codex: typeof codex;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=builtin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtin.d.ts","sourceRoot":"","sources":["../../src/agents/builtin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,wEAAwE;AACxE,eAAO,MAAM,qBAAqB;;;CAA6B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in agent registry: a single source of truth for the two
|
|
3
|
+
* bundled agent ids and their factories. `runAgent` binds them by id, and
|
|
4
|
+
* the config layer reuses `BUILTIN_AGENT_ID` for its agent-config kinds —
|
|
5
|
+
* so "codex"/"claude" is spelled once, not once per layer.
|
|
6
|
+
*/
|
|
7
|
+
import { claude } from "./claude.js";
|
|
8
|
+
import { codex } from "./codex.js";
|
|
9
|
+
export const BUILTIN_AGENT_ID = {
|
|
10
|
+
codex: "codex",
|
|
11
|
+
claude: "claude",
|
|
12
|
+
};
|
|
13
|
+
/** Keyed record, not a branch: adding a built-in is adding an entry. */
|
|
14
|
+
export const builtinAgentFactories = { claude, codex };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in claude adapter (v1 E1/E2 argv kept verbatim):
|
|
3
|
+
* `claude -p [--model m] [--effort e] --output-format stream-json
|
|
4
|
+
* --permission-mode <mode> [tool args] --verbose`, prompt on stdin.
|
|
5
|
+
* Read-only grants map to `--allowedTools` (`Bash(cmd:*)` for shell
|
|
6
|
+
* grants, the bare tool name otherwise); no grants means `--tools ""`.
|
|
7
|
+
*/
|
|
8
|
+
import { type FailureMatcher } from "../kernel/classify.js";
|
|
9
|
+
import type { AgentDefinition } from "../kernel/definition.js";
|
|
10
|
+
export declare const CLAUDE_CONFIG_DIR_ENV_VAR = "CLAUDE_CONFIG_DIR";
|
|
11
|
+
export declare const CLAUDE_API_KEY_ENV_VAR = "ANTHROPIC_API_KEY";
|
|
12
|
+
/**
|
|
13
|
+
* Structured quota signals in Claude CLI NDJSON output (v1 F2), scanned
|
|
14
|
+
* per line: rate_limit_event rejected (with resetsAt), api_error_status
|
|
15
|
+
* 429, and error === "rate_limit". Exported for custom agents that speak
|
|
16
|
+
* the same stream format.
|
|
17
|
+
*/
|
|
18
|
+
export declare function structuredQuotaMatcher(): FailureMatcher;
|
|
19
|
+
export declare function claude(): AgentDefinition<"claude">;
|
|
20
|
+
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/agents/claude.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6CH,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,eAAO,MAAM,yBAAyB,sBAAsB,CAAC;AAC7D,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAwJ1D;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,cAAc,CA0CvD;AA8RD,wBAAgB,MAAM,IAAI,eAAe,CAAC,QAAQ,CAAC,CAyDlD"}
|