@ours.network/fleet 1.1.0-nightly.3 → 1.1.0-nightly.30

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 (208) hide show
  1. package/README.md +244 -40
  2. package/dist/agent-recovery-gate.d.ts +17 -0
  3. package/dist/agent-recovery-gate.js +135 -0
  4. package/dist/application/capabilities.js +18 -6
  5. package/dist/application/fleet-query-service.js +20 -5
  6. package/dist/application/role-command-service.js +9 -0
  7. package/dist/application/role-creation-service.d.ts +4 -4
  8. package/dist/application/role-creation-service.js +19 -1
  9. package/dist/application/role-repository.d.ts +4 -2
  10. package/dist/application/role-repository.js +6 -3
  11. package/dist/application/session-control.d.ts +3 -1
  12. package/dist/application/session-control.js +4 -2
  13. package/dist/application/task-room-service.d.ts +93 -40
  14. package/dist/application/task-room-service.js +579 -173
  15. package/dist/briefing.js +85 -24
  16. package/dist/build-info.json +4 -4
  17. package/dist/canonical-json.d.ts +2 -0
  18. package/dist/canonical-json.js +10 -0
  19. package/dist/cli.js +217 -51
  20. package/dist/config-yaml.d.ts +1 -1
  21. package/dist/config.d.ts +38 -3
  22. package/dist/config.js +240 -28
  23. package/dist/creation.d.ts +1 -1
  24. package/dist/creation.js +7 -4
  25. package/dist/daemon-recovery.d.ts +93 -0
  26. package/dist/daemon-recovery.js +328 -0
  27. package/dist/docs.d.ts +1 -1
  28. package/dist/docs.js +213 -42
  29. package/dist/doctor.d.ts +2 -0
  30. package/dist/doctor.js +54 -4
  31. package/dist/fleet-command-audit.d.ts +181 -0
  32. package/dist/fleet-command-audit.js +738 -0
  33. package/dist/fleet-proxy.d.ts +7 -2
  34. package/dist/harness/agent-session.d.ts +5 -0
  35. package/dist/harness/claude-code-session.d.ts +2 -0
  36. package/dist/harness/claude-code-session.js +6 -1
  37. package/dist/harness/claude-code.js +2 -0
  38. package/dist/harness/codex-app-server-proxy.d.ts +40 -0
  39. package/dist/harness/codex-app-server-proxy.js +348 -14
  40. package/dist/harness/codex-session.d.ts +11 -2
  41. package/dist/harness/codex-session.js +22 -2
  42. package/dist/harness/codex.d.ts +5 -1
  43. package/dist/harness/codex.js +110 -10
  44. package/dist/harness/types.d.ts +1 -1
  45. package/dist/index.d.ts +4 -3
  46. package/dist/index.js +3 -2
  47. package/dist/init-guidance.d.ts +1 -1
  48. package/dist/init-guidance.js +4 -3
  49. package/dist/init-wizard.d.ts +98 -0
  50. package/dist/init-wizard.js +631 -0
  51. package/dist/lifecycle-summary.d.ts +134 -0
  52. package/dist/lifecycle-summary.js +179 -0
  53. package/dist/loops/config.d.ts +10 -1
  54. package/dist/loops/config.js +38 -5
  55. package/dist/model-recovery.d.ts +1 -1
  56. package/dist/ops.js +2 -17
  57. package/dist/owner-channel/channel.d.ts +75 -3
  58. package/dist/owner-channel/channel.js +531 -123
  59. package/dist/owner-channel/commands.d.ts +28 -6
  60. package/dist/owner-channel/commands.js +112 -36
  61. package/dist/owner-channel/lifecycle-outbox.d.ts +24 -0
  62. package/dist/owner-channel/lifecycle-outbox.js +87 -0
  63. package/dist/owner-channel/ours-client.d.ts +19 -0
  64. package/dist/owner-channel/ours-client.js +3 -0
  65. package/dist/owner-channel/state.d.ts +2 -0
  66. package/dist/owner-channel/state.js +8 -2
  67. package/dist/permissions.js +1 -1
  68. package/dist/preset-bootstrap.d.ts +10 -0
  69. package/dist/preset-bootstrap.js +85 -0
  70. package/dist/preset-migration.d.ts +42 -0
  71. package/dist/preset-migration.js +450 -0
  72. package/dist/reports/artifact.d.ts +10 -0
  73. package/dist/reports/artifact.js +32 -0
  74. package/dist/reports/index.d.ts +5 -0
  75. package/dist/reports/index.js +5 -0
  76. package/dist/reports/render.d.ts +6 -0
  77. package/dist/reports/render.js +240 -0
  78. package/dist/reports/service.d.ts +42 -0
  79. package/dist/reports/service.js +57 -0
  80. package/dist/reports/tasks.d.ts +52 -0
  81. package/dist/reports/tasks.js +177 -0
  82. package/dist/reports/types.d.ts +315 -0
  83. package/dist/reports/types.js +6 -0
  84. package/dist/resolved-plan.js +13 -1
  85. package/dist/rooms-tasks/cli.d.ts +2 -0
  86. package/dist/rooms-tasks/cli.js +519 -261
  87. package/dist/rooms-tasks/close.d.ts +9 -1
  88. package/dist/rooms-tasks/close.js +23 -7
  89. package/dist/rooms-tasks/config.js +16 -29
  90. package/dist/rooms-tasks/cowork-adapter.d.ts +5 -0
  91. package/dist/rooms-tasks/cowork-adapter.js +13 -0
  92. package/dist/rooms-tasks/deletion.d.ts +51 -0
  93. package/dist/rooms-tasks/deletion.js +217 -0
  94. package/dist/rooms-tasks/external-worker.d.ts +9 -0
  95. package/dist/rooms-tasks/external-worker.js +52 -9
  96. package/dist/rooms-tasks/launch-snapshot.d.ts +19 -0
  97. package/dist/rooms-tasks/launch-snapshot.js +181 -0
  98. package/dist/rooms-tasks/member-overrides.d.ts +30 -0
  99. package/dist/rooms-tasks/member-overrides.js +204 -0
  100. package/dist/rooms-tasks/member-startup.d.ts +1 -0
  101. package/dist/rooms-tasks/member-startup.js +9 -2
  102. package/dist/rooms-tasks/provision.js +146 -56
  103. package/dist/rooms-tasks/room-state.d.ts +1 -0
  104. package/dist/rooms-tasks/room-state.js +12 -1
  105. package/dist/rooms-tasks/task-room-name.d.ts +12 -0
  106. package/dist/rooms-tasks/task-room-name.js +61 -0
  107. package/dist/rooms-tasks/task-state.d.ts +115 -3
  108. package/dist/rooms-tasks/task-state.js +361 -11
  109. package/dist/rooms-tasks/templates.d.ts +4 -2
  110. package/dist/rooms-tasks/templates.js +42 -78
  111. package/dist/rooms-tasks/terminal.d.ts +3 -0
  112. package/dist/rooms-tasks/terminal.js +10 -4
  113. package/dist/rooms-tasks/types.d.ts +94 -8
  114. package/dist/rooms-tasks/types.js +14 -1
  115. package/dist/runner.d.ts +12 -2
  116. package/dist/runner.js +167 -56
  117. package/dist/session/acp.d.ts +9 -1
  118. package/dist/session/acp.js +35 -9
  119. package/dist/session/arbiter.d.ts +2 -1
  120. package/dist/session/arbiter.js +2 -0
  121. package/dist/session/codex-app-server-transport.d.ts +53 -0
  122. package/dist/session/codex-app-server-transport.js +184 -0
  123. package/dist/session/codex-app-server.d.ts +122 -0
  124. package/dist/session/codex-app-server.js +1031 -0
  125. package/dist/session/control.d.ts +14 -1
  126. package/dist/session/control.js +51 -0
  127. package/dist/session/conversation-types.d.ts +4 -4
  128. package/dist/session/types.d.ts +24 -6
  129. package/dist/session/types.js +28 -0
  130. package/dist/spawn.d.ts +9 -0
  131. package/dist/spawn.js +77 -9
  132. package/dist/temp-lifecycle.d.ts +1 -1
  133. package/dist/web/fleet-config-service.d.ts +1 -0
  134. package/dist/web/fleet-config-service.js +27 -8
  135. package/dist/web/runtime.js +11 -6
  136. package/dist/web/server.js +28 -1
  137. package/dist/web-app/assets/{index-BbTc5KtZ.js → index-C0h3ALvs.js} +8 -8
  138. package/dist/web-app/index.html +1 -1
  139. package/package.json +5 -4
  140. package/presets/brain-catalog.json +17 -0
  141. package/presets/fleet/agent_templates/Critic.yaml +5 -0
  142. package/presets/fleet/agent_templates/Developer.yaml +5 -0
  143. package/presets/fleet/agent_templates/LocalCoordinator.yaml +50 -0
  144. package/presets/fleet/agents/FleetCoordinator.yaml +3 -0
  145. package/presets/fleet/brains/claude-default.yaml +5 -0
  146. package/presets/fleet/brains/claude-fable-5-high.yaml +5 -0
  147. package/presets/fleet/brains/claude-fable-5-low.yaml +5 -0
  148. package/presets/fleet/brains/claude-fable-5-max.yaml +5 -0
  149. package/presets/fleet/brains/claude-fable-5-medium.yaml +5 -0
  150. package/presets/fleet/brains/claude-fable-5-xhigh.yaml +5 -0
  151. package/presets/fleet/brains/claude-opus-5-high.yaml +5 -0
  152. package/presets/fleet/brains/claude-opus-5-low.yaml +5 -0
  153. package/presets/fleet/brains/claude-opus-5-max.yaml +5 -0
  154. package/presets/fleet/brains/claude-opus-5-medium.yaml +5 -0
  155. package/presets/fleet/brains/claude-opus-5-xhigh.yaml +5 -0
  156. package/presets/fleet/brains/claude-sonnet-5-high.yaml +5 -0
  157. package/presets/fleet/brains/claude-sonnet-5-low.yaml +5 -0
  158. package/presets/fleet/brains/claude-sonnet-5-max.yaml +5 -0
  159. package/presets/fleet/brains/claude-sonnet-5-medium.yaml +5 -0
  160. package/presets/fleet/brains/claude-sonnet-5-xhigh.yaml +5 -0
  161. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-high.yaml +5 -0
  162. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-low.yaml +5 -0
  163. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-medium.yaml +5 -0
  164. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-xhigh.yaml +5 -0
  165. package/presets/fleet/brains/codex-gpt-5-4-high.yaml +5 -0
  166. package/presets/fleet/brains/codex-gpt-5-4-low.yaml +5 -0
  167. package/presets/fleet/brains/codex-gpt-5-4-medium.yaml +5 -0
  168. package/presets/fleet/brains/codex-gpt-5-4-mini-high.yaml +5 -0
  169. package/presets/fleet/brains/codex-gpt-5-4-mini-low.yaml +5 -0
  170. package/presets/fleet/brains/codex-gpt-5-4-mini-medium.yaml +5 -0
  171. package/presets/fleet/brains/codex-gpt-5-4-mini-xhigh.yaml +5 -0
  172. package/presets/fleet/brains/codex-gpt-5-4-xhigh.yaml +5 -0
  173. package/presets/fleet/brains/codex-gpt-5-5-high.yaml +5 -0
  174. package/presets/fleet/brains/codex-gpt-5-5-low.yaml +5 -0
  175. package/presets/fleet/brains/codex-gpt-5-5-medium.yaml +5 -0
  176. package/presets/fleet/brains/codex-gpt-5-5-xhigh.yaml +5 -0
  177. package/presets/fleet/brains/codex-gpt-5-6-luna-high.yaml +5 -0
  178. package/presets/fleet/brains/codex-gpt-5-6-luna-low.yaml +5 -0
  179. package/presets/fleet/brains/codex-gpt-5-6-luna-max.yaml +5 -0
  180. package/presets/fleet/brains/codex-gpt-5-6-luna-medium.yaml +5 -0
  181. package/presets/fleet/brains/codex-gpt-5-6-luna-xhigh.yaml +5 -0
  182. package/presets/fleet/brains/codex-gpt-5-6-sol-high.yaml +5 -0
  183. package/presets/fleet/brains/codex-gpt-5-6-sol-low.yaml +5 -0
  184. package/presets/fleet/brains/codex-gpt-5-6-sol-max.yaml +5 -0
  185. package/presets/fleet/brains/codex-gpt-5-6-sol-medium.yaml +5 -0
  186. package/presets/fleet/brains/codex-gpt-5-6-sol-ultra.yaml +5 -0
  187. package/presets/fleet/brains/codex-gpt-5-6-sol-xhigh.yaml +5 -0
  188. package/presets/fleet/brains/codex-gpt-5-6-terra-high.yaml +5 -0
  189. package/presets/fleet/brains/codex-gpt-5-6-terra-low.yaml +5 -0
  190. package/presets/fleet/brains/codex-gpt-5-6-terra-max.yaml +5 -0
  191. package/presets/fleet/brains/codex-gpt-5-6-terra-medium.yaml +5 -0
  192. package/presets/fleet/brains/codex-gpt-5-6-terra-ultra.yaml +5 -0
  193. package/presets/fleet/brains/codex-gpt-5-6-terra-xhigh.yaml +5 -0
  194. package/presets/fleet/brains/codex-gpt-6-astra-high.yaml +5 -0
  195. package/presets/fleet/brains/codex-gpt-6-astra-low.yaml +5 -0
  196. package/presets/fleet/brains/codex-gpt-6-astra-max.yaml +5 -0
  197. package/presets/fleet/brains/codex-gpt-6-astra-medium.yaml +5 -0
  198. package/presets/fleet/brains/codex-gpt-6-astra-ultra.yaml +5 -0
  199. package/presets/fleet/brains/codex-gpt-6-astra-xhigh.yaml +5 -0
  200. package/presets/fleet/roles/Coordinator.yaml +30 -0
  201. package/presets/fleet/roles/Critic.yaml +28 -0
  202. package/presets/fleet/roles/Developer.yaml +28 -0
  203. package/presets/fleet/roles/LocalCoordinator.yaml +35 -0
  204. package/presets/fleet/room_templates/pair.yaml +13 -0
  205. package/presets/fleet/room_templates/single.yaml +9 -0
  206. package/presets/fleet/room_templates/team.yaml +16 -0
  207. package/presets/fleet.yaml +7 -0
  208. package/presets/manifest.json +6 -0
