@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.
Files changed (249) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +224 -0
  3. package/dist/agents/builtin.d.ts +19 -0
  4. package/dist/agents/builtin.d.ts.map +1 -0
  5. package/dist/agents/builtin.js +14 -0
  6. package/dist/agents/claude.d.ts +20 -0
  7. package/dist/agents/claude.d.ts.map +1 -0
  8. package/dist/agents/claude.js +480 -0
  9. package/dist/agents/codex.d.ts +19 -0
  10. package/dist/agents/codex.d.ts.map +1 -0
  11. package/dist/agents/codex.js +355 -0
  12. package/dist/agents/openai-compatible/config.d.ts +16 -0
  13. package/dist/agents/openai-compatible/config.d.ts.map +1 -0
  14. package/dist/agents/openai-compatible/config.js +160 -0
  15. package/dist/agents/openai-compatible/engine.d.ts +18 -0
  16. package/dist/agents/openai-compatible/engine.d.ts.map +1 -0
  17. package/dist/agents/openai-compatible/engine.js +10 -0
  18. package/dist/agents/openai-compatible/fetch-engine.d.ts +38 -0
  19. package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -0
  20. package/dist/agents/openai-compatible/fetch-engine.js +216 -0
  21. package/dist/agents/openai-compatible/pi/engine.d.ts +32 -0
  22. package/dist/agents/openai-compatible/pi/engine.d.ts.map +1 -0
  23. package/dist/agents/openai-compatible/pi/engine.js +98 -0
  24. package/dist/agents/openai-compatible/pi/module.d.ts +87 -0
  25. package/dist/agents/openai-compatible/pi/module.d.ts.map +1 -0
  26. package/dist/agents/openai-compatible/pi/module.js +43 -0
  27. package/dist/agents/openai-compatible/pi/sandbox.d.ts +25 -0
  28. package/dist/agents/openai-compatible/pi/sandbox.d.ts.map +1 -0
  29. package/dist/agents/openai-compatible/pi/sandbox.js +69 -0
  30. package/dist/agents/openai-compatible/pi/session.d.ts +17 -0
  31. package/dist/agents/openai-compatible/pi/session.d.ts.map +1 -0
  32. package/dist/agents/openai-compatible/pi/session.js +354 -0
  33. package/dist/agents/openai-compatible/response.d.ts +19 -0
  34. package/dist/agents/openai-compatible/response.d.ts.map +1 -0
  35. package/dist/agents/openai-compatible/response.js +203 -0
  36. package/dist/agents/openai-compatible/types.d.ts +34 -0
  37. package/dist/agents/openai-compatible/types.d.ts.map +1 -0
  38. package/dist/agents/openai-compatible/types.js +1 -0
  39. package/dist/agents/openai-compatible.d.ts +12 -0
  40. package/dist/agents/openai-compatible.d.ts.map +1 -0
  41. package/dist/agents/openai-compatible.js +45 -0
  42. package/dist/auth/login-probe.d.ts +21 -0
  43. package/dist/auth/login-probe.d.ts.map +1 -0
  44. package/dist/auth/login-probe.js +47 -0
  45. package/dist/auth/login.d.ts +79 -0
  46. package/dist/auth/login.d.ts.map +1 -0
  47. package/dist/auth/login.js +9 -0
  48. package/dist/auth/material.d.ts +87 -0
  49. package/dist/auth/material.d.ts.map +1 -0
  50. package/dist/auth/material.js +59 -0
  51. package/dist/auth/profile-store.d.ts +14 -0
  52. package/dist/auth/profile-store.d.ts.map +1 -0
  53. package/dist/auth/profile-store.js +101 -0
  54. package/dist/auth/secrets.d.ts +14 -0
  55. package/dist/auth/secrets.d.ts.map +1 -0
  56. package/dist/auth/secrets.js +40 -0
  57. package/dist/codex/app-server.d.ts +30 -0
  58. package/dist/codex/app-server.d.ts.map +1 -0
  59. package/dist/codex/app-server.js +322 -0
  60. package/dist/codex/index.d.ts +3 -0
  61. package/dist/codex/index.d.ts.map +1 -0
  62. package/dist/codex/index.js +1 -0
  63. package/dist/codex/protocol.d.ts +124 -0
  64. package/dist/codex/protocol.d.ts.map +1 -0
  65. package/dist/codex/protocol.js +283 -0
  66. package/dist/config/agent-config-validation.d.ts +22 -0
  67. package/dist/config/agent-config-validation.d.ts.map +1 -0
  68. package/dist/config/agent-config-validation.js +31 -0
  69. package/dist/config/agent-configs.d.ts +37 -0
  70. package/dist/config/agent-configs.d.ts.map +1 -0
  71. package/dist/config/agent-configs.js +214 -0
  72. package/dist/config/compose.d.ts +10 -0
  73. package/dist/config/compose.d.ts.map +1 -0
  74. package/dist/config/compose.js +89 -0
  75. package/dist/config/config.d.ts +21 -0
  76. package/dist/config/config.d.ts.map +1 -0
  77. package/dist/config/config.js +33 -0
  78. package/dist/config/errors.d.ts +45 -0
  79. package/dist/config/errors.d.ts.map +1 -0
  80. package/dist/config/errors.js +37 -0
  81. package/dist/config/extension.d.ts +3 -0
  82. package/dist/config/extension.d.ts.map +1 -0
  83. package/dist/config/extension.js +1 -0
  84. package/dist/config/ids.d.ts +8 -0
  85. package/dist/config/ids.d.ts.map +1 -0
  86. package/dist/config/ids.js +4 -0
  87. package/dist/config/index.d.ts +12 -0
  88. package/dist/config/index.d.ts.map +1 -0
  89. package/dist/config/index.js +6 -0
  90. package/dist/config/model.d.ts +105 -0
  91. package/dist/config/model.d.ts.map +1 -0
  92. package/dist/config/model.js +1 -0
  93. package/dist/config/paths.d.ts +7 -0
  94. package/dist/config/paths.d.ts.map +1 -0
  95. package/dist/config/paths.js +10 -0
  96. package/dist/config/schema.d.ts +59 -0
  97. package/dist/config/schema.d.ts.map +1 -0
  98. package/dist/config/schema.js +83 -0
  99. package/dist/config/store.d.ts +34 -0
  100. package/dist/config/store.d.ts.map +1 -0
  101. package/dist/config/store.js +420 -0
  102. package/dist/config/support.d.ts +14 -0
  103. package/dist/config/support.d.ts.map +1 -0
  104. package/dist/config/support.js +32 -0
  105. package/dist/config/values.d.ts +21 -0
  106. package/dist/config/values.d.ts.map +1 -0
  107. package/dist/config/values.js +22 -0
  108. package/dist/config/xdg.d.ts +20 -0
  109. package/dist/config/xdg.d.ts.map +1 -0
  110. package/dist/config/xdg.js +23 -0
  111. package/dist/core/async-queue.d.ts +14 -0
  112. package/dist/core/async-queue.d.ts.map +1 -0
  113. package/dist/core/async-queue.js +46 -0
  114. package/dist/core/env.d.ts +19 -0
  115. package/dist/core/env.d.ts.map +1 -0
  116. package/dist/core/env.js +39 -0
  117. package/dist/core/error.d.ts +121 -0
  118. package/dist/core/error.d.ts.map +1 -0
  119. package/dist/core/error.js +88 -0
  120. package/dist/core/fs.d.ts +16 -0
  121. package/dist/core/fs.d.ts.map +1 -0
  122. package/dist/core/fs.js +30 -0
  123. package/dist/core/json.d.ts +20 -0
  124. package/dist/core/json.d.ts.map +1 -0
  125. package/dist/core/json.js +42 -0
  126. package/dist/core/node-ports.d.ts +9 -0
  127. package/dist/core/node-ports.d.ts.map +1 -0
  128. package/dist/core/node-ports.js +135 -0
  129. package/dist/core/ports.d.ts +71 -0
  130. package/dist/core/ports.d.ts.map +1 -0
  131. package/dist/core/ports.js +19 -0
  132. package/dist/core/redact.d.ts +8 -0
  133. package/dist/core/redact.d.ts.map +1 -0
  134. package/dist/core/redact.js +66 -0
  135. package/dist/core/run.d.ts +125 -0
  136. package/dist/core/run.d.ts.map +1 -0
  137. package/dist/core/run.js +27 -0
  138. package/dist/core/values.d.ts +12 -0
  139. package/dist/core/values.d.ts.map +1 -0
  140. package/dist/core/values.js +9 -0
  141. package/dist/corpus/failure-corpus.d.ts +21 -0
  142. package/dist/corpus/failure-corpus.d.ts.map +1 -0
  143. package/dist/corpus/failure-corpus.js +89 -0
  144. package/dist/fleet/fleet.d.ts +120 -0
  145. package/dist/fleet/fleet.d.ts.map +1 -0
  146. package/dist/fleet/fleet.js +409 -0
  147. package/dist/fleet/policy.d.ts +45 -0
  148. package/dist/fleet/policy.d.ts.map +1 -0
  149. package/dist/fleet/policy.js +50 -0
  150. package/dist/fleet/store.d.ts +28 -0
  151. package/dist/fleet/store.d.ts.map +1 -0
  152. package/dist/fleet/store.js +225 -0
  153. package/dist/host/capabilities.d.ts +146 -0
  154. package/dist/host/capabilities.d.ts.map +1 -0
  155. package/dist/host/capabilities.js +59 -0
  156. package/dist/host/context.d.ts +29 -0
  157. package/dist/host/context.d.ts.map +1 -0
  158. package/dist/host/context.js +11 -0
  159. package/dist/host/github-dir.d.ts +16 -0
  160. package/dist/host/github-dir.d.ts.map +1 -0
  161. package/dist/host/github-dir.js +164 -0
  162. package/dist/host/mcp-list.d.ts +12 -0
  163. package/dist/host/mcp-list.d.ts.map +1 -0
  164. package/dist/host/mcp-list.js +122 -0
  165. package/dist/host/requirement-ref.d.ts +12 -0
  166. package/dist/host/requirement-ref.d.ts.map +1 -0
  167. package/dist/host/requirement-ref.js +40 -0
  168. package/dist/host/run-command.d.ts +27 -0
  169. package/dist/host/run-command.d.ts.map +1 -0
  170. package/dist/host/run-command.js +66 -0
  171. package/dist/host/validate-spec.d.ts +10 -0
  172. package/dist/host/validate-spec.d.ts.map +1 -0
  173. package/dist/host/validate-spec.js +69 -0
  174. package/dist/index.d.ts +69 -0
  175. package/dist/index.d.ts.map +1 -0
  176. package/dist/index.js +41 -0
  177. package/dist/kernel/classify.d.ts +44 -0
  178. package/dist/kernel/classify.d.ts.map +1 -0
  179. package/dist/kernel/classify.js +136 -0
  180. package/dist/kernel/cli-agent.d.ts +62 -0
  181. package/dist/kernel/cli-agent.d.ts.map +1 -0
  182. package/dist/kernel/cli-agent.js +281 -0
  183. package/dist/kernel/cli-login.d.ts +13 -0
  184. package/dist/kernel/cli-login.d.ts.map +1 -0
  185. package/dist/kernel/cli-login.js +199 -0
  186. package/dist/kernel/definition.d.ts +41 -0
  187. package/dist/kernel/definition.d.ts.map +1 -0
  188. package/dist/kernel/definition.js +13 -0
  189. package/dist/kernel/env-template.d.ts +17 -0
  190. package/dist/kernel/env-template.d.ts.map +1 -0
  191. package/dist/kernel/env-template.js +78 -0
  192. package/dist/kernel/facets.d.ts +58 -0
  193. package/dist/kernel/facets.d.ts.map +1 -0
  194. package/dist/kernel/facets.js +102 -0
  195. package/dist/kernel/guard.d.ts +24 -0
  196. package/dist/kernel/guard.d.ts.map +1 -0
  197. package/dist/kernel/guard.js +69 -0
  198. package/dist/kernel/handle.d.ts +29 -0
  199. package/dist/kernel/handle.d.ts.map +1 -0
  200. package/dist/kernel/handle.js +97 -0
  201. package/dist/kernel/keyed.d.ts +19 -0
  202. package/dist/kernel/keyed.d.ts.map +1 -0
  203. package/dist/kernel/keyed.js +35 -0
  204. package/dist/kernel/login.d.ts +20 -0
  205. package/dist/kernel/login.d.ts.map +1 -0
  206. package/dist/kernel/login.js +74 -0
  207. package/dist/kernel/options.d.ts +73 -0
  208. package/dist/kernel/options.d.ts.map +1 -0
  209. package/dist/kernel/options.js +41 -0
  210. package/dist/kernel/run.d.ts +20 -0
  211. package/dist/kernel/run.d.ts.map +1 -0
  212. package/dist/kernel/run.js +245 -0
  213. package/dist/kernel/runtime.d.ts +48 -0
  214. package/dist/kernel/runtime.d.ts.map +1 -0
  215. package/dist/kernel/runtime.js +108 -0
  216. package/dist/keyring/index.d.ts +2 -0
  217. package/dist/keyring/index.d.ts.map +1 -0
  218. package/dist/keyring/index.js +1 -0
  219. package/dist/keyring/resolver.d.ts +9 -0
  220. package/dist/keyring/resolver.d.ts.map +1 -0
  221. package/dist/keyring/resolver.js +62 -0
  222. package/dist/run-agent.d.ts +19 -0
  223. package/dist/run-agent.d.ts.map +1 -0
  224. package/dist/run-agent.js +25 -0
  225. package/dist/structured/extract.d.ts +27 -0
  226. package/dist/structured/extract.d.ts.map +1 -0
  227. package/dist/structured/extract.js +188 -0
  228. package/dist/structured/run-structured.d.ts +83 -0
  229. package/dist/structured/run-structured.d.ts.map +1 -0
  230. package/dist/structured/run-structured.js +202 -0
  231. package/dist/structured/standard-schema.d.ts +34 -0
  232. package/dist/structured/standard-schema.d.ts.map +1 -0
  233. package/dist/structured/standard-schema.js +6 -0
  234. package/dist/testing/fake-agent.d.ts +32 -0
  235. package/dist/testing/fake-agent.d.ts.map +1 -0
  236. package/dist/testing/fake-agent.js +43 -0
  237. package/dist/testing/fake-clock.d.ts +8 -0
  238. package/dist/testing/fake-clock.d.ts.map +1 -0
  239. package/dist/testing/fake-clock.js +44 -0
  240. package/dist/testing/fake-exec.d.ts +26 -0
  241. package/dist/testing/fake-exec.d.ts.map +1 -0
  242. package/dist/testing/fake-exec.js +69 -0
  243. package/dist/testing/fake-secrets.d.ts +3 -0
  244. package/dist/testing/fake-secrets.d.ts.map +1 -0
  245. package/dist/testing/fake-secrets.js +5 -0
  246. package/dist/testing/index.d.ts +10 -0
  247. package/dist/testing/index.d.ts.map +1 -0
  248. package/dist/testing/index.js +9 -0
  249. package/package.json +75 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Shared `mcp list` inventory: run the agent CLI with `--json`, parse the
