@alpacakit/agents 0.1.0-beta.20 → 0.1.0-beta.24

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 (140) hide show
  1. package/README.md +60 -0
  2. package/dist/agents/claude.d.ts.map +1 -1
  3. package/dist/agents/claude.js +3 -0
  4. package/dist/agents/codex.d.ts.map +1 -1
  5. package/dist/agents/codex.js +4 -0
  6. package/dist/agents/openai-compatible/config.d.ts.map +1 -1
  7. package/dist/agents/openai-compatible/config.js +5 -0
  8. package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -1
  9. package/dist/agents/openai-compatible/fetch-engine.js +6 -0
  10. package/dist/agents/openai-compatible/pi/module.d.ts.map +1 -1
  11. package/dist/agents/openai-compatible/pi/module.js +1 -0
  12. package/dist/agents/openai-compatible/pi/sandbox.js +2 -0
  13. package/dist/agents/openai-compatible/response.js +1 -0
  14. package/dist/auth/profile-store.d.ts.map +1 -1
  15. package/dist/auth/profile-store.js +1 -0
  16. package/dist/auth/secrets.d.ts.map +1 -1
  17. package/dist/auth/secrets.js +2 -0
  18. package/dist/codex/app-server.js +6 -0
  19. package/dist/core/controlled-process.d.ts +98 -0
  20. package/dist/core/controlled-process.d.ts.map +1 -0
  21. package/dist/core/controlled-process.js +29 -0
  22. package/dist/core/error.d.ts +25 -0
  23. package/dist/core/error.d.ts.map +1 -1
  24. package/dist/core/error.js +32 -0
  25. package/dist/core/node-controlled-exec.d.ts +3 -0
  26. package/dist/core/node-controlled-exec.d.ts.map +1 -0
  27. package/dist/core/node-controlled-exec.js +32 -0
  28. package/dist/core/node-ports.d.ts +1 -0
  29. package/dist/core/node-ports.d.ts.map +1 -1
  30. package/dist/core/node-ports.js +9 -1
  31. package/dist/core/ports.d.ts +5 -0
  32. package/dist/core/ports.d.ts.map +1 -1
  33. package/dist/fleet/fleet.d.ts.map +1 -1
  34. package/dist/fleet/fleet.js +5 -2
  35. package/dist/fleet/store.d.ts.map +1 -1
  36. package/dist/fleet/store.js +3 -0
  37. package/dist/host/github-dir.d.ts.map +1 -1
  38. package/dist/host/github-dir.js +5 -0
  39. package/dist/host/mcp-list.d.ts.map +1 -1
  40. package/dist/host/mcp-list.js +1 -0
  41. package/dist/host/run-command.d.ts.map +1 -1
  42. package/dist/host/run-command.js +2 -0
  43. package/dist/index.d.ts +6 -3
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -1
  46. package/dist/internal/controlled-process/authentication.d.ts +13 -0
  47. package/dist/internal/controlled-process/authentication.d.ts.map +1 -0
  48. package/dist/internal/controlled-process/authentication.js +112 -0
  49. package/dist/internal/controlled-process/child-fd.d.ts +5 -0
  50. package/dist/internal/controlled-process/child-fd.d.ts.map +1 -0
  51. package/dist/internal/controlled-process/child-fd.js +47 -0
  52. package/dist/internal/controlled-process/framed-transport.d.ts +6 -0
  53. package/dist/internal/controlled-process/framed-transport.d.ts.map +1 -0
  54. package/dist/internal/controlled-process/framed-transport.js +117 -0
  55. package/dist/internal/controlled-process/host-controller.d.ts +23 -0
  56. package/dist/internal/controlled-process/host-controller.d.ts.map +1 -0
  57. package/dist/internal/controlled-process/host-controller.js +911 -0
  58. package/dist/internal/controlled-process/lifecycle.d.ts +5 -0
  59. package/dist/internal/controlled-process/lifecycle.d.ts.map +1 -0
  60. package/dist/internal/controlled-process/lifecycle.js +22 -0
  61. package/dist/internal/controlled-process/model.d.ts +99 -0
  62. package/dist/internal/controlled-process/model.d.ts.map +1 -0
  63. package/dist/internal/controlled-process/model.js +1 -0
  64. package/dist/internal/controlled-process/record-store.d.ts +17 -0
  65. package/dist/internal/controlled-process/record-store.d.ts.map +1 -0
  66. package/dist/internal/controlled-process/record-store.js +170 -0
  67. package/dist/internal/controlled-process/record.d.ts +12 -0
  68. package/dist/internal/controlled-process/record.d.ts.map +1 -0
  69. package/dist/internal/controlled-process/record.js +87 -0
  70. package/dist/internal/controlled-process/schema.d.ts +133 -0
  71. package/dist/internal/controlled-process/schema.d.ts.map +1 -0
  72. package/dist/internal/controlled-process/schema.js +99 -0
  73. package/dist/internal/controlled-process/shim-entry.d.ts +2 -0
  74. package/dist/internal/controlled-process/shim-entry.d.ts.map +1 -0
  75. package/dist/internal/controlled-process/shim-entry.js +2 -0
  76. package/dist/internal/controlled-process/shim-runtime.d.ts +2 -0
  77. package/dist/internal/controlled-process/shim-runtime.d.ts.map +1 -0
  78. package/dist/internal/controlled-process/shim-runtime.js +57 -0
  79. package/dist/internal/controlled-process/supervisor-coordinator.d.ts +67 -0
  80. package/dist/internal/controlled-process/supervisor-coordinator.d.ts.map +1 -0
  81. package/dist/internal/controlled-process/supervisor-coordinator.js +325 -0
  82. package/dist/internal/controlled-process/supervisor-entry.d.ts +2 -0
  83. package/dist/internal/controlled-process/supervisor-entry.d.ts.map +1 -0
  84. package/dist/internal/controlled-process/supervisor-entry.js +2 -0
  85. package/dist/internal/controlled-process/supervisor-model.d.ts +92 -0
  86. package/dist/internal/controlled-process/supervisor-model.d.ts.map +1 -0
  87. package/dist/internal/controlled-process/supervisor-model.js +1 -0
  88. package/dist/internal/controlled-process/supervisor-platform.d.ts +16 -0
  89. package/dist/internal/controlled-process/supervisor-platform.d.ts.map +1 -0
  90. package/dist/internal/controlled-process/supervisor-platform.js +104 -0
  91. package/dist/internal/controlled-process/supervisor-runtime.d.ts +11 -0
  92. package/dist/internal/controlled-process/supervisor-runtime.d.ts.map +1 -0
  93. package/dist/internal/controlled-process/supervisor-runtime.js +773 -0
  94. package/dist/internal/controlled-process/supervisor-schema.d.ts +100 -0
  95. package/dist/internal/controlled-process/supervisor-schema.d.ts.map +1 -0
  96. package/dist/internal/controlled-process/supervisor-schema.js +73 -0
  97. package/dist/internal/controlled-process/supervisor-transport.d.ts +46 -0
  98. package/dist/internal/controlled-process/supervisor-transport.d.ts.map +1 -0
  99. package/dist/internal/controlled-process/supervisor-transport.js +368 -0
  100. package/dist/internal/controlled-process/supervisor-values.d.ts +39 -0
  101. package/dist/internal/controlled-process/supervisor-values.d.ts.map +1 -0
  102. package/dist/internal/controlled-process/supervisor-values.js +38 -0
  103. package/dist/internal/controlled-process/token.d.ts +4 -0
  104. package/dist/internal/controlled-process/token.d.ts.map +1 -0
  105. package/dist/internal/controlled-process/token.js +38 -0
  106. package/dist/internal/controlled-process/values.d.ts +39 -0
  107. package/dist/internal/controlled-process/values.d.ts.map +1 -0
  108. package/dist/internal/controlled-process/values.js +38 -0
  109. package/dist/kernel/cli-agent.d.ts.map +1 -1
  110. package/dist/kernel/cli-agent.js +330 -34
  111. package/dist/kernel/cli-login.d.ts.map +1 -1
  112. package/dist/kernel/cli-login.js +5 -0
  113. package/dist/kernel/env-template.js +1 -0
  114. package/dist/kernel/facets.d.ts.map +1 -1
  115. package/dist/kernel/facets.js +1 -0
  116. package/dist/kernel/keyed.d.ts.map +1 -1
  117. package/dist/kernel/keyed.js +1 -0
  118. package/dist/kernel/login.js +2 -0
  119. package/dist/kernel/options.d.ts +14 -0
  120. package/dist/kernel/options.d.ts.map +1 -1
  121. package/dist/kernel/options.js +3 -0
  122. package/dist/kernel/process-lifecycle-failure.d.ts +5 -0
  123. package/dist/kernel/process-lifecycle-failure.d.ts.map +1 -0
  124. package/dist/kernel/process-lifecycle-failure.js +5 -0
  125. package/dist/kernel/run.d.ts.map +1 -1
  126. package/dist/kernel/run.js +11 -0
  127. package/dist/kernel/runtime.d.ts.map +1 -1
  128. package/dist/kernel/runtime.js +2 -0
  129. package/dist/keyring/resolver.d.ts.map +1 -1
  130. package/dist/keyring/resolver.js +2 -0
  131. package/dist/structured/run-structured.js +1 -0
  132. package/dist/testing/fake-controlled-exec.d.ts +21 -0
  133. package/dist/testing/fake-controlled-exec.d.ts.map +1 -0
  134. package/dist/testing/fake-controlled-exec.js +172 -0
  135. package/dist/testing/fake-exec.d.ts.map +1 -1
  136. package/dist/testing/fake-exec.js +64 -54
  137. package/dist/testing/index.d.ts +1 -0
  138. package/dist/testing/index.d.ts.map +1 -1
  139. package/dist/testing/index.js +1 -0
  140. package/package.json +2 -2