@@ -0,0 +1,134 @@
1
+ import type { AgentSelection, ApprovalMode, FilesystemMode, FleetPermissionMode, MonitorInterrupt, MonitorMode, ResolvedRole, SessionBackendId, UnattendedMode } from './config.js';
2
+ import type { IsolationBackendId, NetworkMode, OnUnavailable } from './isolation/types.js';
3
+ /**
4
+ * Operator-facing launch configuration captured at the launch boundary from
5
+ * the exact ResolvedRole that was spawned. It is the single source for every
6
+ * Fleet lifecycle/report surface (CLI and owner-channel/Messenger).
7
+ *
8
+ * Security boundary: this object is a strict whitelist. It must never carry
9
+ * env, cwd or any local path, harness_options, session_options, owner_channel,
10
+ * or auth_proxy content. Hashes are secondary provenance only, never the
11
+ * primary description.
12
+ */
13
+ export interface AgentLaunchConfiguration {
14
+ version: 1;
15
+ /** Agent template / launch definition label when one was selected. */
16
+ template?: string;
17
+ role: SelectionOrigin;
18
+ brain: SelectionOrigin;
19
+ harness: string;
20
+ session: SessionBackendId;
21
+ /**
22
+ * Model observed effective at launch. `null` reports runtime behavior — the
23
+ * harness ran its own default — not whether the author wrote `model: null`
24
+ * or omitted the field; effectiveRoleModel cannot distinguish those.
25
+ */
26
+ model: string | null;
27
+ effort?: string;
28
+ /** Concise first-line mission label (or Cowork-role fallback), never the full mission. */
29
+ mission?: string;
30
+ approval: ApprovalMode;
31
+ filesystem: FilesystemMode;
32
+ unattended: UnattendedMode;
33
+ /** Portable policy plus the exact native runtime mode after harness_options. */
34
+ permissionMode: {
35
+ fleetMode: FleetPermissionMode;
36
+ nativeMode: string;
37
+ };
38
+ monitor: {
39
+ mode: MonitorMode;
40
+ interrupt: MonitorInterrupt;
41
+ };
42
+ /** Requested isolation policy only — never resolved runtime facts or host paths. */
43
+ isolation?: {
44
+ requested: IsolationBackendId;
45
+ on_unavailable?: OnUnavailable;
46
+ network?: NetworkMode;
47
+ read_mounts?: number;
48
+ write_mounts?: number;
49
+ };
50
+ /** Present only for temporary agents; prompt bodies are never presented. */
51
+ loops?: {
52
+ source: 'agent-template' | 'cli' | 'omitted';
53
+ policy: 'skip-if-busy';
54
+ entries: Array<{
55
+ name: string;
56
+ enabled: boolean;
57
+ intervalMs: number;
58
+ initialDelayMs: number;
59
+ jitterMs: number;
60
+ prompt: {
61
+ bytes: number;
62
+ sha256: string;
63
+ };
64
+ }>;
65
+ };
66
+ }
67
+ /** Where a Brain/Role selection came from; labels are human, hashes secondary. */
68
+ export type SelectionOrigin = {
69
+ kind: 'named';
70
+ ref: string;
71
+ } | {
72
+ kind: 'inline';
73
+ fingerprint?: string;
74
+ } | {
75
+ kind: 'unknown';
76
+ };
77
+ export declare const MISSION_LABEL_MAX = 80;
78
+ /**
79
+ * The inline fingerprint is always computed here from the canonical inline
80
+ * body; provenance can never be an arbitrary caller string.
81
+ */
82
+ export declare function selectionOrigin(selection: AgentSelection | undefined): SelectionOrigin;
83
+ export declare function missionLabel(mission: string | undefined): string | undefined;
84
+ /**
85
+ * Build the presentation from the exact resolved launch state. `origins`
86
+ * carries the authoring-time selections and template label because a merged
87
+ * ResolvedRole no longer distinguishes preset references from inline bodies.
88
+ * `permissionMode` is required at capture time: every supported harness
89
+ * adapter reports it, and the managed-spawn receiver gets it over the wire
90
+ * and must never re-resolve mutable configuration.
91
+ */
92
+ export declare function summarizeResolvedLaunch(role: ResolvedRole, origins: {
93
+ role: SelectionOrigin;
94
+ brain: SelectionOrigin;
95
+ template?: string;
96
+ permissionMode: {
97
+ fleetMode: FleetPermissionMode;
98
+ nativeMode: string;
99
+ };
100
+ /** Shown when the resolved role has no mission text (e.g. Cowork role name). */
101
+ missionFallback?: string;
102
+ }): AgentLaunchConfiguration;
103
+ /**
104
+ * Component budget for one rendered agent line. The complete mandatory
105
+ * rendering must always fit — that is a validity condition of a current-v1
106
+ * configuration, enforced by mandatoryConfigurationFits at the builder AND
107
+ * the wire boundary — while optional components (monitor, isolation) are
108
+ * dropped whole with a visible `…` marker past this budget.
109
+ */
110
+ export declare const AGENT_LINE_MAX_CODE_POINTS = 1500;
111
+ export declare const AGENT_LINE_MAX_BYTES = 5000;
112
+ /**
113
+ * Validity condition of a current-v1 configuration: its complete mandatory
114
+ * rendering fits the per-line budget with the optional-omission suffix
115
+ * reserved. Escaping and code-fence growth (a value made of backticks can
116
+ * more than triple its code span) make this depend on rendered size, not raw
117
+ * field lengths, so both summarizeResolvedLaunch and the wire validator call
118
+ * this instead of trusting per-field caps.
119
+ */
120
+ export declare function mandatoryConfigurationFits(configuration: AgentLaunchConfiguration): boolean;
121
+ /**
122
+ * Render one agent's configuration as a single escaped Markdown line segment.
123
+ * This is the only escaping boundary: callers pass raw values and must not
124
+ * escape the result again (it is safe as a markdownItems entry and inside
125
+ * owner-channel lifecycle messages). Every mandatory component always
126
+ * renders — mandatoryConfigurationFits guarantees the fit for every produced
127
+ * or wire-accepted configuration; only optional components may be dropped,
128
+ * whole (never splitting a Markdown span), with a visible `…`.
129
+ */
130
+ export declare function renderAgentConfiguration(configuration: AgentLaunchConfiguration | undefined, fallback?: {
131
+ role?: string;
132
+ brain?: string;
133
+ permissions?: string;
134
+ }): string;
@@ -0,0 +1,179 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { Buffer } from 'node:buffer';
3
+ import { canonicalJson } from './canonical-json.js';
4
+ import { effectiveRoleModel } from './model-env.js';
5
+ import { markdownCode, markdownProse } from './rooms-tasks/markdown.js';
6
+ const FINGERPRINT_HEX = 12;
7
+ export const MISSION_LABEL_MAX = 80;
8
+ /**
9
+ * The inline fingerprint is always computed here from the canonical inline
10
+ * body; provenance can never be an arbitrary caller string.
11
+ */
12
+ export function selectionOrigin(selection) {
13
+ if (!selection)
14
+ return { kind: 'unknown' };
15
+ if ('ref' in selection)
16
+ return { kind: 'named', ref: selection.ref };
17
+ const fingerprint = createHash('sha256').update(canonicalJson(selection.inline)).digest('hex');
18
+ return { kind: 'inline', fingerprint: fingerprint.slice(0, FINGERPRINT_HEX) };
19
+ }
20
+ export function missionLabel(mission) {
21
+ const line = mission?.trim().split('\n', 1)[0]?.trim();
22
+ if (!line)
23
+ return undefined;
24
+ const points = Array.from(line);
25
+ return points.length > MISSION_LABEL_MAX
26
+ ? `${points.slice(0, MISSION_LABEL_MAX - 1).join('')}…` : line;
27
+ }
28
+ /**
29
+ * Build the presentation from the exact resolved launch state. `origins`
30
+ * carries the authoring-time selections and template label because a merged
31
+ * ResolvedRole no longer distinguishes preset references from inline bodies.
32
+ * `permissionMode` is required at capture time: every supported harness
33
+ * adapter reports it, and the managed-spawn receiver gets it over the wire
34
+ * and must never re-resolve mutable configuration.
35
+ */
36
+ export function summarizeResolvedLaunch(role, origins) {
37
+ const mission = missionLabel(role.mission) ?? missionLabel(origins.missionFallback);
38
+ const fs = role.isolation?.fs;
39
+ const configuration = {
40
+ version: 1,
41
+ ...(origins.template ? { template: origins.template } : {}),
42
+ role: origins.role,
43
+ brain: origins.brain,
44
+ harness: role.harness,
45
+ session: role.session,
46
+ model: effectiveRoleModel(role) ?? null,
47
+ ...(role.effort ? { effort: role.effort } : {}),
48
+ ...(mission ? { mission } : {}),
49
+ approval: role.permissions.approval,
50
+ filesystem: role.permissions.filesystem,
51
+ unattended: role.permissions.unattended,
52
+ permissionMode: origins.permissionMode,
53
+ monitor: { mode: role.monitor.mode, interrupt: role.monitor.interrupt },
54
+ ...(role.isolation?.backend ? { isolation: {
55
+ requested: role.isolation.backend,
56
+ ...(role.isolation.on_unavailable ? { on_unavailable: role.isolation.on_unavailable } : {}),
57
+ ...(role.isolation.network ? { network: role.isolation.network } : {}),
58
+ ...(fs?.read?.length ? { read_mounts: fs.read.length } : {}),
59
+ ...(fs?.write?.length ? { write_mounts: fs.write.length } : {}),
60
+ } } : {}),
61
+ ...(role.temporaryLoopSource ? { loops: {
62
+ source: role.temporaryLoopSource,
63
+ policy: 'skip-if-busy',
64
+ entries: (role.temporaryLoops ?? role.loops ?? []).map(loop => ({
65
+ name: loop.name, enabled: loop.enabled, intervalMs: loop.intervalMs,
66
+ initialDelayMs: loop.initialDelayMs, jitterMs: loop.jitterMs,
67
+ prompt: { bytes: loop.promptBytes, sha256: loop.promptHash },
68
+ })),
69
+ } } : {}),
70
+ };
71
+ // A configuration whose complete mandatory rendering cannot fit must never
72
+ // be produced; real resolved values sit far below the budget, so this is a
73
+ // capture defect, not an expected path.
74
+ if (!mandatoryConfigurationFits(configuration))
75
+ throw new Error('agent launch presentation exceeds the mandatory rendering budget');
76
+ return configuration;
77
+ }
78
+ /**
79
+ * Component budget for one rendered agent line. The complete mandatory
80
+ * rendering must always fit — that is a validity condition of a current-v1
81
+ * configuration, enforced by mandatoryConfigurationFits at the builder AND
82
+ * the wire boundary — while optional components (monitor, isolation) are
83
+ * dropped whole with a visible `…` marker past this budget.
84
+ */
85
+ export const AGENT_LINE_MAX_CODE_POINTS = 1_500;
86
+ export const AGENT_LINE_MAX_BYTES = 5_000;
87
+ const codePoints = (value) => Array.from(value).length;
88
+ const utf8 = (value) => Buffer.byteLength(value, 'utf8');
89
+ const OPTIONAL_OMISSION_SUFFIX = '; …';
90
+ function selectionComponent(kind, value) {
91
+ if (value.kind === 'named')
92
+ return `${kind} preset ${markdownCode(value.ref)}`;
93
+ if (value.kind === 'inline')
94
+ return `inline ${kind}${value.fingerprint ? ` (def ${markdownCode(value.fingerprint)})` : ''}`;
95
+ return `${kind} unknown`;
96
+ }
97
+ /**
98
+ * The complete mandatory rendering: template, origins, mission, harness,
99
+ * model, effort, portable policy triple, and fleet/native permission mode.
100
+ * These must never be omitted from an operator-facing line.
101
+ */
102
+ function mandatoryComponents(configuration) {
103
+ return [
104
+ configuration.template ? `template ${markdownCode(configuration.template)}` : undefined,
105
+ selectionComponent('Role', configuration.role),
106
+ configuration.mission ? `mission “${markdownProse(configuration.mission)}”` : undefined,
107
+ selectionComponent('Brain', configuration.brain),
108
+ `harness ${markdownCode(configuration.harness)}`,
109
+ `model ${configuration.model === null ? 'harness-default' : markdownCode(configuration.model)}`,
110
+ configuration.effort ? `effort ${markdownProse(configuration.effort)}` : undefined,
111
+ `approval=${configuration.approval}, filesystem=${configuration.filesystem}, `
112
+ + `unattended=${configuration.unattended}`,
113
+ `mode ${configuration.permissionMode.fleetMode}/${markdownProse(configuration.permissionMode.nativeMode)}`,
114
+ ].filter((part) => Boolean(part));
115
+ }
116
+ function optionalComponents(configuration) {
117
+ return [
118
+ `monitor ${configuration.monitor.mode}/${String(configuration.monitor.interrupt)}`,
119
+ configuration.isolation
120
+ ? `isolation requested ${configuration.isolation.requested}`
121
+ + `${configuration.isolation.network ? `, net ${configuration.isolation.network}` : ''}`
122
+ + `${configuration.isolation.on_unavailable ? `, on-unavailable ${configuration.isolation.on_unavailable}` : ''}`
123
+ + `${configuration.isolation.read_mounts || configuration.isolation.write_mounts
124
+ ? `, mounts +${configuration.isolation.read_mounts ?? 0}ro/+${configuration.isolation.write_mounts ?? 0}rw` : ''}`
125
+ : undefined,
126
+ configuration.loops
127
+ ? configuration.loops.source === 'omitted'
128
+ ? 'temporary loops omitted (legacy behavior)'
129
+ : configuration.loops.entries.length === 0
130
+ ? `temporary loops disabled (source ${configuration.loops.source})`
131
+ : `temporary loops ${configuration.loops.entries.map(loop => `${loop.name}:${loop.enabled ? 'enabled' : 'disabled'}`
132
+ + ` interval=${loop.intervalMs}ms delay=${loop.initialDelayMs}ms jitter=${loop.jitterMs}ms`
133
+ + ` prompt=${loop.prompt.bytes}B/${loop.prompt.sha256.slice(0, 12)}`).join(', ')}; policy skip-if-busy; source ${configuration.loops.source}`
134
+ : undefined,
135
+ ].filter((part) => Boolean(part));
136
+ }
137
+ /**
138
+ * Validity condition of a current-v1 configuration: its complete mandatory
139
+ * rendering fits the per-line budget with the optional-omission suffix
140
+ * reserved. Escaping and code-fence growth (a value made of backticks can
141
+ * more than triple its code span) make this depend on rendered size, not raw
142
+ * field lengths, so both summarizeResolvedLaunch and the wire validator call
143
+ * this instead of trusting per-field caps.
144
+ */
145
+ export function mandatoryConfigurationFits(configuration) {
146
+ const reserved = `${mandatoryComponents(configuration).join('; ')}${OPTIONAL_OMISSION_SUFFIX}`;
147
+ return codePoints(reserved) <= AGENT_LINE_MAX_CODE_POINTS && utf8(reserved) <= AGENT_LINE_MAX_BYTES;
148
+ }
149
+ /**
150
+ * Render one agent's configuration as a single escaped Markdown line segment.
151
+ * This is the only escaping boundary: callers pass raw values and must not
152
+ * escape the result again (it is safe as a markdownItems entry and inside
153
+ * owner-channel lifecycle messages). Every mandatory component always
154
+ * renders — mandatoryConfigurationFits guarantees the fit for every produced
155
+ * or wire-accepted configuration; only optional components may be dropped,
156
+ * whole (never splitting a Markdown span), with a visible `…`.
157
+ */
158
+ export function renderAgentConfiguration(configuration, fallback) {
159
+ if (!configuration) {
160
+ const labels = [
161
+ fallback?.role ? `Role ${markdownProse(fallback.role)}` : undefined,
162
+ fallback?.brain ? `Brain ${markdownProse(fallback.brain)}` : undefined,
163
+ fallback?.permissions ? `permissions ${markdownProse(fallback.permissions)}` : undefined,
164
+ ].filter(Boolean).join('; ');
165
+ return `legacy launch; resolved details unavailable${labels ? ` (${labels})` : ''}`;
166
+ }
167
+ let line = mandatoryComponents(configuration).join('; ');
168
+ let omitted = false;
169
+ for (const part of optionalComponents(configuration)) {
170
+ const next = `${line}; ${part}`;
171
+ if (codePoints(`${next}${OPTIONAL_OMISSION_SUFFIX}`) > AGENT_LINE_MAX_CODE_POINTS
172
+ || utf8(`${next}${OPTIONAL_OMISSION_SUFFIX}`) > AGENT_LINE_MAX_BYTES) {
173
+ omitted = true;
174
+ continue;
175
+ }
176
+ line = next;
177
+ }
178
+ return omitted ? `${line}${OPTIONAL_OMISSION_SUFFIX}` : line;
179
+ }
@@ -7,6 +7,9 @@ export interface LoopConfig {
7
7
  initial_delay?: string;
8
8
  jitter?: string;
9
9
  }