3
+ * output into `McpServerState[]`. Parsing is tolerant of the shapes the
4
+ * claude/codex CLIs emit (array, `{servers: [...]}` or name-keyed maps),
5
+ * but non-JSON output is a typed failure, never a raw `SyntaxError`.
6
+ */
7
+ import { AGENT_ERROR_CODE, AgentError } from "../core/error.js";
8
+ import { readString, readUnknownRecord, } from "../core/json.js";
9
+ import { redactSecrets } from "../core/redact.js";
10
+ import { MCP_TRANSPORT } from "./capabilities.js";
11
+ import { runHostCommand } from "./run-command.js";
12
+ const OUTPUT_TAIL_CHARS = 2_000;
13
+ const MCP_LIST_ARGS = ["mcp", "list", "--json"];
14
+ const MCP_LIST_FIELD = {
15
+ name: "name",
16
+ servers: "servers",
17
+ state: "state",
18
+ status: "status",
19
+ tools: "tools",
20
+ transport: "transport",
21
+ usable: "usable",
22
+ };
23
+ function readMcpTools(record) {
24
+ const tools = record[MCP_LIST_FIELD.tools];
25
+ if (!Array.isArray(tools)) {
26
+ // The CLI did not enumerate tools; that is unknown, not "no tools".
27
+ return null;
28
+ }
29
+ return tools.flatMap((tool) => {
30
+ if (typeof tool === "string") {
31
+ return [tool];
32
+ }
33
+ const toolRecord = readUnknownRecord(tool);
34
+ const name = toolRecord === null ? null : readString(toolRecord, MCP_LIST_FIELD.name);
35
+ return name === null ? [] : [name];
36
+ });
37
+ }
38
+ function isMcpUsable(record) {
39
+ const usable = record[MCP_LIST_FIELD.usable];
40
+ if (typeof usable === "boolean") {
41
+ return usable;
42
+ }
43
+ const status = readString(record, MCP_LIST_FIELD.status) ??
44
+ readString(record, MCP_LIST_FIELD.state);
45
+ return status === null
46
+ ? true
47
+ : !/disabled|failed|error|unusable/iu.test(status);
48
+ }
49
+ function mcpStateFromRecord(name, record) {
50
+ const rawTransport = readString(record, MCP_LIST_FIELD.transport) ?? MCP_TRANSPORT.stdio;
51
+ if (rawTransport !== MCP_TRANSPORT.stdio &&
52
+ rawTransport !== MCP_TRANSPORT.http) {
53
+ // A transport outside the vocabulary would be misreported as stdio;
54
+ // skip the entry instead of inventing a state for it.
55
+ return null;
56
+ }
57
+ return {
58
+ name,
59
+ transport: rawTransport,
60
+ usable: isMcpUsable(record),
61
+ tools: readMcpTools(record),
62
+ };
63
+ }
64
+ function serverListFromEntries(entries) {
65
+ return entries.flatMap((entry) => {
66
+ const record = readUnknownRecord(entry);
67
+ if (record === null) {
68
+ return [];
69
+ }
70
+ const name = readString(record, MCP_LIST_FIELD.name);
71
+ if (name === null) {
72
+ return [];
73
+ }
74
+ const state = mcpStateFromRecord(name, record);
75
+ return state === null ? [] : [state];
76
+ });
77
+ }
78
+ function serverListFromValue(value) {
79
+ if (Array.isArray(value)) {
80
+ return serverListFromEntries(value);
81
+ }
82
+ const record = readUnknownRecord(value);
83
+ if (record === null) {
84
+ return [];
85
+ }
86
+ const servers = record[MCP_LIST_FIELD.servers];
87
+ if (Array.isArray(servers)) {
88
+ return serverListFromEntries(servers);
89
+ }
90
+ const namedServers = readUnknownRecord(servers) ?? record;
91
+ return Object.entries(namedServers).flatMap(([name, entry]) => {
92
+ const serverRecord = readUnknownRecord(entry);
93
+ if (serverRecord === null) {
94
+ return [];
95
+ }
96
+ const state = mcpStateFromRecord(name, serverRecord);
97
+ return state === null ? [] : [state];
98
+ });
99
+ }
100
+ export async function listMcpServersViaCli(ctx, input) {
101
+ const result = await runHostCommand(ctx, {
102
+ command: input.command,
103
+ args: [...MCP_LIST_ARGS],
104
+ });
105
+ let parsed;
106
+ try {
107
+ parsed = JSON.parse(result.stdout);
108
+ }
109
+ catch (error) {
110
+ throw new AgentError({
111
+ code: AGENT_ERROR_CODE.failed,
112
+ message: "MCP server list output is not valid JSON",
113
+ data: {
114
+ exitCode: result.exit.code,
115
+ stdoutTail: redactSecrets(result.stdout.slice(-OUTPUT_TAIL_CHARS)) || null,
116
+ stderrTail: result.stderr.slice(-OUTPUT_TAIL_CHARS) || null,
117
+ },
118
+ cause: error,
119
+ });
120
+ }
121
+ return serverListFromValue(parsed);
122
+ }
@@ -0,0 +1,12 @@
1
+ export type SkillRequirementRef = {
2
+ readonly agentId: string;
3
+ readonly skillId: string;
4
+ };
5
+ export type McpRequirementRef = {
6
+ readonly agentId: string;
7
+ readonly server: string;
8
+ readonly tool: string | null;
9
+ };
10
+ export declare function parseSkillRequirementRef(ref: string): SkillRequirementRef | null;
11
+ export declare function parseMcpRequirementRef(ref: string): McpRequirementRef | null;
12
+ //# sourceMappingURL=requirement-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirement-ref.d.ts","sourceRoot":"","sources":["../../src/host/requirement-ref.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAMF,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,GACV,mBAAmB,GAAG,IAAI,CAM5B;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAmB5E"}
@@ -0,0 +1,40 @@
1
+ const AGENT_TARGET_SEPARATOR = ":";
2
+ const MCP_TOOL_SEPARATOR = "/";
3
+ const EMPTY_REF_PART = "";
4
+ export function parseSkillRequirementRef(ref) {
5
+ const parts = splitAgentRef(ref);
6
+ if (parts === null || parts.target.includes(MCP_TOOL_SEPARATOR)) {
7
+ return null;
8
+ }
9
+ return { agentId: parts.agentId, skillId: parts.target };
10
+ }
11
+ export function parseMcpRequirementRef(ref) {
12
+ const parts = splitAgentRef(ref);
13
+ if (parts === null) {
14
+ return null;
15
+ }
16
+ const separator = parts.target.indexOf(MCP_TOOL_SEPARATOR);
17
+ if (separator < 0) {
18
+ return { agentId: parts.agentId, server: parts.target, tool: null };
19
+ }
20
+ const server = parts.target.slice(0, separator);
21
+ const tool = parts.target.slice(separator + 1);
22
+ if (server === EMPTY_REF_PART ||
23
+ tool === EMPTY_REF_PART ||
24
+ tool.includes(MCP_TOOL_SEPARATOR)) {
25
+ return null;
26
+ }
27
+ return { agentId: parts.agentId, server, tool };
28
+ }
29
+ function splitAgentRef(ref) {
30
+ const separator = ref.indexOf(AGENT_TARGET_SEPARATOR);
31
+ if (separator <= 0 || separator !== ref.lastIndexOf(AGENT_TARGET_SEPARATOR)) {
32
+ return null;
33
+ }
34
+ const agentId = ref.slice(0, separator);
35
+ const target = ref.slice(separator + 1);
36
+ if (target === EMPTY_REF_PART) {
37
+ return null;
38
+ }
39
+ return { agentId, target };
40
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Shared host-plane command runner: skill/MCP registrations shell out to
3
+ * the agent CLI outside a run. One implementation owns PATH resolution,
4
+ * stderr capture, redaction, and the typed failure boundary — adapters
5
+ * only choose the command and argv.
6
+ */
7
+ import { AGENT_ERROR_CODE, AgentError } from "../core/error.js";
8
+ import type { HostContext } from "./context.js";
9
+ export type HostCommandResult = {
10
+ stdout: string;
11
+ stderr: string;
12
+ exit: {
13
+ code: number | null;
14
+ signal: string | null;
15
+ };
16
+ };
17
+ export declare function runHostCommandResult(ctx: HostContext, input: {
18
+ command: string;
19
+ args: readonly string[];
20
+ }): Promise<HostCommandResult>;
21
+ /** The one way a non-zero host command becomes a typed error. */
22
+ export declare function hostCommandFailedError(command: string, result: HostCommandResult): AgentError<typeof AGENT_ERROR_CODE.failed>;
23
+ export declare function runHostCommand(ctx: HostContext, input: {
24
+ command: string;
25
+ args: readonly string[];
26
+ }): Promise<HostCommandResult>;
27
+ //# sourceMappingURL=run-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-command.d.ts","sourceRoot":"","sources":["../../src/host/run-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,EAChB,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACtD,CAAC;AAEF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAClD,OAAO,CAAC,iBAAiB,CAAC,CA+B5B;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,GACxB,UAAU,CAAC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAc5C;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAClD,OAAO,CAAC,iBAAiB,CAAC,CAM5B"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Shared host-plane command runner: skill/MCP registrations shell out to
3
+ * the agent CLI outside a run. One implementation owns PATH resolution,
4
+ * stderr capture, redaction, and the typed failure boundary — adapters
5
+ * only choose the command and argv.
6
+ */
7
+ import { AGENT_ERROR_CODE, AgentError, NOT_AVAILABLE_CAUSE, } from "../core/error.js";
8
+ import { redactSecrets } from "../core/redact.js";
9
+ import { OUTPUT_CHANNEL } from "../core/values.js";
10
+ const OUTPUT_TAIL_CHARS = 2_000;
11
+ export async function runHostCommandResult(ctx, input) {
12
+ const command = await ctx.exec.which(input.command, ctx.env);
13
+ if (command === null) {
14
+ throw new AgentError({
15
+ code: AGENT_ERROR_CODE.notAvailable,
16
+ message: `Command "${input.command}" was not found on PATH`,
17
+ data: { cause: NOT_AVAILABLE_CAUSE.notInstalled },
18
+ });
19
+ }
20
+ const process = ctx.exec.spawn({
21
+ command,
22
+ args: [...input.args],
23
+ cwd: ctx.location.projectDir ?? ctx.location.homeDir,
24
+ env: ctx.env,
25
+ stdin: null,
26
+ });
27
+ let stdout = "";
28
+ let stderr = "";
29
+ for await (const chunk of process.chunks) {
30
+ if (chunk.channel === OUTPUT_CHANNEL.stdout) {
31
+ stdout += chunk.text;
32
+ }
33
+ else {
34
+ stderr += chunk.text;
35
+ }
36
+ }
37
+ const exit = await process.exit;
38
+ return {
39
+ stdout,
40
+ stderr: redactSecrets(stderr),
41
+ exit,
42
+ };
43
+ }
44
+ /** The one way a non-zero host command becomes a typed error. */
45
+ export function hostCommandFailedError(command, result) {
46
+ // stdout is kept raw for parsing callers, so redact it here at the
47
+ // one place it can enter an error; stderr is redacted at capture.
48
+ const stdoutTail = redactSecrets(result.stdout.slice(-OUTPUT_TAIL_CHARS));
49
+ const stderrTail = result.stderr.slice(-OUTPUT_TAIL_CHARS);
50
+ return new AgentError({
51
+ code: AGENT_ERROR_CODE.failed,
52
+ message: `Host command "${command}" failed with exit code ${result.exit.code ?? "null"}`,
53
+ data: {
54
+ exitCode: result.exit.code,
55
+ stdoutTail: stdoutTail || null,
56
+ stderrTail: stderrTail || null,
57
+ },
58
+ });
59
+ }
60
+ export async function runHostCommand(ctx, input) {
61
+ const result = await runHostCommandResult(ctx, input);
62
+ if (result.exit.code !== 0) {
63
+ throw hostCommandFailedError(input.command, result);
64
+ }
65
+ return result;
66
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Catalog secret rules (K7): no literal secrets in an MCP server spec.
3
+ * `Authorization` headers are forbidden (use `bearerTokenEnvVar`), and
4
+ * suspicious literal values are rejected.
5
+ */
6
+ import type { Issue } from "../core/error.js";
7
+ import { type McpServerSpec } from "./capabilities.js";
8
+ /** Returns an issue list; empty means valid (rule 3). */
9
+ export declare function validateSpecSecrets(spec: McpServerSpec): Issue[];
10
+ //# sourceMappingURL=validate-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-spec.d.ts","sourceRoot":"","sources":["../../src/host/validate-spec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAoEtE,yDAAyD;AACzD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,KAAK,EAAE,CAOhE"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Catalog secret rules (K7): no literal secrets in an MCP server spec.
3
+ * `Authorization` headers are forbidden (use `bearerTokenEnvVar`), and
4
+ * suspicious literal values are rejected.
5
+ */
6
+ import { MCP_TRANSPORT } from "./capabilities.js";
7
+ const SECRET_LIKE_VALUE = /\b(sk-|ghp_|github_pat_|xox[baprs]-|eyJ)/;
8
+ const AUTHORIZATION_HEADER = "authorization";
9
+ const ISSUE_PATH = {
10
+ headers: "headers",
11
+ };
12
+ const SPEC_SECRET_ISSUE_CODE = {
13
+ authorizationHeaderForbidden: "authorization_header_forbidden",
14
+ literalSecret: "literal_secret",
15
+ };
16
+ const SPEC_SECRET_ISSUE_MESSAGE = {
17
+ authorizationHeaderForbidden: "Use bearerTokenEnvVar instead of an Authorization header",
18
+ literalSecret: "MCP server spec appears to contain a literal secret; use an env reference",
19
+ };
20
+ function checkAuthorizationHeaderNames(headers) {
21
+ const issues = [];
22
+ for (const name of Object.keys(headers)) {
23
+ if (name.toLowerCase() === AUTHORIZATION_HEADER) {
24
+ issues.push({
25
+ path: [ISSUE_PATH.headers, name],
26
+ code: SPEC_SECRET_ISSUE_CODE.authorizationHeaderForbidden,
27
+ message: SPEC_SECRET_ISSUE_MESSAGE.authorizationHeaderForbidden,
28
+ });
29
+ }
30
+ }
31
+ return issues;
32
+ }
33
+ function checkLiteralSecretStrings(value) {
34
+ const issues = [];
35
+ collectLiteralSecretStringIssues(value, [], issues);
36
+ return issues;
37
+ }
38
+ function collectLiteralSecretStringIssues(value, path, issues) {
39
+ if (typeof value === "string") {
40
+ if (SECRET_LIKE_VALUE.test(value)) {
41
+ issues.push({
42
+ path,
43
+ code: SPEC_SECRET_ISSUE_CODE.literalSecret,
44
+ message: SPEC_SECRET_ISSUE_MESSAGE.literalSecret,
45
+ });
46
+ }
47
+ return;
48
+ }
49
+ if (Array.isArray(value)) {
50
+ value.forEach((item, index) => {
51
+ collectLiteralSecretStringIssues(item, [...path, index], issues);
52
+ });
53
+ return;
54
+ }
55
+ if (value !== null && typeof value === "object") {
56
+ for (const [key, item] of Object.entries(value)) {
57
+ collectLiteralSecretStringIssues(item, [...path, key], issues);
58
+ }
59
+ }
60
+ }
61
+ /** Returns an issue list; empty means valid (rule 3). */
62
+ export function validateSpecSecrets(spec) {
63
+ return [
64
+ ...checkLiteralSecretStrings(spec),
65
+ ...(spec.transport === MCP_TRANSPORT.http
66
+ ? checkAuthorizationHeaderNames(spec.headers)
67
+ : []),
68
+ ];
69
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * `@alpacakit/agents` — run AI coding agents programmatically.
3
+ *
4
+ * One root entry holds the whole surface: extension points must never
5
+ * require knowing which internal layer owns them. Only genuine isolation
6
+ * lives on a subpath — dev fakes (`/testing`), the codex app-server client
7
+ * (`/codex`), the native keyring (`/keyring`), and machine-local config
8
+ * storage (`/config`).
9
+ */
10
+ export { BUILTIN_AGENT_ID, type BuiltinAgentId, builtinAgentFactories, } from "./agents/builtin.js";
11
+ export { claude, structuredQuotaMatcher } from "./agents/claude.js";
12
+ export { capacityTextMatcher, codex } from "./agents/codex.js";
13
+ export type { PiSessionEngineOptions } from "./agents/openai-compatible/pi/engine.js";
14
+ export { PI_DEFAULT_CONTEXT_WINDOW, PI_DEFAULT_MAX_TOKENS, piSessionEngine, } from "./agents/openai-compatible/pi/engine.js";
15
+ export type { JsonValue, OpenAiCompatibleConfig, OpenAiCompatibleConfigInput, OpenAiCompatibleEngine, } from "./agents/openai-compatible.js";
16
+ export { openaiCompatible } from "./agents/openai-compatible.js";
17
+ export type { LoginCapability, LoginContext, LoginEvent, LoginHandle, LoginHandler, LoginMethod, LoginOutcome, LoginRequest, LoginRun, } from "./auth/login.js";
18
+ export { LOGIN_EVENT_TYPE, LOGIN_METHOD } from "./auth/login.js";
19
+ export type { ApiKeyProfileOptions, AuthCapability, AuthMaterial, AuthMaterialDescriptor, AuthMaterialKind, AuthProfile, AuthStatus, HomeDirProfileOptions, MaterialHandler, MaterialHandlers, SecretRef, } from "./auth/material.js";
20
+ export { AUTH_MATERIAL_KIND, AUTH_STATUS, createApiKeyProfile, createHomeDirProfile, envVarAuthMaterial, } from "./auth/material.js";
21
+ export { fileProfileStore, type ProfileStore } from "./auth/profile-store.js";
22
+ export { envResolver, requireSecret } from "./auth/secrets.js";
23
+ export type { EnvPatch } from "./core/env.js";
24
+ export { applyEnvPatch, EMPTY_ENV_PATCH, mergeEnvPatches, processEnv, } from "./core/env.js";
25
+ export type { AgentErrorCode, AgentErrorData, AgentErrorOptions, AuthFailureReason, GuardViolation, Issue, NotAvailableCause, TimeoutKind, } from "./core/error.js";
26
+ export { AGENT_ERROR_CODE, AgentError, AUTH_FAILURE_REASON, isAgentError, NOT_AVAILABLE_CAUSE, TIMEOUT_KIND, } from "./core/error.js";
27
+ export type { Clock, Exec, ExecChunk, ExecExit, ExecProcess, ExecSpawnOptions, HttpClient, InteractiveExecProcess, InteractiveExecSpawnOptions, Logger, LogLevel, Ports, SecretResolver, SecretResolvers, TelemetrySink, } from "./core/ports.js";
28
+ export { LOG_LEVEL } from "./core/ports.js";
29
+ export { redactJsonSecrets, redactSecrets } from "./core/redact.js";
30
+ export type { AgentEvent, AgentRunOutcome, RunCompletion, RunEvent, RunExit, RunHandle, RunResult, RunTelemetry, RunTiming, RunUsage, } from "./core/run.js";
31
+ export { AGENT_EVENT_TYPE, RUN_COMPLETION_KIND, RUN_EVENT_TYPE, RUN_OUTCOME, } from "./core/run.js";
32
+ export type { OutputChannel, ProcessSignal } from "./core/values.js";
33
+ export { OUTPUT_CHANNEL, PROCESS_SIGNAL } from "./core/values.js";
34
+ export type { FailureCorpusRecorder, FailureCorpusRecorderOptions, } from "./corpus/failure-corpus.js";
35
+ export { createFailureCorpusRecorder } from "./corpus/failure-corpus.js";
36
+ export type { AttemptStatus, AttemptTrace, Blocker, BlockerReason, Candidate, CandidateOptions, CreateFleetOptions, FleetAttemptRunOptions, Fleet, FleetOutcome, FleetPlainRunOptions, FleetOutcomeStatus, FleetRunOptions, FleetStructuredRunOptions, } from "./fleet/fleet.js";
37
+ export { ATTEMPT_STATUS, BLOCKER_REASON, candidateForAgent, candidateFromProfile, candidateKey, createFleet, FLEET_OUTCOME_STATUS, profileCooldownKey, } from "./fleet/fleet.js";
38
+ export type { CooldownScope, FailureAction, FailureActionKind, FailurePolicy, PolicyCode, } from "./fleet/policy.js";
39
+ export { CAPACITY_DEFAULT_COOLDOWN_MS, COOLDOWN_SCOPE, defaultFailurePolicy, FAILURE_ACTION_KIND, QUOTA_DEFAULT_COOLDOWN_MS, } from "./fleet/policy.js";
40
+ export type { CooldownKey, FleetStateStore } from "./fleet/store.js";
41
+ export { fileFleetStore, memoryFleetStore } from "./fleet/store.js";
42
+ export type { DoctorCapability, DoctorCheck, DoctorReport, InstalledSkill, InstallOptions, InstallOutcome, McpAvailability, McpCapability, McpScope, McpServerSpec, McpServerState, McpTransport, SkillAvailability, SkillSource, SkillSourceKind, SkillsCapability, StdioMcpServerSpec, } from "./host/capabilities.js";
43
+ export { CAPABILITY_AVAILABILITY_STATUS, checkMcpAvailability, checkSkillAvailability, DOCTOR_CHECK_STATUS, INSTALL_STATUS, MCP_SCOPE, MCP_TRANSPORT, SKILL_SOURCE_KIND, } from "./host/capabilities.js";
44
+ export type { HostContext, HostLocation } from "./host/context.js";
45
+ export type { McpRequirementRef, SkillRequirementRef, } from "./host/requirement-ref.js";
46
+ export { parseMcpRequirementRef, parseSkillRequirementRef, } from "./host/requirement-ref.js";
47
+ export { validateSpecSecrets } from "./host/validate-spec.js";
48
+ export type { ClassifiedFailure, FailureEvidence, FailureMatcher, } from "./kernel/classify.js";
49
+ export { authIf, capacityIf, classifyFailure, parseCooldownHint, quotaIf, sharedFailureMatchers, } from "./kernel/classify.js";
50
+ export type { ArgContext, CliAgentBlueprint, CliResultCapture, OutputState, SandboxArgBuilders, } from "./kernel/cli-agent.js";
51
+ export { defineCliAgent } from "./kernel/cli-agent.js";
52
+ export type { AgentDefinition, AgentRun, RunContext, } from "./kernel/definition.js";
53
+ export { defineAgent } from "./kernel/definition.js";
54
+ export type { EnvTemplate, EnvTemplateResolution, } from "./kernel/env-template.js";
55
+ export { referencedEnvNames, resolveEnvTemplate, } from "./kernel/env-template.js";
56
+ export type { AgentAuth, AgentDoctor, AgentLogin, AgentMcp, AgentSkills, } from "./kernel/facets.js";
57
+ export type { Guard, GuardContext, GuardFactory } from "./kernel/guard.js";
58
+ export { maxToolCalls, maxTurns, noProgress, repeatedOutput, } from "./kernel/guard.js";
59
+ export type { Grant, Limits, ResolvedLimits, ResolvedRunOptions, ResolvedSandbox, RunOptions, Sandbox, SandboxMode, } from "./kernel/options.js";
60
+ export { GRANT_KIND, SANDBOX_MODE } from "./kernel/options.js";
61
+ export type { Agent, AgentRuntime, AgentRuntimeOptions, } from "./kernel/runtime.js";
62
+ export { createAgentRuntime, resolvePorts } from "./kernel/runtime.js";
63
+ export { type RunAgentOptions, runAgent } from "./run-agent.js";
64
+ export type { ExtractionStrategy, JsonParseOutcome, Markers, } from "./structured/extract.js";
65
+ export { DEFAULT_MARKERS, defaultExtractionStrategies, extractBlock, parseJsonResilient, } from "./structured/extract.js";
66
+ export type { ContractPromptPlacement, OutputContract, ParseOutcome, RepairContext, StructuredAttempt, StructuredHandle, StructuredResult, StructuredRunOptions, } from "./structured/run-structured.js";
67
+ export { CONTRACT_PROMPT_PLACEMENT } from "./structured/run-structured.js";
68
+ export type { StandardSchemaIssue, StandardSchemaV1, } from "./structured/standard-schema.js";
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,EACnB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,GAChB,MAAM,yCAAyC,CAAC;AACjD,YAAY,EACV,SAAS,EACT,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,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C;AAC3E,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,KAAK,EACL,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EACV,KAAK,EACL,YAAY,EACZ,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEhE,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,GACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,YAAY,EACZ,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EACV,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,iCAAiC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `@alpacakit/agents` — run AI coding agents programmatically.
3
+ *
4
+ * One root entry holds the whole surface: extension points must never
5
+ * require knowing which internal layer owns them. Only genuine isolation
6
+ * lives on a subpath — dev fakes (`/testing`), the codex app-server client
7
+ * (`/codex`), the native keyring (`/keyring`), and machine-local config
8
+ * storage (`/config`).
9
+ */
10
+ export { BUILTIN_AGENT_ID, builtinAgentFactories, } from "./agents/builtin.js";
11
+ export { claude, structuredQuotaMatcher } from "./agents/claude.js";
12
+ export { capacityTextMatcher, codex } from "./agents/codex.js";
13
+ export { PI_DEFAULT_CONTEXT_WINDOW, PI_DEFAULT_MAX_TOKENS, piSessionEngine, } from "./agents/openai-compatible/pi/engine.js";
14
+ export { openaiCompatible } from "./agents/openai-compatible.js";
15
+ export { LOGIN_EVENT_TYPE, LOGIN_METHOD } from "./auth/login.js";
16
+ export { AUTH_MATERIAL_KIND, AUTH_STATUS, createApiKeyProfile, createHomeDirProfile, envVarAuthMaterial, } from "./auth/material.js";
17
+ export { fileProfileStore } from "./auth/profile-store.js";
18
+ export { envResolver, requireSecret } from "./auth/secrets.js";
19
+ export { applyEnvPatch, EMPTY_ENV_PATCH, mergeEnvPatches, processEnv, } from "./core/env.js";
20
+ export { AGENT_ERROR_CODE, AgentError, AUTH_FAILURE_REASON, isAgentError, NOT_AVAILABLE_CAUSE, TIMEOUT_KIND, } from "./core/error.js";
21
+ export { LOG_LEVEL } from "./core/ports.js";
22
+ export { redactJsonSecrets, redactSecrets } from "./core/redact.js";
23
+ export { AGENT_EVENT_TYPE, RUN_COMPLETION_KIND, RUN_EVENT_TYPE, RUN_OUTCOME, } from "./core/run.js";
24
+ export { OUTPUT_CHANNEL, PROCESS_SIGNAL } from "./core/values.js";
25
+ export { createFailureCorpusRecorder } from "./corpus/failure-corpus.js";
26
+ export { ATTEMPT_STATUS, BLOCKER_REASON, candidateForAgent, candidateFromProfile, candidateKey, createFleet, FLEET_OUTCOME_STATUS, profileCooldownKey, } from "./fleet/fleet.js";
27
+ export { CAPACITY_DEFAULT_COOLDOWN_MS, COOLDOWN_SCOPE, defaultFailurePolicy, FAILURE_ACTION_KIND, QUOTA_DEFAULT_COOLDOWN_MS, } from "./fleet/policy.js";
28
+ export { fileFleetStore, memoryFleetStore } from "./fleet/store.js";
29
+ export { CAPABILITY_AVAILABILITY_STATUS, checkMcpAvailability, checkSkillAvailability, DOCTOR_CHECK_STATUS, INSTALL_STATUS, MCP_SCOPE, MCP_TRANSPORT, SKILL_SOURCE_KIND, } from "./host/capabilities.js";
30
+ export { parseMcpRequirementRef, parseSkillRequirementRef, } from "./host/requirement-ref.js";
31
+ export { validateSpecSecrets } from "./host/validate-spec.js";
32
+ export { authIf, capacityIf, classifyFailure, parseCooldownHint, quotaIf, sharedFailureMatchers, } from "./kernel/classify.js";
33
+ export { defineCliAgent } from "./kernel/cli-agent.js";
34
+ export { defineAgent } from "./kernel/definition.js";
35
+ export { referencedEnvNames, resolveEnvTemplate, } from "./kernel/env-template.js";
36
+ export { maxToolCalls, maxTurns, noProgress, repeatedOutput, } from "./kernel/guard.js";
37
+ export { GRANT_KIND, SANDBOX_MODE } from "./kernel/options.js";
38
+ export { createAgentRuntime, resolvePorts } from "./kernel/runtime.js";
39
+ export { runAgent } from "./run-agent.js";
40
+ export { DEFAULT_MARKERS, defaultExtractionStrategies, extractBlock, parseJsonResilient, } from "./structured/extract.js";
41
+ export { CONTRACT_PROMPT_PLACEMENT } from "./structured/run-structured.js";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Failure classification (design "Errors"): the matcher contract, the
3
+ * combinators custom agents build on, cooldown-hint parsing, and the
4
+ * generic quota / auth free-text matchers shared by every agent
5
+ * (v1 F3/F5 signals, kept verbatim). Provider-specific matchers live on
6
+ * their adapter modules and enter via the blueprints' `classify` arrays.
7
+ */
8
+ import type { AgentErrorCode, AgentErrorData, AuthFailureReason } from "../core/error.js";
9
+ export type FailureEvidence = {
10
+ stdout: string;
11
+ stderr: string;
12
+ exitCode: number | null;
13
+ signal: string | null;
14
+ /** Epoch ms used as the base for relative cooldown hints. */
15
+ now: number;
16
+ };
17
+ export type ClassifiedFailure<C extends AgentErrorCode = AgentErrorCode> = {
18
+ [K in C]: {
19
+ code: K;
20
+ message: string;
21
+ data: AgentErrorData[K];
22
+ };
23
+ }[C];
24
+ export type FailureMatcher = (evidence: FailureEvidence) => ClassifiedFailure | null;
25
+ export declare function parseEpochTimestamp(value: number): string;
26
+ /**
27
+ * Cooldown-time parsing (F3): ISO timestamps, epoch digits after
28
+ * reset/retry-after, "retry after N s", and relative "in N minutes".
29
+ */
30
+ export declare function parseCooldownHint(text: string, now: number): string | null;
31
+ /** Matcher combinator: classify as quota when the pattern matches. */
32
+ export declare function quotaIf(pattern: RegExp): FailureMatcher;
33
+ /** Matcher combinator: classify as capacity when the pattern matches. */
34
+ export declare function capacityIf(pattern: RegExp): FailureMatcher;
35
+ export declare function detectAuthReason(text: string): AuthFailureReason;
36
+ /** Matcher combinator: classify as auth when the pattern matches. */
37
+ export declare function authIf(pattern: RegExp): FailureMatcher;
38
+ /**
39
+ * Shared matchers, consulted after agent-specific ones. Provider-specific
40
+ * structured quota and capacity text matchers live on built-in blueprints.
41
+ */
42
+ export declare const sharedFailureMatchers: readonly FailureMatcher[];
43
+ export declare function classifyFailure(matchers: readonly FailureMatcher[], evidence: FailureEvidence): ClassifiedFailure | null;
44
+ //# sourceMappingURL=classify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../src/kernel/classify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6DAA6D;IAC7D,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI;KACxE,CAAC,IAAI,CAAC,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,CA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