package/README.md CHANGED
@@ -65,6 +65,66 @@ for await (const event of handle.events) {
65
65
  const result = await handle; // await handle === await handle.result
66
66
  ```
67
67
 
68
+ ### Controlled child lifecycle
69
+
70
+ Embedding hosts that need durable custody of CLI workers create a
71
+ `ControlledExec` and provide it with the run-scoped lifecycle. `beforeExec`
72
+ receives an opaque `{ pid, processStartToken }` identity before the worker
73
+ executes. `afterTermination` runs only after the supervisor has proved the
74
+ whole controlled process group absent and output has reached EOF; the signed
75
+ absence is released only after that callback succeeds.
76
+
77
+ ```ts
78
+ import { createControlledExec } from "@alpacakit/agents";
79
+
80
+ const controlledExec = createControlledExec({
81
+ runtimeDirectory: "/run/my-host/agents",
82
+ termination: {
83
+ termGraceMs: 5_000,
84
+ killProbeTimeoutMs: 5_000,
85
+ probeIntervalMs: 50,
86
+ },
87
+ });
88
+
89
+ await runtime.agent("codex").run({
90
+ prompt,
91
+ workspace,
92
+ resources: {
93
+ childProcess: {
94
+ exec: controlledExec,
95
+ lifecycle: {
96
+ beforeExec: async (identity) => {
97
+ await processRegistry.open(identity);
98
+ },
99
+ afterTermination: async ({ identity, proof }) => {
100
+ await processRegistry.close({ identity, proof });
101
+ },
102
+ },
103
+ },
104
+ },
105
+ });
106
+ ```
107
+
108
+ The resource is reused for structured-repair and fleet-failover spawns. When it
109
+ is absent, execution is ordinary unmanaged `Exec`; when present, the runtime
110
+ uses only the supplied `ControlledExec`. Abort and early completion request
111
+ termination through that controller exactly once. The supervisor owns signal
112
+ escalation and reports either authenticated absence or a typed unkillable
113
+ reason, so the runtime never falls back to direct process signaling.
114
+
115
+ A naturally completed worker includes its exact `{ code, signal }` as
116
+ `workerExit`. Abort-driven termination may complete with `workerExit: null`;
117
+ pre-exec lifecycle failure rejects `spawn` before a process handle is returned.
118
+ If a host restarts after persisting an identity, it can call
119
+ `controlledExec.recovery.recover(identity, { afterTermination })`; absence is
120
+ released only after the same lifecycle callback succeeds. Controlled execution
121
+ is supported on Linux and macOS and fails closed on unsupported platforms or
122
+ an insecure runtime directory.
123
+
124
+ Each recovery call performs one authenticated termination convergence. A
125
+ typed `pending` result invokes no lifecycle callback; the host owns the
126
+ cancellable retry cadence and calls `recover` again when appropriate.
127
+
68
128
  ## Structured output
69
129
 
70
130
  Any Standard Schema validator (zod v4 etc.) works. Repair happens within
@@ -1 +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"}
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;AAoSD,wBAAgB,MAAM,IAAI,eAAe,CAAC,QAAQ,CAAC,CAyDlD"}
@@ -258,6 +258,7 @@ function parseSkillMetadata(markdown) {
258
258
  function skillListReadError(target, cause) {
259
259
  return new AgentError({
260
260
  code: AGENT_ERROR_CODE.failed,
261
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
261
262
  message: `Could not read installed claude skills: ${target}`,
262
263
  data: { exitCode: null, stdoutTail: null, stderrTail: null },
263
264
  cause,
@@ -341,6 +342,7 @@ async function assertSkillDirectory(directory) {
341
342
  }
342
343
  throw new AgentError({
343
344
  code: AGENT_ERROR_CODE.invalidInput,
345
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
344
346
  message: `Skill source does not contain ${SKILL_MARKDOWN}: ${directory}`,
345
347
  data: { reason: `missing ${SKILL_MARKDOWN}` },
346
348
  });
@@ -363,6 +365,7 @@ async function installClaudePlugin(ctx, source, options) {
363
365
  // honest, silently ignoring the request is not.
364
366
  throw new AgentError({
365
367
  code: AGENT_ERROR_CODE.invalidInput,
368
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
366
369
  message: "Claude plugin installation cannot overwrite an installed plugin",
367
370
  data: { reason: "plugin install does not support overwrite" },
368
371
  });
@@ -1 +1 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/agents/codex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwCH,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAG/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAC/C,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AA6GtD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,CAepD;AAyMD,wBAAgB,KAAK,IAAI,eAAe,CAAC,OAAO,CAAC,CAoEhD"}
1
+ {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/agents/codex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwCH,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAG/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAC/C,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AA6GtD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,CAepD;AAiND,wBAAgB,KAAK,IAAI,eAAe,CAAC,OAAO,CAAC,CAoEhD"}
@@ -161,6 +161,7 @@ async function installCodexPlugin(ctx, source, options) {
161
161
  // silently ignoring the request is not (same contract as claude).
162
162
  throw new AgentError({
163
163
  code: AGENT_ERROR_CODE.invalidInput,
164
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
164
165
  message: "Codex plugin installation cannot overwrite an installed plugin",
165
166
  data: { reason: UNSUPPORTED_PLUGIN_OVERWRITE_REASON },
166
167
  });
@@ -211,6 +212,7 @@ function assertCodexStdioMcpSupported(spec, options) {
211
212
  if (spec.cwd !== null) {
212
213
  throw new AgentError({
213
214
  code: AGENT_ERROR_CODE.invalidInput,
215
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
214
216
  message: "Codex stdio MCP registration does not support server cwd",
215
217
  data: { reason: UNSUPPORTED_CWD_REASON },
216
218
  });
@@ -223,6 +225,7 @@ function assertCodexMcpScopeSupported(scope) {
223
225
  const reason = [UNSUPPORTED_SCOPE_REASON_PREFIX, scope].join(": ");
224
226
  throw new AgentError({
225
227
  code: AGENT_ERROR_CODE.invalidInput,
228
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
226
229
  message: `Codex MCP registration does not support scope "${scope}"`,
227
230
  data: { reason },
228
231
  });
@@ -249,6 +252,7 @@ function installOutcomeFromCodexPlugin(name, result) {
249
252
  if (result.appsNeedingAuth.length > 0) {
250
253
  throw new AgentError({
251
254
  code: AGENT_ERROR_CODE.auth,
255
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.auth),
252
256
  message: CODEX_PLUGIN_AUTH_REQUIRED_MESSAGE,
253
257
  data: {
254
258
  reason: AUTH_FAILURE_REASON.notLoggedIn,
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/agents/openai-compatible/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAEV,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAmBpB,MAAM,WAAW,8BAA8B;IAC7C,SAAS,CAAC,EAAE,SAAS,MAAM,EACzB,MAAM,EAAE,sBAAsB,CAAC,EAAE,CAAC,GACjC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAC9B,OAAO,CACL,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,8BAA8B,CAAC;IAClC,YAAY,CACV,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,SAAS,WAAW,EAAE,CAAC;CAC3B;AAED,qBAAa,qCACX,YAAW,8BAA8B;IAEzC,SAAS,CAAC,EAAE,SAAS,MAAM,EACzB,MAAM,EAAE,sBAAsB,CAAC,EAAE,CAAC,GACjC,sBAAsB,CAAC,EAAE,CAAC;IAW7B,OAAO,CACL,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,8BAA8B;IAyCjC,YAAY,CACV,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,SAAS,WAAW,EAAE;IASzB,OAAO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,gBAAgB;CAYzB;AAED,eAAO,MAAM,qCAAqC,uCACL,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/agents/openai-compatible/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAEV,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAmBpB,MAAM,WAAW,8BAA8B;IAC7C,SAAS,CAAC,EAAE,SAAS,MAAM,EACzB,MAAM,EAAE,sBAAsB,CAAC,EAAE,CAAC,GACjC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAC9B,OAAO,CACL,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,8BAA8B,CAAC;IAClC,YAAY,CACV,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,SAAS,WAAW,EAAE,CAAC;CAC3B;AAED,qBAAa,qCACX,YAAW,8BAA8B;IAEzC,SAAS,CAAC,EAAE,SAAS,MAAM,EACzB,MAAM,EAAE,sBAAsB,CAAC,EAAE,CAAC,GACjC,sBAAsB,CAAC,EAAE,CAAC;IAW7B,OAAO,CACL,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,8BAA8B;IAyCjC,YAAY,CACV,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACpC,SAAS,WAAW,EAAE;IASzB,OAAO,CAAC,uBAAuB;IA2B/B,OAAO,CAAC,gBAAgB;CAYzB;AAED,eAAO,MAAM,qCAAqC,uCACL,CAAC"}
@@ -58,6 +58,7 @@ export class DefaultOpenAiCompatibleConfigResolver {
58
58
  if (!resolved.ok) {
59
59
  throw new AgentError({
60
60
  code: AGENT_ERROR_CODE.notAvailable,
61
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
61
62
  message: `openaiCompatible.${label} references ${resolved.reason} environment variable: ${resolved.envName}`,
62
63
  data: { cause: NOT_AVAILABLE_CAUSE.badConfig },
63
64
  });
@@ -65,6 +66,7 @@ export class DefaultOpenAiCompatibleConfigResolver {
65
66
  if (resolved.value.trim().length === 0) {
66
67
  throw new AgentError({
67
68
  code: AGENT_ERROR_CODE.notAvailable,
69
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
68
70
  message: `openaiCompatible.${label} resolved to an empty value`,
69
71
  data: { cause: NOT_AVAILABLE_CAUSE.badConfig },
70
72
  });
@@ -88,6 +90,7 @@ function resolveJsonTemplates(label, value, env) {
88
90
  if (!resolved.ok) {
89
91
  throw new AgentError({
90
92
  code: AGENT_ERROR_CODE.notAvailable,
93
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
91
94
  message: `openaiCompatible.${label} references ${resolved.reason} environment variable: ${resolved.envName}`,
92
95
  data: { cause: NOT_AVAILABLE_CAUSE.badConfig },
93
96
  });
@@ -139,6 +142,7 @@ function assertHttpBaseUrl(baseUrl) {
139
142
  catch {
140
143
  throw new AgentError({
141
144
  code: AGENT_ERROR_CODE.notAvailable,
145
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
142
146
  message: `Invalid OpenAI-compatible baseUrl: ${baseUrl}`,
143
147
  data: { cause: NOT_AVAILABLE_CAUSE.badConfig },
144
148
  });
@@ -147,6 +151,7 @@ function assertHttpBaseUrl(baseUrl) {
147
151
  parsed.protocol !== HTTP_PROTOCOL.https) {
148
152
  throw new AgentError({
149
153
  code: AGENT_ERROR_CODE.notAvailable,
154
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
150
155
  message: `Invalid OpenAI-compatible baseUrl protocol: ${parsed.protocol}`,
151
156
  data: { cause: NOT_AVAILABLE_CAUSE.badConfig },
152
157
  });
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-engine.d.ts","sourceRoot":"","sources":["../../../src/agents/openai-compatible/fetch-engine.ts"],"names":[],"mappings":"AA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UAAU,GAAG,IAAI,CAAC,CAAC;CAC3E;AAED,MAAM,MAAM,uCAAuC,GAAG;IACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,+BAA+B,EAAE,CAAC;IAC/D,QAAQ,CAAC,WAAW,CAAC,EAAE,2BAA2B,CAAC;IACnD,QAAQ,CAAC,aAAa,CAAC,EAAE,iCAAiC,CAAC;CAC5D,CAAC;AAEF,qBAAa,2BAA4B,YAAW,sBAAsB;IACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6C;IACtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8B;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoC;gBAEtD,YAAY,GAAE,uCAA4C;IAUhE,YAAY,IAAI,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC;IAI9C,GAAG,CACR,MAAM,EAAE,8BAA8B,EACtC,OAAO,EAAE,kBAAkB,EAC3B,GAAG,EAAE,UAAU,GACd,QAAQ;IA+CX,OAAO,CAAC,UAAU;CAenB;AAED,qBAAa,kCACX,YAAW,2BAA2B;IAEtC,QAAQ,CAAC,WAAW,KAAwB;IAE5C,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;CAGzD;AAED,qBAAa,wCACX,YAAW,iCAAiC;IAE5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAIvB;IAEI,QAAQ,CACZ,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAM9B;AAmJD,eAAO,MAAM,6BAA6B,6BAAoC,CAAC"}
@@ -92,6 +92,7 @@ export class FetchOpenAiCompatibleEngine {
92
92
  if (decoder === undefined) {
93
93
  throw new AgentError({
94
94
  code: AGENT_ERROR_CODE.failed,
95
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
95
96
  message: "OpenAI-compatible endpoint returned an unsupported response",
96
97
  data: { exitCode: null, stdoutTail: null, stderrTail: null },
97
98
  });
@@ -120,6 +121,7 @@ const authFailureHandler = {
120
121
  matches: (response) => isAuthHttpStatus(response.status),
121
122
  errorFor: async (response) => new AgentError({
122
123
  code: AGENT_ERROR_CODE.auth,
124
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.auth),
123
125
  message: `OpenAI-compatible endpoint rejected authentication with HTTP ${response.status}`,
124
126
  data: {
125
127
  reason: AUTH_REASON_BY_STATUS[response.status],
@@ -133,6 +135,7 @@ const quotaFailureHandler = {
133
135
  const retryAfter = response.headers.get(OPENAI_COMPATIBLE_HTTP_HEADER.retryAfter);
134
136
  return new AgentError({
135
137
  code: AGENT_ERROR_CODE.quota,
138
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.quota),
136
139
  message: "OpenAI-compatible endpoint reported a rate limit",
137
140
  data: {
138
141
  cooldownUntil: retryAfter === null
@@ -149,6 +152,7 @@ const genericHttpFailureHandler = {
149
152
  const redactedBody = redactSecrets(body);
150
153
  return new AgentError({
151
154
  code: AGENT_ERROR_CODE.failed,
155
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
152
156
  message: `OpenAI-compatible endpoint failed with HTTP ${response.status}`,
153
157
  data: {
154
158
  exitCode: null,
@@ -194,6 +198,7 @@ function normalizeRunError(error) {
194
198
  }
195
199
  return new AgentError({
196
200
  code: AGENT_ERROR_CODE.notAvailable,
201
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
197
202
  message: error instanceof Error ? error.message : String(error),
198
203
  data: { cause: NOT_AVAILABLE_CAUSE.unreachable },
199
204
  cause: error,
@@ -209,6 +214,7 @@ function isRetryableRunError(error) {
209
214
  function unreachableError() {
210
215
  return new AgentError({
211
216
  code: AGENT_ERROR_CODE.failed,
217
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
212
218
  message: "OpenAI-compatible endpoint failed without an error",
213
219
  data: { exitCode: null, stdoutTail: null, stderrTail: null },
214
220
  });
@@ -1 +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AAE,CAAC;KAClC,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,cAAc,CAAA;KAAE,CAAC,CAAC;IACzC,wBAAwB,CAAC,EAAE,2BAA2B,CAAC;IACvD,yBAAyB,CAAC,EAAE,4BAA4B,CAAC;CAC1D;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAapD,eAAO,MAAM,qBAAqB,EAAE,cACX,CAAC;AAE1B,wBAAsB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgB5E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAS7D"}
@@ -36,6 +36,7 @@ export async function loadPiModule(loader) {
36
36
  export function piPeerMissingError(cause) {
37
37
  return new AgentError({
38
38
  code: AGENT_ERROR_CODE.notAvailable,
39
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
39
40
  message: PI_PEER_MISSING_MESSAGE,
40
41
  data: { cause: NOT_AVAILABLE_CAUSE.engineMissing },
41
42
  cause,
@@ -38,6 +38,7 @@ function createGuardedBashTool(input, allowlist) {
38
38
  if (createDefinition === undefined || createOperations === undefined) {
39
39
  throw new AgentError({
40
40
  code: AGENT_ERROR_CODE.notAvailable,
41
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
41
42
  message: PI_SHELL_GRANT_MISSING_FACTORY_MESSAGE,
42
43
  data: { cause: NOT_AVAILABLE_CAUSE.engineMissing },
43
44
  });
@@ -63,6 +64,7 @@ function assertAllowedCommand(command, allowlist) {
63
64
  }
64
65
  throw new AgentError({
65
66
  code: AGENT_ERROR_CODE.invalidInput,
67
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
66
68
  message: PI_BASH_COMMAND_NOT_ALLOWED_MESSAGE,
67
69
  data: { reason: PI_BASH_COMMAND_NOT_ALLOWED_REASON },
68
70
  });
@@ -191,6 +191,7 @@ function invalidJsonResponseError(message, body) {
191
191
  const redactedBody = redactSecrets(body);
192
192
  return new AgentError({
193
193
  code: AGENT_ERROR_CODE.failed,
194
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
194
195
  message,
195
196
  data: {
196
197
  exitCode: null,
@@ -1 +1 @@
1
- {"version":3,"file":"profile-store.d.ts","sourceRoot":"","sources":["../../src/auth/profile-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAcrE,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AA6FD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAE/D"}
1
+ {"version":3,"file":"profile-store.d.ts","sourceRoot":"","sources":["../../src/auth/profile-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAcrE,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AA+FD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAE/D"}
@@ -22,6 +22,7 @@ const PROFILE_STORE_ERROR_REASON = {
22
22
  function profileStoreError(reason, cause) {
23
23
  return new AgentError({
24
24
  code: AGENT_ERROR_CODE.invalidInput,
25
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
25
26
  message: `Invalid auth profile store: ${reason}`,
26
27
  data: { reason },
27
28
  ...(cause === undefined ? {} : { cause }),
@@ -1 +1 @@
1
- {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/auth/secrets.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,eAAe,EAC1B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,cAAc,CAS5C"}
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/auth/secrets.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,eAAe,EAC1B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,cAAc,CAS5C"}
@@ -9,6 +9,7 @@ export async function requireSecret(resolvers, ref) {
9
9
  if (resolver === undefined) {
10
10
  throw new AgentError({
11
11
  code: AGENT_ERROR_CODE.invalidInput,
12
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.invalidInput),
12
13
  message: `Unknown secret resolver "${ref.resolver}"`,
13
14
  data: { reason: `no secret resolver registered for "${ref.resolver}"` },
14
15
  });
@@ -17,6 +18,7 @@ export async function requireSecret(resolvers, ref) {
17
18
  if (value === null || value === "") {
18
19
  throw new AgentError({
19
20
  code: AGENT_ERROR_CODE.auth,
21
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.auth),
20
22
  message: `Secret "${ref.id}" is not available from resolver "${ref.resolver}"`,
21
23
  data: {
22
24
  reason: AUTH_FAILURE_REASON.invalidCredentials,
@@ -107,6 +107,7 @@ class ExecCodexAppServer {
107
107
  if (command === null) {
108
108
  throw new AgentError({
109
109
  code: AGENT_ERROR_CODE.notAvailable,
110
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.notAvailable),
110
111
  message: `Command "${this.options.command}" was not found on PATH`,
111
112
  data: { cause: NOT_AVAILABLE_CAUSE.notInstalled },
112
113
  });
@@ -174,6 +175,7 @@ class ExecCodexAppServer {
174
175
  process.kill(PROCESS_SIGNAL.sigkill);
175
176
  reject(new AgentError({
176
177
  code: AGENT_ERROR_CODE.timeout,
178
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.timeout),
177
179
  message: `Codex app-server request timed out: ${String(method)}`,
178
180
  data: {
179
181
  kind: TIMEOUT_KIND.total,
@@ -281,6 +283,7 @@ function appServerResponseError(method, error) {
281
283
  const detail = redactSecrets(error.message ?? "");
282
284
  return new AgentError({
283
285
  code: AGENT_ERROR_CODE.failed,
286
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
284
287
  message: detail === "" ? `Codex app-server request failed: ${method}` : detail,
285
288
  data: {
286
289
  exitCode: null,
@@ -293,6 +296,7 @@ function appServerMalformedResultError(method, result) {
293
296
  const detail = redactSecrets(JSON.stringify(result) ?? "");
294
297
  return new AgentError({
295
298
  code: AGENT_ERROR_CODE.failed,
299
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
296
300
  message: `Codex app-server returned a malformed result: ${method}`,
297
301
  data: {
298
302
  exitCode: null,
@@ -305,6 +309,7 @@ function appServerExitedError(exitCode, stderr) {
305
309
  const stderrTail = redactSecrets(stderr.slice(-OUTPUT_TAIL_CHARS));
306
310
  return new AgentError({
307
311
  code: AGENT_ERROR_CODE.failed,
312
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
308
313
  message: "Codex app-server exited before completing the request",
309
314
  data: {
310
315
  exitCode,
@@ -316,6 +321,7 @@ function appServerExitedError(exitCode, stderr) {
316
321
  function appServerClosedError() {
317
322
  return new AgentError({
318
323
  code: AGENT_ERROR_CODE.failed,
324
+ classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
319
325
  message: "Codex app-server connection closed",
320
326
  data: { exitCode: null, stdoutTail: null, stderrTail: null },
321
327
  });
@@ -0,0 +1,98 @@
1
+ import type { ValueOf } from "@alpacakit/core";
2
+ import type { ExecChunk, ExecExit, ExecSpawnOptions } from "./ports.js";
3
+ export declare const CHILD_PROCESS_TERMINATION_KIND: {
4
+ readonly absent: "absent";
5
+ readonly pending: "pending";
6
+ readonly unkillable: "unkillable";
7
+ };
8
+ export declare const CHILD_PROCESS_TERMINATION_EVIDENCE_KIND: {
9
+ readonly liveChildClose: "live_child_close";
10
+ readonly offlineAbsence: "offline_absence";
11
+ };
12
+ export declare const CHILD_PROCESS_ABSENCE_PROOF: {
13
+ readonly supervisorProbe: "supervisor_probe";
14
+ readonly bootChanged: "boot_changed";
15
+ readonly releasedReceipt: "released_receipt";
16
+ };
17
+ export declare const CHILD_PROCESS_TERMINATION_PHASE: {
18
+ readonly termGrace: "term_grace";
19
+ readonly killProbe: "kill_probe";
20
+ };
21
+ export declare const CHILD_PROCESS_UNKILLABLE_REASON: {
22
+ readonly invalidIdentity: "invalid_identity";
23
+ readonly bootIdentityUnavailable: "boot_identity_unavailable";
24
+ readonly supervisorUnreachable: "supervisor_unreachable";
25
+ readonly recordAuthenticationFailed: "record_authentication_failed";
26
+ readonly recordIdentityMismatch: "record_identity_mismatch";
27
+ readonly protocolFailure: "protocol_failure";
28
+ readonly probePermissionDenied: "probe_permission_denied";
29
+ readonly shimLostWithLiveGroup: "shim_lost_with_live_group";
30
+ readonly groupSurvivedSigkill: "group_survived_sigkill";
31
+ };
32
+ export type ChildProcessAbsenceProof = ValueOf<typeof CHILD_PROCESS_ABSENCE_PROOF>;
33
+ export type ChildProcessTerminationPhase = ValueOf<typeof CHILD_PROCESS_TERMINATION_PHASE>;
34
+ export type ChildProcessUnkillableReason = ValueOf<typeof CHILD_PROCESS_UNKILLABLE_REASON>;
35
+ export type ChildProcessIdentity = {
36
+ readonly pid: number;
37
+ readonly processStartToken: string;
38
+ };
39
+ /**
40
+ * Local lifecycle evidence only. It is deliberately separate from the
41
+ * signed controlled-process record: only a live supervisor response may
42
+ * carry worker exit evidence, while recovery can establish absence only.
43
+ */
44
+ export type ChildProcessTerminationEvidence = {
45
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_EVIDENCE_KIND.liveChildClose;
46
+ readonly identity: ChildProcessIdentity;
47
+ readonly proof: ChildProcessAbsenceProof;
48
+ readonly workerExit: ExecExit;
49
+ } | {
50
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_EVIDENCE_KIND.offlineAbsence;
51
+ readonly identity: ChildProcessIdentity;
52
+ readonly proof: ChildProcessAbsenceProof;
53
+ };
54
+ export interface ChildProcessLifecycle {
55
+ beforeExec(identity: ChildProcessIdentity): Promise<void>;
56
+ afterTermination(evidence: ChildProcessTerminationEvidence): Promise<void>;
57
+ }
58
+ export type ChildProcessTerminationResult = {
59
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_KIND.absent;
60
+ readonly proof: ChildProcessAbsenceProof;
61
+ } | {
62
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_KIND.pending;
63
+ readonly phase: ChildProcessTerminationPhase;
64
+ readonly retryAfterMs: number;
65
+ } | {
66
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_KIND.unkillable;
67
+ readonly reason: ChildProcessUnkillableReason;
68
+ };
69
+ export type ChildProcessCompletion = {
70
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_KIND.absent;
71
+ readonly proof: ChildProcessAbsenceProof;
72
+ readonly workerExit: ExecExit | null;
73
+ } | {
74
+ readonly kind: typeof CHILD_PROCESS_TERMINATION_KIND.unkillable;
75
+ readonly reason: ChildProcessUnkillableReason;
76
+ readonly workerExit: ExecExit | null;
77
+ };
78
+ export type ControlledExecOptions = {
79
+ readonly runtimeDirectory: string;
80
+ readonly termination: {
81
+ readonly termGraceMs: number;
82
+ readonly killProbeTimeoutMs: number;
83
+ readonly probeIntervalMs: number;
84
+ };
85
+ };
86
+ export interface ControlledExecProcess {
87
+ readonly chunks: AsyncIterable<ExecChunk>;
88
+ readonly completion: Promise<ChildProcessCompletion>;
89
+ requestTermination(): Promise<ChildProcessCompletion>;
90
+ }
91
+ export interface ControlledProcessRecovery {
92
+ recover(identity: ChildProcessIdentity, lifecycle: Pick<ChildProcessLifecycle, "afterTermination">): Promise<ChildProcessTerminationResult>;
93
+ }
94
+ export interface ControlledExec {
95
+ spawn(options: ExecSpawnOptions, lifecycle: ChildProcessLifecycle): Promise<ControlledExecProcess>;
96
+ readonly recovery: ControlledProcessRecovery;
97
+ }
98
+ //# sourceMappingURL=controlled-process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controlled-process.d.ts","sourceRoot":"","sources":["../../src/core/controlled-process.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAExE,eAAO,MAAM,8BAA8B;;;;CAIjC,CAAC;AAEX,eAAO,MAAM,uCAAuC;;;CAG1C,CAAC;AAEX,eAAO,MAAM,2BAA2B;;;;CAI9B,CAAC;AAEX,eAAO,MAAM,+BAA+B;;;CAGlC,CAAC;AAEX,eAAO,MAAM,+BAA+B;;;;;;;;;;CAUlC,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,OAAO,2BAA2B,CACnC,CAAC;AACF,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAChD,OAAO,+BAA+B,CACvC,CAAC;AACF,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAChD,OAAO,+BAA+B,CACvC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,iB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KIND = {
7
+ liveChildClose: "live_child_close",
8
+ offlineAbsence: "offline_absence",
9
+ };
10
+ export const CHILD_PROCESS_ABSENCE_PROOF = {
11
+ supervisorProbe: "supervisor_probe",
12
+ bootChanged: "boot_changed",
13
+ releasedReceipt: "released_receipt",
14
+ };
15
+ export const CHILD_PROCESS_TERMINATION_PHASE = {
16
+ termGrace: "term_grace",
17
+ killProbe: "kill_probe",
18
+ };
19
+ export const CHILD_PROCESS_UNKILLABLE_REASON = {
20
+ invalidIdentity: "invalid_identity",
21
+ bootIdentityUnavailable: "boot_identity_unavailable",
22
+ supervisorUnreachable: "supervisor_unreachable",
23
+ recordAuthenticationFailed: "record_authentication_failed",
24
+ recordIdentityMismatch: "record_identity_mismatch",
25
+ protocolFailure: "protocol_failure",
26
+ probePermissionDenied: "probe_permission_denied",
27
+ shimLostWithLiveGroup: "shim_lost_with_live_group",
28
+ groupSurvivedSigkill: "group_survived_sigkill",
29
+ };
@@ -16,6 +16,25 @@ export declare const AGENT_ERROR_CODE: {
16
16
  readonly failed: "failed";
17
17
  };
18
18
  export type AgentErrorCode = (typeof AGENT_ERROR_CODE)[keyof typeof AGENT_ERROR_CODE];
19
+ export declare const AGENT_FAILURE_CLASS: {
20
+ readonly agent: "agent";
21
+ readonly infrastructure: "infrastructure";
22
+ };
23
+ export type AgentFailureClass = (typeof AGENT_FAILURE_CLASS)[keyof typeof AGENT_FAILURE_CLASS];
24
+ export declare const AGENT_INFRASTRUCTURE_FAILURE_CODE: {
25
+ readonly controlledProcessLifecycle: "controlled_process_lifecycle";
26
+ };
27
+ export type AgentInfrastructureFailureCode = (typeof AGENT_INFRASTRUCTURE_FAILURE_CODE)[keyof typeof AGENT_INFRASTRUCTURE_FAILURE_CODE];
28
+ export type AgentFailureCode = AgentErrorCode | AgentInfrastructureFailureCode;
29
+ export type AgentFailure<C extends AgentErrorCode = AgentErrorCode> = {
30
+ readonly failureClass: typeof AGENT_FAILURE_CLASS.agent;
31
+ readonly failureCode: C;
32
+ } | {
33
+ readonly failureClass: typeof AGENT_FAILURE_CLASS.infrastructure;
34
+ readonly failureCode: AgentInfrastructureFailureCode;
35
+ };
36
+ export declare function agentFailure<C extends AgentErrorCode>(failureCode: C): AgentFailure<C>;
37
+ export declare function infrastructureFailure<C extends AgentErrorCode>(failureCode: AgentInfrastructureFailureCode): AgentFailure<C>;
19
38
  export declare const AUTH_FAILURE_REASON: {
20
39
  readonly notLoggedIn: "not_logged_in";
21
40
  readonly invalidApiKey: "invalid_api_key";
@@ -89,6 +108,7 @@ export type AgentErrorData = {
89
108
  };
90
109
  export type AgentErrorOptions<C extends AgentErrorCode> = {
91
110
  code: C;
111
+ classification: AgentFailure<C>;
92
112
  message: string;
93
113
  data: AgentErrorData[C];
94
114
  runId?: string;
@@ -99,11 +119,16 @@ export type AgentErrorOptions<C extends AgentErrorCode> = {
99
119
  };
100
120
  export declare class AgentError<C extends AgentErrorCode = AgentErrorCode> extends Error {
101
121
  readonly code: C;
122
+ readonly classification: AgentFailure<C>;
123
+ readonly failureCode: AgentFailure<C>["failureCode"];
124
+ readonly failureClass: AgentFailure<C>["failureClass"];
102
125
  readonly data: AgentErrorData[C];
103
126
  readonly runId: string | null;
104
127
  readonly agentId: string | null;
105
128
  readonly started: boolean;
106
129
  readonly durationMs: number;
130
+ static agentFailure<C extends AgentErrorCode>(failureCode: C): AgentFailure<C>;
131
+ static infrastructureFailure<C extends AgentErrorCode>(failureCode: AgentInfrastructureFailureCode): AgentFailure<C>;
107
132
  constructor(options: AgentErrorOptions<C>);
108
133
  }
109
134
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/core/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;CAWnB,CAAC;AAEX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,eAAO,MAAM,mB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,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAQxB;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,EACtD,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EACpB,QAAQ,EAAE;IACR,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,GACA,UAAU,CAAC,CAAC,CAAC,CAYf"}
@@ -15,6 +15,25 @@ export const AGENT_ERROR_CODE = {
15
15
  outputRejected: "output_rejected",
16
16
  failed: "failed",
17
17
  };
18
+ export const AGENT_FAILURE_CLASS = {
19
+ agent: "agent",
20
+ infrastructure: "infrastructure",
21
+ };
22
+ export const AGENT_INFRASTRUCTURE_FAILURE_CODE = {
23
+ controlledProcessLifecycle: "controlled_process_lifecycle",
24
+ };
25
+ export function agentFailure(failureCode) {
26
+ return {
27
+ failureClass: AGENT_FAILURE_CLASS.agent,
28
+ failureCode,
29
+ };
30
+ }
31
+ export function infrastructureFailure(failureCode) {
32
+ return {
33
+ failureClass: AGENT_FAILURE_CLASS.infrastructure,
34
+ failureCode,
35
+ };
36
+ }
18
37
  export const AUTH_FAILURE_REASON = {
19
38
  notLoggedIn: "not_logged_in",
20
39
  invalidApiKey: "invalid_api_key",
@@ -40,15 +59,27 @@ export const TIMEOUT_KIND = {
40
59
  const AGENT_ERROR_BRAND = Symbol.for("@alpacakit/agents.AgentError");
41
60
  export class AgentError extends Error {
42
61
  code;
62
+ classification;
63
+ failureCode;
64
+ failureClass;
43
65
  data;
44
66
  runId;
45
67
  agentId;
46
68
  started;
47
69
  durationMs;
70
+ static agentFailure(failureCode) {
71
+ return agentFailure(failureCode);
72
+ }
73
+ static infrastructureFailure(failureCode) {
74
+ return infrastructureFailure(failureCode);
75
+ }
48
76
  constructor(options) {
49
77
  super(options.message, options.cause === undefined ? undefined : { cause: options.cause });
50
78
  this.name = "AgentError";
51
79
  this.code = options.code;
80
+ this.classification = options.classification;
81
+ this.failureCode = options.classification.failureCode;
82
+ this.failureClass = options.classification.failureClass;
52
83
  this.data = options.data;
53
84
  this.runId = options.runId ?? null;
54
85
  this.agentId = options.agentId ?? null;
@@ -77,6 +108,7 @@ export function isAgentError(value, code) {
77
108
  export function withRunIdentity(error, identity) {
78
109
  return new AgentError({
79
110
  code: error.code,
111
+ classification: error.classification,
80
112
  message: error.message,
81
113
  data: error.data,
82
114
  runId: error.runId ?? identity.runId,