10
+ /** Agent Template-local loops are implicitly scoped to the temporary agent. */
11
+ export type AgentLoopConfig = Omit<LoopConfig, 'roles'>;
12
+ export type AgentLoopsConfig = Record<string, AgentLoopConfig>;
10
13
  export interface ResolvedLoop {
11
14
  name: string;
12
15
  selectors: string[];
@@ -24,7 +27,13 @@ export interface ResolvedRoleLoop extends Omit<ResolvedLoop, 'selectors' | 'role
24
27
  role: string;
25
28
  definitionHash: string;
26
29
  }
27
- export declare function resolveLoops(block: unknown, baseFile: string, roles: ResolvedRole[], vars: Record<string, string>): {
30
+ export declare function resolveLoops(block: unknown, baseFile: string, roles: ResolvedRole[], vars: Record<string, string>, options?: {
31
+ assertTrustedSource?: boolean;
32
+ }): {
28
33
  loops: ResolvedLoop[];
29
34
  byRole: Map<string, ResolvedRoleLoop[]>;
30
35
  };
36
+ /** Resolve the canonical Agent Template schema without inventing a second loop language. */
37
+ export declare function resolveAgentLoops(block: unknown, role: ResolvedRole, sourceFile?: string): ResolvedRoleLoop[];
38
+ /** Fully explicit private snapshot form; prompt text is retained for deterministic recovery. */
39
+ export declare function canonicalAgentLoops(loops: ResolvedRoleLoop[]): AgentLoopsConfig;
@@ -1,13 +1,15 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { lstatSync } from 'node:fs';
3
3
  import { ConfigError, ROLE_NAME_RE } from '../config.js';
4
- import { parseDuration } from '../duration.js';
4
+ import { sessionBackendCapabilities } from '../session/types.js';
5
+ import { formatDuration, parseDuration } from '../duration.js';
5
6
  const LOOP_KEYS = ['roles', 'interval', 'prompt', 'enabled', 'initial_delay', 'jitter'];
6
7
  const MIN_INTERVAL_MS = 60_000;
7
8
  const MAX_DURATION_MS = 30 * 24 * 60 * 60 * 1_000;
8
9
  const MAX_JITTER_MS = 60 * 60 * 1_000;
9
10
  const MAX_PROMPT_BYTES = 16 * 1024;
10
11
  const MAX_PROMPT_SCALARS = 12_000;
12
+ const MAX_AGENT_LOOPS = 64;
11
13
  function substitute(value, vars) {
12
14
  if (typeof value === 'string')
13
15
  return value.replace(/\$\{(\w+)\}/g, (match, key) => key in vars ? String(vars[key]) : match);
@@ -47,7 +49,7 @@ function normalizePrompt(raw, where) {
47
49
  function digest(value) {
48
50
  return createHash('sha256').update(JSON.stringify(value)).digest('hex');
49
51
  }
50
- export function resolveLoops(block, baseFile, roles, vars) {
52
+ export function resolveLoops(block, baseFile, roles, vars, options = {}) {
51
53
  const byRole = new Map(roles.map(role => [role.name, []]));
52
54
  if (block === undefined || block === null)
53
55
  return { loops: [], byRole };
@@ -90,8 +92,8 @@ export function resolveLoops(block, baseFile, roles, vars) {
90
92
  const prompt = normalizePrompt(value.prompt, `${where}: prompt`);
91
93
  if (enabled)
92
94
  for (const role of selected) {
93
- if (role.session !== 'acp')
94
- throw new ConfigError(`${where} selects role '${role.name}' with session '${role.session}'; scheduled loops require session: acp`);
95
+ if (!sessionBackendCapabilities(role.session, role.harness).promptInput)
96
+ throw new ConfigError(`${where} selects role '${role.name}' with session '${role.session}'; scheduled loops require managed prompt input`);
95
97
  }
96
98
  const promptHash = digest(prompt);
97
99
  const resolved = {
@@ -113,10 +115,41 @@ export function resolveLoops(block, baseFile, roles, vars) {
113
115
  for (const values of byRole.values())
114
116
  values.sort((a, b) => a.name.localeCompare(b.name));
115
117
  out.sort((a, b) => a.name.localeCompare(b.name));
116
- if (out.some(loop => loop.enabled))
118
+ if (out.some(loop => loop.enabled) && options.assertTrustedSource !== false)
117
119
  assertSafeLoopConfig(baseFile);
118
120
  return { loops: out, byRole };
119
121
  }
122
+ /** Resolve the canonical Agent Template schema without inventing a second loop language. */
123
+ export function resolveAgentLoops(block, role, sourceFile = '(temporary Agent loop)') {
124
+ if (block === undefined)
125
+ return [];
126
+ if (!block || typeof block !== 'object' || Array.isArray(block))
127
+ throw new ConfigError(`${sourceFile}: Agent loops must be a non-empty map`);
128
+ if (!Object.keys(block).length)
129
+ throw new ConfigError(`${sourceFile}: Agent loops must be non-empty; use an explicit no-loops override to disable template loops`);
130
+ if (Object.keys(block).length > MAX_AGENT_LOOPS)
131
+ throw new ConfigError(`${sourceFile}: Agent loops may contain at most ${MAX_AGENT_LOOPS} entries`);
132
+ const scoped = Object.fromEntries(Object.entries(block).map(([name, raw]) => {
133
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
134
+ return [name, raw];
135
+ const value = raw;
136
+ if (Object.hasOwn(value, 'roles'))
137
+ throw new ConfigError(`${sourceFile}: Agent loop '${name}' has unknown key roles; Agent loops are implicitly scoped`);
138
+ return [name, { ...value, roles: [role.name] }];
139
+ }));
140
+ return resolveLoops(scoped, sourceFile, [role], {}, { assertTrustedSource: false })
141
+ .byRole.get(role.name) ?? [];
142
+ }
143
+ /** Fully explicit private snapshot form; prompt text is retained for deterministic recovery. */
144
+ export function canonicalAgentLoops(loops) {
145
+ return Object.fromEntries(loops.map(loop => [loop.name, {
146
+ enabled: loop.enabled,
147
+ interval: formatDuration(loop.intervalMs),
148
+ initial_delay: formatDuration(loop.initialDelayMs),
149
+ jitter: formatDuration(loop.jitterMs),
150
+ prompt: loop.prompt,
151
+ }]));
152
+ }
120
153
  function assertSafeLoopConfig(path) {
121
154
  let stat;
122
155
  try {
@@ -5,7 +5,7 @@ export interface FailureEvidence {
5
5
  httpStatus?: number;
6
6
  model?: string;
7
7
  confidence: 'low' | 'medium' | 'high';
8
- source: 'claude-pane' | 'acp' | 'auth-proxy';
8
+ source: 'claude-pane' | 'acp' | 'codex-app-server' | 'auth-proxy';
9
9
  observedAt: string;
10
10
  }
11
11
  export interface ModelRecoveryLedger {
package/dist/ops.js CHANGED
@@ -179,23 +179,8 @@ async function reconcileWatchdogScheduler(cfg, deps, configPath) {
179
179
  }
180
180
  }
181
181
  export async function down(cfg, names, deps) {
182
- const roles = names.length ? names.map(name => cfg.roles.find(role => role.name === name)) : cfg.roles;
183
- for (let index = 0; index < roles.length; index++) {
184
- const role = roles[index];
185
- const requested = names[index];
186
- if (!role && requested && /^[A-Za-z0-9_-]+$/.test(requested)
187
- && existsSync(agentDir(requested, true))) {
188
- try {
189
- const outcome = await stopTempSupervisor(requested, { exec: deps.exec ?? realExec });
190
- deps.log(`■ ${outcome === 'stopped' ? 'stopping' : 'stopped'} temporary role ${requested}`);
191
- }
192
- catch (e) {
193
- deps.log(` ! could not stop temporary role ${requested}: ${e instanceof Error ? e.message : String(e)}`);
194
- }
195
- continue;
196
- }
197
- if (!role)
198
- throw new Error(`no such role '${requested}'`);
182
+ const roles = selectRoles(cfg, names);
183
+ for (const role of roles) {
199
184
  // Never swallow the backend's reason. "maybe not running" hid real stop
200
185
  // failures — a wedged unit, an unreachable user bus — behind a guess.
201
186
  try {
@@ -2,6 +2,7 @@ import { type OwnerChannelConfig } from '../config.js';
2
2
  import { type AgentSession } from '../session/types.js';
3
3
  import { type OwnerFleetOps } from './commands.js';
4
4
  import type { ManagedFleetSpawnResult } from '../fleet-proxy.js';
5
+ import { type FleetAuditAttempt, type FleetAuditPresentation, type FleetCommandOutcomeClass } from '../fleet-command-audit.js';
5
6
  import { type OursOps } from './ours-client.js';
6
7
  import { type OwnerUpdatePhase } from './notices.js';
7
8
  import { type OwnerEntry } from './state.js';
@@ -27,14 +28,45 @@ export interface OwnerChannelOptions {
27
28
  binderDeps?: OwnerBinderDeps;
28
29
  /** Pre-acquired by the runner so the predecessor control socket remains reachable while waiting. */
29
30
  binderLease?: OwnerBinderLease;
31
+ recoveryDeps?: {
32
+ now(): number;
33
+ setTimer(fn: () => void, ms: number): ReturnType<typeof setTimeout>;
34
+ clearTimer(timer: ReturnType<typeof setTimeout>): void;
35
+ deadlineMs?: number;
36
+ };
30
37
  }
31
38
  export interface OwnerChannelHandle {
32
39
  start(): Promise<void>;
33
40
  drain(): Promise<void>;
34
41
  close(): Promise<void>;
42
+ /** Reattach this same supervisor-owned channel after a daemon generation change. */
43
+ recover?(epoch: string): Promise<void>;
44
+ /** False when shutdown skipped client disposal because quiescence was unproven. */
45
+ binderReleaseSafe?(): boolean;
35
46
  manage(request: OwnerChannelManagementRequest): Promise<OwnerChannelManagementResult>;
36
47
  /** Fleet-owned deterministic lifecycle notice; absent on legacy test doubles. */
37
48
  notifyFleetSpawn?(event: ManagedFleetSpawnResult): Promise<void>;
49
+ notifyFleetLifecycle?(presentations: FleetAuditPresentation[]): Promise<void>;
50
+ beginFleetCommandAudit?(requestId: string, argv: string[]): Promise<FleetAuditAttempt>;
51
+ finishFleetCommandAudit?(input: {
52
+ correlationId: string;
53
+ class: FleetCommandOutcomeClass;
54
+ exitCode?: number;
55
+ effect: 'not_started' | 'completed' | 'unknown';
56
+ resourceIds?: Record<string, string>;
57
+ presentations?: FleetAuditPresentation[];
58
+ }): Promise<FleetAuditAttempt>;
59
+ }
60
+ export declare const OWNER_RECOVERY_QUEUE_CAPACITY = 32;
61
+ export declare const OWNER_RECOVERY_DEGRADED = "OWNER_RECOVERY_DEGRADED";
62
+ export declare class OwnerRecoveryDegradedError extends Error {
63
+ readonly code = "OWNER_RECOVERY_DEGRADED";
64
+ constructor();
65
+ }
66
+ export declare class OwnerRecoveryTimeoutError extends Error {
67
+ readonly stage: string;
68
+ readonly code = "OWNER_RECOVERY_DEGRADED";
69
+ constructor(stage: string);
38
70
  }
39
71
  export type OwnerChannelManagementRequest = {
40
72
  action: 'contact_list';
@@ -144,6 +176,8 @@ export declare class OwnerChannel implements OwnerChannelHandle {
144
176
  * (a crash must replay them) but must not be queued twice while live.
145
177
  */
146
178
  private readonly inFlight;
179
+ /** SDK handlers entered during the current getMessages call. */
180
+ private readonly typedHandlersEntered;
147
181
  /** Wires already NACKed to the managed agent, so a history replay stays quiet. */
148
182
  private readonly relayNacks;
149
183
  /**
@@ -162,17 +196,47 @@ export declare class OwnerChannel implements OwnerChannelHandle {
162
196
  private readonly completionTasks;
163
197
  private readonly activeRequests;
164
198
  private managementTail;
199
+ private recoveryEpoch?;
200
+ private recoveryTask?;
201
+ private recoveryToken;
202
+ private recoveryQueued;
203
+ private watchGeneration;
204
+ /** A timed-out client operation that must settle before replacement is safe. */
205
+ private recoveryQuiescence?;
206
+ private releaseSafe;
165
207
  private ready;
208
+ private startedOnce;
209
+ private shutdownDegraded;
166
210
  private binder?;
167
211
  private binderOwnedInternally;
168
212
  private readonly fleetOps;
169
213
  private readonly prepareRestart;
214
+ private readonly commandAudits;
215
+ private readonly lifecycleOutbox;
170
216
  constructor(options: OwnerChannelOptions);
171
217
  start(): Promise<void>;
172
218
  drain(): Promise<void>;
173
219
  close(): Promise<void>;
220
+ binderReleaseSafe(): boolean;
174
221
  manage(request: OwnerChannelManagementRequest): Promise<OwnerChannelManagementResult>;
175
222
  notifyFleetSpawn(event: ManagedFleetSpawnResult): Promise<void>;
223
+ notifyFleetLifecycle(presentations: FleetAuditPresentation[]): Promise<void>;
224
+ private flushPendingFleetLifecycle;
225
+ beginFleetCommandAudit(requestId: string, argv: string[]): Promise<FleetAuditAttempt>;
226
+ finishFleetCommandAudit(input: {
227
+ correlationId: string;
228
+ class: FleetCommandOutcomeClass;
229
+ exitCode?: number;
230
+ effect: 'not_started' | 'completed' | 'unknown';
231
+ resourceIds?: Record<string, string>;
232
+ presentations?: FleetAuditPresentation[];
233
+ }): Promise<FleetAuditAttempt>;
234
+ private flushPendingFleetCommandAudits;
235
+ private deliverFleetCommandOutcome;
236
+ recover(epoch: string): Promise<void>;
237
+ private recoveryStage;
238
+ private writeShutdownState;
239
+ private queueManagement;
176
240
  private manageNow;
177
241
  /**
178
242
  * The daemon reports established contacts and pending introductions as two
@@ -213,6 +277,15 @@ export declare class OwnerChannel implements OwnerChannelHandle {
213
277
  * agent itself can execute /force-restart, /model, or any other command.
214
278
  */
215
279
  private handleCommand;
280
+ /**
281
+ * Register one typed adapter per primary slash command. The adapter performs
282
+ * the live CID check before constructing the same slash text and entering the
283
+ * existing dispatcher; its null SDK result avoids duplicating the ordinary
284
+ * owner-channel replies that remain the command's result contract.
285
+ */
286
+ private registerTypedCommands;
287
+ private handleRecoveredTypedCommand;
288
+ private handleTypedCommand;
216
289
  /** Queue raw slash text to the harness and report the turn's outcome. */
217
290
  private runHarnessCommand;
218
291
  /**
@@ -225,9 +298,8 @@ export declare class OwnerChannel implements OwnerChannelHandle {
225
298
  * before an external worker starts a saga that can retire this process.
226
299
  */
227
300
  private closeRoomFromOwner;
228
- private recoverRoomFromOwner;
229
- /** Carry a task terminal request through a worker that survives this role. */
230
- private recoverTaskFromOwner;
301
+ /** Accept a permanent any-state deletion, acknowledge it, then hand cleanup to a durable worker. */
302
+ private deleteTaskFromOwner;
231
303
  private terminalTaskFromOwner;
232
304
  /** Code-point-safe tail of the worklog, or undefined when there is none. */
233
305
  private readWorklogTail;